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);
}
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;
});
}
Aggregations