Add eth protocol manager test builder (#7954)

* 7311: Add EthProtocolManagerTestBuilder

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add EthProtocolManagerTestBuilder.builder method

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Replace EthProtocolManagerTestUtil.create() usages with builder

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Replace EthProtocolManagerTestUtil.create(TimeoutPolicy)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Replace EthProtocolManagerTestUtil.create(Blockchain)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Replace EthProtocolManagerTestUtil.create(EthScheduler)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, TimeoutPolicy, WorldStateArchive, TransactionPool, EthProtocolConfiguration)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, EthScheduler)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, EthScheduler)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, WorldStateArchive, TransactionPool, EthProtocolConfiguration)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, EthScheduler, WorldStateArchive, TransactionPool, EthProtocolConfiguration)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Replace EthProtocolManagerTestUtil.create(ProtocolSchedule, Blockchain, EthScheduler, WorldStateArchive, TransactionPool, EthProtocolConfiguration)

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Remove remaining create methods and apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7871/merge
Matilda-Clerke 2 days ago committed by GitHub
parent c320724d29
commit 747a378017
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java
  2. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java
  3. 396
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java
  4. 245
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java
  5. 278
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java
  6. 20
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java
  7. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeerTaskTest.java
  8. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeersTaskTest.java
  9. 15
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java
  10. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/DaoForkPeerValidatorTest.java
  11. 9
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/PeerValidatorRunnerTest.java
  12. 10
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/RequiredBlocksPeerValidatorTest.java
  13. 14
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java
  14. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java
  15. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStepTest.java
  16. 17
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java
  17. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java
  18. 5
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java
  19. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java
  20. 10
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java
  21. 17
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java
  22. 18
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java
  23. 10
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java
  24. 17
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java
  25. 17
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java
  26. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java
  27. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java
  28. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java
  29. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java
  30. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java
  31. 16
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java
  32. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java
  33. 14
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java
  34. 14
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  35. 8
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTaskTest.java
  36. 8
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java

@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -94,12 +95,14 @@ public class WorldStateDownloaderBenchmark {
tempDir = Files.createTempDir().toPath(); tempDir = Files.createTempDir().toPath();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
new EthScheduler( .setEthScheduler(
syncConfig.getDownloaderParallelism(), new EthScheduler(
syncConfig.getTransactionsParallelism(), syncConfig.getDownloaderParallelism(),
syncConfig.getComputationParallelism(), syncConfig.getTransactionsParallelism(),
metricsSystem)); syncConfig.getComputationParallelism(),
metricsSystem))
.build();
peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber()); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber());

