Skip to content

Commit

Permalink
Use previous block hash to compute tx effectiveGasPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy committed Jan 15, 2024
1 parent 08d5d47 commit 29f44ca
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions client/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ where
block,
receipts,
statuses,
substrate_hash,
..
} = block_info.clone();
match (block, statuses, receipts) {
Expand Down Expand Up @@ -287,14 +286,25 @@ where
let effective_gas_price = match transaction {
EthereumTransaction::Legacy(t) => t.gas_price,
EthereumTransaction::EIP2930(t) => t.gas_price,
EthereumTransaction::EIP1559(t) => self
.client
.runtime_api()
.gas_price(substrate_hash)
.unwrap_or_default()
.checked_add(t.max_priority_fee_per_gas)
.unwrap_or_else(U256::max_value)
.min(t.max_fee_per_gas),
EthereumTransaction::EIP1559(t) => {
let parent_eth_hash = block.header.parent_hash;
let parent_substrate_hash = frontier_backend_client::load_hash::<B, C>(
self.client.as_ref(),
self.backend.as_ref(),
parent_eth_hash,
)
.await
.map_err(|err| internal_err(format!("{:?}", err)))?
.ok_or(internal_err("Failed to retrieve substrate parent block hash"))?;

self.client
.runtime_api()
.gas_price(parent_substrate_hash)
.unwrap_or_default()
.checked_add(t.max_priority_fee_per_gas)
.unwrap_or_else(U256::max_value)
.min(t.max_fee_per_gas)
}
};

return Ok(Some(Receipt {
Expand Down

0 comments on commit 29f44ca

Please sign in to comment.