Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6a7e1c3
feat(benchmarks): add feature runtime-benchmarks to all pallets
clearloop May 31, 2021
02867e3
feat(benchmark): add benchmark command to cli
clearloop May 31, 2021
1466317
feat(spec): load spec without path
clearloop May 31, 2021
0e3afe8
feat(cli): enable benchmark command only with feature runtime-benchmarks
clearloop Jun 1, 2021
d20a0a3
chore(benchmakrs): configure runtime-benchmarks features to command b…
clearloop Jun 1, 2021
adfda2a
chore(benchmarks): leave comments to withdraw in asset-index
clearloop Jun 1, 2021
d94785b
feat(committee): benchmark for extrinsic vote
clearloop Jun 2, 2021
14fa3b6
feat(benchmark): benchmark for pallet local-treasury
clearloop Jun 3, 2021
313d9d9
feat(benchmark): add benchmarks to pallet price-feed
clearloop Jun 3, 2021
212578b
feat(benchmark): add benchmark to remote-asset-manager
clearloop Jun 3, 2021
fa00361
feat(benchmark): abstract benchmarks to saft-registry
clearloop Jun 3, 2021
ba1d0db
feat(benchmark): complete benchmarks of committee
clearloop Jun 3, 2021
02b67c3
feat(weights): add weights of asset-index to runtime
clearloop Jun 3, 2021
3a71256
feat(benchmark): add weights of remote-asset-registry to runtime
clearloop Jun 3, 2021
5965730
feat(benchmark): add weights of local-treasury to runtime
clearloop Jun 3, 2021
fa70208
feat(benchmarks): add default weight for tests
clearloop Jun 3, 2021
df93419
chore(weights): add license to weight files
clearloop Jun 3, 2021
f1a4de9
feat(benchmark): add default weight to pallet committee
clearloop Jun 3, 2021
aa76617
feat(benchmark): add default weights to pallet price feed
clearloop Jun 3, 2021
1163ed7
feat(benchmark): add default weight to pallet saft registry
clearloop Jun 3, 2021
f744ee6
chore(weights): add license too the weight config of pallet_saft_regi…
clearloop Jun 3, 2021
d374726
feat(benchmark): add default weight to pallet committee
clearloop Jun 4, 2021
4dfe944
feat(price-feed): configure Chainsafe/chainlink-polkadot to price-feed
clearloop Jun 4, 2021
31323ef
feat(weights): add weights to all calls
clearloop Jun 4, 2021
e70791c
feat(benchmark): add verification to pallet saft-registry
clearloop Jun 5, 2021
0fb7d14
feat(benchmark): add verification to pallet price-feed
clearloop Jun 5, 2021
1c3c6cc
feat(benchmark): add verification to pallet local-treasury
clearloop Jun 5, 2021
bc1dc98
feat(benchmark): add verification to pallet committee
clearloop Jun 5, 2021
a25b48f
feat(benchmarks): clean useless code
clearloop Jun 7, 2021
93c474f
Revert "feat(benchmarks): clean useless code"
clearloop Jun 7, 2021
9ae7704
perf(benchmark): remote TODOs for setting weights
clearloop Jun 8, 2021
b22b654
perf(benchmark): remove comments on the benchmarking of pallet-index
clearloop Jun 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,218 changes: 875 additions & 1,343 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ version = '3.0.0'
git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'
optional = true

[dependencies.parachain-runtime]
path = '../runtime'
Expand Down Expand Up @@ -217,6 +218,7 @@ targets = ['x86_64-unknown-linux-gnu']
[features]
default = []
runtime-benchmarks = [
'frame-benchmarking-cli',
'parachain-runtime/runtime-benchmarks',
'polkadot-service/runtime-benchmarks'
]
5 changes: 5 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub enum Subcommand {

/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),

#[cfg(feature = "runtime-benchmarks")]
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}

/// Command for exporting the genesis state of the parachain
Expand Down
21 changes: 17 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ fn load_spec(
para_id: ParaId,
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"pint-dev" => Box::new(chain_spec::pint_development_config(para_id)),
"pint-local" => Box::new(chain_spec::pint_local_config(para_id)),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
"pint-dev" => Box::new(chain_spec::pint_development_config(para_id)),
path => Box::new(
chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))
.unwrap_or(chain_spec::pint_development_config(para_id)),
),
})
}