@ -58,7 +58,7 @@ public class EthPeersTest {
@BeforeEach @BeforeEach
public void setup() throws Exception { public void setup() throws Exception {
when(peerRequest.sendRequest(any())).thenReturn(responseStream); when(peerRequest.sendRequest(any())).thenReturn(responseStream);
ethProtocolManager = EthProtocolManagerTestUtil.create(); ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
ethPeers = ethProtocolManager.ethContext().getEthPeers(); ethPeers = ethProtocolManager.ethContext().getEthPeers();
final ChainHeadTracker mock = mock(ChainHeadTracker.class); final ChainHeadTracker mock = mock(ChainHeadTracker.class);
final BlockHeader blockHeader = mock(BlockHeader.class); final BlockHeader blockHeader = mock(BlockHeader.class);

@ -77,6 +77,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.testutil.TestClock;
import java.math.BigInteger; import java.math.BigInteger;
@ -132,13 +133,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void handleMalformedRequestIdMessage() { public void handleMalformedRequestIdMessage() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// this is a non-request id message, but we'll be processing it with eth66, make sure we // this is a non-request id message, but we'll be processing it with eth66, make sure we
// disconnect the peer gracefully // disconnect the peer gracefully
final MessageData messageData = GetBlockHeadersMessage.create(1, 1, 0, false); final MessageData messageData = GetBlockHeadersMessage.create(1, 1, 0, false);
@ -151,13 +153,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void disconnectOnUnsolicitedMessage() { public void disconnectOnUnsolicitedMessage() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = final MessageData messageData =
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get()));
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {});
@ -169,13 +172,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void disconnectOnFailureToSendStatusMessage() { public void disconnectOnFailureToSendStatusMessage() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = final MessageData messageData =
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get()));
final MockPeerConnection peer = final MockPeerConnection peer =
@ -188,13 +192,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void disconnectOnWrongChainId() { public void disconnectOnWrongChainId() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = final MessageData messageData =
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get()));
final MockPeerConnection peer = final MockPeerConnection peer =
@ -219,13 +224,14 @@ public final class EthProtocolManagerTest {
public void disconnectNewPoWPeers() { public void disconnectNewPoWPeers() {
final MergePeerFilter mergePeerFilter = new MergePeerFilter(); final MergePeerFilter mergePeerFilter = new MergePeerFilter();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig(), .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
Optional.of(mergePeerFilter))) { .setMergePeerFilter(Optional.of(mergePeerFilter))
.build()) {
final MockPeerConnection workPeer = setupPeer(ethManager, (cap, msg, conn) -> {}); final MockPeerConnection workPeer = setupPeer(ethManager, (cap, msg, conn) -> {});
final MockPeerConnection stakePeer = setupPeer(ethManager, (cap, msg, conn) -> {}); final MockPeerConnection stakePeer = setupPeer(ethManager, (cap, msg, conn) -> {});
@ -267,13 +273,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void doNotDisconnectOnLargeMessageWithinLimits() { public void doNotDisconnectOnLargeMessageWithinLimits() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = mock(MessageData.class); final MessageData messageData = mock(MessageData.class);
when(messageData.getSize()).thenReturn(EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE); when(messageData.getSize()).thenReturn(EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE);
when(messageData.getCode()).thenReturn(EthPV62.TRANSACTIONS); when(messageData.getCode()).thenReturn(EthPV62.TRANSACTIONS);
@ -287,13 +294,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void disconnectOnWrongGenesisHash() { public void disconnectOnWrongGenesisHash() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = final MessageData messageData =
BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get()));
final MockPeerConnection peer = final MockPeerConnection peer =
@ -317,13 +325,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void doNotDisconnectOnValidMessage() { public void doNotDisconnectOnValidMessage() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final MessageData messageData = final MessageData messageData =
GetBlockBodiesMessage.create(Collections.singletonList(gen.hash())); GetBlockBodiesMessage.create(Collections.singletonList(gen.hash()));
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {});
@ -339,13 +348,14 @@ public final class EthProtocolManagerTest {
public void respondToGetHeaders() throws ExecutionException, InterruptedException { public void respondToGetHeaders() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long startBlock = 5L; final long startBlock = 5L;
final int blockCount = 5; final int blockCount = 5;
final MessageData messageData = final MessageData messageData =
@ -379,13 +389,14 @@ public final class EthProtocolManagerTest {
final EthProtocolConfiguration config = final EthProtocolConfiguration config =
EthProtocolConfiguration.builder().maxGetBlockHeaders(limit).build(); EthProtocolConfiguration.builder().maxGetBlockHeaders(limit).build();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
config)) { .setEthereumWireProtocolConfiguration(config)
.build()) {
final long startBlock = 5L; final long startBlock = 5L;
final int blockCount = 10; final int blockCount = 10;
final MessageData messageData = final MessageData messageData =
@ -416,13 +427,14 @@ public final class EthProtocolManagerTest {
public void respondToGetHeadersReversed() throws ExecutionException, InterruptedException { public void respondToGetHeadersReversed() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long endBlock = 10L; final long endBlock = 10L;
final int blockCount = 5; final int blockCount = 5;
@ -453,13 +465,14 @@ public final class EthProtocolManagerTest {
public void respondToGetHeadersWithSkip() throws ExecutionException, InterruptedException { public void respondToGetHeadersWithSkip() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long startBlock = 5L; final long startBlock = 5L;
final int blockCount = 5; final int blockCount = 5;
@ -493,13 +506,14 @@ public final class EthProtocolManagerTest {
throws ExecutionException, InterruptedException { throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long endBlock = 10L; final long endBlock = 10L;
final int blockCount = 5; final int blockCount = 5;
@ -557,13 +571,14 @@ public final class EthProtocolManagerTest {
public void respondToGetHeadersPartial() throws ExecutionException, InterruptedException { public void respondToGetHeadersPartial() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long startBlock = blockchain.getChainHeadBlockNumber() - 1L; final long startBlock = blockchain.getChainHeadBlockNumber() - 1L;
final int blockCount = 5; final int blockCount = 5;
@ -595,13 +610,14 @@ public final class EthProtocolManagerTest {
public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedException { public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long startBlock = blockchain.getChainHeadBlockNumber() + 1; final long startBlock = blockchain.getChainHeadBlockNumber() + 1;
final int blockCount = 5; final int blockCount = 5;
@ -630,13 +646,14 @@ public final class EthProtocolManagerTest {
public void respondToGetBodies() throws ExecutionException, InterruptedException { public void respondToGetBodies() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Setup blocks query // Setup blocks query
final long startBlock = blockchain.getChainHeadBlockNumber() - 5; final long startBlock = blockchain.getChainHeadBlockNumber() - 5;
@ -683,13 +700,14 @@ public final class EthProtocolManagerTest {
final EthProtocolConfiguration config = final EthProtocolConfiguration config =
EthProtocolConfiguration.builder().maxGetBlockBodies(limit).build(); EthProtocolConfiguration.builder().maxGetBlockBodies(limit).build();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
config)) { .setEthereumWireProtocolConfiguration(config)
.build()) {
// Setup blocks query // Setup blocks query
final int blockCount = 10; final int blockCount = 10;
final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount;
@ -732,13 +750,14 @@ public final class EthProtocolManagerTest {
public void respondToGetBodiesPartial() throws ExecutionException, InterruptedException { public void respondToGetBodiesPartial() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Setup blocks query // Setup blocks query
final long expectedBlockNumber = blockchain.getChainHeadBlockNumber() - 1; final long expectedBlockNumber = blockchain.getChainHeadBlockNumber() - 1;
final BlockHeader header = blockchain.getBlockHeader(expectedBlockNumber).get(); final BlockHeader header = blockchain.getBlockHeader(expectedBlockNumber).get();
@ -775,13 +794,14 @@ public final class EthProtocolManagerTest {
public void respondToGetReceipts() throws ExecutionException, InterruptedException { public void respondToGetReceipts() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Setup blocks query // Setup blocks query
final long startBlock = blockchain.getChainHeadBlockNumber() - 5; final long startBlock = blockchain.getChainHeadBlockNumber() - 5;
final int blockCount = 2; final int blockCount = 2;
@ -826,13 +846,14 @@ public final class EthProtocolManagerTest {
final EthProtocolConfiguration config = final EthProtocolConfiguration config =
EthProtocolConfiguration.builder().maxGetReceipts(limit).build(); EthProtocolConfiguration.builder().maxGetReceipts(limit).build();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
config)) { .setEthereumWireProtocolConfiguration(config)
.build()) {
// Setup blocks query // Setup blocks query
final int blockCount = 10; final int blockCount = 10;
final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount;
@ -874,13 +895,14 @@ public final class EthProtocolManagerTest {
public void respondToGetReceiptsPartial() throws ExecutionException, InterruptedException { public void respondToGetReceiptsPartial() throws ExecutionException, InterruptedException {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Setup blocks query // Setup blocks query
final long blockNumber = blockchain.getChainHeadBlockNumber() - 5; final long blockNumber = blockchain.getChainHeadBlockNumber() - 5;
final BlockHeader header = blockchain.getBlockHeader(blockNumber).get(); final BlockHeader header = blockchain.getBlockHeader(blockNumber).get();
@ -919,13 +941,14 @@ public final class EthProtocolManagerTest {
final WorldStateArchive worldStateArchive = protocolContext.getWorldStateArchive(); final WorldStateArchive worldStateArchive = protocolContext.getWorldStateArchive();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Setup node data query // Setup node data query
final List<Bytes> expectedResults = new ArrayList<>(); final List<Bytes> expectedResults = new ArrayList<>();
@ -967,13 +990,14 @@ public final class EthProtocolManagerTest {
@Test @Test
public void newBlockMinedSendsNewBlockMessageToAllPeers() { public void newBlockMinedSendsNewBlockMessageToAllPeers() {
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Define handler to validate response // Define handler to validate response
final PeerSendHandler onSend = mock(PeerSendHandler.class); final PeerSendHandler onSend = mock(PeerSendHandler.class);
final List<PeerConnection> peers = Lists.newArrayList(); final List<PeerConnection> peers = Lists.newArrayList();
@ -1038,13 +1062,14 @@ public final class EthProtocolManagerTest {
final CompletableFuture<Void> done = new CompletableFuture<>(); final CompletableFuture<Void> done = new CompletableFuture<>();
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
final long startBlock = 1L; final long startBlock = 1L;
final int requestedBlockCount = 13; final int requestedBlockCount = 13;
@ -1105,13 +1130,14 @@ public final class EthProtocolManagerTest {
final TransactionsMessage transactionMessage = TransactionsMessage.readFrom(raw); final TransactionsMessage transactionMessage = TransactionsMessage.readFrom(raw);
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
ethScheduler, .setEthScheduler(ethScheduler)
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig())) { .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build()) {
// Create a transaction pool. This has a side effect of registering a listener for the // Create a transaction pool. This has a side effect of registering a listener for the
// transactions message. // transactions message.
TransactionPoolFactory.createTransactionPool( TransactionPoolFactory.createTransactionPool(
@ -1141,15 +1167,17 @@ public final class EthProtocolManagerTest {
public void forkIdForChainHeadLegacyNoForksNotEmpty() { public void forkIdForChainHeadLegacyNoForksNotEmpty() {
final EthScheduler ethScheduler = mock(EthScheduler.class); final EthScheduler ethScheduler = mock(EthScheduler.class);
try (final EthProtocolManager ethManager = try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
ethScheduler, .setEthScheduler(ethScheduler)
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig(), .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
new ForkIdManager( .setForkIdManager(
blockchain, Collections.emptyList(), Collections.emptyList(), true))) { new ForkIdManager(
blockchain, Collections.emptyList(), Collections.emptyList(), true))
.build()) {
assertThat(ethManager.getForkIdAsBytesList()).isNotEmpty(); assertThat(ethManager.getForkIdAsBytesList()).isNotEmpty();
final CRC32 genesisHashCRC = new CRC32(); final CRC32 genesisHashCRC = new CRC32();

@ -0,0 +1,245 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.eth.manager;
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain;
import static org.mockito.Mockito.mock;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.forkid.ForkIdManager;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.testutil.TestClock;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
public class EthProtocolManagerTestBuilder {
private static final BigInteger DEFAULT_NETWORK_ID = BigInteger.ONE;
private static final ProtocolSchedule DEFAULT_PROTOCOL_SCHEDULE = ProtocolScheduleFixture.MAINNET;
private ProtocolSchedule protocolSchedule;
private GenesisConfigFile genesisConfigFile;
private GenesisState genesisState;
private Blockchain blockchain;
private BigInteger networkId;
private WorldStateArchive worldStateArchive;
private TransactionPool transactionPool;
private EthProtocolConfiguration ethereumWireProtocolConfiguration;
private ForkIdManager forkIdManager;
private EthPeers ethPeers;
private EthMessages ethMessages;
private EthMessages snapMessages;
private EthScheduler ethScheduler;
private EthContext ethContext;
private List<PeerValidator> peerValidators;
private Optional<MergePeerFilter> mergePeerFilter;
private SynchronizerConfiguration synchronizerConfiguration;
public static EthProtocolManagerTestBuilder builder() {
return new EthProtocolManagerTestBuilder();
}
public EthProtocolManagerTestBuilder setProtocolSchedule(
final ProtocolSchedule protocolSchedule) {
this.protocolSchedule = protocolSchedule;
return this;
}
public EthProtocolManagerTestBuilder setGenesisConfigFile(
final GenesisConfigFile genesisConfigFile) {
this.genesisConfigFile = genesisConfigFile;
return this;
}
public EthProtocolManagerTestBuilder setGenesisState(final GenesisState genesisState) {
this.genesisState = genesisState;
return this;
}
public EthProtocolManagerTestBuilder setBlockchain(final Blockchain blockchain) {
this.blockchain = blockchain;
return this;
}
public EthProtocolManagerTestBuilder setNetworkId(final BigInteger networkId) {
this.networkId = networkId;
return this;
}
public EthProtocolManagerTestBuilder setWorldStateArchive(
final WorldStateArchive worldStateArchive) {
this.worldStateArchive = worldStateArchive;
return this;
}
public EthProtocolManagerTestBuilder setTransactionPool(final TransactionPool transactionPool) {
this.transactionPool = transactionPool;
return this;
}
public EthProtocolManagerTestBuilder setEthereumWireProtocolConfiguration(
final EthProtocolConfiguration ethereumWireProtocolConfiguration) {
this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration;
return this;
}
public EthProtocolManagerTestBuilder setForkIdManager(final ForkIdManager forkIdManager) {
this.forkIdManager = forkIdManager;
return this;
}
public EthProtocolManagerTestBuilder setEthPeers(final EthPeers ethPeers) {
this.ethPeers = ethPeers;
return this;
}
public EthProtocolManagerTestBuilder setEthMessages(final EthMessages ethMessages) {
this.ethMessages = ethMessages;
return this;
}
public EthProtocolManagerTestBuilder setSnapMessages(final EthMessages snapMessages) {
this.snapMessages = snapMessages;
return this;
}
public EthProtocolManagerTestBuilder setEthContext(final EthContext ethContext) {
this.ethContext = ethContext;
return this;
}
public EthProtocolManagerTestBuilder setPeerValidators(final List<PeerValidator> peerValidators) {
this.peerValidators = peerValidators;
return this;
}
public EthProtocolManagerTestBuilder setMergePeerFilter(
final Optional<MergePeerFilter> mergePeerFilter) {
this.mergePeerFilter = mergePeerFilter;
return this;
}
public EthProtocolManagerTestBuilder setSynchronizerConfiguration(
final SynchronizerConfiguration synchronizerConfiguration) {
this.synchronizerConfiguration = synchronizerConfiguration;
return this;
}
public EthProtocolManagerTestBuilder setEthScheduler(final EthScheduler ethScheduler) {
this.ethScheduler = ethScheduler;
return this;
}
public EthProtocolManager build() {
if (protocolSchedule == null) {
protocolSchedule = DEFAULT_PROTOCOL_SCHEDULE;
}
if (genesisConfigFile == null) {
genesisConfigFile = GenesisConfigFile.mainnet();
}
if (genesisState == null) {
genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule);
}
if (blockchain == null) {
blockchain = createInMemoryBlockchain(genesisState.getBlock());
}
if (networkId == null) {
networkId = DEFAULT_NETWORK_ID;
}
if (worldStateArchive == null) {
worldStateArchive =
BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST).getWorldArchive();
}
if (transactionPool == null) {
transactionPool = mock(TransactionPool.class);
}
if (ethereumWireProtocolConfiguration == null) {
ethereumWireProtocolConfiguration = EthProtocolConfiguration.defaultConfig();
}
if (forkIdManager == null) {
forkIdManager =
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false);
}
if (ethPeers == null) {
ethPeers =
new EthPeers(
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Collections.emptyList(),
Bytes.random(64),
25,
25,
false,
SyncMode.FAST,
forkIdManager);
}
ethPeers.setChainHeadTracker(EthProtocolManagerTestUtil.getChainHeadTrackerMock());
if (ethMessages == null) {
ethMessages = new EthMessages();
}
if (snapMessages == null) {
snapMessages = new EthMessages();
}
if (ethScheduler == null) {
ethScheduler =
new DeterministicEthScheduler(DeterministicEthScheduler.TimeoutPolicy.NEVER_TIMEOUT);
}
if (ethContext == null) {
ethContext = new EthContext(ethPeers, ethMessages, snapMessages, ethScheduler);
}
if (peerValidators == null) {
peerValidators = Collections.emptyList();
}
if (mergePeerFilter == null) {
mergePeerFilter = Optional.of(new MergePeerFilter());
}
if (synchronizerConfiguration == null) {
synchronizerConfiguration = SynchronizerConfiguration.builder().build();
}
return new EthProtocolManager(
blockchain,
networkId,
worldStateArchive,
transactionPool,
ethereumWireProtocolConfiguration,
ethPeers,
ethMessages,
ethContext,
peerValidators,
mergePeerFilter,
synchronizerConfiguration,
ethScheduler,
forkIdManager);
}
}

@ -15,229 +15,29 @@
package org.hyperledger.besu.ethereum.eth.manager; package org.hyperledger.besu.ethereum.eth.manager;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.chain.ChainHead;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocol;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager;
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator;
import org.hyperledger.besu.ethereum.eth.sync.ChainHeadTracker; import org.hyperledger.besu.ethereum.eth.sync.ChainHeadTracker;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.forkid.ForkIdManager;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.testutil.DeterministicEthScheduler.TimeoutPolicy;
import org.hyperledger.besu.testutil.TestClock;
import java.math.BigInteger;
import java.util.Collections;
import java.util.Optional;
import java.util.OptionalLong; import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import org.apache.tuweni.bytes.Bytes;
import org.mockito.Mockito; import org.mockito.Mockito;
public class EthProtocolManagerTestUtil { public class EthProtocolManagerTestUtil {
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final TimeoutPolicy timeoutPolicy,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration) {
return create(
protocolSchedule,
blockchain,
new DeterministicEthScheduler(timeoutPolicy),
worldStateArchive,
transactionPool,
ethereumWireProtocolConfiguration);
}
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
final Optional<MergePeerFilter> mergePeerFilter) {
final EthPeers peers =
new EthPeers(
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Collections.emptyList(),
Bytes.random(64),
25,
25,
false,
SyncMode.FAST,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
final ChainHeadTracker chainHeadTrackerMock = getChainHeadTrackerMock();
peers.setChainHeadTracker(chainHeadTrackerMock);
final EthMessages messages = new EthMessages();
final EthScheduler ethScheduler = new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT);
final EthContext ethContext = new EthContext(peers, messages, ethScheduler);
return new EthProtocolManager(
blockchain,
BigInteger.ONE,
worldStateArchive,
transactionPool,
ethereumWireProtocolConfiguration,
peers,
messages,
ethContext,
Collections.emptyList(),
mergePeerFilter,
mock(SynchronizerConfiguration.class),
ethScheduler,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
}
public static EthProtocolManager create(
final Blockchain blockchain,
final EthScheduler ethScheduler,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
final EthPeers ethPeers,
final EthMessages ethMessages,
final EthContext ethContext) {
return create(
blockchain,
ethScheduler,
worldStateArchive,
transactionPool,
ethereumWireProtocolConfiguration,
ethPeers,
ethMessages,
ethContext,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
}
public static EthProtocolManager create(
final Blockchain blockchain,
final EthScheduler ethScheduler,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethereumWireProtocolConfiguration,
final EthPeers ethPeers,
final EthMessages ethMessages,
final EthContext ethContext,
final ForkIdManager forkIdManager) {
ethPeers.setChainHeadTracker(getChainHeadTrackerMock());
final BigInteger networkId = BigInteger.ONE;
return new EthProtocolManager(
blockchain,
networkId,
worldStateArchive,
transactionPool,
ethereumWireProtocolConfiguration,
ethPeers,
ethMessages,
ethContext,
Collections.emptyList(),
Optional.empty(),
mock(SynchronizerConfiguration.class),
ethScheduler,
forkIdManager);
}
public static EthProtocolManager create(final Blockchain blockchain) {
return create(
ProtocolScheduleFixture.MAINNET,
blockchain,
new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT));
}
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration ethProtocolConfiguration) {
return create(
protocolSchedule,
blockchain,
new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT),
worldStateArchive,
transactionPool,
ethProtocolConfiguration);
}
public static EthProtocolManager create(final EthScheduler ethScheduler) {
final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET;
final GenesisConfigFile config = GenesisConfigFile.mainnet();
final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule);
final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());
return create(protocolSchedule, blockchain, ethScheduler);
}
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final EthScheduler ethScheduler,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration configuration) {
final EthPeers peers =
new EthPeers(
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Collections.emptyList(),
Bytes.random(64),
25,
25,
false,
SyncMode.FAST,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
final EthMessages messages = new EthMessages();
final ChainHeadTracker chtMock = getChainHeadTrackerMock();
peers.setChainHeadTracker(chtMock);
return create(
blockchain,
ethScheduler,
worldStateArchive,
transactionPool,
configuration,
peers,
messages,
new EthContext(peers, messages, ethScheduler));
}
public static ChainHeadTracker getChainHeadTrackerMock() { public static ChainHeadTracker getChainHeadTrackerMock() {
final ChainHeadTracker chtMock = mock(ChainHeadTracker.class); final ChainHeadTracker chtMock = mock(ChainHeadTracker.class);
final BlockHeader blockHeaderMock = mock(BlockHeader.class); final BlockHeader blockHeaderMock = mock(BlockHeader.class);
@ -249,84 +49,6 @@ public class EthProtocolManagerTestUtil {
return chtMock; return chtMock;
} }
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final EthScheduler ethScheduler,
final WorldStateArchive worldStateArchive,
final TransactionPool transactionPool,
final EthProtocolConfiguration configuration,
final ForkIdManager forkIdManager) {
final EthPeers peers =
new EthPeers(
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Collections.emptyList(),
Bytes.random(64),
25,
25,
false,
SyncMode.FAST,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
final EthMessages messages = new EthMessages();
return create(
blockchain,
ethScheduler,
worldStateArchive,
transactionPool,
configuration,
peers,
messages,
new EthContext(peers, messages, ethScheduler),
forkIdManager);
}
public static EthProtocolManager create(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final EthScheduler ethScheduler) {
final EthPeers ethPeers =
new EthPeers(
() -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()),
TestClock.fixed(),
new NoOpMetricsSystem(),
EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE,
Collections.emptyList(),
Bytes.random(64),
25,
25,
false,
SyncMode.FAST,
new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false));
final ChainHeadTracker chainHeadTrackerMock = getChainHeadTrackerMock();
ethPeers.setChainHeadTracker(chainHeadTrackerMock);
final EthMessages messages = new EthMessages();
return create(
blockchain,
ethScheduler,
BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST).getWorldArchive(),
mock(TransactionPool.class),
EthProtocolConfiguration.defaultConfig(),
ethPeers,
messages,
new EthContext(ethPeers, messages, ethScheduler));
}
public static EthProtocolManager create() {
return create(TimeoutPolicy.NEVER_TIMEOUT);
}
public static EthProtocolManager create(final TimeoutPolicy timeoutPolicy) {
return create(new DeterministicEthScheduler(timeoutPolicy));
}
// Utility to prevent scheduler from automatically running submitted tasks // Utility to prevent scheduler from automatically running submitted tasks
public static void disableEthSchedulerAutoRun(final EthProtocolManager ethProtocolManager) { public static void disableEthSchedulerAutoRun(final EthProtocolManager ethProtocolManager) {
final EthScheduler scheduler = ethProtocolManager.ethContext().getScheduler(); final EthScheduler scheduler = ethProtocolManager.ethContext().getScheduler();

@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthMessages;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -146,15 +147,16 @@ public abstract class AbstractMessageTaskTest<T, R> {
transactionPool.setEnabled(); transactionPool.setEnabled();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
blockchain, .setProtocolSchedule(protocolSchedule)
ethScheduler, .setBlockchain(blockchain)
protocolContext.getWorldStateArchive(), .setEthScheduler(ethScheduler)
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig(), .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
ethPeers, .setEthPeers(ethPeers)
ethMessages, .setEthMessages(ethMessages)
ethContext); .setEthContext(ethContext)
.build();
} }
protected abstract T generateDataToBeRequested(); protected abstract T generateDataToBeRequested();

@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
@ -36,7 +37,7 @@ public class WaitForPeerTaskTest {
@BeforeEach @BeforeEach
public void setupTest() { public void setupTest() {
ethProtocolManager = EthProtocolManagerTestUtil.create(); ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
} }

@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
@ -36,7 +37,7 @@ public class WaitForPeersTaskTest {
@BeforeEach @BeforeEach
public void setupTest() { public void setupTest() {
ethProtocolManager = EthProtocolManagerTestUtil.create(); ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
} }

@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage; import org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage;
@ -43,7 +44,11 @@ public abstract class AbstractPeerBlockValidatorTest {
@Test @Test
public void validatePeer_unresponsivePeer() { public void validatePeer_unresponsivePeer() {
final EthProtocolManager ethProtocolManager = final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT); EthProtocolManagerTestBuilder.builder()
.setEthScheduler(
new DeterministicEthScheduler(
DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT))
.build();
final long blockNumber = 500; final long blockNumber = 500;
final PeerValidator validator = createValidator(blockNumber, 0); final PeerValidator validator = createValidator(blockNumber, 0);
@ -61,7 +66,7 @@ public abstract class AbstractPeerBlockValidatorTest {
@Test @Test
public void validatePeer_requestBlockFromPeerBeingTested() { public void validatePeer_requestBlockFromPeerBeingTested() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final long blockNumber = 500; final long blockNumber = 500;
final Block block = gen.block(BlockOptions.create().setBlockNumber(blockNumber)); final Block block = gen.block(BlockOptions.create().setBlockNumber(blockNumber));
@ -97,7 +102,11 @@ public abstract class AbstractPeerBlockValidatorTest {
public void canBeValidated() { public void canBeValidated() {
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final EthProtocolManager ethProtocolManager = final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT); EthProtocolManagerTestBuilder.builder()
.setEthScheduler(
new DeterministicEthScheduler(
DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT))
.build();
final long blockNumber = 500; final long blockNumber = 500;
final long buffer = 10; final long buffer = 10;

@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderValidator;
@ -42,7 +43,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest {
@Test @Test
public void validatePeer_responsivePeerOnRightSideOfFork() { public void validatePeer_responsivePeerOnRightSideOfFork() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final long daoBlockNumber = 500; final long daoBlockNumber = 500;
final Block daoBlock = final Block daoBlock =
@ -73,7 +74,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest {
@Test @Test
public void validatePeer_responsivePeerOnWrongSideOfFork() { public void validatePeer_responsivePeerOnWrongSideOfFork() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final long daoBlockNumber = 500; final long daoBlockNumber = 500;
final Block daoBlock = final Block daoBlock =
@ -101,7 +102,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest {
@Test @Test
public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() { public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final long daoBlockNumber = 500; final long daoBlockNumber = 500;
final PeerValidator validator = final PeerValidator validator =

@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason;
@ -39,7 +40,7 @@ public class PeerValidatorRunnerTest {
public void checkPeer_schedulesFutureCheckWhenPeerNotReady() { public void checkPeer_schedulesFutureCheckWhenPeerNotReady() {
final PeerValidator validator = mock(PeerValidator.class); final PeerValidator validator = mock(PeerValidator.class);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
final EthPeer peer = final EthPeer peer =
EthProtocolManagerTestUtil.peerBuilder() EthProtocolManagerTestUtil.peerBuilder()
@ -78,7 +79,7 @@ public class PeerValidatorRunnerTest {
public void checkPeer_doesNotScheduleFutureCheckWhenPeerNotReadyAndDisconnected() { public void checkPeer_doesNotScheduleFutureCheckWhenPeerNotReadyAndDisconnected() {
final PeerValidator validator = mock(PeerValidator.class); final PeerValidator validator = mock(PeerValidator.class);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
final EthPeer peer = final EthPeer peer =
EthProtocolManagerTestUtil.peerBuilder() EthProtocolManagerTestUtil.peerBuilder()
@ -105,7 +106,7 @@ public class PeerValidatorRunnerTest {
public void checkPeer_handlesInvalidPeer() { public void checkPeer_handlesInvalidPeer() {
final PeerValidator validator = mock(PeerValidator.class); final PeerValidator validator = mock(PeerValidator.class);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
final EthPeer peer = final EthPeer peer =
EthProtocolManagerTestUtil.peerBuilder() EthProtocolManagerTestUtil.peerBuilder()
@ -138,7 +139,7 @@ public class PeerValidatorRunnerTest {
public void checkPeer_handlesValidPeer() { public void checkPeer_handlesValidPeer() {
final PeerValidator validator = mock(PeerValidator.class); final PeerValidator validator = mock(PeerValidator.class);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
final EthPeer peer = final EthPeer peer =
EthProtocolManagerTestUtil.peerBuilder() EthProtocolManagerTestUtil.peerBuilder()

@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
@ -41,7 +42,10 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT
@Test @Test
public void validatePeer_responsivePeerWithRequiredBlock() { public void validatePeer_responsivePeerWithRequiredBlock() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestBuilder.builder()
.setProtocolSchedule(ProtocolScheduleFixture.MAINNET)
.build();
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final long requiredBlockNumber = 500; final long requiredBlockNumber = 500;
final Block requiredBlock = final Block requiredBlock =
@ -73,7 +77,7 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT
@Test @Test
public void validatePeer_responsivePeerWithBadRequiredBlock() { public void validatePeer_responsivePeerWithBadRequiredBlock() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final BlockDataGenerator gen = new BlockDataGenerator(1); final BlockDataGenerator gen = new BlockDataGenerator(1);
final long requiredBlockNumber = 500; final long requiredBlockNumber = 500;
final Block requiredBlock = final Block requiredBlock =
@ -105,7 +109,7 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT
@Test @Test
public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() { public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
final PeerValidator validator = final PeerValidator validator =
new RequiredBlocksPeerValidator( new RequiredBlocksPeerValidator(

@ -45,6 +45,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.manager.EthMessages;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -110,12 +111,13 @@ public abstract class AbstractBlockPropagationManagerTest {
tempProtocolContext.getConsensusContext(ConsensusContext.class), tempProtocolContext.getConsensusContext(ConsensusContext.class),
new BadBlockManager()); new BadBlockManager());
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
blockchainUtil.getWorldArchive(), .setWorldStateArchive(blockchainUtil.getWorldArchive())
blockchainUtil.getTransactionPool(), .setTransactionPool(blockchainUtil.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
syncConfig = SynchronizerConfiguration.builder().blockPropagationRange(-3, 5).build(); syncConfig = SynchronizerConfiguration.builder().blockPropagationRange(-3, 5).build();
syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers()); syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers());
blockBroadcaster = mock(BlockBroadcaster.class); blockBroadcaster = mock(BlockBroadcaster.class);

@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule;
import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.ChainState;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -76,7 +76,7 @@ public class ChainHeadTrackerTest {
public void setup(final DataStorageFormat storageFormat) { public void setup(final DataStorageFormat storageFormat) {
blockchainSetupUtil = BlockchainSetupUtil.forTesting(storageFormat); blockchainSetupUtil = BlockchainSetupUtil.forTesting(storageFormat);
blockchain = blockchainSetupUtil.getBlockchain(); blockchain = blockchainSetupUtil.getBlockchain();
ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build();
respondingPeer = respondingPeer =
RespondingEthPeer.builder() RespondingEthPeer.builder()
.ethProtocolManager(ethProtocolManager) .ethProtocolManager(ethProtocolManager)

@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.sync.range.RangeHeaders; import org.hyperledger.besu.ethereum.eth.sync.range.RangeHeaders;
@ -65,7 +66,7 @@ public class DownloadHeadersStepTest {
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build();
downloader = downloader =
new DownloadHeadersStep( new DownloadHeadersStep(
protocolSchedule, protocolSchedule,

@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder;
@ -36,6 +37,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -73,13 +75,14 @@ public class RangeHeadersFetcherTest {
@BeforeEach @BeforeEach
public void setUpTest() { public void setUpTest() {
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
responder = responder =
RespondingEthPeer.blockchainResponder( RespondingEthPeer.blockchainResponder(
blockchain, protocolContext.getWorldStateArchive(), transactionPool); blockchain, protocolContext.getWorldStateArchive(), transactionPool);

@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
@ -144,7 +145,11 @@ public class BackwardSyncContextTest {
} }
} }
when(protocolContext.getBlockchain()).thenReturn(localBlockchain); when(protocolContext.getBlockchain()).thenReturn(localBlockchain);
EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); EthProtocolManager ethProtocolManager =
EthProtocolManagerTestBuilder.builder()
.setProtocolSchedule(protocolSchedule)
.setBlockchain(localBlockchain)
.build();
peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
EthContext ethContext = ethProtocolManager.ethContext(); EthContext ethContext = ethProtocolManager.ethContext();

@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException; import org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
@ -130,7 +130,8 @@ public class BackwardSyncStepTest {
when(context.getProtocolSchedule()).thenReturn(protocolSchedule); when(context.getProtocolSchedule()).thenReturn(protocolSchedule);
when(context.getBatchSize()).thenReturn(5); when(context.getBatchSize()).thenReturn(5);
EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(ethScheduler); EthProtocolManager ethProtocolManager =
EthProtocolManagerTestBuilder.builder().setEthScheduler(ethScheduler).build();
peer = peer =
RespondingEthPeer.builder() RespondingEthPeer.builder()

@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
@ -127,7 +128,7 @@ public class ForwardSyncStepTest {
when(context.getProtocolContext().getBlockchain()).thenReturn(localBlockchain); when(context.getProtocolContext().getBlockchain()).thenReturn(localBlockchain);
when(context.getProtocolSchedule()).thenReturn(protocolSchedule); when(context.getProtocolSchedule()).thenReturn(protocolSchedule);
when(context.getBatchSize()).thenReturn(2); when(context.getBatchSize()).thenReturn(2);
EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
EthContext ethContext = ethProtocolManager.ethContext(); EthContext ethContext = ethProtocolManager.ethContext();

@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -121,10 +122,11 @@ public class CheckPointSyncChainDownloaderTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
final int blockNumber = 10; final int blockNumber = 10;

@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor;
@ -42,6 +43,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -78,13 +80,14 @@ public class DownloadReceiptsStepTest {
peerTaskExecutor = mock(PeerTaskExecutor.class); peerTaskExecutor = mock(PeerTaskExecutor.class);
TransactionPool transactionPool = mock(TransactionPool.class); TransactionPool transactionPool = mock(TransactionPool.class);
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
ProtocolScheduleFixture.MAINNET, .setProtocolSchedule(ProtocolScheduleFixture.MAINNET)
blockchain, .setBlockchain(blockchain)
() -> false, .setEthScheduler(new DeterministicEthScheduler(() -> false))
protocolContext.getWorldStateArchive(), .setWorldStateArchive(protocolContext.getWorldStateArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
} }
@Test @Test

@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor;
@ -45,6 +46,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -93,13 +95,15 @@ public class FastSyncActionsTest {
blockchainSetupUtil.importAllBlocks(); blockchainSetupUtil.importAllBlocks();
blockchain = blockchainSetupUtil.getBlockchain(); blockchain = blockchainSetupUtil.getBlockchain();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
ProtocolScheduleFixture.MAINNET, .setProtocolSchedule(ProtocolScheduleFixture.MAINNET)
blockchain, .setBlockchain(blockchain)
() -> timeoutCount.getAndDecrement() > 0, .setEthScheduler(
blockchainSetupUtil.getWorldArchive(), new DeterministicEthScheduler(() -> timeoutCount.getAndDecrement() > 0))
blockchainSetupUtil.getTransactionPool(), .setWorldStateArchive(blockchainSetupUtil.getWorldArchive())
EthProtocolConfiguration.defaultConfig()); .setTransactionPool(blockchainSetupUtil.getTransactionPool())
.setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
ethPeers = ethContext.getEthPeers(); ethPeers = ethContext.getEthPeers();
syncState = new SyncState(blockchain, ethPeers); syncState = new SyncState(blockchain, ethPeers);

@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -87,10 +88,11 @@ public class FastSyncChainDownloaderTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());

@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder;
@ -35,6 +36,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -79,13 +81,14 @@ public class PivotBlockConfirmerTest {
protocolSchedule = blockchainSetupUtil.getProtocolSchedule(); protocolSchedule = blockchainSetupUtil.getProtocolSchedule();
protocolContext = blockchainSetupUtil.getProtocolContext(); protocolContext = blockchainSetupUtil.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
timeout::get, .setEthScheduler(new DeterministicEthScheduler(timeout::get))
blockchainSetupUtil.getWorldArchive(), .setWorldStateArchive(blockchainSetupUtil.getWorldArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
pivotBlockConfirmer = createPivotBlockConfirmer(3, 2); pivotBlockConfirmer = createPivotBlockConfirmer(3, 2);
} }

@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder;
@ -37,6 +38,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.util.ExceptionUtils; import org.hyperledger.besu.util.ExceptionUtils;
import java.util.Optional; import java.util.Optional;
@ -82,13 +84,14 @@ public class PivotBlockRetrieverTest {
protocolContext = blockchainSetupUtil.getProtocolContext(); protocolContext = blockchainSetupUtil.getProtocolContext();
transactionPool = blockchainSetupUtil.getTransactionPool(); transactionPool = blockchainSetupUtil.getTransactionPool();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
blockchain, .setBlockchain(blockchain)
timeout::get, .setEthScheduler(new DeterministicEthScheduler(timeout::get))
blockchainSetupUtil.getWorldArchive(), .setWorldStateArchive(blockchainSetupUtil.getWorldArchive())
transactionPool, .setTransactionPool(transactionPool)
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
pivotBlockRetriever = createPivotBlockRetriever(3, 1, 1); pivotBlockRetriever = createPivotBlockRetriever(3, 1, 1);
} }

@ -36,6 +36,7 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -114,7 +115,9 @@ class FastWorldStateDownloaderTest {
.build()); .build());
final EthProtocolManager ethProtocolManager = final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); EthProtocolManagerTestBuilder.builder()
.setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
.build();
@AfterEach @AfterEach
public void tearDown() throws Exception { public void tearDown() throws Exception {
@ -238,7 +241,10 @@ class FastWorldStateDownloaderTest {
void canRecoverFromTimeouts() { void canRecoverFromTimeouts() {
final DeterministicEthScheduler.TimeoutPolicy timeoutPolicy = final DeterministicEthScheduler.TimeoutPolicy timeoutPolicy =
DeterministicEthScheduler.TimeoutPolicy.timeoutXTimes(2); DeterministicEthScheduler.TimeoutPolicy.timeoutXTimes(2);
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(timeoutPolicy); final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestBuilder.builder()
.setEthScheduler(new DeterministicEthScheduler(timeoutPolicy))
.build();
final MockExecutorService serviceExecutor = final MockExecutorService serviceExecutor =
((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler()) ((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler())
.mockServiceExecutor(); .mockServiceExecutor();
@ -382,7 +388,7 @@ class FastWorldStateDownloaderTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void testCancellation(final boolean shouldCancelFuture) { private void testCancellation(final boolean shouldCancelFuture) {
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build();
// Prevent the persistence service from running // Prevent the persistence service from running
final MockExecutorService serviceExecutor = final MockExecutorService serviceExecutor =
((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler()) ((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler())
@ -661,7 +667,9 @@ class FastWorldStateDownloaderTest {
@Timeout(value = 60) @Timeout(value = 60)
void stalledDownloader() { void stalledDownloader() {
final EthProtocolManager ethProtocolManager = final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); EthProtocolManagerTestBuilder.builder()
.setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
.build();
// Setup "remote" state // Setup "remote" state
final ForestWorldStateKeyValueStorage remoteStorage = final ForestWorldStateKeyValueStorage remoteStorage =

@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -66,13 +67,14 @@ public class FullSyncChainDownloaderForkTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
localBlockchainSetup.getWorldArchive(), .setWorldStateArchive(localBlockchainSetup.getWorldArchive())
localBlockchainSetup.getTransactionPool(), .setTransactionPool(localBlockchainSetup.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
} }

@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -96,13 +97,14 @@ public class FullSyncChainDownloaderTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
localBlockchainSetup.getWorldArchive(), .setWorldStateArchive(localBlockchainSetup.getWorldArchive())
localBlockchainSetup.getTransactionPool(), .setTransactionPool(localBlockchainSetup.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
} }

@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -80,13 +81,14 @@ public class FullSyncChainDownloaderTotalTerminalDifficultyTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
localBlockchainSetup.getWorldArchive(), .setWorldStateArchive(localBlockchainSetup.getWorldArchive())
localBlockchainSetup.getTransactionPool(), .setTransactionPool(localBlockchainSetup.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
} }

@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -71,13 +72,14 @@ public class FullSyncDownloaderTest {
protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext(); protocolContext = localBlockchainSetup.getProtocolContext();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
localBlockchainSetup.getWorldArchive(), .setWorldStateArchive(localBlockchainSetup.getWorldArchive())
localBlockchainSetup.getTransactionPool(), .setTransactionPool(localBlockchainSetup.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
} }

@ -30,6 +30,7 @@ import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
@ -81,13 +82,14 @@ public class FullSyncTargetManagerTest {
new ProtocolContext( new ProtocolContext(
localBlockchain, localWorldState, mock(ConsensusContext.class), new BadBlockManager()); localBlockchain, localWorldState, mock(ConsensusContext.class), new BadBlockManager());
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()))
localWorldState, .setWorldStateArchive(localBlockchainSetup.getWorldArchive())
localBlockchainSetup.getTransactionPool(), .setTransactionPool(localBlockchainSetup.getTransactionPool())
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
final EthContext ethContext = ethProtocolManager.ethContext(); final EthContext ethContext = ethProtocolManager.ethContext();
localBlockchainSetup.importFirstBlocks(5); localBlockchainSetup.importFirstBlocks(5);
otherBlockchainSetup.importFirstBlocks(20); otherBlockchainSetup.importFirstBlocks(20);

@ -42,6 +42,7 @@ import org.hyperledger.besu.ethereum.eth.manager.ChainState;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason;
@ -90,7 +91,7 @@ public class SyncStateTest {
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build();
ethPeers = spy(ethProtocolManager.ethContext().getEthPeers()); ethPeers = spy(ethProtocolManager.ethContext().getEthPeers());
syncTargetPeer = createPeer(TARGET_DIFFICULTY, TARGET_CHAIN_HEIGHT); syncTargetPeer = createPeer(TARGET_DIFFICULTY, TARGET_CHAIN_HEIGHT);
otherPeer = createPeer(Difficulty.ZERO, 0); otherPeer = createPeer(Difficulty.ZERO, 0);

@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.task.EthTask; import org.hyperledger.besu.ethereum.eth.manager.task.EthTask;
@ -135,12 +136,13 @@ public class DetermineCommonAncestorTaskParameterizedTest {
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
final EthProtocolManager ethProtocolManager = final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
worldStateArchive, .setWorldStateArchive(worldStateArchive)
mock(TransactionPool.class), .setTransactionPool(mock(TransactionPool.class))
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
final RespondingEthPeer.Responder responder = final RespondingEthPeer.Responder responder =
RespondingEthPeer.blockchainResponder(remoteBlockchain); RespondingEthPeer.blockchainResponder(remoteBlockchain);
final RespondingEthPeer respondingEthPeer = final RespondingEthPeer respondingEthPeer =

@ -41,6 +41,7 @@ import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil;
import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer;
import org.hyperledger.besu.ethereum.eth.manager.exceptions.EthTaskException; import org.hyperledger.besu.ethereum.eth.manager.exceptions.EthTaskException;
@ -81,12 +82,13 @@ public class DetermineCommonAncestorTaskTest {
localBlockchain = createInMemoryBlockchain(localGenesisBlock); localBlockchain = createInMemoryBlockchain(localGenesisBlock);
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
ethProtocolManager = ethProtocolManager =
EthProtocolManagerTestUtil.create( EthProtocolManagerTestBuilder.builder()
protocolSchedule, .setProtocolSchedule(protocolSchedule)
localBlockchain, .setBlockchain(localBlockchain)
worldStateArchive, .setWorldStateArchive(worldStateArchive)
mock(TransactionPool.class), .setTransactionPool(mock(TransactionPool.class))
EthProtocolConfiguration.defaultConfig()); .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
protocolContext = protocolContext =
new ProtocolContext( new ProtocolContext(

@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.sync.tasks.exceptions.InvalidBlockException; import org.hyperledger.besu.ethereum.eth.sync.tasks.exceptions.InvalidBlockException;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -70,7 +70,11 @@ public class PersistBlockTaskTest {
protocolSchedule = blockchainUtil.getProtocolSchedule(); protocolSchedule = blockchainUtil.getProtocolSchedule();
protocolContext = blockchainUtil.getProtocolContext(); protocolContext = blockchainUtil.getProtocolContext();
blockchain = blockchainUtil.getBlockchain(); blockchain = blockchainUtil.getBlockchain();
final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestBuilder.builder()
.setProtocolSchedule(protocolSchedule)
.setBlockchain(blockchain)
.build();
ethContext = ethProtocolManager.ethContext(); ethContext = ethProtocolManager.ethContext();
} }

@ -56,7 +56,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder;
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
import org.hyperledger.besu.ethereum.eth.transactions.layered.LayeredTransactionPoolBaseFeeTest; import org.hyperledger.besu.ethereum.eth.transactions.layered.LayeredTransactionPoolBaseFeeTest;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.LegacyTransactionPoolBaseFeeTest; import org.hyperledger.besu.ethereum.eth.transactions.sorter.LegacyTransactionPoolBaseFeeTest;
@ -225,7 +225,11 @@ public abstract class AbstractTransactionPoolTestBase {
protocolSchedule = spy(executionContext.getProtocolSchedule()); protocolSchedule = spy(executionContext.getProtocolSchedule());
doReturn(protocolSpec).when(protocolSchedule).getByBlockHeader(any()); doReturn(protocolSpec).when(protocolSchedule).getByBlockHeader(any());
blockGasLimit = blockchain.getChainHeadBlock().getHeader().getGasLimit(); blockGasLimit = blockchain.getChainHeadBlock().getHeader().getGasLimit();
ethProtocolManager = EthProtocolManagerTestUtil.create(); ethProtocolManager =
EthProtocolManagerTestBuilder.builder()
.setProtocolSchedule(protocolSchedule)
.setBlockchain(blockchain)
.build();
ethContext = spy(ethProtocolManager.ethContext()); ethContext = spy(ethProtocolManager.ethContext());
final EthScheduler ethScheduler = spy(ethContext.getScheduler()); final EthScheduler ethScheduler = spy(ethContext.getScheduler());

Loading…
Cancel
Save