xcm-emulator: advance relay block number by relay_blocks_per_para_block#11031
xcm-emulator: advance relay block number by relay_blocks_per_para_block#11031
Conversation
AuraDigestProvider sets CurrentSlot = relay_block_number, but the sproof builder was also setting current_slot = relay_block_number. For parachains with slot duration != relay slot duration (e.g. 12s Polkadot/Kusama chains), FixedVelocityConsensusHook derives a different para_slot and panics. Scale sproof.current_slot by slot_duration / RELAY_CHAIN_SLOT_DURATION so the hook's derivation matches CurrentSlot for any slot duration.
|
/cmd prdoc --audience runtime_dev --bump patch |
|
This is needed to unlock runtime 2.1.0 PR where all integration emulated tests are currently failing see polkadot-fellows/runtimes#1065 (comment) I've locally patched the 2.1.0 PR to contain this fix and integration emulated tests pass now. |
…time_dev --bump patch'
let me cherry-pick that and run tests in the runtime with your fix. Keep you posted (and thx) |
@skunert thanks for the reply. I went for your approach and tested in the runtime. With your neater approach, I need to replace in the test AuraDigestProvider with an ad-hoc one like below: pub struct SlotAdjustedDigestProvider<const PARA_SLOT_MS: u64>;
impl<const PARA_SLOT_MS: u64> Convert<(u32, u32), Digest>
for SlotAdjustedDigestProvider<PARA_SLOT_MS>
{
fn convert((_block_number, relay_block_number): (u32, u32)) -> Digest {
let slot: Slot =
(relay_block_number as u64 * RELAY_CHAIN_SLOT_DURATION_MILLIS / PARA_SLOT_MS).into();
let mut digest = Digest::default();
digest.logs.push(DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode()));
digest
}
}which is perfectly fine by me as well. Wdyt?
They diverge because AuraDigestProvider puts the raw relay block number in the digest, but the timestamp now uses RELAY_CHAIN_SLOT_DURATION_MILLIS (6000) instead of slot_duration (12000). In the SDK, this works because the SDK's test chains have slot_duration = 6000. In the runtime repo, Polkadot/Kusama parachains have slot_duration = 12000, so we need a DigestProvider that divides accordingly: slot = relay_block_number * 6000 / 12000. Does it make sense? |
Yes, fine by me. You could make the default AuraDigestProvider do this. Then it would be fixed automatically. Maybe I shouldn't even have introduced the DigestProvider but directly add the digest in xcm-emulator, in the end we have both slot durations available there already. But fine for now. |
…ck (#11031) After `AuraDigestProvider` was introduced, emulated integration tests for parachains with `slot_duration != relay_slot_duration` (e.g. 12s Polkadot/Kusama chains) panic because `FixedVelocityConsensusHook` derives a parachain slot that doesn't match `CurrentSlot`. Fix by advancing the relay block number by `slot_duration / RELAY_CHAIN_SLOT_DURATION_MILLIS` per parachain block (instead of always +1), and computing the aura digest slot inline using both durations. This removes the `DigestProvider` associated type from the `Parachain` trait and the `AuraDigestProvider` struct — the emulator now handles the digest automatically. Downstream users must remove `DigestProvider: AuraDigestProvider,` from their `decl_test_parachains!` invocations. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> (cherry picked from commit a20ac9b)
|
Successfully created backport PR for |
Backport #11031 into `stable2512` from sigurpol. Note that the two changes marked as `major` come from xcm-emulator and a test pallet so they have zero impact on real production runtimes, only on integrated emulation test @EgorPopelyaev See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Paolo La Camera <paolo@parity.io> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Backport paritytech#11031 into `stable2512` from sigurpol. Note that the two changes marked as `major` come from xcm-emulator and a test pallet so they have zero impact on real production runtimes, only on integrated emulation test @EgorPopelyaev See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Paolo La Camera <paolo@parity.io> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
After
AuraDigestProviderwas introduced, emulated integration tests for parachains withslot_duration != relay_slot_duration(e.g. 12s Polkadot/Kusama chains) panic becauseFixedVelocityConsensusHookderives a parachain slot that doesn't matchCurrentSlot.Fix by advancing the relay block number by
slot_duration / RELAY_CHAIN_SLOT_DURATION_MILLISper parachain block (instead of always +1), and computing the aura digest slot inline using both durations.This removes the
DigestProviderassociated type from theParachaintrait and theAuraDigestProviderstruct — the emulator now handles the digest automatically.Downstream users must remove
DigestProvider: AuraDigestProvider,from theirdecl_test_parachains!invocations.