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/finalizer #61

Merged
merged 61 commits into from
Oct 31, 2024
Merged

Feat/finalizer #61

merged 61 commits into from
Oct 31, 2024

Conversation

tak1827
Copy link
Contributor

@tak1827 tak1827 commented Jul 28, 2024

Fast FinalityをBSCのv1.4.6から移植しました。
差分が多いです。新規のファイルは基本的にいじっていません。僕が加えた変更は主にConsensusに集中しています。

気になるところをコメントに残しました。また、処理メモも下に残しました。

動作確認は、private-opstackのfeat/support-finalizerで可能です。updateBLSKeyボタンを押して、BLS鍵を登録する必要があります。

@tak1827
Copy link
Contributor Author

tak1827 commented Aug 20, 2024

Finalizerの処理メモ

フラグ

  • VotingEnabledFlag
    • NewVoteManagerを作るかどうかのフラグ。オンならVoteをする。Voteするだけで、Vote結果を集約させるかは次のフラグで制御
    • default: false
  • DisableVoteAttestationFlag
    • vote結果を集約してBlockに含めることをしない。つまり、Finalizeさせないようにする
    • default: false

各フロー

  • 自分で署名を作る場合のフロー
    • Ethereum.New(backend.go)でNewVoteManagerを作る
    • NewVoteManager
      • VoteSignerを作る
        • signer鍵が複数ある場合、リストの最初のものが自動で選択される
      • VoteJournalを作る
        • 自身のVoteをFileに書き出す
      • loopを起動
        • 新しいHeadがくる(ブロックが積み上がるたびに)とそのHeadのVoteを作る
          • 起動してから5ブロックはSkipされる
          • BLSPubKeyがValidatorセットに登録されているものと一致しない場合はSkip
          • VoteEnvelope
            • SourceBlock
              • Consensusが持つsnapのAttestationのTargetBlockをセット
                • 1回投票されたBlock、つまりJustifyされたBlockをセットする
            • TargetBlock
              • 最新Head
          • AttestationのVote
          • 作られたVoteはPoolにPutされる(pool.PutVote)
  • 署名を受け取る場合のフロー
    • Ethereum.New(backend.go)でbsc/protocolをRegisterProtocolsする
      • どんなプロトコル?
        • VotesMsgをhandleVotesするプロトコル
    • Voteを受け取るとbscHandlerのHandleが呼ばれる
      • 同じPeerが30秒間に300個以上の署名を送ることはできない
      • PoolにPutする(pool.PutVote)
  • Voteを集計してBlockに入れるフロー
    • SealでVoteを集計してHeaderにAttestationを付与する(assembleVoteAttestation)
  • BlockをFinalizeするフロー
    • worker.goのWriteBlockAndSetHeadでSetFinalizedする
      • Finalize対象の高さはConsensusのsnapが持つAttestationのSouceBlockが指定される
        • つまり、2回投票されたBlock
          • SouceはJustifyさられたBlockが指定される。Souceが入ってるAttestaion自体を含めて2回
    • なお、SafeHeadは更新しない

Copy link
Collaborator

@ironbeer ironbeer left a comment

Choose a reason for hiding this comment

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

途中報告です

consensus/oasys/oasys.go Show resolved Hide resolved
consensus/oasys/oasys.go Outdated Show resolved Hide resolved
consensus/oasys/oasys.go Outdated Show resolved Hide resolved
consensus/oasys/oasys.go Show resolved Hide resolved
consensus/oasys/oasys.go Show resolved Hide resolved
consensus/oasys/snapshot.go Show resolved Hide resolved
Copy link
Collaborator

@ironbeer ironbeer left a comment

Choose a reason for hiding this comment

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

途中報告です

consensus/oasys/oasys.go Outdated Show resolved Hide resolved
consensus/oasys/oasys.go Outdated Show resolved Hide resolved
consensus/oasys/oasys.go Show resolved Hide resolved
consensus/oasys/oasys.go Show resolved Hide resolved
@tak1827 tak1827 requested a review from ironbeer October 7, 2024 13:53
Copy link
Collaborator

@ironbeer ironbeer left a comment

Choose a reason for hiding this comment

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

途中報告です

