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

Feat: Optimistic fast finality #316

Merged
merged 42 commits into from
Sep 7, 2023
Merged

Commits on Sep 7, 2023

  1. Configuration menu
    Copy the full SHA
    95c8922 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6586619 View commit details
    Browse the repository at this point in the history
  3. feat: implement bls accounts and keymanager (#298)

    * feat: implement bls accounts and keymanager
    
    * chore: Implement `CreateAccountsKeystore` function
    
    * chore: remove prysm import from keymanager
    DNK90 authored and minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    068a74f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5f8920d View commit details
    Browse the repository at this point in the history
  5. core/types: add finality vote file (#305)

    DNK90 authored and minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    ec15ae4 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    2fe0f4a View commit details
    Browse the repository at this point in the history
  7. crypto/bls: fix bls signature batch unit test (#306)

    We randomly observe this failure when running unit test
    
    go test -test.v -run=^TestSignatureBatch_AggregateBatch/common_and_uncommon_messages_in_batch_with_multiple_messages
    === RUN   TestSignatureBatch_AggregateBatch
    === RUN   TestSignatureBatch_AggregateBatch/common_and_uncommon_messages_in_batch_with_multiple_messages
        signature_batch_test.go:643: AggregateBatch() Descriptions got = [test signature bls aggregated signature test signature bls aggregated signature test signature bls aggregated signature], want [bls aggregated signature test signature bls aggregated signature test signature bls aggregated signature test signature]
    --- FAIL: TestSignatureBatch_AggregateBatch (0.02s)
        --- FAIL: TestSignatureBatch_AggregateBatch/common_and_uncommon_messages_in_batch_with_multiple_messages (0.02s)
    
    The problem is that the signature sort forgets to swap the description when a
    swap occurs. This commit adds the description swap when swap occurs.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    42e63c6 View commit details
    Browse the repository at this point in the history
  8. core/vote: implement finality vote manager and pool (#301)

    * feat: implement vote manager logics
    
    * chore: remove SourceNumber and SourceHash from vote
    
    * chore: Add `Debug` function which allow debugging within `VoteManager`
    
    * nit: Remove unused code
    
    * chore: rename `VoteAddress` to `PublicKey`
    
    * core/vote: validator only votes for the higher block height
    
    This commit implements new rule that allow validator to only vote for higher
    block height than its previous vote. With this vote journal is not necessary
    anymore so we remove it.
    
    * cmd, eth: init the vote manager and vote pool
    
    * vote_signer: clean up code
    
    ---------
    
    Co-authored-by: Bui Quang Minh <[email protected]>
    DNK90 and minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    7b2f9cf View commit details
    Browse the repository at this point in the history
  9. core/types/vote: introduce RawVoteEnvelop (#308)

    RawVoteEnvelop is the same as VoteEnvelop without cached hash
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    039e4dd View commit details
    Browse the repository at this point in the history
  10. core/vote/vote_pool: protect pool against malicious peer (#309)

    This commit limits the number of votes in future queue per peer as the vote in
    future queue is not fully verified. The check happens before the costly
    basicVerify which has to verify the BLS signature.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    6d0a974 View commit details
    Browse the repository at this point in the history
  11. build: add cflags to build portable blst library (#310)

    We randomly get error in CI
    
    	Caught SIGILL in blst_cgo_init, consult <blst>/bindinds/go/README.md.
    
    As in blst documentation, we need to provide CGO_CFLAGS="-O -D__BLST_PORTABLE__"
    to make the compiled blst portable across different CPU. This commit adds this
    CGO_CFLAGS to the build process.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    cc76bf6 View commit details
    Browse the repository at this point in the history
  12. consortium/v2: add finality vote to consensus layer (#299)

    * param: introduce Shillin hardfork
    
    * consortium/v2: add finality vote to consensus layer
    
    This commit extends the snapshot to contains additional BLS public key of the
    validators. The new information is also added to header's extra data like
    aggregated BLS signature and voted validator information. A new system
    transaction is created to reward the finality voted validators.
    
    * consortium/v2: test header encoding and finality signature verification
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    d5a271d View commit details
    Browse the repository at this point in the history
  13. blockchain, rpc, backend: add new forkchoice and finalized block query (

    #303)
    
    * core/blockchain: choose the chain with highest justified block in fork choice
    
    This commit introduces the new logic to fork choice to choose the fork with
    higher justified block before comparing total diffculty. In case the justified
    blocks in forks have the same height, we fallback to compare total difficulty
    same as before.
    
    * rpc, backend: add finalized block the block query
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    2b01e56 View commit details
    Browse the repository at this point in the history
  14. eth/protocols: implement finality vote communication via ronin protoc…

    …ol (#307)
    
    * eth/protocols: implement finality vote communication via ronin protocol
    
    ronin protocol is an extension protocol of eth, a peer is required to support
    eth protocol to run ronin protocol. ronin protocol currently only supports
    NewVotePacket which contains a list of finality votes.
    
    * eth/protocols: don't broadcast known finality vote to peer
    
    If a vote is broadcasted from a peer or we have broadcasted to that peer
    already, we mark this vote is known by that peer and does not broadcast this
    vote to that peer again.
    
    * eth/protocols: test finality vote broadcast via ronin protocol
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    d3e0b17 View commit details
    Browse the repository at this point in the history
  15. vote/vote_pool: use TryRLock in FetchVoteByBlockHash (#311)

    The FetchVoteByBlockHash is called by the consensus engine and we don't want
    this function to block the consensus engine's operations. Currently,
    FetchVoteByBlockHash uses RLock to wait to acquire the read lock but as the
    writers are uncontrolled, it can be blocked when there are a lot of spamming
    writers. This commit makes FetchVoteByBlockHash to use TryRLock to keep polling
    for the lock n times and returns nil in case it cannot acquire the lock. This
    helps to bound the max duration a caller must wait on this function.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    46a63f5 View commit details
    Browse the repository at this point in the history
  16. core/vm: add precompiled contract to verify finality vote violation p…

    …roof (#314)
    
    This precompiled contract is called by system contract to verify signature from
    the provided proof of finality vote violation. It checkes if there is a
    validator has contributed to 2 aggregated signatures on the 2 distinct block
    with the same height.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    9aa5709 View commit details
    Browse the repository at this point in the history
  17. monitor/finality_vote: add finality vote monitor (#312)

    * consortium: add GetActiveValidatorAt to get validators can vote for a block
    
    * monitor/finality_vote: add finality vote monitor
    
    This monitor gets the information from block header and check if a voter votes
    for 2 distinct block at the same height.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    654a936 View commit details
    Browse the repository at this point in the history
  18. consortium/v2: fix snapshot save after Shillin (#317)

    The blsCommon.PublicKey cannot be un/marshalled to json, this commit converts
    that field to hex string before marshalling to json.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    27e6cac View commit details
    Browse the repository at this point in the history
  19. build: add CGO flags to all build targets (#322)

    Currently, we only add CGO flags when running 'make ronin', so sometimes we
    still get the error related to blst library built without the CGO_CFLAGS. This
    commit adds the CGO flags to all places when we use 'go run' to build the binary.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    acb814b View commit details
    Browse the repository at this point in the history
  20. consortium/v2: add contract interaction to get BLS public key (#320)

    This commit adds the contract interaction to get BLS public when preparing
    checkpoint block. This also creates a getCheckpointValidatorsFromContract
    function to be used in both Prepare and Finalize the checkpoint block. Besides,
    a new interface ContractInteraction is created for mock test contract
    interaction.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    2d51eb5 View commit details
    Browse the repository at this point in the history
  21. eth/backend: add vote pool to consortium engine (#323)

    When the vote pool is enabled, make the consortium consensus engine use it.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    7318ee4 View commit details
    Browse the repository at this point in the history
  22. consortium/v2: fix the finality vote fetch from pool (#319)

    The commit fixes the bug when collects and aggregates signatures from vote pool.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    835c313 View commit details
    Browse the repository at this point in the history
  23. blockchain: check total difficulty only when having same justified bl…

    …ock number (#321)
    
    In fork choice, we only need to compare the difficulty of forks when the
    justified block numbers are the same in those forks. Otherwise, we choose the
    fork with higher justified block number. This commit fixes a bug in current fork
    choice to make it follow the correct behavior.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    cb16894 View commit details
    Browse the repository at this point in the history
  24. consortium/v2: edit the finality vote threshold (#324)

    Due to the change in REP-0003, a block is finalized when there are at least
    floor(2/3*numValidators) + 1, this commit changes the calculation to follow the
    rule.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    6f2bf3a View commit details
    Browse the repository at this point in the history
  25. consortium/v2: add RPC API for querying finality vote easily (#318)

    This commit adds 2 APIs in consortiumv2 namespace:
    consortiumv2_getValidatorAtHash, consortiumv2_getFinalityVoteAtHash.
    consortiumv2_getValidatorAtHash returns the authorized validators that can seal
    block hash with BLS public key. consortiumv2_getFinalityVoteAtHash returns the
    finality vote information in the block header at block hash.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    555a252 View commit details
    Browse the repository at this point in the history
  26. accountcmd, entrypoint: add BLS key management commands (#325)

    This commit adds account commands:
    - listbls: show the BLS accounts information
    - importbls: import BLS secret key
    - checkbls: check if the BLS account with the provided secret key already exists
    - generatebls: generate BLS secret key
    
    This commit also adds BLS management code to entrypoint.sh for running node
    using docker.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    0f0e06f View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    4a11959 View commit details
    Browse the repository at this point in the history
  28. consortium/v2: add VerifyVote and fix blsPublicKey access (#327)

    * consortium: add VerifyVote to the outer consortium
    
    As required by the FastFinalityPoSA interface, VerifyVote is needed in the outer
    consortium. We add VerifyVote to outer consortium which simply forwards to the
    consortium v2 function.
    
    * consortium/v2: access blsPublicKey only after Shillin
    
    The BLS public key is only available in checkpoint header after Shillin, so
    don't access this field before Shillin.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    c46cf70 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    9255cdb View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    2e6d7d7 View commit details
    Browse the repository at this point in the history
  31. consortium/v2: fix the incorrect snapshot lookup in GetFinalizedBlock (

    …#330)
    
    Currently, to check if the justified block number - 1 is justfied, we look at
    the snapshot at justfied block number - 1. This is incorrect because at the
    snapshot N, the maximum justified block number is N - 1. So, we need to look at
    the snapshot at justified block number to check if the justified block number -
    1 is justified.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    a0faee0 View commit details
    Browse the repository at this point in the history
  32. Dockerfile, entrypoint: fix start script and install additional packa…

    …ge (#326)
    
    * entrypoint: fix bash script syntax
    
    * Dockerfile: add required libstdc++ package
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    60b52c1 View commit details
    Browse the repository at this point in the history
  33. protocols/ronin, vote/votepool: improve vote channel queue (#336)

    * protocols/ronin: remove redudant finality vote channel put
    
    * vote/vote_pool: make PutVote non-blocking, drop vote in case of failure
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    96febbb View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    857e078 View commit details
    Browse the repository at this point in the history
  35. vote/vote_pool: reject older than justified block number vote (#334)

    * vote/vote_pool: reject older than justified block number vote
    
    The vote which targets the block number that is older or equal to justified
    block number is not useful anymore. We can reject and prune those votes from
    pool.
    
    * vote/vote_pool: prune the future vote map and queue
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    ab7efcc View commit details
    Browse the repository at this point in the history
  36. consortium/v2: make SealHash return unchanged hash after Shillin (#332)

    As we delay assembling finality vote until Seal function, it means the seal hash
    can be updated after the FinalizeAndAssemble. This breaks the worker which uses
    seal hash to store and look up seal tasks between FinalizeAndAssemble and Seal
    function. Worker uses SealHash function to get the header hash and this function
    is used by worker only not by any other parts in the consensus. So in this
    commit, we make this function returns a hash of header without the finality
    vote. This is not the real hash used for sealing but it remains unchanged after
    FinalizeAndAssemble which meet the requirement of the worker.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    c59e820 View commit details
    Browse the repository at this point in the history
  37. consortium/v2: protect the contract interaction under mutex (#339)

    The contract field in consortium v2 consensus engine is written under the call
    to Authorize. The Authorize function is called only once in startup and can run
    concurrently with other funtions that read the contract field which leads to
    data race. We move this write under the mutex lock and the read of this field
    into readSignerAndContract function to avoid data race.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    c0b28d6 View commit details
    Browse the repository at this point in the history
  38. consortium/v2: reject the vote with wrong target number (#338)

    Currently, a vote with wrong target number is not assembled into block as there
    is a check in assembleFinalityVote. In this commit, we move that check to
    VerifyVote to reject the vote earlier in vote pool, avoid the vote pool to be
    DOSed.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    e677d26 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    efe0841 View commit details
    Browse the repository at this point in the history
  40. go.mod: bump blst to v0.3.11 (#348)

    blst v0.3.11 fixes this vulnerability. This vulnerability does not affect us
    because the wrapper we use does not call SigValidate with sigInfcheck argument
    set to true. However, it is not bad to bump to the latest version.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    aa6a2cc View commit details
    Browse the repository at this point in the history
  41. consortium/v2: distribute finality reward for the voters in parent bl…

    …ock (#337)
    
    * consortium/v2: distribute finality reward for the voters in parent block
    
    Because the finality votes are assembled after we FinalizeAndAssemble the block
    and the finality reward distribution transaction is in FinalizeAndAssemble, we
    cannot reward the finality voters in the current block right away. Instead, the
    reward distribution is delayed until next block. So in the FinalizeAndAssemble,
    we look at the finality voters in the parent header and distribute reward to
    them.
    
    * consortium/v2: integrate with the finality tracking contract
    
    This commit integrates with the finality tracking contract
    (axieinfinity/ronin-dpos-contracts#279) to record the
    finality reward for voters.
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    64b67de View commit details
    Browse the repository at this point in the history
  42. params: add optimistic fast finality testnet configuration (#353)

    This commit adds a Shillin hardfork on testnet to enable optimistic fast
    finality. The hardfork is scheduled around Sept 12 2023, 7:00 GMT+7
    (https://saigon-app.roninchain.com/block/20268000)
    minh-bq committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    716f8b5 View commit details
    Browse the repository at this point in the history