Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b75f677
para/tests: Add babe to dependencies
lexnv Dec 3, 2025
c58240d
para/test-utils: Provide relay descendants for run_to_block_with_fina…
lexnv Dec 4, 2025
ac0cc55
Merge branch 'master' into lexnv/fix-descendants
lexnv Dec 4, 2025
e1e92ad
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Dec 4, 2025
52ae36a
Merge remote-tracking branch 'origin/master' into lexnv/fix-descendants
lexnv Dec 5, 2025
4ef65b0
cumulus: Move testing code to relay-sproof-builder
lexnv Dec 5, 2025
cb2444a
TEMP: Enable elastic scaling for AHWestend to filter out tests
lexnv Dec 5, 2025
7d0e9dc
xcm: Add fix to xcm emulator
lexnv Dec 5, 2025
6b60444
Merge branch 'master' into lexnv/fix-descendants
lexnv Dec 8, 2025
0e06716
cumulus: Ensure 2 desc
lexnv Dec 8, 2025
9b430a9
Revert "TEMP: Enable elastic scaling for AHWestend to filter out tests"
lexnv Dec 8, 2025
5d059e9
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Dec 8, 2025
07493d6
Update PRdoc
lexnv Dec 8, 2025
87d61e8
ci: Disable checks for ahw
lexnv Dec 9, 2025
a11db11
ci: Bump timeout to 120s
lexnv Dec 9, 2025
57e1707
Update cumulus/test/relay-sproof-builder/src/lib.rs
lexnv Dec 9, 2025
cfe6d54
Update cumulus/xcm/xcm-emulator/src/lib.rs
lexnv Dec 9, 2025
475e779
cumulus: Rename method for add_babe_pre_digest
lexnv Dec 9, 2025
aff9e35
cumulus: apply suggestions
lexnv Dec 9, 2025
c4754e0
cumulus: Make some fn private
lexnv Dec 9, 2025
b7ac23f
Merge remote-tracking branch 'origin/lexnv/fix-descendants' into lexn…
lexnv Dec 9, 2025
dd5c26a
Merge branch 'master' into lexnv/fix-descendants
lexnv Dec 9, 2025
9f9d534
para-sys: Use no authorities for sproof builder in manual modes
lexnv Dec 9, 2025
2761983
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Dec 9, 2025
9c902b7
ci: Bump timeouts
lexnv Dec 10, 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
2 changes: 2 additions & 0 deletions Cargo.lock

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

20 changes: 18 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ use xcm::latest::prelude::{
NetworkId, NonFungible, ParentThen, Response, WeightLimit, XCM_VERSION,
};

/// Build with an offset of 1 behind the relay chain.
const RELAY_PARENT_OFFSET: u32 = 1;

/// The upper limit of how many parachain blocks are processed by the relay chain per
/// parent. Limits the number of blocks authored per slot. This determines the minimum
/// block time of the parachain:
/// `RELAY_CHAIN_SLOT_DURATION_MILLIS/BLOCK_PROCESSING_VELOCITY`
const BLOCK_PROCESSING_VELOCITY: u32 = 3;

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = (2 + RELAY_PARENT_OFFSET) * BLOCK_PROCESSING_VELOCITY + 1;

/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
Expand Down Expand Up @@ -902,7 +918,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedXcmpWeight = ReservedXcmpWeight;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = ConsensusHook;
type RelayParentOffset = ConstU32<0>;
type RelayParentOffset = ConstU32<RELAY_PARENT_OFFSET>;
}

type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Expand Down Expand Up @@ -1746,7 +1762,7 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(

impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
fn relay_parent_offset() -> u32 {
0
RELAY_PARENT_OFFSET
}
}

Expand Down
24 changes: 19 additions & 5 deletions cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,22 @@ where
AllPalletsWithoutSystem::on_initialize(next_block_number);

let parent_head = HeadData(header.encode());

// Get RelayParentOffset from the parachain system pallet config.
let num_descendants = 1 +
<Runtime as cumulus_pallet_parachain_system::Config>::RelayParentOffset::get()
.saturated_into::<u64>();

let sproof_builder = RelayStateSproofBuilder {
para_id: <Runtime>::SelfParaId::get(),
included_para_head: parent_head.clone().into(),
num_authorities: num_descendants,
..Default::default()
};

