Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pallet-balances = { workspace = true }
pallet-session = { workspace = true }
pallet-timestamp = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
Expand Down Expand Up @@ -63,6 +64,7 @@ std = [
"parachains-common/std",
"polkadot-parachain-primitives/std",
"sp-consensus-aura/std",
"sp-consensus-babe/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
132 changes: 128 additions & 4 deletions cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ use polkadot_parachain_primitives::primitives::{
HeadData, HrmpChannelId, RelayChainBlockNumber, XcmpMessageFormat,
};
use sp_consensus_aura::{SlotDuration, AURA_ENGINE_ID};
use sp_core::{Encode, U256};
use sp_consensus_babe::{
digests::{CompatibleDigestItem, PreDigest, PrimaryPreDigest},
AuthorityId, AuthorityPair, BabeAuthorityWeight,
};
use sp_core::{
sr25519::vrf::{VrfPreOutput, VrfProof, VrfSignature},
Encode, Pair, H256, U256,
};
use sp_runtime::{
traits::{Dispatchable, Header},
BuildStorage, Digest, DigestItem, DispatchError, Either, SaturatedConversion,
Expand Down Expand Up @@ -331,14 +338,36 @@ where
AllPalletsWithoutSystem::on_initialize(next_block_number);

let parent_head = HeadData(header.encode());
let sproof_builder = RelayStateSproofBuilder {
// This ensures the validation in cumulus_pallet_parachain_system passes
const NUM_DESCENDANTS: u64 = 2;
let authorities = generate_authority_pairs(NUM_DESCENDANTS);
let auth_pair = convert_to_authority_weight_pair(&authorities);

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

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

let (relay_parent_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof();

// Build relay parent descendants to pass the validation check
let relay_parent_descendants = build_relay_parent_descendants(
NUM_DESCENDANTS,
relay_parent_storage_root,
authorities,
);

let inherent_data = ParachainInherentData {
validation_data: PersistedValidationData {
parent_head,
Expand All @@ -349,7 +378,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 @@ -709,7 +738,26 @@ pub fn mock_open_hrmp_channel<
},
);

// Generate authorities and relay parent descendants for validation
const NUM_DESCENDANTS: u64 = 2;
let authorities = generate_authority_pairs(NUM_DESCENDANTS);
let auth_pair = convert_to_authority_weight_pair(&authorities);

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

let (relay_parent_storage_root, relay_chain_state) = sproof_builder.into_state_root_and_proof();

// Build relay parent descendants to pass validation
let relay_parent_descendants =
build_relay_parent_descendants(NUM_DESCENDANTS, relay_parent_storage_root, authorities);

let vfp = PersistedValidationData {
relay_parent_number: n as RelayChainBlockNumber,
relay_parent_storage_root,
Expand All @@ -724,7 +772,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 Expand Up @@ -763,3 +811,79 @@ impl<HrmpChannelSource: cumulus_primitives_core::XcmpMessageSource, AllPalletsWi
}
}
}

/// Helper functions for authority and relay header generation
/// 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 the header
fn add_pre_digest(header: &mut TestHeader, 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
}
Loading