From ed481c343a23f103d6700e48806010312e8e838c Mon Sep 17 00:00:00 2001 From: "test@test.com" Date: Tue, 29 Oct 2024 14:08:16 +0000 Subject: [PATCH] wip Signed-off-by: test@test.com --- Cargo.lock | 2 ++ ahm-controller/src/lib.rs | 52 ++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db1ea36e83..293549e068 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7735,6 +7735,8 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", + "sp-crypto-hashing", + "sp-io 37.0.0", "sp-runtime 38.0.0", "sp-std", ] diff --git a/ahm-controller/src/lib.rs b/ahm-controller/src/lib.rs index de45571285..5e7be114ad 100644 --- a/ahm-controller/src/lib.rs +++ b/ahm-controller/src/lib.rs @@ -54,18 +54,21 @@ pub enum Role { } #[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] -pub enum Phase { +pub enum Phases { MigrateBalancesEds { next_account: Option>> }, AllDone, } +/// WARNING EXTREMLY IMPORTANT THAT THESE INDICES ARE CORRECT #[derive(Encode, Decode)] enum AssetHubPalletConfig { - #[codec(index = 244)] - AhmController(AhmCall), #[codec(index = 5)] Indices(pallet_indices::Call), + #[codec(index = 10)] + Balances(pallet_balances::Call), + #[codec(index = 244)] + AhmController(AhmCall), } /// Call encoding for the calls needed from the Broker pallet. @@ -100,7 +103,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::storage] - pub type Phase = StorageValue<_, super::Phase>; + pub type Phase = StorageValue<_, super::Phases>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -146,19 +149,19 @@ pub mod pallet { fn relay_on_init() { // Phase init let phase = match Phase::::get() { - None => Phase::MigrateBalancesEds { next_account: Vec::new() }, + None => Phases::MigrateBalancesEds { next_account: None }, Some(phase) => phase, }; // Phase handling and transistion let phase = match phase { - Phase::MigrateBalancesEds { mut next_account } => { - Self::migrate_eds(&mut next_account, 100)?; + Phases::MigrateBalancesEds { mut next_account } => { + Self::migrate_eds(&mut next_account); if next_account.is_some() { - Phase::MigrateBalancesEds { next_account } + Phases::MigrateBalancesEds { next_account } } else { - Phase::AllDone + Phases::AllDone } }, other => other, @@ -175,13 +178,32 @@ pub mod pallet { }*/ } - fn migrate_eds(next_acc: &mut Option>) -> Result<(), ()> { - frame_support::storage::transactional::with_transaction_opaque_err::<(), (), _>(|| { - let Some((call, weight)) = pallet_balances::Pallet::::migrate_ed(&mut next_acc, 100) else { - return TransactionOutcome::Commit(Ok(())); + // Just to make the BoundedVec compiler stuff work... + fn migrate_eds(next_acc: &mut Option>>) { + let Ok(new) = Self::do_migrate_eds(next_acc.clone().map(|v| v.into_inner())) else { + // TODO what do? + return; + }; + let Some(new) = new else { + *next_acc = None; + return; + }; + + let Ok(new_bounded) = BoundedVec::try_from(new) else { + defensive!("Very bad: could not store next cursor"); + // TODO yikes + return; + }; + *next_acc = Some(new_bounded); + } + + fn do_migrate_eds(next_acc: Option>) -> Result>, ()> { + frame_support::storage::transactional::with_transaction_opaque_err::>, (), _>(|| { + let Some((next_key, call, weight)) = pallet_balances::Pallet::::migrate_ed(next_acc, 100) else { + return TransactionOutcome::Commit(Ok(None)); }; - let ah_call: xcm::DoubleEncoded<()> = AssetHubPalletConfig::::Indices( + let ah_call: xcm::DoubleEncoded<()> = AssetHubPalletConfig::::Balances( call, ).encode().into(); @@ -203,7 +225,7 @@ pub mod pallet { ) { Ok(_) => { Self::deposit_event(Event::SentDownward); - TransactionOutcome::Commit(Ok(())) + TransactionOutcome::Commit(Ok(next_key)) }, Err(_) => { Self::deposit_event(Event::ErrorSendingDownward);