Skip to content

Commit

Permalink
Rename storage to fix try-runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
ark930 committed Dec 11, 2024
1 parent 37c87f0 commit 0aa13de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions pallets/vtoken-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> = StorageDoubleMap<
pub type VotingForV2<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
CurrencyIdOf<T>,
Expand Down Expand Up @@ -425,7 +425,7 @@ pub mod pallet {
>;

#[pallet::storage]
pub type ReferendumTimeout<T: Config> = StorageDoubleMap<
pub type ReferendumTimeoutV2<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
CurrencyIdOf<T>,
Expand Down Expand Up @@ -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::<T>::iter_keys() {
for (vtoken, time_out_block_number) in ReferendumTimeoutV2::<T>::iter_keys() {
let referendum_timeout_list =
ReferendumTimeout::<T>::get(vtoken, time_out_block_number);
ReferendumTimeoutV2::<T>::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) {
Expand Down Expand Up @@ -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::<T>::mutate(
ReferendumTimeoutV2::<T>::mutate(
vtoken,
current_block_number.saturating_add(
UndecidingTimeout::<T>::get(vtoken)
Expand Down Expand Up @@ -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::<T>::NotOngoing)?;
VotingFor::<T>::try_mutate(vtoken, who, |voting| {
VotingForV2::<T>::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) => {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ pub mod pallet {
poll_index: PollIndex,
scope: UnvoteScope,
) -> DispatchResult {
VotingFor::<T>::try_mutate(vtoken, who, |voting| {
VotingForV2::<T>::try_mutate(vtoken, who, |voting| {
if let Voting::Casting(Casting { ref mut votes, delegations, ref mut prior }) =
voting
{
Expand Down Expand Up @@ -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<T>, vtoken: CurrencyIdOf<T>) -> DispatchResult {
let current_block = Self::get_agent_block_number(&vtoken)?;
let lock_needed = VotingFor::<T>::mutate(vtoken, who, |voting| {
let lock_needed = VotingForV2::<T>::mutate(vtoken, who, |voting| {
voting.rejig(current_block);
voting.locked_balance()
});
Expand Down Expand Up @@ -1504,7 +1504,7 @@ pub mod pallet {
None => {},
});
}
ReferendumTimeout::<T>::remove(vtoken, time_out_block_number);
ReferendumTimeoutV2::<T>::remove(vtoken, time_out_block_number);
}
}
}
10 changes: 5 additions & 5 deletions pallets/vtoken-voting/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn migrate_to_v2<T: Config, C: Get<CurrencyIdOf<T>>>() -> Weight {
weight += T::DbWeight::get().writes(1);
}

let r1 = VotingFor::<T>::clear(u32::MAX, None);
let r1 = v3::VotingFor::<T>::clear(u32::MAX, None);
weight += T::DbWeight::get().writes(r1.loops as u64);

let r2 = ClassLocksFor::<T>::clear(u32::MAX, None);
Expand Down Expand Up @@ -270,11 +270,11 @@ pub mod v4 {
);
log::info!(
"vtoken-voting after migration: VotingFor v4 count: {}",
VotingFor::<T>::iter().count()
VotingForV2::<T>::iter().count()
);
log::info!(
"vtoken-voting after migration: ReferendumTimeout v4 count: {}",
ReferendumTimeout::<T>::iter().count()
ReferendumTimeoutV2::<T>::iter().count()
);

Ok(())
Expand All @@ -290,7 +290,7 @@ pub fn migrate_to_v4<T: Config, C: Get<CurrencyIdOf<T>>>() -> Weight {

// Iterate over all items in the old storage
v3::VotingFor::<T>::iter().for_each(|(account, voting)| {
VotingFor::<T>::insert(vtoken, account, voting);
VotingForV2::<T>::insert(vtoken, account, voting);
weight += T::DbWeight::get().reads_writes(0, 1);
});

Expand All @@ -301,7 +301,7 @@ pub fn migrate_to_v4<T: Config, C: Get<CurrencyIdOf<T>>>() -> Weight {
pool_index_vec.try_push(poll_index).unwrap();
}
// Insert into the new storage
ReferendumTimeout::<T>::insert(vtoken, block_number, pool_index_vec);
ReferendumTimeoutV2::<T>::insert(vtoken, block_number, pool_index_vec);
weight += T::DbWeight::get().reads_writes(0, 1);
});

Expand Down

0 comments on commit 0aa13de

Please sign in to comment.