Skip to content

Commit 9575af4

Browse files
committed
enforce slot based and make offset dynamic (#3740)
* enforce slot based and make offset dynamic * fix rust tests * fix: manual seal and lazy-loading and pending block must support relay offset * fix some dev tests expectations * tests: lazy loading tests should not always expect migration * tests: zombie tests should use slot based consensus * bridge test should use slot based * fix coderabbit comment
1 parent 2ec6410 commit 9575af4

19 files changed

Lines changed: 78 additions & 56 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/service/src/lazy_loading/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use crate::{
2323
};
2424
use cumulus_client_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig};
2525
use cumulus_client_service::ParachainTracingExecuteBlock;
26-
use cumulus_primitives_core::{relay_chain, BlockT, CollectCollationInfo, ParaId};
26+
use cumulus_primitives_core::{
27+
relay_chain, BlockT, CollectCollationInfo, ParaId, RelayParentOffsetApi,
28+
};
2729
use fc_rpc::StorageOverrideHandler;
2830
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
2931
use frontier_backend::LazyLoadingFrontierBackend;
@@ -358,7 +360,8 @@ pub async fn new_lazy_loading_service<RuntimeApi, Customizations, Net>(
358360
) -> Result<TaskManager, ServiceError>
359361
where
360362
RuntimeApi: ConstructRuntimeApi<Block, LazyLoadingClient<RuntimeApi>> + Send + Sync + 'static,
361-
RuntimeApi::RuntimeApi: RuntimeApiCollection,
363+
RuntimeApi::RuntimeApi:
364+
RuntimeApiCollection + cumulus_primitives_core::RelayParentOffsetApi<Block>,
362365
Customizations: ClientCustomizations + 'static,
363366
Net: NetworkBackend<Block, Hash>,
364367
{
@@ -654,6 +657,9 @@ where
654657
}
655658
};
656659

660+
let relay_parent_offset =
661+
client_for_xcm.runtime_api().relay_parent_offset(block)?;
662+
657663
let mocked_parachain = MockValidationDataInherentDataProvider {
658664
current_para_block,
659665
para_id: parachain_id,
@@ -664,7 +670,8 @@ where
664670
UpgradeGoAhead::GoAhead
665671
}),
666672
current_para_block_head,
667-
relay_offset: additional_relay_offset.load(Ordering::SeqCst),
673+
relay_offset: relay_parent_offset
674+
.saturating_add(additional_relay_offset.load(Ordering::SeqCst)),
668675
relay_blocks_per_para_block: 1,
669676
para_blocks_per_relay_epoch: 10,
670677
relay_randomness_config: (),

node/service/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use cumulus_client_service::{
3434
};
3535
use cumulus_primitives_core::{
3636
relay_chain::{self, well_known_keys, CollatorPair},
37-
CollectCollationInfo, ParaId,
37+
CollectCollationInfo, ParaId, RelayParentOffsetApi,
3838
};
3939
use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;
4040
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface, RelayChainResult};
@@ -1297,7 +1297,8 @@ pub async fn new_dev<RuntimeApi, Customizations, Net>(
12971297
) -> Result<TaskManager, ServiceError>
12981298
where
12991299
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi>> + Send + Sync + 'static,
1300-
RuntimeApi::RuntimeApi: RuntimeApiCollection,
1300+
RuntimeApi::RuntimeApi:
1301+
RuntimeApiCollection + cumulus_primitives_core::RelayParentOffsetApi<Block>,
13011302
Customizations: ClientCustomizations + 'static,
13021303
Net: NetworkBackend<Block, Hash>,
13031304
{
@@ -1548,6 +1549,9 @@ where
15481549
}
15491550
};
15501551

1552+
let relay_parent_offset =
1553+
client_for_xcm.runtime_api().relay_parent_offset(block)?;
1554+
15511555
let mocked_parachain = MockValidationDataInherentDataProvider {
15521556
current_para_block,
15531557
para_id: parachain_id,
@@ -1559,7 +1563,8 @@ where
15591563
UpgradeGoAhead::GoAhead
15601564
}),
15611565
current_para_block_head,
1562-
relay_offset: additional_relay_offset.load(Ordering::SeqCst),
1566+
relay_offset: relay_parent_offset
1567+
.saturating_add(additional_relay_offset.load(Ordering::SeqCst)),
15631568
relay_blocks_per_para_block: 1,
15641569
para_blocks_per_relay_epoch: 10,
15651570
relay_randomness_config: (),

node/service/src/rpc.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use sp_block_builder::BlockBuilder;
2525

