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

Pass WeightInfo to the runner #1447

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 15 additions & 21 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ use fp_consensus::{PostLog, PreLog, FRONTIER_ENGINE_ID};
pub use fp_ethereum::TransactionData;
use fp_ethereum::ValidatedTransaction as ValidatedTransactionT;
use fp_evm::{
CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, TransactionValidationError,
CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, EvmWeightInfo,
TransactionValidationError,
};
pub use fp_rpc::TransactionStatus;
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
Expand Down Expand Up @@ -361,17 +362,14 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
pub fn transaction_weight(transaction_data: &TransactionData) -> (Option<Weight>, Option<u64>) {
match <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
pub fn transaction_weight(transaction_data: &TransactionData) -> Option<EvmWeightInfo> {
let weight_limit = <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
transaction_data.gas_limit.unique_saturated_into(),
true,
) {
weight_limit if weight_limit.proof_size() > 0 => (
Some(weight_limit),
Some(transaction_data.proof_size_base_cost()),
),
_ => (None, None),
}
);
let proof_size_base_cost = transaction_data.proof_size_base_cost();

EvmWeightInfo::new(weight_limit, proof_size_base_cost)
}

fn recover_signer(transaction: &Transaction) -> Option<H160> {
Expand Down Expand Up @@ -493,7 +491,7 @@ impl<T: Config> Pallet<T> {
) -> TransactionValidity {
let transaction_data: TransactionData = transaction.into();
let transaction_nonce = transaction_data.nonce;
let (weight_limit, proof_size_base_cost) = Self::transaction_weight(&transaction_data);
let weight_info = Self::transaction_weight(&transaction_data);
let (base_fee, _) = T::FeeCalculator::min_gas_price();
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&origin);

Expand All @@ -506,8 +504,7 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
transaction_data.clone().into(),
weight_limit,
proof_size_base_cost,
weight_info,
)
.validate_in_pool_for(&who)
.and_then(|v| v.with_chain_id())
Expand Down Expand Up @@ -723,7 +720,7 @@ impl<T: Config> Pallet<T> {
config: Option<evm::Config>,
) -> Result<(Option<H160>, Option<H160>, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let transaction_data: TransactionData = transaction.into();
let (weight_limit, proof_size_base_cost) = Self::transaction_weight(&transaction_data);
let weight_info = Self::transaction_weight(&transaction_data);
let is_transactional = true;
let validate = false;

Expand Down Expand Up @@ -801,8 +798,7 @@ impl<T: Config> Pallet<T> {
access_list,
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
weight_info,
config.as_ref().unwrap_or_else(|| T::config()),
) {
Ok(res) => res,
Expand Down Expand Up @@ -831,8 +827,7 @@ impl<T: Config> Pallet<T> {
access_list,
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
weight_info,
config.as_ref().unwrap_or_else(|| T::config()),
) {
Ok(res) => res,
Expand Down Expand Up @@ -861,7 +856,7 @@ impl<T: Config> Pallet<T> {
transaction: &Transaction,
) -> Result<(), TransactionValidityError> {
let transaction_data: TransactionData = transaction.into();
let (weight_limit, proof_size_base_cost) = Self::transaction_weight(&transaction_data);
let weight_info = Self::transaction_weight(&transaction_data);
let (base_fee, _) = T::FeeCalculator::min_gas_price();
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&origin);

Expand All @@ -874,8 +869,7 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
transaction_data.into(),
weight_limit,
proof_size_base_cost,
weight_info,
)
.validate_in_block_for(&who)
.and_then(|v| v.with_chain_id())
Expand Down
6 changes: 2 additions & 4 deletions frame/ethereum/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,8 @@ fn proof_size_weight_limit_validation_works() {
tx.input = vec![0u8; (weight_limit.proof_size() + 1) as usize];
let tx = tx.sign(&alice.private_key, None);

// Execute
assert!(
Ethereum::transact(RawOrigin::EthereumTransaction(alice.address).into(), tx,).is_err()
);
// Validate in Pool
assert!(Ethereum::validate_transaction_in_pool(alice.address, &tx).is_err());
});
}

