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

Commit

Permalink
Update EthBlockGasLimit (#306)
Browse files Browse the repository at this point in the history
* Update pangolin's max gas limit

* Update other runtimes

* Move evm tests

* Self review
  • Loading branch information
boundless-forest authored Mar 1, 2023
1 parent 8ddcaa4 commit 9253372
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 114 deletions.
43 changes: 24 additions & 19 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,23 @@ macro_rules! impl_account_migration_tests {
}
};
}

#[macro_export]
macro_rules! impl_evm_tests {
() => {
mod evm {
// darwinia
use crate::mock::{Runtime, WeightPerGas};

#[test]
fn configured_base_extrinsic_weight_is_evm_compatible() {
let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000;
let base_extrinsic = <Runtime as frame_system::Config>::BlockWeights::get()
.get(frame_support::dispatch::DispatchClass::Normal)
.base_extrinsic;

assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time());
}
}
};
}
2 changes: 2 additions & 0 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pallet-bridge-parachains = { workspace = true }
pallet-fee-market = { workspace = true }

# frontier
fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
pallet-ethereum = { workspace = true, features = ["forbid-evm-reentrancy"] }
Expand Down Expand Up @@ -177,6 +178,7 @@ std = [
"pallet-fee-market/std",

# frontier
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"pallet-ethereum/std",
Expand Down
16 changes: 0 additions & 16 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,19 +615,3 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}

#[cfg(test)]
mod tests {
// darwinia
use super::*;

#[test]
fn configured_base_extrinsic_weight_is_evm_compatible() {
let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000;
let base_extrinsic = <Runtime as frame_system::Config>::BlockWeights::get()
.get(frame_support::dispatch::DispatchClass::Normal)
.base_extrinsic;

assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time());
}
}
7 changes: 3 additions & 4 deletions runtime/crab/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ use crate::*;
// frontier
use pallet_evm::Precompile;

const WEIGHT_PER_GAS: u64 = 40_000;

const BLOCK_GAS_LIMIT: u64 = 10_000_000;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
pub PrecompilesValue: CrabPrecompiles<Runtime> = CrabPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_ref_time(WEIGHT_PER_GAS);
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_ref_time(fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK));
}

// TODO: Integrate to the upstream repo
Expand Down
3 changes: 2 additions & 1 deletion runtime/crab/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const AVERAGE_ON_INITIALIZE_RATIO: sp_runtime::Perbill = sp_runtime::Perbill::fr
pub const NORMAL_DISPATCH_RATIO: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(75);

/// We allow for 0.5 of a second of compute with a 12 second average block time.
pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 500;
pub const MAXIMUM_BLOCK_WEIGHT: frame_support::weights::Weight =
frame_support::weights::Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
frame_support::weights::constants::WEIGHT_REF_TIME_PER_MILLIS * WEIGHT_MILLISECS_PER_BLOCK,
cumulus_primitives_core::relay_chain::v2::MAX_POV_SIZE as u64,
);

Expand Down
2 changes: 2 additions & 0 deletions runtime/crab/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod mock;

darwinia_common_runtime::impl_account_migration_tests! {}

darwinia_common_runtime::impl_evm_tests! {}
2 changes: 2 additions & 0 deletions runtime/darwinia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pallet-bridge-parachains = { workspace = true }
pallet-fee-market = { workspace = true }

# frontier
fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
pallet-ethereum = { features = ["forbid-evm-reentrancy"], workspace = true }
Expand Down Expand Up @@ -177,6 +178,7 @@ std = [
"pallet-fee-market/std",

# frontier
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"pallet-ethereum/std",
Expand Down
16 changes: 0 additions & 16 deletions runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,19 +616,3 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}

#[cfg(test)]
mod tests {
// darwinia
use super::*;

#[test]
fn configured_base_extrinsic_weight_is_evm_compatible() {
let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000;
let base_extrinsic = <Runtime as frame_system::Config>::BlockWeights::get()
.get(frame_support::dispatch::DispatchClass::Normal)
.base_extrinsic;

assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time());
}
}
7 changes: 3 additions & 4 deletions runtime/darwinia/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ use crate::*;
// frontier
use pallet_evm::Precompile;

const WEIGHT_PER_GAS: u64 = 40_000;

const BLOCK_GAS_LIMIT: u64 = 10_000_000;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
pub PrecompilesValue: DarwiniaPrecompiles<Runtime> = DarwiniaPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_ref_time(WEIGHT_PER_GAS);
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_ref_time(fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK));
}

// TODO: Integrate to the upstream repo
Expand Down
3 changes: 2 additions & 1 deletion runtime/darwinia/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const AVERAGE_ON_INITIALIZE_RATIO: sp_runtime::Perbill = sp_runtime::Perbill::fr
pub const NORMAL_DISPATCH_RATIO: sp_runtime::Perbill = sp_runtime::Perbill::from_percent(75);

/// We allow for 0.5 of a second of compute with a 12 second average block time.
pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 500;
pub const MAXIMUM_BLOCK_WEIGHT: frame_support::weights::Weight =
frame_support::weights::Weight::from_parts(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
frame_support::weights::constants::WEIGHT_REF_TIME_PER_MILLIS * WEIGHT_MILLISECS_PER_BLOCK,
cumulus_primitives_core::relay_chain::v2::MAX_POV_SIZE as u64,
);

Expand Down
2 changes: 2 additions & 0 deletions runtime/darwinia/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod mock;

darwinia_common_runtime::impl_account_migration_tests! {}

darwinia_common_runtime::impl_evm_tests! {}
2 changes: 2 additions & 0 deletions runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pallet-bridge-parachains = { workspace = true }
pallet-fee-market = { workspace = true }

# frontier
fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
pallet-ethereum = { features = ["forbid-evm-reentrancy"], workspace = true }
Expand Down Expand Up @@ -177,6 +178,7 @@ std = [
"pallet-fee-market/std",

# frontier
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"pallet-ethereum/std",
Expand Down
Loading

0 comments on commit 9253372

Please sign in to comment.