mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
babe, aura, pow: only call check_inherents if authoring version is compatible (#6862)
* pow: check can_author_with before calling check_inherents * babe: check can_author_with before calling check_inherents * aura: check can_author_with before calling check_inherents * Fix node and node template compile * Add missing comma * Put each parameter on its own line * Add debug print * Fix line width too long * Fix pow line width issue
This commit is contained in:
@@ -787,22 +787,24 @@ impl<Block: BlockT> BabeLink<Block> {
|
||||
}
|
||||
|
||||
/// A verifier for Babe blocks.
|
||||
pub struct BabeVerifier<Block: BlockT, Client, SelectChain> {
|
||||
pub struct BabeVerifier<Block: BlockT, Client, SelectChain, CAW> {
|
||||
client: Arc<Client>,
|
||||
select_chain: SelectChain,
|
||||
inherent_data_providers: sp_inherents::InherentDataProviders,
|
||||
config: Config,
|
||||
epoch_changes: SharedEpochChanges<Block, Epoch>,
|
||||
time_source: TimeSource,
|
||||
can_author_with: CAW,
|
||||
}
|
||||
|
||||
impl<Block, Client, SelectChain> BabeVerifier<Block, Client, SelectChain>
|
||||
impl<Block, Client, SelectChain, CAW> BabeVerifier<Block, Client, SelectChain, CAW>
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: AuxStore + HeaderBackend<Block> + HeaderMetadata<Block> + ProvideRuntimeApi<Block>,
|
||||
Client::Api: BlockBuilderApi<Block, Error = sp_blockchain::Error>
|
||||
+ BabeApi<Block, Error = sp_blockchain::Error>,
|
||||
SelectChain: sp_consensus::SelectChain<Block>,
|
||||
CAW: CanAuthorWith<Block>,
|
||||
{
|
||||
fn check_inherents(
|
||||
&self,
|
||||
@@ -810,6 +812,16 @@ where
|
||||
block_id: BlockId<Block>,
|
||||
inherent_data: InherentData,
|
||||
) -> Result<(), Error<Block>> {
|
||||
if let Err(e) = self.can_author_with.can_author_with(&block_id) {
|
||||
debug!(
|
||||
target: "babe",
|
||||
"Skipping `check_inherents` as authoring version is not compatible: {}",
|
||||
e,
|
||||
);
|
||||
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let inherent_res = self.client.runtime_api().check_inherents(
|
||||
&block_id,
|
||||
block,
|
||||
@@ -908,13 +920,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, Client, SelectChain> Verifier<Block> for BabeVerifier<Block, Client, SelectChain>
|
||||
impl<Block, Client, SelectChain, CAW> Verifier<Block>
|
||||
for BabeVerifier<Block, Client, SelectChain, CAW>
|
||||
where
|
||||
Block: BlockT,
|
||||
Client: HeaderMetadata<Block, Error = sp_blockchain::Error> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||
+ Send + Sync + AuxStore + ProvideCache<Block>,
|
||||
Client::Api: BlockBuilderApi<Block, Error = sp_blockchain::Error> + BabeApi<Block, Error = sp_blockchain::Error>,
|
||||
SelectChain: sp_consensus::SelectChain<Block>,
|
||||
CAW: CanAuthorWith<Block> + Send + Sync,
|
||||
{
|
||||
fn verify(
|
||||
&mut self,
|
||||
@@ -1422,7 +1436,7 @@ pub fn block_import<Client, Block: BlockT, I>(
|
||||
///
|
||||
/// The block import object provided must be the `BabeBlockImport` or a wrapper
|
||||
/// of it, otherwise crucial import logic will be omitted.
|
||||
pub fn import_queue<Block: BlockT, Client, SelectChain, Inner>(
|
||||
pub fn import_queue<Block: BlockT, Client, SelectChain, Inner, CAW>(
|
||||
babe_link: BabeLink<Block>,
|
||||
block_import: Inner,
|
||||
justification_import: Option<BoxJustificationImport<Block>>,
|
||||
@@ -1432,6 +1446,7 @@ pub fn import_queue<Block: BlockT, Client, SelectChain, Inner>(
|
||||
inherent_data_providers: InherentDataProviders,
|
||||
spawner: &impl sp_core::traits::SpawnNamed,
|
||||
registry: Option<&Registry>,
|
||||
can_author_with: CAW,
|
||||
) -> ClientResult<DefaultImportQueue<Block, Client>> where
|
||||
Inner: BlockImport<Block, Error = ConsensusError, Transaction = sp_api::TransactionFor<Client, Block>>
|
||||
+ Send + Sync + 'static,
|
||||
@@ -1439,6 +1454,7 @@ pub fn import_queue<Block: BlockT, Client, SelectChain, Inner>(
|
||||
Client: HeaderBackend<Block> + HeaderMetadata<Block, Error = sp_blockchain::Error>,
|
||||
Client::Api: BlockBuilderApi<Block> + BabeApi<Block> + ApiExt<Block, Error = sp_blockchain::Error>,
|
||||
SelectChain: sp_consensus::SelectChain<Block> + 'static,
|
||||
CAW: CanAuthorWith<Block> + Send + Sync + 'static,
|
||||
{
|
||||
register_babe_inherent_data_provider(&inherent_data_providers, babe_link.config.slot_duration)?;
|
||||
|
||||
@@ -1449,6 +1465,7 @@ pub fn import_queue<Block: BlockT, Client, SelectChain, Inner>(
|
||||
config: babe_link.config,
|
||||
epoch_changes: babe_link.epoch_changes,
|
||||
time_source: babe_link.time_source,
|
||||
can_author_with,
|
||||
};
|
||||
|
||||
Ok(BasicQueue::new(
|
||||
|
||||
@@ -31,7 +31,7 @@ use sp_consensus_babe::{
|
||||
};
|
||||
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
|
||||
use sp_consensus::{
|
||||
NoNetwork as DummyOracle, Proposal, RecordProof,
|
||||
NoNetwork as DummyOracle, Proposal, RecordProof, AlwaysCanAuthor,
|
||||
import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport},
|
||||
};
|
||||
use sc_network_test::*;
|
||||
@@ -220,7 +220,7 @@ type TestSelectChain = substrate_test_runtime_client::LongestChain<
|
||||
>;
|
||||
|
||||
pub struct TestVerifier {
|
||||
inner: BabeVerifier<TestBlock, PeersFullClient, TestSelectChain>,
|
||||
inner: BabeVerifier<TestBlock, PeersFullClient, TestSelectChain, AlwaysCanAuthor>,
|
||||
mutator: Mutator,
|
||||
}
|
||||
|
||||
@@ -320,6 +320,7 @@ impl TestNetFactory for BabeTestNet {
|
||||
config: data.link.config.clone(),
|
||||
epoch_changes: data.link.epoch_changes.clone(),
|
||||
time_source: data.link.time_source.clone(),
|
||||
can_author_with: AlwaysCanAuthor,
|
||||
},
|
||||
mutator: MUTATOR.with(|m| m.borrow().clone()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user