Skip to content

Commit 5592ce6

Browse files
authored
Use previous block hash to compute tx effectiveGasPrice (polkadot-evm#1280)
* Use previous block hash to compute tx effectiveGasPrice * Fall back to current block for base_fee when tx is on genesis
1 parent 08d5d47 commit 5592ce6

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

client/rpc/src/eth/transaction.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,31 @@ where
287287
let effective_gas_price = match transaction {
288288
EthereumTransaction::Legacy(t) => t.gas_price,
289289
EthereumTransaction::EIP2930(t) => t.gas_price,
290-
EthereumTransaction::EIP1559(t) => self
291-
.client
292-
.runtime_api()
293-
.gas_price(substrate_hash)
294-
.unwrap_or_default()
295-
.checked_add(t.max_priority_fee_per_gas)
296-
.unwrap_or_else(U256::max_value)
297-
.min(t.max_fee_per_gas),
290+
EthereumTransaction::EIP1559(t) => {
291+
let parent_eth_hash = block.header.parent_hash;
292+
let base_fee_block_substrate_hash = if parent_eth_hash.is_zero() {
293+
substrate_hash
294+
} else {
295+
frontier_backend_client::load_hash::<B, C>(
296+
self.client.as_ref(),
297+
self.backend.as_ref(),
298+
parent_eth_hash,
299+
)
300+
.await
301+
.map_err(|err| internal_err(format!("{:?}", err)))?
302+
.ok_or(internal_err(
303+
"Failed to retrieve substrate parent block hash",
304+
))?
305+
};
306+
307+
self.client
308+
.runtime_api()
309+
.gas_price(base_fee_block_substrate_hash)
310+
.unwrap_or_default()
311+
.checked_add(t.max_priority_fee_per_gas)
312+
.unwrap_or_else(U256::max_value)
313+
.min(t.max_fee_per_gas)
314+
}
298315
};
299316

300317
return Ok(Some(Receipt {

0 commit comments

Comments
 (0)