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

added richness to useless peer disconnect reasons #6899

Merged
merged 1 commit into from
Apr 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void disconnectWorstUselessPeer() {
.addArgument(this::peerCount)
.addArgument(this::getMaxPeers)
.log();
peer.disconnect(DisconnectMessage.DisconnectReason.USELESS_PEER);
peer.disconnect(DisconnectMessage.DisconnectReason.USELESS_PEER_BY_CHAIN_COMPARATOR);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Optional<DisconnectReason> recordUselessResponse(final long timestamp) {
if (uselessResponseTimes.size() >= USELESS_RESPONSE_THRESHOLD) {
score -= LARGE_ADJUSTMENT;
LOG.debug("Disconnection triggered by exceeding useless response threshold");
return Optional.of(DisconnectReason.USELESS_PEER);
return Optional.of(DisconnectReason.USELESS_PEER_USELESS_RESPONSES);
} else {
score -= SMALL_ADJUSTMENT;
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void refreshPeers() {
.addArgument(peers::peerCount)
.addArgument(peers::getMaxPeers)
.log();
peer.disconnect(DisconnectReason.USELESS_PEER);
peer.disconnect(DisconnectReason.USELESS_PEER_BY_REPUTATION);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void onPeerConnected(final EthPeer peer) {
.addArgument(peer::getLoggableId)
.addArgument(error)
.log();
peer.disconnect(DisconnectReason.USELESS_PEER);
peer.disconnect(DisconnectReason.USELESS_PEER_FAILED_TO_RETRIEVE_CHAIN_STATE);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void enforceTrailingPeerLimit() {
? "(no chain state)"
: peerToDisconnect.chainState().getEstimatedHeight())
.log();
peerToDisconnect.disconnect(DisconnectReason.USELESS_PEER);
peerToDisconnect.disconnect(DisconnectReason.USELESS_PEER_TRAILING_PEER);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private CompletableFuture<Optional<EthPeer>> confirmPivotBlockHeader(final EthPe
pivotBlockHeader.getHash(),
result.size() == 1 ? result.get(0).getHash() : "invalid response",
bestPeer);
bestPeer.disconnect(DisconnectReason.USELESS_PEER);
bestPeer.disconnect(DisconnectReason.USELESS_PEER_MISMATCHED_PIVOT_BLOCK);
return CompletableFuture.completedFuture(Optional.<EthPeer>empty());
}
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected Optional<SyncTarget> finalizeSelectedSyncTarget(final SyncTarget syncT
syncTarget.peer(),
commonAncestor.getNumber(),
commonAncestor.getHash());
syncTarget.peer().disconnect(DisconnectReason.USELESS_PEER);
syncTarget.peer().disconnect(DisconnectReason.USELESS_PEER_WORLD_STATE_NOT_AVAILABLE);
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason.TIMEOUT;
import static org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason.USELESS_PEER;
import static org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason.USELESS_PEER_USELESS_RESPONSES;

import org.hyperledger.besu.ethereum.eth.messages.EthPV62;

Expand Down Expand Up @@ -62,7 +62,7 @@ public void shouldResetTimeoutCountForRequestType() {
@Test
public void shouldOnlyDisconnectWhenEmptyResponseThresholdReached() {
sendUselessResponses(1001, PeerReputation.USELESS_RESPONSE_THRESHOLD - 1);
assertThat(reputation.recordUselessResponse(1005)).contains(USELESS_PEER);
assertThat(reputation.recordUselessResponse(1005)).contains(USELESS_PEER_USELESS_RESPONSES);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void assertDisconnections(final EthPeer... disconnectedPeers) {
final List<EthPeer> disconnected = asList(disconnectedPeers);
for (final EthPeer peer : peers) {
if (disconnected.contains(peer)) {
verify(peer).disconnect(DisconnectReason.USELESS_PEER);
verify(peer).disconnect(DisconnectReason.USELESS_PEER_TRAILING_PEER);
} else {
verify(peer, never()).disconnect(any(DisconnectReason.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final L
LOG.debug("Disconnecting because no capabilities are shared: {}", peerInfo);
connectFuture.completeExceptionally(
new IncompatiblePeerException("No shared capabilities"));
connection.disconnect(DisconnectMessage.DisconnectReason.USELESS_PEER);
connection.disconnect(
DisconnectMessage.DisconnectReason.USELESS_PEER_NO_SHARED_CAPABILITIES);
}

// Setup next stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public enum DisconnectReason {
TCP_SUBSYSTEM_ERROR((byte) 0x01),
BREACH_OF_PROTOCOL((byte) 0x02),
USELESS_PEER((byte) 0x03),
USELESS_PEER_USELESS_RESPONSES((byte) 0x03, "Useless responses: exceeded threshold"),
USELESS_PEER_TRAILING_PEER((byte) 0x03, "Trailing peer requirement"),
USELESS_PEER_NO_SHARED_CAPABILITIES((byte) 0x03, "No shared capabilities"),
USELESS_PEER_WORLD_STATE_NOT_AVAILABLE((byte) 0x03, "World state not available"),
USELESS_PEER_MISMATCHED_PIVOT_BLOCK((byte) 0x03, "Mismatched pivot block"),
USELESS_PEER_FAILED_TO_RETRIEVE_CHAIN_STATE(
(byte) 0x03, "Failed to retrieve header for chain state"),
USELESS_PEER_BY_REPUTATION((byte) 0x03, "Lowest reputation score"),
USELESS_PEER_BY_CHAIN_COMPARATOR((byte) 0x03, "Lowest by chain height comparator"),
TOO_MANY_PEERS((byte) 0x04),
ALREADY_CONNECTED((byte) 0x05),
INCOMPATIBLE_P2P_PROTOCOL_VERSION((byte) 0x06),
Expand Down
Loading