-
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
Changes from 6 commits
1f22b20
ecdcad2
7aac01e
f0ad746
e3590a1
deb864b
f7851b3
cabf95c
d91bd51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
|
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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; | ||
import org.hyperledger.besu.ethereum.eth.messages.EthPV62; | ||
import org.hyperledger.besu.ethereum.eth.messages.StatusMessage; | ||
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; | ||
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidatorRunner; | ||
import org.hyperledger.besu.ethereum.eth.sync.BlockBroadcaster; | ||
import org.hyperledger.besu.ethereum.p2p.network.ProtocolManager; | ||
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; | ||
|
@@ -66,17 +68,20 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { | |
private List<Capability> supportedCapabilities; | ||
private final Blockchain blockchain; | ||
private final BlockBroadcaster blockBroadcaster; | ||
private final List<PeerValidator> peerValidators; | ||
|
||
public EthProtocolManager( | ||
final Blockchain blockchain, | ||
final WorldStateArchive worldStateArchive, | ||
final BigInteger networkId, | ||
final List<PeerValidator> peerValidators, | ||
final boolean fastSyncEnabled, | ||
final EthScheduler scheduler, | ||
final EthProtocolConfiguration ethereumWireProtocolConfiguration, | ||
final Clock clock, | ||
final MetricsSystem metricsSystem) { | ||
this.networkId = networkId; | ||
this.peerValidators = peerValidators; | ||
this.scheduler = scheduler; | ||
this.blockchain = blockchain; | ||
this.fastSyncEnabled = fastSyncEnabled; | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
PeerValidatorRunner.runValidator(ethContext, peerValidator); | ||
} | ||
|
||
// Set up request handlers | ||
new EthServer(blockchain, worldStateArchive, ethMessages, ethereumWireProtocolConfiguration); | ||
} | ||
|
@@ -98,6 +108,7 @@ public EthProtocolManager( | |
final Blockchain blockchain, | ||
final WorldStateArchive worldStateArchive, | ||
final BigInteger networkId, | ||
final List<PeerValidator> peerValidators, | ||
final boolean fastSyncEnabled, | ||
final int syncWorkers, | ||
final int txWorkers, | ||
|
@@ -108,6 +119,7 @@ public EthProtocolManager( | |
blockchain, | ||
worldStateArchive, | ||
networkId, | ||
peerValidators, | ||
fastSyncEnabled, | ||
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem), | ||
EthProtocolConfiguration.defaultConfig(), | ||
|
@@ -119,6 +131,7 @@ public EthProtocolManager( | |
final Blockchain blockchain, | ||
final WorldStateArchive worldStateArchive, | ||
final BigInteger networkId, | ||
final List<PeerValidator> peerValidators, | ||
final boolean fastSyncEnabled, | ||
final int syncWorkers, | ||
final int txWorkers, | ||
|
@@ -130,6 +143,7 @@ public EthProtocolManager( | |
blockchain, | ||
worldStateArchive, | ||
networkId, | ||
peerValidators, | ||
fastSyncEnabled, | ||
new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem), | ||
ethereumWireProtocolConfiguration, | ||
|
@@ -212,7 +226,7 @@ public void processMessage(final Capability cap, final Message message) { | |
|
||
@Override | ||
public void handleNewConnection(final PeerConnection connection) { | ||
ethPeers.registerConnection(connection); | ||
ethPeers.registerConnection(connection, peerValidators); | ||
final EthPeer peer = ethPeers.peer(connection); | ||
if (peer.statusHasBeenSentToPeer()) { | ||
return; | ||
|
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.