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

[PAN-2333] Use only fully validated peers for fast sync pivot selection #21

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Sep 18, 2019

PR description

Expose EthPeer validation state so that the Synchronizer can choose peers based on whether or not they have been fully validated. This allows us to use only fully validated peers when choosing a pivot block.

ethProtocolManager = createEthProtocolManager(protocolContext, fastSyncEnabled);
ethProtocolManager =
createEthProtocolManager(
protocolContext, fastSyncEnabled, createPeerValidators(protocolSchedule));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move validator management into EthProtocolManager so that every EthPeer can track its validation state.

@@ -52,28 +55,6 @@ public Istanbul64ProtocolManager(
ethereumWireProtocolConfiguration);
}

public Istanbul64ProtocolManager(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dead code

@@ -86,6 +90,30 @@ protected boolean removeEldestEntry(final Map.Entry<Hash, Boolean> eldest) {
}));
this.chainHeadState = new ChainState();
this.onStatusesExchanged.set(onStatusesExchanged);
for (PeerValidator peerValidator : peerValidators) {
validationStatus.put(peerValidator, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Track validation status within each EthPeer.

}

@Override
public CompletableFuture<Boolean> validatePeer(final EthPeer ethPeer) {
public CompletableFuture<Boolean> validatePeer(
final EthContext ethContext, final EthPeer ethPeer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validators are constructed before EthProtocolManager, so EthContext must be passed in.

}

public static RespondingEthPeer create(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replace factory methods with a Builder.

@mbaxter mbaxter marked this pull request as ready for review September 18, 2019 14:30
Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -90,6 +95,11 @@ public EthProtocolManager(

this.blockBroadcaster = new BlockBroadcaster(ethContext);

// Run validators
for (final PeerValidator peerValidator : this.peerValidators) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: How fast is the validation ? Is it worth validating in parallel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The runValidator method just sets up a listener, so I think we should be fine with a plain loop here.

@@ -113,15 +114,15 @@ public FastSyncActions(
private CompletableFuture<FastSyncState> selectPivotBlockFromPeers() {
return ethContext
.getEthPeers()
.bestPeerWithHeightEstimate()
.bestPeerMatchingCriteria(this::canPeerDeterminePivotBlock)
Copy link
Contributor

Choose a reason for hiding this comment

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

Super readable 🎉

}

@Test
public void checkPeer_doesNotScheduleFutureCheckWhenPeerNotReadyAndDisconnected() {
PeerValidator validator = mock(PeerValidator.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 updated!

EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
EthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager).getEthPeer();
EthPeer peer =
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

verify(runner, never()).disconnectPeer(eq(peer));
verify(runner, times(0)).scheduleNextCheck(eq(peer));
}

@Test
public void checkPeer_handlesInvalidPeer() {
PeerValidator validator = mock(PeerValidator.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
EthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager).getEthPeer();
EthPeer peer =
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

}

@Test
public void checkPeer_handlesValidPeer() {
PeerValidator validator = mock(PeerValidator.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager);
EthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager).getEthPeer();
EthPeer peer =
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) make the variable final

Signed-off-by: Meredith Baxter <[email protected]>
@shemnon shemnon merged commit 5d1d3be into hyperledger:master Sep 18, 2019
garyschulte pushed a commit to garyschulte/besu that referenced this pull request Jan 5, 2024
fab-10 pushed a commit to fab-10/besu that referenced this pull request Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants