-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging into the AHM working branch. Depends on #579 # Pallet Vesting Pallet vesting has one storage map to hold the vesting schedules and one storage value to track the current version of the pallet. The version can be easily migrated, but for the schedules it is a bit difficult. ## Storage: Vesting The vesting schedules are already measured in relay blocks, as can be seen [here](https://github.com/polkadot-fellows/runtimes/blob/b613b54d94af5f4702533a56c6260651a14bdccb/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs#L297). This means that we can just integrate the existing schedules. The only possibly issue is when there are lots of pre-existing schedules. The maximal number of schedules is 28; both on Relay and AH. We cannot use the merge functionality of the vesting pallet since that can be used as an attack vector: anyone can send 28 vested transfers with very large unlock duration and low amount to force all other schedules to adapt this long unlock period. This would reduce the rewards per block, which is bad. For now, we are writing all colliding AH schedules into a storage item for manual inspection later. It could still happen that unmalicious users will have more than 28 schedules, but as nobody has used the vested transfers on AH yet. Q: Maybe we should disable vested transfers with the next runtime upgrade on AH. ## Storage: StorageVersion The vesting pallet is not using the proper FRAME version tracking; rather, it tracks its version in the `StorageVersion` value. It does this incorrectly though, with Asset Hub reporting version 0 instead of 1. We ignore and correct this by writing 1 to the storage. ## User Impact This affects users that have vesting schedules on the Relay chain or on Asset Hub. There exists a risk that the number of total schedules exceeds 28, which means that they will not fit into the storage anymore. We then prioritize the schedules from AH and pause and stash all schedules that do not fit (up to 28). - [x] Does not require a CHANGELOG entry --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]>
- Loading branch information
Showing
10 changed files
with
440 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! To run these benchmarks, you will need a modified version of `frame-omni-bencher` that can load | ||
//! snapshots of the relay and asset hub. You can find it on branch `oty-ahm-omni-bencher` of the | ||
//! SDK. Install it with | ||
//! `cargo install --path substrate/utils/frame/omni-bencher --profile production` | ||
//! | ||
//! ```bash | ||
//! frame-omni-bencher v1 benchmark pallet --runtime=target/release/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.wasm --pallet "pallet-ah-migrator" --extrinsic "" --snap=ah-polkadot.snap --rc-snap=polkadot.snap | ||
//! ``` | ||
use crate::*; | ||
use core::str::FromStr; | ||
use cumulus_primitives_core::{AggregateMessageOrigin, InboundDownwardMessage}; | ||
use frame_benchmarking::v2::*; | ||
use frame_support::{traits::EnqueueMessage, weights::WeightMeter}; | ||
use frame_system::RawOrigin; | ||
use pallet_rc_migrator::types::PalletMigration; | ||
use xcm::VersionedXcm; | ||
|
||
#[benchmarks(where T: pallet_balances::Config)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn receive_multisigs() { | ||
verify_snapshot::<T>(); | ||
let (messages, _cursor) = relay_snapshot(|| { | ||
unwrap_no_debug(pallet_rc_migrator::multisig::MultisigMigrator::<T>::migrate_out_many( | ||
None, | ||
&mut WeightMeter::new(), | ||
)) | ||
}); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Root, messages); | ||
|
||
// TODO assert event | ||
} | ||
|
||
#[benchmark] | ||
fn receive_nom_pools_messages_pool_members() { | ||
verify_snapshot::<T>(); | ||
let (messages, _cursor) = relay_snapshot(|| { | ||
unwrap_no_debug(pallet_rc_migrator::staking::nom_pools::NomPoolsMigrator::<T>::migrate_many( | ||
None, | ||
&mut WeightMeter::new(), | ||
)) | ||
}); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Root, messages); | ||
|
||
// TODO assert event | ||
} | ||
} | ||
|
||
/// Unwrap something that does not implement Debug. Otherwise we would need to require | ||
/// `pallet_rc_migrator::Config` on out runtime `T`. | ||
pub fn unwrap_no_debug<T, E>(result: Result<T, E>) -> T { | ||
match result { | ||
Ok(t) => t, | ||
Err(_) => panic!("unwrap_no_debug"), | ||
} | ||
} | ||
|
||
/// Check that Oliver's account has some balance on AH and Relay. | ||
/// | ||
/// This serves as sanity check that the snapshots were loaded correctly. | ||
fn verify_snapshot<T: Config>() { | ||
let raw_acc: [u8; 32] = | ||
hex::decode("6c9e3102dd2c24274667d416e07570ebce6f20ab80ee3fc9917bf4a7568b8fd2") | ||
.unwrap() | ||
.try_into() | ||
.unwrap(); | ||
let acc = AccountId32::from(raw_acc); | ||
frame_system::Pallet::<T>::reset_events(); | ||
|
||
// Sanity check that this is the right account | ||
let ah_acc = frame_system::Account::<T>::get(&acc); | ||
if ah_acc.data.free == 0 { | ||
panic!("No or broken snapshot: account does not have any balance"); | ||
} | ||
|
||
let key = frame_system::Account::<T>::hashed_key_for(&acc); | ||
let raw_acc = relay_snapshot(|| { | ||
frame_support::storage::unhashed::get::< | ||
pallet_balances::AccountData<<T as pallet_balances::Config>::Balance>, | ||
>(key.as_ref()) | ||
}).unwrap(); | ||
|
||
if raw_acc.free == 0 { | ||
panic!("No or broken snapshot: account does not have any balance"); | ||
} | ||
} | ||
|
||
/// Read something from the relay chain snapshot instead of the asset hub one. | ||
fn relay_snapshot<R, F: FnOnce() -> R>(f: F) -> R { | ||
sp_io::storage::get(b"relay_chain_enable"); | ||
let result = f(); | ||
sp_io::storage::get(b"relay_chain_disable"); | ||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.