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
This commit is contained in:
Dusan Stanivukovic 2021-06-29 22:17:00 +02:00 committed by GitHub
parent 287409f9f5
commit eec38b30e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 24 deletions

View File

@ -1954,7 +1954,12 @@ impl Call for Client {
last_hashes: self.build_last_hashes(header.parent_hash()), last_hashes: self.build_last_hashes(header.parent_hash()),
gas_used: U256::default(), gas_used: U256::default(),
gas_limit: U256::max_value(), 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(); let machine = self.engine.machine();
@ -1982,6 +1987,13 @@ impl Call for Client {
let machine = self.engine.machine(); let machine = self.engine.machine();
for &(ref t, analytics) in transactions { 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)?; let ret = Self::do_virtual_call(machine, &env_info, state, t, analytics)?;
env_info.gas_used = ret.cumulative_gas_used; env_info.gas_used = ret.cumulative_gas_used;
results.push(ret); results.push(ret);
@ -2008,7 +2020,11 @@ impl Call for Client {
last_hashes: self.build_last_hashes(header.parent_hash()), last_hashes: self.build_last_hashes(header.parent_hash()),
gas_used: U256::default(), gas_used: U256::default(),
gas_limit: max, 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) (init, max, env_info)

View File

@ -53,29 +53,22 @@ pub fn sign_call(request: CallRequest) -> Result<SignedTransaction, Error> {
)) ))
} }
Some(TypedTxId::EIP1559Transaction) => { Some(TypedTxId::EIP1559Transaction) => {
if let Some(max_fee_per_gas) = request.max_fee_per_gas { tx_legacy.gas_price = request.max_fee_per_gas.unwrap_or_default();
tx_legacy.gas_price = max_fee_per_gas;
} else {
return Err(Error::new(ErrorCode::InvalidParams));
}
if let Some(max_priority_fee_per_gas) = request.max_priority_fee_per_gas { let transaction = AccessListTx::new(
let transaction = AccessListTx::new( tx_legacy,
tx_legacy, request
request .access_list
.access_list .unwrap_or_default()
.unwrap_or_default() .into_iter()
.into_iter() .map(Into::into)
.map(Into::into) .collect(),
.collect(), );
);
TypedTransaction::EIP1559Transaction(EIP1559TransactionTx { TypedTransaction::EIP1559Transaction(EIP1559TransactionTx {
transaction, transaction,
max_priority_fee_per_gas, max_priority_fee_per_gas: request.max_priority_fee_per_gas.unwrap_or_default(),
}) })
} else {
return Err(Error::new(ErrorCode::InvalidParams));
}
} }
_ => return Err(Error::new(ErrorCode::InvalidParams)), _ => return Err(Error::new(ErrorCode::InvalidParams)),
}; };