Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weak blocks WIP #1 #2055

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
10362c9
WeakBlockAlgos
kushti Aug 22, 2023
76e2f60
Merge branch 'v5.0.15' of github.com:ergoplatform/ergo into weak-blocks
kushti Sep 12, 2023
c5d30d3
WeakBlockInfo, WeakBlockMessageSpec
kushti Sep 18, 2023
5c2eb29
impl steps
kushti Sep 28, 2023
d378942
Merge branch 'v5.0.16' of github.com:ergoplatform/ergo into weak-blocks
kushti Oct 25, 2023
8843114
initial weak blocks structures and algos
kushti Oct 30, 2023
5c4f9c2
compact block like messaging
kushti Oct 31, 2023
0dbfeb0
before structures
kushti Nov 1, 2023
1a68d0e
skeleton of processing algo
kushti Nov 4, 2023
1040926
weak blocks => sub blocks
kushti Nov 7, 2023
636f3d8
more weak=>sub renaming
kushti Nov 7, 2023
6293421
returning download plan
kushti Nov 7, 2023
23a5db0
better comments and todos, formatting
kushti Nov 9, 2023
2c5cf3c
motivation started in EIP, data structures refined
kushti Nov 10, 2023
4189783
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Nov 28, 2023
4962218
pow, superblocks
kushti Dec 1, 2023
514e6fb
subblocks section finished
kushti Dec 2, 2023
564ad05
propagation text started, prevSubBlockId made optional (comp fails)
kushti Dec 6, 2023
346e1a7
commitment
kushti Dec 21, 2023
a068545
styling fixes
kushti Dec 28, 2023
c0709f2
key spaces for sub-blocks and sidechains
kushti Dec 29, 2023
85de7a4
eip update
kushti Jan 3, 2024
a248ccf
dag note, new subsections added
kushti Jan 4, 2024
0a9fd56
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Feb 12, 2024
93bc6bc
merging w. master, accounting for optional prevSubBlockId
kushti Feb 12, 2024
02056c2
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Jul 17, 2024
92baed0
input/ordering blocks intro
kushti Jul 19, 2024
54c9971
script execution ctx started
kushti Jul 20, 2024
73d76f2
extending subblocks info
kushti Jul 24, 2024
69adf58
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Jul 30, 2024
bed12e6
SubsPerBlock* improved comments in SubBlockAlgos
kushti Jul 30, 2024
01da1a0
BlockKind, distnguishing fn
kushti Aug 3, 2024
e448fb8
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Aug 5, 2024
3e9f4d1
blockKind()
kushti Aug 6, 2024
1a8aaeb
unused reportModifierIsInvalid removed
kushti Aug 7, 2024
184996e
ProgressInfo.empty, removing implicit ScorexEncoder
kushti Aug 7, 2024
8bc72cc
MessageSpecInitial / MessageSpecSubBlock
kushti Aug 12, 2024
4192c61
merkle proof added to SubBlockInfo, serializer updated, SubBlockMessa…
kushti Aug 14, 2024
a044955
batch merkle proof usage and serialization
kushti Aug 29, 2024
613fc58
Merge branch 'jni-dep' of github.com:ergoplatform/ergo into weak-blocks
kushti Aug 29, 2024
c382a38
processSubblock started
kushti Sep 3, 2024
15ca997
subblock height check
kushti Sep 3, 2024
222c850
SubBlockTransactionsRequestSpec, completing processSubblock stub
kushti Sep 4, 2024
e6ee392
SubBlockTransactionsSpec
kushti Sep 5, 2024
fb98a2e
subblocks p2p logic stub
kushti Sep 8, 2024
95fb95e
LocallyGeneratedSubBlock
kushti Sep 13, 2024
5f66580
subblock keys, CandidateGenerator simplification
kushti Sep 13, 2024
f118879
more simplification in CandidateGenerator
kushti Sep 13, 2024
e8bcdfa
bestSubblock() stub. createCandidate #1
kushti Sep 13, 2024
647b6db
initial version of best subblock selection
kushti Sep 18, 2024
e93d333
merging w. 5.0.23
kushti Sep 19, 2024
e0feb83
input/ordering block distintcion in mining logic #1, input block gene…
kushti Sep 19, 2024
9ebe5db
subblocks generation
kushti Oct 1, 2024
5e623b4
fixing delivery of sub-blocks to processing
kushti Oct 1, 2024
c9de516
input block pow validation
kushti Oct 10, 2024
b908142
completeOrderingBlock / completeInputBlock
kushti Oct 10, 2024
08c52d6
sendInputToNodeView stub (pre-refactoring)
kushti Oct 15, 2024
ac824a4
LocallyGeneratedInputBlock / LocallyGeneratedOrderingBlock
kushti Oct 16, 2024
4fc43c5
reworked LocallyGeneratedInputBlock signature
kushti Oct 18, 2024
ef02664
forum post
kushti Oct 30, 2024
4011aa5
removing subblock field from Candidate
kushti Oct 30, 2024
e9811ce
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Dec 10, 2024
c81839d
papers/subblocks folder
kushti Dec 10, 2024
319f7a6
forming SubBlockInfo, SubBlockTransactionsData moved to completeInput…
kushti Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions papers/subblocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Sub-Blocks and Improved Confirmed Transactions Propagation
==========================

