mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-08 15:57:21 +00:00
Beefy on-demand justifications as a custom RequestResponse protocol (#12124)
* client/beefy: create communication module and move gossip there * client/beefy: move beefy_protocol_name module to communication * client/beefy: move notification module under communication * client/beefy: add incoming request_response protocol handler * client/beefy: keep track of connected peers and their progress * client/beefy: add logic for generating Justif requests * client/beefy: cancel outdated on-demand justification requests * try Andre's suggestion for JustificationEngine * justif engine add justifs validation * client/beefy: impl OnDemandJustificationsEngine async next() * move beefy proto name test * client/beefy: initialize OnDemandJustificationsEngine * client/tests: allow for custom req-resp protocols * client/beefy: on-demand-justif: implement simple peer selection strategy * client/beefy: fix voter initialization Fix corner case where voter gets a single burst of finality notifications just when it starts. The notification stream was consumed by "wait_for_pallet" logic, then main loop would subscribe to finality notifications, but by that time some notifications might've been lost. Fix this by subscribing the main loop to notifications before waiting for pallet to become available. Share the same stream with the main loop so that notifications for blocks before pallet available are ignored, while _all_ notifications after pallet available are processed. Add regression test for this. Signed-off-by: acatangiu <adrian@parity.io> * client/beefy: make sure justif requests are always out for mandatory blocks * client/beefy: add test for on-demand justifications sync * client/beefy: tweak main loop event processing order * client/beefy: run on-demand-justif-handler under same async task as voter * client/beefy: add test for known-peers * client/beefy: reorg request-response module * client/beefy: add issue references for future work todos * client/beefy: consolidate on-demand-justifications engine state machine Signed-off-by: acatangiu <adrian@parity.io> * client/beefy: fix for polkadot companion * client/beefy: implement review suggestions * cargo fmt and clippy * fix merge damage * fix rust-doc * fix merge damage * fix merge damage * client/beefy: add test for justif proto name Signed-off-by: acatangiu <adrian@parity.io>
This commit is contained in:
@@ -33,7 +33,7 @@ use sp_runtime::traits::{Block, NumberFor};
|
||||
/// whether the local `self` validator has voted/signed.
|
||||
///
|
||||
/// Does not do any validation on votes or signatures, layers above need to handle that (gossip).
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
struct RoundTracker {
|
||||
self_vote: bool,
|
||||
votes: HashMap<Public, Signature>,
|
||||
@@ -69,6 +69,7 @@ pub fn threshold(authorities: usize) -> usize {
|
||||
/// Only round numbers > `best_done` are of interest, all others are considered stale.
|
||||
///
|
||||
/// Does not do any validation on votes or signatures, layers above need to handle that (gossip).
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Rounds<Payload, B: Block> {
|
||||
rounds: BTreeMap<(Payload, NumberFor<B>), RoundTracker>,
|
||||
session_start: NumberFor<B>,
|
||||
@@ -135,7 +136,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn try_conclude(
|
||||
pub(crate) fn should_conclude(
|
||||
&mut self,
|
||||
round: &(P, NumberFor<B>),
|
||||
) -> Option<Vec<Option<Signature>>> {
|
||||
@@ -148,7 +149,6 @@ where
|
||||
|
||||
if done {
|
||||
let signatures = self.rounds.remove(round)?.votes;
|
||||
self.conclude(round.1);
|
||||
Some(
|
||||
self.validators()
|
||||
.iter()
|
||||
@@ -279,7 +279,7 @@ mod tests {
|
||||
true
|
||||
));
|
||||
// round not concluded
|
||||
assert!(rounds.try_conclude(&round).is_none());
|
||||
assert!(rounds.should_conclude(&round).is_none());
|
||||
// self vote already present, should not self vote
|
||||
assert!(!rounds.should_self_vote(&round));
|
||||
|
||||
@@ -296,7 +296,7 @@ mod tests {
|
||||
(Keyring::Dave.public(), Keyring::Dave.sign(b"I am committed")),
|
||||
false
|
||||
));
|
||||
assert!(rounds.try_conclude(&round).is_none());
|
||||
assert!(rounds.should_conclude(&round).is_none());
|
||||
|
||||
// add 2nd good vote
|
||||
assert!(rounds.add_vote(
|
||||
@@ -305,7 +305,7 @@ mod tests {
|
||||
false
|
||||
));
|
||||
// round not concluded
|
||||
assert!(rounds.try_conclude(&round).is_none());
|
||||
assert!(rounds.should_conclude(&round).is_none());
|
||||
|
||||
// add 3rd good vote
|
||||
assert!(rounds.add_vote(
|
||||
@@ -314,7 +314,8 @@ mod tests {
|
||||
false
|
||||
));
|
||||
// round concluded
|
||||
assert!(rounds.try_conclude(&round).is_some());
|
||||
assert!(rounds.should_conclude(&round).is_some());
|
||||
rounds.conclude(round.1);
|
||||
|
||||
// Eve is a validator, but round was concluded, adding vote disallowed
|
||||
assert!(!rounds.add_vote(
|
||||
@@ -432,11 +433,12 @@ mod tests {
|
||||
assert_eq!(3, rounds.rounds.len());
|
||||
|
||||
// conclude unknown round
|
||||
assert!(rounds.try_conclude(&(H256::from_low_u64_le(5), 5)).is_none());
|
||||
assert!(rounds.should_conclude(&(H256::from_low_u64_le(5), 5)).is_none());
|
||||
assert_eq!(3, rounds.rounds.len());
|
||||
|
||||
// conclude round 2
|
||||
let signatures = rounds.try_conclude(&(H256::from_low_u64_le(2), 2)).unwrap();
|
||||
let signatures = rounds.should_conclude(&(H256::from_low_u64_le(2), 2)).unwrap();
|
||||
rounds.conclude(2);
|
||||
assert_eq!(1, rounds.rounds.len());
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user