Merge branch 'refs/heads/7311-add-peertask-foundation-code' into 7311-add-GetReceiptsFromPeerTask

pull/7638/head
Matilda Clerke 2 months ago
commit fe50d95492
  1. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java
  2. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/NewPooledTransactionHashesMessageHandler.java
  3. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionsMessageHandler.java
  4. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/CompleteTaskStepTest.java
  5. 23
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStepTest.java
  6. 14
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java

@ -179,6 +179,10 @@ public class StorageRangeDataRequest extends SnapDataRequest {
final StackTrie.TaskElement taskElement = stackTrie.getElement(startKeyHash);
if (null == taskElement) {
return Stream.empty();
}
findNewBeginElementInRange(storageRoot, taskElement.proofs(), taskElement.keys(), endKeyHash)
.ifPresent(
missingRightElement -> {

@ -45,11 +45,11 @@ class NewPooledTransactionHashesMessageHandler implements EthMessages.MessageCal
@Override
public void exec(final EthMessage message) {
if (isEnabled.get()) {
final Capability capability = message.getPeer().getConnection().capability(EthProtocol.NAME);
final NewPooledTransactionHashesMessage transactionsMessage =
NewPooledTransactionHashesMessage.readFrom(message.getData(), capability);
final Instant startedAt = now();
if (isEnabled.get()) {
scheduler.scheduleTxWorkerTask(
() ->
transactionsMessageProcessor.processNewPooledTransactionHashesMessage(

@ -43,9 +43,10 @@ class TransactionsMessageHandler implements EthMessages.MessageCallback {
@Override
public void exec(final EthMessage message) {
final TransactionsMessage transactionsMessage = TransactionsMessage.readFrom(message.getData());
final Instant startedAt = now();
if (isEnabled.get()) {
final TransactionsMessage transactionsMessage =
TransactionsMessage.readFrom(message.getData());
final Instant startedAt = now();
scheduler.scheduleTxWorkerTask(
() ->
transactionsMessageProcessor.processTransactionsMessage(

@ -116,7 +116,7 @@ public class CompleteTaskStepTest {
@Test
public void shouldMarkSnapsyncTaskCompleteWhenData() {
final List<Task<SnapDataRequest>> requests = TaskGenerator.createAccountRequest(true);
final List<Task<SnapDataRequest>> requests = TaskGenerator.createAccountRequest(true, false);
requests.stream()
.map(StubTask.class::cast)
.forEach(
@ -132,7 +132,7 @@ public class CompleteTaskStepTest {
@Test
public void shouldMarkSnapsyncTaskAsFailedWhenNoData() {
final List<Task<SnapDataRequest>> requests = TaskGenerator.createAccountRequest(false);
final List<Task<SnapDataRequest>> requests = TaskGenerator.createAccountRequest(false, false);
requests.stream()
.map(StubTask.class::cast)
.forEach(

@ -68,7 +68,7 @@ public class PersistDataStepTest {
@Test
public void shouldPersistDataWhenPresent() {
final List<Task<SnapDataRequest>> tasks = TaskGenerator.createAccountRequest(true);
final List<Task<SnapDataRequest>> tasks = TaskGenerator.createAccountRequest(true, false);
final List<Task<SnapDataRequest>> result = persistDataStep.persist(tasks);
assertThat(result).isSameAs(tasks);
@ -105,7 +105,7 @@ public class PersistDataStepTest {
@Test
public void shouldSkipPersistDataWhenNoData() {
final List<Task<SnapDataRequest>> tasks = TaskGenerator.createAccountRequest(false);
final List<Task<SnapDataRequest>> tasks = TaskGenerator.createAccountRequest(false, false);
final List<Task<SnapDataRequest>> result = persistDataStep.persist(tasks);
assertThat(result).isSameAs(tasks);
@ -116,6 +116,25 @@ public class PersistDataStepTest {
.isEmpty();
}
@Test
public void shouldHandleNullTaskElementInTrie() {
// Create a StorageRangeDataRequest where taskElement might be null or incomplete
List<Task<SnapDataRequest>> tasks = TaskGenerator.createAccountRequest(false, true);
try {
List<Task<SnapDataRequest>> result = persistDataStep.persist(tasks);
// check for proper handling of null taskElement
assertThat(result).isSameAs(tasks);
assertThat(result)
.isNotNull(); // Make sure the result isn't null even with the bad taskElement
} catch (NullPointerException e) {
fail(
"NullPointerException occurred during persist step, taskElement might be null: "
+ e.getMessage());
}
}
private void assertDataPersisted(final List<Task<SnapDataRequest>> tasks) {
tasks.forEach(
task -> {

@ -44,7 +44,8 @@ import org.apache.tuweni.bytes.Bytes32;
public class TaskGenerator {
public static List<Task<SnapDataRequest>> createAccountRequest(final boolean withData) {
public static List<Task<SnapDataRequest>> createAccountRequest(
final boolean withData, final boolean withNullTaskElement) {
final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage =
new BonsaiWorldStateKeyValueStorage(
@ -91,7 +92,8 @@ public class TaskGenerator {
rootHash,
accountHash,
stateTrieAccountValue.getStorageRoot(),
withData);
withData,
withNullTaskElement);
final BytecodeRequest bytecodeRequest =
createBytecodeDataRequest(
worldStateKeyValueStorage,
@ -112,7 +114,8 @@ public class TaskGenerator {
final Hash rootHash,
final Hash accountHash,
final Bytes32 storageRoot,
final boolean withData) {
final boolean withData,
final boolean withNullTaskElement) {
final RangeStorageEntriesCollector collector =
RangeStorageEntriesCollector.createCollector(
@ -140,6 +143,11 @@ public class TaskGenerator {
request.setProofValid(true);
request.addResponse(null, worldStateProofProvider, slots, new ArrayDeque<>());
}
if (withNullTaskElement) {
// setting isValidProof to true to simulate a null task element.
request.setProofValid(true);
}
return request;
}

Loading…
Cancel
Save