Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ public CompletableFuture<Integer> 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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down