-
Notifications
You must be signed in to change notification settings - Fork 870
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
[PAN-2333] Use only fully validated peers for fast sync pivot selection #21
Conversation
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
Signed-off-by: Meredith Baxter <[email protected]>
…ble-to-synchronizer
ethProtocolManager = createEthProtocolManager(protocolContext, fastSyncEnabled); | ||
ethProtocolManager = | ||
createEthProtocolManager( | ||
protocolContext, fastSyncEnabled, createPeerValidators(protocolSchedule)); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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]>
PR description
Expose
EthPeer
validation state so that theSynchronizer
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.