mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
sc-consensus-beefy: pump gossip engine while waiting for initialization conditions (#3435)
As part of BEEFY worker/voter initialization the task waits for certain chain and backend conditions to be fulfilled: - BEEFY consensus enabled on-chain & GRANDPA best finalized higher than on-chain BEEFY genesis block, - backend has synced headers for BEEFY mandatory blocks between best BEEFY and best GRANDPA. During this waiting time, any messages gossiped on the BEEFY topic for current chain get enqueued in the gossip engine, leading to RAM bloating and output warning/error messages when the wait time is non-negligible (like during a clean sync). This PR adds logic to pump the gossip engine while waiting for other things to make sure gossiped messages get consumed (practically discarded until worker is fully initialized). Also raises the warning threshold for enqueued messages from 10k to 100k. This is in line with the other gossip protocols on the node. Fixes https://github.com/paritytech/polkadot-sdk/issues/3390 --------- Signed-off-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
@@ -32,8 +32,8 @@ use crate::{
|
||||
gossip_protocol_name,
|
||||
justification::*,
|
||||
wait_for_runtime_pallet,
|
||||
worker::{BeefyWorkerBase, PersistedState},
|
||||
BeefyRPCLinks, BeefyVoterLinks, KnownPeers,
|
||||
worker::PersistedState,
|
||||
BeefyRPCLinks, BeefyVoterLinks, BeefyWorkerBuilder, KnownPeers,
|
||||
};
|
||||
use futures::{future, stream::FuturesUnordered, Future, FutureExt, StreamExt};
|
||||
use parking_lot::Mutex;
|
||||
@@ -368,27 +368,19 @@ async fn voter_init_setup(
|
||||
api: &TestApi,
|
||||
) -> Result<PersistedState<Block>, Error> {
|
||||
let backend = net.peer(0).client().as_backend();
|
||||
let known_peers = Arc::new(Mutex::new(KnownPeers::new()));
|
||||
let (gossip_validator, _) = GossipValidator::new(known_peers);
|
||||
let gossip_validator = Arc::new(gossip_validator);
|
||||
let mut gossip_engine = sc_network_gossip::GossipEngine::new(
|
||||
net.peer(0).network_service().clone(),
|
||||
net.peer(0).sync_service().clone(),
|
||||
net.peer(0).take_notification_service(&beefy_gossip_proto_name()).unwrap(),
|
||||
"/beefy/whatever",
|
||||
gossip_validator,
|
||||
None,
|
||||
);
|
||||
let (beefy_genesis, best_grandpa) =
|
||||
wait_for_runtime_pallet(api, &mut gossip_engine, finality).await.unwrap();
|
||||
let mut worker_base = BeefyWorkerBase {
|
||||
let (beefy_genesis, best_grandpa) = wait_for_runtime_pallet(api, finality).await.unwrap();
|
||||
let key_store = None.into();
|
||||
let metrics = None;
|
||||
BeefyWorkerBuilder::load_or_init_state(
|
||||
beefy_genesis,
|
||||
best_grandpa,
|
||||
1,
|
||||
backend,
|
||||
runtime: Arc::new(api.clone()),
|
||||
key_store: None.into(),
|
||||
metrics: None,
|
||||
_phantom: Default::default(),
|
||||
};
|
||||
worker_base.load_or_init_state(beefy_genesis, best_grandpa, 1).await
|
||||
Arc::new(api.clone()),
|
||||
&key_store,
|
||||
&metrics,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Spawns beefy voters. Returns a future to spawn on the runtime.
|
||||
@@ -1065,32 +1057,7 @@ async fn should_initialize_voter_at_custom_genesis() {
|
||||
net.peer(0).client().as_client().finalize_block(hashes[8], None).unwrap();
|
||||
|
||||
// load persistent state - nothing in DB, should init at genesis
|
||||
//
|
||||
// NOTE: code from `voter_init_setup()` is moved here because the new network event system
|
||||
// doesn't allow creating a new `GossipEngine` as the notification handle is consumed by the
|
||||
// first `GossipEngine`
|
||||
let known_peers = Arc::new(Mutex::new(KnownPeers::new()));
|
||||
let (gossip_validator, _) = GossipValidator::new(known_peers);
|
||||
let gossip_validator = Arc::new(gossip_validator);
|
||||
let mut gossip_engine = sc_network_gossip::GossipEngine::new(
|
||||
net.peer(0).network_service().clone(),
|
||||
net.peer(0).sync_service().clone(),
|
||||
net.peer(0).take_notification_service(&beefy_gossip_proto_name()).unwrap(),
|
||||
"/beefy/whatever",
|
||||
gossip_validator,
|
||||
None,
|
||||
);
|
||||
let (beefy_genesis, best_grandpa) =
|
||||
wait_for_runtime_pallet(&api, &mut gossip_engine, &mut finality).await.unwrap();
|
||||
let mut worker_base = BeefyWorkerBase {
|
||||
backend: backend.clone(),
|
||||
runtime: Arc::new(api),
|
||||
key_store: None.into(),
|
||||
metrics: None,
|
||||
_phantom: Default::default(),
|
||||
};
|
||||
let persisted_state =
|
||||
worker_base.load_or_init_state(beefy_genesis, best_grandpa, 1).await.unwrap();
|
||||
let persisted_state = voter_init_setup(&mut net, &mut finality, &api).await.unwrap();
|
||||
|
||||
// Test initialization at session boundary.
|
||||
// verify voter initialized with single session starting at block `custom_pallet_genesis` (7)
|
||||
@@ -1120,18 +1087,7 @@ async fn should_initialize_voter_at_custom_genesis() {
|
||||
|
||||
net.peer(0).client().as_client().finalize_block(hashes[10], None).unwrap();
|
||||
// load persistent state - state preset in DB, but with different pallet genesis
|
||||
// the network state persists and uses the old `GossipEngine` initialized for `peer(0)`
|
||||
let (beefy_genesis, best_grandpa) =
|
||||
wait_for_runtime_pallet(&api, &mut gossip_engine, &mut finality).await.unwrap();
|
||||
let mut worker_base = BeefyWorkerBase {
|
||||
backend: backend.clone(),
|
||||
runtime: Arc::new(api),
|
||||
key_store: None.into(),
|
||||
metrics: None,
|
||||
_phantom: Default::default(),
|
||||
};
|
||||
let new_persisted_state =
|
||||
worker_base.load_or_init_state(beefy_genesis, best_grandpa, 1).await.unwrap();
|
||||
let new_persisted_state = voter_init_setup(&mut net, &mut finality, &api).await.unwrap();
|
||||
|
||||
// verify voter initialized with single session starting at block `new_pallet_genesis` (10)
|
||||
let sessions = new_persisted_state.voting_oracle().sessions();
|
||||
@@ -1322,32 +1278,7 @@ async fn should_catch_up_when_loading_saved_voter_state() {
|
||||
let api = TestApi::with_validator_set(&validator_set);
|
||||
|
||||
// load persistent state - nothing in DB, should init at genesis
|
||||
//
|
||||
// NOTE: code from `voter_init_setup()` is moved here because the new network event system
|
||||
// doesn't allow creating a new `GossipEngine` as the notification handle is consumed by the
|
||||
// first `GossipEngine`
|
||||
let known_peers = Arc::new(Mutex::new(KnownPeers::new()));
|
||||
let (gossip_validator, _) = GossipValidator::new(known_peers);
|
||||
let gossip_validator = Arc::new(gossip_validator);
|
||||
let mut gossip_engine = sc_network_gossip::GossipEngine::new(
|
||||
net.peer(0).network_service().clone(),
|
||||
net.peer(0).sync_service().clone(),
|
||||
net.peer(0).take_notification_service(&beefy_gossip_proto_name()).unwrap(),
|
||||
"/beefy/whatever",
|
||||
gossip_validator,
|
||||
None,
|
||||
);
|
||||
let (beefy_genesis, best_grandpa) =
|
||||
wait_for_runtime_pallet(&api, &mut gossip_engine, &mut finality).await.unwrap();
|
||||
let mut worker_base = BeefyWorkerBase {
|
||||
backend: backend.clone(),
|
||||
runtime: Arc::new(api.clone()),
|
||||
key_store: None.into(),
|
||||
metrics: None,
|
||||
_phantom: Default::default(),
|
||||
};
|
||||
let persisted_state =
|
||||
worker_base.load_or_init_state(beefy_genesis, best_grandpa, 1).await.unwrap();
|
||||
let persisted_state = voter_init_setup(&mut net, &mut finality, &api).await.unwrap();
|
||||
|
||||
// Test initialization at session boundary.
|
||||
// verify voter initialized with two sessions starting at blocks 1 and 10
|
||||
@@ -1374,18 +1305,7 @@ async fn should_catch_up_when_loading_saved_voter_state() {
|
||||
// finalize 25 without justifications
|
||||
net.peer(0).client().as_client().finalize_block(hashes[25], None).unwrap();
|
||||
// load persistent state - state preset in DB
|
||||
// the network state persists and uses the old `GossipEngine` initialized for `peer(0)`
|
||||
let (beefy_genesis, best_grandpa) =
|
||||
wait_for_runtime_pallet(&api, &mut gossip_engine, &mut finality).await.unwrap();
|
||||
let mut worker_base = BeefyWorkerBase {
|
||||
backend: backend.clone(),
|
||||
runtime: Arc::new(api),
|
||||
key_store: None.into(),
|
||||
metrics: None,
|
||||
_phantom: Default::default(),
|
||||
};
|
||||
let persisted_state =
|
||||
worker_base.load_or_init_state(beefy_genesis, best_grandpa, 1).await.unwrap();
|
||||
let persisted_state = voter_init_setup(&mut net, &mut finality, &api).await.unwrap();
|
||||
|
||||
// Verify voter initialized with old sessions plus a new one starting at block 20.
|
||||
// There shouldn't be any duplicates.
|
||||
|
||||
Reference in New Issue
Block a user