Skip to content

Commit

Permalink
Storage version, additional benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Sep 27, 2023
1 parent 866a0ba commit a8900aa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
18 changes: 18 additions & 0 deletions pallets/dynamic-evm-base-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ mod benchmarks {
assert_eq!(BaseFeePerGas::<T>::get(), new_bfpg);
}

#[benchmark]
fn min_gas_price() {
let first_block = T::BlockNumber::from(1u32);

// Setup actions, should ensure some value is written to storage.
Pallet::<T>::on_initialize(first_block);
Pallet::<T>::on_finalize(first_block);
assert!(
BaseFeePerGas::<T>::exists(),
"Value should exist in storage after first on_finalize call"
);

#[block]
{
let _ = Pallet::<T>::min_gas_price();

Check failure on line 79 in pallets/dynamic-evm-base-fee/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

no function or associated item named `min_gas_price` found for struct `pallet::Pallet` in the current scope

error[E0599]: no function or associated item named `min_gas_price` found for struct `pallet::Pallet` in the current scope --> pallets/dynamic-evm-base-fee/src/benchmarking.rs:79:34 | 79 | let _ = Pallet::<T>::min_gas_price(); | ^^^^^^^^^^^^^ function or associated item not found in `Pallet<T>` | ::: pallets/dynamic-evm-base-fee/src/lib.rs:107:5 | 107 | pub struct Pallet<T>(PhantomData<T>); | -------------------- function or associated item `min_gas_price` not found for this struct | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | 27 | use fp_evm::FeeCalculator; |
}
}

impl_benchmark_test_suite!(
Pallet,
crate::benchmarking::tests::new_test_ext(),
Expand Down
9 changes: 6 additions & 3 deletions pallets/dynamic-evm-base-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{traits::Get, weights::Weight};
use frame_support::weights::Weight;
use sp_core::U256;
use sp_runtime::{traits::UniqueSaturatedInto, FixedPointNumber, FixedU128, Perquintill};

Expand All @@ -99,7 +99,11 @@ pub mod pallet {

use super::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
Expand Down Expand Up @@ -229,7 +233,6 @@ pub mod pallet {

impl<T: Config> fp_evm::FeeCalculator for Pallet<T> {
fn min_gas_price() -> (U256, Weight) {
// TODO: account for PoV?
(BaseFeePerGas::<T>::get(), T::DbWeight::get().reads(1))
(BaseFeePerGas::<T>::get(), T::WeightInfo::min_gas_price())
}
}
7 changes: 7 additions & 0 deletions pallets/dynamic-evm-base-fee/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use core::marker::PhantomData;
pub trait WeightInfo {
fn base_fee_per_gas_adjustment() -> Weight;
fn set_base_fee_per_gas() -> Weight;
fn min_gas_price() -> Weight;
}

/// Weights for pallet_dynamic_evm_base_fee using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -79,6 +80,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_parts(9_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
fn min_gas_price() -> Weight {
Weight::from_parts(0, 0)
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -106,4 +110,7 @@ impl WeightInfo for () {
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
fn min_gas_price() -> Weight {
Weight::from_parts(0, 0)
}
}
5 changes: 4 additions & 1 deletion runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ parameter_types! {
}

/// Simple `OnRuntimeUpgrade` logic to prepare Shibuya runtime for `DynamicEvmBaseFee` pallet.
pub use frame_support::traits::OnRuntimeUpgrade;
pub use frame_support::traits::{OnRuntimeUpgrade, StorageVersion};
pub struct DynamicEvmBaseFeeMigration;
impl OnRuntimeUpgrade for DynamicEvmBaseFeeMigration {
fn on_runtime_upgrade() -> Weight {
Expand All @@ -1344,6 +1344,9 @@ impl OnRuntimeUpgrade for DynamicEvmBaseFeeMigration {
// Shibuya's multiplier is so low that we have to set it to minimum value directly.
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::put(MinimumMultiplier::get());

// Set init storage version for the pallet
StorageVersion::new(1).put::<pallet_dynamic_evm_base_fee::Pallet<Runtime>>();

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 2)
}
}
Expand Down

0 comments on commit a8900aa

Please sign in to comment.