Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
11c775a
Allow production of multiple blocks per slot in slot-based collator.
skunert Feb 13, 2025
3b2a1db
Taplo
skunert Feb 13, 2025
f1935bd
Use --authoring
skunert Feb 14, 2025
c571119
Update from skunert running command 'prdoc --audience node_operator -…
github-actions[bot] Feb 14, 2025
d7d183d
Apply suggestions from code review
skunert Feb 14, 2025
2e12f6d
Drift -> Offset
skunert Feb 14, 2025
765759d
Better docs
skunert Feb 14, 2025
3960f73
More docs
skunert Feb 14, 2025
79e96f2
Update from skunert running command 'fmt'
github-actions[bot] Feb 14, 2025
3ff3d24
Fixes
skunert Feb 15, 2025
782b3b2
Add new case
skunert Feb 15, 2025
1f0d3bd
Rustdoc
skunert Feb 17, 2025
acaeea9
refactor tests to run in ci
pepoviola Feb 18, 2025
7eb7304
fmt and license
pepoviola Feb 18, 2025
c7eba15
fix ci needs for test artifacts
pepoviola Feb 18, 2025
a281e7b
fixes for ci
pepoviola Feb 18, 2025
3464c9d
increase timeout
pepoviola Feb 18, 2025
6374256
fix provider in ci
pepoviola Feb 19, 2025
c5e42dc
ci, k8s auth and bump version
pepoviola Feb 19, 2025
5bab725
ci, use bash
pepoviola Feb 19, 2025
9cab1d7
ci, fix parachain image
pepoviola Feb 19, 2025
0f4739f
Apply suggestions from code review
skunert Feb 19, 2025
4f492bd
Update cumulus/client/consensus/aura/src/collators/slot_based/block_b…
skunert Feb 19, 2025
08ef715
Review comments
skunert Feb 19, 2025
5f4e3e9
Improve test helpers
skunert Feb 20, 2025
f208a43
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Feb 20, 2025
62de415
More comments
skunert Feb 21, 2025
a85c73d
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Feb 24, 2025
5d09524
Remove support for sub-6s slot durations.
skunert Feb 24, 2025
9f68dad
Review comments
skunert Feb 26, 2025
1972424
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Feb 26, 2025
cb85152
PRDOC
skunert Feb 27, 2025
8e44e91
Adjust cumulus-test-runtime to not use 2s slots anymore
skunert Feb 27, 2025
2e06dcb
Improve assertion to take into account finality lag instead of total …
skunert Feb 27, 2025
f19a1fd
Fix lockfile
skunert Feb 27, 2025
43ee813
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Feb 27, 2025
c812ad9
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Feb 28, 2025
cfb31fa
Remove substrate-compat feature from subxt
skunert Feb 28, 2025
1365e25
Fix feature flags in cumulus-test-runtime
skunert Feb 28, 2025
b212b2e
Disable colored logs in test-parachain
skunert Mar 3, 2025
01742bd
Increase resources, use imported instead of finalized for assertions
skunert Mar 3, 2025
4a58b91
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Mar 4, 2025
691864e
Improve test assertions
skunert Mar 5, 2025
88655bc
Extract zombienet-helpers
skunert Mar 6, 2025
323078f
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Mar 9, 2025
f1d4d8e
Lock
skunert Mar 9, 2025
e887244
toml format
skunert Mar 9, 2025
9b02e3b
CI
skunert Mar 9, 2025
0e941d7
Use $POLKADOT_IMAGE instead of $RELAY_IMAGE
skunert Mar 10, 2025
56e7d3b
Use $POLKADOT_IMAGE instead of $RELAY_IMAGE
skunert Mar 10, 2025
a4fad4d
bump zombienet version
pepoviola Mar 10, 2025
69ed3bd
Merge branch 'master' into skunert/multiple-blocks-per-slot
skunert Mar 10, 2025
93df323
Fix fmt
skunert Mar 11, 2025
10eb186
Fix comment
skunert Mar 11, 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
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ members = [
"cumulus/test/runtime",
"cumulus/test/service",
"cumulus/xcm/xcm-emulator",
"cumulus/zombienet/zombienet-sdk",
"docs/sdk",
"docs/sdk/packages/guides/first-pallet",
"docs/sdk/packages/guides/first-runtime",
Expand Down
1 change: 1 addition & 0 deletions cumulus/client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ polkadot-primitives = { workspace = true, default-features = true }
[dev-dependencies]
cumulus-test-client = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true }
rstest = { workspace = true }
sp-keyring = { workspace = true }

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ use cumulus_relay_chain_interface::RelayChainInterface;

use polkadot_primitives::{Block as RelayBlock, Id as ParaId};

use futures::prelude::*;
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
use sc_consensus::BlockImport;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus_aura::{AuraApi, Slot};
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member};
use sp_timestamp::Timestamp;
use std::{sync::Arc, time::Duration};

use super::CollatorMessage;
use crate::{
collator::{self as collator_util},
Expand All @@ -48,10 +34,23 @@ use crate::{
slot_based::{
core_selector,
relay_chain_data_cache::{RelayChainData, RelayChainDataCache},
slot_timer::SlotTimer,
},
},
LOG_TARGET,
};
use futures::prelude::*;
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
use sc_consensus::BlockImport;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member};
use std::{sync::Arc, time::Duration};

