Skip to content

Commit

Permalink
Use previous block hash to compute tx effectiveGasPrice (#1280)
Browse files Browse the repository at this point in the history
* Use previous block hash to compute tx effectiveGasPrice

* Fall back to current block for base_fee when tx is on genesis
  • Loading branch information
elfedy authored Jan 16, 2024
1 parent 08d5d47 commit 5592ce6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions client/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,31 @@ 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 base_fee_block_substrate_hash = if parent_eth_hash.is_zero() {
substrate_hash
} else {
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(base_fee_block_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 5592ce6

Please sign in to comment.