Skip to content

Commit

Permalink
fix zn test, do some renaming and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alindima committed Jan 13, 2025
1 parent eddec7e commit 61df047
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitlab/pipeline/zombienet/polkadot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ zombienet-polkadot-elastic-scaling-doesnt-break-parachains:
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export CUMULUS_IMAGE="${COL_IMAGE}"
- export X_INFRA_INSTANCE=spot # use spot by default
variables:
KUBERNETES_CPU_REQUEST: "1"
Expand Down
26 changes: 20 additions & 6 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ pub mod ump_constants {
}

/// Trait for selecting the next core to build the candidate for.
/// If methods return `None`,
/// WARN: Only use an implementation that returns `Some(..)` if you're sure that all collator nodes
/// have been updated to the latest version and are using the slot-based collator.
pub trait SelectCore {
/// Core selector information for the current block.
fn selected_core() -> Option<(CoreSelector, ClaimQueueOffset)>;
Expand All @@ -210,10 +213,18 @@ impl SelectCore for () {
}
}

/// The default core selection policy.
pub struct DefaultCoreSelector<T>(PhantomData<T>);
/// Default core selection policy, no-op. Leaves the core selection up to the node side.
/// Backwards compatible with all node versions. Use this unless you are sure that all collator
/// nodes have been updated to latest version and are using the slot-based collator.
pub type DefaultCoreSelector = ();

impl<T: frame_system::Config> SelectCore for DefaultCoreSelector<T> {
/// Core selection policy which does a round-robin selection on the assigned cores at claim queue
/// depth 0.
/// WARN: Only use if you're sure that all collator nodes have been updated to the latest version
/// and are using the slot-based collator.
pub struct RoundRobinCoreSelector<T>(PhantomData<T>);

impl<T: frame_system::Config> SelectCore for RoundRobinCoreSelector<T> {
fn selected_core() -> Option<(CoreSelector, ClaimQueueOffset)> {
let core_selector: U256 = frame_system::Pallet::<T>::block_number().into();

Expand All @@ -227,10 +238,13 @@ impl<T: frame_system::Config> SelectCore for DefaultCoreSelector<T> {
}
}

/// Core selection policy that builds on claim queue offset 1.
pub struct LookaheadCoreSelector<T>(PhantomData<T>);
/// Core selection policy which does a round-robin selection on the assigned cores at claim queue
/// depth 1.
/// WARN: Only use if you're sure that all collator nodes have been updated to the latest version
/// and are using the slot-based collator.
pub struct LookaheadRoundRobinCoreSelector<T>(PhantomData<T>);

impl<T: frame_system::Config> SelectCore for LookaheadCoreSelector<T> {
impl<T: frame_system::Config> SelectCore for LookaheadRoundRobinCoreSelector<T> {
fn selected_core() -> Option<(CoreSelector, ClaimQueueOffset)> {
let core_selector: U256 = frame_system::Pallet::<T>::block_number().into();

Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/parachain-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Config for Test {
type CheckAssociatedRelayNumber = AnyRelayNumber;
type ConsensusHook = TestConsensusHook;
type WeightInfo = ();
type SelectCore = TestCoreSelector<DefaultCoreSelector<Test>>;
type SelectCore = TestCoreSelector<RoundRobinCoreSelector<Test>>;
}

std::thread_local! {
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/xcmp-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl cumulus_pallet_parachain_system::Config for Test {
type ReservedXcmpWeight = ();
type CheckAssociatedRelayNumber = AnyRelayNumber;
type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Test>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Test>;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

impl parachain_info::Config for Runtime {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

impl parachain_info::Config for Runtime {}
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
#[cfg(feature = "ump-signals")]
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
#[cfg(not(feature = "ump-signals"))]
type SelectCore = ();
}
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/src/polkadot_sdk/cumulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
>;
type WeightInfo = ();
type DmpQueue = frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = ();
}

impl parachain_info::Config for Runtime {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ async fn doesnt_break_parachains_test() -> Result<(), anyhow::Error> {
(1..4).fold(r, |acc, i| acc.with_node(|node| node.with_name(&format!("validator-{i}"))))
})
.with_parachain(|p| {
// Use rococo-parachain default, which has 6 second slot time. Also, don't use
// slot-based collator.
// Use test-parachain default, which has 6 second slot time and doesn't output ump
// signals. Also, don't use slot-based collator.
p.with_id(2000)
.with_default_command("polkadot-parachain")
.with_default_command("test-parachain")
.with_default_image(images.cumulus.as_str())
.with_default_args(vec![("-lparachain=debug,aura=debug").into()])
.with_collator(|n| n.with_name("collator-2000"))
Expand Down
2 changes: 1 addition & 1 deletion templates/parachain/runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
type SelectCore = cumulus_pallet_parachain_system::RoundRobinCoreSelector<Runtime>;
}

impl parachain_info::Config for Runtime {}
Expand Down

0 comments on commit 61df047

Please sign in to comment.