Skip to content

Commit

Permalink
Merge branch 'hyperledger:main' into zkbesu
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuafernandes authored Feb 13, 2025
2 parents bdc6423 + c34e396 commit 3d56e87
Show file tree
Hide file tree
Showing 120 changed files with 5,458 additions and 2,455 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Breaking Changes

### Upcoming Breaking Changes
- `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge`
- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release. Use docker or none instead.
Expand All @@ -14,9 +15,11 @@
- Smart-contract-based (onchain) permissioning
- Proof of Work consensus
- Fast Sync
- Transaction indexing will be disabled by default in a future release for snap sync and checkpoint sync modes. This will break RPCs that use transaction hash for historical queries.
### Additions and Improvements
- Add TLS/mTLS options and configure the GraphQL HTTP service[#7910](https://github.com/hyperledger/besu/pull/7910)
- Allow plugins to propose transactions during block creation [#8268](https://github.com/hyperledger/besu/pull/8268)
- Update `eth_getLogs` to return a `Block not found` error when the requested block is not found. [#8290](https://github.com/hyperledger/besu/pull/8290)
### Bug fixes
- Upgrade Netty to version 4.1.118 to fix CVE-2025-24970 [#8275](https://github.com/hyperledger/besu/pull/8275)
- Add missing RPC method `debug_accountRange` to `RpcMethod.java` and implemented its handler. [#8153](https://github.com/hyperledger/besu/issues/8153)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class SynchronizerOptions implements CLIOptions<SynchronizerConfiguration
"--Xsnapsync-synchronizer-bytecode-count-per-request";
private static final String SNAP_TRIENODE_COUNT_PER_REQUEST_FLAG =
"--Xsnapsync-synchronizer-trienode-count-per-request";
private static final String SNAP_TRANSACTION_INDEXING_ENABLED_FLAG =
"--Xsnapsync-synchronizer-transaction-indexing-enabled";

private static final String SNAP_FLAT_ACCOUNT_HEALED_COUNT_PER_REQUEST_FLAG =
"--Xsnapsync-synchronizer-flat-account-healed-count-per-request";
Expand Down Expand Up @@ -319,6 +321,15 @@ public void parseBlockPropagationRange(final String arg) {
"Temporary feature toggle to enable using the new peertask system (default: ${DEFAULT-VALUE})")
private final Boolean isPeerTaskSystemEnabled = false;

@CommandLine.Option(
names = SNAP_TRANSACTION_INDEXING_ENABLED_FLAG,
hidden = true,
paramLabel = "<Boolean>",
arity = "0..1",
description = "Enable transaction indexing during snap sync. (default: ${DEFAULT-VALUE})")
private Boolean snapTransactionIndexingEnabled =
SnapSyncConfiguration.DEFAULT_SNAP_SYNC_TRANSACTION_INDEXING_ENABLED;

private SynchronizerOptions() {}

/**
Expand Down Expand Up @@ -399,6 +410,8 @@ public static SynchronizerOptions fromConfig(final SynchronizerConfiguration con
options.checkpointPostMergeSyncEnabled = config.isCheckpointPostMergeEnabled();
options.snapsyncServerEnabled = config.getSnapSyncConfiguration().isSnapServerEnabled();
options.snapsyncBftEnabled = config.getSnapSyncConfiguration().isSnapSyncBftEnabled();
options.snapTransactionIndexingEnabled =
config.getSnapSyncConfiguration().isSnapSyncTransactionIndexingEnabled();
return options;
}

Expand Down Expand Up @@ -432,6 +445,7 @@ public SynchronizerConfiguration.Builder toDomainObject() {
.localFlatStorageCountToHealPerRequest(snapsyncFlatStorageHealedCountPerRequest)
.isSnapServerEnabled(snapsyncServerEnabled)
.isSnapSyncBftEnabled(snapsyncBftEnabled)
.isSnapSyncTransactionIndexingEnabled(snapTransactionIndexingEnabled)
.build());
builder.checkpointPostMergeEnabled(checkpointPostMergeSyncEnabled);
builder.isPeerTaskSystemEnabled(isPeerTaskSystemEnabled);
Expand Down Expand Up @@ -491,7 +505,9 @@ public List<String> getCLIOptions() {
SNAP_SERVER_ENABLED_FLAG,
OptionParser.format(snapsyncServerEnabled),
SNAP_SYNC_BFT_ENABLED_FLAG,
OptionParser.format(snapsyncBftEnabled));
OptionParser.format(snapsyncBftEnabled),
SNAP_TRANSACTION_INDEXING_ENABLED_FLAG,
OptionParser.format(snapTransactionIndexingEnabled));
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected SynchronizerConfiguration.Builder createCustomizedDomainObject() {
.bytecodeCountPerRequest(
SnapSyncConfiguration.DEFAULT_BYTECODE_COUNT_PER_REQUEST + 2)
.isSnapServerEnabled(Boolean.TRUE)
.isSnapSyncTransactionIndexingEnabled(Boolean.TRUE)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
.getBlockHash()
.map(
blockHash ->
blockchain.matchingLogs(
blockHash, filter.getLogsQuery(), requestContext::isAlive))
blockchain
.getBlockHeaderByHash(blockHash)
.map(
blockHeader ->
blockchain.matchingLogs(
blockHeader.getBlockHash(),
filter.getLogsQuery(),
requestContext::isAlive))
.orElseThrow(
() ->
new InvalidJsonRpcParameters(
"Block not found", RpcErrorType.BLOCK_NOT_FOUND)))
.orElseGet(
() -> {
final long fromBlockNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"response": {
"jsonrpc": "2.0",
"id": 406,
"result" : [ ]
"error" : {
"code": -32000,
"message": "Block not found"
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,20 @@ public void setBlockChoiceRule(final Comparator<BlockHeader> blockChoiceRule) {
@Override
public synchronized void appendBlock(final Block block, final List<TransactionReceipt> receipts) {
if (numberOfBlocksToCache != 0) cacheBlockData(block, receipts);
appendBlockHelper(new BlockWithReceipts(block, receipts), false);
appendBlockHelper(new BlockWithReceipts(block, receipts), false, true);
}

@Override
public synchronized void appendBlockWithoutIndexingTransactions(
final Block block, final List<TransactionReceipt> receipts) {
if (numberOfBlocksToCache != 0) cacheBlockData(block, receipts);
appendBlockHelper(new BlockWithReceipts(block, receipts), false, false);
}

@Override
public synchronized void storeBlock(final Block block, final List<TransactionReceipt> receipts) {
if (numberOfBlocksToCache != 0) cacheBlockData(block, receipts);
appendBlockHelper(new BlockWithReceipts(block, receipts), true);
appendBlockHelper(new BlockWithReceipts(block, receipts), true, true);
}

private void cacheBlockData(final Block block, final List<TransactionReceipt> receipts) {
Expand All @@ -447,7 +454,9 @@ private boolean blockShouldBeProcessed(
}

private void appendBlockHelper(
final BlockWithReceipts blockWithReceipts, final boolean storeOnly) {
final BlockWithReceipts blockWithReceipts,
final boolean storeOnly,
final boolean transactionIndexing) {

if (!blockShouldBeProcessed(blockWithReceipts.getBlock(), blockWithReceipts.getReceipts())) {
return;
Expand All @@ -469,7 +478,7 @@ private void appendBlockHelper(
if (storeOnly) {
blockAddedEvent = handleStoreOnly(blockWithReceipts);
} else {
blockAddedEvent = updateCanonicalChainData(updater, blockWithReceipts);
blockAddedEvent = updateCanonicalChainData(updater, blockWithReceipts, transactionIndexing);
if (blockAddedEvent.isNewCanonicalHead()) {
updateCacheForNewCanonicalHead(block, td);
}
Expand Down Expand Up @@ -521,7 +530,9 @@ public Difficulty calculateTotalDifficulty(final BlockHeader blockHeader) {
}

private BlockAddedEvent updateCanonicalChainData(
final BlockchainStorage.Updater updater, final BlockWithReceipts blockWithReceipts) {
final Updater updater,
final BlockWithReceipts blockWithReceipts,
final boolean transactionIndexing) {

final Block newBlock = blockWithReceipts.getBlock();
final Hash chainHead = blockchainStorage.getChainHead().orElse(null);
Expand All @@ -532,7 +543,7 @@ private BlockAddedEvent updateCanonicalChainData(

try {
if (newBlock.getHeader().getParentHash().equals(chainHead) || chainHead == null) {
return handleNewHead(updater, blockWithReceipts);
return handleNewHead(updater, blockWithReceipts, transactionIndexing);
} else if (blockChoiceRule.compare(newBlock.getHeader(), chainHeader) > 0) {
// New block represents a chain reorganization
return handleChainReorg(updater, blockWithReceipts);
Expand All @@ -553,14 +564,18 @@ private BlockAddedEvent handleStoreOnly(final BlockWithReceipts blockWithReceipt
}

private BlockAddedEvent handleNewHead(
final Updater updater, final BlockWithReceipts blockWithReceipts) {
final Updater updater,
final BlockWithReceipts blockWithReceipts,
final boolean transactionIndexing) {
// This block advances the chain, update the chain head
final Hash newBlockHash = blockWithReceipts.getHash();

updater.putBlockHash(blockWithReceipts.getNumber(), newBlockHash);
updater.setChainHead(newBlockHash);
indexTransactionsForBlock(
updater, newBlockHash, blockWithReceipts.getBlock().getBody().getTransactions());
if (transactionIndexing) {
indexTransactionsForBlock(
updater, newBlockHash, blockWithReceipts.getBlock().getBody().getTransactions());
}
gasUsedCounter.inc(blockWithReceipts.getHeader().getGasUsed());
numberOfTransactionsCounter.inc(
blockWithReceipts.getBlock().getBody().getTransactions().size());
Expand Down Expand Up @@ -745,7 +760,7 @@ public boolean forwardToBlock(final BlockHeader blockHeader) {
try {
final BlockWithReceipts blockWithReceipts = getBlockWithReceipts(blockHeader).get();

BlockAddedEvent newHeadEvent = handleNewHead(updater, blockWithReceipts);
BlockAddedEvent newHeadEvent = handleNewHead(updater, blockWithReceipts, true);
updateCacheForNewCanonicalHead(
blockWithReceipts.getBlock(), calculateTotalDifficulty(blockHeader));
updater.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public interface MutableBlockchain extends Blockchain {
*/
void appendBlock(Block block, List<TransactionReceipt> receipts);

/**
* Adds a block to the blockchain without indexing transactions.
*
* <p>Block must be connected to the existing blockchain (its parent must already be stored),
* otherwise an {@link IllegalArgumentException} is thrown. Blocks representing forks are allowed
* as long as they are connected.
*
* @param block The block to append.
* @param receipts The list of receipts associated with this block's transactions.
*/
void appendBlockWithoutIndexingTransactions(Block block, List<TransactionReceipt> receipts);

/**
* Adds a block to the blockchain, without updating the chain state.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ BlockImportResult importBlock(
* @param receipts The receipts associated with this block.
* @param headerValidationMode Determines the validation to perform on this header.
* @param ommerValidationMode Determines the validation to perform on ommer headers.
* @param bodyValidationMode Determines the validation to perform on the block's body.
* @param importWithTxIndexing Whether to import the block with transaction indexing.
* @return {@code BlockImportResult}
* @see BlockImportResult
*/
Expand All @@ -80,5 +82,6 @@ BlockImportResult importBlockForSyncing(
List<TransactionReceipt> receipts,
HeaderValidationMode headerValidationMode,
HeaderValidationMode ommerValidationMode,
BodyValidationMode bodyValidationMode);
BodyValidationMode bodyValidationMode,
boolean importWithTxIndexing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;

public class CancunTargetingGasLimitCalculator extends LondonTargetingGasLimitCalculator {

Expand All @@ -25,19 +25,23 @@ public class CancunTargetingGasLimitCalculator extends LondonTargetingGasLimitCa
private final long maxBlobGasPerBlock;

public CancunTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket) {
this(londonForkBlock, feeMarket, DEFAULT_MAX_BLOBS_PER_BLOCK_CANCUN);
final long londonForkBlock,
final BaseFeeMarket feeMarket,
final GasCalculator gasCalculator) {
this(londonForkBlock, feeMarket, gasCalculator, DEFAULT_MAX_BLOBS_PER_BLOCK_CANCUN);
}

/**
* Using Cancun mainnet default of 6 blobs for maxBlobsPerBlock: getBlobGasPerBlob() * 6 blobs =
* 131072 * 6 = 786432 = 0xC0000
*/
public CancunTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket, final int maxBlobsPerBlock) {
final long londonForkBlock,
final BaseFeeMarket feeMarket,
final GasCalculator gasCalculator,
final int maxBlobsPerBlock) {
super(londonForkBlock, feeMarket);
final CancunGasCalculator cancunGasCalculator = new CancunGasCalculator();
this.maxBlobGasPerBlock = cancunGasCalculator.getBlobGasPerBlob() * maxBlobsPerBlock;
this.maxBlobGasPerBlock = gasCalculator.getBlobGasPerBlob() * maxBlobsPerBlock;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ public BlockImportResult importBlockForSyncing(
final List<TransactionReceipt> receipts,
final HeaderValidationMode headerValidationMode,
final HeaderValidationMode ommerValidationMode,
final BodyValidationMode bodyValidationMode) {
final BodyValidationMode bodyValidationMode,
final boolean importWithTxIndexing) {

if (blockValidator.validateBlockForSyncing(
context, block, receipts, headerValidationMode, ommerValidationMode, bodyValidationMode)) {
context.getBlockchain().appendBlock(block, receipts);
if (importWithTxIndexing) {
context.getBlockchain().appendBlock(block, receipts);
} else {
context.getBlockchain().appendBlockWithoutIndexingTransactions(block, receipts);
}
return new BlockImportResult(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,10 @@ static ProtocolSpecBuilder cancunDefinition(
.gasLimitCalculatorBuilder(
feeMarket ->
new CancunTargetingGasLimitCalculator(
londonForkBlockNumber, (BaseFeeMarket) feeMarket, cancunBlobSchedule.getMax()))
londonForkBlockNumber,
(BaseFeeMarket) feeMarket,
cancunGasCalcSupplier.get(),
cancunBlobSchedule.getMax()))
// EVM changes to support EIP-1153: TSTORE and EIP-5656: MCOPY
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
Expand Down Expand Up @@ -854,7 +857,10 @@ static ProtocolSpecBuilder pragueDefinition(
.gasLimitCalculatorBuilder(
feeMarket ->
new PragueTargetingGasLimitCalculator(
londonForkBlockNumber, (BaseFeeMarket) feeMarket, pragueBlobSchedule.getMax()))
londonForkBlockNumber,
(BaseFeeMarket) feeMarket,
pragueGasCalcSupplier.get(),
pragueBlobSchedule.getMax()))
// EIP-3074 AUTH and AUTHCALL
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
Expand Down Expand Up @@ -950,7 +956,10 @@ private static ProtocolSpecBuilder addEOF(
.gasLimitCalculatorBuilder(
feeMarket ->
new OsakaTargetingGasLimitCalculator(
londonForkBlockNumber, (BaseFeeMarket) feeMarket, maxBlobsPerBlock))
londonForkBlockNumber,
(BaseFeeMarket) feeMarket,
osakaGasCalcSupplier.get(),
maxBlobsPerBlock))
// EIP-7692 EOF v1 EVM and opcodes
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public TransactionProcessingResult processTransaction(
}
}

// TODO SLD are the log correct following EIP-7623?
if (LOG.isTraceEnabled()) {
LOG.trace(
"Gas used by transaction: {}, by message call/contract creation: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;

public class OsakaTargetingGasLimitCalculator extends PragueTargetingGasLimitCalculator {

/** The mainnet default maximum number of blobs per block for Osaka */
private static final int DEFAULT_MAX_BLOBS_PER_BLOCK_OSAKA = 12;

public OsakaTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket) {
super(londonForkBlock, feeMarket, DEFAULT_MAX_BLOBS_PER_BLOCK_OSAKA);
final long londonForkBlock,
final BaseFeeMarket feeMarket,
final GasCalculator gasCalculator) {
super(londonForkBlock, feeMarket, gasCalculator, DEFAULT_MAX_BLOBS_PER_BLOCK_OSAKA);
}

/**
* Using Osaka mainnet default of 12 blobs for maxBlobsPerBlock:
* CancunGasCalculator.BLOB_GAS_PER_BLOB * 12 blobs = 131072 * 12 = 1572864 = 0x180000
*/
public OsakaTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket, final int maxBlobsPerBlock) {
super(londonForkBlock, feeMarket, maxBlobsPerBlock);
final long londonForkBlock,
final BaseFeeMarket feeMarket,
final GasCalculator gasCalculator,
final int maxBlobsPerBlock) {
super(londonForkBlock, feeMarket, gasCalculator, maxBlobsPerBlock);
}
}
Loading

0 comments on commit 3d56e87

Please sign in to comment.