Skip to content

Commit 7663d7f

Browse files
authored
Merge pull request #1974 from parallel-finance/fix-vault
Deal with vaults contribution
2 parents eb28af9 + 9f63f4d commit 7663d7f

File tree

6 files changed

+94
-11
lines changed

6 files changed

+94
-11
lines changed

pallets/crowdloans/src/migrations.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,86 @@ pub mod v3 {
382382
Ok(())
383383
}
384384
}
385+
386+
pub mod v4 {
387+
use super::*;
388+
use frame_support::{log, traits::Get};
389+
use primitives::ParaId;
390+
use sp_std::{vec, vec::Vec};
391+
use types::*;
392+
393+
pub fn pre_migrate<T: Config>() -> Result<Vec<u8>, &'static str> {
394+
frame_support::ensure!(
395+
StorageVersion::<T>::get() == Releases::V3_0_0,
396+
"must be V3_0_0"
397+
);
398+
frame_support::ensure!(NextTrieIndex::<T>::get() == 31, "must be 31");
399+
Ok(Vec::new())
400+
}
401+
402+
pub fn migrate<T: Config>() -> frame_support::weights::Weight {
403+
if StorageVersion::<T>::get() == Releases::V3_0_0 {
404+
log::info!(
405+
target: "crowdloans::migrate",
406+
"migrating crowdloan storage"
407+
);
408+
// paraId, ctoken, contributed, cap, end_block, trie_index, lease_start, lease_end
409+
let batch: Vec<(u32, u32, u128, u128, u32, u32, u32, u32)> = vec![
410+
// 2040,8-15,3000000000000000,150000000000000000,10881401
411+
(
412+
2040,
413+
200080015,
414+
3000000000000000,
415+
150_000_000_000_000_000,
416+
10881401,
417+
25,
418+
8,
419+
15,
420+
),
421+
];
422+
let length = batch.len() as u64;
423+
for (para_id, _, raised, _, _, _, lease_start, lease_end) in batch.into_iter() {
424+
match Vaults::<T>::get((&ParaId::from(para_id), &lease_start, &lease_end)) {
425+
Some(vault) if vault.phase == VaultPhase::Expired => {
426+
Vaults::<T>::insert(
427+
(&ParaId::from(para_id), &lease_start, &lease_end),
428+
Vault {
429+
contributed: raised,
430+
..vault
431+
},
432+
);
433+
}
434+
Some(_) => {
435+
log::error!("Vault for para_id {} is not in Expired phase", para_id);
436+
}
437+
None => {
438+
log::error!(
439+
"No vault found for para_id {} ({}, {})",
440+
para_id,
441+
lease_start,
442+
lease_end
443+
);
444+
}
445+
}
446+
}
447+
log::info!(
448+
target: "crowdloans::migrate",
449+
"completed crowdloans storage migration"
450+
);
451+
<T as frame_system::Config>::DbWeight::get().writes(length * 3 + 1u64)
452+
} else {
453+
T::DbWeight::get().reads(1)
454+
}
455+
}
456+
457+
pub fn post_migrate<T: Config>() -> Result<(), &'static str> {
458+
frame_support::ensure!(
459+
StorageVersion::<T>::get() == Releases::V3_0_0,
460+
"must be V3_0_0"
461+
);
462+
frame_support::ensure!(NextTrieIndex::<T>::get() == 31, "must be 31");
463+
log::info!("👜 crowdloan migration passes POST migrate checks ✅",);
464+
465+
Ok(())
466+
}
467+
}

runtime/heiko/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
180180
spec_name: create_runtime_str!("heiko"),
181181
impl_name: create_runtime_str!("heiko"),
182182
authoring_version: 1,
183-
spec_version: 206,
183+
spec_version: 207,
184184
impl_version: 33,
185185
apis: RUNTIME_API_VERSIONS,
186186
transaction_version: 17,

runtime/kerria/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
180180
spec_name: create_runtime_str!("kerria"),
181181
impl_name: create_runtime_str!("kerria"),
182182
authoring_version: 1,
183-
spec_version: 206,
183+
spec_version: 207,
184184
impl_version: 33,
185185
apis: RUNTIME_API_VERSIONS,
186186
transaction_version: 17,

runtime/parallel/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
185185
spec_name: create_runtime_str!("parallel"),
186186
impl_name: create_runtime_str!("parallel"),
187187
authoring_version: 1,
188-
spec_version: 206,
188+
spec_version: 207,
189189
impl_version: 33,
190190
apis: RUNTIME_API_VERSIONS,
191191
transaction_version: 17,
@@ -2073,7 +2073,7 @@ pub type Executive = frame_executive::Executive<
20732073
frame_system::ChainContext<Runtime>,
20742074
Runtime,
20752075
AllPalletsWithSystem,
2076-
CrowdloansMigrationV3,
2076+
CrowdloansMigrationV4,
20772077
>;
20782078

20792079
impl fp_self_contained::SelfContainedCall for RuntimeCall {
@@ -2134,20 +2134,20 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
21342134
}
21352135
}
21362136

2137-
pub struct CrowdloansMigrationV3;
2138-
impl OnRuntimeUpgrade for CrowdloansMigrationV3 {
2137+
pub struct CrowdloansMigrationV4;
2138+
impl OnRuntimeUpgrade for CrowdloansMigrationV4 {
21392139
fn on_runtime_upgrade() -> frame_support::weights::Weight {
2140-
pallet_crowdloans::migrations::v3::migrate::<Runtime>()
2140+
pallet_crowdloans::migrations::v4::migrate::<Runtime>()
21412141
}
21422142

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

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

runtime/vanilla/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
180180
spec_name: create_runtime_str!("vanilla"),
181181
impl_name: create_runtime_str!("vanilla"),
182182
authoring_version: 1,
183-
spec_version: 206,
183+
spec_version: 207,
184184
impl_version: 33,
185185
apis: RUNTIME_API_VERSIONS,
186186
transaction_version: 17,

scripts/collator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ VOLUME="chains"
2020
NODE_KEY="$1"
2121
KEYSTORE_PATH="$2"
2222
NODE_NAME="$3"
23-
DOCKER_IMAGE="parallelfinance/parallel:v2.0.6"
23+
DOCKER_IMAGE="parallelfinance/parallel:v2.0.7"
2424
BASE_PATH="/data"
2525

2626
if [ $# -lt 3 ]; then

0 commit comments

Comments
 (0)