difftreelog
Merge pull request #810 from UniqueNetwork/fix/app-promotion-benchmarks
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5550,7 +5550,7 @@
[[package]]
name = "pallet-app-promotion"
-version = "0.1.2"
+version = "0.1.3"
dependencies = [
"frame-benchmarking",
"frame-support",
pallets/app-promotion/CHANGELOG.mddiffbeforeafterboth--- a/pallets/app-promotion/CHANGELOG.md
+++ b/pallets/app-promotion/CHANGELOG.md
@@ -4,6 +4,12 @@
<!-- bureaucrate goes here -->
+## [0.1.3] - 2022-12-25
+
+### Fixed
+
+- Benchmarks for `payoutStakers` and `unstake` extrinsics.
+
## [0.1.2] - 2022-12-20
### Fixed
pallets/app-promotion/Cargo.tomldiffbeforeafterboth--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -9,13 +9,13 @@
license = 'GPLv3'
name = 'pallet-app-promotion'
repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.1.2'
+version = '0.1.3'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
[features]
-default = ['std']
+default = ['std',]
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -77,27 +77,36 @@
} : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin))
payout_stakers{
- let b in 1..101;
+ let b in 1..100;
let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
let share = Perbill::from_rational(1u32, 20);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
<T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::make_free_balance_be(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- let staker: T::AccountId = account("caller", 0, SEED);
- <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();
stakers.iter().for_each(|staker| {
<T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
});
- (0..10).try_for_each(|_| {
+ (1..11).try_for_each(|i| {
+ <frame_system::Pallet<T>>::set_block_number(i.into());
+ T::RelayBlockNumberProvider::set_block_number((2*i).into());
+ assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
+ assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
stakers.iter()
- .map(|staker| {
- PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
- }).collect::<Result<Vec<_>, _>>()?;
- <frame_system::Pallet<T>>::finalize();
+ .map(|staker| {
+ PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
+ }).collect::<Result<Vec<_>, _>>()?;
+
Result::<(), sp_runtime::DispatchError>::Ok(())
})?;
+
+ let stakes = Staked::<T>::iter_prefix((&stakers[0],)).into_iter().collect::<Vec<_>>();
+ assert_eq!(stakes.len(), 10);
+
+ <frame_system::Pallet<T>>::set_block_number(15_000.into());
+ T::RelayBlockNumberProvider::set_block_number(30_000.into());
} : _(RawOrigin::Signed(pallet_admin.clone()), Some(b as u8))
stake {
@@ -110,9 +119,12 @@
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 20);
let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- (0..10).map(|_| {
+ (1..11).map(|i| {
// used to change block number
- <frame_system::Pallet<T>>::finalize();
+ <frame_system::Pallet<T>>::set_block_number(i.into());
+ T::RelayBlockNumberProvider::set_block_number((2*i).into());
+ assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
+ assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))
}).collect::<Result<Vec<_>, _>>()?;
pallets/app-promotion/src/weights.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/weights.rs
+++ b/pallets/app-promotion/src/weights.rs
@@ -3,7 +3,7 @@
//! Autogenerated weights for pallet_app_promotion
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
-//! DATE: 2022-09-07, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2022-12-25, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
// Executed Command:
@@ -51,77 +51,84 @@
// Storage: AppPromotion PendingUnstake (r:1 w:0)
// Storage: System Account (r:1 w:1)
fn on_initialize(b: u32, ) -> Weight {
- Weight::from_ref_time(2_651_000)
- // Standard Error: 103_000
- .saturating_add(Weight::from_ref_time(6_024_000).saturating_mul(b as u64))
+ Weight::from_ref_time(3_079_948 as u64)
+ // Standard Error: 30_376
+ .saturating_add(Weight::from_ref_time(6_343_630 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(b as u64)))
}
// Storage: AppPromotion Admin (r:0 w:1)
fn set_admin_address() -> Weight {
- Weight::from_ref_time(7_117_000)
+ Weight::from_ref_time(6_653_000 as u64)
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: ParachainSystem ValidationData (r:1 w:0)
- // Storage: AppPromotion NextCalculatedRecord (r:1 w:1)
- // Storage: AppPromotion Staked (r:2 w:0)
+ // Storage: AppPromotion PreviousCalculatedRecord (r:1 w:1)
+ // Storage: AppPromotion Staked (r:11 w:10)
+ // Storage: System Account (r:2 w:2)
+ // Storage: Balances Locks (r:1 w:1)
+ // Storage: AppPromotion TotalStaked (r:1 w:1)
fn payout_stakers(b: u32, ) -> Weight {
- Weight::from_ref_time(9_958_000)
- // Standard Error: 8_000
- .saturating_add(Weight::from_ref_time(4_406_000).saturating_mul(b as u64))
- .saturating_add(T::DbWeight::get().reads(4 as u64))
- .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))
- .saturating_add(T::DbWeight::get().writes(1 as u64))
+ Weight::from_ref_time(74_048_000 as u64)
+ // Standard Error: 33_223
+ .saturating_add(Weight::from_ref_time(57_702_092 as u64).saturating_mul(b as u64))
+ .saturating_add(T::DbWeight::get().reads(7 as u64))
+ .saturating_add(T::DbWeight::get().reads((12 as u64).saturating_mul(b as u64)))
+ .saturating_add(T::DbWeight::get().writes(3 as u64))
+ .saturating_add(T::DbWeight::get().writes((12 as u64).saturating_mul(b as u64)))
}
// Storage: AppPromotion StakesPerAccount (r:1 w:1)
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: ParachainSystem ValidationData (r:1 w:0)
// Storage: AppPromotion Staked (r:1 w:1)
// Storage: AppPromotion TotalStaked (r:1 w:1)
fn stake() -> Weight {
- Weight::from_ref_time(20_574_000)
- .saturating_add(T::DbWeight::get().reads(6 as u64))
+ Weight::from_ref_time(20_314_000 as u64)
+ .saturating_add(T::DbWeight::get().reads(7 as u64))
.saturating_add(T::DbWeight::get().writes(5 as u64))
}
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: AppPromotion PendingUnstake (r:1 w:1)
- // Storage: AppPromotion Staked (r:2 w:1)
+ // Storage: AppPromotion Staked (r:11 w:10)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AppPromotion TotalStaked (r:1 w:1)
// Storage: AppPromotion StakesPerAccount (r:0 w:1)
fn unstake() -> Weight {
- Weight::from_ref_time(31_703_000)
- .saturating_add(T::DbWeight::get().reads(6 as u64))
- .saturating_add(T::DbWeight::get().writes(6 as u64))
+ Weight::from_ref_time(64_582_000 as u64)
+ .saturating_add(T::DbWeight::get().reads(16 as u64))
+ .saturating_add(T::DbWeight::get().writes(15 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: Common CollectionById (r:1 w:1)
fn sponsor_collection() -> Weight {
- Weight::from_ref_time(12_932_000)
+ Weight::from_ref_time(16_364_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: Common CollectionById (r:1 w:1)
fn stop_sponsoring_collection() -> Weight {
- Weight::from_ref_time(12_453_000)
+ Weight::from_ref_time(15_710_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: EvmContractHelpers Sponsoring (r:0 w:1)
fn sponsor_contract() -> Weight {
- Weight::from_ref_time(11_952_000)
+ Weight::from_ref_time(12_669_000 as u64)
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: EvmContractHelpers Sponsoring (r:1 w:1)
fn stop_sponsoring_contract() -> Weight {
- Weight::from_ref_time(12_538_000)
+ Weight::from_ref_time(14_406_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
@@ -132,77 +139,84 @@
// Storage: AppPromotion PendingUnstake (r:1 w:0)
// Storage: System Account (r:1 w:1)
fn on_initialize(b: u32, ) -> Weight {
- Weight::from_ref_time(2_651_000)
- // Standard Error: 103_000
- .saturating_add(Weight::from_ref_time(6_024_000).saturating_mul(b as u64))
+ Weight::from_ref_time(3_079_948 as u64)
+ // Standard Error: 30_376
+ .saturating_add(Weight::from_ref_time(6_343_630 as u64).saturating_mul(b as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(b as u64)))
}
// Storage: AppPromotion Admin (r:0 w:1)
fn set_admin_address() -> Weight {
- Weight::from_ref_time(7_117_000)
+ Weight::from_ref_time(6_653_000 as u64)
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: ParachainSystem ValidationData (r:1 w:0)
- // Storage: AppPromotion NextCalculatedRecord (r:1 w:1)
- // Storage: AppPromotion Staked (r:2 w:0)
+ // Storage: AppPromotion PreviousCalculatedRecord (r:1 w:1)
+ // Storage: AppPromotion Staked (r:11 w:10)
+ // Storage: System Account (r:2 w:2)
+ // Storage: Balances Locks (r:1 w:1)
+ // Storage: AppPromotion TotalStaked (r:1 w:1)
fn payout_stakers(b: u32, ) -> Weight {
- Weight::from_ref_time(9_958_000)
- // Standard Error: 8_000
- .saturating_add(Weight::from_ref_time(4_406_000).saturating_mul(b as u64))
- .saturating_add(RocksDbWeight::get().reads(4 as u64))
- .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))
- .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ Weight::from_ref_time(74_048_000 as u64)
+ // Standard Error: 33_223
+ .saturating_add(Weight::from_ref_time(57_702_092 as u64).saturating_mul(b as u64))
+ .saturating_add(RocksDbWeight::get().reads(7 as u64))
+ .saturating_add(RocksDbWeight::get().reads((12 as u64).saturating_mul(b as u64)))
+ .saturating_add(RocksDbWeight::get().writes(3 as u64))
+ .saturating_add(RocksDbWeight::get().writes((12 as u64).saturating_mul(b as u64)))
}
// Storage: AppPromotion StakesPerAccount (r:1 w:1)
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
// Storage: ParachainSystem ValidationData (r:1 w:0)
// Storage: AppPromotion Staked (r:1 w:1)
// Storage: AppPromotion TotalStaked (r:1 w:1)
fn stake() -> Weight {
- Weight::from_ref_time(20_574_000)
- .saturating_add(RocksDbWeight::get().reads(6 as u64))
+ Weight::from_ref_time(20_314_000 as u64)
+ .saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(5 as u64))
}
+ // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)
// Storage: AppPromotion PendingUnstake (r:1 w:1)
- // Storage: AppPromotion Staked (r:2 w:1)
+ // Storage: AppPromotion Staked (r:11 w:10)
// Storage: Balances Locks (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: AppPromotion TotalStaked (r:1 w:1)
// Storage: AppPromotion StakesPerAccount (r:0 w:1)
fn unstake() -> Weight {
- Weight::from_ref_time(31_703_000)
- .saturating_add(RocksDbWeight::get().reads(6 as u64))
- .saturating_add(RocksDbWeight::get().writes(6 as u64))
+ Weight::from_ref_time(64_582_000 as u64)
+ .saturating_add(RocksDbWeight::get().reads(16 as u64))
+ .saturating_add(RocksDbWeight::get().writes(15 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: Common CollectionById (r:1 w:1)
fn sponsor_collection() -> Weight {
- Weight::from_ref_time(12_932_000)
+ Weight::from_ref_time(16_364_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: Common CollectionById (r:1 w:1)
fn stop_sponsoring_collection() -> Weight {
- Weight::from_ref_time(12_453_000)
+ Weight::from_ref_time(15_710_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: EvmContractHelpers Sponsoring (r:0 w:1)
fn sponsor_contract() -> Weight {
- Weight::from_ref_time(11_952_000)
+ Weight::from_ref_time(12_669_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: AppPromotion Admin (r:1 w:0)
// Storage: EvmContractHelpers Sponsoring (r:1 w:1)
fn stop_sponsoring_contract() -> Weight {
- Weight::from_ref_time(12_538_000)
+ Weight::from_ref_time(14_406_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
runtime/common/mod.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod instance;22pub mod maintenance;23pub mod runtime_apis;24pub mod xcm;2526#[cfg(feature = "scheduler")]27pub mod scheduler;2829pub mod sponsoring;30pub mod weights;3132#[cfg(test)]33pub mod tests;3435use sp_core::H160;36use frame_support::traits::{Currency, OnUnbalanced, Imbalance};37use sp_runtime::{38 generic,39 traits::{BlakeTwo256, BlockNumberProvider},40 impl_opaque_keys,41};42use sp_std::vec::Vec;4344#[cfg(feature = "std")]45use sp_version::NativeVersion;4647use crate::{48 Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,49 InherentDataExt,50};51use up_common::types::{AccountId, BlockNumber};5253#[macro_export]54macro_rules! unsupported {55 () => {56 pallet_common::unsupported!($crate::Runtime)57 };58}5960/// The address format for describing accounts.61pub type Address = sp_runtime::MultiAddress<AccountId, ()>;62/// Block header type as expected by this runtime.63pub type Header = generic::Header<BlockNumber, BlakeTwo256>;64/// Block type as expected by this runtime.65pub type Block = generic::Block<Header, UncheckedExtrinsic>;66/// A Block signed with a Justification67pub type SignedBlock = generic::SignedBlock<Block>;68/// BlockId type as expected by this runtime.69pub type BlockId = generic::BlockId<Block>;7071impl_opaque_keys! {72 pub struct SessionKeys {73 pub aura: Aura,74 }75}7677/// The version information used to identify this runtime when compiled natively.78#[cfg(feature = "std")]79pub fn native_version() -> NativeVersion {80 NativeVersion {81 runtime_version: crate::VERSION,82 can_author_with: Default::default(),83 }84}8586pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8788pub type SignedExtra = (89 frame_system::CheckSpecVersion<Runtime>,90 frame_system::CheckTxVersion<Runtime>,91 frame_system::CheckGenesis<Runtime>,92 frame_system::CheckEra<Runtime>,93 frame_system::CheckNonce<Runtime>,94 frame_system::CheckWeight<Runtime>,95 maintenance::CheckMaintenance,96 ChargeTransactionPayment,97 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,98 pallet_ethereum::FakeTransactionFinalizer<Runtime>,99);100101/// Unchecked extrinsic type as expected by this runtime.102pub type UncheckedExtrinsic =103 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;104105/// Extrinsic type that has already been checked.106pub type CheckedExtrinsic =107 fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;108109/// Executive: handles dispatch to the various modules.110pub type Executive = frame_executive::Executive<111 Runtime,112 Block,113 frame_system::ChainContext<Runtime>,114 Runtime,115 AllPalletsWithSystem,116>;117118type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;119120pub struct DealWithFees;121impl OnUnbalanced<NegativeImbalance> for DealWithFees {122 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {123 if let Some(fees) = fees_then_tips.next() {124 // for fees, 100% to treasury125 let mut split = fees.ration(100, 0);126 if let Some(tips) = fees_then_tips.next() {127 // for tips, if any, 100% to treasury128 tips.ration_merge_into(100, 0, &mut split);129 }130 Treasury::on_unbalanced(split.0);131 // Author::on_unbalanced(split.1);132 }133 }134}135136pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);137138impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider139 for RelayChainBlockNumberProvider<T>140{141 type BlockNumber = BlockNumber;142143 fn current_block_number() -> Self::BlockNumber {144 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()145 .map(|d| d.relay_parent_number)146 .unwrap_or_default()147 }148}149150pub(crate) struct CheckInherents;151152impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {153 fn check_inherents(154 block: &Block,155 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,156 ) -> sp_inherents::CheckInherentsResult {157 let relay_chain_slot = relay_state_proof158 .read_slot()159 .expect("Could not read the relay chain slot from the proof");160161 let inherent_data =162 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(163 relay_chain_slot,164 sp_std::time::Duration::from_secs(6),165 )166 .create_inherent_data()167 .expect("Could not create the timestamp inherent data");168169 inherent_data.check_extrinsics(block)170 }171}172173#[derive(codec::Encode, codec::Decode)]174pub enum XCMPMessage<XAccountId, XBalance> {175 /// Transfer tokens to the given account from the Parachain account.176 TransferToken(XAccountId, XBalance),177}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod instance;22pub mod maintenance;23pub mod runtime_apis;24pub mod xcm;2526#[cfg(feature = "scheduler")]27pub mod scheduler;2829pub mod sponsoring;30pub mod weights;3132#[cfg(test)]33pub mod tests;3435use sp_core::H160;36use frame_support::traits::{Currency, OnUnbalanced, Imbalance};37use sp_runtime::{38 generic,39 traits::{BlakeTwo256, BlockNumberProvider},40 impl_opaque_keys,41};42use sp_std::vec::Vec;4344#[cfg(feature = "std")]45use sp_version::NativeVersion;4647use crate::{48 Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,49 InherentDataExt,50};51use up_common::types::{AccountId, BlockNumber};5253#[macro_export]54macro_rules! unsupported {55 () => {56 pallet_common::unsupported!($crate::Runtime)57 };58}5960/// The address format for describing accounts.61pub type Address = sp_runtime::MultiAddress<AccountId, ()>;62/// Block header type as expected by this runtime.63pub type Header = generic::Header<BlockNumber, BlakeTwo256>;64/// Block type as expected by this runtime.65pub type Block = generic::Block<Header, UncheckedExtrinsic>;66/// A Block signed with a Justification67pub type SignedBlock = generic::SignedBlock<Block>;68/// BlockId type as expected by this runtime.69pub type BlockId = generic::BlockId<Block>;7071impl_opaque_keys! {72 pub struct SessionKeys {73 pub aura: Aura,74 }75}7677/// The version information used to identify this runtime when compiled natively.78#[cfg(feature = "std")]79pub fn native_version() -> NativeVersion {80 NativeVersion {81 runtime_version: crate::VERSION,82 can_author_with: Default::default(),83 }84}8586pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8788pub type SignedExtra = (89 frame_system::CheckSpecVersion<Runtime>,90 frame_system::CheckTxVersion<Runtime>,91 frame_system::CheckGenesis<Runtime>,92 frame_system::CheckEra<Runtime>,93 frame_system::CheckNonce<Runtime>,94 frame_system::CheckWeight<Runtime>,95 maintenance::CheckMaintenance,96 ChargeTransactionPayment,97 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,98 pallet_ethereum::FakeTransactionFinalizer<Runtime>,99);100101/// Unchecked extrinsic type as expected by this runtime.102pub type UncheckedExtrinsic =103 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;104105/// Extrinsic type that has already been checked.106pub type CheckedExtrinsic =107 fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;108109/// Executive: handles dispatch to the various modules.110pub type Executive = frame_executive::Executive<111 Runtime,112 Block,113 frame_system::ChainContext<Runtime>,114 Runtime,115 AllPalletsWithSystem,116>;117118type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;119120pub struct DealWithFees;121impl OnUnbalanced<NegativeImbalance> for DealWithFees {122 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {123 if let Some(fees) = fees_then_tips.next() {124 // for fees, 100% to treasury125 let mut split = fees.ration(100, 0);126 if let Some(tips) = fees_then_tips.next() {127 // for tips, if any, 100% to treasury128 tips.ration_merge_into(100, 0, &mut split);129 }130 Treasury::on_unbalanced(split.0);131 // Author::on_unbalanced(split.1);132 }133 }134}135136pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);137138impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider139 for RelayChainBlockNumberProvider<T>140{141 type BlockNumber = BlockNumber;142143 fn current_block_number() -> Self::BlockNumber {144 cumulus_pallet_parachain_system::Pallet::<T>::validation_data()145 .map(|d| d.relay_parent_number)146 .unwrap_or_default()147 }148 #[cfg(feature = "runtime-benchmarks")]149 fn set_block_number(block: Self::BlockNumber) {150 cumulus_pallet_parachain_system::RelaychainBlockNumberProvider::<T>::set_block_number(block)151 }152}153154pub(crate) struct CheckInherents;155156impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {157 fn check_inherents(158 block: &Block,159 relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,160 ) -> sp_inherents::CheckInherentsResult {161 let relay_chain_slot = relay_state_proof162 .read_slot()163 .expect("Could not read the relay chain slot from the proof");164165 let inherent_data =166 cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(167 relay_chain_slot,168 sp_std::time::Duration::from_secs(6),169 )170 .create_inherent_data()171 .expect("Could not create the timestamp inherent data");172173 inherent_data.check_extrinsics(block)174 }175}176177#[derive(codec::Encode, codec::Decode)]178pub enum XCMPMessage<XAccountId, XBalance> {179 /// Transfer tokens to the given account from the Parachain account.180 TransferToken(XAccountId, XBalance),181}runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -44,6 +44,7 @@
'sp-runtime/runtime-benchmarks',
'xcm-builder/runtime-benchmarks',
'pallet-maintenance/runtime-benchmarks',
+ 'cumulus-pallet-parachain-system/runtime-benchmarks'
]
try-runtime = [
'frame-try-runtime',
runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -43,6 +43,7 @@
'sp-runtime/runtime-benchmarks',
'xcm-builder/runtime-benchmarks',
'pallet-maintenance/runtime-benchmarks',
+ 'cumulus-pallet-parachain-system/runtime-benchmarks',
]
try-runtime = [
'frame-try-runtime',