From 02044affc6b825e4e9dbf0f56512674f7a448b1e Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 18 Aug 2021 11:32:43 +0800 Subject: [PATCH 1/3] update format --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3be6a24897..2ce93b3cce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2628,7 +2628,7 @@ dependencies = [ [[package]] name = "ethabi" version = "13.0.0" -source = "git+https://github.com/darwinia-network/ethabi.git?tag=v13.0.0-no-std#baacf174d5c2f12122c4ee3fe31506fb52069983" +source = "git+https://github.com/darwinia-network/ethabi?tag=v13.0.0-no-std#baacf174d5c2f12122c4ee3fe31506fb52069983" dependencies = [ "anyhow", "ethereum-types", From 6d38c8f33957b2bb3d6912b9526e554dcd073c26 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 18 Aug 2021 13:01:13 +0800 Subject: [PATCH 2/3] drop bounty --- bin/node/runtime/pangolin/src/lib.rs | 31 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/bin/node/runtime/pangolin/src/lib.rs b/bin/node/runtime/pangolin/src/lib.rs index d5924ddb51..cd6d198749 100644 --- a/bin/node/runtime/pangolin/src/lib.rs +++ b/bin/node/runtime/pangolin/src/lib.rs @@ -899,28 +899,33 @@ impl dvm_rpc_runtime_api::ConvertTransaction for TransactionCon } } +fn migrate_treasury() { + // --- paritytech --- + use frame_support::migration; + + const MODULE: &[u8] = b"DarwiniaTreasury"; + + migration::remove_storage_prefix(MODULE, b"BountyCount", &[]); + log::info!("`BountyCount` Removed"); + migration::remove_storage_prefix(MODULE, b"Bounties", &[]); + log::info!("`Bounties` Removed"); + migration::remove_storage_prefix(MODULE, b"BountyDescriptions", &[]); + log::info!("`BountyDescriptions` Removed"); + migration::remove_storage_prefix(MODULE, b"BountyApprovals", &[]); + log::info!("`BountyApprovals` Removed"); +} + pub struct CustomOnRuntimeUpgrade; impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result<(), &'static str> { - // <--- Hack for local test - use frame_support::traits::Currency; - let _ = Ring::deposit_creating(&BridgeMillauMessages::relayer_fund_account_id(), 1 << 50); - // ---> + migrate_treasury(); Ok(()) } fn on_runtime_upgrade() -> Weight { - // <--- Hack for local test - // use frame_support::traits::Currency; - // let _ = Ring::deposit_creating(&BridgeMillauMessages::relayer_fund_account_id(), 1 << 50); - // ---> - - // --- paritytech --- - use frame_support::migration; - - migration::move_pallet(b"DarwiniaEthereumBacking", b"EthereumBacking"); + migrate_treasury(); RuntimeBlockWeights::get().max_block } From 3e7d13c82303aa062849b292f1e7b3a21e1c8aa5 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 18 Aug 2021 14:52:03 +0800 Subject: [PATCH 3/3] add migration part.1 --- Cargo.lock | 31 ++++++++ bin/node/runtime/pangolin/Cargo.toml | 4 + bin/node/runtime/pangolin/src/lib.rs | 105 +++++++++++++++++++++++++-- 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ce93b3cce..359711cebf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5928,6 +5928,20 @@ dependencies = [ "sp-timestamp", ] +[[package]] +name = "pallet-tips" +version = "3.0.0" +source = "git+https://github.com/darwinia-network/substrate?branch=main#1d7f6e12c651d776fc0dc1adefd007bb60f60b63" +dependencies = [ + "frame-support", + "frame-system", + "pallet-treasury", + "parity-scale-codec", + "serde", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-transaction-payment" version = "3.0.0" @@ -5972,6 +5986,21 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-treasury" +version = "3.0.0" +source = "git+https://github.com/darwinia-network/substrate?branch=main#1d7f6e12c651d776fc0dc1adefd007bb60f60b63" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "pallet-balances", + "parity-scale-codec", + "serde", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-utility" version = "3.0.0" @@ -6084,8 +6113,10 @@ dependencies = [ "pallet-society", "pallet-sudo", "pallet-timestamp", + "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", "pallet-utility", "pangolin-bridge-primitives", "pangolin-constants", diff --git a/bin/node/runtime/pangolin/Cargo.toml b/bin/node/runtime/pangolin/Cargo.toml index 98ccee3040..a7f7c4a51b 100644 --- a/bin/node/runtime/pangolin/Cargo.toml +++ b/bin/node/runtime/pangolin/Cargo.toml @@ -92,8 +92,10 @@ pallet-session = { default-features = false, git = " pallet-society = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } pallet-sudo = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } pallet-timestamp = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } +pallet-tips = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } pallet-transaction-payment = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } +pallet-treasury = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } pallet-utility = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } sp-application-crypto = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "main" } @@ -198,8 +200,10 @@ std = [ "pallet-society/std", "pallet-sudo/std", "pallet-timestamp/std", + "pallet-tips/std", "pallet-transaction-payment/std", "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-treasury/std", "pallet-utility/std", "sp-api/std", "sp-application-crypto/std", diff --git a/bin/node/runtime/pangolin/src/lib.rs b/bin/node/runtime/pangolin/src/lib.rs index cd6d198749..c16c4150e3 100644 --- a/bin/node/runtime/pangolin/src/lib.rs +++ b/bin/node/runtime/pangolin/src/lib.rs @@ -901,18 +901,111 @@ impl dvm_rpc_runtime_api::ConvertTransaction for TransactionCon fn migrate_treasury() { // --- paritytech --- - use frame_support::migration; + use frame_support::{ + migration::{self, StorageKeyIterator}, + Twox64Concat, + }; + + type ProposalIndex = u32; - const MODULE: &[u8] = b"DarwiniaTreasury"; + const OLD_PREFIX: &[u8] = b"DarwiniaTreasury"; + const NEW_PREFIX: &[u8] = b"Instance1Treasury"; - migration::remove_storage_prefix(MODULE, b"BountyCount", &[]); + migration::remove_storage_prefix(OLD_PREFIX, b"BountyCount", &[]); log::info!("`BountyCount` Removed"); - migration::remove_storage_prefix(MODULE, b"Bounties", &[]); + migration::remove_storage_prefix(OLD_PREFIX, b"Bounties", &[]); log::info!("`Bounties` Removed"); - migration::remove_storage_prefix(MODULE, b"BountyDescriptions", &[]); + migration::remove_storage_prefix(OLD_PREFIX, b"BountyDescriptions", &[]); log::info!("`BountyDescriptions` Removed"); - migration::remove_storage_prefix(MODULE, b"BountyApprovals", &[]); + migration::remove_storage_prefix(OLD_PREFIX, b"BountyApprovals", &[]); log::info!("`BountyApprovals` Removed"); + + migration::move_storage_from_pallet(b"ProposalCount", OLD_PREFIX, NEW_PREFIX); + log::info!("`ProposalCount` Migrated"); + migration::move_storage_from_pallet(b"Approvals", OLD_PREFIX, NEW_PREFIX); + log::info!("`Approvals` Migrated"); + + #[derive(Encode, Decode)] + struct OldProposal { + proposer: AccountId, + beneficiary: AccountId, + ring_value: Balance, + kton_value: Balance, + ring_bond: Balance, + kton_bond: Balance, + } + #[derive(Encode, Decode)] + struct Proposal { + proposer: AccountId, + value: Balance, + beneficiary: AccountId, + bond: Balance, + } + for (index, old_proposal) in + StorageKeyIterator::::new( + OLD_PREFIX, + b"Proposals", + ) + .drain() + { + if old_proposal.ring_value != 0 { + let new_proposal = Proposal { + proposer: old_proposal.proposer.clone(), + value: old_proposal.ring_value, + beneficiary: old_proposal.beneficiary.clone(), + bond: old_proposal.ring_bond, + }; + } + if old_proposal.kton_value != 0 { + let new_proposal = Proposal { + proposer: old_proposal.proposer, + value: old_proposal.kton_value, + beneficiary: old_proposal.beneficiary, + bond: old_proposal.kton_bond, + }; + } + } + migration::remove_storage_prefix(OLD_PREFIX, b"Proposals", &[]); + log::info!("`Proposals` Migrated"); + + #[derive(Encode, Decode)] + struct OldTip { + reason: Hash, + who: AccountId, + finder: Option<(AccountId, Balance)>, + closes: Option, + tips: Vec<(AccountId, Balance)>, + } + #[derive(Encode, Decode)] + struct OpenTip { + reason: Hash, + who: AccountId, + finder: AccountId, + deposit: Balance, + closes: Option, + tips: Vec<(AccountId, Balance)>, + finders_fee: bool, + } + for (hash, old_tip) in + StorageKeyIterator::::new(OLD_PREFIX, b"Tips").drain() + { + let (finder, deposit, finders_fee) = if let Some((finder, deposit)) = old_tip.finder { + (finder, deposit, true) + } else { + (AccountId::default(), 0, false) + }; + let new_tip = OpenTip { + reason: old_tip.reason, + who: old_tip.who, + finder, + deposit, + closes: old_tip.closes, + tips: old_tip.tips, + finders_fee, + }; + } + migration::remove_storage_prefix(OLD_PREFIX, b"Tips", &[]); + log::info!("`Tips` Migrated"); } pub struct CustomOnRuntimeUpgrade;