From 0aa13deb5bccb74aac26d8e7a3dcbcfd74e35b08 Mon Sep 17 00:00:00 2001 From: Edwin Wang Date: Wed, 11 Dec 2024 17:22:57 +0800 Subject: [PATCH] Rename storage to fix try-runtime error --- pallets/vtoken-voting/src/lib.rs | 18 +++++++++--------- pallets/vtoken-voting/src/migration.rs | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pallets/vtoken-voting/src/lib.rs b/pallets/vtoken-voting/src/lib.rs index 953a8a1153..40f610614a 100644 --- a/pallets/vtoken-voting/src/lib.rs +++ b/pallets/vtoken-voting/src/lib.rs @@ -337,7 +337,7 @@ pub mod pallet { /// All voting for a particular voter in a particular voting class. We store the balance for the /// number of votes that we have recorded. #[pallet::storage] - pub type VotingFor = StorageDoubleMap< + pub type VotingForV2 = StorageDoubleMap< _, Twox64Concat, CurrencyIdOf, @@ -425,7 +425,7 @@ pub mod pallet { >; #[pallet::storage] - pub type ReferendumTimeout = StorageDoubleMap< + pub type ReferendumTimeoutV2 = StorageDoubleMap< _, Twox64Concat, CurrencyIdOf, @@ -487,9 +487,9 @@ pub mod pallet { let relay_current_block_number = T::RelaychainBlockNumberProvider::current_block_number(); - for (vtoken, time_out_block_number) in ReferendumTimeout::::iter_keys() { + for (vtoken, time_out_block_number) in ReferendumTimeoutV2::::iter_keys() { let referendum_timeout_list = - ReferendumTimeout::::get(vtoken, time_out_block_number); + ReferendumTimeoutV2::::get(vtoken, time_out_block_number); let len = referendum_timeout_list.len() as u64; let temp_weight = db_weight.reads_writes(len, len) + db_weight.writes(1); if remaining_weight.any_lt(used_weight + temp_weight) { @@ -880,7 +880,7 @@ pub mod pallet { if let ReferendumInfo::Ongoing(status) = info { let current_block_number = Self::get_agent_block_number(&vtoken)?; status.submitted = Some(current_block_number); - ReferendumTimeout::::mutate( + ReferendumTimeoutV2::::mutate( vtoken, current_block_number.saturating_add( UndecidingTimeout::::get(vtoken) @@ -1078,7 +1078,7 @@ pub mod pallet { let mut total_vote = None; Self::try_access_poll(vtoken, poll_index, |poll_status| { let tally = poll_status.ensure_ongoing().ok_or(Error::::NotOngoing)?; - VotingFor::::try_mutate(vtoken, who, |voting| { + VotingForV2::::try_mutate(vtoken, who, |voting| { if let Voting::Casting(Casting { ref mut votes, delegations, .. }) = voting { match votes.binary_search_by_key(&poll_index, |i| i.0) { Ok(i) => { @@ -1131,7 +1131,7 @@ pub mod pallet { poll_index: PollIndex, scope: UnvoteScope, ) -> DispatchResult { - VotingFor::::try_mutate(vtoken, who, |voting| { + VotingForV2::::try_mutate(vtoken, who, |voting| { if let Voting::Casting(Casting { ref mut votes, delegations, ref mut prior }) = voting { @@ -1183,7 +1183,7 @@ pub mod pallet { /// indicate a security hole) but may be reduced from what they are currently. pub(crate) fn update_lock(who: &AccountIdOf, vtoken: CurrencyIdOf) -> DispatchResult { let current_block = Self::get_agent_block_number(&vtoken)?; - let lock_needed = VotingFor::::mutate(vtoken, who, |voting| { + let lock_needed = VotingForV2::::mutate(vtoken, who, |voting| { voting.rejig(current_block); voting.locked_balance() }); @@ -1504,7 +1504,7 @@ pub mod pallet { None => {}, }); } - ReferendumTimeout::::remove(vtoken, time_out_block_number); + ReferendumTimeoutV2::::remove(vtoken, time_out_block_number); } } } diff --git a/pallets/vtoken-voting/src/migration.rs b/pallets/vtoken-voting/src/migration.rs index c302464e34..ce5a451fd2 100644 --- a/pallets/vtoken-voting/src/migration.rs +++ b/pallets/vtoken-voting/src/migration.rs @@ -124,7 +124,7 @@ pub fn migrate_to_v2>>() -> Weight { weight += T::DbWeight::get().writes(1); } - let r1 = VotingFor::::clear(u32::MAX, None); + let r1 = v3::VotingFor::::clear(u32::MAX, None); weight += T::DbWeight::get().writes(r1.loops as u64); let r2 = ClassLocksFor::::clear(u32::MAX, None); @@ -270,11 +270,11 @@ pub mod v4 { ); log::info!( "vtoken-voting after migration: VotingFor v4 count: {}", - VotingFor::::iter().count() + VotingForV2::::iter().count() ); log::info!( "vtoken-voting after migration: ReferendumTimeout v4 count: {}", - ReferendumTimeout::::iter().count() + ReferendumTimeoutV2::::iter().count() ); Ok(()) @@ -290,7 +290,7 @@ pub fn migrate_to_v4>>() -> Weight { // Iterate over all items in the old storage v3::VotingFor::::iter().for_each(|(account, voting)| { - VotingFor::::insert(vtoken, account, voting); + VotingForV2::::insert(vtoken, account, voting); weight += T::DbWeight::get().reads_writes(0, 1); }); @@ -301,7 +301,7 @@ pub fn migrate_to_v4>>() -> Weight { pool_index_vec.try_push(poll_index).unwrap(); } // Insert into the new storage - ReferendumTimeout::::insert(vtoken, block_number, pool_index_vec); + ReferendumTimeoutV2::::insert(vtoken, block_number, pool_index_vec); weight += T::DbWeight::get().reads_writes(0, 1); });