Skip to content

Commit

Permalink
Enable try-runtime feature (availproject#129)
Browse files Browse the repository at this point in the history
* Enable `try-runtime` feature
* Add migration Nomination pools & try-runtime support
  • Loading branch information
MiguelDD1 authored Jan 9, 2023
1 parent 4a15ef7 commit fb4a414
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 143 deletions.
21 changes: 1 addition & 20 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ nomad-base = { git="https://github.com/maticnetwork/avail-core", version = "0.1.
nomad-core = { git="https://github.com/maticnetwork/avail-core", version = "0.1.2", tag = "da-primitives/v0.4.2" }

# Other stuff
syn = { git = "https://github.com/dtolnay/syn.git", tag = "1.0.96" }
primitive-types = { git = "https://github.com/paritytech/parity-common.git", tag = "rlp-v0.5.2" }
parity-db = { git = "https://github.com/paritytech/parity-db.git", tag = "v0.3.12" }
parity-util-mem = { git = "https://github.com/paritytech/parity-common.git", tag = "rlp-v0.5.2" }
uint = { git = "https://github.com/paritytech/parity-common.git", tag="rlp-v0.5.2" }
rlp = { git = "https://github.com/paritytech/parity-common.git", tag="rlp-v0.5.2" }
Expand Down Expand Up @@ -133,8 +131,6 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate.git", branch
pallet-child-bounties = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
pallet-preimage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
pallet-nomination-pools = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
pallet-election-provider-support-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }


Expand Down
5 changes: 3 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ substrate-state-trie-migration-rpc = "4.0.0-dev"
frame-benchmarking = "4.0.0-dev"
frame-benchmarking-cli = "4.0.0-dev"

# Try-runtime
try-runtime-cli = { version = "0.10.0-dev", optional = true }

[build-dependencies]
substrate-build-script-utils = "3.0.0"
clap = { version = "4.0.9", optional = true }
clap_complete = { version = "4.0.2", optional = true }
try-runtime-cli = { version = "0.10.0-dev", optional = true }
frame-benchmarking-cli = { version = "4.0.0-dev", optional = true }

[dev-dependencies]
Expand All @@ -123,7 +125,6 @@ default = ["cli"]
cli = [
"clap",
"clap_complete",
"try-runtime-cli",
"frame-benchmarking-cli",
]
runtime-benchmarks = [
Expand Down
26 changes: 15 additions & 11 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use da_control::AppKeyInfo;
use da_primitives::currency::AVL;
use da_runtime::{
wasm_binary_unwrap, AccountId, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig,
Block, CouncilConfig, DataAvailabilityConfig, DemocracyConfig, DesiredMembers, ElectionsConfig,
GenesisConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations, NomadHomeConfig,
NominationPoolsConfig, SessionConfig, SessionKeys, Signature, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, TechnicalCommitteeConfig, UpdaterManagerConfig,
constants, wasm_binary_unwrap, AccountId, AuthorityDiscoveryConfig, BabeConfig, Balance,
BalancesConfig, Block, CouncilConfig, DataAvailabilityConfig, DemocracyConfig, DesiredMembers,
ElectionsConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations,
NomadHomeConfig, NominationPoolsConfig, SessionConfig, SessionKeys, Signature, StakerStatus,
StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, UpdaterManagerConfig,
};
use frame_system::limits::BlockLength;
use kate::config::{MAX_BLOCK_COLUMNS, MAX_BLOCK_ROWS};
Expand Down Expand Up @@ -339,9 +339,11 @@ pub fn testnet_genesis(
},
da_bridge: Default::default(),
nomination_pools: NominationPoolsConfig {
min_create_bond: 10 * AVL,
min_join_bond: 1 * AVL,
..Default::default()
min_create_bond: constants::nomination_pools::MIN_CREATE_BOND,
min_join_bond: constants::nomination_pools::MIN_JOIN_BOND,
max_pools: Some(constants::nomination_pools::MAX_POOLS),
max_members_per_pool: Some(constants::nomination_pools::MAX_MEMBERS_PER_POOL),
max_members: Some(constants::nomination_pools::MAX_MEMBERS),
},
}
}
Expand Down Expand Up @@ -501,9 +503,11 @@ fn genesis_builder(
nomad_home: Default::default(),
da_bridge: Default::default(),
nomination_pools: NominationPoolsConfig {
min_create_bond: 10 * AVL,
min_join_bond: 1 * AVL,
..Default::default()
min_create_bond: constants::nomination_pools::MIN_CREATE_BOND,
min_join_bond: constants::nomination_pools::MIN_JOIN_BOND,
max_pools: Some(constants::nomination_pools::MAX_POOLS),
max_members_per_pool: Some(constants::nomination_pools::MAX_MEMBERS_PER_POOL),
max_members: Some(constants::nomination_pools::MAX_MEMBERS),
},
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/dactr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
9 changes: 5 additions & 4 deletions pallets/executive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false }
frame-system = { version = "4.0.0-dev", default-features = false }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, optional = true }
sp-runtime = { version = "6.0.0", default-features = false }
sp-tracing = { version = "5.0.0", default-features = false}
sp-std = { version = "4.0.0", default-features = false }
Expand All @@ -44,14 +45,14 @@ default = ["std"]
with-tracing = ["sp-tracing/with-tracing"]
std = [
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-tracing/std",
"sp-std/std",
"sp-io/std",
"sp-tracing/std",
"da-primitives/std",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = ["frame-support/try-runtime", "frame-try-runtime/try-runtime" ]
4 changes: 2 additions & 2 deletions pallets/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,13 @@ mod tests {
block_import_works_inner(
new_test_ext_v0(1),
array_bytes::hex_n_into_unchecked(
"29e2f2885158e4179d302f7f7ed0a64e75423a1fc2cf1d6fdc4219cd30023792",
"6d988b132b3dc0200c6d8102274428b9f58024fbb32c210b8b432302bc85be17",
),
);
block_import_works_inner(
new_test_ext(1),
array_bytes::hex_n_into_unchecked(
"0c32c81e9258686fdb492888b7630e757096548842326e5d603138474ca2e49d",
"0b93b0592690a181d6e080c6cc73108793e0447c24ad82145c763b798d94edc7",
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ pub mod pallet {
sp_io::storage::set(KATE_PUBLIC_PARAMS, &self.kc_public_params);
<DynamicBlockLength<T>>::put(&self.block_length);

StorageVersion::new(2).put::<Pallet<T>>();
StorageVersion::new(1).put::<Pallet<T>>();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/system/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use frame_support::{
use sp_std::prelude::*;

use crate::{Config, Pallet};
pub mod v1;

/// Type used to encode the number of references an account has.
type RefCount = u32;
Expand Down
116 changes: 21 additions & 95 deletions pallets/system/src/migrations/v1.rs
Original file line number Diff line number Diff line change
@@ -1,101 +1,27 @@
use codec::Decode;
use frame_support::traits::{Get, StorageVersion};
use frame_support::weights::Weight;
use sp_core::Get;

use crate::{Account, AccountInfo, Config, Pallet, RefCount, UpgradedToTripleRefCount, Weight};
/// # V1 Migrations
/// - `BlockLength` migration to `DynamicBlockLength`.
/// - `AllExtrinsicLen` from single `u32` into `ExtrinsicLen` type.
use crate::{limits::BlockLength, AllExtrinsicsLen, Config, DynamicBlockLength, ExtrinsicLen};

pub fn migrate<T: Config>() -> Weight {
// Original pallet migrations
let mut weight = if !UpgradedToTripleRefCount::<T>::get() {
UpgradedToTripleRefCount::<T>::put(true);
migrate_to_triple_ref_count::<T>()
} else {
0
};

// Polygon versions.
let curr_version = StorageVersion::get::<Pallet<T>>();
if curr_version < 1 {
weight = weight.saturating_add(v1::migrate::<T>());
}

// Update the pallet version.
StorageVersion::new(1).put::<Pallet<T>>();
weight.saturating_add(T::DbWeight::get().reads_writes(0, 1))
}
pub const BLOCK_LENGTH: &[u8] = b":block_length:";

#[allow(dead_code)]
/// Migrate from unique `u8` reference counting to triple `u32` reference counting.
pub fn migrate_all<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, u8, T::AccountData), _>(|_key, (nonce, rc, data)| {
Some(AccountInfo {
nonce,
consumers: rc as RefCount,
providers: 1,
sufficients: 0,
data,
})
pub fn migrate<T: Config>() -> Weight {
let mut weight = Weight::zero();

// 1. Raw storage ":block_length:" into `System::DynamicBlockLength`.
let encoded_block_len = sp_io::storage::get(BLOCK_LENGTH).unwrap_or_default();
let block_len = BlockLength::decode(&mut &encoded_block_len[..]).unwrap_or_default();
DynamicBlockLength::<T>::put(block_len);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));

// 2. Storage `AllExtrinsicsLen` from `u32` to `ExtrinsicLen`.
// As it is called before `on_initialize`, it should be 0.
let _ = <AllExtrinsicsLen<T>>::translate(|maybe_len: Option<u32>| -> Option<ExtrinsicLen> {
maybe_len.map(|_| ExtrinsicLen::default())
});
T::BlockWeights::get().max_block
}

#[allow(dead_code)]
/// Migrate from unique `u32` reference counting to triple `u32` reference counting.
pub fn migrate_to_dual_ref_count<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, RefCount, T::AccountData), _>(
|_key, (nonce, consumers, data)| {
Some(AccountInfo {
nonce,
consumers,
providers: 1,
sufficients: 0,
data,
})
},
);
T::BlockWeights::get().max_block
}

/// Migrate from dual `u32` reference counting to triple `u32` reference counting.
pub fn migrate_to_triple_ref_count<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, RefCount, RefCount, T::AccountData), _>(
|_key, (nonce, consumers, providers, data)| {
Some(AccountInfo {
nonce,
consumers,
providers,
sufficients: 0,
data,
})
},
);
T::BlockWeights::get().max_block
}

/// V1 Migrations
/// -
mod v1 {
use super::*;
use crate::{limits::BlockLength, AllExtrinsicsLen, DynamicBlockLength, ExtrinsicLen};

pub const BLOCK_LENGTH: &[u8] = b":block_length:";

pub fn migrate<T: Config>() -> Weight {
let mut weight: Weight = 0;

// 1. Raw storage ":block_length:" into `System::DynamicBlockLength`.
let encoded_block_len = sp_io::storage::get(BLOCK_LENGTH).unwrap_or_default();
let block_len = BlockLength::decode(&mut &encoded_block_len[..]).unwrap_or_default();
DynamicBlockLength::<T>::put(block_len);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));

// 2. Storage `AllExtrinsicsLen` from `u32` to `ExtrinsicLen`.
// As it is called before `on_initialize`, it should be 0.
let _ =
<AllExtrinsicsLen<T>>::translate(|maybe_len: Option<u32>| -> Option<ExtrinsicLen> {
maybe_len.map(|_| ExtrinsicLen::default())
});
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));

