Skip to content

Commit

Permalink
fix try-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
f-gate committed Dec 4, 2023
1 parent 505f922 commit 02c4434
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions pallets/fellowship/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub mod v0 {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1));
} else {
log::warn!("Skipping v1, should be removed from Executive");
log::warn!("on_chain = {:?}, current = {:?}", onchain, current);
weight = weight.saturating_add(T::DbWeight::get().reads(1));
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/proposals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub mod pallet {
type AssetSignerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

const STORAGE_VERSION: StorageVersion = StorageVersion::new(6);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
19 changes: 15 additions & 4 deletions pallets/proposals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ pub mod v7 {
let onchain = <Pallet<T> as GetStorageVersion>::on_chain_storage_version();

ensure!(
<T as Config>::MaxJuryMembers::get() < u8::MAX as u32,

<<T as Config>::JurySelector as SelectJury<AccountIdOf<T>>>::JurySize::get() < u8::MAX as u32,
"Max jury members must be smaller than u8"
);

Expand Down Expand Up @@ -767,9 +768,15 @@ pub mod v7 {
weight
}



#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::warn!( target: "pallet-proposals", "Running post_upgrade()");
Projects::<T>::iter().for_each(|(_k, project)|{

assert!(project.jury.len() > 0, "jury size must be > 0");
});

ensure!(
Pallet::<T>::current_storage_version() == 7,
Expand All @@ -793,8 +800,6 @@ pub mod v7 {
v5::FundingType::Grant(_) => crate::FundingPath::WaitForFunding,
};

let jury = <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury();

let refund_locations: BoundedVec<(Locality<AccountIdOf<T>>, Percent), T::MaximumContributorsPerProject> = match project.funding_type {
v5::FundingType::Proposal => crate::Pallet::<T>::convert_contributions_to_refund_locations(&project.contributions),
v5::FundingType::Brief => crate::Pallet::<T>::convert_contributions_to_refund_locations(&project.contributions),
Expand All @@ -812,6 +817,12 @@ pub mod v7 {
},
};

let jury = match project.funding_type {
v5::FundingType::Grant(_) => project.contributions.keys().cloned().collect::<Vec<AccountIdOf<T>>>(),
v5::FundingType::Brief => <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury().to_vec(),
_ => <T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury().to_vec(),
};

let mut new_milestones: BoundedBTreeMilestones<T> = BoundedBTreeMap::new();
project.milestones.iter().for_each(|(_ms_key, ms): (&MilestoneKey, &v6::V6Milestone)| {
// assume that if its approved then its been withdrawn.
Expand Down Expand Up @@ -844,7 +855,7 @@ pub mod v7 {
cancelled: project.cancelled,
deposit_id: project.deposit_id,
refund_locations,
jury,
jury: jury.try_into().expect("contributions bound is larger than jury bound, reduce contribution bound or increase jury bound."),
on_creation_funding,
refunded_funds: Zero::zero(),
};
Expand Down
5 changes: 3 additions & 2 deletions runtime/imbue-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ pub mod migrations {
use super::*;
/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
pallet_proposals::migration::v7::MigrateToV7<Runtime>,
pallet_fellowship::migration::v0::MigrateInitial<Runtime>,
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
pallet_xcm::migration::v1::VersionUncheckedMigrateToV1<Runtime>,
pallet_fellowship::migration::v0::MigrateInitial<Runtime>,
orml_unknown_tokens::Migration<Runtime>,
// PROPOSALS MIGRATION MUST BE RUN AFTER FELLOWSHIP MIGRATION
pallet_proposals::migration::v7::MigrateToV7<Runtime>,
);
}

Expand Down

0 comments on commit 02c4434

Please sign in to comment.