Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AHM] Bounties data migration #585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions pallets/ah-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ log = { workspace = true }
pallet-asset-rate = { workspace = true }
pallet-balances = { workspace = true }
pallet-bags-list = { workspace = true }
pallet-bounties = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-fast-unstake = { workspace = true }
pallet-multisig = { workspace = true }
Expand All @@ -28,6 +29,7 @@ pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-state-trie-migration = { workspace = true }
pallet-treasury = { workspace = true }
polkadot-parachain-primitives = { workspace = true }
polkadot-runtime-common = { workspace = true }
runtime-parachains = { workspace = true }
Expand All @@ -53,6 +55,7 @@ std = [
"pallet-asset-rate/std",
"pallet-bags-list/std",
"pallet-balances/std",
"pallet-bounties/std",
"pallet-conviction-voting/std",
"pallet-fast-unstake/std",
"pallet-indices/std",
Expand All @@ -65,6 +68,7 @@ std = [
"pallet-scheduler/std",
"pallet-staking/std",
"pallet-state-trie-migration/std",
"pallet-treasury/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"runtime-parachains/std",
Expand All @@ -83,6 +87,7 @@ runtime-benchmarks = [
"pallet-asset-rate/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
Expand All @@ -95,6 +100,7 @@ runtime-benchmarks = [
"pallet-scheduler/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"runtime-parachains/runtime-benchmarks",
Expand All @@ -106,6 +112,7 @@ try-runtime = [
"pallet-asset-rate/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-indices/try-runtime",
Expand All @@ -118,6 +125,7 @@ try-runtime = [
"pallet-scheduler/try-runtime",
"pallet-staking/try-runtime",
"pallet-state-trie-migration/try-runtime",
"pallet-treasury/try-runtime",
"polkadot-runtime-common/try-runtime",
"runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
Expand Down
81 changes: 81 additions & 0 deletions pallets/ah-migrator/src/bounties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::*;
use pallet_rc_migrator::bounties::{RcBountiesMessage, RcBountiesMessageOf};

impl<T: Config> Pallet<T> {
pub fn do_receive_bounties_messages(
messages: Vec<RcBountiesMessageOf<T>>,
) -> Result<(), Error<T>> {
log::info!(target: LOG_TARGET, "Processing {} bounties messages", messages.len());
Self::deposit_event(Event::BatchReceived {
pallet: PalletEventName::Bounties,
count: messages.len() as u32,
});
let (mut count_good, mut count_bad) = (0, 0);

for message in messages {
match Self::do_process_bounty_message(message) {
Ok(()) => count_good += 1,
Err(_) => count_bad += 1,
}
}

Self::deposit_event(Event::BatchProcessed {
pallet: PalletEventName::Bounties,
count_good,
count_bad,
});
log::info!(target: LOG_TARGET, "Processed {}/{} bounties messages", count_good, count_bad);

Ok(())
}

fn do_process_bounty_message(message: RcBountiesMessageOf<T>) -> Result<(), Error<T>> {
log::debug!(target: LOG_TARGET, "Processing bounties message: {:?}", message);

match message {
RcBountiesMessage::BountyCount(count) => {
log::debug!(target: LOG_TARGET, "Integrating bounties count: {:?}", count);
pallet_bounties::BountyCount::<T>::put(count);
},
RcBountiesMessage::BountyApprovals(approvals) => {
log::debug!(target: LOG_TARGET, "Integrating bounties approvals: {:?}", approvals);
let approvals = BoundedVec::<
_,
<T as pallet_treasury::Config>::MaxApprovals
>::defensive_truncate_from(approvals);
pallet_bounties::BountyApprovals::<T>::put(approvals);
},
RcBountiesMessage::BountyDescriptions((index, description)) => {
log::debug!(target: LOG_TARGET, "Integrating bounties descriptions: {:?}", description);
let description = BoundedVec::<
_,
<T as pallet_bounties::Config>::MaximumReasonLength,
>::defensive_truncate_from(description);
pallet_bounties::BountyDescriptions::<T>::insert(index, description);
},
RcBountiesMessage::Bounties((index, bounty)) => {
log::debug!(target: LOG_TARGET, "Integrating bounty: {:?}", index);
pallet_bounties::Bounties::<T>::insert(index, bounty);
},
}

log::debug!(target: LOG_TARGET, "Processed bounties message");
Ok(())
}
}
19 changes: 17 additions & 2 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

pub mod account;
pub mod asset_rate;
pub mod bounties;
pub mod call;
pub mod claims;
pub mod conviction_voting;
Expand All @@ -53,8 +54,8 @@ use frame_support::{
storage::{transactional::with_transaction_opaque_err, TransactionOutcome},
traits::{
fungible::{InspectFreeze, Mutate, MutateFreeze, MutateHold},
Defensive, LockableCurrency, OriginTrait, QueryPreimage, ReservableCurrency, StorePreimage,
WithdrawReasons as LockWithdrawReasons,
Defensive, DefensiveTruncateFrom, LockableCurrency, OriginTrait, QueryPreimage,
ReservableCurrency, StorePreimage, WithdrawReasons as LockWithdrawReasons,
},
};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -99,6 +100,7 @@ pub enum PalletEventName {
Indices,
FastUnstake,
BagsList,
Bounties,
}

#[frame_support::pallet(dev_mode)]
Expand All @@ -122,6 +124,8 @@ pub mod pallet {
+ pallet_scheduler::Config
+ pallet_indices::Config
+ pallet_conviction_voting::Config
+ pallet_bounties::Config
+ pallet_treasury::Config
+ pallet_asset_rate::Config
{
/// The overarching event type.
Expand Down Expand Up @@ -198,6 +202,7 @@ pub mod pallet {
pub enum Event<T: Config> {
/// The event that should to be replaced by something meaningful.
TODO,

/// We received a batch of accounts that we are going to integrate.
AccountBatchReceived {
/// How many accounts are in the batch.
Expand Down Expand Up @@ -547,6 +552,16 @@ pub mod pallet {
}

#[pallet::call_index(16)]
pub fn receive_bounties_messages(
origin: OriginFor<T>,
messages: Vec<pallet_rc_migrator::bounties::RcBountiesMessageOf<T>>,
) -> DispatchResult {
ensure_root(origin)?;

Self::do_receive_bounties_messages(messages).map_err(Into::into)
}

#[pallet::call_index(17)]
pub fn receive_asset_rates(
origin: OriginFor<T>,
rates: Vec<(<T as pallet_asset_rate::Config>::AssetKind, FixedU128)>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/ah-migrator/src/preimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<T: Config> pallet_rc_migrator::types::PalletMigrationChecks for PreimageMig
alias::RequestStatusFor::<T>::iter_keys().count(),
"Preimage::PreimageFor and Preimage::RequestStatusFor have different lengths"
);*/
// TODO fixme (ggwpez had to comment this since it fails with a new snapshot)
// TODO fixme (ggwpez had to comment this since it fails with a new snapshot)

// Check that the PreimageFor entries are sane.
for (key, preimage) in alias::PreimageFor::<T>::iter() {
Expand Down
8 changes: 8 additions & 0 deletions pallets/rc-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ sp-io = { workspace = true }
pallet-asset-rate = { workspace = true }
pallet-balances = { workspace = true }
pallet-bags-list = { workspace = true }
pallet-bounties = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-proxy = { workspace = true }
pallet-indices = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-treasury = { workspace = true }
pallet-fast-unstake = { workspace = true }
pallet-referenda = { workspace = true }
pallet-nomination-pools = { workspace = true }
Expand All @@ -50,6 +52,7 @@ std = [
"pallet-asset-rate/std",
"pallet-bags-list/std",
"pallet-balances/std",
"pallet-bounties/std",
"pallet-conviction-voting/std",
"pallet-fast-unstake/std",
"pallet-indices/std",
Expand All @@ -60,6 +63,7 @@ std = [
"pallet-referenda/std",
"pallet-scheduler/std",
"pallet-staking/std",
"pallet-treasury/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"runtime-parachains/std",
Expand All @@ -79,6 +83,7 @@ runtime-benchmarks = [
"pallet-asset-rate/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
Expand All @@ -89,6 +94,7 @@ runtime-benchmarks = [
"pallet-referenda/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"runtime-parachains/runtime-benchmarks",
Expand All @@ -101,6 +107,7 @@ try-runtime = [
"pallet-asset-rate/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-indices/try-runtime",
Expand All @@ -111,6 +118,7 @@ try-runtime = [
"pallet-referenda/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-staking/try-runtime",
"pallet-treasury/try-runtime",
"polkadot-runtime-common/try-runtime",
"runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
Expand Down
Loading
Loading