weight
}
weight.saturating_add(T::DbWeight::get().reads_writes(1, 1))
}
33 changes: 32 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,36 @@ try-runtime = [
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",

"da-control/try-runtime",
"nomad-home/try-runtime",
"da-bridge/try-runtime",
"nomad-updater-manager/try-runtime",
"pallet-utility/try-runtime",
"pallet-babe/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-authorship/try-runtime",
"pallet-indices/try-runtime",
"pallet-balances/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-staking/try-runtime",
"pallet-session/try-runtime",
"pallet-democracy/try-runtime",
"pallet-collective/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-membership/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-treasury/try-runtime",
"pallet-sudo/try-runtime",
"pallet-im-online/try-runtime",
"pallet-authority-discovery/try-runtime",
"pallet-offences/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-bounties/try-runtime",
"pallet-mmr/try-runtime",
"pallet-preimage/try-runtime",
"pallet-multisig/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-tips/try-runtime",
]
16 changes: 15 additions & 1 deletion runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

//! A set of constant values used in substrate runtime.
use da_primitives::currency::Balance;

/// Money matters.
pub mod currency {
use da_primitives::currency::Balance;
use super::Balance;

pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
Expand Down Expand Up @@ -72,6 +74,18 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;
}

pub mod nomination_pools {
use da_primitives::currency::AVL;

use super::Balance;

pub const MIN_CREATE_BOND: Balance = 10 * AVL;
pub const MIN_JOIN_BOND: Balance = 1 * AVL;
pub const MAX_POOLS: u32 = 16;
pub const MAX_MEMBERS_PER_POOL: u32 = 100;
pub const MAX_MEMBERS: u32 = MAX_POOLS * MAX_MEMBERS_PER_POOL;
}

/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
Expand Down
Loading

0 comments on commit fb4a414

Please sign in to comment.