Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas accounting for EIP-4844 #4992

Merged
merged 36 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e43731
Gas accounting for EIP-4844
fab-10 Jan 24, 2023
05f4387
Update CHANGELOG
fab-10 Jan 24, 2023
7a94b4a
Fix tests
fab-10 Jan 24, 2023
642c26f
Merge branch 'main' into 4844-gas-accounting
fab-10 Jan 24, 2023
18ef1be
Remove duplicated code
fab-10 Jan 24, 2023
080ead0
Fix blob tx identification
fab-10 Jan 24, 2023
52c00f9
Merge branch 'main' into 4844-gas-accounting
fab-10 Jan 24, 2023
55b1f7a
Update log
fab-10 Jan 24, 2023
657f975
Add reference to the EIP-4844
fab-10 Jan 24, 2023
0a0c702
Fix and improvements from code review
fab-10 Jan 24, 2023
ffb6c93
Move Cancun fee market constants into Cancun class
fab-10 Jan 24, 2023
72c6988
Code reorg
fab-10 Jan 24, 2023
6c575ec
Track max data gas per block using GasLimitCalculator
fab-10 Jan 24, 2023
1699663
Use long internally to represent data gas
fab-10 Jan 24, 2023
af7c70a
Fix javadoc
fab-10 Jan 24, 2023
79e9338
Write power of 2 in a self documenting way
fab-10 Jan 24, 2023
0719ded
Consumed data gas receipt fix (#5018)
fab-10 Jan 27, 2023
c967962
Allow blob tx in Cancun (#5007)
fab-10 Jan 26, 2023
437c770
Revert "Consumed data gas receipt fix (#5018)"
fab-10 Feb 1, 2023
dd91da3
Consumed data gas receipt fix (#5018)
fab-10 Jan 27, 2023
112e774
Fix data gas calculation during block import (#5023)
fab-10 Jan 31, 2023
a9ecadd
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 1, 2023
dd5f1c4
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 3, 2023
fc9abee
Correctly set the fee market Cancun (#5045)
fab-10 Feb 3, 2023
b029714
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 14, 2023
6becf37
Optimization to avoid to compute dataGasPrice for every txs in a block
fab-10 Feb 14, 2023
7b7e50a
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 17, 2023
1f9ba3f
Use actual dataPrice in BlockTransactionSelector
fab-10 Feb 17, 2023
b8fa8f8
Use actual dataPrice in BlockTransactionSelector
fab-10 Feb 17, 2023
0a3730c
Remove uneeded changes
fab-10 Feb 17, 2023
457ef1e
Fixes
fab-10 Feb 17, 2023
cec997f
Always get the excessDataGas from the parent to calculate dataGasPrice
fab-10 Feb 17, 2023
641de9e
TOTAL_DATA_GAS_TOO_HIGH json rpc error
fab-10 Feb 17, 2023
7ef58f9
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 21, 2023
7c4ea9e
Merge branch 'main' into 4844-gas-accounting
fab-10 Feb 23, 2023
ae6320e
Merge branch '4844-gas-accounting' of github.com:fab-10/besu into 484…
fab-10 Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Send only hash announcement for blob transaction type [#4940](https://github.com/hyperledger/besu/pull/4940)
- Add `excess_data_gas` field to block header [#4958](https://github.com/hyperledger/besu/pull/4958)
- Add `max_fee_per_data_gas` field to transaction [#4970](https://github.com/hyperledger/besu/pull/4970)
- Gas accounting for EIP-4844 [#4992](https://github.com/hyperledger/besu/pull/4992)

### Bug Fixes
- Mitigation fix for stale bonsai code storage leading to log rolling issues on contract recreates [#4906](https://github.com/hyperledger/besu/pull/4906)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package org.hyperledger.besu.ethereum.blockcreation;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.DataGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
Expand All @@ -43,6 +45,7 @@
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.plugin.data.TransactionType;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException;

Expand Down Expand Up @@ -209,6 +212,10 @@ protected BlockCreationResult createBlock(

throwIfStopped();

final DataGas newExcessDataGas = computeExcessDataGas(transactionResults, newProtocolSpec);

throwIfStopped();

final SealableBlockHeader sealableBlockHeader =
BlockHeaderBuilder.create()
.populateFrom(processableBlockHeader)
Expand All @@ -224,6 +231,7 @@ protected BlockCreationResult createBlock(
withdrawalsCanBeProcessed
? BodyValidation.withdrawalsRoot(maybeWithdrawals.get())
: null)
.excessDataGas(newExcessDataGas)
.buildSealableBlockHeader();

final BlockHeader blockHeader = createFinalBlockHeader(sealableBlockHeader);
Expand All @@ -245,6 +253,26 @@ protected BlockCreationResult createBlock(
}
}

private DataGas computeExcessDataGas(
BlockTransactionSelector.TransactionSelectionResults transactionResults,
ProtocolSpec newProtocolSpec) {

if (newProtocolSpec.getFeeMarket().implementsDataFee()) {
final var gasCalculator = newProtocolSpec.getGasCalculator();
final int newBlobsCount =
transactionResults.getTransactionsByType(TransactionType.BLOB).stream()
.map(tx -> tx.getVersionedHashes().orElseThrow())
.mapToInt(List::size)
.sum();
// casting parent excess data gas to long since for the moment it should be well below that
// limit
return DataGas.of(
gasCalculator.computeExcessDataGas(
parentHeader.getExcessDataGas().map(DataGas::toLong).orElse(0L), newBlobsCount));
}
return null;
}

private BlockTransactionSelector.TransactionSelectionResults selectTransactions(
final ProcessableBlockHeader processableBlockHeader,
final MutableWorldState disposableWorldState,
Expand All @@ -269,7 +297,9 @@ private BlockTransactionSelector.TransactionSelectionResults selectTransactions(
minBlockOccupancyRatio,
isCancelled::get,
miningBeneficiary,
protocolSpec.getFeeMarket());
protocolSpec.getFeeMarket(),
protocolSpec.getGasCalculator(),
protocolSpec.getGasLimitCalculator());

if (transactions.isPresent()) {
return selector.evaluateTransactions(transactions.get());
Expand Down Expand Up @@ -312,13 +342,13 @@ private ProcessableBlockHeader createPendingBlockHeader(
final Optional<Bytes32> maybePrevRandao,
final ProtocolSpec protocolSpec) {
final long newBlockNumber = parentHeader.getNumber() + 1;
long gasLimit =
protocolSpec
.getGasLimitCalculator()
.nextGasLimit(
parentHeader.getGasLimit(),
targetGasLimitSupplier.get().orElse(parentHeader.getGasLimit()),
newBlockNumber);
final GasLimitCalculator gasLimitCalculator = protocolSpec.getGasLimitCalculator();

final long gasLimit =
gasLimitCalculator.nextGasLimit(
parentHeader.getGasLimit(),
targetGasLimitSupplier.get().orElse(parentHeader.getGasLimit()),
newBlockNumber);

final DifficultyCalculator difficultyCalculator = protocolSpec.getDifficultyCalculator();
final BigInteger difficulty =
Expand Down
Loading