Search in sources :

Example 1 with EthPV63

use of org.hyperledger.besu.ethereum.eth.messages.EthPV63 in project besu by hyperledger.

the class FastWorldStateDownloaderTest method resumesFromNonEmptyQueue.

@Test
public void resumesFromNonEmptyQueue() {
    // Setup "remote" state
    final WorldStateStorage remoteStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage());
    final WorldStateArchive remoteWorldStateArchive = new DefaultWorldStateArchive(remoteStorage, createPreimageStorage());
    final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable();
    // Generate accounts and save corresponding state root
    List<Account> accounts = dataGen.createRandomAccounts(remoteWorldState, 10);
    final Hash stateRoot = remoteWorldState.rootHash();
    // Sanity check
    assertThat(stateRoot).isNotEqualTo(EMPTY_TRIE_ROOT);
    final BlockHeader header = dataGen.block(BlockOptions.create().setStateRoot(stateRoot).setBlockNumber(10)).getHeader();
    // Add some nodes to the taskCollection
    final InMemoryTasksPriorityQueues<NodeDataRequest> taskCollection = spy(new InMemoryTasksPriorityQueues<>());
    List<Bytes32> queuedHashes = getFirstSetOfChildNodeRequests(remoteStorage, stateRoot);
    // Sanity check
    assertThat(queuedHashes.size()).isGreaterThan(0);
    for (Bytes32 bytes32 : queuedHashes) {
        taskCollection.add(new AccountTrieNodeDataRequest(Hash.wrap(bytes32), Optional.empty()));
    }
    // Sanity check
    for (final Bytes32 bytes32 : queuedHashes) {
        final Hash hash = Hash.wrap(bytes32);
        verify(taskCollection, times(1)).add(argThat((r) -> r.getHash().equals(hash)));
    }
    final WorldStateStorage localStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage());
    final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().worldStateMaxRequestsWithoutProgress(10).build();
    final WorldStateDownloader downloader = createDownloader(syncConfig, ethProtocolManager.ethContext(), localStorage, taskCollection);
    // Create a peer that can respond
    final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, header.getNumber());
    // Respond to node data requests
    final List<MessageData> sentMessages = new ArrayList<>();
    final RespondingEthPeer.Responder blockChainResponder = RespondingEthPeer.blockchainResponder(mock(Blockchain.class), remoteWorldStateArchive);
    final RespondingEthPeer.Responder responder = RespondingEthPeer.wrapResponderWithCollector(blockChainResponder, sentMessages);
    CompletableFuture<Void> result = downloader.run(null, new FastSyncState(header));
    peer.respondWhileOtherThreadsWork(responder, () -> !result.isDone());
    assertThat(localStorage.isWorldStateAvailable(stateRoot, header.getHash())).isTrue();
    // Check that already enqueued trie nodes were requested
    final List<Bytes32> requestedHashes = sentMessages.stream().filter(m -> m.getCode() == EthPV63.GET_NODE_DATA).map(GetNodeDataMessage::readFrom).flatMap(m -> StreamSupport.stream(m.hashes().spliterator(), true)).collect(Collectors.toList());
    assertThat(requestedHashes.size()).isGreaterThan(0);
    assertThat(requestedHashes).containsAll(queuedHashes);
    // Check that already enqueued requests were not enqueued more than once
    for (Bytes32 bytes32 : queuedHashes) {
        final Hash hash = Hash.wrap(bytes32);
        verify(taskCollection, times(1)).add(argThat((r) -> r.getHash().equals(hash)));
    }
    // Check that all expected account data was downloaded
    assertThat(result).isDone();
    final WorldStateArchive localWorldStateArchive = new DefaultWorldStateArchive(localStorage, createPreimageStorage());
    final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get();
    assertAccountsMatch(localWorldState, accounts);
}
Also used : BlockOptions(org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions) WorldStateKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage) Node(org.hyperledger.besu.ethereum.trie.Node) Account(org.hyperledger.besu.evm.account.Account) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EthProtocolManagerTestUtil(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) StalledDownloadException(org.hyperledger.besu.ethereum.eth.sync.worldstate.StalledDownloadException) Map(java.util.Map) After(org.junit.After) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Bytes32(org.apache.tuweni.bytes.Bytes32) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) InMemoryTasksPriorityQueues(org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues) MockExecutorService(org.hyperledger.besu.testutil.MockExecutorService) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Set(java.util.Set) Collectors(java.util.stream.Collectors) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) LockSupport(java.util.concurrent.locks.LockSupport) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader) List(java.util.List) Stream(java.util.stream.Stream) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) Optional(java.util.Optional) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) StoredMerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.StoredMerklePatriciaTrie) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.spy(org.mockito.Mockito.spy) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TrieNodeDecoder(org.hyperledger.besu.ethereum.trie.TrieNodeDecoder) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Timeout(org.junit.rules.Timeout) WorldStatePreimageKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage) StreamSupport(java.util.stream.StreamSupport) ExecutorService(java.util.concurrent.ExecutorService) WorldState(org.hyperledger.besu.evm.worldstate.WorldState) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) AccountStorageEntry(org.hyperledger.besu.evm.account.AccountStorageEntry) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) Mockito.times(org.mockito.Mockito.times) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) RLP(org.hyperledger.besu.ethereum.rlp.RLP) Test(org.junit.Test) WorldStatePreimageStorage(org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage) MerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.MerklePatriciaTrie) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) Ignore(org.junit.Ignore) DeterministicEthScheduler(org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler) EthPV63(org.hyperledger.besu.ethereum.eth.messages.EthPV63) Updater(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater) Mockito.reset(org.mockito.Mockito.reset) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Account(org.hyperledger.besu.evm.account.Account) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) ArrayList(java.util.ArrayList) WorldState(org.hyperledger.besu.evm.worldstate.WorldState) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Hash(org.hyperledger.besu.datatypes.Hash) Bytes32(org.apache.tuweni.bytes.Bytes32) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader) WorldStateKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Test(org.junit.Test)

