From 4456dc15deadfda1c48121223bc2c82fd336fae8 Mon Sep 17 00:00:00 2001 From: David Mechler Date: Tue, 9 Feb 2021 15:45:32 -0500 Subject: [PATCH] Changes made for adding ETH field to ENR (#1893) Signed-off-by: David Mechler --- .../acceptance/dsl/node/ThreadBesuNodeRunner.java | 1 + .../java/org/hyperledger/besu/RunnerBuilder.java | 12 ++++++++++-- .../java/org/hyperledger/besu/cli/BesuCommand.java | 1 + .../org/hyperledger/besu/RunnerBuilderTest.java | 1 + .../test/java/org/hyperledger/besu/RunnerTest.java | 6 +++++- .../hyperledger/besu/cli/CommandTestAbstract.java | 1 + .../api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java | 3 +++ .../ethereum/eth/manager/EthProtocolManager.java | 5 +++++ .../besu/ethereum/eth/manager/ForkId.java | 8 ++++++++ .../besu/ethereum/eth/transactions/TestNode.java | 1 + .../ethereum/p2p/discovery/PeerDiscoveryAgent.java | 10 ++++++++-- .../p2p/discovery/VertxPeerDiscoveryAgent.java | 14 ++++++++++++-- .../ethereum/p2p/network/DefaultP2PNetwork.java | 12 +++++++++++- .../p2p/discovery/PeerDiscoveryAgentTest.java | 10 +++++++--- .../p2p/discovery/PeerDiscoveryTestHelper.java | 8 +++++++- .../discovery/internal/MockPeerDiscoveryAgent.java | 7 +++++-- .../p2p/network/DefaultP2PNetworkTest.java | 5 ++++- .../network/NetworkingServiceLifecycleTest.java | 5 ++++- .../besu/ethereum/p2p/network/P2PNetworkTest.java | 4 +++- gradle/versions.gradle | 2 +- 20 files changed, 98 insertions(+), 18 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 968d6260f9..ab04fba2bc 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -205,6 +205,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner { .besuPluginContext(new BesuPluginContextImpl()) .autoLogBloomCaching(false) .storageProvider(storageProvider) + .forkIdSupplier(() -> besuController.getProtocolManager().getForkIdAsBytesList()) .build(); runner.start(); diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index a07e28df90..f76391e910 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -119,6 +119,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -170,6 +171,7 @@ public class RunnerBuilder { private boolean autoLogBloomCaching = true; private boolean randomPeerPriority; private StorageProvider storageProvider; + private Supplier> forkIdSupplier; public RunnerBuilder vertx(final Vertx vertx) { this.vertx = vertx; @@ -341,6 +343,11 @@ public class RunnerBuilder { return this; } + public RunnerBuilder forkIdSupplier(final Supplier> forkIdSupplier) { + this.forkIdSupplier = forkIdSupplier; + return this; + } + public Runner build() { Preconditions.checkNotNull(besuController); @@ -414,9 +421,9 @@ public class RunnerBuilder { LOG.info("Detecting NAT service."); final boolean fallbackEnabled = natMethod == NatMethod.AUTO || natMethodFallbackEnabled; final NatService natService = new NatService(buildNatManager(natMethod), fallbackEnabled); - final NetworkBuilder inactiveNetwork = (caps) -> new NoopP2PNetwork(); + final NetworkBuilder inactiveNetwork = caps -> new NoopP2PNetwork(); final NetworkBuilder activeNetwork = - (caps) -> + caps -> DefaultP2PNetwork.builder() .vertx(vertx) .nodeKey(nodeKey) @@ -427,6 +434,7 @@ public class RunnerBuilder { .natService(natService) .randomPeerPriority(randomPeerPriority) .storageProvider(storageProvider) + .forkIdSupplier(forkIdSupplier) .build(); final NetworkRunner networkRunner = diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index b16e9ebb5b..401d23d9bd 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2257,6 +2257,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { .ethstatsUrl(unstableEthstatsOptions.getEthstatsUrl()) .ethstatsContact(unstableEthstatsOptions.getEthstatsContact()) .storageProvider(keyValueStorageProvider(keyValueStorageName)) + .forkIdSupplier(() -> besuController.getProtocolManager().getForkIdAsBytesList()) .build(); addShutdownHook(runner); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java index 38cde4aa2e..98b4e00e6c 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java @@ -124,6 +124,7 @@ public final class RunnerBuilderTest { .vertx(vertx) .dataDir(dataDir.getRoot().toPath()) .storageProvider(mock(KeyValueStorageProvider.class)) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)) .build(); runner.start(); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 522a8a8eb6..365fd03861 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -82,6 +82,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; import org.awaitility.Awaitility; import org.junit.After; @@ -203,7 +204,8 @@ public final class RunnerTest { .maxPeers(3) .metricsSystem(noOpMetricsSystem) .staticNodes(emptySet()) - .storageProvider(new InMemoryStorageProvider()); + .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)); Runner runnerBehind = null; final Runner runnerAhead = @@ -217,6 +219,7 @@ public final class RunnerTest { .dataDir(dbAhead) .pidPath(pidPath) .besuPluginContext(new BesuPluginContextImpl()) + .forkIdSupplier(() -> controllerAhead.getProtocolManager().getForkIdAsBytesList()) .build(); try { @@ -269,6 +272,7 @@ public final class RunnerTest { .metricsConfiguration(behindMetricsConfiguration) .dataDir(temp.newFolder().toPath()) .metricsSystem(noOpMetricsSystem) + .forkIdSupplier(() -> controllerBehind.getProtocolManager().getForkIdAsBytesList()) .build(); runnerBehind.start(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index f6c0d88245..bd4238fbb1 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -238,6 +238,7 @@ public abstract class CommandTestAbstract { when(mockRunnerBuilder.ethstatsUrl(anyString())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.ethstatsContact(anyString())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.storageProvider(any())).thenReturn(mockRunnerBuilder); + when(mockRunnerBuilder.forkIdSupplier(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.build()).thenReturn(mockRunner); final Bytes32 keyPairPrvKey = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 6ba804079b..16eac490d4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -51,6 +51,7 @@ import org.hyperledger.besu.nat.NatService; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -67,6 +68,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.tuweni.bytes.Bytes; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -263,6 +265,7 @@ public class JsonRpcHttpServiceRpcApisTest { .config(config) .metricsSystem(new NoOpMetricsSystem()) .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)) .build(); p2pNetwork.start(); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 352c22631e..4df9a7805d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -49,6 +49,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.tuweni.bytes.Bytes; public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { private static final Logger LOG = LogManager.getLogger(); @@ -358,4 +359,8 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { "Unable to get total difficulty from blockchain for mined block.")); blockBroadcaster.propagate(block, totalDifficulty); } + + public List getForkIdAsBytesList() { + return forkIdManager.computeForkId().getForkIdAsBytesList(); + } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ForkId.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ForkId.java index 4ae0dc6d4a..b854ed6220 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ForkId.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/ForkId.java @@ -47,6 +47,14 @@ public class ForkId { return hash; } + public List getForkIdAsBytesList() { + List bytesList = new ArrayList<>(); + bytesList.add(hash); + bytesList.add(next); + + return bytesList; + } + void createForkIdRLP() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); writeTo(out); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index 38fb34b12d..c866fe8c45 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -168,6 +168,7 @@ public class TestNode implements Closeable { .metricsSystem(new NoOpMetricsSystem()) .supportedCapabilities(capabilities) .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)) .build()) .metricsSystem(new NoOpMetricsSystem()) .build(); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java index fbfbdd2d46..229a0ece9e 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java @@ -43,10 +43,12 @@ import org.hyperledger.besu.util.Subscribers; import java.net.InetSocketAddress; import java.net.SocketException; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -97,6 +99,7 @@ public abstract class PeerDiscoveryAgent { protected final Subscribers peerBondedObservers = Subscribers.create(); private final StorageProvider storageProvider; + private final Supplier> forkIdSupplier; protected PeerDiscoveryAgent( final NodeKey nodeKey, @@ -104,7 +107,8 @@ public abstract class PeerDiscoveryAgent { final PeerPermissions peerPermissions, final NatService natService, final MetricsSystem metricsSystem, - final StorageProvider storageProvider) { + final StorageProvider storageProvider, + final Supplier> forkIdSupplier) { this.metricsSystem = metricsSystem; checkArgument(nodeKey != null, "nodeKey cannot be null"); checkArgument(config != null, "provided configuration cannot be null"); @@ -122,6 +126,7 @@ public abstract class PeerDiscoveryAgent { id = nodeKey.getPublicKey().getEncodedBytes(); this.storageProvider = storageProvider; + this.forkIdSupplier = forkIdSupplier; } protected abstract TimerUtil createTimer(); @@ -202,7 +207,8 @@ public abstract class PeerDiscoveryAgent { new EnrField(EnrField.PKEY_SECP256K1, Functions.compressPublicKey(nodeId)), new EnrField(EnrField.IP_V4, addressBytes), new EnrField(EnrField.TCP, tcpPort), - new EnrField(EnrField.UDP, udpPort)); + new EnrField(EnrField.UDP, udpPort), + new EnrField("eth", Collections.singletonList(forkIdSupplier.get()))); nodeRecord.setSignature( nodeKey .sign(Hash.keccak256(nodeRecord.serializeNoSignature())) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java index e8c5a43a9e..6d62f02b37 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.net.BindException; import java.net.InetSocketAddress; import java.net.SocketException; +import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.IntSupplier; @@ -49,6 +50,7 @@ import io.vertx.core.datagram.DatagramSocket; import io.vertx.core.datagram.DatagramSocketOptions; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.tuweni.bytes.Bytes; public class VertxPeerDiscoveryAgent extends PeerDiscoveryAgent { private static final Logger LOG = LogManager.getLogger(); @@ -64,8 +66,16 @@ public class VertxPeerDiscoveryAgent extends PeerDiscoveryAgent { final PeerPermissions peerPermissions, final NatService natService, final MetricsSystem metricsSystem, - final StorageProvider storageProvider) { - super(nodeKey, config, peerPermissions, natService, metricsSystem, storageProvider); + final StorageProvider storageProvider, + final Supplier> forkIdSupplier) { + super( + nodeKey, + config, + peerPermissions, + natService, + metricsSystem, + storageProvider, + forkIdSupplier); checkArgument(vertx != null, "vertx instance cannot be null"); this.vertx = vertx; diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java index ed1f87b3c5..b4ba038271 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java @@ -64,6 +64,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -447,6 +448,7 @@ public class DefaultP2PNetwork implements P2PNetwork { private MetricsSystem metricsSystem; private StorageProvider storageProvider; + private Supplier> forkIdSupplier; public P2PNetwork build() { validate(); @@ -487,6 +489,7 @@ public class DefaultP2PNetwork implements P2PNetwork { checkState(metricsSystem != null, "MetricsSystem must be set."); checkState(storageProvider != null, "StorageProvider must be set."); checkState(peerDiscoveryAgent != null || vertx != null, "Vertx must be set."); + checkState(forkIdSupplier != null, "ForkIdSupplier must be set."); } private PeerDiscoveryAgent createDiscoveryAgent() { @@ -498,7 +501,8 @@ public class DefaultP2PNetwork implements P2PNetwork { peerPermissions, natService, metricsSystem, - storageProvider); + storageProvider, + forkIdSupplier); } private RlpxAgent createRlpxAgent( @@ -589,5 +593,11 @@ public class DefaultP2PNetwork implements P2PNetwork { this.storageProvider = storageProvider; return this; } + + public Builder forkIdSupplier(final Supplier> forkIdSupplier) { + checkNotNull(forkIdSupplier); + this.forkIdSupplier = forkIdSupplier; + return this; + } } } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java index b90f3717ef..95839f6f35 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java @@ -45,6 +45,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.ethereum.beacon.discovery.schema.NodeRecord; import org.junit.Test; @@ -92,11 +93,14 @@ public class PeerDiscoveryAgentTest { assertThat(nodeRecord.getIdentityScheme()).isNotNull(); assertThat(nodeRecord.getSignature()).isNotNull(); assertThat(nodeRecord.getSeq()).isNotNull(); + assertThat(nodeRecord.get("eth")).isNotNull(); + assertThat(nodeRecord.get("eth")) + .isEqualTo(Collections.singletonList(Collections.singletonList(Bytes.EMPTY))); assertThat(nodeRecord.asEnr()) .isEqualTo( - "enr:-Im4QIEcZbEzW8DSEX-0BPB36s1UwTT54D_I-mvrSHqsZpVzGg7wlXyHb6vRq3GTGNBNQyoUkKkJGryrTo" - + "DTersRuNYBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA" - + "8yWM0xOIN0Y3ACg3VkcIJ2Xw"); + "enr:-JC4QOfroMOa1sB6ajxcBKdWn3s9S4Ojl33pbRm72S5FnCwyZfskmjkJvZznQaWNTrOHrnKxw1R9xMm9rl" + + "EGOcsOyscBg2V0aMLBgIJpZIJ2NIJpcIR_AAABiXNlY3AyNTZrMaEDymNMrg1JrLQB2KTGtv6MVbcNEV" + + "v0AHacwUAPMljNMTiDdGNwAoN1ZHCCdl8"); } @Test diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java index 05383f2c06..700415844e 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java @@ -283,7 +283,13 @@ public class PeerDiscoveryTestHelper { config.setActive(active); MockPeerDiscoveryAgent mockPeerDiscoveryAgent = - new MockPeerDiscoveryAgent(nodeKey, config, peerPermissions, agents, natService); + new MockPeerDiscoveryAgent( + nodeKey, + config, + peerPermissions, + agents, + natService, + () -> Collections.singletonList(Bytes.EMPTY)); mockPeerDiscoveryAgent.getAdvertisedPeer().ifPresent(peer -> peer.setNodeRecord(nodeRecord)); return mockPeerDiscoveryAgent; diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java index be36994653..dbc4ae8e78 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/MockPeerDiscoveryAgent.java @@ -31,6 +31,7 @@ import java.util.Deque; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -49,14 +50,16 @@ public class MockPeerDiscoveryAgent extends PeerDiscoveryAgent { final DiscoveryConfiguration config, final PeerPermissions peerPermissions, final Map agentNetwork, - final NatService natService) { + final NatService natService, + final Supplier> forkIdSupplier) { super( nodeKey, config, peerPermissions, natService, new NoOpMetricsSystem(), - new InMemoryStorageProvider()); + new InMemoryStorageProvider(), + forkIdSupplier); this.agentNetwork = agentNetwork; } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java index d6bb2447d9..fd282d44cc 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java @@ -52,12 +52,14 @@ import org.hyperledger.besu.nat.core.domain.NetworkProtocol; import org.hyperledger.besu.nat.upnp.UpnpNatManager; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; @@ -347,6 +349,7 @@ public final class DefaultP2PNetworkTest { .maintainedPeers(maintainedPeers) .metricsSystem(new NoOpMetricsSystem()) .supportedCapabilities(Capability.create("eth", 63)) - .storageProvider(new InMemoryStorageProvider()); + .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)); } } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/NetworkingServiceLifecycleTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/NetworkingServiceLifecycleTest.java index a676db27a7..a131b3b692 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/NetworkingServiceLifecycleTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/NetworkingServiceLifecycleTest.java @@ -30,8 +30,10 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import io.vertx.core.Vertx; +import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Test; @@ -160,6 +162,7 @@ public class NetworkingServiceLifecycleTest { .config(config) .metricsSystem(new NoOpMetricsSystem()) .supportedCapabilities(Arrays.asList(Capability.create("eth", 63))) - .storageProvider(new InMemoryStorageProvider()); + .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)); } } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java index 633d5bdd62..fbec2e3b1b 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java @@ -41,6 +41,7 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.net.InetAddress; import java.util.Arrays; +import java.util.Collections; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -335,6 +336,7 @@ public class P2PNetworkTest { .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .supportedCapabilities(Arrays.asList(Capability.create("eth", 63))) - .storageProvider(new InMemoryStorageProvider()); + .storageProvider(new InMemoryStorageProvider()) + .forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)); } } diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 64bcbf0f34..0cb74a5fba 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -148,7 +148,7 @@ dependencyManagement { dependency 'org.yaml:snakeyaml:1.26' - dependency 'tech.pegasys.discovery:discovery:0.4.1' + dependency 'tech.pegasys.discovery:discovery:0.4.2' dependency 'tech.pegasys.ethsigner.internal:core:0.4.0' dependency 'tech.pegasys.ethsigner.internal:file-based:0.4.0'