From 93d2e8acc047842eed740ca4b6ab3186e8622bc9 Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 19 Jul 2023 11:50:40 +0800 Subject: [PATCH] Bump frontier and fix tests (#1208) --- Cargo.lock | 40 ++++++++--------- runtime/crab/src/lib.rs | 89 +++++++++++++++++++++++++++++++++---- runtime/darwinia/src/lib.rs | 89 +++++++++++++++++++++++++++++++++---- runtime/pangolin/src/lib.rs | 89 +++++++++++++++++++++++++++++++++---- runtime/pangoro/src/lib.rs | 89 +++++++++++++++++++++++++++++++++---- tests/ethereum/test-bls.ts | 2 +- tests/ethereum/test-gas.ts | 2 +- 7 files changed, 346 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4511d838..21a6b0cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3785,7 +3785,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "async-trait", "fp-consensus", @@ -3801,7 +3801,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "async-trait", "ethereum", @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fc-db", "fc-storage", @@ -3854,7 +3854,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -3904,7 +3904,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -3917,7 +3917,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -4108,7 +4108,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "hex", "impl-serde", @@ -4127,7 +4127,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "parity-scale-codec", @@ -4139,7 +4139,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -4153,7 +4153,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "evm", "frame-support", @@ -4168,7 +4168,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -4185,7 +4185,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "frame-support", "parity-scale-codec", @@ -4197,7 +4197,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "parity-scale-codec", "serde", @@ -7865,7 +7865,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "ethereum", "ethereum-types 0.14.1", @@ -7914,7 +7914,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "environmental", "evm", @@ -7939,7 +7939,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fp-evm", ] @@ -7947,7 +7947,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fp-evm", "sp-core", @@ -7957,7 +7957,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fp-evm", "frame-support", @@ -7967,7 +7967,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fp-evm", "num", @@ -7976,7 +7976,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#adf7117f373b68d4128385ad08c28a9f7c597cd0" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.43#c2605558ad7e23362be1f16c7d2ec3e7d2e658ab" dependencies = [ "fp-evm", "ripemd", diff --git a/runtime/crab/src/lib.rs b/runtime/crab/src/lib.rs index 4c62474e6..35ee72e3c 100644 --- a/runtime/crab/src/lib.rs +++ b/runtime/crab/src/lib.rs @@ -418,8 +418,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -435,6 +437,40 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // to + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::call( from, to, @@ -447,9 +483,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } @@ -465,8 +500,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -482,6 +519,43 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = if gas_limit > sp_core::U256::from(u64::MAX) { + u64::MAX + } else { + gas_limit.low_u64() + }; + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::create( from, data, @@ -493,9 +567,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } diff --git a/runtime/darwinia/src/lib.rs b/runtime/darwinia/src/lib.rs index cf3781563..90d7d6ff7 100644 --- a/runtime/darwinia/src/lib.rs +++ b/runtime/darwinia/src/lib.rs @@ -419,8 +419,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -436,6 +438,40 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // to + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::call( from, to, @@ -448,9 +484,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } @@ -466,8 +501,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -483,6 +520,43 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = if gas_limit > sp_core::U256::from(u64::MAX) { + u64::MAX + } else { + gas_limit.low_u64() + }; + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::create( from, data, @@ -494,9 +568,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 73cf565d8..c06935da0 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -420,8 +420,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -437,6 +439,40 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // to + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::call( from, to, @@ -449,9 +485,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } @@ -467,8 +502,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -484,6 +521,43 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = if gas_limit > sp_core::U256::from(u64::MAX) { + u64::MAX + } else { + gas_limit.low_u64() + }; + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::create( from, data, @@ -495,9 +569,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } diff --git a/runtime/pangoro/src/lib.rs b/runtime/pangoro/src/lib.rs index dd30a4840..5196d0561 100644 --- a/runtime/pangoro/src/lib.rs +++ b/runtime/pangoro/src/lib.rs @@ -419,8 +419,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -436,6 +438,40 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // to + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::call( from, to, @@ -448,9 +484,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } @@ -466,8 +501,10 @@ sp_api::impl_runtime_apis! { estimate: bool, access_list: Option)>>, ) -> Result { + // crates.io + use codec::Encode; // frontier - use pallet_evm::Runner; + use pallet_evm::{Runner, GasWeightMapping}; // substrate use sp_runtime::traits::UniqueSaturatedInto; @@ -483,6 +520,43 @@ sp_api::impl_runtime_apis! { let validate = true; #[allow(clippy::or_fun_call)] let evm_config = config.as_ref().unwrap_or(::config()); + + let mut estimated_transaction_len = data.len() + + 20 + // from + 32 + // value + 32 + // gas_limit + 32 + // nonce + 1 + // TransactionAction + 8 + // chain id + 65; // signature + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = if gas_limit > sp_core::U256::from(u64::MAX) { + u64::MAX + } else { + gas_limit.low_u64() + }; + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; ::Runner::create( from, data, @@ -494,9 +568,8 @@ sp_api::impl_runtime_apis! { access_list.unwrap_or_default(), is_transactional, validate, - // TODO: FIX ME https://github.com/paritytech/frontier/pull/1101 - None, - None, + weight_limit, + proof_size_base_cost, evm_config, ).map_err(|err| err.error.into()) } diff --git a/tests/ethereum/test-bls.ts b/tests/ethereum/test-bls.ts index 598894092..2101bfbda 100644 --- a/tests/ethereum/test-bls.ts +++ b/tests/ethereum/test-bls.ts @@ -566,7 +566,7 @@ describe("Test Bls precompile", () => { }).timeout(60000); it("Return OutOfGas if insufficient gas", async () => { - bls.options.gas = 100_000; + bls.options.gas = 300_000; await bls.methods .fast_aggregate_verify(pub_keys_bytes, hexToBytes(message), hexToBytes(signature)) .call() diff --git a/tests/ethereum/test-gas.ts b/tests/ethereum/test-gas.ts index 02e5b78c2..1c7547cba 100644 --- a/tests/ethereum/test-gas.ts +++ b/tests/ethereum/test-gas.ts @@ -25,7 +25,7 @@ describe("Test transaction gas limit", () => { from: FAITH, data: data.encodeABI(), }) - ).to.equal(257336); + ).to.equal(257398); }).timeout(60000); it("Test contract call estimate gas", async () => {