From eec38b30e3cabd4334543732edcb8c0341b3a4d3 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Tue, 29 Jun 2021 22:17:00 +0200 Subject: [PATCH] forcing base fee to zero if gas pricing is omitted (#460) * forcing base fee to zero if gas pricing is omitted * force base fee to zero for estimate_gas --- crates/ethcore/src/client/client.rs | 20 ++++++++++++-- crates/rpc/src/v1/helpers/fake_sign.rs | 37 +++++++++++--------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index c88f867b6..b1210a27f 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -1954,7 +1954,12 @@ impl Call for Client { last_hashes: self.build_last_hashes(header.parent_hash()), gas_used: U256::default(), gas_limit: U256::max_value(), - base_fee: header.base_fee(), + //if gas pricing is not defined, force base_fee to zero + base_fee: if transaction.effective_gas_price(header.base_fee()) == 0.into() { + Some(0.into()) + } else { + header.base_fee() + }, }; let machine = self.engine.machine(); @@ -1982,6 +1987,13 @@ impl Call for Client { let machine = self.engine.machine(); for &(ref t, analytics) in transactions { + //if gas pricing is not defined, force base_fee to zero + if t.effective_gas_price(header.base_fee()) == 0.into() { + env_info.base_fee = Some(0.into()); + } else { + env_info.base_fee = header.base_fee() + } + let ret = Self::do_virtual_call(machine, &env_info, state, t, analytics)?; env_info.gas_used = ret.cumulative_gas_used; results.push(ret); @@ -2008,7 +2020,11 @@ impl Call for Client { last_hashes: self.build_last_hashes(header.parent_hash()), gas_used: U256::default(), gas_limit: max, - base_fee: header.base_fee(), + base_fee: if t.effective_gas_price(header.base_fee()) == 0.into() { + Some(0.into()) + } else { + header.base_fee() + }, }; (init, max, env_info) diff --git a/crates/rpc/src/v1/helpers/fake_sign.rs b/crates/rpc/src/v1/helpers/fake_sign.rs index 2f10ea1c5..70f4d6673 100644 --- a/crates/rpc/src/v1/helpers/fake_sign.rs +++ b/crates/rpc/src/v1/helpers/fake_sign.rs @@ -53,29 +53,22 @@ pub fn sign_call(request: CallRequest) -> Result { )) } Some(TypedTxId::EIP1559Transaction) => { - if let Some(max_fee_per_gas) = request.max_fee_per_gas { - tx_legacy.gas_price = max_fee_per_gas; - } else { - return Err(Error::new(ErrorCode::InvalidParams)); - } + tx_legacy.gas_price = request.max_fee_per_gas.unwrap_or_default(); - if let Some(max_priority_fee_per_gas) = request.max_priority_fee_per_gas { - let transaction = AccessListTx::new( - tx_legacy, - request - .access_list - .unwrap_or_default() - .into_iter() - .map(Into::into) - .collect(), - ); - TypedTransaction::EIP1559Transaction(EIP1559TransactionTx { - transaction, - max_priority_fee_per_gas, - }) - } else { - return Err(Error::new(ErrorCode::InvalidParams)); - } + let transaction = AccessListTx::new( + tx_legacy, + request + .access_list + .unwrap_or_default() + .into_iter() + .map(Into::into) + .collect(), + ); + + TypedTransaction::EIP1559Transaction(EIP1559TransactionTx { + transaction, + max_priority_fee_per_gas: request.max_priority_fee_per_gas.unwrap_or_default(), + }) } _ => return Err(Error::new(ErrorCode::InvalidParams)), };