rustfmt common runtime and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
8d69e5c87e
commit
24a6f803c5
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-runtime-common"
|
name = "ghost-runtime-common"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
use primitives::{AccountId, Balance};
|
|
||||||
use pallet_treasury::ArgumentsFactory;
|
|
||||||
use sp_core::crypto::FromEntropy;
|
|
||||||
use frame_support::traits::tokens::{Pay, PaymentStatus};
|
use frame_support::traits::tokens::{Pay, PaymentStatus};
|
||||||
|
use pallet_treasury::ArgumentsFactory;
|
||||||
|
use primitives::{AccountId, Balance};
|
||||||
|
use sp_core::crypto::FromEntropy;
|
||||||
|
|
||||||
pub struct BenchmarkTreasuryHelper;
|
pub struct BenchmarkTreasuryHelper;
|
||||||
impl ArgumentsFactory<(), AccountId> for BenchmarkTreasuryHelper {
|
impl ArgumentsFactory<(), AccountId> for BenchmarkTreasuryHelper {
|
||||||
fn create_asset_kind(_seed: u32) -> () { () }
|
fn create_asset_kind(_seed: u32) -> () {
|
||||||
|
()
|
||||||
|
}
|
||||||
fn create_beneficiary(seed: [u8; 32]) -> AccountId {
|
fn create_beneficiary(seed: [u8; 32]) -> AccountId {
|
||||||
AccountId::from_entropy(&mut seed.as_slice()).unwrap()
|
AccountId::from_entropy(&mut seed.as_slice()).unwrap()
|
||||||
}
|
}
|
||||||
@ -19,8 +21,16 @@ impl Pay for BenchmarkTreasuryPaymaster {
|
|||||||
type AssetKind = ();
|
type AssetKind = ();
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn pay(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) -> Result<Self::Id, Self::Error> { Ok(()) }
|
fn pay(
|
||||||
fn check_payment(_: Self::Id) -> PaymentStatus { PaymentStatus::Success }
|
_: &Self::Beneficiary,
|
||||||
|
_: Self::AssetKind,
|
||||||
|
_: Self::Balance,
|
||||||
|
) -> Result<Self::Id, Self::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn check_payment(_: Self::Id) -> PaymentStatus {
|
||||||
|
PaymentStatus::Success
|
||||||
|
}
|
||||||
fn ensure_successful(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) {}
|
fn ensure_successful(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) {}
|
||||||
fn ensure_concluded(_: Self::Id) {}
|
fn ensure_concluded(_: Self::Id) {}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ macro_rules! impl_elections_weights {
|
|||||||
parameter_types! {
|
parameter_types! {
|
||||||
/// A limit for off-chain phragmen unsigned solution submission.
|
/// A limit for off-chain phragmen unsigned solution submission.
|
||||||
///
|
///
|
||||||
/// We want to keep it as high as possible, but can't risk having
|
/// We want to keep it as high as possible, but can't risk having
|
||||||
/// it reject, so we always substract the base block execution weight.
|
/// it reject, so we always substract the base block execution weight.
|
||||||
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get()
|
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get()
|
||||||
.get(DispatchClass::Normal)
|
.get(DispatchClass::Normal)
|
||||||
@ -23,8 +23,8 @@ macro_rules! impl_elections_weights {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number configured here could always be more than the maximum limits of
|
/// The number configured here could always be more than the maximum limits of
|
||||||
/// staking pallet to ensure election snapshot will not run out of memory. For
|
/// staking pallet to ensure election snapshot will not run out of memory. For
|
||||||
/// now, we set them to smaller values since the staking is bounded and the weight
|
/// now, we set them to smaller values since the staking is bounded and the weight
|
||||||
/// pipeline takes for this single pallet.
|
/// pipeline takes for this single pallet.
|
||||||
pub struct BenchmarkConfig;
|
pub struct BenchmarkConfig;
|
||||||
|
@ -51,13 +51,13 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
derive_impl,
|
derive_impl,
|
||||||
dispatch::DispatchClass,
|
dispatch::DispatchClass,
|
||||||
parameter_types,
|
parameter_types,
|
||||||
traits::{
|
traits::{
|
||||||
tokens::{PayFromAccount, UnityAssetBalanceConversion},
|
tokens::{PayFromAccount, UnityAssetBalanceConversion},
|
||||||
ConstU32, FindAuthor
|
ConstU32, FindAuthor,
|
||||||
},
|
},
|
||||||
weights::Weight,
|
weights::Weight,
|
||||||
PalletId,
|
PalletId,
|
||||||
};
|
};
|
||||||
use frame_system::limits;
|
use frame_system::limits;
|
||||||
@ -65,14 +65,14 @@ mod tests {
|
|||||||
use sp_core::{ConstU64, H256};
|
use sp_core::{ConstU64, H256};
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{BlakeTwo256, IdentityLookup},
|
traits::{BlakeTwo256, IdentityLookup},
|
||||||
Perbill, BuildStorage,
|
BuildStorage, Perbill,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Block = frame_system::mocking::MockingBlock<Test>;
|
type Block = frame_system::mocking::MockingBlock<Test>;
|
||||||
const TEST_ACCOUNT: AccountId = AccountId::new([1; 32]);
|
const TEST_ACCOUNT: AccountId = AccountId::new([1; 32]);
|
||||||
|
|
||||||
frame_support::construct_runtime!(
|
frame_support::construct_runtime!(
|
||||||
pub enum Test
|
pub enum Test
|
||||||
{
|
{
|
||||||
System: frame_system,
|
System: frame_system,
|
||||||
Authorship: pallet_authorship,
|
Authorship: pallet_authorship,
|
||||||
@ -172,7 +172,10 @@ mod tests {
|
|||||||
|
|
||||||
pub struct OneAuthor;
|
pub struct OneAuthor;
|
||||||
impl FindAuthor<AccountId> for OneAuthor {
|
impl FindAuthor<AccountId> for OneAuthor {
|
||||||
fn find_author<'a, I>(_: I) -> Option<AccountId> where I: 'a {
|
fn find_author<'a, I>(_: I) -> Option<AccountId>
|
||||||
|
where
|
||||||
|
I: 'a,
|
||||||
|
{
|
||||||
Some(TEST_ACCOUNT)
|
Some(TEST_ACCOUNT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +188,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
let mut t = frame_system::GenesisConfig::default()
|
||||||
|
.build_storage::<Test>()
|
||||||
|
.unwrap();
|
||||||
// We use default for brevity, but you can configure as desired if needed.
|
// We use default for brevity, but you can configure as desired if needed.
|
||||||
pallet_balances::GenesisConfig::<Test>::default()
|
pallet_balances::GenesisConfig::<Test>::default()
|
||||||
.assimilate_storage(&mut t)
|
.assimilate_storage(&mut t)
|
||||||
@ -196,8 +201,14 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_fees_and_tips_split() {
|
fn test_fees_and_tips_split() {
|
||||||
new_test_ext().execute_with(|| {
|
new_test_ext().execute_with(|| {
|
||||||
let fee = <paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<AccountId>>::issue(10);
|
let fee =
|
||||||
let tip = <paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<AccountId>>::issue(20);
|
<paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
|
||||||
|
AccountId,
|
||||||
|
>>::issue(10);
|
||||||
|
let tip =
|
||||||
|
<paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
|
||||||
|
AccountId,
|
||||||
|
>>::issue(20);
|
||||||
|
|
||||||
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
|
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
|
||||||
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0);
|
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0);
|
||||||
@ -242,11 +253,23 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn era_payout_should_give_sensible_results() {
|
fn era_payout_should_give_sensible_results() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ),
|
era_payout(
|
||||||
|
75,
|
||||||
|
100,
|
||||||
|
Perquintill::from_percent(10),
|
||||||
|
Perquintill::one(),
|
||||||
|
0,
|
||||||
|
),
|
||||||
(10, 0)
|
(10, 0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ),
|
era_payout(
|
||||||
|
80,
|
||||||
|
100,
|
||||||
|
Perquintill::from_percent(10),
|
||||||
|
Perquintill::one(),
|
||||||
|
0,
|
||||||
|
),
|
||||||
(6, 4)
|
(6, 4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
pub mod impls;
|
|
||||||
pub mod elections;
|
pub mod elections;
|
||||||
|
pub mod impls;
|
||||||
|
|
||||||
#[cfg(feature = "try-runtime")]
|
#[cfg(feature = "try-runtime")]
|
||||||
pub mod elections;
|
pub mod elections;
|
||||||
@ -10,7 +10,8 @@ pub mod elections;
|
|||||||
pub mod benchmarking;
|
pub mod benchmarking;
|
||||||
|
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
parameter_types, traits::ConstU32,
|
parameter_types,
|
||||||
|
traits::ConstU32,
|
||||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
|
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
|
||||||
};
|
};
|
||||||
use frame_system::limits;
|
use frame_system::limits;
|
||||||
@ -92,8 +93,8 @@ macro_rules! impl_runtime_weights {
|
|||||||
use frame_system::limits;
|
use frame_system::limits;
|
||||||
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
|
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
|
||||||
pub use runtime_common::{
|
pub use runtime_common::{
|
||||||
impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO,
|
impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT,
|
||||||
MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
|
NORMAL_DISPATCH_RATIO,
|
||||||
};
|
};
|
||||||
use sp_runtime::{FixedPointNumber, Perquintill};
|
use sp_runtime::{FixedPointNumber, Perquintill};
|
||||||
|
|
||||||
@ -101,8 +102,7 @@ macro_rules! impl_runtime_weights {
|
|||||||
|
|
||||||
// Expose the weight from the runtime constants module.
|
// Expose the weight from the runtime constants module.
|
||||||
pub use $runtime::weights::{
|
pub use $runtime::weights::{
|
||||||
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
|
BlockExecutionWeight, ExtrinsicBaseWeight, ParityDbWeight, RocksDbWeight,
|
||||||
ParityDbWeight,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
@ -129,7 +129,6 @@ macro_rules! impl_runtime_weights {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The type used for currency conversion.
|
/// The type used for currency conversion.
|
||||||
///
|
///
|
||||||
/// This must be only be used as long as the balance type is `u128`.
|
/// This must be only be used as long as the balance type is `u128`.
|
||||||
|
@ -4,7 +4,7 @@ use frame_support::{
|
|||||||
};
|
};
|
||||||
use pallet_fast_unstake::{Pallet as FastUnstake, *};
|
use pallet_fast_unstake::{Pallet as FastUnstake, *};
|
||||||
use pallet_staking::*;
|
use pallet_staking::*;
|
||||||
use sp_std::{collections::btree_set::BTreeSet, prelude:*};
|
use sp_std::{collections::btree_set::BTreeSet, prelude::*};
|
||||||
|
|
||||||
/// Register all inactive nominators for fast unstake, and progress until they
|
/// Register all inactive nominators for fast unstake, and progress until they
|
||||||
/// have all benn processed.
|
/// have all benn processed.
|
||||||
@ -16,7 +16,9 @@ where
|
|||||||
let mut unstaked_err = 0;
|
let mut unstaked_err = 0;
|
||||||
let mut unstaked_slashed = 0;
|
let mut unstaked_slashed = 0;
|
||||||
|
|
||||||
let all_stakers = Ledger::<T>::iter().map(|(ctrl, l)| (ctrl, l.stash)).collect::<BTreeSet<_>>();
|
let all_stakers = Ledger::<T>::iter()
|
||||||
|
.map(|(ctrl, l)| (ctrl, l.stash))
|
||||||
|
.collect::<BTreeSet<_>>();
|
||||||
let mut all_exposed = BTreeSet::new();
|
let mut all_exposed = BTreeSet::new();
|
||||||
ErasStakers::<T>::iter().for_each(|(_, val, expo)| {
|
ErasStakers::<T>::iter().for_each(|(_, val, expo)| {
|
||||||
all_exposed.insert(val);
|
all_exposed.insert(val);
|
||||||
@ -55,7 +57,7 @@ where
|
|||||||
let weight = <T as frame_system::Config>::BlockWeights::get().max_block;
|
let weight = <T as frame_system::Config>::BlockWeights::get().max_block;
|
||||||
let consumed = FastUnstake::<T>::on_idle(now, weight);
|
let consumed = FastUnstake::<T>::on_idle(now, weight);
|
||||||
log::debug!(
|
log::debug!(
|
||||||
target: "runtime::test",
|
target: "runtime::test",
|
||||||
"consumed {:?} ({})",
|
"consumed {:?} ({})",
|
||||||
consumed,
|
consumed,
|
||||||
consumed.ref_time() as f32 / weight.ref_time() as f32,
|
consumed.ref_time() as f32 / weight.ref_time() as f32,
|
||||||
@ -70,15 +72,16 @@ where
|
|||||||
maybe_fast_unstake_event
|
maybe_fast_unstake_event
|
||||||
})
|
})
|
||||||
.for_each(|e: pallet_fast_unstake::Event<T>| match e {
|
.for_each(|e: pallet_fast_unstake::Event<T>| match e {
|
||||||
pallet_fast_unstake::Event<T>::Unstaked { result, .. } =>
|
pallet_fast_unstake::Event::<T>::Unstaked { result, .. } => {
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
unstaked_ok += 1;
|
unstaked_ok += 1;
|
||||||
} else {
|
} else {
|
||||||
unstaked_err += 1;
|
unstaked_err += 1;
|
||||||
},
|
}
|
||||||
|
}
|
||||||
pallet_fast_unstake::Event::<T>::Slashed { .. } => unstaked_slashed += 1,
|
pallet_fast_unstake::Event::<T>::Slashed { .. } => unstaked_slashed += 1,
|
||||||
pallet_fast_unstake::Event::<T>::InternalError { .. } => unreachable!(),
|
pallet_fast_unstake::Event::<T>::InternalError { .. } => unreachable!(),
|
||||||
_ => {},
|
_ => {}
|
||||||
});
|
});
|
||||||
|
|
||||||
if now % 100u32.into() == sp_runtime::traits::Zero::zero() {
|
if now % 100u32.into() == sp_runtime::traits::Zero::zero() {
|
||||||
|
Loading…
Reference in New Issue
Block a user