Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9ebf20c
check inherents in import_block
sistemd May 20, 2025
4431bb1
empty prdoc
sistemd May 20, 2025
0f9533b
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] May 20, 2025
e3e5846
fix clippies
sistemd May 20, 2025
dc09e64
toml formatting
sistemd May 20, 2025
610fd40
update test
sistemd May 20, 2025
09a0896
fix semver
sistemd May 20, 2025
73a9b0a
remove .vim
sistemd May 21, 2025
4eb7197
use Arc instead of custom CreateInherentDataProvider impls
sistemd May 22, 2025
cc36b4a
remove CheckForEquivocation
sistemd May 23, 2025
eb14482
typedefs
sistemd May 23, 2025
8966cbf
remove redundant type parameter
sistemd May 23, 2025
484579a
improvements and oversights
sistemd May 27, 2025
ea74fa2
Merge remote-tracking branch 'origin/master' into sistemd/check-inher…
sistemd May 27, 2025
9bc4f69
improve logs
sistemd May 30, 2025
d59dc15
Merge remote-tracking branch 'origin/master' into sistemd/check-inher…
sistemd May 30, 2025
f9c046a
fix
sistemd May 30, 2025
fc83d6b
remove ValidatingBlockImport
sistemd Jun 2, 2025
d3f0bc7
remove outdated comment
sistemd Jun 6, 2025
a171009
remove unneeded BlockBuilder trait
sistemd Jun 6, 2025
2130887
remove unnecessary InherentDataProviderExt constraint
sistemd Jun 6, 2025
4e9a465
use simple callback for AuraVerifier instead of CIDP
sistemd Jun 6, 2025
ab5abde
Merge remote-tracking branch 'origin/master' into sistemd/check-inher…
sistemd Jun 6, 2025
c1c9e97
fix compiler errors
sistemd Jun 6, 2025
40fd334
update prdoc
sistemd Jun 6, 2025
ac54928
remove BlockBuilder constraint
sistemd Jun 9, 2025
b8b9b72
remove doc hidden
sistemd Jun 9, 2025
2d800c0
update prdoc
sistemd Jun 9, 2025
50c8e9c
remove unneeded constraints
sistemd Jun 11, 2025
81d7d39
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jun 11, 2025
8566346
fix warning
sistemd Jun 11, 2025
7a28d33
add AuraBlockImport for polkadot-omni-node
sistemd Jun 12, 2025
89642dc
Merge remote-tracking branch 'origin/master' into sistemd/check-inher…
sistemd Jun 12, 2025
6147815
fixing ci
sistemd Jun 13, 2025
07df2ee
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jun 13, 2025
55dcf7b
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jun 13, 2025
500d87a
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jun 24, 2025
171156c
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jun 25, 2025
4a77f23
remove some unneeded constraints
sistemd Jun 25, 2025
8aae9f1
move NaiveEquivocationDefender back into import queue
sistemd Jun 30, 2025
845db2b
move AuraBlockImport to substrate
sistemd Jun 30, 2025
ef58955
strict equivocation check in AuraBlockImport
sistemd Jun 30, 2025
f90501f
don't check equivocations in SlotBasedBlockImport
sistemd Jul 1, 2025
8a755d5
use fully_verifying_import_queue in cumulus-test-client
sistemd Jul 2, 2025
507f3b2
Merge remote-tracking branch 'origin/master' into sistemd/check-inher…
sistemd Jul 2, 2025
5779e08
fixing the build
sistemd Jul 2, 2025
78ab1cc
fix doc comment
sistemd Jul 2, 2025
b7e5656
remove ImportQueueParams
sistemd Jul 2, 2025
2721f74
Merge branch 'master' into sistemd/check-inherents-when-importing-block
sistemd Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ where
AuraApi<Block, P::Public> + CollectCollationInfo<Block> + AuraUnincludedSegmentApi<Block>,
Backend: sc_client_api::Backend<Block> + 'static,
RClient: RelayChainInterface + Clone + 'static,
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
CIDP: CreateInherentDataProviders<Block, ()> + Clone + 'static,
CIDP::InherentDataProviders: Send,
BI: BlockImport<Block> + ParachainBlockImportMarker + Send + Sync + 'static,
BI::Error: Into<sp_consensus::Error>,
Proposer: ProposerInterface<Block> + Send + Sync + 'static,
CS: CollatorServiceInterface<Block> + Send + Sync + 'static,
CHP: consensus_common::ValidationCodeHashProvider<Block::Hash> + Send + 'static,
P: Pair,
P: Pair + Send + Sync + 'static,
P::Public: AppPublic + Member + Codec,
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
{
Expand Down
117 changes: 107 additions & 10 deletions cumulus/client/consensus/aura/src/collators/slot_based/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <https://www.gnu.org/licenses/>.

use codec::Codec;
use futures::{stream::FusedStream, StreamExt};
use sc_consensus::{BlockImport, StateAction};
use sc_consensus_aura::{find_pre_digest, CompatibilityMode};
use sc_consensus_slots::InherentDataProviderExt;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_api::{ApiExt, CallApiAt, CallContext, Core, ProvideRuntimeApi, StorageProof};
use sp_runtime::traits::{Block as BlockT, Header as _};
use sp_block_builder::{BlockBuilder as BlockBuilderApi, BlockBuilder};
use sp_consensus_aura::{inherents::AuraInherentData, AuraApi};
use sp_core::Pair;
use sp_inherents::InherentDataProvider;
use sp_runtime::traits::{Block as BlockT, Header as _, NumberFor};
use sp_trie::proof_size_extension::ProofSizeExt;
use std::sync::Arc;

Expand Down Expand Up @@ -47,40 +54,84 @@ impl<Block> SlotBasedBlockImportHandle<Block> {
}

/// Special block import for the slot based collator.
pub struct SlotBasedBlockImport<Block, BI, Client> {
pub struct SlotBasedBlockImport<Block, BI, Client, CIDP, P, N> {
inner: BI,
client: Arc<Client>,
sender: TracingUnboundedSender<(Block, StorageProof)>,
create_inherent_data_providers: CIDP,
check_for_equivocation: bool,
compatibility_mode: CompatibilityMode<N>,
_phantom: std::marker::PhantomData<P>,
}

impl<Block, BI, Client> SlotBasedBlockImport<Block, BI, Client> {
impl<Block, BI, Client, CIDP, P, N> SlotBasedBlockImport<Block, BI, Client, CIDP, P, N> {
/// Create a new instance.
///
/// The returned [`SlotBasedBlockImportHandle`] needs to be passed to the
/// [`Params`](super::Params), so that this block import instance can communicate with the
/// collation task. If the node is not running as a collator, just dropping the handle is fine.
pub fn new(inner: BI, client: Arc<Client>) -> (Self, SlotBasedBlockImportHandle<Block>) {
pub fn new(
inner: BI,
client: Arc<Client>,
create_inherent_data_providers: CIDP,
check_for_equivocation: bool,
compatibility_mode: CompatibilityMode<N>,
) -> (Self, SlotBasedBlockImportHandle<Block>) {
let (sender, receiver) = tracing_unbounded("SlotBasedBlockImportChannel", 1000);

(Self { sender, client, inner }, SlotBasedBlockImportHandle { receiver })
(
Self {
sender,
client,
inner,
create_inherent_data_providers,
check_for_equivocation,
compatibility_mode,
_phantom: Default::default(),
},
SlotBasedBlockImportHandle { receiver },
)
}
}

impl<Block, BI: Clone, Client> Clone for SlotBasedBlockImport<Block, BI, Client> {
impl<Block, BI: Clone, Client, CIDP, P, N> Clone
for SlotBasedBlockImport<Block, BI, Client, CIDP, P, N>
where
CIDP: Clone,
N: Clone,
{
fn clone(&self) -> Self {
Self { inner: self.inner.clone(), client: self.client.clone(), sender: self.sender.clone() }
Self {
inner: self.inner.clone(),
client: self.client.clone(),
sender: self.sender.clone(),
create_inherent_data_providers: self.create_inherent_data_providers.clone(),
check_for_equivocation: self.check_for_equivocation,
compatibility_mode: self.compatibility_mode.clone(),
_phantom: Default::default(),
}
}
}

#[async_trait::async_trait]
impl<Block, BI, Client> BlockImport<Block> for SlotBasedBlockImport<Block, BI, Client>
impl<Block, BI, Client, CIDP, P> BlockImport<Block>
for SlotBasedBlockImport<Block, BI, Client, CIDP, P, NumberFor<Block>>
where
Block: BlockT,
BI: BlockImport<Block> + Send + Sync,
BI::Error: Into<sp_consensus::Error>,
Client: ProvideRuntimeApi<Block> + CallApiAt<Block> + Send + Sync,
Client: ProvideRuntimeApi<Block>
+ CallApiAt<Block>
+ sc_client_api::backend::AuxStore
+ Send
+ Sync,
Client::StateBackend: Send,
Client::Api: Core<Block>,
Client::Api: Core<Block> + BlockBuilderApi<Block> + AuraApi<Block, <P as Pair>::Public>,
P: Pair + Sync,
P::Public: Codec + std::fmt::Debug,
P::Signature: Codec,
CIDP: sp_inherents::CreateInherentDataProviders<Block, ()> + Send,
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
{
type Error = sp_consensus::Error;

Expand All @@ -95,6 +146,52 @@ where
&self,
mut params: sc_consensus::BlockImportParams<Block>,
) -> Result<sc_consensus::ImportResult, Self::Error> {
let slot = find_pre_digest::<Block, P::Signature>(&params.header)
.map_err(|e| sp_consensus::Error::Other(Box::new(e)))?;
let parent_hash = *params.header.parent_hash();
let create_inherent_data_providers = self
.create_inherent_data_providers
.create_inherent_data_providers(parent_hash, ())
.await
.map_err(sp_consensus::Error::Other)?;

// Check inherents.
// if the body is passed through, we need to use the runtime
// to check that the internally-set timestamp in the inherents
// actually matches the slot set in the seal.
if let Some(inner_body) = params.body.take() {
let new_block = Block::new(params.header.clone(), inner_body);
if self
.client
.runtime_api()
.has_api_with::<dyn BlockBuilder<Block>, _>(parent_hash, |v| v >= 2)
.map_err(|e| sp_consensus::Error::Other(Box::new(e)))?
{
let mut inherent_data = create_inherent_data_providers
.create_inherent_data()
.await
.map_err(|e| sp_consensus::Error::Other(Box::new(e)))?;
inherent_data.aura_replace_inherent_data(slot);
let inherent_res = self
.client
.runtime_api()
.check_inherents(parent_hash, new_block.clone(), inherent_data)
.map_err(|e| sp_consensus::Error::Other(Box::new(e)))?;

if !inherent_res.ok() {
for (i, e) in inherent_res.into_errors() {
match create_inherent_data_providers.try_handle_error(&i, &e).await {
Some(res) =>
res.map_err(|e| sp_consensus::Error::InvalidInherents(e))?,
None => return Err(sp_consensus::Error::InvalidInherentsUnhandled(i)),
}
}
}
}
let (_, inner_body) = new_block.deconstruct();
params.body = Some(inner_body);
}

// If the channel exists and it is required to execute the block, we will execute the block
// here. This is done to collect the storage proof and to prevent re-execution, we push
// downwards the state changes. `StateAction::ApplyChanges` is ignored, because it either
Expand Down
97 changes: 8 additions & 89 deletions cumulus/client/consensus/aura/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,109 +17,28 @@

//! Parachain specific wrapper for the AuRa import queue.

use codec::Codec;
use cumulus_client_consensus_common::ParachainBlockImportMarker;
use prometheus_endpoint::Registry;
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
use sc_consensus::{import_queue::DefaultImportQueue, BlockImport};
use sc_consensus_aura::{AuraVerifier, CompatibilityMode};
use sc_consensus_slots::InherentDataProviderExt;
use sc_telemetry::TelemetryHandle;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::Error as ConsensusError;
use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block as BlockT;
use std::{fmt::Debug, sync::Arc};

/// Parameters for [`import_queue`].
pub struct ImportQueueParams<'a, I, C, CIDP, S> {
/// The block import to use.
pub block_import: I,
/// The client to interact with the chain.
pub client: Arc<C>,
/// The inherent data providers, to create the inherent data.
pub create_inherent_data_providers: CIDP,
/// The spawner to spawn background tasks.
pub spawner: &'a S,
/// The prometheus registry.
pub registry: Option<&'a Registry>,
/// The telemetry handle.
pub telemetry: Option<TelemetryHandle>,
}

/// Start an import queue for the Aura consensus algorithm.
pub fn import_queue<P, Block, I, C, S, CIDP>(
ImportQueueParams {
block_import,
client,
create_inherent_data_providers,
spawner,
registry,
telemetry,
}: ImportQueueParams<'_, I, C, CIDP, S>,
) -> Result<DefaultImportQueue<Block>, sp_consensus::Error>
where
Block: BlockT,
C::Api: BlockBuilderApi<Block> + AuraApi<Block, P::Public> + ApiExt<Block>,
C: 'static
+ ProvideRuntimeApi<Block>
+ BlockOf
+ Send
+ Sync
+ AuxStore
+ UsageProvider<Block>
+ HeaderBackend<Block>,
I: BlockImport<Block, Error = ConsensusError>
+ ParachainBlockImportMarker
+ Send
+ Sync
+ 'static,
P: Pair + 'static,
P::Public: Debug + Codec,
P::Signature: Codec,
S: sp_core::traits::SpawnEssentialNamed,
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
{
sc_consensus_aura::import_queue::<P, _, _, _, _, _>(sc_consensus_aura::ImportQueueParams {
block_import,
justification_import: None,
client,
create_inherent_data_providers,
spawner,
registry,
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
telemetry,
compatibility_mode: CompatibilityMode::None,
})
}
use std::sync::Arc;

/// Parameters of [`build_verifier`].
pub struct BuildVerifierParams<C, CIDP> {
pub struct BuildVerifierParams<C, GetSlotFn> {
/// The client to interact with the chain.
pub client: Arc<C>,
/// The inherent data providers, to create the inherent data.
pub create_inherent_data_providers: CIDP,
/// Something that can get the current slot.
pub get_slot: GetSlotFn,
/// The telemetry handle.
pub telemetry: Option<TelemetryHandle>,
}

/// Build the [`AuraVerifier`].
pub fn build_verifier<P, C, CIDP, N>(
BuildVerifierParams { client, create_inherent_data_providers, telemetry }: BuildVerifierParams<
C,
CIDP,
>,
) -> AuraVerifier<C, P, CIDP, N> {
pub fn build_verifier<P, C, GetSlotFn, N>(
BuildVerifierParams { client, get_slot, telemetry }: BuildVerifierParams<C, GetSlotFn>,
) -> AuraVerifier<C, P, GetSlotFn, N> {
sc_consensus_aura::build_verifier(sc_consensus_aura::BuildVerifierParams {
client,
create_inherent_data_providers,
get_slot,
telemetry,
check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
compatibility_mode: CompatibilityMode::None,
})
}
4 changes: 2 additions & 2 deletions cumulus/client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//!
//! This extends the Substrate provided AuRa consensus implementation to make it compatible for
//! parachains. The main entry points for of this consensus algorithm are [`AuraConsensus::build`]
//! and [`fn@import_queue`].
//! and [`fn@equivocation_import_queue::fully_verifying_import_queue`].
//!
//! For more information about AuRa, the Substrate crate should be checked.

Expand Down Expand Up @@ -59,7 +59,7 @@ use std::{

mod import_queue;

pub use import_queue::{build_verifier, import_queue, BuildVerifierParams, ImportQueueParams};
pub use import_queue::{build_verifier, BuildVerifierParams};
use polkadot_node_primitives::PoV;
pub use sc_consensus_aura::{
slot_duration, standalone::slot_duration_at, AuraVerifier, BuildAuraWorkerParams,
Expand Down
5 changes: 5 additions & 0 deletions cumulus/polkadot-omni-node/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sc-cli = { workspace = true, default-features = false }
sc-client-api = { workspace = true, default-features = true }
sc-client-db = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-consensus-aura = { workspace = true, default-features = true }
sc-consensus-manual-seal = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-keystore = { workspace = true, default-features = true }
Expand Down Expand Up @@ -104,9 +105,12 @@ cumulus-primitives-aura = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
cumulus-relay-chain-interface = { workspace = true, default-features = true }
futures-timer = { workspace = true }
schnellru = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }
cumulus-test-client = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true, default-features = true }
cumulus-test-runtime = { workspace = true }
nix = { features = ["signal"], workspace = true }
tokio = { version = "1.43.1", features = ["macros", "parking_lot", "time"] }
Expand All @@ -118,6 +122,7 @@ rococo-native = ["polkadot-cli/rococo-native"]
westend-native = ["polkadot-cli/westend-native"]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"cumulus-test-client/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
Expand Down
Loading
Loading