Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
843dad9
babe: keep stateless verification in `Verifier`, move everything else…
sistemd Jul 9, 2025
0b7a2dc
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Jul 9, 2025
5eb0fe1
update prdoc description
sistemd Jul 9, 2025
a46e26b
revert some unneeded changes
sistemd Jul 9, 2025
3368dc2
replace BabeCreateInherentDataProviders
sistemd Jul 10, 2025
ef7327c
remove unneeded create_inherent_data_providers call
sistemd Jul 10, 2025
7966bf3
calculate the slot directly
sistemd Jul 10, 2025
f6c2374
Merge branch 'master' into sistemd/babe-import-queue-split
sistemd Jul 10, 2025
f454698
Merge branch 'master' into sistemd/babe-import-queue-split
sistemd Jul 11, 2025
2ea4261
fix prdoc
sistemd Jul 11, 2025
2a688a2
clean up error handling
sistemd Jul 11, 2025
da01d0d
authorities length check
sistemd Jul 11, 2025
d1170dc
don't fetch parent metadata
sistemd Jul 11, 2025
839ac5d
query_epoch_changes function
sistemd Jul 11, 2025
159e2fe
nicer block number calculation
sistemd Jul 14, 2025
57a0dfc
syntax
sistemd Jul 14, 2025
5b2c5fd
move some code into check_inherents
sistemd Jul 14, 2025
89acaed
better SlotAuthorNotFound error checking
sistemd Jul 14, 2025
6311296
Merge remote-tracking branch 'origin/master' into sistemd/babe-import…
sistemd Jul 14, 2025
5b7f423
fix warning
sistemd Jul 15, 2025
8e4d190
last nits
sistemd Jul 18, 2025
cef602e
Merge branch 'master' into sistemd/babe-import-queue-split
sistemd Jul 18, 2025
b2b573b
Merge branch 'master' into sistemd/babe-import-queue-split
sistemd Jul 18, 2025
c084b7b
Merge branch 'master' into sistemd/babe-import-queue-split
sistemd Jul 20, 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
36 changes: 20 additions & 16 deletions polkadot/node/service/src/builder/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use sc_service::{Configuration, Error as SubstrateServiceError, KeystoreContaine
use sc_telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_consensus::SelectChain;
use sp_consensus_babe::inherents::BabeCreateInherentDataProviders;
use sp_consensus_beefy::ecdsa_crypto;
use std::sync::Arc;

Expand Down Expand Up @@ -64,6 +65,8 @@ pub(crate) type PolkadotPartialComponents<ChainSelection> = sc_service::PartialC
FullGrandpaBlockImport<ChainSelection>,
ecdsa_crypto::AuthorityId,
>,
BabeCreateInherentDataProviders<Block>,
ChainSelection,
>,
sc_consensus_grandpa::LinkHalf<Block, FullClient, ChainSelection>,
sc_consensus_babe::BabeLink<Block>,
Expand Down Expand Up @@ -184,32 +187,33 @@ where
);

let babe_config = sc_consensus_babe::configuration(&*client)?;
let (block_import, babe_link) =
sc_consensus_babe::block_import(babe_config.clone(), beefy_block_import, client.clone())?;
let slot_duration = babe_config.slot_duration();
let (block_import, babe_link) = sc_consensus_babe::block_import(
babe_config.clone(),
beefy_block_import,
client.clone(),
Arc::new(move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot = sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
Ok((slot, timestamp))
}) as BabeCreateInherentDataProviders<Block>,
select_chain.clone(),
OffchainTransactionPoolFactory::new(transaction_pool.clone()),
)?;

let slot_duration = babe_link.config().slot_duration();
let (import_queue, babe_worker_handle) =
sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams {
link: babe_link.clone(),
block_import: block_import.clone(),
justification_import: Some(Box::new(justification_import)),
client: client.clone(),
select_chain: select_chain.clone(),
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
slot_duration,
spawner: &task_manager.spawn_essential_handle(),
registry: config.prometheus_registry(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()),
})?;