Example 2 with EthPV63

use of org.hyperledger.besu.ethereum.eth.messages.EthPV63 in project besu by hyperledger.

the class FastWorldStateDownloaderTest method doesNotRequestKnownStorageTrieNodesFromNetwork.

@Test
public void doesNotRequestKnownStorageTrieNodesFromNetwork() {
    // Setup "remote" state
    final WorldStateStorage remoteStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage());
    final WorldStateArchive remoteWorldStateArchive = new DefaultWorldStateArchive(remoteStorage, createPreimageStorage());
    final MutableWorldState remoteWorldState = remoteWorldStateArchive.getMutable();
    // Generate accounts and save corresponding state root
    final List<Account> accounts = dataGen.createRandomContractAccountsWithNonEmptyStorage(remoteWorldState, 20);
    final Hash stateRoot = remoteWorldState.rootHash();
    final BlockHeader header = dataGen.block(BlockOptions.create().setStateRoot(stateRoot).setBlockNumber(10)).getHeader();
    // Create some peers
    final List<RespondingEthPeer> peers = Stream.generate(() -> EthProtocolManagerTestUtil.createPeer(ethProtocolManager, header.getNumber())).limit(5).collect(Collectors.toList());
    final InMemoryTasksPriorityQueues<NodeDataRequest> taskCollection = new InMemoryTasksPriorityQueues<>();
    final WorldStateStorage localStorage = new WorldStateKeyValueStorage(new InMemoryKeyValueStorage());
    // Seed local storage with some trie node values
    final List<Bytes32> storageRootHashes = new StoredMerklePatriciaTrie<>(remoteStorage::getNodeData, remoteWorldState.rootHash(), Function.identity(), Function.identity()).entriesFrom(Bytes32.ZERO, 5).values().stream().map(RLP::input).map(StateTrieAccountValue::readFrom).map(StateTrieAccountValue::getStorageRoot).collect(Collectors.toList());
    final Map<Bytes32, Bytes> allTrieNodes = new HashMap<>();
    final Set<Bytes32> knownNodes = new HashSet<>();
    final Set<Bytes32> unknownNodes = new HashSet<>();
    for (final Bytes32 storageRootHash : storageRootHashes) {
        allTrieNodes.putAll(collectTrieNodesToBeRequestedAfterRoot(remoteStorage, storageRootHash, 5));
    }
    // Sanity check
    assertThat(allTrieNodes.size()).isGreaterThan(0);
    final Updater localStorageUpdater = localStorage.updater();
    boolean storeNode = true;
    for (final Map.Entry<Bytes32, Bytes> entry : allTrieNodes.entrySet()) {
        final Bytes32 hash = entry.getKey();
        final Bytes data = entry.getValue();
        if (storeNode) {
            localStorageUpdater.putAccountStorageTrieNode(null, null, hash, data);
            knownNodes.add(hash);
        } else {
            unknownNodes.add(hash);
        }
        storeNode = !storeNode;
    }
    localStorageUpdater.commit();
    final WorldStateDownloader downloader = createDownloader(ethProtocolManager.ethContext(), localStorage, taskCollection);
    final FastSyncState fastSyncState = new FastSyncState(header);
    final CompletableFuture<Void> result = downloader.run(null, fastSyncState);
    // Respond to node data requests
    final List<MessageData> sentMessages = new ArrayList<>();
    final RespondingEthPeer.Responder blockChainResponder = RespondingEthPeer.blockchainResponder(mock(Blockchain.class), remoteWorldStateArchive, mock(TransactionPool.class));
    final RespondingEthPeer.Responder responder = RespondingEthPeer.wrapResponderWithCollector(blockChainResponder, sentMessages);
    respondUntilDone(peers, responder, result);
    // World state should be available by the time the result is complete
    assertThat(localStorage.isWorldStateAvailable(stateRoot, header.getHash())).isTrue();
    // Check that unknown trie nodes were requested
    final List<Bytes32> requestedHashes = sentMessages.stream().filter(m -> m.getCode() == EthPV63.GET_NODE_DATA).map(GetNodeDataMessage::readFrom).flatMap(m -> StreamSupport.stream(m.hashes().spliterator(), true)).collect(Collectors.toList());
    assertThat(requestedHashes.size()).isGreaterThan(0);
    assertThat(requestedHashes).containsAll(unknownNodes);
    assertThat(requestedHashes).doesNotContainAnyElementsOf(knownNodes);
    // Check that all expected account data was downloaded
    final WorldStateArchive localWorldStateArchive = new DefaultWorldStateArchive(localStorage, createPreimageStorage());
    final WorldState localWorldState = localWorldStateArchive.get(stateRoot, null).get();
    assertThat(result).isDone();
    assertAccountsMatch(localWorldState, accounts);
}
Also used : BlockOptions(org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions) WorldStateKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage) Node(org.hyperledger.besu.ethereum.trie.Node) Account(org.hyperledger.besu.evm.account.Account) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EthProtocolManagerTestUtil(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) StalledDownloadException(org.hyperledger.besu.ethereum.eth.sync.worldstate.StalledDownloadException) Map(java.util.Map) After(org.junit.After) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Bytes32(org.apache.tuweni.bytes.Bytes32) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) InMemoryTasksPriorityQueues(org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues) MockExecutorService(org.hyperledger.besu.testutil.MockExecutorService) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Set(java.util.Set) Collectors(java.util.stream.Collectors) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) LockSupport(java.util.concurrent.locks.LockSupport) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader) List(java.util.List) Stream(java.util.stream.Stream) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) Optional(java.util.Optional) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) StoredMerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.StoredMerklePatriciaTrie) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.spy(org.mockito.Mockito.spy) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TrieNodeDecoder(org.hyperledger.besu.ethereum.trie.TrieNodeDecoder) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Timeout(org.junit.rules.Timeout) WorldStatePreimageKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage) StreamSupport(java.util.stream.StreamSupport) ExecutorService(java.util.concurrent.ExecutorService) WorldState(org.hyperledger.besu.evm.worldstate.WorldState) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) AccountStorageEntry(org.hyperledger.besu.evm.account.AccountStorageEntry) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) Mockito.times(org.mockito.Mockito.times) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) RLP(org.hyperledger.besu.ethereum.rlp.RLP) Test(org.junit.Test) WorldStatePreimageStorage(org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage) MerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.MerklePatriciaTrie) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) Ignore(org.junit.Ignore) DeterministicEthScheduler(org.hyperledger.besu.ethereum.eth.manager.DeterministicEthScheduler) EthPV63(org.hyperledger.besu.ethereum.eth.messages.EthPV63) Updater(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater) Mockito.reset(org.mockito.Mockito.reset) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Account(org.hyperledger.besu.evm.account.Account) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) HashMap(java.util.HashMap) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) ArrayList(java.util.ArrayList) WorldState(org.hyperledger.besu.evm.worldstate.WorldState) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Hash(org.hyperledger.besu.datatypes.Hash) Bytes32(org.apache.tuweni.bytes.Bytes32) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader) Bytes(org.apache.tuweni.bytes.Bytes) WorldStateKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage) Updater(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) HashSet(java.util.HashSet) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) InMemoryTasksPriorityQueues(org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with EthPV63

use of org.hyperledger.besu.ethereum.eth.messages.EthPV63 in project besu by hyperledger.

the class EthProtocolManagerTest method respondToGetNodeData.

@Test
public void respondToGetNodeData() throws Exception {
    final CompletableFuture<Void> done = new CompletableFuture<>();
    final WorldStateArchive worldStateArchive = protocolContext.getWorldStateArchive();
    try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create(blockchain, () -> false, protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig())) {
        // Setup node data query
        final List<Bytes> expectedResults = new ArrayList<>();
        final List<Hash> requestedHashes = new ArrayList<>();
        final long startBlock = blockchain.getChainHeadBlockNumber() - 5;
        final int blockCount = 2;
        for (int i = 0; i < blockCount; i++) {
            final BlockHeader header = blockchain.getBlockHeader(startBlock + i).get();
            requestedHashes.add(header.getStateRoot());
            expectedResults.add(worldStateArchive.getNodeData(header.getStateRoot()).get());
        }
        final MessageData messageData = GetNodeDataMessage.create(requestedHashes);
        // Define handler to validate response
        final PeerSendHandler onSend = (cap, message, conn) -> {
            if (message.getCode() == EthPV62.STATUS) {
                // Ignore status message
                return;
            }
            assertThat(message.getCode()).isEqualTo(EthPV63.NODE_DATA);
            final NodeDataMessage receiptsMessage = NodeDataMessage.readFrom(message);
            final List<Bytes> nodeData = receiptsMessage.nodeData();
            assertThat(nodeData).hasSize(blockCount);
            for (int i = 0; i < blockCount; i++) {
                assertThat(expectedResults.get(i)).isEqualTo(nodeData.get(i));
            }
            done.complete(null);
        };
        // Run test
        final PeerConnection peer = setupPeer(ethManager, onSend);
        ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, messageData));
        done.get();
    }
}
Also used : TransactionsMessage(org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RawMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BigInteger(java.math.BigInteger) Block(org.hyperledger.besu.ethereum.core.Block) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) ConditionFactory(org.awaitility.core.ConditionFactory) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Set(java.util.Set) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Collectors(java.util.stream.Collectors) BlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.BlockBodiesMessage) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) TransactionPoolFactory(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StatusMessage(org.hyperledger.besu.ethereum.eth.messages.StatusMessage) EthPV62(org.hyperledger.besu.ethereum.eth.messages.EthPV62) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) ArrayList(java.util.ArrayList) NodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) HashSet(java.util.HashSet) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) GetBlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Wei(org.hyperledger.besu.datatypes.Wei) DisconnectReason(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason) ExecutorService(java.util.concurrent.ExecutorService) GetReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) NewBlockMessage(org.hyperledger.besu.ethereum.eth.messages.NewBlockMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) GetBlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockBodiesMessage) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) EthPV63(org.hyperledger.besu.ethereum.eth.messages.EthPV63) Mockito.reset(org.mockito.Mockito.reset) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) ArrayList(java.util.ArrayList) Hash(org.hyperledger.besu.datatypes.Hash) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) NodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage) Bytes(org.apache.tuweni.bytes.Bytes) CompletableFuture(java.util.concurrent.CompletableFuture) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) List(java.util.List) ArrayList(java.util.ArrayList) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) Test(org.junit.Test)

