From 0559d8c2d50cb8c706b75413855f7f22ac8ce30a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 17 Apr 2023 16:31:52 +0200 Subject: [PATCH] fix(payload): sum cumulative gas used before adding receipt (#2284) --- crates/payload/basic/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index e346128b5..b5c72a4b4 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -477,10 +477,14 @@ fn build_payload( // TODO skip invalid transactions let ResultAndState { result, state } = evm.transact().map_err(PayloadBuilderError::EvmExecutionError)?; + let gas_used = result.gas_used(); // commit changes commit_state_changes(&mut db, &mut post_state, state, true); + // add gas used by the transaction to cumulative gas used, before creating the receipt + cumulative_gas_used += gas_used; + // Push transaction changeset and calculate header bloom filter for receipt. post_state.add_receipt(Receipt { tx_type: tx.tx_type(), @@ -489,17 +493,12 @@ fn build_payload( logs: result.logs().into_iter().map(into_reth_log).collect(), }); - let gas_used = result.gas_used(); - // update add to total fees let miner_fee = tx .effective_tip_per_gas(base_fee) .expect("fee is always valid; execution succeeded"); total_fees += U256::from(miner_fee) * U256::from(gas_used); - // append gas used - cumulative_gas_used += gas_used; - // append transaction to the list of executed transactions executed_txs.push(tx.into_signed()); }