mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 02:21:04 +00:00
Make BlockImport and Verifier async (#8472)
* Make grandpa work * Introduce `SharedData` * Add test and fix bugs * Switch to `SharedData` * Make grandpa tests working * More Babe work * Make it async * Fix fix * Use `async_trait` in sc-consensus-slots This makes the code a little bit easier to read and also expresses that there can always only be one call at a time to `on_slot`. * Make grandpa tests compile * More Babe tests work * Fix network test * Start fixing service test * Finish service-test * Fix sc-consensus-aura * Fix fix fix * More fixes * Make everything compile *yeah* * Fix build when we have Rust 1.51 * Update client/consensus/common/src/shared_data.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/common/src/shared_data.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/common/src/shared_data.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/common/src/shared_data.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/common/src/shared_data.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/babe/src/tests.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/babe/src/tests.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Fix warning Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -23,6 +23,7 @@ parking_lot = "0.11.1"
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0" }
|
||||
serde = { version = "1.0", features=["derive"] }
|
||||
assert_matches = "1.3.0"
|
||||
async-trait = "0.1.42"
|
||||
|
||||
sc-client-api = { path = "../../api", version = "3.0.0"}
|
||||
sc-consensus-babe = { path = "../../consensus/babe", version = "0.9.0"}
|
||||
|
||||
@@ -21,12 +21,7 @@
|
||||
use super::ConsensusDataProvider;
|
||||
use crate::Error;
|
||||
use codec::Encode;
|
||||
use std::{
|
||||
any::Any,
|
||||
borrow::Cow,
|
||||
sync::{Arc, atomic},
|
||||
time::SystemTime,
|
||||
};
|
||||
use std::{borrow::Cow, sync::{Arc, atomic}, time::SystemTime};
|
||||
use sc_client_api::AuxStore;
|
||||
use sc_consensus_babe::{
|
||||
Config, Epoch, authorship, CompatibleDigestItem, BabeIntermediate,
|
||||
@@ -102,7 +97,7 @@ impl<B, C> BabeConsensusDataProvider<B, C>
|
||||
}
|
||||
|
||||
fn epoch(&self, parent: &B::Header, slot: Slot) -> Result<Epoch, Error> {
|
||||
let epoch_changes = self.epoch_changes.lock();
|
||||
let epoch_changes = self.epoch_changes.shared_data();
|
||||
let epoch_descriptor = epoch_changes
|
||||
.epoch_descriptor_for_child_of(
|
||||
descendent_query(&*self.client),
|
||||
@@ -156,7 +151,7 @@ impl<B, C> ConsensusDataProvider<B> for BabeConsensusDataProvider<B, C>
|
||||
authority_index: 0_u32,
|
||||
});
|
||||
|
||||
let mut epoch_changes = self.epoch_changes.lock();
|
||||
let mut epoch_changes = self.epoch_changes.shared_data();
|
||||
let epoch_descriptor = epoch_changes
|
||||
.epoch_descriptor_for_child_of(
|
||||
descendent_query(&*self.client),
|
||||
@@ -200,7 +195,7 @@ impl<B, C> ConsensusDataProvider<B> for BabeConsensusDataProvider<B, C>
|
||||
inherents: &InherentData
|
||||
) -> Result<(), Error> {
|
||||
let slot = inherents.babe_inherent_data()?;
|
||||
let epoch_changes = self.epoch_changes.lock();
|
||||
let epoch_changes = self.epoch_changes.shared_data();
|
||||
let mut epoch_descriptor = epoch_changes
|
||||
.epoch_descriptor_for_child_of(
|
||||
descendent_query(&*self.client),
|
||||
@@ -239,7 +234,7 @@ impl<B, C> ConsensusDataProvider<B> for BabeConsensusDataProvider<B, C>
|
||||
|
||||
params.intermediates.insert(
|
||||
Cow::from(INTERMEDIATE_KEY),
|
||||
Box::new(BabeIntermediate::<B> { epoch_descriptor }) as Box<dyn Any>,
|
||||
Box::new(BabeIntermediate::<B> { epoch_descriptor }) as Box<_>,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -55,8 +55,9 @@ pub const MANUAL_SEAL_ENGINE_ID: ConsensusEngineId = [b'm', b'a', b'n', b'l'];
|
||||
/// The verifier for the manual seal engine; instantly finalizes.
|
||||
struct ManualSealVerifier;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<B: BlockT> Verifier<B> for ManualSealVerifier {
|
||||
fn verify(
|
||||
async fn verify(
|
||||
&mut self,
|
||||
origin: BlockOrigin,
|
||||
header: B::Header,
|
||||
|
||||
@@ -144,7 +144,7 @@ pub async fn seal_block<B, BI, SC, C, E, P>(
|
||||
digest_provider.append_block_import(&parent, &mut params, &id)?;
|
||||
}
|
||||
|
||||
match block_import.import_block(params, HashMap::new())? {
|
||||
match block_import.import_block(params, HashMap::new()).await? {
|
||||
ImportResult::Imported(aux) => {
|
||||
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&header), aux })
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user