Skip to content

Commit

Permalink
fix: add blob_gas_used after succesful tx execution (#4913)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
Rjected and mattsse authored Oct 5, 2023
1 parent 005ca66 commit 4dceabf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
23 changes: 14 additions & 9 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,14 +705,6 @@ where
// the gas limit condition for regular transactions above.
best_txs.mark_invalid(&pool_tx);
continue
} else {
// add to the data gas if we're going to execute the transaction
sum_blob_gas_used += tx_blob_gas;

// if we've reached the max data gas per block, we can skip blob txs entirely
if sum_blob_gas_used == MAX_DATA_GAS_PER_BLOCK {
best_txs.skip_blobs();
}
}
}

Expand Down Expand Up @@ -740,6 +732,7 @@ where
trace!(?err, ?tx, "skipping invalid transaction and its descendants");
best_txs.mark_invalid(&pool_tx);
}

continue
}
err => {
Expand All @@ -750,10 +743,22 @@ where
}
};

let gas_used = result.gas_used();
// commit changes
db.commit(state);

// add to the total blob gas used if the transaction successfully executed
if let Some(blob_tx) = tx.transaction.as_eip4844() {
let tx_blob_gas = blob_tx.blob_gas();
sum_blob_gas_used += tx_blob_gas;

// if we've reached the max data gas per block, we can skip blob txs entirely
if sum_blob_gas_used == MAX_DATA_GAS_PER_BLOCK {
best_txs.skip_blobs();
}
}

let gas_used = result.gas_used();

// add gas used by the transaction to cumulative gas used, before creating the receipt
cumulative_gas_used += gas_used;

Expand Down
22 changes: 13 additions & 9 deletions crates/rpc/rpc/src/eth/api/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ impl PendingBlockEnv {
// for regular transactions above.
best_txs.mark_invalid(&pool_tx);
continue
} else {
// add to the data gas if we're going to execute the transaction
sum_blob_gas_used += tx_blob_gas;

// if we've reached the max data gas per block, we can skip blob txs entirely
if sum_blob_gas_used == MAX_DATA_GAS_PER_BLOCK {
best_txs.skip_blobs();
}
}
}

Expand Down Expand Up @@ -155,10 +147,22 @@ impl PendingBlockEnv {
}
};

let gas_used = result.gas_used();
// commit changes
db.commit(state);

// add to the total blob gas used if the transaction successfully executed
if let Some(blob_tx) = tx.transaction.as_eip4844() {
let tx_blob_gas = blob_tx.blob_gas();
sum_blob_gas_used += tx_blob_gas;

// if we've reached the max data gas per block, we can skip blob txs entirely
if sum_blob_gas_used == MAX_DATA_GAS_PER_BLOCK {
best_txs.skip_blobs();
}
}

let gas_used = result.gas_used();

// add gas used by the transaction to cumulative gas used, before creating the receipt
cumulative_gas_used += gas_used;

Expand Down

0 comments on commit 4dceabf

Please sign in to comment.