mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Reduce number of active leaves at startup (#2631)
Currently we will take all leaves and give that to the overseer on startup, but this is a bad idea when the finality is lagging for example. There can be many of unfinalized leaves, we don't even need to look at anymore. To solve this, the pr adds a maximum of 4 leaves we forward to the overseer and the pr also checks that we only pass uncles of the best block.
This commit is contained in:
Generated
+2
@@ -1,5 +1,7 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "Inflector"
|
name = "Inflector"
|
||||||
version = "0.11.4"
|
version = "0.11.4"
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ use {
|
|||||||
sc_keystore::LocalKeystore,
|
sc_keystore::LocalKeystore,
|
||||||
babe_primitives::BabeApi,
|
babe_primitives::BabeApi,
|
||||||
grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider},
|
grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider},
|
||||||
|
sp_runtime::traits::Header as HeaderT,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "real-overseer")]
|
#[cfg(feature = "real-overseer")]
|
||||||
use polkadot_network_bridge::RequestMultiplexer;
|
use polkadot_network_bridge::RequestMultiplexer;
|
||||||
|
|
||||||
use sp_core::traits::SpawnNamed;
|
use sp_core::traits::SpawnNamed;
|
||||||
|
|
||||||
|
|
||||||
use polkadot_subsystem::jaeger;
|
use polkadot_subsystem::jaeger;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -78,6 +78,9 @@ pub use polkadot_runtime;
|
|||||||
pub use rococo_runtime;
|
pub use rococo_runtime;
|
||||||
pub use westend_runtime;
|
pub use westend_runtime;
|
||||||
|
|
||||||
|
/// The maximum number of active leaves we forward to the [`Overseer`] on startup.
|
||||||
|
const MAX_ACTIVE_LEAVES: usize = 4;
|
||||||
|
|
||||||
native_executor_instance!(
|
native_executor_instance!(
|
||||||
pub PolkadotExecutor,
|
pub PolkadotExecutor,
|
||||||
polkadot_runtime::api::dispatch,
|
polkadot_runtime::api::dispatch,
|
||||||
@@ -591,6 +594,56 @@ impl IsCollator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the active leaves the overseer should start with.
|
||||||
|
#[cfg(feature = "full-node")]
|
||||||
|
fn active_leaves<RuntimeApi, Executor>(
|
||||||
|
select_chain: &sc_consensus::LongestChain<FullBackend, Block>,
|
||||||
|
client: &FullClient<RuntimeApi, Executor>,
|
||||||
|
) -> Result<Vec<BlockInfo>, Error>
|
||||||
|
where
|
||||||
|
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
|
||||||
|
RuntimeApi::RuntimeApi:
|
||||||
|
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
|
||||||
|
Executor: NativeExecutionDispatch + 'static,
|
||||||
|
{
|
||||||
|
let best_block = select_chain.best_chain()?;
|
||||||
|
|
||||||
|
let mut leaves = select_chain
|
||||||
|
.leaves()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|hash| {
|
||||||
|
let number = client.number(hash).ok()??;
|
||||||
|
|
||||||
|
// Only consider leaves that are in maximum an uncle of the best block.
|
||||||
|
if number < best_block.number().saturating_sub(1) {
|
||||||
|
return None
|
||||||
|
} else if hash == best_block.hash() {
|
||||||
|
return None
|
||||||
|
};
|
||||||
|
|
||||||
|
let parent_hash = client.header(&BlockId::Hash(hash)).ok()??.parent_hash;
|
||||||
|
|
||||||
|
Some(BlockInfo {
|
||||||
|
hash,
|
||||||
|
parent_hash,
|
||||||
|
number,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
// Sort by block number and get the maximum number of leaves
|
||||||
|
leaves.sort_by_key(|b| b.number);
|
||||||
|
|
||||||
|
leaves.push(BlockInfo {
|
||||||
|
hash: best_block.hash(),
|
||||||
|
parent_hash: *best_block.parent_hash(),
|
||||||
|
number: *best_block.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(leaves.into_iter().rev().take(MAX_ACTIVE_LEAVES).collect())
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new full node of arbitrary runtime and executor.
|
/// Create a new full node of arbitrary runtime and executor.
|
||||||
///
|
///
|
||||||
/// This is an advanced feature and not recommended for general use. Generally, `build_full` is
|
/// This is an advanced feature and not recommended for general use. Generally, `build_full` is
|
||||||
@@ -769,21 +822,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
|||||||
|
|
||||||
let overseer_client = client.clone();
|
let overseer_client = client.clone();
|
||||||
let spawner = task_manager.spawn_handle();
|
let spawner = task_manager.spawn_handle();
|
||||||
let leaves: Vec<_> = select_chain.clone()
|
let active_leaves = active_leaves(&select_chain, &*client)?;
|
||||||
.leaves()
|
|
||||||
.unwrap_or_else(|_| vec![])
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|hash| {
|
|
||||||
let number = client.number(hash).ok()??;
|
|
||||||
let parent_hash = client.header(&BlockId::Hash(hash)).ok()??.parent_hash;
|
|
||||||
|
|
||||||
Some(BlockInfo {
|
|
||||||
hash,
|
|
||||||
parent_hash,
|
|
||||||
number,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let authority_discovery_service = if role.is_authority() || is_collator.is_collator() {
|
let authority_discovery_service = if role.is_authority() || is_collator.is_collator() {
|
||||||
use sc_network::Event;
|
use sc_network::Event;
|
||||||
@@ -828,7 +867,7 @@ pub fn new_full<RuntimeApi, Executor>(
|
|||||||
|
|
||||||
let overseer_handler = if let Some((authority_discovery_service, keystore)) = maybe_params {
|
let overseer_handler = if let Some((authority_discovery_service, keystore)) = maybe_params {
|
||||||
let (overseer, overseer_handler) = real_overseer(
|
let (overseer, overseer_handler) = real_overseer(
|
||||||
leaves,
|
active_leaves,
|
||||||
keystore,
|
keystore,
|
||||||
overseer_client.clone(),
|
overseer_client.clone(),
|
||||||
availability_config,
|
availability_config,
|
||||||
|
|||||||
Reference in New Issue
Block a user