Search in sources :

Example 1 with StubTask

use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.

the class CompleteTaskStepTest method shouldMarkCompleteWhenTaskHasData.

@Test
public void shouldMarkCompleteWhenTaskHasData() {
    // Use an arbitrary but actually valid trie node to get children from.
    final StubTask task = validTask();
    completeTaskStep.markAsCompleteOrFailed(blockHeader, downloadState, task);
    assertThat(task.isCompleted()).isTrue();
    assertThat(task.isFailed()).isFalse();
    verify(downloadState).checkCompletion(worldStateStorage, blockHeader);
}
Also used : StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask) Test(org.junit.Test)

Example 2 with StubTask

use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.

the class PersistDataStepTest method shouldSkipPersistingTasksWithNoData.

@Test
public void shouldSkipPersistingTasksWithNoData() {
    final Task<NodeDataRequest> withData = createTaskWithData(1, 2, 3);
    final StubTask withoutData = createTaskWithoutData(4, 5, 6);
    final List<Task<NodeDataRequest>> tasks = asList(withData, withoutData);
    final List<Task<NodeDataRequest>> result = persistDataStep.persist(tasks, blockHeader, downloadState);
    assertThat(result).isSameAs(tasks);
    assertThat(worldStateStorage.contains(withData.getData().getHash())).isTrue();
    assertThat(worldStateStorage.contains(withoutData.getData().getHash())).isFalse();
}
Also used : 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)

Example 3 with StubTask

use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.

the class RequestDataStepTest method shouldReportNoProgressWhenRequestCompletesWithNoData.

@Test
public void shouldReportNoProgressWhenRequestCompletesWithNoData() {
    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.complete(emptyMap());
    assertThat(result).isDone();
    assertThat(result).isCompletedWithValue(tasks);
    verify(downloadState).requestComplete(false);
}
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 4 with StubTask

use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.

the class RequestDataStepTest method shouldRequestDistinctHashesForTasks.

@Test
public void shouldRequestDistinctHashesForTasks() {
    final StubTask task1 = StubTask.forHash(HASH1);
    final StubTask task2 = StubTask.forHash(HASH2);
    final StubTask task3 = StubTask.forHash(HASH1);
    final List<Task<NodeDataRequest>> tasks = asList(task1, task2, task3);
    when(getNodeDataTaskFactory.apply(asList(HASH1, HASH2), BLOCK_NUMBER)).thenReturn(ethTask);
    final CompletableFuture<List<Task<NodeDataRequest>>> result = requestDataStep.requestData(tasks, blockHeader, downloadState);
    assertThat(result).isNotDone();
    getDataFuture.complete(ImmutableMap.of(HASH1, DATA1, HASH2, DATA2));
    assertThat(result).isDone();
    assertThat(result).isCompletedWithValue(tasks);
    assertThat(task1.getData().getData()).isEqualTo(DATA1);
    assertThat(task2.getData().getData()).isEqualTo(DATA2);
    assertThat(task3.getData().getData()).isEqualTo(DATA1);
    verify(downloadState).requestComplete(true);
}
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 5 with StubTask

use of org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask in project besu by hyperledger.

the class PersistDataStepTest method createTaskWithData.

private Task<NodeDataRequest> createTaskWithData(final Bytes data) {
    final StubTask task = createTaskWithoutData(data);
    MerklePatriciaTrie<Bytes, String> trie = new SimpleMerklePatriciaTrie<>(value -> (value != null) ? Bytes.wrap(value.getBytes(StandardCharsets.UTF_8)) : null);
    trie.put(data, "01");
    task.getData().setData(trie.getValueWithProof(data).getProofRelatedNodes().get(0));
    return task;
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SimpleMerklePatriciaTrie(org.hyperledger.besu.ethereum.trie.SimpleMerklePatriciaTrie) StubTask(org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask)

Aggregations

StubTask (org.hyperledger.besu.ethereum.eth.sync.worldstate.StubTask)8 Test (org.junit.Test)7 Task (org.hyperledger.besu.services.tasks.Task)5 EthTask (org.hyperledger.besu.ethereum.eth.manager.task.EthTask)4 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Bytes (org.apache.tuweni.bytes.Bytes)1 SimpleMerklePatriciaTrie (org.hyperledger.besu.ethereum.trie.SimpleMerklePatriciaTrie)1