mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 18:27:56 +00:00
Expose MMR root through runtime API - use it in BEEFY client (#11183)
* beefy-gadget: allow custom runtime api provider * beefy-gadget: use mock runtime api in tests * pallet-mmr: expose mmr root from state through runtime API * beefy-gadget: get mmr root from runtime state * pallet-beefy-mmr: remove MmrRoot from header digests * frame/mmr: move mmr primitives out of frame * frame/mmr: completely move primitives out of frame * address review comments * beefy-mmr: bring back mmr root from header digest * clippy fixes for rustc 1.60 * address review comments
This commit is contained in:
@@ -27,9 +27,10 @@ use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::SyncOracle;
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
use sp_mmr_primitives::MmrApi;
|
||||
use sp_runtime::traits::Block;
|
||||
|
||||
use beefy_primitives::BeefyApi;
|
||||
use beefy_primitives::{BeefyApi, MmrRootHash};
|
||||
|
||||
use crate::notification::{BeefyBestBlockSender, BeefySignedCommitmentSender};
|
||||
|
||||
@@ -87,7 +88,7 @@ pub fn beefy_peers_set_config(
|
||||
/// of today, Rust does not allow a type alias to be used as a trait bound. Tracking
|
||||
/// issue is <https://github.com/rust-lang/rust/issues/41517>.
|
||||
pub trait Client<B, BE>:
|
||||
BlockchainEvents<B> + HeaderBackend<B> + Finalizer<B, BE> + ProvideRuntimeApi<B> + Send + Sync
|
||||
BlockchainEvents<B> + HeaderBackend<B> + Finalizer<B, BE> + Send + Sync
|
||||
where
|
||||
B: Block,
|
||||
BE: Backend<B>,
|
||||
@@ -110,18 +111,21 @@ where
|
||||
}
|
||||
|
||||
/// BEEFY gadget initialization parameters.
|
||||
pub struct BeefyParams<B, BE, C, N>
|
||||
pub struct BeefyParams<B, BE, C, N, R>
|
||||
where
|
||||
B: Block,
|
||||
BE: Backend<B>,
|
||||
C: Client<B, BE>,
|
||||
C::Api: BeefyApi<B>,
|
||||
R: ProvideRuntimeApi<B>,
|
||||
R::Api: BeefyApi<B> + MmrApi<B, MmrRootHash>,
|
||||
N: GossipNetwork<B> + Clone + SyncOracle + Send + Sync + 'static,
|
||||
{
|
||||
/// BEEFY client
|
||||
pub client: Arc<C>,
|
||||
/// Client Backend
|
||||
pub backend: Arc<BE>,
|
||||
/// Runtime Api Provider
|
||||
pub runtime: Arc<R>,
|
||||
/// Local key store
|
||||
pub key_store: Option<SyncCryptoStorePtr>,
|
||||
/// Gossip network
|
||||
@@ -138,21 +142,22 @@ where
|
||||
pub protocol_name: std::borrow::Cow<'static, str>,
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
/// Start the BEEFY gadget.
|
||||
///
|
||||
/// This is a thin shim around running and awaiting a BEEFY worker.
|
||||
pub async fn start_beefy_gadget<B, BE, C, N>(beefy_params: BeefyParams<B, BE, C, N>)
|
||||
pub async fn start_beefy_gadget<B, BE, C, N, R>(beefy_params: BeefyParams<B, BE, C, N, R>)
|
||||
where
|
||||
B: Block,
|
||||
BE: Backend<B>,
|
||||
C: Client<B, BE>,
|
||||
C::Api: BeefyApi<B>,
|
||||
R: ProvideRuntimeApi<B>,
|
||||
R::Api: BeefyApi<B> + MmrApi<B, MmrRootHash>,
|
||||
N: GossipNetwork<B> + Clone + SyncOracle + Send + Sync + 'static,
|
||||
{
|
||||
let BeefyParams {
|
||||
client,
|
||||
backend,
|
||||
runtime,
|
||||
key_store,
|
||||
network,
|
||||
signed_commitment_sender,
|
||||
@@ -188,6 +193,7 @@ where
|
||||
let worker_params = worker::WorkerParams {
|
||||
client,
|
||||
backend,
|
||||
runtime,
|
||||
key_store: key_store.into(),
|
||||
signed_commitment_sender,
|
||||
beefy_best_block_sender,
|
||||
@@ -198,7 +204,7 @@ where
|
||||
sync_oracle,
|
||||
};
|
||||
|
||||
let worker = worker::BeefyWorker::<_, _, _, _>::new(worker_params);
|
||||
let worker = worker::BeefyWorker::<_, _, _, _, _>::new(worker_params);
|
||||
|
||||
worker.run().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user