Expand Down
6 changes: 2 additions & 4 deletions frame/ethereum/src/tests/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,8 @@ fn proof_size_weight_limit_validation_works() {
tx.input = vec![0u8; (weight_limit.proof_size() + 1) as usize];
let tx = tx.sign(&alice.private_key, None);

// Execute
assert!(
Ethereum::transact(RawOrigin::EthereumTransaction(alice.address).into(), tx,).is_err()
);
// Validate in Pool
assert!(Ethereum::validate_transaction_in_pool(alice.address, &tx).is_err());
});
}

Expand Down
6 changes: 2 additions & 4 deletions frame/ethereum/src/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,8 @@ fn proof_size_weight_limit_validation_works() {
tx.input = vec![0u8; (weight_limit.proof_size() + 1) as usize];
let tx = tx.sign(&alice.private_key);

// Execute
assert!(
Ethereum::transact(RawOrigin::EthereumTransaction(alice.address).into(), tx,).is_err()
);
// Validate in Pool
assert!(Ethereum::validate_transaction_in_pool(alice.address, &tx).is_err());
});
}

Expand Down
17 changes: 10 additions & 7 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ use sp_runtime::{
};
// Frontier
use fp_account::AccountId20;
use fp_evm::GenesisAccount;
pub use fp_evm::{
Account, CallInfo, CreateInfo, ExecutionInfoV2 as ExecutionInfo, FeeCalculator,
IsPrecompileResult, LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileOutput, PrecompileResult, PrecompileSet, TransactionValidationError, Vicinity,
};
use fp_evm::{EvmWeightInfo, GenesisAccount};

pub use self::{
pallet::*,
Expand Down Expand Up @@ -233,6 +233,8 @@ pub mod pallet {

let is_transactional = true;
let validate = true;
let weight_limit = T::GasWeightMapping::gas_to_weight(gas_limit, true);
let weight_info = EvmWeightInfo::new(weight_limit, 0);
let info = match T::Runner::call(
source,
target,
Expand All @@ -245,8 +247,7 @@ pub mod pallet {
access_list,
is_transactional,
validate,
None,
None,
weight_info,
T::config(),
) {
Ok(info) => info,
Expand Down Expand Up @@ -309,6 +310,8 @@ pub mod pallet {

let is_transactional = true;
let validate = true;
let weight_limit = T::GasWeightMapping::gas_to_weight(gas_limit, true);
let weight_info = EvmWeightInfo::new(weight_limit, 0);
let info = match T::Runner::create(
source,
init,
Expand All @@ -320,8 +323,7 @@ pub mod pallet {
access_list,
is_transactional,
validate,
None,
None,
weight_info,
T::config(),
) {
Ok(info) => info,
Expand Down Expand Up @@ -396,6 +398,8 @@ pub mod pallet {

let is_transactional = true;
let validate = true;
let weight_limit = T::GasWeightMapping::gas_to_weight(gas_limit, true);
let weight_info = EvmWeightInfo::new(weight_limit, 0);
let info = match T::Runner::create2(
source,
init,
Expand All @@ -408,8 +412,7 @@ pub mod pallet {
access_list,
is_transactional,
validate,
None,
None,
weight_info,
T::config(),
) {
Ok(info) => info,
Expand Down
14 changes: 5 additions & 9 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod stack;

use crate::{Config, Weight};
use alloc::vec::Vec;
use fp_evm::{CallInfo, CreateInfo};
use fp_evm::{CallInfo, CreateInfo, EvmWeightInfo};
use sp_core::{H160, H256, U256};

#[derive(Debug)]
Expand All @@ -42,8 +42,7 @@ pub trait Runner<T: Config> {
nonce: Option<U256>,
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
weight_info: Option<EvmWeightInfo>,
evm_config: &evm::Config,
) -> Result<(), RunnerError<Self::Error>>;

Expand All @@ -59,8 +58,7 @@ pub trait Runner<T: Config> {
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
weight_info: Option<EvmWeightInfo>,
config: &evm::Config,
) -> Result<CallInfo, RunnerError<Self::Error>>;

Expand All @@ -75,8 +73,7 @@ pub trait Runner<T: Config> {
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
weight_info: Option<EvmWeightInfo>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>>;

Expand All @@ -92,8 +89,7 @@ pub trait Runner<T: Config> {
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
weight_info: Option<EvmWeightInfo>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>>;
}
Loading
Loading