Search in sources :

Example 1 with BlockAddedEvent

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);
}
Also used : BlockAddedEvent(org.hyperledger.besu.ethereum.chain.BlockAddedEvent) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) Test(org.junit.Test)

Example 2 with BlockAddedEvent

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);
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) BlockAddedEvent(org.hyperledger.besu.ethereum.chain.BlockAddedEvent) Block(org.hyperledger.besu.ethereum.core.Block) Test(org.junit.Test)

Example 3 with BlockAddedEvent

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()));
    });
}
Also used : TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) PrivateTransactionEvent(org.hyperledger.besu.ethereum.privacy.PrivateTransactionEvent) Collections.emptyList(java.util.Collections.emptyList) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) PrivacyQueries(org.hyperledger.besu.ethereum.api.query.PrivacyQueries) List(java.util.List) PrivateTransactionObserver(org.hyperledger.besu.ethereum.privacy.PrivateTransactionObserver) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) AbstractVerticle(io.vertx.core.AbstractVerticle) BlockParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter) Optional(java.util.Optional) BlockAddedEvent(org.hyperledger.besu.ethereum.chain.BlockAddedEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Hash(org.hyperledger.besu.datatypes.Hash) Optional(java.util.Optional) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) LogsQuery(org.hyperledger.besu.ethereum.api.query.LogsQuery) Hash(org.hyperledger.besu.datatypes.Hash)

Example 4 with BlockAddedEvent

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;
}
Also used : BlockAddedEvent(org.hyperledger.besu.ethereum.chain.BlockAddedEvent) Block(org.hyperledger.besu.ethereum.core.Block) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator)

Example 5 with BlockAddedEvent

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

Aggregations

BlockAddedEvent (org.hyperledger.besu.ethereum.chain.BlockAddedEvent)6 Test (org.junit.Test)4 Block (org.hyperledger.besu.ethereum.core.Block)3 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)2 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)1 Hash (org.hyperledger.besu.datatypes.Hash)1 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)1 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)1 LogsQuery (org.hyperledger.besu.ethereum.api.query.LogsQuery)1 PrivacyQueries (org.hyperledger.besu.ethereum.api.query.PrivacyQueries)1