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

Adjust GasLimitPovSizeRatio #1274

Merged
merged 6 commits into from
Sep 20, 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
32 changes: 32 additions & 0 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,38 @@ macro_rules! impl_weight_tests {
let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default();
assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof);
}

#[test]
fn eth_transaction_max_allowed_gas_limit() {
// frontier
use pallet_evm::GasWeightMapping;

let max_extrinsic_weight = <Runtime as frame_system::Config>::BlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic
.expect("Failed to get max extrinsic weight");

assert!(!<Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
12_000_000, true
)
.any_gt(max_extrinsic_weight));
assert!(!<Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
14_000_000, true
)
.any_gt(max_extrinsic_weight));
assert!(!<Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
16_000_000, true
)
.any_gt(max_extrinsic_weight));
assert!(!<Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
18_000_000, true
)
.any_gt(max_extrinsic_weight));
assert!(<Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
20_000_000, true
)
.any_gt(max_extrinsic_weight));
}
}
};
}
Expand Down
7 changes: 5 additions & 2 deletions runtime/crab/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
// darwinia
use crate::*;
// substrate
use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays};
// frontier
use pallet_evm::{ExitError, IsPrecompileResult, Precompile};
use pallet_evm_precompile_dispatch::DispatchValidateT;

const BLOCK_GAS_LIMIT: u64 = 20_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
// Restrict the POV size of the Ethereum transactions in the same way as weight limit.
pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64;
pub PrecompilesValue: CrabPrecompiles<Runtime> = CrabPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(
fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK),
0
);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
// TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581
pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1;
}

pub struct CrabPrecompiles<R>(sp_std::marker::PhantomData<R>);
Expand Down
7 changes: 5 additions & 2 deletions runtime/darwinia/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
// darwinia
use crate::*;
// substrate
use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays};
// frontier
use pallet_evm::{ExitError, IsPrecompileResult, Precompile};
use pallet_evm_precompile_dispatch::DispatchValidateT;

const BLOCK_GAS_LIMIT: u64 = 20_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
// Restrict the POV size of the Ethereum transactions in the same way as weight limit.
pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64;
pub PrecompilesValue: DarwiniaPrecompiles<Runtime> = DarwiniaPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(
fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK),
0
);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
// TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581
pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1;
}
pub struct DarwiniaPrecompiles<R>(sp_std::marker::PhantomData<R>);
impl<R> DarwiniaPrecompiles<R>
Expand Down
7 changes: 5 additions & 2 deletions runtime/pangolin/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
// darwinia
use crate::*;
// substrate
use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays};
// frontier
use pallet_evm::{ExitError, IsPrecompileResult, Precompile};
use pallet_evm_precompile_dispatch::DispatchValidateT;

const BLOCK_GAS_LIMIT: u64 = 20_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
// Restrict the POV size of the Ethereum transactions in the same way as weight limit.
pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64;
pub PrecompilesValue: PangolinPrecompiles<Runtime> = PangolinPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(
fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK),
0
);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
// TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581
pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1;
}

pub struct PangolinPrecompiles<R>(sp_std::marker::PhantomData<R>);
Expand Down
7 changes: 5 additions & 2 deletions runtime/pangoro/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
// darwinia
use crate::*;
// substrate
use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::dispatch::{DispatchClass, GetDispatchInfo, Pays};
// frontier
use pallet_evm::{ExitError, IsPrecompileResult, Precompile};
use pallet_evm_precompile_dispatch::DispatchValidateT;

const BLOCK_GAS_LIMIT: u64 = 20_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
frame_support::parameter_types! {
pub BlockGasLimit: sp_core::U256 = sp_core::U256::from(BLOCK_GAS_LIMIT);
// Restrict the POV size of the Ethereum transactions in the same way as weight limit.
pub BlockPovSizeLimit: u64 = NORMAL_DISPATCH_RATIO * MAX_POV_SIZE as u64;
pub PrecompilesValue: PangoroPrecompiles<Runtime> = PangoroPrecompiles::<_>::new();
pub WeightPerGas: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(
fp_evm::weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK),
0
);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
// TODO: FIX ME. https://github.com/rust-lang/rust/issues/88581
pub GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(BlockPovSizeLimit::get()) + 1;
}

pub struct PangoroPrecompiles<R>(sp_std::marker::PhantomData<R>);
Expand Down
2 changes: 1 addition & 1 deletion tests/ethereum/test-bls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ describe("Test Bls precompile", () => {
}).timeout(60000);

it("Return OutOfGas if insufficient gas", async () => {
bls.options.gas = 300_000;
bls.options.gas = 1000_000; // Less than the normal used gas
await bls.methods
.fast_aggregate_verify(pub_keys_bytes, hexToBytes(message), hexToBytes(signature))
.call()
Expand Down