let (relay_parent_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof();
let (relay_parent_storage_root, relay_chain_state, relay_parent_descendants) =
sproof_builder.into_state_root_proof_and_descendants(num_descendants);

let inherent_data = ParachainInherentData {
validation_data: PersistedValidationData {
parent_head,
Expand All @@ -349,7 +357,7 @@ where
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
relay_parent_descendants: Default::default(),
relay_parent_descendants,
collator_peer_id: None,
};

Expand Down Expand Up @@ -689,12 +697,16 @@ pub fn mock_open_hrmp_channel<
let timestamp = slot.saturating_mul(slot_durations.para.as_millis());
let relay_slot = Slot::from_timestamp(timestamp.into(), slot_durations.relay);

// Get RelayParentOffset from the parachain system pallet config.
let num_descendants = 1 + C::RelayParentOffset::get().saturated_into::<u64>();

let n = 1_u32;
let mut sproof_builder = RelayStateSproofBuilder {
para_id: sender,
included_para_head: Some(HeadData(included_head.encode())),
hrmp_egress_channel_index: Some(vec![recipient]),
current_slot: relay_slot,
num_authorities: num_descendants,
..Default::default()
};
sproof_builder.hrmp_channels.insert(
Expand All @@ -709,7 +721,9 @@ pub fn mock_open_hrmp_channel<
},
);

let (relay_parent_storage_root, relay_chain_state) = sproof_builder.into_state_root_and_proof();
let (relay_parent_storage_root, relay_chain_state, relay_parent_descendants) =
sproof_builder.into_state_root_proof_and_descendants(num_descendants);

let vfp = PersistedValidationData {
relay_parent_number: n as RelayChainBlockNumber,
relay_parent_storage_root,
Expand All @@ -724,7 +738,7 @@ pub fn mock_open_hrmp_channel<
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
relay_parent_descendants: Default::default(),
relay_parent_descendants,
collator_peer_id: None,
};
inherent_data
Expand Down
4 changes: 4 additions & 0 deletions cumulus/test/relay-sproof-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ workspace = true
codec = { features = ["derive"], workspace = true }

# Substrate
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-state-machine = { workspace = true }
sp-trie = { workspace = true }
Expand All @@ -31,6 +33,8 @@ std = [
"codec/std",
"cumulus-primitives-core/std",
"polkadot-primitives/std",
"sp-consensus-babe/std",
"sp-core/std",
"sp-runtime/std",
"sp-state-machine/std",
"sp-trie/std",
Expand Down
127 changes: 125 additions & 2 deletions cumulus/test/relay-sproof-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
extern crate alloc;

use alloc::collections::btree_map::BTreeMap;
use codec::{Decode, Encode};
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, AbridgedHrmpChannel, ParaId,
};
use polkadot_primitives::UpgradeGoAhead;
use sp_runtime::traits::HashingFor;
use sp_consensus_babe::{
digests::{CompatibleDigestItem, PreDigest, PrimaryPreDigest},
AuthorityId, AuthorityPair, BabeAuthorityWeight,
};
use sp_core::{
sr25519::vrf::{VrfPreOutput, VrfProof, VrfSignature},
Pair, H256,
};
use sp_runtime::{
traits::{HashingFor, Header},
Digest, DigestItem,
};
use sp_trie::PrefixedMemoryDB;

/// Builds a sproof (portmanteau of 'spoof' and 'proof') of the relay chain state.
Expand Down Expand Up @@ -49,6 +61,7 @@ pub struct RelayStateSproofBuilder {
pub randomness: relay_chain::Hash,
pub additional_key_values: Vec<(Vec<u8>, Vec<u8>)>,
pub included_para_head: Option<relay_chain::HeadData>,
pub num_authorities: u64,
}

impl Default for RelayStateSproofBuilder {
Expand Down Expand Up @@ -81,6 +94,7 @@ impl Default for RelayStateSproofBuilder {
randomness: relay_chain::Hash::default(),
additional_key_values: vec![],
included_para_head: None,
num_authorities: 0,
}
}
}
Expand Down Expand Up @@ -129,9 +143,39 @@ impl RelayStateSproofBuilder {
})
}