Example 4 with EthPV63

use of org.hyperledger.besu.ethereum.eth.messages.EthPV63 in project besu by hyperledger.

the class EthProtocolManagerTest method respondToGetReceiptsWithinLimits.

@Test
public void respondToGetReceiptsWithinLimits() throws ExecutionException, InterruptedException {
    final CompletableFuture<Void> done = new CompletableFuture<>();
    final int limit = 5;
    try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create(blockchain, () -> false, protocolContext.getWorldStateArchive(), transactionPool, new EthProtocolConfiguration(limit, limit, limit, limit, limit, false))) {
        // Setup blocks query
        final int blockCount = 10;
        final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount;
        final List<List<TransactionReceipt>> expectedReceipts = new ArrayList<>(blockCount);
        final List<Hash> blockHashes = new ArrayList<>(blockCount);
        for (int i = 0; i < blockCount; i++) {
            final BlockHeader header = blockchain.getBlockHeader(startBlock + i).get();
            expectedReceipts.add(blockchain.getTxReceipts(header.getHash()).get());
            blockHashes.add(header.getHash());
        }
        final MessageData messageData = GetReceiptsMessage.create(blockHashes);
        // Define handler to validate response
        final PeerSendHandler onSend = (cap, message, conn) -> {
            if (message.getCode() == EthPV62.STATUS) {
                // Ignore status message
                return;
            }
            assertThat(message.getCode()).isEqualTo(EthPV63.RECEIPTS);
            final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(message);
            final List<List<TransactionReceipt>> receipts = Lists.newArrayList(receiptsMessage.receipts());
            assertThat(receipts).hasSize(limit);
            for (int i = 0; i < limit; i++) {
                assertThat(expectedReceipts.get(i)).isEqualTo(receipts.get(i));
            }
            done.complete(null);
        };
        // Run test
        final PeerConnection peer = setupPeer(ethManager, onSend);
        ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, messageData));
        done.get();
    }
}
Also used : TransactionsMessage(org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RawMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BigInteger(java.math.BigInteger) Block(org.hyperledger.besu.ethereum.core.Block) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) ConditionFactory(org.awaitility.core.ConditionFactory) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Set(java.util.Set) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Collectors(java.util.stream.Collectors) BlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.BlockBodiesMessage) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) TransactionPoolFactory(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StatusMessage(org.hyperledger.besu.ethereum.eth.messages.StatusMessage) EthPV62(org.hyperledger.besu.ethereum.eth.messages.EthPV62) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) ArrayList(java.util.ArrayList) NodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) HashSet(java.util.HashSet) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) GetBlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Wei(org.hyperledger.besu.datatypes.Wei) DisconnectReason(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason) ExecutorService(java.util.concurrent.ExecutorService) GetReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) NewBlockMessage(org.hyperledger.besu.ethereum.eth.messages.NewBlockMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) GetBlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockBodiesMessage) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) EthPV63(org.hyperledger.besu.ethereum.eth.messages.EthPV63) Mockito.reset(org.mockito.Mockito.reset) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) ArrayList(java.util.ArrayList) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) GetReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage) Hash(org.hyperledger.besu.datatypes.Hash) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ArrayList(java.util.ArrayList) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) Test(org.junit.Test)