/// Parameters for [`run_block_builder`].
pub struct BuilderTaskParams<
Expand Down Expand Up @@ -91,6 +90,7 @@ pub struct BuilderTaskParams<
pub authoring_duration: Duration,
/// Channel to send built blocks to the collation task.
pub collator_sender: sc_utils::mpsc::TracingUnboundedSender<CollatorMessage<Block>>,
pub relay_chain_slot_duration: Duration,
/// Drift every slot by this duration.
/// This is a time quantity that is subtracted from the actual timestamp when computing
/// the time left to enter a new slot. In practice, this *left-shifts* the clock time with the
Expand All @@ -100,64 +100,6 @@ pub struct BuilderTaskParams<
pub slot_drift: Duration,
}

#[derive(Debug)]
struct SlotInfo {
pub timestamp: Timestamp,
pub slot: Slot,
}

#[derive(Debug)]
struct SlotTimer<Block, Client, P> {
client: Arc<Client>,
drift: Duration,
_marker: std::marker::PhantomData<(Block, Box<dyn Fn(P) + Send + Sync + 'static>)>,
}

/// Returns current duration since Unix epoch.
fn duration_now() -> Duration {
use std::time::SystemTime;
let now = SystemTime::now();
now.duration_since(SystemTime::UNIX_EPOCH).unwrap_or_else(|e| {
panic!("Current time {:?} is before Unix epoch. Something is wrong: {:?}", now, e)
})
}

/// Returns the duration until the next slot from now.
fn time_until_next_slot(slot_duration: Duration, drift: Duration) -> Duration {
let now = duration_now().as_millis() - drift.as_millis();

let next_slot = (now + slot_duration.as_millis()) / slot_duration.as_millis();
let remaining_millis = next_slot * slot_duration.as_millis() - now;
Duration::from_millis(remaining_millis as u64)
}

impl<Block, Client, P> SlotTimer<Block, Client, P>
where
Block: BlockT,
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static + UsageProvider<Block>,
Client::Api: AuraApi<Block, P::Public>,
P: Pair,
P::Public: AppPublic + Member + Codec,
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
{
pub fn new_with_drift(client: Arc<Client>, drift: Duration) -> Self {
Self { client, drift, _marker: Default::default() }
}

/// Returns a future that resolves when the next slot arrives.
pub async fn wait_until_next_slot(&self) -> Result<SlotInfo, ()> {
let Ok(slot_duration) = crate::slot_duration(&*self.client) else {
tracing::error!(target: crate::LOG_TARGET, "Failed to fetch slot duration from runtime.");
return Err(())
};

let time_until_next_slot = time_until_next_slot(slot_duration.as_duration(), self.drift);
tokio::time::sleep(time_until_next_slot).await;
let timestamp = sp_timestamp::Timestamp::current();
Ok(SlotInfo { slot: Slot::from_timestamp(timestamp, slot_duration), timestamp })
}
}

/// Run block-builder.
pub fn run_block_builder<Block, P, BI, CIDP, Client, Backend, RelayClient, CHP, Proposer, CS>(
params: BuilderTaskParams<Block, BI, CIDP, Client, Backend, RelayClient, CHP, Proposer, CS>,
Expand Down Expand Up @@ -201,11 +143,16 @@ where
collator_sender,
code_hash_provider,
authoring_duration,
relay_chain_slot_duration,
para_backend,
slot_drift,
} = params;

let slot_timer = SlotTimer::<_, _, P>::new_with_drift(para_client.clone(), slot_drift);
let mut slot_timer = SlotTimer::<_, _, P>::new_with_drift(
para_client.clone(),
slot_drift,
relay_chain_slot_duration,
);

let mut collator = {
let params = collator_util::Params {
Expand Down Expand Up @@ -281,6 +228,8 @@ where
);
}

slot_timer.update_scheduling(scheduled_cores.len() as u32);

let core_selector = core_selector.0 as usize % scheduled_cores.len();
let Some(core_index) = scheduled_cores.get(core_selector) else {
// This cannot really happen, as we modulo the core selector with the
Expand Down
5 changes: 5 additions & 0 deletions cumulus/client/consensus/aura/src/collators/slot_based/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ mod block_import;
mod collation_task;
mod relay_chain_data_cache;

mod slot_timer;

/// Parameters for [`run`].
pub struct Params<Block, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spawner> {
/// Inherent data providers. Only non-consensus inherent data should be provided, i.e.
Expand Down Expand Up @@ -100,6 +102,7 @@ pub struct Params<Block, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS,
pub block_import_handle: SlotBasedBlockImportHandle<Block>,
/// Spawner for spawning futures.
pub spawner: Spawner,
pub relay_chain_slot_duration: Duration,
}

/// Run aura-based block building and collation task.
Expand All @@ -120,6 +123,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
reinitialize,
slot_drift,
block_import_handle,
relay_chain_slot_duration,
spawner,
}: Params<Block, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spawner>,
) where
Expand Down Expand Up @@ -174,6 +178,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
collator_service,
authoring_duration,
collator_sender: tx,
relay_chain_slot_duration,
slot_drift,
};

Expand Down
Loading
Loading