Search in sources :

Example 1 with PeerValidator

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;
}
Also used : RequiredBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator) PeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator) OptionalLong(java.util.OptionalLong) Hash(org.hyperledger.besu.datatypes.Hash) RequiredBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator)

Example 2 with PeerValidator

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;
}
Also used : CheckpointBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator) ArrayList(java.util.ArrayList) ClassicForkPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator) Hash(org.hyperledger.besu.datatypes.Hash) DaoForkPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.DaoForkPeerValidator) ClassicForkPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator) CheckpointBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator) RequiredBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator) PeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator) DaoForkPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.DaoForkPeerValidator) OptionalLong(java.util.OptionalLong) CheckpointConfigOptions(org.hyperledger.besu.config.CheckpointConfigOptions) OptionalLong(java.util.OptionalLong) Map(java.util.Map) RequiredBlocksPeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator)

Example 3 with PeerValidator

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()));
}
Also used : PeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Responder(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder) Test(org.junit.Test)

Example 4 with PeerValidator

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NodeMessagePermissioningProvider(org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider) Bytes(org.apache.tuweni.bytes.Bytes) Collections.singletonList(java.util.Collections.singletonList) NodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) PeerInfo(org.hyperledger.besu.ethereum.p2p.rlpx.wire.PeerInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Collections.emptyList(java.util.Collections.emptyList) PingMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.PingMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) BlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.BlockBodiesMessage) Mockito.verify(org.mockito.Mockito.verify) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) Consumer(java.util.function.Consumer) PeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator) List(java.util.List) Stream(java.util.stream.Stream) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) PeerNotConnected(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection.PeerNotConnected) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) Mockito.mock(org.mockito.Mockito.mock) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection)

Example 5 with PeerValidator

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();
}
Also used : PeerValidator(org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator) Test(org.junit.Test)

Aggregations

PeerValidator (org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator)9 ArrayList (java.util.ArrayList)4 OptionalLong (java.util.OptionalLong)4 Test (org.junit.Test)4 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)3 RequiredBlocksPeerValidator (org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator)3 Hash (org.hyperledger.besu.datatypes.Hash)2 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)2 CheckpointBlocksPeerValidator (org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator)2 ClassicForkPeerValidator (org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator)2 DaoForkPeerValidator (org.hyperledger.besu.ethereum.eth.peervalidation.DaoForkPeerValidator)2 Closeable (java.io.Closeable)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1