pub fn into_state_root_and_proof(
/// Build sproof and generate relay parent descendants with the configured authorities.
///
/// Returns a tuple of (state_root, storage_proof, relay_parent_descendants).
pub fn into_state_root_proof_and_descendants(
self,
num_descendants: u64,
) -> (polkadot_primitives::Hash, sp_state_machine::StorageProof, Vec<TestHeader>) {
let authorities = generate_authority_pairs(self.num_authorities);
let (state_root, proof) = self.into_state_root_and_proof();
let descendants =
build_relay_parent_descendants(num_descendants, state_root.into(), authorities);
(state_root, proof, descendants)
}

pub fn into_state_root_and_proof(
mut self,
) -> (polkadot_primitives::Hash, sp_state_machine::StorageProof) {
// Generate and add authorities if num_authorities is set
if self.num_authorities > 0 {
let authorities = generate_authority_pairs(self.num_authorities);
let auth_pair = convert_to_authority_weight_pair(&authorities);

// Add authorities to the sproof builder
self.additional_key_values.push((
relay_chain::well_known_keys::AUTHORITIES.to_vec(),
auth_pair.clone().encode(),
));
self.additional_key_values.push((
relay_chain::well_known_keys::NEXT_AUTHORITIES.to_vec(),
auth_pair.encode(),
));
}

let (db, root) =
PrefixedMemoryDB::<HashingFor<polkadot_primitives::Block>>::default_with_root();
let state_version = Default::default(); // for test using default.
Expand Down Expand Up @@ -213,3 +257,82 @@ impl RelayStateSproofBuilder {
(root, proof)
}
}

/// Block Header type for testing
pub type TestHeader = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;

/// Generate a vector of AuthorityPairs
pub fn generate_authority_pairs(num_authorities: u64) -> Vec<AuthorityPair> {
(0..num_authorities).map(|i| AuthorityPair::from_seed(&[i as u8; 32])).collect()
}

/// Convert AuthorityPair to (AuthorityId, BabeAuthorityWeight)
pub fn convert_to_authority_weight_pair(
authorities: &[AuthorityPair],
) -> Vec<(AuthorityId, BabeAuthorityWeight)> {
authorities
.iter()
.map(|auth| (auth.public().into(), Default::default()))
.collect()
}

/// Add a BABE pre-digest to a generic header
pub fn add_pre_digest<Header: sp_runtime::traits::Header>(
header: &mut Header,
authority_index: u32,
block_number: u64,
) {
/// This method generates some vrf data, but only to make the compiler happy
fn generate_testing_vrf() -> VrfSignature {
let vrf_proof_bytes = [0u8; 64];
let proof: VrfProof = VrfProof::decode(&mut vrf_proof_bytes.as_slice()).unwrap();
let vrf_pre_out_bytes = [0u8; 32];
let pre_output: VrfPreOutput =
VrfPreOutput::decode(&mut vrf_pre_out_bytes.as_slice()).unwrap();
VrfSignature { pre_output, proof }
}

let pre_digest = PrimaryPreDigest {
authority_index,
slot: block_number.into(),
vrf_signature: generate_testing_vrf(),
};

header
.digest_mut()
.push(DigestItem::babe_pre_digest(PreDigest::Primary(pre_digest)));
}

/// Create a mock chain of relay headers as descendants of the relay parent
pub fn build_relay_parent_descendants(
num_headers: u64,
state_root: H256,
authorities: Vec<AuthorityPair>,
) -> Vec<TestHeader> {
let mut headers = Vec::with_capacity(num_headers as usize);

let mut previous_hash = None;

for block_number in 0..=num_headers as u32 - 1 {
let mut header = TestHeader {
number: block_number,
parent_hash: previous_hash.unwrap_or_default(),
state_root,
extrinsics_root: H256::default(),
digest: Digest::default(),
};
let authority_index = block_number % (authorities.len() as u32);

// Add pre-digest
add_pre_digest(&mut header, authority_index, block_number as u64);

// Sign and seal the header
let signature = authorities[authority_index as usize].sign(header.hash().as_bytes());
header.digest_mut().push(DigestItem::babe_seal(signature.into()));

previous_hash = Some(header.hash());
headers.push(header);
}

headers
}
16 changes: 12 additions & 4 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use sp_tracing;
// Cumulus
pub use cumulus_pallet_parachain_system::{
parachain_inherent::{deconstruct_parachain_inherent_data, InboundMessagesData},
Call as ParachainSystemCall, Pallet as ParachainSystemPallet,
Call as ParachainSystemCall, Config as ParachainSystemConfig, Pallet as ParachainSystemPallet,
};
pub use cumulus_primitives_core::{
relay_chain::{BlockNumber as RelayBlockNumber, HeadData, HrmpChannelId},
Expand Down Expand Up @@ -205,6 +205,7 @@ pub trait Network {
para_id: u32,
relay_parent_number: u32,
parent_head_data: HeadData,
relay_parent_offset: u64,
) -> ParachainInherentData;
fn send_horizontal_messages<I: Iterator<Item = (ParaId, RelayBlockNumber, Vec<u8>)>>(
to_para_id: u32,
Expand Down Expand Up @@ -731,8 +732,11 @@ macro_rules! decl_test_parachains {
timestamp_set.dispatch(<Self as Chain>::RuntimeOrigin::none())
);

// Get RelayParentOffset from the runtime
let relay_parent_offset = <<<Self as $crate::Chain>::Runtime as $crate::ParachainSystemConfig>::RelayParentOffset as frame_support::traits::Get<u32>>::get();

// 2. inherent: cumulus_pallet_parachain_system::Call::set_validation_data
let data = N::hrmp_channel_parachain_inherent_data(para_id, relay_block_number, parent_head_data);
let data = N::hrmp_channel_parachain_inherent_data(para_id, relay_block_number, parent_head_data, relay_parent_offset as u64);
let (data, mut downward_messages, mut horizontal_messages) =
$crate::deconstruct_parachain_inherent_data(data);
let inbound_messages_data = $crate::InboundMessagesData::new(
Expand Down Expand Up @@ -1195,11 +1199,14 @@ macro_rules! decl_test_networks {
para_id: u32,
relay_parent_number: u32,
parent_head_data: $crate::HeadData,
relay_parent_offset: u64,
) -> $crate::ParachainInherentData {
let mut sproof = $crate::RelayStateSproofBuilder::default();
sproof.para_id = para_id.into();
sproof.current_slot = $crate::polkadot_primitives::Slot::from(relay_parent_number as u64);
sproof.host_config.max_upward_message_size = 1024 * 1024;
sproof.num_authorities = relay_parent_offset + 1;
let num_descendants = sproof.num_authorities;

// egress channel
let e_index = sproof.hrmp_egress_channel_index.get_or_insert_with(Vec::new);
Expand Down Expand Up @@ -1227,7 +1234,8 @@ macro_rules! decl_test_networks {
});
}

let (relay_storage_root, proof) = sproof.into_state_root_and_proof();
let (relay_storage_root, proof, relay_parent_descendants) =
sproof.into_state_root_proof_and_descendants(num_descendants);

$crate::ParachainInherentData {
validation_data: $crate::PersistedValidationData {
Expand All @@ -1239,7 +1247,7 @@ macro_rules! decl_test_networks {
relay_chain_state: proof,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
relay_parent_descendants: Default::default(),
relay_parent_descendants,
collator_peer_id: None,
}
}
Expand Down
24 changes: 24 additions & 0 deletions prdoc/pr_10541.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
title: 'test-utils/fix: Parachains test-utils relay parent descendants mock data'
doc:
- audience: Node Dev
description: |-
This PR ensures that the parachains test-utils crate has 2 relay parent descendants for testing purposes.

Effectively fixes a panic because we missed this mock data for chains that started with `RP_offset > 0`:

```
Unable to verify provided relay parent descendants. expected_rp_descendants_num: 1 error: InvalidNumberOfDescendants { expected: 2, received: 0 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Detected in:
- https://github.com/polkadot-fellows/runtimes/actions/runs/19857064730/job/56897622908?pr=1018

Unblocks:
- https://github.com/polkadot-fellows/runtimes/pull/1018

Inspired by a similar fix I've introduced in:
- https://github.com/paritytech/polkadot-sdk/pull/9880
crates:
- name: parachains-runtimes-test-utils
bump: patch
Loading