Skip to content
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
2 changes: 2 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 pallets/ah-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ frame-system = { workspace = true }
log = { workspace = true }
pallet-balances = { workspace = true }
pallet-bags-list = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-fast-unstake = { workspace = true }
pallet-multisig = { workspace = true }
pallet-nomination-pools = { workspace = true }
Expand Down Expand Up @@ -49,6 +50,7 @@ std = [
"log/std",
"pallet-bags-list/std",
"pallet-balances/std",
"pallet-conviction-voting/std",
"pallet-fast-unstake/std",
"pallet-multisig/std",
"pallet-nomination-pools/std",
Expand Down Expand Up @@ -76,6 +78,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
Expand All @@ -96,6 +99,7 @@ try-runtime = [
"frame-system/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nomination-pools/try-runtime",
Expand Down
72 changes: 72 additions & 0 deletions pallets/ah-migrator/src/conviction_voting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 frame_support::traits::{ClassCountOf, DefensiveTruncateFrom};
use pallet_conviction_voting::TallyOf;
use pallet_rc_migrator::conviction_voting::{
alias, RcConvictionVotingMessage, RcConvictionVotingMessageOf,
};

impl<T: Config> Pallet<T> {
pub fn do_receive_conviction_voting_messages(
messages: Vec<RcConvictionVotingMessageOf<T>>,
) -> Result<(), Error<T>> {
log::info!(target: LOG_TARGET, "Processing {} conviction voting messages", messages.len());
let count = messages.len() as u32;
Self::deposit_event(Event::ConvictionVotingMessagesReceived { count });

for message in messages {
Self::do_receive_conviction_voting_message(message);
}

Self::deposit_event(Event::ConvictionVotingMessagesProcessed { count_good: count });

Ok(())
}

pub fn do_receive_conviction_voting_message(message: RcConvictionVotingMessageOf<T>) {
match message {
RcConvictionVotingMessage::VotingFor(account_id, class, voting) => {
Self::do_process_voting_for(account_id, class, voting);
},
RcConvictionVotingMessage::ClassLocksFor(account_id, balance_per_class) => {
Self::do_process_class_locks_for(account_id, balance_per_class);
},
};
}

pub fn do_process_voting_for(
account_id: T::AccountId,
class: alias::ClassOf<T>,
voting: alias::VotingOf<T>,
) {
log::debug!(target: LOG_TARGET, "Processing VotingFor record for: {:?}", &account_id);
alias::VotingFor::<T>::insert(account_id, class, voting);
}

pub fn do_process_class_locks_for(
account_id: T::AccountId,
balance_per_class: Vec<(alias::ClassOf<T>, alias::BalanceOf<T>)>,
) {
log::debug!(target: LOG_TARGET, "Processing ClassLocksFor record for: {:?}", &account_id);
let balance_per_class =
BoundedVec::<_, ClassCountOf<T::Polls, TallyOf<T, ()>>>::defensive_truncate_from(
balance_per_class,
);
pallet_conviction_voting::ClassLocksFor::<T>::insert(account_id, balance_per_class);
}
}
21 changes: 21 additions & 0 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
pub mod account;
pub mod call;
pub mod claims;
pub mod conviction_voting;
pub mod multisig;
pub mod preimage;
pub mod proxy;
Expand All @@ -58,6 +59,7 @@ use pallet_balances::{AccountData, Reasons as LockReasons};
use pallet_rc_migrator::{
accounts::Account as RcAccount,
claims::RcClaimsMessageOf,
conviction_voting::RcConvictionVotingMessageOf,
multisig::*,
preimage::*,
proxy::*,
Expand Down Expand Up @@ -113,6 +115,7 @@ pub mod pallet {
+ pallet_fast_unstake::Config
+ pallet_bags_list::Config<pallet_bags_list::Instance1>
+ pallet_scheduler::Config
+ pallet_conviction_voting::Config
{
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -329,6 +332,14 @@ pub mod pallet {
/// How many scheduler messages failed to integrate.
count_bad: u32,
},
ConvictionVotingMessagesReceived {
/// How many conviction voting messages are in the batch.
count: u32,
},
ConvictionVotingMessagesProcessed {
/// How many conviction voting messages were successfully integrated.
count_good: u32,
},
}

#[pallet::pallet]
Expand Down Expand Up @@ -497,6 +508,16 @@ pub mod pallet {

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

#[pallet::call_index(14)]
pub fn receive_conviction_voting_messages(
origin: OriginFor<T>,
messages: Vec<RcConvictionVotingMessageOf<T>>,
) -> DispatchResult {
ensure_root(origin)?;

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

#[pallet::hooks]
Expand Down
4 changes: 4 additions & 0 deletions pallets/rc-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sp-std = { workspace = true }
sp-io = { workspace = true }
pallet-balances = { workspace = true }
pallet-bags-list = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-proxy = { workspace = true }
Expand All @@ -46,6 +47,7 @@ std = [
"log/std",
"pallet-bags-list/std",
"pallet-balances/std",
"pallet-conviction-voting/std",
"pallet-fast-unstake/std",
"pallet-multisig/std",
"pallet-nomination-pools/std",
Expand All @@ -72,6 +74,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
Expand All @@ -91,6 +94,7 @@ try-runtime = [
"frame-system/try-runtime",
"pallet-bags-list/try-runtime",
"pallet-balances/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nomination-pools/try-runtime",
Expand Down
Loading
Loading