Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)

* Initial setup

* Adds node block

* Uses UncheckedExtrinsic and removes Where section

* Updates frame_system to use Block

* Adds deprecation warning

* Fixes pallet-timestamp

* Removes Header and BlockNumber

* Addresses review comments

* Addresses review comments

* Adds comment about compiler bug

* Removes where clause

* Refactors code

* Fixes errors in cargo check

* Fixes errors in cargo check

* Fixes warnings in cargo check

* Formatting

* Fixes construct_runtime tests

* Uses import instead of full path for BlockNumber

* Uses import instead of full path for Header

* Formatting

* Fixes construct_runtime tests

* Fixes imports in benchmarks

* Formatting

* Fixes construct_runtime tests

* Formatting

* Minor updates

* Fixes construct_runtime ui tests

* Fixes construct_runtime ui tests with 1.70

* Fixes docs

* Fixes docs

* Adds u128 mock block type

* Fixes split example

* fixes for cumulus

* ".git/.scripts/commands/fmt/fmt.sh"

* Updates new tests

* Fixes fully-qualified path in few places

* Formatting

* Update frame/examples/default-config/src/lib.rs

Co-authored-by: Juan <juangirini@gmail.com>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Juan <juangirini@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* Addresses some review comments

* Fixes build

* ".git/.scripts/commands/fmt/fmt.sh"

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Addresses review comments

* Updates trait bounds

* Minor fix

* ".git/.scripts/commands/fmt/fmt.sh"

* Removes unnecessary bound

* ".git/.scripts/commands/fmt/fmt.sh"

* Updates test

* Fixes build

* Adds a bound for header

* ".git/.scripts/commands/fmt/fmt.sh"

* Removes where block

* Minor fix

* Minor fix

* Fixes tests

* ".git/.scripts/commands/update-ui/update-ui.sh" 1.70

* Updates test

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Updates doc

* Updates doc

---------

