Search in sources :

Example 1 with TrieNodeDataRequest

use of org.hyperledger.besu.ethereum.eth.sync.snapsync.request.TrieNodeDataRequest in project besu by hyperledger.

the class LoadLocalDataStep method loadLocalDataTrieNode.

public Stream<Task<SnapDataRequest>> loadLocalDataTrieNode(final Task<SnapDataRequest> task, final Pipe<Task<SnapDataRequest>> completedTasks) {
    final TrieNodeDataRequest request = (TrieNodeDataRequest) task.getData();
    // check if node is already stored in the worldstate
    if (snapSyncState.hasPivotBlockHeader()) {
        Optional<Bytes> existingData = request.getExistingData(worldStateStorage);
        if (existingData.isPresent()) {
            existingNodeCounter.inc();
            request.setData(existingData.get());
            request.setRequiresPersisting(false);
            final WorldStateStorage.Updater updater = worldStateStorage.updater();
            request.persist(worldStateStorage, updater, downloadState, snapSyncState);
            updater.commit();
            downloadState.enqueueRequests(request.getRootStorageRequests(worldStateStorage));
            completedTasks.put(task);
            return Stream.empty();
        }
    }
    return Stream.of(task);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) TrieNodeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.TrieNodeDataRequest)

Example 2 with TrieNodeDataRequest

use of org.hyperledger.besu.ethereum.eth.sync.snapsync.request.TrieNodeDataRequest in project besu by hyperledger.

the class RequestDataStep method requestTrieNodeByPath.

public CompletableFuture<List<Task<SnapDataRequest>>> requestTrieNodeByPath(final List<Task<SnapDataRequest>> requestTasks) {
    final BlockHeader blockHeader = fastSyncState.getPivotBlockHeader().get();
    final Map<Bytes, List<Bytes>> message = new HashMap<>();
    requestTasks.stream().map(Task::getData).map(TrieNodeDataRequest.class::cast).map(TrieNodeDataRequest::getTrieNodePath).forEach(path -> {
        final List<Bytes> bytes = message.computeIfAbsent(path.get(0), k -> Lists.newArrayList());
        if (path.size() > 1) {
            bytes.add(path.get(1));
        }
    });
    final EthTask<Map<Bytes, Bytes>> getTrieNodeFromPeerTask = RetryingGetTrieNodeFromPeerTask.forTrieNodes(ethContext, message, blockHeader, metricsSystem);
    downloadState.addOutstandingTask(getTrieNodeFromPeerTask);
    return getTrieNodeFromPeerTask.run().handle((response, error) -> {
        if (response != null) {
            downloadState.removeOutstandingTask(getTrieNodeFromPeerTask);
            for (final Task<SnapDataRequest> task : requestTasks) {
                final TrieNodeDataRequest request = (TrieNodeDataRequest) task.getData();
                final Bytes matchingData = response.get(request.getPathId());
                if (matchingData != null) {
                    request.setData(matchingData);
                }
            }
        }
        return requestTasks;
    });
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) HashMap(java.util.HashMap) SnapDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest) TrieNodeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.TrieNodeDataRequest) List(java.util.List) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Bytes (org.apache.tuweni.bytes.Bytes)2 TrieNodeDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.TrieNodeDataRequest)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 SnapDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest)1 WorldStateStorage (org.hyperledger.besu.ethereum.worldstate.WorldStateStorage)1