* Author: kushti
* Status: Proposed
* Created: 31-Oct-2023
* License: CC0
* Forking: Soft Fork

Motivation
----------

Currently, a block is generated every two minutes on average, and confirmed transactions are propagated along with
other block sections.

This is not efficient at all. Most of new block's transactions are already available in a node's mempool, and
bottlenecking network bandwidth after two minutes of (more or less) idle state is also downgrading network performance.

Also, while average block delay in Ergo is 2 minutes, variance is high, and often a user may wait 10 minutes for
first confirmation. Proposals to lower variance are introducing experimental and controversial changes in consensus protocol.
Changing block delay via hardfork would have a lot of harsh consequences (e.g. many contracts relying on current block
delay would be broken). Thus it makes sense to consider weaker notions of confirmation which still could be useful for
a variety of applications.

Sub-Blocks
----------

A valid block is sequence of (semantically valid) header fields (and corresponding valid block sections, such as block
transactions), including special field to iterate over, called nonce, such as *H(b) < T*, where *H()* is Autolykos Proof-of-Work
function, *b* are block bytes (including nonce), and *T* is a Proof-of-Work *target* value. A value which is reverse
to target is called difficulty *D*: *D = 2^256 / T* (in fact, slightly less value than 2^256 is taken, namely, order of
secp256k1 curve group, this is inherited from initial Autolykos 1 Proof-of-Work algorithm). *D* (and so *T*) is being readjusted
regularly via a deterministic procedure (called difficulty readjustment algorithm) to have blocks coming every two minutes on average.

Aside of blocks, *superblocks" are also used in the Ergo protocol, for building NiPoPoWs on top of them. A superblock is
a block which is more difficult to find than an ordinary, for example, for a (level-1) superblock *S* we may require
*H(S) < T/2*, and in general, we can call n-level superblock a block *S* for which *H(S) < T/2^n*. Please note that a
superblock is also a valid block (every superblock is passing block PoW test).

Similarly, we can go in opposite direction and use *subblocks*, so blocks with lower difficulty. We can set *t = T/64*
and define superblock *s* as *H(s) < t*, then miner can generate on average 64 subblocks (including normal block itself)
per block generation period. Please note that, unlike superblocks, subblocks are not blocks, but a block is passing
subblock check.

Subblocks are similar to block shares already used in pooled mining. Rather, this proposal is considering to use
sub-blocks for improving transactions propagation and providing a framework for weaker confirmations.

Sub-Blocks And Transactions Propagation
---------------------------------------

Let's consider that new block is just generated. Miners A and B (among others) are working on a new block. Users are
submitting new unconfirmed transactions at the same time to the p2p network, and eventually they are reaching miners
(including A and B, but at a given time a transaction could be in one of the mempools just, not necessarily both, it
could also be somewhere else and not known to both A and B).

Then, for example, miner A is generating a sub-block committing to new transactions after last block. It sends sub-block
header as well as weak transaction ids (6 bytes hashes) of transactions included into this sub-block but not previous
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be worth detailing weak transaction ids a little bit, why 6 bytes of hashes specifically?

sub-blocks to peers. Peers then are asking for transactions they do not know only, and if previous sub-block is not
known, they are downloading it along with its transactions delta, and go further recursively if needed.

Thus pulse of sub-blocks will allow to exchange transactions quickly. And when a new sub-block is also a block (passing
normal difficulty check), not many transactions to download, normally. Thus instead of exchanging all the full-block
transactions when a new block comes, peers will exchange relatively small transaction deltas all the time. Full-block
transactions sections exchange still will be supported, to support downloading historical blocks, and also old clients.

Sub-blocks Structure and Commitment to Sub-Blocks
-------------------------------------------------

Here we consider what kind of footprint sub-blocks would have in consensus-enforced data structures (i.e. on-chain).
Proper balance here is critical and hard to achieve. Strict consensus-enforced commitments (when all the
sub-blocks committed on-chain) require from all the miners to have all the sub-blocks in order to check them. But,
at the same time, consensus-enforced commitments to properly ordered sub-blocks would allow for protocols and
applications using sub-blocks data.

We have chosen weak commitments. That is, a miner may (and incentivized to) to commit to longest sub-blocks chain
since previous full-block, but that there are no any requirements about that in Ergo consensus rules.

