Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge 7b98b2f into d05de27
Browse files Browse the repository at this point in the history
  • Loading branch information
cab404 authored Sep 8, 2021
2 parents d05de27 + 7b98b2f commit 6050470
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 44 deletions.
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SHELL := bash
SHELL := /usr/bin/env bash

.PHONY: init
init:
Expand All @@ -10,11 +10,12 @@ check:
cargo check --all
cargo check --all --tests
make check-no-std
make check-benchmarks

.PHONY: check-benchmarks
check-benchmarks:
export SKIP_WASM_BUILD=1
pushd node && cargo check --features=runtime-benchmarks; popd
cargo check --features=runtime-benchmarks; popd

.PHONY: check-no-std
check-no-std:
Expand All @@ -26,12 +27,13 @@ clippy:
pushd pallets/sp-mvm && cargo clippy -p=sp-mvm --target=wasm32-unknown-unknown --no-default-features

.PHONY: bench
bench:
make assets
bench: assets
# This is just an example about how to run benchmarks for the pallet
mkdir -p ./target/sp-bench
pushd node && \
cargo run --release --features=runtime-benchmarks -- \
cargo run \
--release \
--bin pontem \
--features=runtime-benchmarks -- \
benchmark \
--dev \
-lsp_mvm=trace \
Expand All @@ -40,7 +42,7 @@ bench:
--execution=wasm \
--wasm-execution=compiled \
--steps=20 --repeat=10 \
--output=../target/sp-bench
--output=target/sp-bench

.PHONY: test
test:
Expand All @@ -59,8 +61,12 @@ build:
cargo build --release

.PHONY: assets
assets:
assets: pallets/sp-mvm/tests/assets/stdlib pallets/sp-mvm/tests/benchmark_assets/stdlib

pallets/sp-mvm/tests/assets/stdlib:
pushd pallets/sp-mvm/tests/assets && ./build_assets.sh

pallets/sp-mvm/tests/benchmark_assets/stdlib:
pushd pallets/sp-mvm/tests/benchmark_assets && ./build_assets.sh

.PHONY: coverage
Expand Down
2 changes: 1 addition & 1 deletion pallets/multisig/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_benchmarking::{benchmarks, account};
use sp_runtime::traits::Bounded;
use core::convert::TryInto;

use crate::Module as Multisig;
use crate::Pallet as Multisig;

const SEED: u32 = 0;

Expand Down
62 changes: 27 additions & 35 deletions pallets/sp-mvm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ use super::*;
use super::Pallet as Mvm;

