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

fix benchmarking for different node templates #179

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions frame/evm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ benchmarks! {

let caller = "1000000000000000000000000000000000000001".parse::<H160>().unwrap();

let mut nonce: u64 = 1;
let mut nonce: u64 = 0;
let nonce_as_u256: U256 = nonce.into();

let value = U256::default();
Expand All @@ -83,8 +83,8 @@ benchmarks! {
contract_bytecode,
value,
gas_limit_create,
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(nonce_as_u256),
Vec::new(),
is_transactional,
Expand Down Expand Up @@ -120,8 +120,8 @@ benchmarks! {
encoded_call,
value,
gas_limit_call,
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(nonce_as_u256),
Vec::new(),
is_transactional,
Expand Down
70 changes: 70 additions & 0 deletions frame/evm/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,93 @@ use core::marker::PhantomData;

/// Weight functions needed for pallet_evm.
pub trait WeightInfo {
fn runner_execute(x: u32, ) -> Weight;
fn withdraw() -> Weight;
}

/// Weights for pallet_evm using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: BaseFee BaseFeePerGas (r:1 w:0)
/// Proof: BaseFee BaseFeePerGas (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
/// Storage: System Account (r:2 w:1)
/// Proof: System Account (max_values: None, max_size: Some(116), added: 2591, mode: MaxEncodedLen)
/// Storage: EVMChainId ChainId (r:1 w:0)
/// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
/// Storage: EVM AccountCodes (r:2 w:0)
/// Proof Skipped: EVM AccountCodes (max_values: None, max_size: None, mode: Measured)
/// Storage: System Number (r:1 w:0)
/// Proof: System Number (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: System ExecutionPhase (r:1 w:0)
/// Proof: System ExecutionPhase (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: System EventCount (r:1 w:1)
/// Proof: System EventCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: System Events (r:1 w:1)
/// Proof Skipped: System Events (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Digest (r:1 w:0)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: EVM AccountStorages (r:1 w:0)
/// Proof Skipped: EVM AccountStorages (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances TotalIssuance (r:1 w:1)
/// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen)
/// The range of component `x` is `[1, 10000000]`.
fn runner_execute(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `913`
// Estimated: `6853`
// Minimum execution time: 20_400_192_000 picoseconds.
Weight::from_parts(20_767_272_339, 6853)
// Standard Error: 33
.saturating_add(Weight::from_parts(42, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(13_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
fn withdraw() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_000_000, 0)
}

}

// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: BaseFee BaseFeePerGas (r:1 w:0)
/// Proof: BaseFee BaseFeePerGas (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
/// Storage: System Account (r:2 w:1)
/// Proof: System Account (max_values: None, max_size: Some(116), added: 2591, mode: MaxEncodedLen)
/// Storage: EVMChainId ChainId (r:1 w:0)
/// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
/// Storage: EVM AccountCodes (r:2 w:0)
/// Proof Skipped: EVM AccountCodes (max_values: None, max_size: None, mode: Measured)
/// Storage: System Number (r:1 w:0)
/// Proof: System Number (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: System ExecutionPhase (r:1 w:0)
/// Proof: System ExecutionPhase (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: System EventCount (r:1 w:1)
/// Proof: System EventCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: System Events (r:1 w:1)
/// Proof Skipped: System Events (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Digest (r:1 w:0)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: EVM AccountStorages (r:1 w:0)
/// Proof Skipped: EVM AccountStorages (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances TotalIssuance (r:1 w:1)
/// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen)
/// The range of component `x` is `[1, 10000000]`.
fn runner_execute(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `913`
// Estimated: `6853`
// Minimum execution time: 20_400_192_000 picoseconds.
Weight::from_parts(20_767_272_339, 6853)
// Standard Error: 33
.saturating_add(Weight::from_parts(42, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(13_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
fn withdraw() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
Expand Down
3 changes: 2 additions & 1 deletion scripts/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ function bench {
--extrinsic="${2}" \
--execution=wasm \
--wasm-execution=compiled \
--header=HEADER-APACHE2 \
--output=weights.rs \
--template=./benchmarking/frame-weight-template.hbs
--template=./.maintain/frame-weight-template.hbs
}

if [[ $# -eq 1 && "${1}" == "--help" ]]; then
Expand Down
7 changes: 4 additions & 3 deletions template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ fn testnet_genesis(
H160::from_str("1000000000000000000000000000000000000001")
.expect("internal H160 is valid; qed"),
fp_evm::GenesisAccount {
nonce: U256::from(1),
balance: U256::from(1_000_000_000_000_000_000_000_000u128),
nonce: Default::default(),
balance: U256::from_str("0xffffffffffffffffffffffffffffffff")
.expect("internal U256 is valid; qed"),
storage: Default::default(),
code: vec![0x00],
code: Default::default(),
},
);
map
Expand Down