Expand Down Expand Up @@ -258,6 +259,18 @@ pub fn run() -> Result<()> {

Ok(())
}
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(params)) => {
if cfg!(feature = "runtime-benchmarks") {
let runner = cli.create_runner(params)?;

runner.sync_run(|config| params.run::<Block, crate::service::Executor>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
}
}
None => {
let runner = cli.create_runner(&*cli.run)?;

Expand Down
1 change: 1 addition & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ native_executor_instance!(
pub Executor,
parachain_runtime::api::dispatch,
parachain_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);

/// Starts a `ServiceBuilder` for a full service.
Expand Down
13 changes: 13 additions & 0 deletions pallets/asset-depository/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ std = [
'frame-support/std',
'frame-system/std',
]
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'frame-system/runtime-benchmarks',
]

[dependencies.codec]
default-features = false
features = ['derive']
Expand All @@ -33,6 +39,13 @@ git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'

[dependencies.frame-benchmarking]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'
optional = true

[dev-dependencies]
serde = { version = "1.0.101" }

Expand Down
7 changes: 7 additions & 0 deletions pallets/asset-depository/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2021 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
//! Benchmarks
//!
//! TODO:
//!
//! This pallet contains no calls currently.
21 changes: 21 additions & 0 deletions pallets/asset-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ std = [
'xcm/std',
'xcm-executor/std',
]
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'pallet-remote-asset-manager/runtime-benchmarks',
'pallet-asset-depository/runtime-benchmarks',
'pallet-price-feed/runtime-benchmarks',
'pallet-chainlink-feed/runtime-benchmarks',
]

[dependencies.codec]
default-features = false
features = ['derive']
Expand All @@ -45,6 +54,18 @@ git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'

[dependencies.frame-benchmarking]
default-features = false
git = 'https://github.com/paritytech/substrate'
branch = 'rococo-v1'
optional = true

[dependencies.pallet-chainlink-feed]
default_features = false
package = 'pallet-chainlink-feed'
git = "https://github.com/ChainSafe/chainlink-polkadot"
optional = true

[dependencies.xcm]
git = "https://github.com/paritytech/polkadot"
branch = 'rococo-v1'
Expand Down
31 changes: 31 additions & 0 deletions pallets/asset-index/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2021 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
use super::*;
use crate::types::{AssetAvailability, IndexAssetData};
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_support::traits::Currency;
use frame_system::RawOrigin;
use xcm::v0::MultiLocation;

benchmarks! {
add_asset {
let asset_id = 42.into();
let caller: T::AccountId = whitelisted_caller();
let million = 1_000_000u32.into();
T::IndexToken::deposit_creating(&caller, million);
}: _(
RawOrigin::Signed(caller.clone()),
asset_id,
million,
AssetAvailability::Liquid(MultiLocation::Null),
million
) verify {
assert_eq!(
<Holdings<T>>::get(asset_id),
Some(IndexAssetData::new(
million,
AssetAvailability::Liquid(MultiLocation::Null)
))
);
}
}
21 changes: 19 additions & 2 deletions pallets/asset-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod traits;
mod types;

Expand Down Expand Up @@ -87,7 +89,7 @@ pub mod pallet {
Self::Balance,
>;
/// Type used to identify assets
type AssetId: Parameter + Member;
type AssetId: Parameter + Member + From<u32> + Copy;
/// Handles asset depositing and withdrawing from sovereign user accounts
type MultiAssetDepository: MultiAssetDepository<
Self::AssetId,
Expand All @@ -102,6 +104,9 @@ pub mod pallet {
#[pallet::constant]
type TreasuryPalletId: Get<PalletId>;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

/// The weight for this pallet's extrinsics.
type WeightInfo: WeightInfo;
}

#[pallet::pallet]
Expand Down Expand Up @@ -159,7 +164,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(10_000)] // TODO: Set weights
#[pallet::weight(T::WeightInfo::add_asset())]
/// Callable by an admin to add new assets to the index and mint some IndexToken
/// Caller balance is updated to allocate the correct amount of the IndexToken
/// Creates IndexAssetData if it doesn’t exist, otherwise adds to list of deposits
Expand Down Expand Up @@ -472,4 +477,16 @@ pub mod pallet {
.unwrap_or_default()
}
}

/// Trait for the asset-index pallet extrinsic weights.
pub trait WeightInfo {
fn add_asset() -> Weight;
}