benchmarks! {
publish_std {
let s in 0 .. 100;
let stdlib_modules = stdlib()
.into_iter()
.map(|(_, m)|m)
.collect::<Vec<_>>();
}: _(RawOrigin::Root, stdlib_modules, 100_000_000)
verify {
for (name, _) in stdlib() {
assert!(VMStorage::<T>::contains_key(module_access_core(name)));
}
}

// Needs to be fixed in multisig. Not yet sure how, needs more deconstruction.
where_clause { where Result<pallet_multisig::Origin<T>, <T as frame_system::Config>::Origin>: From<<T as frame_system::Config>::Origin> }

publish_empty_module {
let s in 0 .. 100;
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -46,7 +38,7 @@ benchmarks! {
VMStorage::<T>::insert(module_access_core(name), module);
}
let caller: T::AccountId = whitelisted_caller();
let module = include_bytes!("../tests/benchmark_assets/artifacts/modules/51_StdImport.mv").to_vec();
let module = include_bytes!("../tests/benchmark_assets/artifacts/modules/52_StdImport.mv").to_vec();
}: publish_module(RawOrigin::Signed(caller), module, 100_000_000)
verify {
assert!(VMStorage::<T>::contains_key(module_access("StdImport")));
Expand Down Expand Up @@ -235,99 +227,99 @@ pub fn stdlib() -> Vec<(&'static str, Vec<u8>)> {
),
(
"DesignatedDealer",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/23_DesignatedDealer.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/24_DesignatedDealer.mv").to_vec()
),
(
"AccountFreezing",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/24_AccountFreezing.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/25_AccountFreezing.mv").to_vec()
),
(
"DiemAccount",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/25_DiemAccount.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/26_DiemAccount.mv").to_vec()
),
(
"Hash",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/26_Hash.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/27_Hash.mv").to_vec()
),
(
"Authenticator",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/27_Authenticator.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/28_Authenticator.mv").to_vec()
),
(
"SharedEd25519PublicKey",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/28_SharedEd25519PublicKey.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/29_SharedEd25519PublicKey.mv").to_vec()
),
(
"RecoveryAddress",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/29_RecoveryAddress.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/30_RecoveryAddress.mv").to_vec()
),
(
"Errors",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/2_Errors.mv").to_vec()
),
(
"AccountAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/30_AccountAdministrationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/31_AccountAdministrationScripts.mv").to_vec()
),
(
"AccountCreationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/31_AccountCreationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/32_AccountCreationScripts.mv").to_vec()
),
(
"ChainId",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/32_ChainId.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/33_ChainId.mv").to_vec()
),
(
"DiemBlock",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/33_DiemBlock.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/34_DiemBlock.mv").to_vec()
),
(
"DiemConsensusConfig",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/34_DiemConsensusConfig.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/35_DiemConsensusConfig.mv").to_vec()
),
(
"DiemSystem",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/35_DiemSystem.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/36_DiemSystem.mv").to_vec()
),
(
"DiemTransactionPublishingOption",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/36_DiemTransactionPublishingOption.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/37_DiemTransactionPublishingOption.mv").to_vec()
),
(
"DiemVMConfig",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/37_DiemVMConfig.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/38_DiemVMConfig.mv").to_vec()
),
(
"DiemVersion",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/38_DiemVersion.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/39_DiemVersion.mv").to_vec()
),
(
"TransactionFee",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/39_TransactionFee.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/40_TransactionFee.mv").to_vec()
),
(
"CoreAddresses",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/3_CoreAddresses.mv").to_vec()
),
(
"Genesis",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/40_Genesis.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/41_Genesis.mv").to_vec()
),
(
"PaymentScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/41_PaymentScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/42_PaymentScripts.mv").to_vec()
),
(
"SystemAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/42_SystemAdministrationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/43_SystemAdministrationScripts.mv").to_vec()
),
(
"TreasuryComplianceScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/43_TreasuryComplianceScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/44_TreasuryComplianceScripts.mv").to_vec()
),
(
"ValidatorAdministrationScripts",
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/44_ValidatorAdministrationScripts.mv").to_vec()
include_bytes!("../tests/benchmark_assets/stdlib/artifacts/modules/45_ValidatorAdministrationScripts.mv").to_vec()
),
(
"DiemTimestamp",
Expand Down
25 changes: 25 additions & 0 deletions rename_modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#/usr/bin/env bash
# Renames move modules in $bench, by finding modules with the same name in stdlib but with different priority.
# Usually works
# Invoke from repo root

# Path to benchmarking.rs
bench=pallets/sp-mvm/src/benchmarking.rs

# Path to new stdlib
basedir=$(dirname ${bench})/../tests/benchmark_assets/stdlib/artifacts/modules

find_new() {
modname=$(echo $1 | grep -Po "(?<=_)(.*)(?=\.)")
found=$(echo ${basedir}/*_$modname.mv)
# echo "found $found for $1"
newname=$(basename $found)
# echo $modname '|' $1 '->' $newname
[ $newname != $1 ] && echo "s|modules/$1|modules/${newname}|g"
}

for F in $(cat ${bench} | grep -Po '(?<=/)\d+_(.+).mv'); do
pat=$(find_new $F)
echo for $F replacing $pat
sed -i "$pat" $bench
done
16 changes: 16 additions & 0 deletions scripts/rename_modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bench=pallets/sp-mvm/src/benchmarking.rs
basedir=$(dirname ${bench})/../tests/benchmark_assets/stdlib/artifacts/modules
find_new() {
modname=$(echo $1 | grep -Po "(?<=_)(.*)(?=\.)")
found=$(ls ${basedir}/*_$modname.mv)
# echo "found $found for $1"
newname=$(basename $found)
# echo $modname '|' $1 '->' $newname
[ $newname != $1 ] && echo "s|modules/$1|modules/${newname}|g"
}

for F in $(cat ${bench} | grep -Po '(?<=/)\d+_(.+).mv'); do
pat=$(find_new $F)
echo for $F replacing $pat
sed -i "$pat" $bench
done

0 comments on commit 6050470

Please sign in to comment.