diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 75c4a53ed4f37..e5b0690cb98ab 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -209,12 +209,12 @@ decl_module! { Lateness::::kill(); } + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { for i in 0..=SegmentIndex::get() { UnderConstruction::migrate_key_from_blake(i); } - // TODO: determine weight - 0 + T::MaximumBlockWeight::get() } } } diff --git a/frame/balances/src/migration.rs b/frame/balances/src/migration.rs index ace17f63fd386..8153d61a1fc24 100644 --- a/frame/balances/src/migration.rs +++ b/frame/balances/src/migration.rs @@ -32,6 +32,7 @@ pub fn on_runtime_upgrade, I: Instance>() -> Weight { } // Upgrade from the pre-#4649 balances/vesting into the new balances. +// The accounts migration is so big we just assume it consumes the whole block. fn upgrade_v1_to_v2, I: Instance>() -> Weight { sp_runtime::print("🕊️ Migrating Account Balances..."); // First, migrate from old FreeBalance to new Account. @@ -140,6 +141,5 @@ fn upgrade_v1_to_v2, I: Instance>() -> Weight { StorageVersion::::put(Releases::V2_0_0); sp_runtime::print("🕊️ Done Account Balances."); - // TODO determine actual weight? T::MaximumBlockWeight::get() } diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 410e458e1d569..0a222b8fbfe10 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -352,10 +352,10 @@ decl_module! { fn deposit_event() = default; + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } /// Set the collective's membership. diff --git a/frame/contracts/src/migration.rs b/frame/contracts/src/migration.rs index 39f6657dc0634..6a19cd57faec2 100644 --- a/frame/contracts/src/migration.rs +++ b/frame/contracts/src/migration.rs @@ -17,13 +17,83 @@ //! Migration code to update storage. use super::*; -use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; +use frame_support::storage::migration::{ remove_storage_prefix, take_storage_value, StorageIterator}; use frame_support::weights::Weight; +use frame_support::runtime_print; + +use crate::gas::Gas; pub fn on_runtime_upgrade() -> Weight { - // TODO: removed for now because it's failing - // change_name_contract_to_contracts::() - 0 + change_name_contract_to_contracts::() +} + +mod deprecated { + use super::*; + + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] + pub struct Schedule { + /// Version of the schedule. + pub version: u32, + + /// Cost of putting a byte of code into storage. + pub put_code_per_byte_cost: Gas, + + /// Gas cost of a growing memory by single page. + pub grow_mem_cost: Gas, + + /// Gas cost of a regular operation. + pub regular_op_cost: Gas, + + /// Gas cost per one byte returned. + pub return_data_per_byte_cost: Gas, + + /// Gas cost to deposit an event; the per-byte portion. + pub event_data_per_byte_cost: Gas, + + /// Gas cost to deposit an event; the cost per topic. + pub event_per_topic_cost: Gas, + + /// Gas cost to deposit an event; the base. + pub event_base_cost: Gas, + + /// Base gas cost to call into a contract. + pub call_base_cost: Gas, + + /// Base gas cost to instantiate a contract. + pub instantiate_base_cost: Gas, + + /// Gas cost per one byte read from the sandbox memory. + pub sandbox_data_read_cost: Gas, + + /// Gas cost per one byte written to the sandbox memory. + pub sandbox_data_write_cost: Gas, + + /// Cost for a simple balance transfer. + pub transfer_cost: Gas, + + /// The maximum number of topics supported by an event. + pub max_event_topics: u32, + + /// Maximum allowed stack height. + /// + /// See https://wiki.parity.io/WebAssembly-StackHeight to find out + /// how the stack frame cost is calculated. + pub max_stack_height: u32, + + /// Maximum number of memory pages allowed for a contract. + pub max_memory_pages: u32, + + /// Maximum allowed size of a declared table. + pub max_table_size: u32, + + /// Whether the `ext_println` function is allowed to be used contracts. + /// MUST only be enabled for `dev` chains, NOT for production chains + pub enable_println: bool, + + /// The maximum length of a subject used for PRNG generation. + pub max_subject_len: u32, + } } // Change the storage name used by this pallet from `Contract` to `Contracts`. @@ -31,51 +101,38 @@ pub fn on_runtime_upgrade() -> Weight { // Since the format of the storage items themselves have not changed, we do not // need to keep track of a storage version. If the runtime does not need to be // upgraded, nothing here will happen anyway. - fn change_name_contract_to_contracts() -> Weight { sp_runtime::print("🕊️ Migrating Contracts."); - let mut weight = 0; - let db = T::DbWeight::get(); - if let Some(gas_spent) = take_storage_value::(b"Contract", b"GasSpent", &[]) { - put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent); - weight += db.writes(2); - } - weight += db.reads(1); + // Remove `GasSpent` because it doesn't exist anymore. + remove_storage_prefix(b"Contract", b"GasSpent", &[]); - if let Some(current_schedule) = take_storage_value::(b"Contract", b"CurrentSchedule", &[]) { - put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule); - weight += db.writes(2); - } - weight += db.reads(1); + // Replace the old with the new schedule. + take_storage_value::(b"Contract", b"CurrentSchedule", &[]); + CurrentSchedule::put(Schedule::default()); - for (hash, pristine_code) in StorageIterator::>::new(b"Contract", b"PristineCode").drain() { - put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code); - weight += db.reads_writes(1, 2); + // There are currently no contracts on Edgeware so this should just do nothing. + // Include logging just in case. + for (hash, _code) in StorageIterator::>::new(b"Contract", b"PristineCode").drain() { + runtime_print!("Contracts: Discarding PristinceCode at hash {:?}", hash); } - - for (hash, code_storage) in StorageIterator::::new(b"Contract", b"CodeStorage").drain() { - put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage); - weight += db.reads_writes(1, 2); + for (hash, _storage) in StorageIterator::::new(b"Contract", b"CodeStorage").drain() { + runtime_print!("Contracts: Discarding CodeStorage at hash {:?}", hash); } - - if let Some(current_schedule) = take_storage_value::(b"Contract", b"AccountCounter", &[]) { - put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule); - weight += db.writes(2); + for (hash, _info) in StorageIterator::>::new(b"Contract", b"ContractInfoOf").drain() { + runtime_print!("Contracts: Discarding ContractInfoOf at hash {:?}", hash); } - weight += db.reads(1); - for (hash, contract_info_of) in StorageIterator::>::new(b"Contract", b"ContractInfoOf").drain() { - put_storage_value(b"Contracts", b"ContractInfoOf", &hash, contract_info_of); - weight += db.reads_writes(1, 2); + // (Re-)Set the AccountCounter. + if let Some(counter) = take_storage_value::(b"Contract", b"AccountCounter", &[]) { + AccountCounter::put(counter); + } else { + AccountCounter::put(0); } - if let Some(get_price) = take_storage_value::>(b"Contract", b"GetPrice", &[]) { - put_storage_value(b"Contracts", b"GetPrice", &[], get_price); - weight += db.writes(2); - } - weight += db.reads(1); + // Remove `GetPrice` because it doesn't exist anymore. + remove_storage_prefix(b"Contract", b"GetPrice", &[]); sp_runtime::print("🕊️ Done Contracts."); - weight + T::MaximumBlockWeight::get() } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index d6d8d190e8120..723a49d596683 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -184,6 +184,8 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; +pub mod migration; + const DEMOCRACY_ID: LockIdentifier = *b"democrac"; /// The maximum number of vetoers on a single proposal used to compute Weight. @@ -569,100 +571,7 @@ mod weight_for { impl MigrateAccount for Module { fn migrate_account(a: &T::AccountId) { - mod deprecated { - use sp_std::prelude::*; - - use codec::{Encode, EncodeLike, Decode, Input, Output}; - use frame_support::{decl_module, decl_storage}; - use sp_runtime::RuntimeDebug; - use sp_std::convert::TryFrom; - - use crate::{Trait, ReferendumIndex, Conviction}; - - #[derive(Copy, Clone, Eq, PartialEq, Default, RuntimeDebug)] - pub struct Vote { - pub aye: bool, - pub conviction: Conviction, - } - - impl Encode for Vote { - fn encode_to(&self, output: &mut T) { - output.push_byte(u8::from(self.conviction) | if self.aye { 0b1000_0000 } else { 0 }); - } - } - - impl EncodeLike for Vote {} - - impl Decode for Vote { - fn decode(input: &mut I) -> core::result::Result { - let b = input.read_byte()?; - Ok(Vote { - aye: (b & 0b1000_0000) == 0b1000_0000, - conviction: Conviction::try_from(b & 0b0111_1111) - .map_err(|_| codec::Error::from("Invalid conviction"))?, - }) - } - } - - decl_module! { - pub struct Module for enum Call where origin: T::Origin { } - } - decl_storage! { - trait Store for Module as Democracy { - pub VoteOf get(fn vote_of): - map hasher(opaque_blake2_256) (ReferendumIndex, T::AccountId) => Vote; - pub Delegations get(fn delegations): - map hasher(opaque_blake2_256) T::AccountId => (T::AccountId, Conviction); - } - } - } - - Locks::::migrate_key_from_blake(a); - // TODO: will not actually do any useful migration - deprecated::Delegations::::migrate_key_from_blake(a); - for i in LowestUnbaked::get()..ReferendumCount::get() { - // TODO: will not actually do any useful migration - deprecated::VoteOf::::migrate_key_from_blake((i, a)); - } - } -} - -mod migration { - use super::*; - - pub fn migrate() -> Weight { - mod deprecated { - use super::*; - - decl_module! { - pub struct Module for enum Call where origin: T::Origin { } - } - decl_storage! { - trait Store for Module as Democracy { - pub VotersFor get(fn voters_for): - map hasher(opaque_blake2_256) ReferendumIndex => Vec; - pub Proxy get(fn proxy): - map hasher(opaque_blake2_256) T::AccountId => Option; - } - } - } - - // proxies were removed - deprecated::Proxy::::remove_all(); - Blacklist::::remove_all(); - Cancellations::::remove_all(); - for i in LowestUnbaked::get()..ReferendumCount::get() { - // TODO: will not actually do any useful migration - deprecated::VotersFor::::migrate_key_from_blake(i); - ReferendumInfoOf::::migrate_key_from_blake(i); - } - for (p, h, _) in PublicProps::::get().into_iter() { - DepositOf::::migrate_key_from_blake(p); - Preimages::::migrate_key_from_blake(h); - } - - // TODO: figure out actual weight - 0 + migration::migrate_account::(a) } } @@ -701,7 +610,7 @@ decl_module! { fn deposit_event() = default; fn on_runtime_upgrade() -> Weight { - migration::migrate::() + migration::migrate_all::() } /// Propose a sensitive action to be taken. diff --git a/frame/democracy/src/migration.rs b/frame/democracy/src/migration.rs new file mode 100644 index 0000000000000..7efc2287a6fdc --- /dev/null +++ b/frame/democracy/src/migration.rs @@ -0,0 +1,152 @@ + +use super::*; + +mod deprecated { + use sp_std::prelude::*; + + use codec::{Encode, EncodeLike, Decode, Input, Output}; + use frame_support::{decl_module, decl_storage, Parameter}; + use sp_runtime::RuntimeDebug; + use sp_std::convert::TryFrom; + + use crate::{Trait, BalanceOf, PropIndex, ReferendumIndex, Conviction, vote_threshold::VoteThreshold}; + + #[derive(Copy, Clone, Eq, PartialEq, Default, RuntimeDebug)] + pub struct Vote { + pub aye: bool, + pub conviction: Conviction, + } + + impl Encode for Vote { + fn encode_to(&self, output: &mut T) { + output.push_byte(u8::from(self.conviction) | if self.aye { 0b1000_0000 } else { 0 }); + } + } + + impl EncodeLike for Vote {} + + impl Decode for Vote { + fn decode(input: &mut I) -> core::result::Result { + let b = input.read_byte()?; + Ok(Vote { + aye: (b & 0b1000_0000) == 0b1000_0000, + conviction: Conviction::try_from(b & 0b0111_1111) + .map_err(|_| codec::Error::from("Invalid conviction"))?, + }) + } + } + + #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)] + pub struct ReferendumInfo { + /// When voting on this referendum will end. + end: BlockNumber, + /// The hash of the proposal being voted on. + proposal_hash: Hash, + /// The thresholding mechanism to determine whether it passed. + threshold: VoteThreshold, + /// The delay (in blocks) to wait after a successful referendum before deploying. + delay: BlockNumber, + } + + decl_module! { + pub struct Module for enum Call where origin: T::Origin { } + } + decl_storage! { + trait Store for Module as Democracy { + pub VotersFor get(fn voters_for): + map hasher(opaque_blake2_256) ReferendumIndex => Vec; + pub VoteOf get(fn vote_of): + map hasher(opaque_blake2_256) (ReferendumIndex, T::AccountId) => Vote; + pub Proxy get(fn proxy): + map hasher(opaque_blake2_256) T::AccountId => Option; + pub Delegations get(fn delegations): + map hasher(opaque_blake2_256) T::AccountId => (T::AccountId, Conviction); + + // Note these actually used to be `blake2_256`, but this way we can migrate them + // to then make use of them in the other migration. + pub ReferendumInfoOf get(fn referendum_info): + map hasher(twox_64_concat) ReferendumIndex + => Option>; + + pub DepositOf get(fn deposit_of): + map hasher(opaque_blake2_256) PropIndex => Option<(BalanceOf, Vec)>; + pub Preimages: + map hasher(opaque_blake2_256) T::Hash + => Option<(Vec, T::AccountId, BalanceOf, T::BlockNumber)>; + } + } +} + +pub fn migrate_account(a: &T::AccountId) { + Locks::::migrate_key_from_blake(a); +} + +// The edgeware migration is so big we just assume it consumes the whole block. +pub fn migrate_all() -> Weight { + sp_runtime::print("🕊️ Migrating Democracy..."); + let mut weight = T::MaximumBlockWeight::get(); + sp_runtime::print("Democracy: Hasher"); + weight += migrate_hasher::(); + sp_runtime::print("Democracy: Remove Unused"); + weight += migrate_remove_unused_storage::(); + sp_runtime::print("Democracy: ReferendumInfo"); + weight += migrate_referendum_info::(); + sp_runtime::print("🕊️ Done Democracy."); + weight +} + +pub fn migrate_hasher() -> Weight { + // Edgeware does not have any blacklist/cancellations that need to be migrated --> remove + Blacklist::::remove_all(); + Cancellations::::remove_all(); + // Note this only migrates the hasher, `ReferendumInfoOf` is fully migrated in + // `migrate_referendum_info`. + sp_runtime::print("Democracy: Hasher: ReferendumInfo"); + for i in LowestUnbaked::get()..ReferendumCount::get() { + deprecated::ReferendumInfoOf::::migrate_key_from_blake(i); + } + sp_runtime::print("Democracy: Hasher: PublicProps"); + for (prop_idx, prop_hash, _) in PublicProps::::get().into_iter() { + // based on [democracy weights PR](https://github.com/paritytech/substrate/pull/5828/) + if let Some((deposit, depositors)) = deprecated::DepositOf::::take(prop_idx) { + DepositOf::::insert(prop_idx, (depositors, deposit)); + } + // necessary because of [scheduler PR](https://github.com/paritytech/substrate/pull/5412) + if let Some((data, provider, deposit, since)) = deprecated::Preimages::::take(prop_hash) { + Preimages::::insert(prop_hash, PreimageStatus::Available{data, provider, deposit, since, expiry: None}); + } + } + 0 +} + +pub fn migrate_remove_unused_storage() -> Weight { + // It's unlikely that Edgeware will have open proposals during the migration so we can assume + // this to be fine. + deprecated::VotersFor::::remove_all(); + deprecated::VoteOf::::remove_all(); + deprecated::Proxy::::remove_all(); + deprecated::Delegations::::remove_all(); + 0 +} + +// migration based on [substrate/#5294](https://github.com/paritytech/substrate/pull/5294) +pub fn migrate_referendum_info() -> Weight { + use frame_support::{Twox64Concat, migration::{StorageKeyIterator}}; + + let range = LowestUnbaked::get()..ReferendumCount::get(); + for (index, (end, proposal_hash, threshold, delay)) + in StorageKeyIterator::< + ReferendumIndex, + (T::BlockNumber, T::Hash, VoteThreshold, T::BlockNumber), + Twox64Concat, + >::new(b"Democracy", b"ReferendumInfoOf").drain() + { + if range.contains(&index) { + let status = ReferendumStatus { + end, proposal_hash, threshold, delay, tally: Tally::default() + }; + ReferendumInfoOf::::insert(index, ReferendumInfo::Ongoing(status)) + } + } + 0 +} \ No newline at end of file diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index d1bae611168ac..baef68cb57ce3 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -669,10 +669,10 @@ decl_module! { Self::end_block(n) } + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: Find sensible weight - 0 + T::MaximumBlockWeight::get() } } } @@ -711,6 +711,8 @@ impl MigrateAccount for Module { } decl_storage! { trait Store for Module as PhragmenElection { + // Note these actually used to be `blake2_256`, but this way we can migrate them + // to then make use of them in the other migration. pub VotesOf get(fn votes_of): map hasher(twox_64_concat) T::AccountId => Vec; pub StakeOf get(fn stake_of): diff --git a/frame/elections-phragmen/src/migration.rs b/frame/elections-phragmen/src/migration.rs index c72f45351f1f0..d4ceef89b635a 100644 --- a/frame/elections-phragmen/src/migration.rs +++ b/frame/elections-phragmen/src/migration.rs @@ -2,7 +2,7 @@ use super::*; use frame_support::{migration::{StorageKeyIterator, take_storage_item}, Twox64Concat}; pub fn migrate() { - sp_runtime::print("🕊️ Migrating Election Phragmen."); + sp_runtime::print("🕊️ Migrating PhragmenElection..."); for (who, votes) in StorageKeyIterator ::, Twox64Concat> ::new(b"PhragmenElection", b"VotesOf") @@ -13,5 +13,5 @@ pub fn migrate() { sp_runtime::print("Phragmen: inserted Voting."); } } - sp_runtime::print("🕊️ Done Election Phragmen."); + sp_runtime::print("🕊️ Done PhragmenElection."); } \ No newline at end of file diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index eea6e3b85dfeb..48d40f215aac0 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -233,6 +233,8 @@ where digest: &Digest, ) { if Self::runtime_upgraded() { + // the block hash migration needs the block number to perform the migration + frame_system::Number::::put(block_number); // System is not part of `AllModules`, so we need to call this manually. let mut weight = as OnRuntimeUpgrade>::on_runtime_upgrade(); weight = weight.saturating_add(COnRuntimeUpgrade::on_runtime_upgrade()); diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 51d5241e33c3c..c768e0695255d 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -40,7 +40,7 @@ use fg_primitives::{ GRANDPA_ENGINE_ID, }; use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, storage, traits::KeyOwnerProofSystem, + decl_error, decl_event, decl_module, decl_storage, storage, traits::{Get, KeyOwnerProofSystem}, Parameter, weights::Weight, }; use frame_system::{self as system, ensure_signed, DigestOf}; @@ -239,17 +239,10 @@ decl_module! { fn deposit_event() = default; + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: determine actual weight - 0 - } - - fn on_initialize() -> Weight { - #[cfg(feature = "migrate-authorities")] - Self::migrate_authorities(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } /// Report voter equivocation/misbehavior. This method will verify the diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 4c279be54cabf..7c33f05b64950 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -339,10 +339,10 @@ decl_module! { fn deposit_event() = default; + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } /// # diff --git a/frame/offences/src/lib.rs b/frame/offences/src/lib.rs index 40b8be2b12375..742f61389cc3c 100644 --- a/frame/offences/src/lib.rs +++ b/frame/offences/src/lib.rs @@ -142,12 +142,12 @@ decl_module! { consumed } + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { Reports::::remove_all(); ConcurrentReportsIndex::::remove_all(); ReportsByKindIndex::remove_all(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } } } diff --git a/frame/session/src/historical/mod.rs b/frame/session/src/historical/mod.rs index 1b6ac0c2adb94..1e9ac1e1c017d 100644 --- a/frame/session/src/historical/mod.rs +++ b/frame/session/src/historical/mod.rs @@ -74,13 +74,14 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin { fn on_initialize(_n: T::BlockNumber) -> Weight { CachedObsolete::::remove_all(); - // TODO: determine actual weight 0 } + // The edgeware migration is so big we just assume it consumes the whole block. + // Tricky to get access to `T::MaximumBlockWeight` here, so we just use 0 because this is + // part of a bigger migration. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: determine actual weight 0 } } diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index ea8e9977c9f5d..fe4a5f64ef0f6 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -1381,10 +1381,10 @@ decl_module! { } } + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migrate_hasher::(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } fn on_finalize() { diff --git a/frame/staking/src/migration.rs b/frame/staking/src/migration.rs index 4735c77bbe6a6..97c4ff4c025b1 100644 --- a/frame/staking/src/migration.rs +++ b/frame/staking/src/migration.rs @@ -85,6 +85,8 @@ struct OldStakingLedger { // * CurrentEraStart // * CurrentEraStartSessionIndex // * CurrentEraPointsEarned +// +// The edgeware migration is so big we just assume it consumes the whole block. pub fn migrate_to_simple_payouts() -> Weight { sp_runtime::print("🕊️ Migrating Staking..."); let current_era_start_index = deprecated::CurrentEraStartSessionIndex::get(); @@ -146,6 +148,5 @@ pub fn migrate_to_simple_payouts() -> Weight { deprecated::CurrentEraPointsEarned::kill(); sp_runtime::print("🕊️ Done Staking."); - // TODO: determine actual weight? T::MaximumBlockWeight::get() } \ No newline at end of file diff --git a/frame/support/src/storage/unhashed.rs b/frame/support/src/storage/unhashed.rs index 34b146b86f6ba..889e1544a92c7 100644 --- a/frame/support/src/storage/unhashed.rs +++ b/frame/support/src/storage/unhashed.rs @@ -23,7 +23,10 @@ use codec::{Encode, Decode}; /// Return the value of the item in storage under `key`, or `None` if there is no explicit entry. pub fn get(key: &[u8]) -> Option { sp_io::storage::get(key).and_then(|val| { - Decode::decode(&mut &val[..]).map(Some).unwrap_or_else(|_| { + Decode::decode(&mut &val[..]).map_err(|e| { + frame_support::runtime_print!("Decode Error: {}", e.what()); + e + }).map(Some).unwrap_or_else(|_| { // TODO #3700: error should be handleable. runtime_print!("ERROR: Corrupted state at {:?}", key); None diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 6590f16675e1b..acb331ebe08f6 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -453,7 +453,8 @@ decl_storage! { ExtrinsicData get(fn extrinsic_data): map hasher(twox_64_concat) u32 => Vec; /// The current block number being processed. Set by `execute_block`. - Number get(fn block_number): T::BlockNumber; + // make block number public so we can set it in `Executive` for the block hash migration + pub Number get(fn block_number): T::BlockNumber; /// Hash of the previous block. ParentHash get(fn parent_hash) build(|_| hash69()): T::Hash; @@ -572,6 +573,7 @@ decl_module! { /// The maximum length of a block (in bytes). const MaximumBlockLength: u32 = T::MaximumBlockLength::get(); + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); @@ -579,8 +581,7 @@ decl_module! { let mut runtime_upgraded_key = sp_io::hashing::twox_128(b"System").to_vec(); runtime_upgraded_key.extend(&sp_io::hashing::twox_128(b"RuntimeUpgraded")); sp_io::storage::clear(&runtime_upgraded_key); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } /// A dispatch that will fill the block weight up to the given ratio. diff --git a/frame/system/src/migration.rs b/frame/system/src/migration.rs index 092a6f4bbe5f6..5882de0905846 100644 --- a/frame/system/src/migration.rs +++ b/frame/system/src/migration.rs @@ -13,13 +13,13 @@ pub fn migrate_block_hash() -> Weight { // Number - 2 is therefore the most recent block's hash that needs migrating. let db = T::DbWeight::get(); let block_num = Number::::get(); + frame_support::runtime_print!("BlockNumber: {}", block_num.saturated_into::()); if block_num > One::one() { sp_runtime::print("🕊️ Migrating BlockHashes..."); BlockHash::::migrate_key_from_blake(T::BlockNumber::zero()); let mut n = block_num - One::one() - One::one(); let mut migrations = 1; while !n.is_zero() { - sp_runtime::print(n.saturated_into::()); migrations += 1; if BlockHash::::migrate_key_from_blake(n).is_none() { break; @@ -29,7 +29,7 @@ pub fn migrate_block_hash() -> Weight { sp_runtime::print("🕊️ Done BlockHashes"); db.reads_writes(migrations + 1, migrations) } else { - sp_runtime::print("No BlockHashes to migrate..."); + sp_runtime::print("🕊️ No BlockHashes to migrate..."); db.reads(1) } } diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index e643a79203848..e749fb8ac60a3 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -334,10 +334,10 @@ decl_module! { fn deposit_event() = default; + // The edgeware migration is so big we just assume it consumes the whole block. fn on_runtime_upgrade() -> Weight { migration::migrate::(); - // TODO: determine actual weight - 0 + T::MaximumBlockWeight::get() } /// Put forward a suggestion for spending. A deposit proportional to the value