Kitchensink chain: Add BEEFY support (#2856)

Related to https://github.com/paritytech/polkadot-sdk/issues/2787

Adding BEEFY support to the kitchensink chain in order to be able to
extend the current warp sync zombienet tests with BEEFY enabled
This commit is contained in:
Serban Iorga
2024-01-06 12:18:38 +01:00
committed by GitHub
parent 930c151928
commit 2e4b8996c4
14 changed files with 320 additions and 93 deletions
+128 -39
View File
@@ -63,6 +63,8 @@ type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
type FullGrandpaBlockImport =
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
type FullBeefyBlockImport<InnerBlockImport> =
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport>;
/// The transaction pool type definition.
pub type TransactionPool = sc_transaction_pool::FullPool<Block, FullClient>;
@@ -165,9 +167,14 @@ pub fn new_partial(
sc_rpc::SubscriptionTaskExecutor,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>,
(
sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
sc_consensus_babe::BabeBlockImport<
Block,
FullClient,
FullBeefyBlockImport<FullGrandpaBlockImport>,
>,
grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
sc_consensus_babe::BabeLink<Block>,
beefy::BeefyVoterLinks<Block>,
),
grandpa::SharedVoterState,
Option<Telemetry>,
@@ -222,9 +229,17 @@ pub fn new_partial(
)?;
let justification_import = grandpa_block_import.clone();
let (beefy_block_import, beefy_voter_links, beefy_rpc_links) =
beefy::beefy_block_import_and_links(
grandpa_block_import,
backend.clone(),
client.clone(),
config.prometheus_registry().cloned(),
);
let (block_import, babe_link) = sc_consensus_babe::block_import(
sc_consensus_babe::configuration(&*client)?,
grandpa_block_import,
beefy_block_import,
client.clone(),
)?;
@@ -253,7 +268,7 @@ pub fn new_partial(
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()),
})?;
let import_setup = (block_import, grandpa_link, babe_link);
let import_setup = (block_import, grandpa_link, babe_link, beefy_voter_links);
let statement_store = sc_statement_store::Store::new_shared(
&config.data_path,
@@ -268,7 +283,7 @@ pub fn new_partial(
let (mixnet_api, mixnet_api_backend) = mixnet_config.map(sc_mixnet::Api::new).unzip();
let (rpc_extensions_builder, rpc_setup) = {
let (_, grandpa_link, _) = &import_setup;
let (_, grandpa_link, _, _) = &import_setup;
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
@@ -288,31 +303,41 @@ pub fn new_partial(
let rpc_backend = backend.clone();
let rpc_statement_store = statement_store.clone();
let rpc_extensions_builder = move |deny_unsafe, subscription_executor| {
let deps = node_rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
select_chain: select_chain.clone(),
chain_spec: chain_spec.cloned_box(),
deny_unsafe,
babe: node_rpc::BabeDeps {
keystore: keystore.clone(),
babe_worker_handle: babe_worker_handle.clone(),
},
grandpa: node_rpc::GrandpaDeps {
shared_voter_state: shared_voter_state.clone(),
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor,
finality_provider: finality_proof_provider.clone(),
},
statement_store: rpc_statement_store.clone(),
backend: rpc_backend.clone(),
mixnet_api: mixnet_api.as_ref().cloned(),
};
let rpc_extensions_builder =
move |deny_unsafe, subscription_executor: node_rpc::SubscriptionTaskExecutor| {
let deps = node_rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
select_chain: select_chain.clone(),
chain_spec: chain_spec.cloned_box(),
deny_unsafe,
babe: node_rpc::BabeDeps {
keystore: keystore.clone(),
babe_worker_handle: babe_worker_handle.clone(),
},
grandpa: node_rpc::GrandpaDeps {
shared_voter_state: shared_voter_state.clone(),
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
beefy: node_rpc::BeefyDeps {
beefy_finality_proof_stream: beefy_rpc_links
.from_voter_justif_stream
.clone(),
beefy_best_block_stream: beefy_rpc_links
.from_voter_best_beefy_stream
.clone(),
subscription_executor,
},
statement_store: rpc_statement_store.clone(),
backend: rpc_backend.clone(),
mixnet_api: mixnet_api.as_ref().cloned(),
};
node_rpc::create_full(deps).map_err(Into::into)
};
node_rpc::create_full(deps).map_err(Into::into)
};
(rpc_extensions_builder, shared_voter_state2)
};
@@ -358,10 +383,24 @@ pub fn new_full_base(
mixnet_config: Option<sc_mixnet::Config>,
disable_hardware_benchmarks: bool,
with_startup_data: impl FnOnce(
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
&sc_consensus_babe::BabeBlockImport<
Block,
FullClient,
FullBeefyBlockImport<FullGrandpaBlockImport>,
>,
&sc_consensus_babe::BabeLink<Block>,
),
) -> Result<NewFullBase, ServiceError> {
let is_offchain_indexing_enabled = config.offchain_worker.indexing_enabled;
let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks =
Some(sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging::default());
let name = config.network.node_name.clone();
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();
let enable_offchain_worker = config.offchain_worker.enabled;
let hwbench = (!disable_hardware_benchmarks)
.then_some(config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
@@ -391,6 +430,24 @@ pub fn new_full_base(
grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone());
net_config.add_notification_protocol(grandpa_protocol_config);
let beefy_gossip_proto_name =
beefy::gossip_protocol_name(&genesis_hash, config.chain_spec.fork_id());
// `beefy_on_demand_justifications_handler` is given to `beefy-gadget` task to be run,
// while `beefy_req_resp_cfg` is added to `config.network.request_response_protocols`.
let (beefy_on_demand_justifications_handler, beefy_req_resp_cfg) =
beefy::communication::request_response::BeefyJustifsRequestHandler::new(
&genesis_hash,
config.chain_spec.fork_id(),
client.clone(),
prometheus_registry.clone(),
);
let (beefy_notification_config, beefy_notification_service) =
beefy::communication::beefy_peers_set_config(beefy_gossip_proto_name.clone());
net_config.add_notification_protocol(beefy_notification_config);
net_config.add_request_response_protocol(beefy_req_resp_cfg);
let (statement_handler_proto, statement_config) =
sc_network_statement::StatementHandlerPrototype::new(
genesis_hash,
@@ -442,15 +499,6 @@ pub fn new_full_base(
task_manager.spawn_handle().spawn("mixnet", None, mixnet);
}
let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks =
Some(sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging::default());
let name = config.network.node_name.clone();
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();
let enable_offchain_worker = config.offchain_worker.enabled;
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
config,
backend: backend.clone(),
@@ -488,7 +536,7 @@ pub fn new_full_base(
}
}
let (block_import, grandpa_link, babe_link) = import_setup;
let (block_import, grandpa_link, babe_link, beefy_links) = import_setup;
(with_startup_data)(&block_import, &babe_link);
@@ -582,6 +630,47 @@ pub fn new_full_base(
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() { Some(keystore_container.keystore()) } else { None };
// beefy is enabled if its notification service exists
let network_params = beefy::BeefyNetworkParams {
network: network.clone(),
sync: sync_service.clone(),
gossip_protocol_name: beefy_gossip_proto_name,
justifications_protocol_name: beefy_on_demand_justifications_handler.protocol_name(),
notification_service: beefy_notification_service,
_phantom: core::marker::PhantomData::<Block>,
};
let beefy_params = beefy::BeefyParams {
client: client.clone(),
backend: backend.clone(),
payload_provider: beefy_primitives::mmr::MmrRootProvider::new(client.clone()),
runtime: client.clone(),
key_store: keystore.clone(),
network_params,
min_block_delta: 8,
prometheus_registry: prometheus_registry.clone(),
links: beefy_links,
on_demand_justifications_handler: beefy_on_demand_justifications_handler,
};
let beefy_gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);
// BEEFY is part of consensus, if it fails we'll bring the node down with it to make sure it
// is noticed.
task_manager
.spawn_essential_handle()
.spawn_blocking("beefy-gadget", None, beefy_gadget);
// When offchain indexing is enabled, MMR gadget should also run.
if is_offchain_indexing_enabled {
task_manager.spawn_essential_handle().spawn_blocking(
"mmr-gadget",
None,
mmr_gadget::MmrGadget::start(
client.clone(),
backend.clone(),
sp_mmr_primitives::INDEXING_PREFIX.to_vec(),
),
);
}
let grandpa_config = grandpa::Config {
// FIXME #1578 make this available through chainspec
gossip_duration: std::time::Duration::from_millis(333),