Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper XCM weights benchmark #781

Merged
merged 24 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2c3ff59
Compiles, but doens't work
ghzlatarev Jul 22, 2022
89bec65
Compiles and works
ghzlatarev Aug 31, 2022
ec3a948
Clean up
ghzlatarev Aug 31, 2022
8556789
Use new weights
ghzlatarev Aug 31, 2022
1005dc7
Fix merge conflicts with manta, tests compile but don't pass
ghzlatarev Aug 31, 2022
0e9b879
Remove new relaychain asset config, tests pass
ghzlatarev Aug 31, 2022
fad69ff
Update benchmarking script
ghzlatarev Aug 31, 2022
d6ce433
Clean up
ghzlatarev Aug 31, 2022
cab8198
Stop integration test jobs with the same condition as with starting them
ghzlatarev Aug 31, 2022
5db22b3
Fix fmt
ghzlatarev Aug 31, 2022
078febc
Fix toml lint
ghzlatarev Aug 31, 2022
40b5d7f
Implement for Dolphin
ghzlatarev Aug 31, 2022
dc50af2
Update header and reference-machine link in all-benchmarks script
ghzlatarev Aug 31, 2022
8cb7271
Fix clippy
ghzlatarev Aug 31, 2022
253f989
Upload correct benchmarking output folders
ghzlatarev Aug 31, 2022
6cde174
Dedupe artifacts names
ghzlatarev Aug 31, 2022
1ced65a
Fix xcm benchmark output files name
ghzlatarev Aug 31, 2022
2fdf3b5
Update all-benchmarks script to replace :: with _ in pallet names
ghzlatarev Aug 31, 2022
f42bc28
Add real weights benchmarked by the benchmarking machine
ghzlatarev Sep 1, 2022
e823afc
Add real weights benchmarked by the benchmarking machine
ghzlatarev Sep 1, 2022
8254245
Merge branch 'manta' into ghzlatarev/xcm-weights-benchmark
ghzlatarev Sep 1, 2022
fbdf120
Revert stopper job code change
ghzlatarev Sep 2, 2022
7fa60d5
Fix clippy unnecessary borrows
ghzlatarev Sep 2, 2022
29b14f5
Comment
ghzlatarev Sep 2, 2022
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
67 changes: 67 additions & 0 deletions .github/resources/xcm-weight-template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2020-2022 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

//! Autogenerated weights for `{{pallet}}`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}

