Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Merge 3e7d13c into ebecfca
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Lau authored Aug 18, 2021
2 parents ebecfca + 3e7d13c commit f64db84
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 13 deletions.
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bin/node/runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down
124 changes: 111 additions & 13 deletions bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,28 +899,126 @@ impl dvm_rpc_runtime_api::ConvertTransaction<OpaqueExtrinsic> for TransactionCon
}
}

fn migrate_treasury() {
// --- paritytech ---
use frame_support::{
migration::{self, StorageKeyIterator},
Twox64Concat,
};

type ProposalIndex = u32;

const OLD_PREFIX: &[u8] = b"DarwiniaTreasury";
const NEW_PREFIX: &[u8] = b"Instance1Treasury";

migration::remove_storage_prefix(OLD_PREFIX, b"BountyCount", &[]);
log::info!("`BountyCount` Removed");
migration::remove_storage_prefix(OLD_PREFIX, b"Bounties", &[]);
log::info!("`Bounties` Removed");
migration::remove_storage_prefix(OLD_PREFIX, b"BountyDescriptions", &[]);
log::info!("`BountyDescriptions` Removed");
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::<ProposalIndex, OldProposal, Twox64Concat>::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<BlockNumber>,
tips: Vec<(AccountId, Balance)>,
}
#[derive(Encode, Decode)]
struct OpenTip {
reason: Hash,
who: AccountId,
finder: AccountId,
deposit: Balance,
closes: Option<BlockNumber>,
tips: Vec<(AccountId, Balance)>,
finders_fee: bool,
}
for (hash, old_tip) in
StorageKeyIterator::<Hash, OldTip, Twox64Concat>::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;
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
}
Expand Down

0 comments on commit f64db84

Please sign in to comment.