Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hyperledger/besu into use-retry-swi…
Browse files Browse the repository at this point in the history
…tching-peer
  • Loading branch information
pinges committed Dec 15, 2023
2 parents 24a96a5 + a099137 commit c26fea6
Show file tree
Hide file tree
Showing 143 changed files with 800 additions and 738 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212)
- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211)
- Set Ethereum Classic mainnet activation block for Spiral network upgrade [#6267](https://github.com/hyperledger/besu/pull/6267)
- Add custom genesis file name to config overview if specified [#6297](https://github.com/hyperledger/besu/pull/6297)

### Bug fixes

Expand Down
2 changes: 0 additions & 2 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ dependencies {
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'tech.pegasys.discovery:discovery'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
annotationProcessor 'com.google.dagger:dagger-compiler'
}
5 changes: 4 additions & 1 deletion besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder;
import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.evm.precompile.AbstractAltBnPrecompiledContract;
import org.hyperledger.besu.evm.precompile.BigIntegerModularExponentiationPrecompiledContract;
import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract;
Expand Down Expand Up @@ -3526,6 +3526,9 @@ private String generateConfigurationOverview() {
}

builder.setHasCustomGenesis(genesisFile != null);
if (genesisFile != null) {
builder.setCustomGenesis(genesisFile.getAbsolutePath());
}
builder.setNetworkId(ethNetworkConfig.getNetworkId());

builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ConfigurationOverviewBuilder {
private String network;
private BigInteger networkId;
private boolean hasCustomGenesis;
private String customGenesisFileName;
private String dataStorage;
private String syncMode;
private Integer rpcPort;
Expand Down Expand Up @@ -98,6 +99,17 @@ public ConfigurationOverviewBuilder setHasCustomGenesis(final boolean hasCustomG
return this;
}

/**
* Sets location of custom genesis file specified.
*
* @param customGenesisFileName the filename of the custom genesis file, only set if specified
* @return the builder
*/
public ConfigurationOverviewBuilder setCustomGenesis(final String customGenesisFileName) {
this.customGenesisFileName = customGenesisFileName;
return this;
}

/**
* Sets data storage.
*
Expand Down Expand Up @@ -269,7 +281,9 @@ public String build() {
}

if (hasCustomGenesis) {
lines.add("Network: Custom genesis file specified");
lines.add("Network: Custom genesis file");
lines.add(
customGenesisFileName == null ? "Custom genesis file is null" : customGenesisFileName);
}

if (networkId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.hyperledger.besu.ethereum.api.query.StateBackupService.BackupStatus;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive;
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

Expand Down Expand Up @@ -82,7 +82,7 @@ public void run() {
final BesuController besuController = createBesuController();
final MutableBlockchain blockchain = besuController.getProtocolContext().getBlockchain();
final WorldStateStorage worldStateStorage =
((DefaultWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
.getWorldStateStorage();
final EthScheduler scheduler = new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.hyperledger.besu.ethereum.trie.Node;
import org.hyperledger.besu.ethereum.trie.PersistVisitor;
import org.hyperledger.besu.ethereum.trie.RestoreVisitor;
import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive;
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.util.io.RollingFileReader;
Expand Down Expand Up @@ -250,7 +250,7 @@ private void newWorldStateUpdater() {
updater.commit();
}
final WorldStateStorage worldStateStorage =
((DefaultWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
((ForestWorldStateArchive) besuController.getProtocolContext().getWorldStateArchive())
.getWorldStateStorage();
updater = worldStateStorage.updater();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.hyperledger.besu.components;

import org.hyperledger.besu.cli.BesuCommand;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoaderModule;
import org.hyperledger.besu.ethereum.eth.transactions.BlobCache;
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoaderModule;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.services.BesuPluginContextImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods;
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateProvider;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.BlockchainStorage;
import org.hyperledger.besu.ethereum.chain.ChainDataPruner;
Expand Down Expand Up @@ -84,12 +80,16 @@
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider;
import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogPruner;
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive;
import org.hyperledger.besu.ethereum.trie.forest.pruner.MarkSweepPruner;
import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner;
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.MarkSweepPruner;
import org.hyperledger.besu.ethereum.worldstate.Pruner;
import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
Expand Down Expand Up @@ -657,7 +657,7 @@ public BesuController build() {
Optional.of(
new Pruner(
new MarkSweepPruner(
((DefaultWorldStateArchive) worldStateArchive).getWorldStateStorage(),
((ForestWorldStateArchive) worldStateArchive).getWorldStateStorage(),
blockchain,
storageProvider.getStorageBySegmentIdentifier(
KeyValueSegmentIdentifier.PRUNING_STATE),
Expand Down Expand Up @@ -1093,7 +1093,7 @@ yield new BonsaiWorldStateProvider(
case FOREST -> {
final WorldStatePreimageStorage preimageStorage =
storageProvider.createWorldStatePreimageStorage();
yield new DefaultWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration);
yield new ForestWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.trie.forest.pruner.Pruner;
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.Pruner;
import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,30 @@
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.junit.jupiter.MockitoExtension;

/** Tests for {@link BlockExporter}. */
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public final class RlpBlockExporterTest {

@ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
@TempDir public static Path folder;
private static Blockchain blockchain;
private static long chainHead;
private static ProtocolSchedule protocolSchedule;

@BeforeClass
@BeforeAll
public static void setupBlockchain() throws IOException {
final BesuController controller = createController();
final Path blocks = folder.newFile("1000.blocks").toPath();
final BesuController controller =
createController(Files.createTempDirectory(folder, "rlpBlockExporterTestData"));
final Path blocks = Files.createTempFile(folder, "1000", "blocks");
BlockTestUtil.write1000Blocks(blocks);
blockchain = importBlocks(controller, blocks);
chainHead = blockchain.getChainHeadBlockNumber();
Expand All @@ -83,8 +84,7 @@ private static Blockchain importBlocks(final BesuController controller, final Pa
return controller.getProtocolContext().getBlockchain();
}

private static BesuController createController() throws IOException {
final Path dataDir = folder.newFolder().toPath();
private static BesuController createController(final @TempDir Path dataDir) throws IOException {
return new BesuController.Builder()
.fromGenesisConfig(GenesisConfigFile.mainnet(), SyncMode.FAST)
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
Expand All @@ -105,13 +105,13 @@ private static BesuController createController() throws IOException {
}

@Test
public void exportBlocks_noBounds() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_noBounds(final @TempDir Path outputDir) throws IOException {
final Path outputPath = outputDir.resolve("output");
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);
exporter.exportBlocks(outputPath, Optional.empty(), Optional.empty());
exporter.exportBlocks(outputPath.toFile(), Optional.empty(), Optional.empty());

// Iterate over blocks and check that they match expectations
final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath());
final RawBlockIterator blockIterator = getBlockIterator(outputPath);
long currentBlockNumber = 0;
while (blockIterator.hasNext()) {
final Block actual = blockIterator.next();
Expand All @@ -125,15 +125,15 @@ public void exportBlocks_noBounds() throws IOException {
}

@Test
public void exportBlocks_withLowerBound() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_withLowerBound(final @TempDir Path outputDir) throws IOException {
final Path outputPath = outputDir.resolve("output");
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = 990;
exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.empty());
exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.empty());

// Iterate over blocks and check that they match expectations
final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath());
final RawBlockIterator blockIterator = getBlockIterator(outputPath);
long currentBlockNumber = lowerBound;
while (blockIterator.hasNext()) {
final Block actual = blockIterator.next();
Expand All @@ -147,15 +147,15 @@ public void exportBlocks_withLowerBound() throws IOException {
}

@Test
public void exportBlocks_withUpperBound() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_withUpperBound(final @TempDir Path outputDir) throws IOException {
final Path outputPath = outputDir.resolve("output");
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long upperBound = 10;
exporter.exportBlocks(outputPath, Optional.empty(), Optional.of(upperBound));
exporter.exportBlocks(outputPath.toFile(), Optional.empty(), Optional.of(upperBound));

// Iterate over blocks and check that they match expectations
final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath());
final RawBlockIterator blockIterator = getBlockIterator(outputPath);
long currentBlockNumber = 0;
while (blockIterator.hasNext()) {
final Block actual = blockIterator.next();
Expand All @@ -169,16 +169,17 @@ public void exportBlocks_withUpperBound() throws IOException {
}

@Test
public void exportBlocks_withUpperAndLowerBounds() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_withUpperAndLowerBounds(final @TempDir Path outputDir)
throws IOException {
final Path outputPath = outputDir.resolve("output");
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = 5;
final long upperBound = 10;
exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.of(upperBound));
exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.of(upperBound));

// Iterate over blocks and check that they match expectations
final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath());
final RawBlockIterator blockIterator = getBlockIterator(outputPath);
long currentBlockNumber = lowerBound;
while (blockIterator.hasNext()) {
final Block actual = blockIterator.next();
Expand All @@ -192,16 +193,17 @@ public void exportBlocks_withUpperAndLowerBounds() throws IOException {
}

@Test
public void exportBlocks_withRangeBeyondChainHead() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_withRangeBeyondChainHead(final @TempDir Path outputDir)
throws IOException {
final Path outputPath = outputDir.resolve("output");
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

final long lowerBound = chainHead - 10;
final long upperBound = chainHead + 10;
exporter.exportBlocks(outputPath, Optional.of(lowerBound), Optional.of(upperBound));
exporter.exportBlocks(outputPath.toFile(), Optional.of(lowerBound), Optional.of(upperBound));

// Iterate over blocks and check that they match expectations
final RawBlockIterator blockIterator = getBlockIterator(outputPath.toPath());
final RawBlockIterator blockIterator = getBlockIterator(outputPath);
long currentBlockNumber = lowerBound;
while (blockIterator.hasNext()) {
final Block actual = blockIterator.next();
Expand All @@ -215,8 +217,7 @@ public void exportBlocks_withRangeBeyondChainHead() throws IOException {
}

@Test
public void exportBlocks_negativeStartNumber() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_negativeStartNumber(final @TempDir File outputPath) throws IOException {
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(-1L), Optional.empty()))
Expand All @@ -225,8 +226,7 @@ public void exportBlocks_negativeStartNumber() throws IOException {
}

@Test
public void exportBlocks_negativeEndNumber() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_negativeEndNumber(final @TempDir File outputPath) throws IOException {
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.empty(), Optional.of(-1L)))
Expand All @@ -235,8 +235,7 @@ public void exportBlocks_negativeEndNumber() throws IOException {
}

@Test
public void exportBlocks_outOfOrderBounds() throws IOException {
final File outputPath = folder.newFile();
public void exportBlocks_outOfOrderBounds(final @TempDir File outputPath) throws IOException {
final RlpBlockExporter exporter = new RlpBlockExporter(blockchain);

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(10L), Optional.of(2L)))
Expand Down
Loading

0 comments on commit c26fea6

Please sign in to comment.