// Executed Command:
{{#each args as |arg|}}
// {{arg}}
{{/each}}

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weights for `{{pallet}}`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo<T> {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
// {{comment}}
{{/each}}
pub(crate) fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as Weight)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
{{/each}}
}
{{/each}}
}
12 changes: 9 additions & 3 deletions .github/workflows/run_all_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ jobs:
name: manta
path: ./target/production/manta
- if: always()
name: upload pallets' weights
name: upload frame weights
uses: actions/upload-artifact@v3
with:
name: weights-output
path: ./scripts/benchmarking/weights-output/
name: frame-weights-output
path: ./scripts/benchmarking/frame-weights-output/
- if: always()
name: upload xcm weights
uses: actions/upload-artifact@v3
with:
name: xcm-weights-output
path: ./scripts/benchmarking/xcm-weights-output/
- if: always()
name: upload benchmarking errors
uses: actions/upload-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ runtime/**/target
/scripts/benchmarking/benchmarking_errors.txt
/scripts/benchmarking/machine_benchmark_result.txt
/scripts/benchmarking/rocksdb_weights.rs
/scripts/benchmarking/weights-output/
/scripts/benchmarking/frame-weights-output/
/scripts/benchmarking/xcm-weights-output/
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ pub fn run_with(cli: Cli) -> Result {
runner.run_node_until_exit(|config| async move {
let hwbench = if !cli.no_hardware_benchmarks {
config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
let _ = std::fs::create_dir_all(database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})
} else {
Expand Down
32 changes: 16 additions & 16 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ pub mod pallet {
let asset_id = <T::AssetConfig as AssetConfig<T>>::NativeAssetId::get();
let metadata = <T::AssetConfig as AssetConfig<T>>::NativeAssetMetadata::get();
let location = <T::AssetConfig as AssetConfig<T>>::NativeAssetLocation::get();
AssetIdLocation::<T>::insert(&asset_id, &location);
AssetIdMetadata::<T>::insert(&asset_id, &metadata);
LocationAssetId::<T>::insert(&location, &asset_id);
AssetIdLocation::<T>::insert(asset_id, &location);
AssetIdMetadata::<T>::insert(asset_id, &metadata);
LocationAssetId::<T>::insert(&location, asset_id);
}
}

Expand Down Expand Up @@ -278,9 +278,9 @@ pub mod pallet {
metadata.is_sufficient(),
)
.map_err(|_| Error::<T>::ErrorCreatingAsset)?;
AssetIdLocation::<T>::insert(&asset_id, &location);
AssetIdMetadata::<T>::insert(&asset_id, &metadata);
LocationAssetId::<T>::insert(&location, &asset_id);
AssetIdLocation::<T>::insert(asset_id, &location);
AssetIdMetadata::<T>::insert(asset_id, &metadata);
LocationAssetId::<T>::insert(&location, asset_id);

// If it's a new para id, which will be inserted with AssetCount as 1.
// If not, AssetCount will increased by 1.
Expand Down Expand Up @@ -314,7 +314,7 @@ pub mod pallet {
// checks validity
T::ModifierOrigin::ensure_origin(origin)?;
ensure!(
AssetIdLocation::<T>::contains_key(&asset_id),
AssetIdLocation::<T>::contains_key(asset_id),
Error::<T>::UpdateNonExistAsset
);
ensure!(
Expand All @@ -323,10 +323,10 @@ pub mod pallet {
);
// change the ledger state.
let old_location =
AssetIdLocation::<T>::get(&asset_id).ok_or(Error::<T>::UpdateNonExistAsset)?;
AssetIdLocation::<T>::get(asset_id).ok_or(Error::<T>::UpdateNonExistAsset)?;
LocationAssetId::<T>::remove(&old_location);
LocationAssetId::<T>::insert(&location, &asset_id);
AssetIdLocation::<T>::insert(&asset_id, &location);
LocationAssetId::<T>::insert(&location, asset_id);
AssetIdLocation::<T>::insert(asset_id, &location);

// 1. If the new location has new para id, insert the new para id,
// the old para id will be deleted if AssetCount <= 1, or decreased by 1.
Expand Down Expand Up @@ -379,14 +379,14 @@ pub mod pallet {
Error::<T>::CannotUpdateNativeAssetMetadata
);
ensure!(
AssetIdLocation::<T>::contains_key(&asset_id),
AssetIdLocation::<T>::contains_key(asset_id),
Error::<T>::UpdateNonExistAsset
);
<T::AssetConfig as AssetConfig<T>>::AssetRegistrar::update_asset_metadata(
asset_id,
metadata.clone().into(),
)?;
AssetIdMetadata::<T>::insert(&asset_id, &metadata);
AssetIdMetadata::<T>::insert(asset_id, &metadata);
Self::deposit_event(Event::<T>::AssetMetadataUpdated { asset_id, metadata });
Ok(())
}
Expand All @@ -406,10 +406,10 @@ pub mod pallet {
) -> DispatchResult {
T::ModifierOrigin::ensure_origin(origin)?;
ensure!(
AssetIdLocation::<T>::contains_key(&asset_id),
AssetIdLocation::<T>::contains_key(asset_id),
Error::<T>::UpdateNonExistAsset
);
UnitsPerSecond::<T>::insert(&asset_id, &units_per_second);
UnitsPerSecond::<T>::insert(asset_id, units_per_second);
Self::deposit_event(Event::<T>::UnitsPerSecondUpdated {
asset_id,
units_per_second,
Expand All @@ -434,7 +434,7 @@ pub mod pallet {
) -> DispatchResult {
T::ModifierOrigin::ensure_origin(origin)?;
ensure!(
AssetIdLocation::<T>::contains_key(&asset_id),
AssetIdLocation::<T>::contains_key(asset_id),
Error::<T>::UpdateNonExistAsset
);

Expand Down Expand Up @@ -475,7 +475,7 @@ pub mod pallet {
#[pallet::compact] min_xcm_fee: u128,
) -> DispatchResult {
T::ModifierOrigin::ensure_origin(origin)?;
MinXcmFee::<T>::insert(&reserve_chain, &min_xcm_fee);
MinXcmFee::<T>::insert(&reserve_chain, min_xcm_fee);
Self::deposit_event(Event::<T>::MinXcmFeeUpdated {
reserve_chain,
min_xcm_fee,
Expand Down
12 changes: 6 additions & 6 deletions pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ pub mod pallet {
self.eviction_tolerance <= Percent::one(),
"Eviction tolerance must be given as a percentage - number between 0 and 100",
);
<DesiredCandidates<T>>::put(&self.desired_candidates);
<CandidacyBond<T>>::put(&self.candidacy_bond);
<EvictionBaseline<T>>::put(&self.eviction_baseline);
<EvictionTolerance<T>>::put(&self.eviction_tolerance);
<DesiredCandidates<T>>::put(self.desired_candidates);
<CandidacyBond<T>>::put(self.candidacy_bond);
<EvictionBaseline<T>>::put(self.eviction_baseline);
<EvictionTolerance<T>>::put(self.eviction_tolerance);
<Invulnerables<T>>::put(&self.invulnerables);
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ pub mod pallet {
if max > T::MaxCandidates::get() {
log::warn!("max > T::MaxCandidates; you might need to run benchmarks again");
}
<DesiredCandidates<T>>::put(&max);
<DesiredCandidates<T>>::put(max);
Self::deposit_event(Event::NewDesiredCandidates(max));
Ok(().into())
}
Expand All @@ -377,7 +377,7 @@ pub mod pallet {
bond: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
T::UpdateOrigin::ensure_origin(origin)?;
<CandidacyBond<T>>::put(&bond);
<CandidacyBond<T>>::put(bond);
Self::deposit_event(Event::NewCandidacyBond(bond));
Ok(().into())
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/manta-pay/src/bin/precompute_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn main() -> Result<()> {
target_file,
);
fs::create_dir_all(
&target_file
target_file
.parent()
.expect("This file should have a parent."),
)?;
Expand Down
12 changes: 6 additions & 6 deletions pallets/manta-pay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ where

#[inline]
fn is_unspent(&self, void_number: config::VoidNumber) -> Option<Self::ValidVoidNumber> {
if VoidNumberSet::<T>::contains_key(encode(&void_number)) {
if VoidNumberSet::<T>::contains_key(encode(void_number)) {
None
} else {
Some(Wrap(void_number))
Expand All @@ -698,7 +698,7 @@ where
&self,
output: config::UtxoAccumulatorOutput,
) -> Option<Self::ValidUtxoAccumulatorOutput> {
if UtxoAccumulatorOutputs::<T>::contains_key(encode(&output)) {
if UtxoAccumulatorOutputs::<T>::contains_key(encode(output)) {
return Some(Wrap(output));
}
None
Expand All @@ -713,7 +713,7 @@ where
let index = VoidNumberSetSize::<T>::get();
let mut i = 0;
for (_, void_number) in iter {
let void_number = encode(&void_number.0);
let void_number = encode(void_number.0);
VoidNumberSet::<T>::insert(void_number, ());
VoidNumberSetInsertionOrder::<T>::insert(index + i, void_number);
i += 1;
Expand All @@ -733,7 +733,7 @@ where

#[inline]
fn is_not_registered(&self, utxo: config::Utxo) -> Option<Self::ValidUtxo> {
if UtxoSet::<T>::contains_key(encode(&utxo)) {
if UtxoSet::<T>::contains_key(encode(utxo)) {
None
} else {
Some(Wrap(utxo))
Expand Down Expand Up @@ -784,14 +784,14 @@ where
.expect("If this errors, then we have run out of Merkle Tree capacity."),
);
let next_index = current_path.leaf_index().0 as u64;
let utxo = encode(&utxo);
let utxo = encode(utxo);
UtxoSet::<T>::insert(utxo, ());
Shards::<T>::insert(shard_index, next_index, (utxo, EncryptedNote::from(note)));
}
tree.current_path = current_path.into();
if let Some(next_root) = next_root {
ShardTrees::<T>::insert(shard_index, tree);
UtxoAccumulatorOutputs::<T>::insert(encode(&next_root), ());
UtxoAccumulatorOutputs::<T>::insert(encode(next_root), ());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions pallets/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub mod pallet {
/// The dispatch origin for this call must be _Signed_.
///
/// - `target`: The account receiving the vested funds.
/// - `locked_amount`: How much tokens will be transfered.
/// - `locked_amount`: How much tokens will be transferred.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::vested_transfer())]
pub fn vested_transfer(
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<T: Config> Pallet<T> {
/// (Re)set pallet's currency lock on `who`'s account in accordance with their
/// current unvested amount.
fn update_lock(who: &T::AccountId) -> DispatchResult {
let vesting = Self::vesting_balance(&who).ok_or(Error::<T>::NotVesting)?;
let vesting = Self::vesting_balance(who).ok_or(Error::<T>::NotVesting)?;
let now = T::Timestamp::now().as_secs();

// compute the vested portion
Expand All @@ -291,7 +291,7 @@ impl<T: Config> Pallet<T> {

if unvested.is_zero() {
T::Currency::remove_lock(VESTING_ID, who);
VestingBalances::<T>::remove(&who);
VestingBalances::<T>::remove(who);
Self::deposit_event(Event::<T>::VestingCompleted(who.clone()));
} else {
let reasons = WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE;
Expand All @@ -309,11 +309,11 @@ impl<T: Config> Pallet<T> {

// Ensure current user doesn't have any vested token.
ensure!(
!VestingBalances::<T>::contains_key(&who),
!VestingBalances::<T>::contains_key(who),
Error::<T>::ExistingVestingSchedule
);

VestingBalances::<T>::insert(&who, locked);
VestingBalances::<T>::insert(who, locked);
// it can't fail, but even if somehow it did, we don't really care.
Self::update_lock(who)
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/calamari/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pallet-author-inherent = { git = "https://github.com/manta-network/nimbus.git",

# Polkadot dependencies
pallet-xcm = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.26" }
pallet-xcm-benchmarks = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.26", optional = true }
polkadot-parachain = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.26" }
polkadot-primitives = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.26" }
xcm = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.26" }
Expand Down Expand Up @@ -137,6 +138,7 @@ runtime-benchmarks = [
'pallet-asset-manager/runtime-benchmarks',
'cumulus-pallet-xcmp-queue/runtime-benchmarks',
'cumulus-pallet-parachain-system/runtime-benchmarks',
'pallet-xcm-benchmarks',
]
try-runtime = [
'frame-executive/try-runtime',
Expand Down
Loading