/// For backwards compatibility and tests
impl WeightInfo for () {
fn add_asset() -> Weight {
Default::default()
}
}
}
1 change: 1 addition & 0 deletions pallets/asset-index/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl pallet_asset_index::Config for Test {
type PriceFeed = MockPriceFeed;
type TreasuryPalletId = TreasuryPalletId;
type WithdrawalFee = ();
type WeightInfo = ();
}

pub struct MockRemoteAssetManager;
Expand Down
15 changes: 13 additions & 2 deletions pallets/committee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ std = [
'frame-system/std',
'sp-runtime/std',
]
# this feature is only for compilation now
runtime-benchmarks = []
runtime-benchmarks = [
'frame-benchmarking',
'frame-support/runtime-benchmarks',
'frame-system/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]

[dependencies.codec]
default-features = false
Expand All @@ -38,6 +42,13 @@ git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'

[dependencies.frame-benchmarking]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
branch = 'rococo-v1'
version = '3.0.0'
optional = true

[dependencies.sp-runtime]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
Expand Down
98 changes: 98 additions & 0 deletions pallets/committee/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2021 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
use super::*;
use frame_benchmarking::{account, benchmarks, vec, whitelisted_caller, Box};
use frame_support::{assert_noop, assert_ok, traits::Get};
use frame_system::{Call as SystemCall, Pallet as System, RawOrigin as SystemOrigin};

fn submit_proposal<T: Config>(caller: T::AccountId) -> pallet::Proposal<T> {
let action: T::Action = <SystemCall<T>>::remark(vec![0; 0]).into();
let expected_nonce = pallet::ProposalCount::<T>::get();
assert_ok!(<Pallet<T>>::propose(
SystemOrigin::Signed(caller).into(),
Box::new(action.clone())
));
pallet::Proposal::<T>::new(expected_nonce, action)
}

benchmarks! {
propose {
let caller: T::AccountId = whitelisted_caller();
let proposal = submit_proposal::<T>(caller.clone());
}: _(
SystemOrigin::Signed(caller.clone()),
Box::new(<SystemCall<T>>::remark(vec![0; 0]).into())
) verify {
assert!(<Pallet<T>>::get_proposal(&proposal.hash()) == Some(proposal));
}

vote {
let caller: T::AccountId = whitelisted_caller();
let proposal = submit_proposal::<T>(caller.clone());
assert_ok!(<Pallet<T>>::add_constituent(SystemOrigin::Root.into(), caller.clone()));

// run to voting period
<System<T>>::set_block_number(
<System<T>>::block_number()
+ <T as Config>::VotingPeriod::get()
+ <T as Config>::ProposalSubmissionPeriod::get() + 1_u32.into(),
);
}: _(
SystemOrigin::Signed(caller.clone()),
proposal.hash(),
Vote::Abstain
) verify {
assert_eq!(
<Pallet<T>>::get_votes_for(&proposal.hash()).unwrap().votes.len(),
1,
);
}

close {
let caller: T::AccountId = whitelisted_caller();
let proposal: pallet::Proposal<T> = submit_proposal::<T>(caller.clone());
assert_ok!(<Pallet<T>>::add_constituent(SystemOrigin::Root.into(), caller.clone()));
let voters = ["a", "b", "c", "d", "e"];

// run to voting period
<System<T>>::set_block_number(<System<T>>::block_number() + <T as Config>::VotingPeriod::get() + <T as Config>::ProposalSubmissionPeriod::get() + 1_u32.into());

// generate members
for i in &voters {
let voter: T::AccountId = account(i, 0, 0);
<Members<T>>::insert(voter.clone(), MemberType::Council);

// vote aye
assert_ok!(<Pallet<T>>::vote(
SystemOrigin::Signed(voter).into(),
proposal.hash(),
Vote::Aye,
));
}

// run out of voting period
<System<T>>::set_block_number(
<System<T>>::block_number()
+ <T as Config>::VotingPeriod::get() * 2_u32.into()
+ <T as Config>::ProposalSubmissionPeriod::get()
+ 1_u32.into()
);
}: _(
SystemOrigin::Signed(caller.clone()),
proposal.hash()
) verify {
assert_noop!(
<Pallet<T>>::close(SystemOrigin::Signed(caller.clone()).into(), proposal.hash()),
<Error<T>>::ProposalAlreadyExecuted
);
}

add_constituent {
let constituent: T::AccountId = account("constituent", 0, 0);
}: _(
SystemOrigin::Root,
constituent.clone()
) verify {
assert!(<pallet::Members<T>>::contains_key(constituent));
}
}
Loading