Refactoring: Remove ExtraVerification in the import queue (#2844)

* Remove ExtraVerification in the import queue

* Fix Babe

* Fix node-template
This commit is contained in:
Pierre Krieger
2019-06-12 14:56:31 +02:00
committed by Robert Habermeier
parent 3496f11404
commit ce302390dd
5 changed files with 18 additions and 84 deletions
+7 -32
View File
@@ -68,7 +68,7 @@ use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS
use slots::{CheckedHeader, SlotData, SlotWorker, SlotInfo, SlotCompatible, slot_now, check_equivocation};
pub use aura_primitives::*;
pub use consensus_common::{SyncOracle, ExtraVerification};
pub use consensus_common::SyncOracle;
pub use digest::CompatibleDigestItem;
mod digest;
@@ -446,14 +446,13 @@ fn check_header<C, B: Block, P: Pair>(
}
/// A verifier for Aura blocks.
pub struct AuraVerifier<C, E, P> {
pub struct AuraVerifier<C, P> {
client: Arc<C>,
extra: E,
phantom: PhantomData<P>,
inherent_data_providers: inherents::InherentDataProviders,
}
impl<C, E, P> AuraVerifier<C, E, P>
impl<C, P> AuraVerifier<C, P>
where P: Send + Sync + 'static
{
fn check_inherents<B: Block>(
@@ -505,24 +504,11 @@ impl<C, E, P> AuraVerifier<C, E, P>
}
}
/// No-op extra verification.
#[derive(Debug, Clone, Copy)]
pub struct NothingExtra;
impl<B: Block> ExtraVerification<B> for NothingExtra {
type Verified = Result<(), String>;
fn verify(&self, _: &B::Header, _: Option<&[B::Extrinsic]>) -> Self::Verified {
Ok(())
}
}
#[forbid(deprecated)]
impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where
impl<B: Block, C, P> Verifier<B> for AuraVerifier<C, P> where
C: ProvideRuntimeApi + Send + Sync + client::backend::AuxStore,
C::Api: BlockBuilderApi<B>,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
E: ExtraVerification<B>,
P: Pair + Send + Sync + 'static,
P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + AsRef<P::Public> + 'static,
P::Signature: Encode + Decode,
@@ -543,11 +529,6 @@ impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where
let authorities = self.authorities(&BlockId::Hash(parent_hash))
.map_err(|e| format!("Could not fetch authorities at {:?}: {:?}", parent_hash, e))?;
let extra_verification = self.extra.verify(
&header,
body.as_ref().map(|x| &x[..]),
);
// we add one to allow for some small drift.
// FIXME #1019 in the future, alter this queue to allow deferring of
// headers
@@ -588,8 +569,6 @@ impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where
trace!(target: "aura", "Checked {:?}; importing.", pre_header);
telemetry!(CONSENSUS_TRACE; "aura.checked_and_importing"; "pre_header" => ?pre_header);
extra_verification.into_future().wait()?;
let new_authorities = pre_header.digest()
.log(DigestItem::as_authorities_change)
.map(|digest| digest.to_vec());
@@ -618,7 +597,7 @@ impl<B: Block, C, E, P> Verifier<B> for AuraVerifier<C, E, P> where
}
}
impl<B, C, E, P> Authorities<B> for AuraVerifier<C, E, P> where
impl<B, C, P> Authorities<B> for AuraVerifier<C, P> where
B: Block,
C: ProvideRuntimeApi + ProvideCache<B>,
C::Api: AuthoritiesApi<B>,
@@ -697,21 +676,19 @@ fn register_aura_inherent_data_provider(
}
/// Start an import queue for the Aura consensus algorithm.
pub fn import_queue<B, C, E, P>(
pub fn import_queue<B, C, P>(
slot_duration: SlotDuration,
block_import: SharedBlockImport<B>,
justification_import: Option<SharedJustificationImport<B>>,
finality_proof_import: Option<SharedFinalityProofImport<B>>,
finality_proof_request_builder: Option<SharedFinalityProofRequestBuilder<B>>,
client: Arc<C>,
extra: E,
inherent_data_providers: InherentDataProviders,
) -> Result<AuraImportQueue<B>, consensus_common::Error> where
B: Block,
C: 'static + ProvideRuntimeApi + ProvideCache<B> + Send + Sync + AuxStore,
C::Api: BlockBuilderApi<B> + AuthoritiesApi<B>,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
E: 'static + ExtraVerification<B>,
P: Pair + Send + Sync + 'static,
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode + AsRef<P::Public>,
P::Signature: Encode + Decode,
@@ -722,7 +699,6 @@ pub fn import_queue<B, C, E, P>(
let verifier = Arc::new(
AuraVerifier {
client: client.clone(),
extra,
inherent_data_providers,
phantom: PhantomData,
}
@@ -794,7 +770,7 @@ mod tests {
impl TestNetFactory for AuraTestNet {
type Specialization = DummySpecialization;
type Verifier = AuraVerifier<PeersFullClient, NothingExtra, sr25519::Pair>;
type Verifier = AuraVerifier<PeersFullClient, sr25519::Pair>;
type PeerData = ();
/// Create new test network with peers and given config.
@@ -821,7 +797,6 @@ mod tests {
assert_eq!(slot_duration.get(), SLOT_DURATION);
Arc::new(AuraVerifier {
client,
extra: NothingExtra,
inherent_data_providers,
phantom: Default::default(),
})