New extension key space starting with 0x03 will be used for sub-blocks related data, with one key used per this EIP:

0x03 0x00 - digest of a Merkle tree of longest sub-blocks chain starting with previous block (but not including it).

So first sub-block having full-block as a parent will have empty tree, next one will have only first, and next
full-block will commit to all the sub-blocks since previous full-block.

At the same time, no any new checks are planned for the Ergo protocol. Checks are possible for sidechains.


Sub-Block Based Sidechains
--------------------------

As L1 incentivization for propagating and committing on-chain to sub-blocks are missed, we consider sub-block based
merge-mined sidechains as possible option to incentivize miners to participate in the sub-blocks sub-protocol. They
also can be used to enforce linearity (so that transactions added in a previous sub-block can't be reversed).

A merged-mined sidechain is using sub-blocks as well as blocks to update its state which can be committed via main-chain
transactions even. That is, in every sub-blocks side-chain state (sidechain UTXO set digest etc) can be written in a box
with sidechain NFT, and then every sub-block the box may be updated.

For rewarding miners submitting sub-blocks to Ergo network (sidechain block generators are listening to), a sidechain block
may be consist of main-chain sub-block and sidechain state along with membership proof. For enforcing linearity of transactions
, sidechain consensus may enforce rollback to a sub-block before transaction reversal on proof of reversal being published.

Incentivization
---------------

No incentives to generate and propagate sub-blocks are planned for the Ergo core protocols at the moment. At the same
time, incentives can be provided on the sub-block based merge-mined sidechains, or via application-specific agreements
(where applications may pay to miners for faster confirmations).
11 changes: 10 additions & 1 deletion src/main/scala/org/ergoplatform/http/api/MiningApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import akka.pattern.ask
import io.circe.syntax._
import io.circe.{Encoder, Json}
import org.ergoplatform.mining.CandidateGenerator.Candidate
import org.ergoplatform.mining.{AutolykosSolution, CandidateGenerator, ErgoMiner}
import org.ergoplatform.mining.{AutolykosSolution, CandidateGenerator, ErgoMiner, WeakAutolykosSolution}
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.nodeView.wallet.ErgoAddressJsonEncoder
import org.ergoplatform.settings.ErgoSettings
Expand Down Expand Up @@ -63,6 +63,15 @@ case class MiningApiRoute(miner: ActorRef,
ApiResponse(result)
}

def weakSolutionR: Route = (path("weakSolution") & post & entity(as[WeakAutolykosSolution])) { solution =>
val result = if (ergoSettings.nodeSettings.useExternalMiner) {
miner.askWithStatus(solution).mapTo[Unit]
} else {
Future.failed(new Exception("External miner support is inactive"))
}
ApiResponse(result)
}

def rewardAddressR: Route = (path("rewardAddress") & get) {
val addressF: Future[ErgoAddress] =
miner.askWithStatus(ErgoMiner.ReadMinerPk)
Expand Down
25 changes: 25 additions & 0 deletions src/main/scala/org/ergoplatform/mining/AutolykosSolution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
import org.bouncycastle.util.BigIntegers
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.mining.AutolykosSolution.pkForV2
import org.ergoplatform.modifiers.history.header.Header.Version
import org.ergoplatform.settings.Algos
import scorex.core.serialization.ErgoSerializer
Expand Down Expand Up @@ -57,6 +58,30 @@ object AutolykosSolution extends ApiCodecs {

}

case class WeakAutolykosSolution(pk: EcPointType, n: Array[Byte]) {
val encodedPk: Array[Byte] = groupElemToBytes(pk)
}

object WeakAutolykosSolution extends ApiCodecs {
implicit val jsonEncoder: Encoder[WeakAutolykosSolution] = { s: WeakAutolykosSolution =>
Map(
"pk" -> s.pk.asJson,
"n" -> Algos.encode(s.n).asJson
).asJson
}

implicit val jsonDecoder: Decoder[WeakAutolykosSolution] = { c: HCursor =>
for {
pkOpt <- c.downField("pk").as[Option[EcPointType]]
n <- c.downField("n").as[Array[Byte]]
} yield {
WeakAutolykosSolution(pkOpt.getOrElse(pkForV2), n)
}
}

}



/**
* Binary serializer for Autolykos v1 solution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ object Extension extends ApiCodecs {
*/
val ValidationRulesPrefix: Byte = 0x02

/**
* Prefix for keys related to sub-blocks related data.
*/
val SubBlocksDataPrefix: Byte = 0x03

/**
* Prefix for keys related to sidechains data.
*/
val SidechainsDataPrefix: Byte = 0x04

/**
* Id a type of network object encoding extension
*/
Expand Down
Loading