Skip to content

Commit

Permalink
Merge pull request #73 from moonbeam-foundation/rq/add-try-runtime
Browse files Browse the repository at this point in the history
add try-runtime and update to polkadot-sdk 1.7.2
  • Loading branch information
RomarQ authored Mar 7, 2024
2 parents 7c403c0 + d5abea5 commit c6d6d11
Show file tree
Hide file tree
Showing 8 changed files with 1,808 additions and 791 deletions.
2,464 changes: 1,746 additions & 718 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ version = '0.6.0'
description = "Reward citizens who participated in a crowdloan to acquire a parachain slot o nthe backing relay chain."

[dependencies]
parity-scale-codec = { version = "3.1.5", default-features = false}
serde = { version = "1.0.101", optional = true, features = ["derive"], default-features = false }
log = { version = "0.4", default-features = false }
scale-info = { version = "2.0", default-features = false, features = ["derive"] }

frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.43" }
ed25519-dalek = { version = "1.0.1", default-features = false, features = ["u64_backend", "alloc"], optional = true }
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.43" }
log = { version = "0.4.20", default-features = false }
parity-scale-codec = { version = "3.6.5", default-features = false}
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.188", optional = true, features = ["derive"], default-features = false }

frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true , branch = "release-polkadot-v1.7.2" }
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true , branch = "release-polkadot-v1.7.2" }

