Skip to content

Commit

Permalink
the benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: xermicus <[email protected]>
  • Loading branch information
xermicus committed Jan 15, 2025
1 parent 2c8637a commit 31217da
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions substrate/frame/revive/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
29 changes: 22 additions & 7 deletions substrate/frame/revive/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -482,6 +484,7 @@ impl<T: Config> Token<T> 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(),
Expand Down Expand Up @@ -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| <E::T as Config>::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]
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions substrate/frame/revive/src/weights.rs

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

0 comments on commit 31217da

Please sign in to comment.