consensus/oasys/snapshot.go Outdated Show resolved Hide resolved
consensus/oasys/oasys.go Outdated Show resolved Hide resolved
consensus/oasys/snapshot.go Show resolved Hide resolved
ironbeer and others added 3 commits October 8, 2024 20:36
Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>
@tak1827 tak1827 requested a review from ironbeer October 8, 2024 12:13
core/blockchain.go Outdated Show resolved Hide resolved
@tak1827 tak1827 requested a review from ironbeer October 10, 2024 04:07
eth/ethconfig/config.go Outdated Show resolved Hide resolved
* Imported diffs of blockchain.go and headerchain.go from bsc@v1.4.6

* Imported fast finality reorganization from bsc@v1.4.6 (#75)

* Imported fast finality reorganization from bsc@v1.4.6

* Fix errors in test code

* elaborate the timeing update finalized and justified gauge (#77)

---------

Co-authored-by: tak <re795h@gmail.com>
miner/worker.go Outdated Show resolved Hide resolved
ironbeer and others added 2 commits October 18, 2024 12:49
* Imported stop process of eth.handler from bsc@v1.4.6

* Imported `chainFinalizedHeightFn` of fetcher.BlockFetcher from bsc@v1.4.6

* remove stop chan from eth/handler (#82)

---------

Co-authored-by: tak <re795h@gmail.com>
@tak1827 tak1827 requested a review from ironbeer October 20, 2024 05:23
@tak1827 tak1827 merged commit ee00963 into main Oct 31, 2024
@tak1827 tak1827 deleted the feat/finalizer branch October 31, 2024 02:41
tak1827 added a commit that referenced this pull request Oct 31, 2024
* Configured block time shortening epoch for the mainnet

* Fix block time shortening epoch for the mainnet

* Feat/finalizer (#61)

* copy new files from bsc@v1.4.6

* copy from bsc v1.4.6

* resolve interface missing method error for mock structs

* apply finality to our consensus

* add oasys consensus test: env/validators assemble

* whether broadcast vote judging from peers's TD

* fix lots of error to make work voting

* increase vote DOS threadhold

* fix lint error

* modify go.mod according to BSC

* vote attestaion stake weighted

* add MaliciousVoteMonitor

* remove bsc dependent comments/message

* rename finalizer to fast finality

* replace genesis contract by v1.6.0

* update genesis contract submodule (v1.6.0)

* resolved several consensus issue

* increment version to v1.6.0

* print error log: prepareWork and commit

* print warn log in case of invalid vote

* sort validators by owner for fast finality

* apply validators sort changes to snapshot.go

* disable deployments11

* refactor consensus

* upgrade stake manager contract version

* delete unused CeilDiv function

* delete unused metrics.label file copyed from bsc

* add comment to formHeader of finalize and seal case

* add comment why disable fromHeader on Finalize

* fix mainnet sync error: failed to verify header

* fix getValidators marshal error by suppporting old contract interface

* commit leak of previous one

* fix verify header error by adding missing return

* deal with unexpected value is presented to callGetHighStakesCommon

* fix getHighStakes unpack error. replace wrong contract

* sort by owner only fast finality enabled

* Improved performance degradation due to change in json format of consensus snapshot

* Improved EnvironmentValue parsing (#70)

* Add note to BLSPublicKey's Marshaler

* fix null pointer error after taking #69

* temporary set testnet hardfork for private testnet

* increase private testnet hardork block

* bring private hardfork time closer

* fix feedback from @ironbeer part1

* vot validator point to parent block(=target block)

* Add contract deploy test

* Update consensus/oasys/snapshot.go

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>

* fix feedback from ironbeer part2

* Added `Equal` method to EnvironmentValue (#71)

* Imported diffs of blockchain.go and headerchain.go from bsc@v1.4.6 (#74)

* Imported diffs of blockchain.go and headerchain.go from bsc@v1.4.6

* Imported fast finality reorganization from bsc@v1.4.6 (#75)

* Imported fast finality reorganization from bsc@v1.4.6

* Fix errors in test code

* elaborate the timeing update finalized and justified gauge (#77)

---------

Co-authored-by: tak <re795h@gmail.com>

* Fix panic when BLS key is nothing & support multiple keys (#81)

* Imported eth.handler from bsc@v1.4.6 (#78)

* Imported stop process of eth.handler from bsc@v1.4.6

* Imported `chainFinalizedHeightFn` of fetcher.BlockFetcher from bsc@v1.4.6

* remove stop chan from eth/handler (#82)

---------

Co-authored-by: tak <re795h@gmail.com>

* fix feadback from ironbeer part3

* Fix reorg when justification chain is split (#85)

* update loas contract & reset testnet hardfork schedule

* Fix misc (#87)

* Fix test error

* Fix image build error

---------

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>

* set testnet hardfork for v1.6.0 (#88)

---------

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>
tak1827 added a commit that referenced this pull request Oct 31, 2024
* Configured block time shortening epoch for the mainnet

* Fix block time shortening epoch for the mainnet

* Feat/finalizer (#61)

* copy new files from bsc@v1.4.6

* copy from bsc v1.4.6

* resolve interface missing method error for mock structs

* apply finality to our consensus

* add oasys consensus test: env/validators assemble

* whether broadcast vote judging from peers's TD

* fix lots of error to make work voting

* increase vote DOS threadhold

* fix lint error

* modify go.mod according to BSC

* vote attestaion stake weighted

* add MaliciousVoteMonitor

* remove bsc dependent comments/message

* rename finalizer to fast finality

* replace genesis contract by v1.6.0

* update genesis contract submodule (v1.6.0)

* resolved several consensus issue

* increment version to v1.6.0

* print error log: prepareWork and commit

* print warn log in case of invalid vote

* sort validators by owner for fast finality

* apply validators sort changes to snapshot.go

* disable deployments11

* refactor consensus

* upgrade stake manager contract version

* delete unused CeilDiv function

* delete unused metrics.label file copyed from bsc

* add comment to formHeader of finalize and seal case

* add comment why disable fromHeader on Finalize

* fix mainnet sync error: failed to verify header

* fix getValidators marshal error by suppporting old contract interface

* commit leak of previous one

* fix verify header error by adding missing return

* deal with unexpected value is presented to callGetHighStakesCommon

* fix getHighStakes unpack error. replace wrong contract

* sort by owner only fast finality enabled

* Improved performance degradation due to change in json format of consensus snapshot

* Improved EnvironmentValue parsing (#70)

* Add note to BLSPublicKey's Marshaler

* fix null pointer error after taking #69

* temporary set testnet hardfork for private testnet

* increase private testnet hardork block

* bring private hardfork time closer

* fix feedback from @ironbeer part1

* vot validator point to parent block(=target block)

* Add contract deploy test

* Update consensus/oasys/snapshot.go

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>

* fix feedback from ironbeer part2

* Added `Equal` method to EnvironmentValue (#71)

* Imported diffs of blockchain.go and headerchain.go from bsc@v1.4.6 (#74)

* Imported diffs of blockchain.go and headerchain.go from bsc@v1.4.6

* Imported fast finality reorganization from bsc@v1.4.6 (#75)

* Imported fast finality reorganization from bsc@v1.4.6

* Fix errors in test code

* elaborate the timeing update finalized and justified gauge (#77)

---------

Co-authored-by: tak <re795h@gmail.com>

* Fix panic when BLS key is nothing & support multiple keys (#81)

* Imported eth.handler from bsc@v1.4.6 (#78)

* Imported stop process of eth.handler from bsc@v1.4.6

* Imported `chainFinalizedHeightFn` of fetcher.BlockFetcher from bsc@v1.4.6

* remove stop chan from eth/handler (#82)

---------

Co-authored-by: tak <re795h@gmail.com>

* fix feadback from ironbeer part3

* Fix reorg when justification chain is split (#85)

* update loas contract & reset testnet hardfork schedule

* Fix misc (#87)

* Fix test error

* Fix image build error

---------

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>

* set testnet hardfork for v1.6.0 (#88)

* Fix voting process stopping with each synchronization (#90)

* Fix nil panic in td.Cmp(bestTd)

* Fix voting process stopping with each synchronization.

RelatedCode:
- eth/downloader/downloader.go#L463
- core/vote/vote_manager.go#L108-L110)

---------

Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants