beefy: initialize voter from genesis and fix initial sync (#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 <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2022-09-05 13:47:15 +03:00
committed by GitHub
parent 1fabf067d0
commit 84acfd5f50
4 changed files with 342 additions and 147 deletions
+5 -7
View File
@@ -145,7 +145,7 @@ impl BeefyTestNet {
})
}
pub(crate) fn generate_blocks(
pub(crate) fn generate_blocks_and_sync(
&mut self,
count: usize,
session_length: u64,
@@ -168,6 +168,7 @@ impl BeefyTestNet {
block
});
self.block_until_sync();
}
}
@@ -528,8 +529,7 @@ fn beefy_finalizing_blocks() {
runtime.spawn(initialize_beefy(&mut net, beefy_peers, min_block_delta));
// push 42 blocks including `AuthorityChange` digests every 10 blocks.
net.generate_blocks(42, session_len, &validator_set, true);
net.block_until_sync();
net.generate_blocks_and_sync(42, session_len, &validator_set, true);
let net = Arc::new(Mutex::new(net));
@@ -567,8 +567,7 @@ fn lagging_validators() {
runtime.spawn(initialize_beefy(&mut net, beefy_peers, min_block_delta));
// push 62 blocks including `AuthorityChange` digests every 30 blocks.
net.generate_blocks(62, session_len, &validator_set, true);
net.block_until_sync();
net.generate_blocks_and_sync(62, session_len, &validator_set, true);
let net = Arc::new(Mutex::new(net));
@@ -644,8 +643,7 @@ fn correct_beefy_payload() {
runtime.spawn(initialize_beefy(&mut net, bad_peers, min_block_delta));
// push 10 blocks
net.generate_blocks(12, session_len, &validator_set, false);
net.block_until_sync();
net.generate_blocks_and_sync(12, session_len, &validator_set, false);
let net = Arc::new(Mutex::new(net));
// with 3 good voters and 1 bad one, consensus should happen and best blocks produced.