use of org.hyperledger.besu.ethereum.chain.BlockAddedEvent in project besu by hyperledger.
the class BftMiningCoordinatorTest method addsNewChainHeadEventWhenNewCanonicalHeadBlockEventReceived.
@Test
public void addsNewChainHeadEventWhenNewCanonicalHeadBlockEventReceived() throws Exception {
BlockAddedEvent headAdvancement = BlockAddedEvent.createForHeadAdvancement(block, Collections.emptyList(), Collections.emptyList());
bftMiningCoordinator.onBlockAdded(headAdvancement);
assertThat(eventQueue.size()).isEqualTo(1);
final NewChainHead ibftEvent = (NewChainHead) eventQueue.poll(1, TimeUnit.SECONDS);
assertThat(ibftEvent.getNewChainHeadHeader()).isEqualTo(blockHeader);
}
use of org.hyperledger.besu.ethereum.chain.BlockAddedEvent in project besu by hyperledger.
the class TrailingPeerLimiterTest method shouldRecheckTrailingPeersWhenBlockAddedThatIsMultipleOf100.
@Test
public void shouldRecheckTrailingPeersWhenBlockAddedThatIsMultipleOf100() {
final EthPeer ethPeer1 = addPeerWithEstimatedHeight(1);
addPeerWithEstimatedHeight(3);
addPeerWithEstimatedHeight(2);
final BlockAddedEvent blockAddedEvent = BlockAddedEvent.createForHeadAdvancement(new Block(new BlockHeaderTestFixture().number(500).buildHeader(), new BlockBody(emptyList(), emptyList())), Collections.emptyList(), Collections.emptyList());
trailingPeerLimiter.onBlockAdded(blockAddedEvent);
assertDisconnections(ethPeer1);
}
use of org.hyperledger.besu.ethereum.chain.BlockAddedEvent in project besu by hyperledger.
the class FilterManager method recordBlockEvent.
public void recordBlockEvent(final BlockAddedEvent event) {
final Hash blockHash = event.getBlock().getHash();
final Collection<BlockFilter> blockFilters = filterRepository.getFiltersOfType(BlockFilter.class);
blockFilters.forEach(filter -> {
synchronized (filter) {
filter.addBlockHash(blockHash);
}
});
removalEvents.stream().forEach(removalEvent -> processRemovalEvent(removalEvent));
removalEvents.clear();
final List<LogWithMetadata> logsWithMetadata = event.getLogsWithMetadata();
filterRepository.getFiltersOfType(LogFilter.class).stream().filter(// Only keep filters where the "to" block could include the block in the event
filter -> {
final Optional<Long> maybeToBlockNumber = filter.getToBlock().getNumber();
return maybeToBlockNumber.isEmpty() || maybeToBlockNumber.get() >= event.getBlock().getHeader().getNumber();
}).forEach(filter -> {
final LogsQuery logsQuery = filter.getLogsQuery();
filter.addLogs(// log filters we already have all the info in the event
filter instanceof PrivateLogFilter ? privacyQueries.map(pq -> pq.matchingLogs(((PrivateLogFilter) filter).getPrivacyGroupId(), blockHash, logsQuery)).orElse(emptyList()) : logsWithMetadata.stream().filter(logsQuery::matches).collect(toUnmodifiableList()));
});
}
use of org.hyperledger.besu.ethereum.chain.BlockAddedEvent in project besu by hyperledger.
the class FilterManagerLogFilterTest method recordBlockEvents.
private List<BlockAddedEvent> recordBlockEvents(final int numEvents) {
final BlockDataGenerator gen = new BlockDataGenerator();
final List<BlockAddedEvent> blockAddedEvents = Stream.generate(() -> {
final Block block = gen.block(new BlockDataGenerator.BlockOptions().setBlockNumber(3));
return BlockAddedEvent.createForHeadAdvancement(block, LogWithMetadata.generate(block, gen.receipts(block), false), emptyList());
}).limit(numEvents).collect(toUnmodifiableList());
blockAddedEvents.forEach(event -> filterManager.recordBlockEvent(event));
return blockAddedEvents;
}
use of org.hyperledger.besu.ethereum.chain.BlockAddedEvent in project besu by hyperledger.
the class BftMiningCoordinatorTest method doesntAddNewChainHeadEventWhenNotACanonicalHeadBlockEvent.
@Test
public void doesntAddNewChainHeadEventWhenNotACanonicalHeadBlockEvent() {
final BlockAddedEvent fork = BlockAddedEvent.createForFork(block);
bftMiningCoordinator.onBlockAdded(fork);
assertThat(eventQueue.isEmpty()).isTrue();
}
Aggregations