diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e7f15dd7c..8c3d8c6b134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 21.1.5 + +### Additions and Improvements + +### Bug Fixes + +- Fixed `NullPointerException` when crossing network upgrade blocks when peer discovery is disabled. [\#2140](https://github.com/hyperledger/besu/pull/2140) + +### Early Access Features + +#### Previously identified known issues + ## 21.1.4 ### Additions and Improvements 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 243436693f1..c3ea951aa69 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 @@ -176,7 +176,11 @@ public CompletableFuture start(final int tcpPort) { } } - public NodeRecord updateNodeRecord() { + public void updateNodeRecord() { + if (!config.isActive()) { + return; + } + final KeyValueStorage keyValueStorage = storageProvider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.BLOCKCHAIN); final NodeRecordFactory nodeRecordFactory = NodeRecordFactory.DEFAULT; @@ -232,7 +236,6 @@ public NodeRecord updateNodeRecord() { localNode .orElseThrow(() -> new IllegalStateException("Local node should be set here")) .setNodeRecord(newNodeRecord); - return newNodeRecord; } public void addPeerRequirement(final PeerRequirement peerRequirement) { 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 2ee34e6e1e8..7050beb3654 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 @@ -16,6 +16,7 @@ import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -137,6 +138,28 @@ public void testNodeRecordCreatedUpdatesDiscoveryPeer() { assertThat(pre).isNotEqualTo(post); } + @Test + public void testNodeRecordNotUpdatedIfNoPeerDiscovery() { + KeyPair keyPair = + SIGNATURE_ALGORITHM + .get() + .createKeyPair( + SIGNATURE_ALGORITHM + .get() + .createPrivateKey( + Bytes32.fromHexString( + "0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"))); + final MockPeerDiscoveryAgent agent = + helper.startDiscoveryAgent( + helper + .agentBuilder() + .nodeKey(NodeKeyUtils.createFrom(keyPair)) + .advertisedHost("127.0.0.1") + .bindPort(30303) + .active(false)); + assertThatCode(agent::updateNodeRecord).doesNotThrowAnyException(); + } + @Test public void neighborsPacketFromUnbondedPeerIsDropped() { // Start an agent with no bootstrap peers.