let justification_stream = grandpa_link.justification_stream();
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_9147.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
title: 'babe: keep stateless verification in `Verifier`, move everything else to the
import queue'
doc:
- audience: Node Operator
description: Only do stateless verification without runtime calls in the `BabeVerifier`, do all other verification in the import queue.
crates:
- name: polkadot-service
bump: patch
- name: sc-consensus-babe-rpc
bump: patch
- name: sc-consensus-babe
bump: major
- name: sp-consensus-babe
bump: minor
- name: sp-consensus
bump: major
- name: sp-inherents
bump: minor
37 changes: 21 additions & 16 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use polkadot_sdk::{
sc_consensus_beefy as beefy, sc_consensus_grandpa as grandpa,
sp_consensus_babe::inherents::BabeCreateInherentDataProviders,
sp_consensus_beefy as beefy_primitives, *,
};

Expand Down Expand Up @@ -190,6 +191,8 @@ pub fn new_partial(
Block,
FullClient,
FullBeefyBlockImport<FullGrandpaBlockImport>,
BabeCreateInherentDataProviders<Block>,
FullSelectChain,
>,
grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
sc_consensus_babe::BabeLink<Block>,
Expand Down Expand Up @@ -259,35 +262,35 @@ pub fn new_partial(
config.prometheus_registry().cloned(),
);

let babe_config = sc_consensus_babe::configuration(&*client)?;
let slot_duration = babe_config.slot_duration();
let (block_import, babe_link) = sc_consensus_babe::block_import(
sc_consensus_babe::configuration(&*client)?,
babe_config,
beefy_block_import,
client.clone(),
Arc::new(move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
Ok((slot, timestamp))
}) as BabeCreateInherentDataProviders<Block>,
select_chain.clone(),
OffchainTransactionPoolFactory::new(transaction_pool.clone()),
)?;

let slot_duration = babe_link.config().slot_duration();
let (import_queue, babe_worker_handle) =
sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams {
link: babe_link.clone(),
block_import: block_import.clone(),
justification_import: Some(Box::new(justification_import)),
client: client.clone(),
select_chain: select_chain.clone(),
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
slot_duration,
spawner: &task_manager.spawn_essential_handle(),
registry: config.prometheus_registry(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()),
})?;

let import_setup = (block_import, grandpa_link, babe_link, beefy_voter_links);
Expand Down Expand Up @@ -408,6 +411,8 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
Block,
FullClient,
FullBeefyBlockImport<FullGrandpaBlockImport>,
BabeCreateInherentDataProviders<Block>,
FullSelectChain,
>,
&sc_consensus_babe::BabeLink<Block>,
),
Expand Down Expand Up @@ -926,7 +931,7 @@ mod tests {
config,
None,
false,
|block_import: &sc_consensus_babe::BabeBlockImport<Block, _, _>,
|block_import: &sc_consensus_babe::BabeBlockImport<Block, _, _, _, _>,
babe_link: &sc_consensus_babe::BabeLink<Block>| {
setup_handles = Some((block_import.clone(), babe_link.clone()));
},
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ sp-crypto-hashing = { workspace = true, default-features = true }
sp-inherents = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-timestamp = { workspace = true, default-features = true }
thiserror = { workspace = true }

[dev-dependencies]
sc-block-builder = { workspace = true, default-features = true }
sc-network-test = { workspace = true }
sp-keyring = { workspace = true, default-features = true }
sp-timestamp = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
substrate-test-runtime-client = { workspace = true }
tokio = { workspace = true, default-features = true }
28 changes: 15 additions & 13 deletions substrate/client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,30 @@ mod tests {
let config = sc_consensus_babe::configuration(&*client).expect("config available");
let slot_duration = config.slot_duration();

let (block_import, link) =
sc_consensus_babe::block_import(config.clone(), client.clone(), client.clone())
.expect("can initialize block-import");
let (block_import, link) = sc_consensus_babe::block_import(
config.clone(),
client.clone(),
client.clone(),
move |_, _| async move {
Ok((InherentDataProvider::from_timestamp_and_slot_duration(
0.into(),
slot_duration,
),))
},
longest_chain.clone(),
OffchainTransactionPoolFactory::new(RejectAllTxPool::default()),
)
.expect("can initialize block-import");

let (_, babe_worker_handle) = sc_consensus_babe::import_queue(ImportQueueParams {
link: link.clone(),
block_import: block_import.clone(),
justification_import: None,
client: client.clone(),
select_chain: longest_chain.clone(),
create_inherent_data_providers: move |_, _| async move {
Ok((InherentDataProvider::from_timestamp_and_slot_duration(
0.into(),
slot_duration,
),))
},
slot_duration,
spawner: &task_executor,
registry: None,
telemetry: None,
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(
RejectAllTxPool::default(),
),
})
.unwrap();

Expand Down
Loading
Loading