Don't Create New Node Record If Discovery Is Disabled (#2140)

If peer discovery was disabled, we would still try to create a Node Record even though we hadn't initialized required fields.

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/2160/head
Ratan (Rai) Sur 4 years ago committed by GitHub
parent 51283cc7d4
commit 0eb871c1b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      CHANGELOG.md
  2. 7
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java
  3. 23
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java

@ -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

@ -176,7 +176,11 @@ public abstract class PeerDiscoveryAgent {
}
}
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 abstract class PeerDiscoveryAgent {
localNode
.orElseThrow(() -> new IllegalStateException("Local node should be set here"))
.setNodeRecord(newNodeRecord);
return newNodeRecord;
}
public void addPeerRequirement(final PeerRequirement peerRequirement) {

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.p2p.discovery;
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 class PeerDiscoveryAgentTest {
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.

Loading…
Cancel
Save