-
Notifications
You must be signed in to change notification settings - Fork 2.6k
beefy: initialize voter from genesis and fix initial sync #11959
Conversation
Now that we have justifications import, we can drop the "lean beefy" behaviour and start building justifications chain from Genesis with containing all past sessions' mandatory blocks justifications.
Signed-off-by: acatangiu <[email protected]>
During initial block import blocks are not finalized, so trying to validate and append justifications within block import fails (for initial network sync imported blocks). Changes: - Move justification validation to _after_ `inner.block_import()`, so block is imported in backend and runtime api can be called to get the BEEFY authorities for said block. - Move append-to-backend for imported BEEFY justification to voter, because it already has the required logic to BEEFY-finalize blocks only after GRANDPA finalized them. - Mark voting rounds as concluded when finalizing through imported justifications as well as when finalizing through voting. Signed-off-by: acatangiu <[email protected]>
The only way we'd get _different_ _validated_ justifications for same block number is if authorities are double voting, which will be handled later.
I will follow-up with a zombienet regression test for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
backend | ||
.blockchain() | ||
.expect_header(BlockId::hash(*hash)) | ||
.expect("just finalized block should be available; qed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also avoid calling expect here - there are db issues. concurrency, caches, mocked backends, ... they may cause their own issues. Otoh BEEFY worker may actually stop working because of that, so I can't say that logging + ignoring an error is any better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that is my thinking as well, if this errors out on a session boundary the voter is dead in the water anyway.
This way at least you can see the beefy-gadget task crashing and restart it..
BEEFY voter should resume voting from either: - last BEEFY finalized block, - session start, whichever is closest to head. Signed-off-by: acatangiu <[email protected]>
Signed-off-by: acatangiu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. I've just added a nitpick (not super relevant) and a question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for reviewing @davxy !
…#11959) * client/beefy: use backend instead of client where possible * client/beefy: initialize voter from genesis Now that we have justifications import, we can drop the "lean beefy" behaviour and start building justifications chain from Genesis with containing all past sessions' mandatory blocks justifications. * client/beefy: walk finality tree_route to catch session changes * client/beefy: fix block import During initial block import blocks are not finalized, so trying to validate and append justifications within block import fails (for initial network sync imported blocks). Changes: - Move justification validation to _after_ `inner.block_import()`, so block is imported in backend and runtime api can be called to get the BEEFY authorities for said block. - Move append-to-backend for imported BEEFY justification to voter, because it already has the required logic to BEEFY-finalize blocks only after GRANDPA finalized them. - Mark voting rounds as concluded when finalizing through imported justifications as well as when finalizing through voting. * client/beefy: valid justifications are one per block number The only way we'd get _different_ _validated_ justifications for same block number is if authorities are double voting, which will be handled later. * client/beefy: process incoming justifs during major sync * client/beefy: correct voter initialization BEEFY voter should resume voting from either: - last BEEFY finalized block, - session start, whichever is closest to head. * client/beefy: test voter initialization * client/beefy: impl review suggestions Signed-off-by: acatangiu <[email protected]>
Now that we have justifications import (added in #11821), we can drop the "lean beefy" behaviour and start building justifications chain from Genesis with containing all past sessions' mandatory blocks justifications.
For each finality notification also walk finality
tree_route
to catch session changes.During initial block import blocks are not finalized, so trying to validate and append justifications within block import fails (for initial network sync imported blocks). Fix this by:
inner.block_import()
, so block is imported in backend and runtime api can be called to get the BEEFY authorities for said block.Fixes #11954
Regression test in zombienet: paritytech/polkadot#5855