Skip to content

Commit

Permalink
Consumed data gas receipt fix (#5018)
Browse files Browse the repository at this point in the history
* adding test for nonblob blob transaction
* Do not add consumed data gas to gas used in the transaction receipt

Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Jiri Peinlich <jiri.peinlich@gmail.com>
  • Loading branch information
fab-10 and gezero authored Jan 27, 2023
1 parent fd427d4 commit b13583a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,14 @@ private void updateTransactionResultTracking(
transaction.isGoQuorumPrivateTransaction(
transactionProcessor.getTransactionValidator().getGoQuorumCompatibilityMode());

final long dataGasUsed = gasCalculator.dataGasCost(transaction.getBlobCount());

final long gasUsedByTransaction =
isGoQuorumPrivateTransaction
? 0
: transaction.getGasLimit() + dataGasUsed - result.getGasRemaining();
isGoQuorumPrivateTransaction ? 0 : transaction.getGasLimit() - result.getGasRemaining();

final long cumulativeGasUsed =
transactionSelectionResult.getCumulativeGasUsed() + gasUsedByTransaction;

final long dataGasUsed = gasCalculator.dataGasCost(transaction.getBlobCount());

transactionSelectionResult.update(
transaction,
transactionReceiptFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public BlockProcessingResult processBlock(
final PrivateMetadataUpdater privateMetadataUpdater) {
final List<TransactionReceipt> receipts = new ArrayList<>();
long currentGasUsed = 0;

final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);

for (final Transaction transaction : transactions) {
if (!hasAvailableBlockBudget(blockHeader, transaction, currentGasUsed)) {
return new BlockProcessingResult(Optional.empty(), "provided gas insufficient");
Expand Down Expand Up @@ -132,15 +135,18 @@ public BlockProcessingResult processBlock(
}
worldStateUpdater.commit();

currentGasUsed += transaction.getGasLimit() - result.getGasRemaining();
final long dataGasUsed =
protocolSpec.getGasCalculator().dataGasCost(transaction.getBlobCount());

currentGasUsed += transaction.getGasLimit() - result.getGasRemaining() - dataGasUsed;
final TransactionReceipt transactionReceipt =
transactionReceiptFactory.create(
transaction.getType(), result, worldState, currentGasUsed);
receipts.add(transactionReceipt);
}

final Optional<WithdrawalsProcessor> maybeWithdrawalsProcessor =
protocolSchedule.getByBlockHeader(blockHeader).getWithdrawalsProcessor();
protocolSpec.getWithdrawalsProcessor();
if (maybeWithdrawalsProcessor.isPresent() && maybeWithdrawals.isPresent()) {
maybeWithdrawalsProcessor
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ static ProtocolSpecBuilder shanghaiDefinition(
final boolean quorumCompatibilityMode,
final EvmConfiguration evmConfiguration) {

// extra vaiables need to support flipping the warm coinbase flag.
// extra variables need to support flipping the warm coinbase flag.
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L);
final BaseFeeMarket londonFeeMarket =
Expand Down

0 comments on commit b13583a

Please sign in to comment.