-
Notifications
You must be signed in to change notification settings - Fork 879
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
Merged
shemnon
merged 9 commits into
hyperledger:master
from
mbaxter:PAN-2333/make-peer-validation-state-available-to-synchronizer
Sep 18, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1f22b20
Move peer validation management into EthProtocolManager
mbaxter ecdcad2
Remove dead code
mbaxter 7aac01e
Expose validation status on EthPeer
mbaxter f0ad746
Simplify validation tracking
mbaxter e3590a1
Update pivot selection logic to only use fully validated peers
mbaxter deb864b
Move PeerValidatorRunner back to validation package
mbaxter f7851b3
Fix RunnerTest
mbaxter cabf95c
Merge branch 'master' into PAN-2333/make-peer-validation-state-availa…
mbaxter d91bd51
Add final's
mbaxter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; | ||
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; | ||
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; | ||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability; | ||
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; | ||
import org.hyperledger.besu.plugin.services.MetricsSystem; | ||
|
@@ -32,6 +33,7 @@ public Istanbul64ProtocolManager( | |
final Blockchain blockchain, | ||
final WorldStateArchive worldStateArchive, | ||
final BigInteger networkId, | ||
final List<PeerValidator> peerValidators, | ||
final boolean fastSyncEnabled, | ||
final int syncWorkers, | ||
final int txWorkers, | ||
|
@@ -43,6 +45,7 @@ public Istanbul64ProtocolManager( | |
blockchain, | ||
worldStateArchive, | ||
networkId, | ||
peerValidators, | ||
fastSyncEnabled, | ||
syncWorkers, | ||
txWorkers, | ||
|
@@ -52,28 +55,6 @@ public Istanbul64ProtocolManager( | |
ethereumWireProtocolConfiguration); | ||
} | ||
|
||
public Istanbul64ProtocolManager( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
final Blockchain blockchain, | ||
final WorldStateArchive worldStateArchive, | ||
final BigInteger networkId, | ||
final boolean fastSyncEnabled, | ||
final int syncWorkers, | ||
final int txWorkers, | ||
final int computationWorkers, | ||
final Clock clock, | ||
final MetricsSystem metricsSystem) { | ||
super( | ||
blockchain, | ||
worldStateArchive, | ||
networkId, | ||
fastSyncEnabled, | ||
syncWorkers, | ||
txWorkers, | ||
computationWorkers, | ||
clock, | ||
metricsSystem); | ||
} | ||
|
||
@Override | ||
public List<Capability> getSupportedCapabilities() { | ||
return singletonList(Istanbul64Protocol.ISTANBUL64); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage; | ||
import org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage; | ||
import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; | ||
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; | ||
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; | ||
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection.PeerNotConnected; | ||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; | ||
|
@@ -30,6 +31,7 @@ | |
|
||
import java.time.Clock; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -66,11 +68,13 @@ public class EthPeer { | |
|
||
private final AtomicReference<Consumer<EthPeer>> onStatusesExchanged = new AtomicReference<>(); | ||
private final PeerReputation reputation = new PeerReputation(); | ||
private final Map<PeerValidator, Boolean> validationStatus = new HashMap<>(); | ||
|
||
EthPeer( | ||
final PeerConnection connection, | ||
final String protocolName, | ||
final Consumer<EthPeer> onStatusesExchanged, | ||
final List<PeerValidator> peerValidators, | ||
final Clock clock) { | ||
this.connection = connection; | ||
this.protocolName = protocolName; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Track validation status within each |
||
} | ||
} | ||
|
||
public void markValidated(final PeerValidator validator) { | ||
if (!validationStatus.containsKey(validator)) { | ||
throw new IllegalArgumentException("Attempt to update unknown validation status"); | ||
} | ||
validationStatus.put(validator, true); | ||
} | ||
|
||
/** | ||
* Check if this peer has been fully validated. | ||
* | ||
* @return {@code true} if all peer validation logic has run and successfully validated this peer | ||
*/ | ||
public boolean isFullyValidated() { | ||
for (Boolean isValid : validationStatus.values()) { | ||
if (!isValid) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public boolean isDisconnected() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 everyEthPeer
can track its validation state.