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
26 changes: 26 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ sp-weights = { version = "31.0.0", default-features = false }
static_assertions = { version = "1.1.0" }
substrate-wasm-builder = { version = "24.0.1" }
system-parachains-constants = { path = "system-parachains/constants", default-features = false }
system-parachains-common = { path = "system-parachains/common", default-features = false }
tokio = { version = "1.36.0" }
xcm = { version = "14.2.0", default-features = false, package = "staging-xcm" }
xcm-builder = { version = "17.0.1", default-features = false, package = "staging-xcm-builder" }
Expand Down
29 changes: 23 additions & 6 deletions integration-tests/ahm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ async fn account_migration_works() {
// Simulate relay blocks and grab the DMP messages
let (dmp_messages, pre_check_payload) = rc.execute_with(|| {
let mut dmps = Vec::new();

if let Ok(stage) = std::env::var("START_STAGE") {
let stage = state_from_str::<Polkadot>(&stage);
RcMigrationStage::<Polkadot>::put(stage);
}

let pre_check_payload =
pallet_rc_migrator::preimage::PreimageChunkMigrator::<Polkadot>::pre_check();

Expand Down Expand Up @@ -96,13 +102,24 @@ async fn account_migration_works() {
next_block_ah();
}

pallet_rc_migrator::preimage::PreimageChunkMigrator::<Polkadot>::post_check(
pre_check_payload,
);
pallet_ah_migrator::preimage::PreimageMigrationCheck::<AssetHub>::post_check(
ah_pre_check_payload,
);
// pallet_rc_migrator::preimage::PreimageChunkMigrator::<Polkadot>::post_check(
// pre_check_payload,
// );
// pallet_ah_migrator::preimage::PreimageMigrationCheck::<AssetHub>::post_check(
// ah_pre_check_payload,
// );
// NOTE that the DMP queue is probably not empty because the snapshot that we use contains
// some overweight ones.
});
}

pub fn state_from_str<T: pallet_rc_migrator::Config>(
s: &str,
) -> pallet_rc_migrator::MigrationStageOf<T> {
use pallet_rc_migrator::MigrationStage;
match s {
"preimage" => MigrationStage::PreimageMigrationInit,
"referenda" => MigrationStage::ReferendaMigrationInit,
_ => MigrationStage::Pending,
}
}
8 changes: 8 additions & 0 deletions pallets/ah-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pallet-nomination-pools = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-rc-migrator = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-state-trie-migration = { workspace = true }
polkadot-parachain-primitives = { workspace = true }
Expand Down Expand Up @@ -47,6 +49,8 @@ std = [
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-rc-migrator/std",
"pallet-referenda/std",
"pallet-scheduler/std",
"pallet-staking/std",
"pallet-state-trie-migration/std",
"polkadot-parachain-primitives/std",
Expand All @@ -70,6 +74,8 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-rc-migrator/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand All @@ -86,6 +92,8 @@ try-runtime = [
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-rc-migrator/try-runtime",
"pallet-referenda/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-staking/try-runtime",
"pallet-state-trie-migration/try-runtime",
"polkadot-runtime-common/try-runtime",
Expand Down
62 changes: 61 additions & 1 deletion pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod account;
pub mod multisig;
pub mod preimage;
pub mod proxy;
pub mod referenda;
pub mod staking;
pub mod types;

Expand All @@ -45,14 +46,17 @@ use frame_support::{
storage::{transactional::with_transaction_opaque_err, TransactionOutcome},
traits::{
fungible::{InspectFreeze, Mutate, MutateFreeze, MutateHold},
Defensive, LockableCurrency, ReservableCurrency, WithdrawReasons as LockWithdrawReasons,
Defensive, DefensiveResult, LockableCurrency, OriginTrait, QueryPreimage,
ReservableCurrency, WithdrawReasons as LockWithdrawReasons,
},
};
use frame_system::pallet_prelude::*;
use pallet_balances::{AccountData, Reasons as LockReasons};
use pallet_rc_migrator::{
accounts::Account as RcAccount, multisig::*, preimage::*, proxy::*, staking::nom_pools::*,
};
use pallet_referenda::TrackIdOf;
use referenda::RcReferendumInfoOf;
use sp_application_crypto::Ss58Codec;
use sp_core::H256;
use sp_runtime::{
Expand Down Expand Up @@ -84,6 +88,7 @@ pub mod pallet {
+ pallet_multisig::Config
+ pallet_proxy::Config
+ pallet_preimage::Config<Hash = H256>
+ pallet_referenda::Config<Votes = u128>
+ pallet_nomination_pools::Config
{
/// The overarching event type.
Expand Down Expand Up @@ -116,6 +121,17 @@ pub mod pallet {
type RcToAhDelay: Convert<BlockNumberFor<Self>, BlockNumberFor<Self>>;
/// Access the block number of the Relay Chain.
type RcBlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
/// Some part of the Relay Chain origins used in Governance.
type RcPalletsOrigin: Parameter;
/// Convert a Relay Chain origin to an Asset Hub one.
type RcToAhPalletsOrigin: TryConvert<
Self::RcPalletsOrigin,
<Self::RuntimeOrigin as OriginTrait>::PalletsOrigin,
>;
/// Preimage registry.
type Preimage: QueryPreimage<H = <Self as frame_system::Config>::Hashing>;
/// Convert a Relay Chain Call to a local AH one.
type RcToAhCall: for<'a> TryConvert<&'a [u8], <Self as frame_system::Config>::RuntimeCall>;
}

/// RC accounts that failed to migrate when were received on the Asset Hub.
Expand All @@ -132,6 +148,10 @@ pub mod pallet {
FailedToUnreserveDeposit,
/// Failed to process an account data from RC.
FailedToProcessAccount,
/// Failed to convert RC type to AH type.
FailedToConvertType,
/// Failed to fetch preimage.
PreimageNotFound,
}

#[pallet::event]
Expand Down Expand Up @@ -234,6 +254,19 @@ pub mod pallet {
/// How many nom pools messages failed to integrate.
count_bad: u32,
},
/// We received a batch of referendums that we are going to integrate.
ReferendumsBatchReceived {
/// How many referendums are in the batch.
count: u32,
},
/// We processed a batch of referendums that we received.
ReferendumsBatchProcessed {
/// How many referendums were successfully integrated.
count_good: u32,
/// How many referendums failed to integrate.
count_bad: u32,
},
ReferendaProcessed,
}

#[pallet::pallet]
Expand Down Expand Up @@ -335,6 +368,33 @@ pub mod pallet {

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

/// Receive referendum counts, deciding counts, votes for the track queue.
#[pallet::call_index(8)]
pub fn receive_referenda_values(
origin: OriginFor<T>,
referendum_count: u32,
// track_id, count
deciding_count: Vec<(TrackIdOf<T, ()>, u32)>,
// referendum_id, votes
track_queue: Vec<(TrackIdOf<T, ()>, Vec<(u32, u128)>)>,
) -> DispatchResult {
ensure_root(origin)?;

Self::do_receive_referenda_values(referendum_count, deciding_count, track_queue)
.map_err(Into::into)
}

/// Receive referendums from the Relay Chain.
#[pallet::call_index(9)]
pub fn receive_referendums(
origin: OriginFor<T>,
referendums: Vec<(u32, RcReferendumInfoOf<T, ()>)>,
) -> DispatchResult {
ensure_root(origin)?;

Self::do_receive_referendums(referendums).map_err(Into::into)
}
}

#[pallet::hooks]
Expand Down
Loading
Loading