Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make migration compile
  • Loading branch information
shawntabrizi committed May 4, 2022
commit 5fef49cce2dc4b3d4e2a45a1ab28dc075d1d9eda
12 changes: 6 additions & 6 deletions frame/bags-list/src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ impl<T: Config<I>, I: 'static> Bag<T, I> {
#[scale_info(skip_type_params(T, I))]
#[cfg_attr(feature = "std", derive(frame_support::DebugNoBound, Clone, PartialEq))]
pub struct Node<T: Config<I>, I: 'static = ()> {
id: T::AccountId,
prev: Option<T::AccountId>,
next: Option<T::AccountId>,
bag_upper: T::Score,
score: T::Score,
pub(crate) id: T::AccountId,
pub(crate) prev: Option<T::AccountId>,
pub(crate) next: Option<T::AccountId>,
pub(crate) bag_upper: T::Score,
pub(crate) score: T::Score,
Copy link
Member

@ggwpez ggwpez May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a migration since you added a field to storage?
Nvm there is a migration...
I am debugging paritytech/polkadot#5596 since it blocks the release.
Locally I get:

(key, value) failed to decode at [116, 221, 112, 45, 164, 111, 119, 215, 172, 247, 127, 90, 72, 212, 175, 125, 98, 85, 106, 133, 252, 183, 
198, 27, 44, 108, 117, 9, 36, 132, 107, 21, 255, 184, 248, 37, 19, 246, 37, 119, 222, 177, 148, 77, 167, 140, 139, 203, 242, 13, 84, 197, 223, 249, 159, 230, 1
47, 188, 232, 252, 82, 35, 170, 133, 105, 44, 24, 208, 131, 9, 38, 100]: Error { cause: Some(Error { cause: None, desc: "Not enough data to fill buffer" }), de
sc: "Could not decode `Node::score`" }

#[codec(skip)]
_phantom: PhantomData<I>,
pub(crate) _phantom: PhantomData<I>,
}

impl<T: Config<I>, I: 'static> Node<T, I> {
Expand Down
22 changes: 13 additions & 9 deletions frame/bags-list/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{ensure, storage::migration, traits::OnRuntimeUpgrade};
use frame_election_provider_support::ScoreProvider;
use frame_support::{ensure, storage::migration, traits::OnRuntimeUpgrade};
use sp_runtime::traits::Zero;

/// A struct that does not migration, but only checks that the counter prefix exists and is correct.
pub struct CheckCounterPrefix<T: crate::Config<I>, I: 'static>(sp_std::marker::PhantomData<(T, I)>);
Expand Down Expand Up @@ -52,12 +53,12 @@ impl<T: crate::Config<I>, I: 'static> OnRuntimeUpgrade for CheckCounterPrefix<T,

#[derive(Encode, Decode)]
struct PreScoreNode<T: crate::Config<I>, I: 'static = ()> {
id: T::AccountId,
prev: Option<T::AccountId>,
next: Option<T::AccountId>,
bag_upper: T::Score,
pub id: T::AccountId,
pub prev: Option<T::AccountId>,
pub next: Option<T::AccountId>,
pub bag_upper: T::Score,
#[codec(skip)]
_phantom: PhantomData<I>,
pub _phantom: PhantomData<I>,
}

/// A struct that migrates all bags lists to contain a score value.
Expand All @@ -80,11 +81,11 @@ impl<T: crate::Config<I>, I: 'static> OnRuntimeUpgrade for AddScore<T, I> {
migration::move_pallet(b"BagsList", b"VoterList");
let old_nodes = migration::storage_iter::<PreScoreNode<T, I>>(b"VoterList", b"ListNodes");

for node in old_nodes.iter() {
let score = T::ScoreProvider::score(node.id);
for (_key, node) in old_nodes.drain() {
let score = T::ScoreProvider::score(&node.id);

let new_node = crate::Node {
id: node.id,
id: node.id.clone(),
prev: node.prev,
next: node.next,
bag_upper: node.bag_upper,
Expand All @@ -104,6 +105,9 @@ impl<T: crate::Config<I>, I: 'static> OnRuntimeUpgrade for AddScore<T, I> {
crate::ListNodes::<T, I>::iter().count() > 0,
"Items do not exist where some were expected."
);
for (_id, node) in crate::ListNodes::<T, I>::iter() {
ensure!(!node.score.is_zero(), "Score should be greater than zero");
}
ensure!(
crate::ListBags::<T, I>::iter().count() > 0,
"Items do not exist where some were expected."
Expand Down