use of org.hyperledger.besu.services.tasks.Task in project besu by hyperledger.
the class PersistDataStep method persist.
public List<Task<NodeDataRequest>> persist(final List<Task<NodeDataRequest>> tasks, final BlockHeader blockHeader, final WorldDownloadState<NodeDataRequest> downloadState) {
final Updater updater = worldStateStorage.updater();
tasks.stream().map(task -> {
enqueueChildren(task, downloadState);
return task;
}).map(Task::getData).filter(request -> request.getData() != null).forEach(request -> {
if (isRootState(blockHeader, request)) {
downloadState.setRootNodeData(request.getData());
} else {
request.persist(updater);
}
});
updater.commit();
return tasks;
}
use of org.hyperledger.besu.services.tasks.Task in project besu by hyperledger.
the class TaskGenerator method createAccountRequest.
public static List<Task<SnapDataRequest>> createAccountRequest(final boolean withData) {
final WorldStateStorage worldStateStorage = new InMemoryKeyValueStorageProvider().createWorldStateStorage(DataStorageFormat.FOREST);
final WorldStateProofProvider worldStateProofProvider = new WorldStateProofProvider(worldStateStorage);
final MerklePatriciaTrie<Bytes32, Bytes> trie = TrieGenerator.generateTrie(worldStateStorage, 1);
final RangeStorageEntriesCollector collector = RangeStorageEntriesCollector.createCollector(Bytes32.ZERO, RangeManager.MAX_RANGE, 1, Integer.MAX_VALUE);
final TrieIterator<Bytes> visitor = RangeStorageEntriesCollector.createVisitor(collector);
final TreeMap<Bytes32, Bytes> accounts = (TreeMap<Bytes32, Bytes>) trie.entriesFrom(root -> RangeStorageEntriesCollector.collectEntries(collector, visitor, root, Bytes32.ZERO));
final Hash rootHash = Hash.wrap(trie.getRootHash());
final AccountRangeDataRequest accountRangeDataRequest = SnapDataRequest.createAccountRangeDataRequest(rootHash, RangeManager.MIN_RANGE, RangeManager.MAX_RANGE);
if (withData) {
accountRangeDataRequest.addResponse(worldStateProofProvider, accounts, new ArrayDeque<>());
}
final StateTrieAccountValue stateTrieAccountValue = StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue()));
final Hash accountHash = Hash.wrap(accounts.firstKey());
final StorageRangeDataRequest storageRangeDataRequest = createStorageRangeDataRequest(worldStateProofProvider, worldStateStorage, rootHash, accountHash, stateTrieAccountValue.getStorageRoot(), withData);
final BytecodeRequest bytecodeRequest = createBytecodeDataRequest(worldStateStorage, rootHash, accountHash, stateTrieAccountValue.getCodeHash(), withData);
return List.of(new StubTask(accountRangeDataRequest), new StubTask(storageRangeDataRequest), new StubTask(bytecodeRequest));
}
use of org.hyperledger.besu.services.tasks.Task in project besu by hyperledger.
the class RequestDataStepTest method shouldNotReportNoProgressWhenTaskFails.
@Test
public void shouldNotReportNoProgressWhenTaskFails() {
final StubTask task1 = StubTask.forHash(HASH1);
final List<Task<NodeDataRequest>> tasks = singletonList(task1);
when(getNodeDataTaskFactory.apply(singletonList(HASH1), BLOCK_NUMBER)).thenReturn(ethTask);
final CompletableFuture<List<Task<NodeDataRequest>>> result = requestDataStep.requestData(tasks, blockHeader, downloadState);
assertThat(result).isNotDone();
getDataFuture.completeExceptionally(new RuntimeException());
assertThat(result).isDone();
assertThat(result).isCompletedWithValue(tasks);
verify(downloadState, never()).requestComplete(anyBoolean());
}
use of org.hyperledger.besu.services.tasks.Task in project besu by hyperledger.
the class RequestDataStepTest method shouldTrackOutstandingTasks.
@Test
public void shouldTrackOutstandingTasks() {
final StubTask task1 = StubTask.forHash(HASH1);
final List<Task<NodeDataRequest>> tasks = singletonList(task1);
when(getNodeDataTaskFactory.apply(singletonList(HASH1), BLOCK_NUMBER)).thenReturn(ethTask);
requestDataStep.requestData(tasks, blockHeader, downloadState);
verify(downloadState).addOutstandingTask(ethTask);
getDataFuture.complete(emptyMap());
verify(downloadState).removeOutstandingTask(ethTask);
}
Aggregations