From 3b17b91f03e84accef6a53c53ff66dfad85848ee Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Mon, 20 May 2024 20:16:50 -0700 Subject: [PATCH 1/3] fix async backing implementation on moonriver --- Cargo.lock | 3 +++ node/cli/src/command.rs | 2 +- runtime/common/Cargo.toml | 7 ++++++- runtime/common/src/lib.rs | 1 + runtime/{moonbase => common}/src/timestamp.rs | 13 +++++++++---- runtime/moonbase/src/lib.rs | 10 ++++++---- runtime/moonriver/Cargo.toml | 1 + runtime/moonriver/src/lib.rs | 12 ++++++++---- runtime/moonriver/tests/common/mod.rs | 19 +++++++++++++++++-- runtime/moonriver/tests/integration_test.rs | 12 ++++++------ 10 files changed, 58 insertions(+), 22 deletions(-) rename runtime/{moonbase => common}/src/timestamp.rs (89%) diff --git a/Cargo.lock b/Cargo.lock index a610ea160a5..9adedae07a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6783,6 +6783,7 @@ name = "moonbeam-runtime-common" version = "0.8.0-dev" dependencies = [ "account", + "cumulus-pallet-parachain-system", "cumulus-pallet-xcmp-queue", "fp-ethereum", "fp-evm", @@ -6793,6 +6794,7 @@ dependencies = [ "hex-literal 0.3.4", "impl-trait-for-tuples", "log", + "moonbeam-core-primitives", "moonbeam-xcm-benchmarks", "nimbus-primitives", "pallet-asset-manager", @@ -7162,6 +7164,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-std", + "sp-timestamp", "sp-transaction-pool", "sp-version", "sp-weights", diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 3e5a1758931..e82fd3a3644 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -794,7 +794,7 @@ pub fn run() -> Result<()> { collator_options, id, rpc_config, - false, + true, cli.run.block_authoring_duration, hwbench, ) diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 309b6700792..a6e2387eabd 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -13,6 +13,7 @@ impl-trait-for-tuples = "0.2.1" log = "0.4" # Moonbeam +moonbeam-core-primitives = { workspace = true } moonbeam-xcm-benchmarks = { workspace = true } pallet-asset-manager = { workspace = true } pallet-author-mapping = { workspace = true } @@ -29,6 +30,7 @@ precompile-utils = { workspace = true } xcm-primitives = { workspace = true } # Substrate +cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } frame-benchmarking = { workspace = true } frame-support = { workspace = true } @@ -82,9 +84,11 @@ account = { workspace = true } [features] std = [ + "cumulus-pallet-parachain-system/std", "fp-ethereum/std", "fp-evm/std", "frame-support/std", + "moonbeam-core-primitives/std", "pallet-asset-manager/std", "pallet-async-backing/std", "pallet-author-inherent/std", @@ -111,6 +115,7 @@ std = [ "account/std", ] runtime-benchmarks = [ + "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "pallet-asset-manager/runtime-benchmarks", @@ -143,4 +148,4 @@ runtime-benchmarks = [ "pallet-moonbeam-lazy-migrations/runtime-benchmarks", "moonbeam-xcm-benchmarks/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime", "pallet-migrations/try-runtime"] +try-runtime = ["cumulus-pallet-parachain-system/try-runtime", "frame-support/try-runtime", "pallet-migrations/try-runtime"] diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index a905eb57218..747a8a326b8 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ mod impl_on_charge_evm_transaction; mod impl_self_contained_call; mod impl_xcm_evm_runner; pub mod migrations; +pub mod timestamp; pub mod weights; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/moonbase/src/timestamp.rs b/runtime/common/src/timestamp.rs similarity index 89% rename from runtime/moonbase/src/timestamp.rs rename to runtime/common/src/timestamp.rs index 4df4eca60a3..82a67ef3082 100644 --- a/runtime/moonbase/src/timestamp.rs +++ b/runtime/common/src/timestamp.rs @@ -16,7 +16,6 @@ //! A way to get a relyable timestamp -use crate::Runtime; use cumulus_pallet_parachain_system::{ consensus_hook::UnincludedSegmentCapacity, relay_state_snapshot::{self, ReadEntryErr}, @@ -39,9 +38,15 @@ impl Time for RelayTimestamp { } } -/// A wrapper around the consensus hook to get the relay timlestmap from the relay storage proof -pub struct ConsensusHookWrapperForRelayTimestamp(core::marker::PhantomData); -impl ConsensusHook for ConsensusHookWrapperForRelayTimestamp { +/// A wrapper around the consensus hook to get the relay timestamp from the relay storage proof +pub struct ConsensusHookWrapperForRelayTimestamp( + core::marker::PhantomData<(Runtime, Inner)>, +); +impl ConsensusHook for ConsensusHookWrapperForRelayTimestamp +where + Runtime: frame_system::Config, + Inner: ConsensusHook, +{ fn on_state_proof(state_proof: &RelayChainStateProof) -> (Weight, UnincludedSegmentCapacity) { let relay_timestamp: u64 = match state_proof.read_entry(well_known_relay_keys::TIMESTAMP_NOW, None) { diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 307e2b4995a..c072d3ec5ec 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -30,7 +30,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod asset_config; pub mod governance; -pub mod timestamp; pub mod xcm_config; mod migrations; @@ -79,7 +78,10 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSigned}; use governance::councils::*; use moonbeam_rpc_primitives_txpool::TxPoolResponse; -use moonbeam_runtime_common::weights as moonbeam_weights; +use moonbeam_runtime_common::{ + timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp}, + weights as moonbeam_weights, +}; use nimbus_primitives::CanAuthor; use pallet_ethereum::Call::transact; use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; @@ -520,7 +522,7 @@ impl pallet_evm::Config for Runtime { type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type SuicideQuickClearLimit = ConstU32<0>; type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; - type Timestamp = crate::timestamp::RelayTimestamp; + type Timestamp = RelayTimestamp; type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo; } @@ -739,7 +741,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type XcmpMessageHandler = EmergencyParaXcm; type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = EmergencyParaXcm; - type ConsensusHook = crate::timestamp::ConsensusHookWrapperForRelayTimestamp; + type ConsensusHook = ConsensusHookWrapperForRelayTimestamp; type DmpQueue = frame_support::traits::EnqueueWithOrigin; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 554deaa2e8c..2ab9b858635 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -181,6 +181,7 @@ sha3 = { workspace = true, features = ["std"] } cumulus-primitives-parachain-inherent = { workspace = true } cumulus-test-relay-sproof-builder = { workspace = true } +sp-timestamp = { workspace = true } polkadot-runtime-parachains = { workspace = true } xcm-simulator = { workspace = true } diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 6a4071ccc60..201f9a4c005 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -64,7 +64,10 @@ pub use moonbeam_core_primitives::{ Index, Signature, }; use moonbeam_rpc_primitives_txpool::TxPoolResponse; -use moonbeam_runtime_common::weights as moonbeam_weights; +use moonbeam_runtime_common::{ + timestamp::{ConsensusHookWrapperForRelayTimestamp, RelayTimestamp}, + weights as moonbeam_weights, +}; use pallet_ethereum::Call::transact; use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; use pallet_evm::{ @@ -507,7 +510,7 @@ impl pallet_evm::Config for Runtime { type GasLimitPovSizeRatio = GasLimitPovSizeRatio; type SuicideQuickClearLimit = ConstU32<0>; type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; - type Timestamp = Timestamp; + type Timestamp = RelayTimestamp; type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo; } @@ -724,8 +727,9 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; - type ConsensusHook = cumulus_pallet_parachain_system::ExpectParentIncluded; + type CheckAssociatedRelayNumber = + cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type ConsensusHook = ConsensusHookWrapperForRelayTimestamp; type DmpQueue = frame_support::traits::EnqueueWithOrigin; type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; } diff --git a/runtime/moonriver/tests/common/mod.rs b/runtime/moonriver/tests/common/mod.rs index c4b5ec77aa8..81747067292 100644 --- a/runtime/moonriver/tests/common/mod.rs +++ b/runtime/moonriver/tests/common/mod.rs @@ -32,6 +32,7 @@ pub use moonriver_runtime::{ UncheckedExtrinsic, HOURS, WEEKS, }; use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; +use polkadot_parachain::primitives::HeadData; use sp_consensus_slots::Slot; use sp_core::{Encode, H160}; use sp_runtime::{traits::Dispatchable, BuildStorage, Digest, DigestItem, Perbill, Percent}; @@ -85,6 +86,8 @@ pub fn run_to_block(n: u32, author: Option) { } } + increase_last_relay_slot_number(1); + // Initialize the new block AuthorInherent::on_initialize(System::block_number()); ParachainStaking::on_initialize(System::block_number()); @@ -347,8 +350,20 @@ pub fn root_origin() -> ::RuntimeOrigin { pub fn set_parachain_inherent_data() { use cumulus_primitives_core::PersistedValidationData; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; - let (relay_parent_storage_root, relay_chain_state) = - RelayStateSproofBuilder::default().into_state_root_and_proof(); + + let mut relay_sproof = RelayStateSproofBuilder::default(); + relay_sproof.para_id = 100u32.into(); + relay_sproof.included_para_head = Some(HeadData(vec![1, 2, 3])); + + let additional_key_values = vec![( + moonbeam_core_primitives::well_known_relay_keys::TIMESTAMP_NOW.to_vec(), + sp_timestamp::Timestamp::default().encode(), + )]; + + relay_sproof.additional_key_values = additional_key_values; + + let (relay_parent_storage_root, relay_chain_state) = relay_sproof.into_state_root_and_proof(); + let vfp = PersistedValidationData { relay_parent_number: 1u32, relay_parent_storage_root, diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index 1f669ff4ccc..a2b57635de2 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -631,11 +631,11 @@ fn reward_block_authors() { // rewards minted and distributed assert_eq!( Balances::usable_balance(AccountId::from(ALICE)), - 10101206388888506666666, + 11547666666208000000000, ); assert_eq!( Balances::usable_balance(AccountId::from(BOB)), - 9500047777777156666667, + 9557333332588000000000, ); }); } @@ -683,7 +683,7 @@ fn reward_block_authors_with_parachain_bond_reserved() { // 30% reserved for parachain bond assert_eq!( Balances::usable_balance(AccountId::from(CHARLIE)), - 1376262500000000000, + 452515000000000000000, ); // Go to round 3 @@ -692,16 +692,16 @@ fn reward_block_authors_with_parachain_bond_reserved() { // rewards minted and distributed assert_eq!( Balances::usable_balance(AccountId::from(ALICE)), - 10100848083729919833333, + 11117700475903800000000, ); assert_eq!( Balances::usable_balance(AccountId::from(BOB)), - 9500029862102786395833, + 9535834523343675000000, ); // 30% reserved for parachain bond again assert_eq!( Balances::usable_balance(AccountId::from(CHARLIE)), - 1376262500000000000, + 910802725000000000000, ); }); } From d48902ada04a42c3fbb6fbbaeefdc3f68cbabcb1 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Tue, 21 May 2024 09:35:11 -0700 Subject: [PATCH 2/3] fix staking consts --- runtime/moonriver/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 201f9a4c005..36b413b4c7f 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -837,8 +837,8 @@ impl pallet_parachain_staking::Config for Runtime { type SlotProvider = RelayChainSlotProvider; type WeightInfo = moonbeam_weights::pallet_parachain_staking::WeightInfo; type MaxCandidates = ConstU32<200>; - type SlotDuration = ConstU64<12_000>; - type BlockTime = ConstU64<12_000>; + type SlotDuration = ConstU64<6_000>; + type BlockTime = ConstU64<6_000>; } impl pallet_author_inherent::Config for Runtime { From 25738d174c04227f7263f994881944c72300e170 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Tue, 21 May 2024 09:39:18 -0700 Subject: [PATCH 3/3] set MinimumPeriod to 3000 millisecs --- runtime/moonriver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 36b413b4c7f..15b72ee0122 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -287,7 +287,7 @@ impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; type OnTimestampSet = (); - type MinimumPeriod = ConstU64<6000>; + type MinimumPeriod = ConstU64<3000>; type WeightInfo = moonbeam_weights::pallet_timestamp::WeightInfo; }