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

confirm pivot block - removed disconnect based on chain height estimate #6889

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e64112f
gst
macfarla Apr 4, 2024
e44fcc2
update chain height estimate of that peer to reflect reality
macfarla Apr 4, 2024
da0454a
log details on comparator update
macfarla Apr 5, 2024
9a374ab
use default comparator not chain height
macfarla Apr 5, 2024
77b9ea7
extra logging re best peer
macfarla Apr 5, 2024
d01a423
allow 1 trailing peer not zero
macfarla Apr 5, 2024
500843d
removed check for chain height prior to confirming pivot block
macfarla Apr 5, 2024
c825c47
remove a log line that is repeated unnecessarily
macfarla Apr 5, 2024
5ebcdac
cleanup
macfarla Apr 5, 2024
8f5ac92
Merge branch 'main' of github.com:hyperledger/besu into chain-height-…
macfarla Apr 5, 2024
7db08e9
removed unused method
macfarla Apr 5, 2024
ea60f72
allow 5 trailing peers not 0
macfarla Apr 7, 2024
d3d15f6
add chain height estimate to ethPeer.toString()
macfarla Apr 7, 2024
75da10f
Merge branch 'main' of github.com:hyperledger/besu into chain-height-…
macfarla Apr 7, 2024
efe7a64
logging order
macfarla Apr 8, 2024
755d41b
revert change in comparator
macfarla Apr 8, 2024
2ea6a32
update test
macfarla Apr 8, 2024
a3dceb4
merge
macfarla Apr 8, 2024
20dbba0
Merge branch 'main' of github.com:hyperledger/besu into chain-height-…
macfarla Apr 8, 2024
2d81237
Merge branch 'main' into chain-height-estimate-tolerance
gfukushima Apr 10, 2024
8352324
use Long.MAX_VALUE to skip the trailingPeer validation, likely incorr…
gfukushima Apr 10, 2024
47fae0a
Merge branch 'main' of github.com:hyperledger/besu into chain-height-…
macfarla Apr 28, 2024
94f3a3e
Merge branch 'chain-height-estimate-tolerance' of github.com:macfarla…
macfarla Apr 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -629,8 +629,9 @@ public boolean hasSupportForMessage(final int messageCode) {
@Override
public String toString() {
return String.format(
"PeerId: %s %s, validated? %s, disconnected? %s, client: %s, %s, %s",
"PeerId: %s height (est): %s %s, validated? %s, disconnected? %s, client: %s, %s, %s",
getLoggableId(),
chainState().getEstimatedHeight(),
reputation,
isFullyValidated(),
isDisconnected(),
Expand Down
Expand Up @@ -198,7 +198,7 @@ private boolean registerDisconnect(final EthPeer peer, final PeerConnection conn
peer.handleDisconnect();
abortPendingRequestsAssignedToDisconnectedPeers();
if (peer.getReputation().getScore() > USEFULL_PEER_SCORE_THRESHOLD) {
LOG.debug("Disconnected USEFULL peer {}", peer);
LOG.info("Disconnected USEFULL peer {}", peer);
} else {
LOG.debug("Disconnected EthPeer {}", peer.getLoggableId());
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public Optional<EthPeer> bestPeerMatchingCriteria(final Predicate<EthPeer> match
}

public void setBestChainComparator(final Comparator<EthPeer> comparator) {
LOG.info("Updating the default best peer comparator");
LOG.info("Updating the default best peer comparator to " + comparator.toString());
bestPeerComparator = comparator;
}

Expand Down Expand Up @@ -380,23 +380,6 @@ public boolean shouldConnect(final Peer peer, final boolean inbound) {
return true;
}

public void disconnectWorstUselessPeer() {
streamAvailablePeers()
.sorted(getBestChainComparator())
.findFirst()
.ifPresent(
peer -> {
LOG.atDebug()
.setMessage(
"disconnecting peer {}. Waiting for better peers. Current {} of max {}")
.addArgument(peer::getLoggableId)
.addArgument(this::peerCount)
.addArgument(this::getMaxPeers)
.log();
peer.disconnect(DisconnectMessage.DisconnectReason.USELESS_PEER_BY_CHAIN_COMPARATOR);
});
}

@FunctionalInterface
public interface ConnectCallback {
void onPeerConnected(EthPeer newPeer);
Expand Down
Expand Up @@ -143,7 +143,6 @@ private void updatePeerChainState(final EthPeer peer, final BlockHeader blockHea
.log();
peer.chainState().update(blockHeader);
}
LOG.trace("Peer chain state {}", peer.chainState());
}

protected abstract boolean matchesFirstHeader(BlockHeader firstHeader);
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void enforceTrailingPeerLimit() {
final EthPeer peerToDisconnect = trailingPeers.remove(0);
LOG.atDebug()
.setMessage(
"Enforcing trailing peers limit (min height {}, max trailing peers {}) by disconnecting {}... with height {}")
"Enforcing trailing peers limit (min height {}, max trailing peers {}) by disconnecting {} with height {}")
.addArgument(minimumHeightToBeUpToDate)
.addArgument(maxTrailingPeers)
.addArgument(peerToDisconnect::getLoggableId)
Expand Down
Expand Up @@ -19,8 +19,11 @@
import java.util.Objects;

import com.google.common.base.MoreObjects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TrailingPeerRequirements {
private static final Logger LOG = LoggerFactory.getLogger(TrailingPeerRequirements.class);
public static TrailingPeerRequirements UNRESTRICTED =
new TrailingPeerRequirements(BlockHeader.GENESIS_BLOCK_NUMBER, Long.MAX_VALUE);
private final long minimumHeightToBeUpToDate;
Expand All @@ -30,6 +33,7 @@ public TrailingPeerRequirements(
final long minimumHeightToBeUpToDate, final long maxTrailingPeers) {
this.minimumHeightToBeUpToDate = minimumHeightToBeUpToDate;
this.maxTrailingPeers = maxTrailingPeers;
LOG.info("trailing peer requirements {}", this);
}

public long getMinimumHeightToBeUpToDate() {
Expand Down
Expand Up @@ -163,7 +163,7 @@ public void deleteFastSyncState() {
protected FastSyncState updateMaxTrailingPeers(final FastSyncState state) {
if (state.getPivotBlockNumber().isPresent()) {
trailingPeerRequirements =
Optional.of(new TrailingPeerRequirements(state.getPivotBlockNumber().getAsLong(), 0));
Optional.of(new TrailingPeerRequirements(state.getPivotBlockNumber().getAsLong(), 5));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is, we should probably eliminate this TrailingPeer validation (since there's no garantee that peers are going to have their chain height estimate up-to-date) but for test purpose we can easily skip the trailing validation by assigning Long.MAX_VALUE to the second param of the TrailingPeerRequirements constructor

} else {
trailingPeerRequirements = Optional.empty();
}
Expand Down
Expand Up @@ -93,19 +93,12 @@ protected CompletableFuture<Optional<EthPeer>> selectBestAvailableSyncTarget() {
return completedFuture(Optional.empty());
} else {
final EthPeer bestPeer = maybeBestPeer.get();
if (bestPeer.chainState().getEstimatedHeight() < pivotBlockHeader.getNumber()) {
LOG.info(
"Best peer {} has chain height {} below pivotBlock height {}. Waiting for better peers. Current {} of max {}",
maybeBestPeer.map(EthPeer::getLoggableId).orElse("none"),
maybeBestPeer.map(p -> p.chainState().getEstimatedHeight()).orElse(-1L),
pivotBlockHeader.getNumber(),
ethPeers.peerCount(),
ethPeers.getMaxPeers());
ethPeers.disconnectWorstUselessPeer();
return completedFuture(Optional.empty());
} else {
return confirmPivotBlockHeader(bestPeer);
}
LOG.debug(
"attempting to confirm pivot block {} with best peer {}",
pivotBlockHeader.getNumber(),
bestPeer);

return confirmPivotBlockHeader(bestPeer);
}
}

Expand Down Expand Up @@ -142,6 +135,11 @@ private CompletableFuture<Optional<EthPeer>> confirmPivotBlockHeader(final EthPe
pivotBlockHeader.toLogString());
return confirmPivotBlockHeader(bestPeer);
} else {
LOG.debug(
"Confirmed pivot block {} with peer {}",
pivotBlockHeader.getNumber(),
bestPeer.getLoggableId());
bestPeer.chainState().updateHeightEstimate(pivotBlockHeader.getNumber());
return CompletableFuture.completedFuture(Optional.of(bestPeer));
}
})
Expand Down
Expand Up @@ -564,7 +564,7 @@ public void shouldNotAllowPeersBeforePivotBlockOnceSelected(

downloader.start();
Assertions.assertThat(downloader.calculateTrailingPeerRequirements())
.contains(new TrailingPeerRequirements(50, 0));
.contains(new TrailingPeerRequirements(50, 5));
}

@ParameterizedTest
Expand Down
Expand Up @@ -118,7 +118,6 @@ public enum DisconnectReason {
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