From cd43d503e2c19eba07d60e3cf4aed3de18a1816d Mon Sep 17 00:00:00 2001 From: dio-will Date: Mon, 10 Jun 2024 19:37:34 +0800 Subject: [PATCH 1/6] Update rust-toolchain --- Makefile | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f64a6683b..bdb27f74d 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ RELAY_DOCKER_TAG := v0.9.42 init: submodules git config advice.ignoredHook false git config core.hooksPath .githooks - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2022-11-15 --component rust-src --component rustfmt --component clippy --target wasm32-unknown-unknown + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2024-02-04 --component rust-src --component rustfmt --component clippy --target wasm32-unknown-unknown cargo install cargo-udeps --locked cd scripts/helper && yarn cd scripts/polkadot-launch && yarn diff --git a/rust-toolchain b/rust-toolchain index 45d3fb304..196683588 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2022-11-15" +channel = "nightly-2024-02-04" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] profile = "minimal" From f5d5215adc0a0ccdf8e89898517b62bd58c6b59f Mon Sep 17 00:00:00 2001 From: dio-will Date: Mon, 10 Jun 2024 19:40:11 +0800 Subject: [PATCH 2/6] Deal with vaults contribution --- pallets/crowdloans/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pallets/crowdloans/src/lib.rs b/pallets/crowdloans/src/lib.rs index 76b73a8a4..83d569e9a 100644 --- a/pallets/crowdloans/src/lib.rs +++ b/pallets/crowdloans/src/lib.rs @@ -1810,7 +1810,7 @@ pub mod pallet { ) -> DispatchResult { let ctoken = Self::ctoken_of((&lease_start, &lease_end)) .ok_or(Error::::CTokenDoesNotExist)?; - let mut vault = Self::vaults((&crowdloan, &lease_start, &lease_end)) + let vault = Self::vaults((&crowdloan, &lease_start, &lease_end)) .ok_or(Error::::VaultDoesNotExist)?; ensure!( @@ -1832,10 +1832,11 @@ pub mod pallet { let ctoken_balance = T::Assets::reducible_balance(ctoken, &who, false); ensure!(ctoken_balance >= amount, Error::::InsufficientBalance); - vault.contributed = vault - .contributed - .checked_sub(amount) - .ok_or(ArithmeticError::Underflow)?; + // NOTE: skipping the vault contribution check + // vault.contributed = vault + // .contributed + // .checked_sub(amount) + // .ok_or(ArithmeticError::Underflow)?; T::Assets::burn_from(ctoken, &who, amount)?; // SovereignAccount on relaychain must have From 2fdf9fd40ced5b1aa6b5a882b3af898d697ab0ff Mon Sep 17 00:00:00 2001 From: dio-will Date: Mon, 10 Jun 2024 19:41:20 +0800 Subject: [PATCH 3/6] Bump to version 207 --- runtime/heiko/src/lib.rs | 2 +- runtime/kerria/src/lib.rs | 2 +- runtime/parallel/src/lib.rs | 19 +------------------ runtime/vanilla/src/lib.rs | 2 +- scripts/collator.sh | 2 +- 5 files changed, 5 insertions(+), 22 deletions(-) diff --git a/runtime/heiko/src/lib.rs b/runtime/heiko/src/lib.rs index 645bc636d..6f7ca8592 100644 --- a/runtime/heiko/src/lib.rs +++ b/runtime/heiko/src/lib.rs @@ -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, diff --git a/runtime/kerria/src/lib.rs b/runtime/kerria/src/lib.rs index 0df60c323..528f1ced6 100644 --- a/runtime/kerria/src/lib.rs +++ b/runtime/kerria/src/lib.rs @@ -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, diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index 9f7333f49..238e5f96a 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -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, @@ -2134,23 +2134,6 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { } } -pub struct CrowdloansMigrationV3; -impl OnRuntimeUpgrade for CrowdloansMigrationV3 { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - pallet_crowdloans::migrations::v3::migrate::() - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - pallet_crowdloans::migrations::v3::pre_migrate::() - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_: Vec) -> Result<(), &'static str> { - pallet_crowdloans::migrations::v3::post_migrate::() - } -} - impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { diff --git a/runtime/vanilla/src/lib.rs b/runtime/vanilla/src/lib.rs index da78c4c01..fd4836115 100644 --- a/runtime/vanilla/src/lib.rs +++ b/runtime/vanilla/src/lib.rs @@ -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, diff --git a/scripts/collator.sh b/scripts/collator.sh index 2c07503c1..5390e2b2d 100755 --- a/scripts/collator.sh +++ b/scripts/collator.sh @@ -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 From e18b4636cdd15afc8d00b60b736e4a0de5b92442 Mon Sep 17 00:00:00 2001 From: dio-will Date: Mon, 10 Jun 2024 19:44:02 +0800 Subject: [PATCH 4/6] Revert the change of rust-toolchain --- Makefile | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bdb27f74d..f64a6683b 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ RELAY_DOCKER_TAG := v0.9.42 init: submodules git config advice.ignoredHook false git config core.hooksPath .githooks - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2024-02-04 --component rust-src --component rustfmt --component clippy --target wasm32-unknown-unknown + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2022-11-15 --component rust-src --component rustfmt --component clippy --target wasm32-unknown-unknown cargo install cargo-udeps --locked cd scripts/helper && yarn cd scripts/polkadot-launch && yarn diff --git a/rust-toolchain b/rust-toolchain index 196683588..45d3fb304 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-02-04" +channel = "nightly-2022-11-15" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] profile = "minimal" From 52369a59ed94533ec129960a2eb11cb82d3aae97 Mon Sep 17 00:00:00 2001 From: dio-will Date: Mon, 10 Jun 2024 21:53:25 +0800 Subject: [PATCH 5/6] Fix chore --- pallets/crowdloans/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/crowdloans/src/lib.rs b/pallets/crowdloans/src/lib.rs index 83d569e9a..5807355e1 100644 --- a/pallets/crowdloans/src/lib.rs +++ b/pallets/crowdloans/src/lib.rs @@ -1843,7 +1843,7 @@ pub mod pallet { // withdrawn the contribution T::Assets::mint_into(T::RelayCurrency::get(), &who, amount)?; - Vaults::::insert((&crowdloan, &lease_start, &lease_end), vault); + // Vaults::::insert((&crowdloan, &lease_start, &lease_end), vault); Self::deposit_event(Event::::VaultRedeemed( crowdloan, From 9f63f4d93c4e932026c6fe9ca85504d9c7300811 Mon Sep 17 00:00:00 2001 From: dio-will Date: Tue, 11 Jun 2024 12:57:12 +0800 Subject: [PATCH 6/6] Apply storage migration --- pallets/crowdloans/src/lib.rs | 13 ++--- pallets/crowdloans/src/migrations.rs | 83 ++++++++++++++++++++++++++++ runtime/parallel/src/lib.rs | 19 ++++++- 3 files changed, 107 insertions(+), 8 deletions(-) diff --git a/pallets/crowdloans/src/lib.rs b/pallets/crowdloans/src/lib.rs index 5807355e1..76b73a8a4 100644 --- a/pallets/crowdloans/src/lib.rs +++ b/pallets/crowdloans/src/lib.rs @@ -1810,7 +1810,7 @@ pub mod pallet { ) -> DispatchResult { let ctoken = Self::ctoken_of((&lease_start, &lease_end)) .ok_or(Error::::CTokenDoesNotExist)?; - let vault = Self::vaults((&crowdloan, &lease_start, &lease_end)) + let mut vault = Self::vaults((&crowdloan, &lease_start, &lease_end)) .ok_or(Error::::VaultDoesNotExist)?; ensure!( @@ -1832,18 +1832,17 @@ pub mod pallet { let ctoken_balance = T::Assets::reducible_balance(ctoken, &who, false); ensure!(ctoken_balance >= amount, Error::::InsufficientBalance); - // NOTE: skipping the vault contribution check - // vault.contributed = vault - // .contributed - // .checked_sub(amount) - // .ok_or(ArithmeticError::Underflow)?; + vault.contributed = vault + .contributed + .checked_sub(amount) + .ok_or(ArithmeticError::Underflow)?; T::Assets::burn_from(ctoken, &who, amount)?; // SovereignAccount on relaychain must have // withdrawn the contribution T::Assets::mint_into(T::RelayCurrency::get(), &who, amount)?; - // Vaults::::insert((&crowdloan, &lease_start, &lease_end), vault); + Vaults::::insert((&crowdloan, &lease_start, &lease_end), vault); Self::deposit_event(Event::::VaultRedeemed( crowdloan, diff --git a/pallets/crowdloans/src/migrations.rs b/pallets/crowdloans/src/migrations.rs index 22dca14d0..053db7077 100644 --- a/pallets/crowdloans/src/migrations.rs +++ b/pallets/crowdloans/src/migrations.rs @@ -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() -> Result, &'static str> { + frame_support::ensure!( + StorageVersion::::get() == Releases::V3_0_0, + "must be V3_0_0" + ); + frame_support::ensure!(NextTrieIndex::::get() == 31, "must be 31"); + Ok(Vec::new()) + } + + pub fn migrate() -> frame_support::weights::Weight { + if StorageVersion::::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::::get((&ParaId::from(para_id), &lease_start, &lease_end)) { + Some(vault) if vault.phase == VaultPhase::Expired => { + Vaults::::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" + ); + ::DbWeight::get().writes(length * 3 + 1u64) + } else { + T::DbWeight::get().reads(1) + } + } + + pub fn post_migrate() -> Result<(), &'static str> { + frame_support::ensure!( + StorageVersion::::get() == Releases::V3_0_0, + "must be V3_0_0" + ); + frame_support::ensure!(NextTrieIndex::::get() == 31, "must be 31"); + log::info!("👜 crowdloan migration passes POST migrate checks ✅",); + + Ok(()) + } +} diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index 238e5f96a..42a82d956 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -2073,7 +2073,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - CrowdloansMigrationV3, + CrowdloansMigrationV4, >; impl fp_self_contained::SelfContainedCall for RuntimeCall { @@ -2134,6 +2134,23 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall { } } +pub struct CrowdloansMigrationV4; +impl OnRuntimeUpgrade for CrowdloansMigrationV4 { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + pallet_crowdloans::migrations::v4::migrate::() + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + pallet_crowdloans::migrations::v4::pre_migrate::() + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), &'static str> { + pallet_crowdloans::migrations::v4::post_migrate::() + } +} + impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration {