use of org.hyperledger.besu.ethereum.eth.sync.ValidationPolicy in project besu by hyperledger.
the class DownloadHeaderSequenceTaskTest method failsWhenPeerReturnsOnlySubsetOfHeaders.
@Test
public void failsWhenPeerReturnsOnlySubsetOfHeaders() {
final RespondingEthPeer respondingPeer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
// Execute task and wait for response
final BlockHeader referenceHeader = blockchain.getChainHeadHeader();
final EthTask<List<BlockHeader>> task = DownloadHeaderSequenceTask.endingAtHeader(protocolSchedule, protocolContext, ethContext, referenceHeader, 10, maxRetries, validationPolicy, metricsSystem);
final CompletableFuture<List<BlockHeader>> future = task.run();
// Filter response to include only reference header and previous header
final RespondingEthPeer.Responder fullResponder = RespondingEthPeer.blockchainResponder(blockchain);
final RespondingEthPeer.Responder responder = (cap, message) -> {
final Optional<MessageData> fullResponse = fullResponder.respond(cap, message);
if (!fullResponse.isPresent() || message.getCode() != EthPV62.GET_BLOCK_HEADERS) {
return fullResponse;
}
final BlockHeadersMessage headersMessage = BlockHeadersMessage.readFrom(fullResponse.get());
// Filter for a subset of headers
final List<BlockHeader> headerSubset = headersMessage.getHeaders(protocolSchedule).stream().filter(h -> h.getNumber() >= referenceHeader.getNumber() - 1L).collect(Collectors.toList());
return Optional.of(BlockHeadersMessage.create(headerSubset));
};
respondingPeer.respondTimes(responder, 100);
assertThat(future.isDone()).isTrue();
assertThat(future.isCompletedExceptionally()).isTrue();
assertThatThrownBy(future::get).hasCauseInstanceOf(MaxRetriesReachedException.class);
}
use of org.hyperledger.besu.ethereum.eth.sync.ValidationPolicy in project besu by hyperledger.
the class DownloadHeaderSequenceTaskTest method failsWhenPeerReturnsOnlyReferenceHeader.
@Test
public void failsWhenPeerReturnsOnlyReferenceHeader() {
final RespondingEthPeer respondingPeer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
// Execute task and wait for response
final BlockHeader referenceHeader = blockchain.getChainHeadHeader();
final EthTask<List<BlockHeader>> task = DownloadHeaderSequenceTask.endingAtHeader(protocolSchedule, protocolContext, ethContext, referenceHeader, 10, maxRetries, validationPolicy, metricsSystem);
final CompletableFuture<List<BlockHeader>> future = task.run();
// Respond with only the reference header
final RespondingEthPeer.Responder responder = (cap, message) -> Optional.of(BlockHeadersMessage.create(Collections.singletonList(referenceHeader)));
respondingPeer.respondWhile(responder, () -> !future.isDone());
assertThat(future.isDone()).isTrue();
assertThat(future.isCompletedExceptionally()).isTrue();
assertThatThrownBy(future::get).hasCauseInstanceOf(MaxRetriesReachedException.class);
}
use of org.hyperledger.besu.ethereum.eth.sync.ValidationPolicy in project besu by hyperledger.
the class FastImportBlocksStepTest method shouldImportBlocks.
@Test
public void shouldImportBlocks() {
final List<Block> blocks = gen.blockSequence(5);
final List<BlockWithReceipts> blocksWithReceipts = blocks.stream().map(block -> new BlockWithReceipts(block, gen.receipts(block))).collect(toList());
for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) {
when(blockImporter.fastImportBlock(protocolContext, blockWithReceipts.getBlock(), blockWithReceipts.getReceipts(), FULL, LIGHT)).thenReturn(true);
}
importBlocksStep.accept(blocksWithReceipts);
for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) {
verify(protocolSchedule).getByBlockNumber(blockWithReceipts.getNumber());
}
verify(validationPolicy, times(blocks.size())).getValidationModeForNextBlock();
}
Aggregations