polkadot_omni_node_lib/common/
statement_store.rs1use crate::common::{types::ParachainClient, ConstructNodeRuntimeApi, NodeBlock};
18use parachains_common::Hash;
19use sc_network::{
20 config::FullNetworkConfiguration, service::traits::NetworkService, NetworkBackend,
21};
22use sc_service::{Configuration, TaskManager};
23use sc_statement_store::Store;
24use std::sync::Arc;
25
26pub(crate) fn new_statement_handler_proto<
34 Block: NodeBlock,
35 RuntimeApi,
36 Net: NetworkBackend<Block, Hash>,
37>(
38 client: &ParachainClient<Block, RuntimeApi>,
39 parachain_config: &Configuration,
40 metrics: &sc_network::NotificationMetrics,
41 net_config: &mut FullNetworkConfiguration<Block, Hash, Net>,
42) -> sc_network_statement::StatementHandlerPrototype {
43 let (statement_handler_proto, statement_config) =
44 sc_network_statement::StatementHandlerPrototype::new::<_, _, Net>(
45 client.chain_info().genesis_hash,
46 parachain_config.chain_spec.fork_id(),
47 metrics.clone(),
48 Arc::clone(&net_config.peer_store_handle()),
49 );
50 net_config.add_notification_protocol(statement_config);
51 statement_handler_proto
52}
53
54pub(crate) fn build_statement_store<
56 Block: NodeBlock,
57 RuntimeApi: ConstructNodeRuntimeApi<Block, ParachainClient<Block, RuntimeApi>>,
58>(
59 parachain_config: &Configuration,
60 task_manager: &mut TaskManager,
61 client: Arc<ParachainClient<Block, RuntimeApi>>,
62 network: Arc<dyn NetworkService + 'static>,
63 sync_service: Arc<sc_network_sync::service::syncing_service::SyncingService<Block>>,
64 local_keystore: Arc<sc_keystore::LocalKeystore>,
65 statement_handler_proto: sc_network_statement::StatementHandlerPrototype,
66) -> sc_service::error::Result<Arc<Store>> {
67 let statement_store = sc_statement_store::Store::new_shared(
68 ¶chain_config.data_path,
69 Default::default(),
70 client,
71 local_keystore,
72 parachain_config.prometheus_registry(),
73 &task_manager.spawn_handle(),
74 )
75 .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;
76 let statement_protocol_executor = {
77 let spawn_handle = task_manager.spawn_handle();
78 Box::new(move |fut| {
79 spawn_handle.spawn("network-statement-validator", Some("networking"), fut);
80 })
81 };
82 let statement_handler = statement_handler_proto.build(
83 network,
84 sync_service,
85 statement_store.clone(),
86 parachain_config.prometheus_registry(),
87 statement_protocol_executor,
88 )?;
89 task_manager.spawn_handle().spawn(
90 "network-statement-handler",
91 Some("networking"),
92 statement_handler.run(),
93 );
94
95 Ok(statement_store)
96}