[features]
default = ["std"]
Expand All @@ -46,3 +46,4 @@ runtime-benchmarks = [
"ed25519-dalek",
"sp-runtime/runtime-benchmarks"
]
try-runtime = ["frame-support/try-runtime"]
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2022-11-14"
channel = "1.74.0"
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
16 changes: 9 additions & 7 deletions src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{BalanceOf, Call, Pallet, WRAPPED_BYTES_POSTFIX, WRAPPED_BYTES_PREFIX
use ed25519_dalek::Signer;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::traits::{Currency, Get, OnFinalize};
use frame_system::pallet_prelude::*;
use frame_system::RawOrigin;
use parity_scale_codec::Encode;
use sp_core::{
Expand Down Expand Up @@ -159,7 +160,7 @@ benchmarks! {

// We need to create the first block inherent, to initialize the initRelayBlock
T::VestingBlockProvider::set_block_number(1u32.into());
Pallet::<T>::on_finalize(T::BlockNumber::one());
Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());

}: _(RawOrigin::Root, 10u32.into())
verify {
Expand Down Expand Up @@ -187,7 +188,7 @@ benchmarks! {

// First inherent
T::VestingBlockProvider::set_block_number(1u32.into());
Pallet::<T>::on_finalize(T::BlockNumber::one());
Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());

// Create 4th relay block, by now the user should have vested some amount
T::VestingBlockProvider::set_block_number(4u32.into());
Expand Down Expand Up @@ -218,7 +219,7 @@ benchmarks! {

// First inherent
T::VestingBlockProvider::set_block_number(1u32.into());
Pallet::<T>::on_finalize(T::BlockNumber::one());
Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());


// Let's advance the relay so that the vested amount get transferred
Expand Down Expand Up @@ -263,7 +264,7 @@ benchmarks! {

// First inherent
T::VestingBlockProvider::set_block_number(1u32.into());
Pallet::<T>::on_finalize(T::BlockNumber::one());
Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());

}: _(RawOrigin::Signed(caller.clone()), caller.clone(), relay_account.into(), signature)
verify {
Expand Down Expand Up @@ -317,7 +318,7 @@ benchmarks! {

// First inherent
T::VestingBlockProvider::set_block_number(1u32.into());
Pallet::<T>::on_finalize(T::BlockNumber::one());
Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());

}: _(RawOrigin::Signed(first_reward_account.clone()), second_reward_account.clone(), first_reward_account.clone(), proofs)
verify {
Expand All @@ -332,10 +333,11 @@ benchmarks! {
mod tests {
use crate::mock::Test;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@

#![cfg_attr(not(feature = "std"), no_std)]

pub use crate::weights::WeightInfo;
use frame_support::pallet;
pub use pallet::*;

#[cfg(any(test, feature = "runtime-benchmarks"))]
mod benchmarks;
#[cfg(test)]
Expand All @@ -72,8 +74,7 @@ pub mod weights;

#[pallet]
pub mod pallet {

use crate::weights::WeightInfo;
use super::*;
use frame_support::traits::WithdrawReasons;
use frame_support::{
pallet_prelude::*,
Expand Down Expand Up @@ -167,7 +168,7 @@ pub mod pallet {
// This hook is in charge of initializing the vesting height at the first block of the parachain
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(n: <T as frame_system::Config>::BlockNumber) {
fn on_finalize(n: BlockNumberFor<T>) {
// In the first block of the parachain we need to introduce the vesting block related info
if n == 1u32.into() {
<InitVestingBlock<T>>::put(T::VestingBlockProvider::current_block_number());
Expand Down Expand Up @@ -695,7 +696,6 @@ pub mod pallet {
pub funded_amount: BalanceOf<T>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
Expand All @@ -705,7 +705,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
// This sets the funds of the crowdloan pallet
fn build(&self) {
T::RewardCurrency::deposit_creating(&Pallet::<T>::account_id(), self.funded_amount);
Expand Down
33 changes: 14 additions & 19 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@
use crate::{self as pallet_crowdloan_rewards, Config};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU32, GenesisBuild, Nothing, OnFinalize, OnInitialize},
traits::{ConstU32, Nothing, OnFinalize, OnInitialize},
};
use frame_system::EnsureSigned;
use sp_core::{ed25519, Pair, H256};
use sp_io;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Perbill,
BuildStorage, Perbill,
};
use sp_std::convert::{From, TryInto};

pub type Balance = u128;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Crowdloan: pallet_crowdloan_rewards::{Pallet, Call, Storage, Event<T>},
Utility: pallet_utility::{Pallet, Call, Storage, Event},
System: frame_system,
Balances: pallet_balances,
Crowdloan: pallet_crowdloan_rewards,
Utility: pallet_utility,
}
);

Expand All @@ -57,14 +52,14 @@ impl frame_system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeTask = RuntimeTask;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = u64;
type Block = Block;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
Expand Down Expand Up @@ -93,10 +88,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
type RuntimeFreezeReason = ();
}

pub struct MockedBlockProvider;
Expand Down Expand Up @@ -148,8 +143,8 @@ impl pallet_utility::Config for Test {
}

fn genesis(funded_amount: Balance) -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut storage = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
pallet_crowdloan_rewards::GenesisConfig::<Test> { funded_amount }
.assimilate_storage(&mut storage)
Expand Down
3 changes: 1 addition & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
//! Unit testing

use crate::*;
use frame_support::dispatch::{DispatchError, Dispatchable};
use frame_support::{assert_noop, assert_ok};
use mock::*;
use parity_scale_codec::Encode;
use sp_core::Pair;
use sp_runtime::{ModuleError, MultiSignature};
use sp_runtime::{traits::Dispatchable, DispatchError, ModuleError, MultiSignature};

// Constant that reflects the desired vesting period for the tests
// Most tests complete initialization passing initRelayBlock + VESTING as the endRelayBlock
Expand Down
40 changes: 16 additions & 24 deletions src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,38 @@ pub trait WeightInfo {
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn initialize_reward_vec(x: u32) -> Weight {
Weight::from_ref_time(143_109_000)
Weight::from_all(143_109_000)
// Standard Error: 21_000
.saturating_add(Weight::from_ref_time(
72_298_000_u64.saturating_mul(x as u64),
))
.saturating_add(Weight::from_all(72_298_000_u64.saturating_mul(x as u64)))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().reads(x as u64))
.saturating_add(T::DbWeight::get().writes(5))
.saturating_add(T::DbWeight::get().writes(3 as u64))
}
fn complete_initialization() -> Weight {
Weight::from_ref_time(51_047_000)
Weight::from_all(51_047_000)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}
fn claim() -> Weight {
Weight::from_ref_time(101_484_000)
Weight::from_all(101_484_000)
.saturating_add(T::DbWeight::get().reads(11))
.saturating_add(T::DbWeight::get().writes(5))
}
fn update_reward_address() -> Weight {
Weight::from_ref_time(59_051_000)
Weight::from_all(59_051_000)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}
fn associate_native_identity() -> Weight {
Weight::from_ref_time(152_997_000)
Weight::from_all(152_997_000)
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(7))
}
fn change_association_with_relay_keys(x: u32) -> Weight {
Weight::from_ref_time(0)
Weight::from_all(0)
// Standard Error: 7_000
.saturating_add(Weight::from_ref_time(
47_373_000_u64.saturating_mul(x as u64),
))
.saturating_add(Weight::from_all(47_373_000_u64.saturating_mul(x as u64)))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}
Expand All @@ -107,42 +103,38 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
fn initialize_reward_vec(x: u32) -> Weight {
Weight::from_ref_time(143_109_000)
Weight::from_all(143_109_000)
// Standard Error: 21_000
.saturating_add(Weight::from_ref_time(
72_298_000_u64.saturating_mul(x as u64),
))
.saturating_add(Weight::from_all(72_298_000_u64.saturating_mul(x as u64)))
.saturating_add(RocksDbWeight::get().reads(8))
.saturating_add(RocksDbWeight::get().reads(x as u64))
.saturating_add(RocksDbWeight::get().writes(5))
.saturating_add(RocksDbWeight::get().writes(x as u64))
}
fn complete_initialization() -> Weight {
Weight::from_ref_time(51_047_000)
Weight::from_all(51_047_000)
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(3))
}
fn claim() -> Weight {
Weight::from_ref_time(101_484_000)
Weight::from_all(101_484_000)
.saturating_add(RocksDbWeight::get().reads(11))
.saturating_add(RocksDbWeight::get().writes(5))
}
fn update_reward_address() -> Weight {
Weight::from_ref_time(59_051_000)
Weight::from_all(59_051_000)
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4))
}
fn associate_native_identity() -> Weight {
Weight::from_ref_time(152_997_000)
Weight::from_all(152_997_000)
.saturating_add(RocksDbWeight::get().reads(9))
.saturating_add(RocksDbWeight::get().writes(7))
}
fn change_association_with_relay_keys(x: u32) -> Weight {
Weight::from_ref_time(0)
Weight::from_all(0)
// Standard Error: 7_000
.saturating_add(Weight::from_ref_time(
47_373_000_u64.saturating_mul(x as u64),
))
.saturating_add(Weight::from_all(47_373_000_u64.saturating_mul(x as u64)))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4))
}
Expand Down

0 comments on commit c6d6d11

Please sign in to comment.