Co-authored-by: command-bot <>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
gupnik
2023-07-13 17:31:34 +05:30
committed by GitHub
parent e42a669c50
commit 5e7b27e98c
277 changed files with 2017 additions and 2450 deletions
+5 -5
View File
@@ -21,7 +21,7 @@
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::assert_ok;
use frame_system::{Pallet as System, RawOrigin};
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul};
use super::*;
@@ -55,7 +55,7 @@ fn add_vesting_schedules<T: Config>(
let source_lookup = T::Lookup::unlookup(source.clone());
T::Currency::make_free_balance_be(&source, BalanceOf::<T>::max_value());
System::<T>::set_block_number(T::BlockNumber::zero());
System::<T>::set_block_number(BlockNumberFor::<T>::zero());
let mut total_locked: BalanceOf<T> = Zero::zero();
for _ in 0..n {
@@ -88,7 +88,7 @@ benchmarks! {
let expected_balance = add_vesting_schedules::<T>(caller_lookup, s)?;
// At block zero, everything is vested.
assert_eq!(System::<T>::block_number(), T::BlockNumber::zero());
assert_eq!(System::<T>::block_number(), BlockNumberFor::<T>::zero());
assert_eq!(
Vesting::<T>::vesting_balance(&caller),
Some(expected_balance),
@@ -144,7 +144,7 @@ benchmarks! {
let expected_balance = add_vesting_schedules::<T>(other_lookup.clone(), s)?;
// At block zero, everything is vested.
assert_eq!(System::<T>::block_number(), T::BlockNumber::zero());
assert_eq!(System::<T>::block_number(), BlockNumberFor::<T>::zero());
assert_eq!(
Vesting::<T>::vesting_balance(&other),
Some(expected_balance),
@@ -284,7 +284,7 @@ benchmarks! {
let expected_balance = add_vesting_schedules::<T>(caller_lookup, s)?;
// Schedules are not vesting at block 0.
assert_eq!(System::<T>::block_number(), T::BlockNumber::zero());
assert_eq!(System::<T>::block_number(), BlockNumberFor::<T>::zero());
assert_eq!(
Vesting::<T>::vesting_balance(&caller),
Some(expected_balance),
+22 -21
View File
@@ -67,6 +67,7 @@ use frame_support::{
},
weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{
@@ -127,8 +128,8 @@ impl VestingAction {
/// Pick the schedules that this action dictates should continue vesting undisturbed.
fn pick_schedules<T: Config>(
&self,
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
) -> impl Iterator<Item = VestingInfo<BalanceOf<T>, T::BlockNumber>> + '_ {
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
) -> impl Iterator<Item = VestingInfo<BalanceOf<T>, BlockNumberFor<T>>> + '_ {
schedules.into_iter().enumerate().filter_map(move |(index, schedule)| {
if self.should_remove(index) {
None
@@ -162,7 +163,7 @@ pub mod pallet {
type Currency: LockableCurrency<Self::AccountId>;
/// Convert the block number into a balance.
type BlockNumberToBalance: Convert<Self::BlockNumber, BalanceOf<Self>>;
type BlockNumberToBalance: Convert<BlockNumberFor<Self>, BalanceOf<Self>>;
/// The minimum amount transferred to call `vested_transfer`.
#[pallet::constant]
@@ -201,7 +202,7 @@ pub mod pallet {
_,
Blake2_128Concat,
T::AccountId,
BoundedVec<VestingInfo<BalanceOf<T>, T::BlockNumber>, MaxVestingSchedulesGet<T>>,
BoundedVec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>, MaxVestingSchedulesGet<T>>,
>;
/// Storage version of the pallet.
@@ -216,7 +217,7 @@ pub mod pallet {
#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub vesting: Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, BalanceOf<T>)>,
pub vesting: Vec<(T::AccountId, BlockNumberFor<T>, BlockNumberFor<T>, BalanceOf<T>)>,
}
#[pallet::genesis_build]
@@ -342,7 +343,7 @@ pub mod pallet {
pub fn vested_transfer(
origin: OriginFor<T>,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let transactor = <T::Lookup as StaticLookup>::unlookup(transactor);
@@ -371,7 +372,7 @@ pub mod pallet {
origin: OriginFor<T>,
source: AccountIdLookupOf<T>,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
) -> DispatchResult {
ensure_root(origin)?;
Self::do_vested_transfer(source, target, schedule)
@@ -433,10 +434,10 @@ impl<T: Config> Pallet<T> {
// Create a new `VestingInfo`, based off of two other `VestingInfo`s.
// NOTE: We assume both schedules have had funds unlocked up through the current block.
fn merge_vesting_info(
now: T::BlockNumber,
schedule1: VestingInfo<BalanceOf<T>, T::BlockNumber>,
schedule2: VestingInfo<BalanceOf<T>, T::BlockNumber>,
) -> Option<VestingInfo<BalanceOf<T>, T::BlockNumber>> {
now: BlockNumberFor<T>,
schedule1: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
schedule2: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
) -> Option<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>> {
let schedule1_ending_block = schedule1.ending_block_as_balance::<T::BlockNumberToBalance>();
let schedule2_ending_block = schedule2.ending_block_as_balance::<T::BlockNumberToBalance>();
let now_as_balance = T::BlockNumberToBalance::convert(now);
@@ -483,7 +484,7 @@ impl<T: Config> Pallet<T> {
fn do_vested_transfer(
source: AccountIdLookupOf<T>,
target: AccountIdLookupOf<T>,
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
) -> DispatchResult {
// Validate user inputs.
ensure!(schedule.locked() >= T::MinVestedTransfer::get(), Error::<T>::AmountLow);
@@ -531,9 +532,9 @@ impl<T: Config> Pallet<T> {
///
/// NOTE: the amount locked does not include any schedules that are filtered out via `action`.
fn report_schedule_updates(
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
action: VestingAction,
) -> (Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>, BalanceOf<T>) {
) -> (Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>, BalanceOf<T>) {
let now = <frame_system::Pallet<T>>::block_number();
let mut total_locked_now: BalanceOf<T> = Zero::zero();
@@ -570,10 +571,10 @@ impl<T: Config> Pallet<T> {
/// Write an accounts updated vesting schedules to storage.
fn write_vesting(
who: &T::AccountId,
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
) -> Result<(), DispatchError> {
let schedules: BoundedVec<
VestingInfo<BalanceOf<T>, T::BlockNumber>,
VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
MaxVestingSchedulesGet<T>,
> = schedules.try_into().map_err(|_| Error::<T>::AtMaxVestingSchedules)?;
@@ -602,9 +603,9 @@ impl<T: Config> Pallet<T> {
/// Execute a `VestingAction` against the given `schedules`. Returns the updated schedules
/// and locked amount.
fn exec_action(
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
action: VestingAction,
) -> Result<(Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>, BalanceOf<T>), DispatchError> {
) -> Result<(Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>, BalanceOf<T>), DispatchError> {
let (schedules, locked_now) = match action {
VestingAction::Merge { index1: idx1, index2: idx2 } => {
// The schedule index is based off of the schedule ordering prior to filtering out
@@ -649,7 +650,7 @@ where
BalanceOf<T>: MaybeSerializeDeserialize + Debug,
{
type Currency = T::Currency;
type Moment = T::BlockNumber;
type Moment = BlockNumberFor<T>;
/// Get the amount that is currently being vested and cannot be transferred out of this account.
fn vesting_balance(who: &T::AccountId) -> Option<BalanceOf<T>> {
@@ -680,7 +681,7 @@ where
who: &T::AccountId,
locked: BalanceOf<T>,
per_block: BalanceOf<T>,
starting_block: T::BlockNumber,
starting_block: BlockNumberFor<T>,
) -> DispatchResult {
if locked.is_zero() {
return Ok(())
@@ -713,7 +714,7 @@ where
who: &T::AccountId,
locked: BalanceOf<T>,
per_block: BalanceOf<T>,
starting_block: T::BlockNumber,
starting_block: BlockNumberFor<T>,
) -> DispatchResult {
// Check for `per_block` or `locked` of 0.
if !VestingInfo::new(locked, per_block, starting_block).is_valid() {
+2 -2
View File
@@ -40,12 +40,12 @@ pub mod v1 {
pub fn migrate<T: Config>() -> Weight {
let mut reads_writes = 0;
Vesting::<T>::translate::<VestingInfo<BalanceOf<T>, T::BlockNumber>, _>(
Vesting::<T>::translate::<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>, _>(
|_key, vesting_info| {
reads_writes += 1;
let v: Option<
BoundedVec<
VestingInfo<BalanceOf<T>, T::BlockNumber>,
VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
MaxVestingSchedulesGet<T>,
>,
> = vec![vesting_info].try_into().ok();
+2 -8
View File
@@ -21,7 +21,6 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, Identity, IdentityLookup},
BuildStorage,
};
@@ -29,14 +28,10 @@ use sp_runtime::{
use super::*;
use crate as pallet_vesting;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -50,14 +45,13 @@ impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = ConstU64<250>;
type BlockLength = ();
type BlockNumber = u64;
type BlockWeights = ();
type RuntimeCall = RuntimeCall;
type DbWeight = ();
type RuntimeEvent = RuntimeEvent;
type Hash = H256;
type Hashing = BlakeTwo256;
type Header = Header;
type Block = Block;
type Index = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type OnKilledAccount = ();