use of org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator in project besu by hyperledger.
the class MergeBesuControllerBuilder method createPeerValidators.
@Override
protected List<PeerValidator> createPeerValidators(final ProtocolSchedule protocolSchedule) {
List<PeerValidator> retval = super.createPeerValidators(protocolSchedule);
final OptionalLong powTerminalBlockNumber = configOptionsSupplier.get().getTerminalBlockNumber();
final Optional<Hash> powTerminalBlockHash = configOptionsSupplier.get().getTerminalBlockHash();
if (powTerminalBlockHash.isPresent() && powTerminalBlockNumber.isPresent()) {
retval.add(new RequiredBlocksPeerValidator(protocolSchedule, metricsSystem, powTerminalBlockNumber.getAsLong(), powTerminalBlockHash.get(), 0));
} else {
LOG.debug("unable to validate peers with terminal difficulty blocks");
}
return retval;
}
use of org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator in project besu by hyperledger.
the class BesuControllerBuilder method createPeerValidators.
protected List<PeerValidator> createPeerValidators(final ProtocolSchedule protocolSchedule) {
final List<PeerValidator> validators = new ArrayList<>();
final OptionalLong daoBlock = configOptionsSupplier.get().getDaoForkBlock();
if (daoBlock.isPresent()) {
// Setup dao validator
validators.add(new DaoForkPeerValidator(protocolSchedule, metricsSystem, daoBlock.getAsLong()));
}
final OptionalLong classicBlock = configOptionsSupplier.get().getClassicForkBlock();
// setup classic validator
if (classicBlock.isPresent()) {
validators.add(new ClassicForkPeerValidator(protocolSchedule, metricsSystem, classicBlock.getAsLong()));
}
for (final Map.Entry<Long, Hash> requiredBlock : requiredBlocks.entrySet()) {
validators.add(new RequiredBlocksPeerValidator(protocolSchedule, metricsSystem, requiredBlock.getKey(), requiredBlock.getValue()));
}
final CheckpointConfigOptions checkpointConfigOptions = genesisConfig.getConfigOptions(genesisConfigOverrides).getCheckpointOptions();
if (SyncMode.X_CHECKPOINT.equals(syncConfig.getSyncMode()) && checkpointConfigOptions.isValid()) {
validators.add(new CheckpointBlocksPeerValidator(protocolSchedule, metricsSystem, checkpointConfigOptions.getNumber().orElseThrow(), checkpointConfigOptions.getHash().map(Hash::fromHexString).orElseThrow()));
}
return validators;
}
use of org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator in project besu by hyperledger.
the class PivotBlockRetrieverTest method shouldIgnorePeersThatAreNotFullyValidated.
@Test
public void shouldIgnorePeersThatAreNotFullyValidated() {
final PeerValidator peerValidator = mock(PeerValidator.class);
final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(blockchain, protocolContext.getWorldStateArchive(), transactionPool);
final RespondingEthPeer respondingPeerA = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000, peerValidator);
final RespondingEthPeer badPeerA = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000, peerValidator);
final RespondingEthPeer badPeerB = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000, peerValidator);
// Mark peerA valid
respondingPeerA.getEthPeer().markValidated(peerValidator);
final CompletableFuture<FastSyncState> future = pivotBlockRetriever.downloadPivotBlockHeader();
respondingPeerA.respond(responder);
// With only one peer with sufficient height, we should not be done yet
assertThat(future).isNotCompleted();
// Check that invalid peers were not queried
assertThat(badPeerA.hasOutstandingRequests()).isFalse();
assertThat(badPeerB.hasOutstandingRequests()).isFalse();
// Add new peer that we can query
final RespondingEthPeer respondingPeerB = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000, peerValidator);
respondingPeerB.getEthPeer().markValidated(peerValidator);
// When our new peer "connects", it is not yet valid, so we need to expire our retry timeout
// so that the peer will get re-processed
EthProtocolManagerTestUtil.expirePendingTimeouts(ethProtocolManager);
assertThat(respondingPeerB.hasOutstandingRequests()).isTrue();
respondingPeerB.respond(responder);
// We need one more responsive peer before we're done
assertThat(future).isNotCompleted();
assertThat(badPeerA.hasOutstandingRequests()).isFalse();
assertThat(badPeerB.hasOutstandingRequests()).isFalse();
// Add new peer that we can query
final RespondingEthPeer respondingPeerC = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000, peerValidator);
respondingPeerC.getEthPeer().markValidated(peerValidator);
EthProtocolManagerTestUtil.expirePendingTimeouts(ethProtocolManager);
assertThat(respondingPeerC.hasOutstandingRequests()).isTrue();
respondingPeerC.respond(responder);
assertThat(badPeerA.hasOutstandingRequests()).isFalse();
assertThat(badPeerB.hasOutstandingRequests()).isFalse();
assertThat(future).isCompletedWithValue(new FastSyncState(blockchain.getBlockHeader(PIVOT_BLOCK_NUMBER).get()));
}
use of org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator in project besu by hyperledger.
the class EthPeerTest method createPeer.
private EthPeer createPeer(final List<PeerValidator> peerValidators, final List<NodeMessagePermissioningProvider> permissioningProviders) {
final PeerConnection peerConnection = mock(PeerConnection.class);
final Consumer<EthPeer> onPeerReady = (peer) -> {
};
// that extend the sub-protocol work correctly
return new EthPeer(peerConnection, "foo", onPeerReady, peerValidators, clock, permissioningProviders);
}
use of org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator in project besu by hyperledger.
the class EthPeerTest method isFullyValidated_singleValidator_notValidated.
@Test
public void isFullyValidated_singleValidator_notValidated() {
final PeerValidator validator = mock(PeerValidator.class);
final EthPeer peer = createPeer(validator);
assertThat(peer.isFullyValidated()).isFalse();
}
Aggregations