Skip to content

Commit

Permalink
Merge pull request #1974 from parallel-finance/fix-vault
Browse files Browse the repository at this point in the history
Deal with vaults contribution
  • Loading branch information
dio-will committed Jun 11, 2024
2 parents eb28af9 + 9f63f4d commit 7663d7f
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
83 changes: 83 additions & 0 deletions pallets/crowdloans/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,86 @@ pub mod v3 {
Ok(())
}
}

pub mod v4 {
use super::*;
use frame_support::{log, traits::Get};
use primitives::ParaId;
use sp_std::{vec, vec::Vec};
use types::*;

pub fn pre_migrate<T: Config>() -> Result<Vec<u8>, &'static str> {
frame_support::ensure!(
StorageVersion::<T>::get() == Releases::V3_0_0,
"must be V3_0_0"
);
frame_support::ensure!(NextTrieIndex::<T>::get() == 31, "must be 31");
Ok(Vec::new())
}

pub fn migrate<T: Config>() -> frame_support::weights::Weight {
if StorageVersion::<T>::get() == Releases::V3_0_0 {
log::info!(
target: "crowdloans::migrate",
"migrating crowdloan storage"
);
// paraId, ctoken, contributed, cap, end_block, trie_index, lease_start, lease_end
let batch: Vec<(u32, u32, u128, u128, u32, u32, u32, u32)> = vec![
// 2040,8-15,3000000000000000,150000000000000000,10881401
(
2040,
200080015,
3000000000000000,
150_000_000_000_000_000,
10881401,
25,
8,
15,
),
];
let length = batch.len() as u64;
for (para_id, _, raised, _, _, _, lease_start, lease_end) in batch.into_iter() {
match Vaults::<T>::get((&ParaId::from(para_id), &lease_start, &lease_end)) {
Some(vault) if vault.phase == VaultPhase::Expired => {
Vaults::<T>::insert(
(&ParaId::from(para_id), &lease_start, &lease_end),
Vault {
contributed: raised,
..vault
},
);
}
Some(_) => {
log::error!("Vault for para_id {} is not in Expired phase", para_id);
}
None => {
log::error!(
"No vault found for para_id {} ({}, {})",
para_id,
lease_start,
lease_end
);
}
}
}
log::info!(
target: "crowdloans::migrate",
"completed crowdloans storage migration"
);
<T as frame_system::Config>::DbWeight::get().writes(length * 3 + 1u64)
} else {
T::DbWeight::get().reads(1)
}
}

pub fn post_migrate<T: Config>() -> Result<(), &'static str> {
frame_support::ensure!(
StorageVersion::<T>::get() == Releases::V3_0_0,
"must be V3_0_0"
);
frame_support::ensure!(NextTrieIndex::<T>::get() == 31, "must be 31");
log::info!("👜 crowdloan migration passes POST migrate checks ✅",);

Ok(())
}
}
2 changes: 1 addition & 1 deletion runtime/heiko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("heiko"),
impl_name: create_runtime_str!("heiko"),
authoring_version: 1,
spec_version: 206,
spec_version: 207,
impl_version: 33,
apis: RUNTIME_API_VERSIONS,
transaction_version: 17,
Expand Down
2 changes: 1 addition & 1 deletion runtime/kerria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kerria"),
impl_name: create_runtime_str!("kerria"),
authoring_version: 1,
spec_version: 206,
spec_version: 207,
impl_version: 33,
apis: RUNTIME_API_VERSIONS,
transaction_version: 17,
Expand Down
14 changes: 7 additions & 7 deletions runtime/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("parallel"),
impl_name: create_runtime_str!("parallel"),
authoring_version: 1,
spec_version: 206,
spec_version: 207,
impl_version: 33,
apis: RUNTIME_API_VERSIONS,
transaction_version: 17,
Expand Down Expand Up @@ -2073,7 +2073,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
CrowdloansMigrationV3,
CrowdloansMigrationV4,
>;

impl fp_self_contained::SelfContainedCall for RuntimeCall {
Expand Down Expand Up @@ -2134,20 +2134,20 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
}
}

pub struct CrowdloansMigrationV3;
impl OnRuntimeUpgrade for CrowdloansMigrationV3 {
pub struct CrowdloansMigrationV4;
impl OnRuntimeUpgrade for CrowdloansMigrationV4 {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_crowdloans::migrations::v3::migrate::<Runtime>()
pallet_crowdloans::migrations::v4::migrate::<Runtime>()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
pallet_crowdloans::migrations::v3::pre_migrate::<Runtime>()
pallet_crowdloans::migrations::v4::pre_migrate::<Runtime>()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
pallet_crowdloans::migrations::v3::post_migrate::<Runtime>()
pallet_crowdloans::migrations::v4::post_migrate::<Runtime>()
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/vanilla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("vanilla"),
impl_name: create_runtime_str!("vanilla"),
authoring_version: 1,
spec_version: 206,
spec_version: 207,
impl_version: 33,
apis: RUNTIME_API_VERSIONS,
transaction_version: 17,
Expand Down
2 changes: 1 addition & 1 deletion scripts/collator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VOLUME="chains"
NODE_KEY="$1"
KEYSTORE_PATH="$2"
NODE_NAME="$3"
DOCKER_IMAGE="parallelfinance/parallel:v2.0.6"
DOCKER_IMAGE="parallelfinance/parallel:v2.0.7"
BASE_PATH="/data"

if [ $# -lt 3 ]; then
Expand Down

0 comments on commit 7663d7f

Please sign in to comment.