Search in sources :

Example 6 with Task

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;
}
Also used : WorldDownloadState(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState) List(java.util.List) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Task(org.hyperledger.besu.services.tasks.Task) Updater(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater) Task(org.hyperledger.besu.services.tasks.Task) Updater(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater)

Example 7 with Task

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));
}
Also used : TrieGenerator(org.hyperledger.besu.ethereum.core.TrieGenerator) StoredMerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.StoredMerklePatriciaTrie) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) RLP(org.hyperledger.besu.ethereum.rlp.RLP) Bytes(org.apache.tuweni.bytes.Bytes) MerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.MerklePatriciaTrie) BytecodeRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.BytecodeRequest) ArrayDeque(kotlin.collections.ArrayDeque) SnapDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest) List(java.util.List) RangeStorageEntriesCollector(org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector) DataStorageFormat(org.hyperledger.besu.ethereum.worldstate.DataStorageFormat) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) TreeMap(java.util.TreeMap) WorldStateProofProvider(org.hyperledger.besu.ethereum.proof.WorldStateProofProvider) AccountRangeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest) TrieIterator(org.hyperledger.besu.ethereum.trie.TrieIterator) StorageRangeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataRequest) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) Task(org.hyperledger.besu.services.tasks.Task) Bytes32(org.apache.tuweni.bytes.Bytes32) Hash(org.hyperledger.besu.datatypes.Hash) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) WorldStateProofProvider(org.hyperledger.besu.ethereum.proof.WorldStateProofProvider) BytecodeRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.BytecodeRequest) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) TreeMap(java.util.TreeMap) Hash(org.hyperledger.besu.datatypes.Hash) Bytes32(org.apache.tuweni.bytes.Bytes32) Bytes(org.apache.tuweni.bytes.Bytes) RangeStorageEntriesCollector(org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) AccountRangeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest) StorageRangeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataRequest)

Example 8 with Task

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());
}
Also used : EthTask(org.hyperledger.besu.ethereum.eth.manager.task.EthTask) StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask) Task(org.hyperledger.besu.services.tasks.Task) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask) Test(org.junit.Test)

Example 9 with Task

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);
}
Also used : EthTask(org.hyperledger.besu.ethereum.eth.manager.task.EthTask) StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask) Task(org.hyperledger.besu.services.tasks.Task) StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask) Test(org.junit.Test)

Aggregations

Task (org.hyperledger.besu.services.tasks.Task)9 List (java.util.List)6 Test (org.junit.Test)6 EthTask (org.hyperledger.besu.ethereum.eth.manager.task.EthTask)5 StubTask (org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask)5 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 BytecodeRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.BytecodeRequest)3 SnapDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest)3 WorldStateStorage (org.hyperledger.besu.ethereum.worldstate.WorldStateStorage)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Hash (org.hyperledger.besu.datatypes.Hash)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2 InMemoryKeyValueStorageProvider (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider)2 AccountRangeDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest)2 StorageRangeDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataRequest)2 StoredMerklePatriciaTrie (org.hyperledger.besu.ethereum.trie.StoredMerklePatriciaTrie)2 DataStorageFormat (org.hyperledger.besu.ethereum.worldstate.DataStorageFormat)2 HashMap (java.util.HashMap)1