Example 5 with EthPV63

use of org.hyperledger.besu.ethereum.eth.messages.EthPV63 in project besu by hyperledger.

the class EthProtocolManagerTest method respondToGetReceiptsPartial.

@Test
public void respondToGetReceiptsPartial() throws ExecutionException, InterruptedException {
    final CompletableFuture<Void> done = new CompletableFuture<>();
    try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create(blockchain, () -> false, protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig())) {
        // Setup blocks query
        final long blockNumber = blockchain.getChainHeadBlockNumber() - 5;
        final BlockHeader header = blockchain.getBlockHeader(blockNumber).get();
        final List<TransactionReceipt> expectedReceipts = blockchain.getTxReceipts(header.getHash()).get();
        final Hash blockHash = header.getHash();
        final MessageData messageData = GetReceiptsMessage.create(Arrays.asList(gen.hash(), blockHash, gen.hash()));
        // Define handler to validate response
        final PeerSendHandler onSend = (cap, message, conn) -> {
            if (message.getCode() == EthPV62.STATUS) {
                // Ignore status message
                return;
            }
            assertThat(message.getCode()).isEqualTo(EthPV63.RECEIPTS);
            final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(message);
            final List<List<TransactionReceipt>> receipts = Lists.newArrayList(receiptsMessage.receipts());
            assertThat(receipts).hasSize(1);
            assertThat(expectedReceipts).isEqualTo(receipts.get(0));
            done.complete(null);
        };
        // Run test
        final PeerConnection peer = setupPeer(ethManager, onSend);
        ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, messageData));
        done.get();
    }
}
Also used : TransactionsMessage(org.hyperledger.besu.ethereum.eth.messages.TransactionsMessage) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RawMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) BlockchainSetupUtil(org.hyperledger.besu.ethereum.core.BlockchainSetupUtil) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) BigInteger(java.math.BigInteger) Block(org.hyperledger.besu.ethereum.core.Block) GetNodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage) ConditionFactory(org.awaitility.core.ConditionFactory) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Set(java.util.Set) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Collectors(java.util.stream.Collectors) BlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.BlockBodiesMessage) BlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) Optional(java.util.Optional) Capability(org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) TransactionPoolFactory(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StatusMessage(org.hyperledger.besu.ethereum.eth.messages.StatusMessage) EthPV62(org.hyperledger.besu.ethereum.eth.messages.EthPV62) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) EthProtocol(org.hyperledger.besu.ethereum.eth.EthProtocol) ArrayList(java.util.ArrayList) NodeDataMessage(org.hyperledger.besu.ethereum.eth.messages.NodeDataMessage) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) HashSet(java.util.HashSet) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) GetBlockHeadersMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Wei(org.hyperledger.besu.datatypes.Wei) DisconnectReason(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason) ExecutorService(java.util.concurrent.ExecutorService) GetReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage) TransactionPool(org.hyperledger.besu.ethereum.eth.transactions.TransactionPool) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) NewBlockMessage(org.hyperledger.besu.ethereum.eth.messages.NewBlockMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) GetBlockBodiesMessage(org.hyperledger.besu.ethereum.eth.messages.GetBlockBodiesMessage) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) EthPV63(org.hyperledger.besu.ethereum.eth.messages.EthPV63) Mockito.reset(org.mockito.Mockito.reset) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) DefaultMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage) GetReceiptsMessage(org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage) Hash(org.hyperledger.besu.datatypes.Hash) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ArrayList(java.util.ArrayList) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) PeerSendHandler(org.hyperledger.besu.ethereum.eth.manager.MockPeerConnection.PeerSendHandler) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Optional (java.util.Optional)8 Set (java.util.Set)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 ExecutorService (java.util.concurrent.ExecutorService)8 TimeUnit (java.util.concurrent.TimeUnit)8 Collectors (java.util.stream.Collectors)8 Bytes (org.apache.tuweni.bytes.Bytes)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8 Hash (org.hyperledger.besu.datatypes.Hash)8 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)8 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)8 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)8 ProtocolScheduleFixture (org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture)8 EthPV63 (org.hyperledger.besu.ethereum.eth.messages.EthPV63)8 GetNodeDataMessage (org.hyperledger.besu.ethereum.eth.messages.GetNodeDataMessage)8