Companion for Substrate#10568 - Add new BEEFY RPC (#4638)

* support best Beefy RPC through arc<mutex>

* beefy RPC through lockless message passing - wip

Not working because channel can't be simply opened and receiver passed
to `rpc_extensions_builder` because `rpc_extensions_builder` has to be
`Fn` and not `FnOnce`... and and Receiver side of mpsc can't be cloned

yay!..

* beefy RPC through lockless message passing

* beefy: use specialized type definitions

* bubble up service errors from BEEFY RPC

* update lockfile for substrate

Co-authored-by: parity-processbot <>
This commit is contained in:
Adrian Catangiu
2022-01-06 16:33:50 +02:00
committed by GitHub
parent 041543882b
commit 5cc5b674f9
3 changed files with 193 additions and 179 deletions
+169 -164
View File
File diff suppressed because it is too large Load Diff
+14 -8
View File
@@ -34,6 +34,7 @@ mod tests;
#[cfg(feature = "full-node")]
use {
beefy_gadget::notification::{BeefyBestBlockSender, BeefySignedCommitmentSender},
grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider},
polkadot_node_core_approval_voting::Config as ApprovalVotingConfig,
polkadot_node_core_av_store::Config as AvailabilityConfig,
@@ -414,7 +415,7 @@ fn new_partial<RuntimeApi, ExecutorDispatch, ChainSelection>(
>,
grandpa::LinkHalf<Block, FullClient<RuntimeApi, ExecutorDispatch>, ChainSelection>,
babe::BabeLink<Block>,
beefy_gadget::notification::BeefySignedCommitmentSender<Block>,
(BeefySignedCommitmentSender<Block>, BeefyBestBlockSender<Block>),
),
grandpa::SharedVoterState,
std::time::Duration, // slot-duration
@@ -485,8 +486,11 @@ where
telemetry.as_ref().map(|x| x.handle()),
)?;
let (beefy_link, beefy_commitment_stream) =
beefy_gadget::notification::BeefySignedCommitmentStream::channel();
let (beefy_commitment_link, beefy_commitment_stream) =
beefy_gadget::notification::BeefySignedCommitmentStream::<Block>::channel();
let (beefy_best_block_link, beefy_best_block_stream) =
beefy_gadget::notification::BeefyBestBlockStream::<Block>::channel();
let beefy_links = (beefy_commitment_link, beefy_best_block_link);
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
@@ -496,12 +500,12 @@ where
Some(shared_authority_set.clone()),
);
let import_setup = (block_import.clone(), grandpa_link, babe_link.clone(), beefy_link);
let rpc_setup = shared_voter_state.clone();
let shared_epoch_changes = babe_link.epoch_changes().clone();
let slot_duration = babe_config.slot_duration();
let import_setup = (block_import, grandpa_link, babe_link, beefy_links);
let rpc_setup = shared_voter_state.clone();
let rpc_extensions_builder = {
let client = client.clone();
let keystore = keystore_container.sync_keystore();
@@ -532,6 +536,7 @@ where
},
beefy: polkadot_rpc::BeefyDeps {
beefy_commitment_stream: beefy_commitment_stream.clone(),
beefy_best_block_stream: beefy_best_block_stream.clone(),
subscription_executor,
},
};
@@ -893,7 +898,7 @@ where
telemetry: telemetry.as_mut(),
})?;
let (block_import, link_half, babe_link, beefy_link) = import_setup;
let (block_import, link_half, babe_link, beefy_links) = import_setup;
let overseer_client = client.clone();
let spawner = task_manager.spawn_handle();
@@ -1091,7 +1096,8 @@ where
backend: backend.clone(),
key_store: keystore_opt.clone(),
network: network.clone(),
signed_commitment_sender: beefy_link,
signed_commitment_sender: beefy_links.0,
beefy_best_block_sender: beefy_links.1,
min_block_delta: if chain_spec.is_wococo() { 4 } else { 8 },
prometheus_registry: prometheus_registry.clone(),
protocol_name: beefy_protocol_name,
+10 -7
View File
@@ -61,10 +61,13 @@ pub struct GrandpaDeps<B> {
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
}
use beefy_gadget::notification::{BeefyBestBlockStream, BeefySignedCommitmentStream};
/// Dependencies for BEEFY
pub struct BeefyDeps {
/// Receives notifications about signed commitment events from BEEFY.
pub beefy_commitment_stream: beefy_gadget::notification::BeefySignedCommitmentStream<Block>,
pub beefy_commitment_stream: BeefySignedCommitmentStream<Block>,
/// Receives notifications about best block events from BEEFY.
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
/// Executor to drive the subscription manager in the BEEFY RPC handler.
pub subscription_executor: sc_rpc::SubscriptionTaskExecutor,
}
@@ -155,12 +158,12 @@ where
deny_unsafe,
)?));
io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate(
beefy_gadget_rpc::BeefyRpcHandler::new(
beefy.beefy_commitment_stream,
beefy.subscription_executor,
),
));
let handler: beefy_gadget_rpc::BeefyRpcHandler<Block> = beefy_gadget_rpc::BeefyRpcHandler::new(
beefy.beefy_commitment_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
)?;
io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate(handler));
Ok(io)
}