2626
use crate::client::RuntimeApiCollection;
2727
use crate::RELAY_CHAIN_SLOT_DURATION_MILLIS;
28-
use cumulus_primitives_core::{ParaId, PersistedValidationData};
28+
use cumulus_primitives_core::{ParaId, PersistedValidationData, RelayParentOffsetApi};
2929
use cumulus_primitives_parachain_inherent::ParachainInherentData;
3030
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
3131
use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};
@@ -175,7 +175,7 @@ where
175175
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
176176
C: CallApiAt<Block>,
177177
C: Send + Sync + 'static,
178-
C::Api: RuntimeApiCollection,
178+
C::Api: RuntimeApiCollection + RelayParentOffsetApi<Block>,
179179
P: TransactionPool<Block = Block, Hash = <Block as BlockT>::Hash> + 'static,
180180
{
181181
use fc_rpc::{
@@ -241,10 +241,12 @@ where
241241
);
242242

243243
let maybe_current_para_head = client_for_cidp.expect_header(block);
244+
let maybe_relay_parent_offset = client_for_cidp.runtime_api().relay_parent_offset(block);
244245
async move {
245246
let current_para_block_head = Some(polkadot_primitives::HeadData(
246247
maybe_current_para_head?.encode(),
247248
));
249+
let relay_parent_offset = maybe_relay_parent_offset?;
248250

249251
let builder = RelayStateSproofBuilder {
250252
para_id,
@@ -262,8 +264,8 @@ where
262264
// Create a dummy parachain inherent data provider which is required to pass
263265
// the checks by the para chain system. We use dummy values because in the 'pending context'
264266
// neither do we have access to the real values nor do we need them.
265-
let (relay_parent_storage_root, relay_chain_state) =
266-
builder.into_state_root_and_proof();
267+
let (relay_parent_storage_root, relay_chain_state, relay_parent_descendants) =
268+
builder.into_state_root_proof_and_descendants(u64::from(relay_parent_offset));
267269

268270
let vfp = PersistedValidationData {
269271
// This is a hack to make `cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases`
@@ -277,7 +279,7 @@ where
277279
relay_chain_state,
278280
downward_messages: Default::default(),
279281
horizontal_messages: Default::default(),
280-
relay_parent_descendants: Default::default(),
282+
relay_parent_descendants,
281283
collator_peer_id: None,
282284
};
283285

runtime/common/src/apis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ macro_rules! impl_runtime_apis_plus_common {
9090

9191
impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
9292
fn relay_parent_offset() -> u32 {
93-
crate::RELAY_PARENT_OFFSET
93+
crate::AsyncBacking::relay_parent_offset()
9494
}
9595
}
9696

runtime/moonbase/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,6 @@ const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
746746
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
747747
/// into the relay chain.
748748
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
749-
/// Build with an offset of 1 behind the relay chain.
750-
const RELAY_PARENT_OFFSET: u32 = 1;
751749
/// How many parachain blocks are processed by the relay chain per parent. Limits the
752750
/// number of blocks authored per slot.
753751
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
@@ -771,7 +769,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
771769
type ConsensusHook = ConsensusHook;
772770
type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
773771
type WeightInfo = moonbase_weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
774-
type RelayParentOffset = ConstU32<0>;
772+
type RelayParentOffset = AsyncBacking;
775773
}
776774

777775
impl parachain_info::Config for Runtime {}

runtime/moonbase/tests/common/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ pub fn set_parachain_inherent_data() {
428428

429429
relay_sproof.additional_key_values = additional_key_values;
430430

431-
let (relay_parent_storage_root, relay_chain_state) = relay_sproof.into_state_root_and_proof();
431+
let (relay_parent_storage_root, relay_chain_state, relay_parent_descendants) = relay_sproof
432+
.into_state_root_proof_and_descendants(u64::from(AsyncBacking::relay_parent_offset()));
432433

433434
let vfp = PersistedValidationData {
434435
relay_parent_number: 1u32,
@@ -440,7 +441,7 @@ pub fn set_parachain_inherent_data() {
440441
validation_data: vfp,
441442
relay_chain_state,
442443
collator_peer_id: Default::default(),
443-
relay_parent_descendants: Default::default(),
444+
relay_parent_descendants,
444445
};
445446

446447
let inbound_messages_data = InboundMessagesData {

runtime/moonbeam/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,6 @@ const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
709709
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
710710
/// into the relay chain.
711711
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
712-
/// Build with an offset of 1 behind the relay chain.
713-
const RELAY_PARENT_OFFSET: u32 = 1;
714712
/// How many parachain blocks are processed by the relay chain per parent. Limits the
715713
/// number of blocks authored per slot.
716714
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
@@ -734,7 +732,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
734732
type ConsensusHook = ConsensusHook;
735733
type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
736734
type WeightInfo = moonbeam_weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
737-
type RelayParentOffset = ConstU32<0>;
735+
type RelayParentOffset = AsyncBacking;
738736
}
739737

740738
pub struct EthereumXcmEnsureProxy;

runtime/moonbeam/tests/common/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ pub fn set_parachain_inherent_data() {
444444

445445
relay_sproof.additional_key_values = additional_key_values;
446446

447-
let (relay_parent_storage_root, relay_chain_state) = relay_sproof.into_state_root_and_proof();
447+
let (relay_parent_storage_root, relay_chain_state, relay_parent_descendants) = relay_sproof
448+
.into_state_root_proof_and_descendants(u64::from(AsyncBacking::relay_parent_offset()));
448449

449450
let vfp = PersistedValidationData {
450451
relay_parent_number: 1u32,
@@ -455,7 +456,7 @@ pub fn set_parachain_inherent_data() {
455456
validation_data: vfp,
456457
relay_chain_state,
457458
collator_peer_id: Default::default(),
458-
relay_parent_descendants: Default::default(),
459+
relay_parent_descendants,
459460
};
460461

461462
let inbound_messages_data = InboundMessagesData {

runtime/moonriver/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,6 @@ const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
747747
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
748748
/// into the relay chain.
749749
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
750-
/// Build with an offset of 1 behind the relay chain.
751-
const RELAY_PARENT_OFFSET: u32 = 1;
752750
/// How many parachain blocks are processed by the relay chain per parent. Limits the
753751
/// number of blocks authored per slot.
754752
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
@@ -772,7 +770,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
772770
type ConsensusHook = ConsensusHook;
773771
type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
774772
type WeightInfo = moonriver_weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
775-
type RelayParentOffset = ConstU32<0>;
773+
type RelayParentOffset = AsyncBacking;
776774
}
777775

778776
impl parachain_info::Config for Runtime {}

0 commit comments

Comments
 (0)