From 31217da6677faeade59b27524818fa7605ef0a57 Mon Sep 17 00:00:00 2001 From: xermicus Date: Wed, 15 Jan 2025 13:09:55 +0100 Subject: [PATCH] the benchmark Signed-off-by: xermicus --- substrate/bin/node/runtime/src/lib.rs | 1 + .../frame/revive/src/benchmarking/mod.rs | 17 +++++++++++ substrate/frame/revive/src/wasm/runtime.rs | 29 ++++++++++++++----- substrate/frame/revive/src/weights.rs | 15 ++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index e11a009c1c3f..475c60448917 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1469,6 +1469,7 @@ impl pallet_revive::Config for Runtime { type ChainId = ConstU64<420_420_420>; type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12. type EthGasEncoder = (); + type FindAuthor = (); } impl pallet_sudo::Config for Runtime { diff --git a/substrate/frame/revive/src/benchmarking/mod.rs b/substrate/frame/revive/src/benchmarking/mod.rs index e67c39ec0899..daf875206260 100644 --- a/substrate/frame/revive/src/benchmarking/mod.rs +++ b/substrate/frame/revive/src/benchmarking/mod.rs @@ -856,6 +856,23 @@ mod benchmarks { assert_eq!(U256::from_little_endian(&memory[..]), runtime.ext().block_number()); } + #[benchmark(pov_mode = Measured)] + fn seal_block_author() { + build_runtime!(runtime, memory: [[123u8; 20], ]); + let result; + #[block] + { + result = runtime.bench_block_author(memory.as_mut_slice(), 0); + } + assert_ok!(result); + let block_author = runtime + .ext() + .block_author() + .map(|account| T::AddressMapper::to_address(&account)) + .unwrap_or(H160::zero()); + assert_eq!(&memory[..], block_author.as_bytes()); + } + #[benchmark(pov_mode = Measured)] fn seal_block_hash() { let mut memory = vec![0u8; 64]; diff --git a/substrate/frame/revive/src/wasm/runtime.rs b/substrate/frame/revive/src/wasm/runtime.rs index b9344afc2e0d..58d8d60c9977 100644 --- a/substrate/frame/revive/src/wasm/runtime.rs +++ b/substrate/frame/revive/src/wasm/runtime.rs @@ -325,6 +325,8 @@ pub enum RuntimeCosts { BlockNumber, /// Weight of calling `seal_block_hash`. BlockHash, + /// Weight of calling `seal_block_author`. + BlockAuthor, /// Weight of calling `seal_gas_price`. GasPrice, /// Weight of calling `seal_base_fee`. @@ -482,6 +484,7 @@ impl Token for RuntimeCosts { MinimumBalance => T::WeightInfo::seal_minimum_balance(), BlockNumber => T::WeightInfo::seal_block_number(), BlockHash => T::WeightInfo::seal_block_hash(), + BlockAuthor => T::WeightInfo::seal_block_author(), GasPrice => T::WeightInfo::seal_gas_price(), BaseFee => T::WeightInfo::seal_base_fee(), Now => T::WeightInfo::seal_now(), @@ -1681,6 +1684,25 @@ pub mod env { )?) } + /// Stores the current block author into the supplied buffer. + /// See [`pallet_revive_uapi::HostFn::block_author`]. + #[stable] + fn block_author(&mut self, memory: &mut M, out_ptr: u32) -> Result<(), TrapReason> { + self.charge_gas(RuntimeCosts::BlockAuthor)?; + let block_author = self + .ext + .block_author() + .map(|account| ::AddressMapper::to_address(&account)) + .unwrap_or(H160::zero()); + Ok(self.write_fixed_sandbox_output( + memory, + out_ptr, + &block_author.as_bytes(), + false, + already_charged, + )?) + } + /// Computes the KECCAK 256-bit hash on the given input buffer. /// See [`pallet_revive_uapi::HostFn::hash_keccak_256`]. #[stable] @@ -1746,13 +1768,6 @@ pub mod env { Ok(self.ext.gas_meter().gas_left().ref_time()) } - /// Returns the block author. - /// See [`pallet_revive_uapi::HostFn::ref_time_left`]. - #[stable] - fn coinbase(&mut self, memory: &mut M, out_ptr: u32) -> Result<(), TrapReason> { - Ok(()) - } - /// Call into the chain extension provided by the chain if any. /// See [`pallet_revive_uapi::HostFn::call_chain_extension`]. fn call_chain_extension( diff --git a/substrate/frame/revive/src/weights.rs b/substrate/frame/revive/src/weights.rs index e35ba5ca0766..c634d2757fcf 100644 --- a/substrate/frame/revive/src/weights.rs +++ b/substrate/frame/revive/src/weights.rs @@ -88,6 +88,7 @@ pub trait WeightInfo { fn seal_base_fee() -> Weight; fn seal_block_number() -> Weight; fn seal_block_hash() -> Weight; + fn seal_block_author() -> Weight; fn seal_now() -> Weight; fn seal_weight_to_fee() -> Weight; fn seal_copy_to_contract(n: u32, ) -> Weight; @@ -544,6 +545,13 @@ impl WeightInfo for SubstrateWeight { // Minimum execution time: 224_000 picoseconds. Weight::from_parts(274_000, 0) } + fn seal_block_author() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 224_000 picoseconds. + Weight::from_parts(274_000, 0) + } /// Storage: `System::BlockHash` (r:1 w:0) /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `Measured`) fn seal_block_hash() -> Weight { @@ -1450,6 +1458,13 @@ impl WeightInfo for () { Weight::from_parts(3_692_000, 3495) .saturating_add(RocksDbWeight::get().reads(1_u64)) } + fn seal_block_author() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 224_000 picoseconds. + Weight::from_parts(274_000, 0) + } fn seal_now() -> Weight { // Proof Size summary in bytes: // Measured: `0`