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); final StackTrie.TaskElement taskElement = stackTrie.getElement(startKeyHash);
if (null == taskElement) {
return Stream.empty();
}
findNewBeginElementInRange(storageRoot, taskElement.proofs(), taskElement.keys(), endKeyHash) findNewBeginElementInRange(storageRoot, taskElement.proofs(), taskElement.keys(), endKeyHash)
.ifPresent( .ifPresent(
missingRightElement -> { missingRightElement -> {

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

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

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

@ -68,7 +68,7 @@ public class PersistDataStepTest {
@Test @Test
public void shouldPersistDataWhenPresent() { 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); final List<Task<SnapDataRequest>> result = persistDataStep.persist(tasks);
assertThat(result).isSameAs(tasks); assertThat(result).isSameAs(tasks);
@ -105,7 +105,7 @@ public class PersistDataStepTest {
@Test @Test
public void shouldSkipPersistDataWhenNoData() { 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); final List<Task<SnapDataRequest>> result = persistDataStep.persist(tasks);
assertThat(result).isSameAs(tasks); assertThat(result).isSameAs(tasks);
@ -116,6 +116,25 @@ public class PersistDataStepTest {
.isEmpty(); .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) { private void assertDataPersisted(final List<Task<SnapDataRequest>> tasks) {
tasks.forEach( tasks.forEach(
task -> { task -> {

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

Loading…
Cancel
Save