Skip to content

Commit d1abab6

Browse files
committed
short circuit getChildRequest in storage and account range requests when the proof is valid and empty (request was complete)
Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent 97ffa9f commit d1abab6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,17 @@ public Stream<SnapDataRequest> getChildRequests(
167167
final SnapSyncProcessState snapSyncState) {
168168
final List<SnapDataRequest> childRequests = new ArrayList<>();
169169

170+
if (!isProofValid.orElse(false)) {
171+
return Stream.empty();
172+
}
173+
170174
final StackTrie.TaskElement taskElement = stackTrie.getElement(startKeyHash);
175+
176+
// if the proof is valid, but there are no entries, that implies the range is complete
177+
if (taskElement.proofs().isEmpty()) {
178+
return Stream.empty();
179+
}
180+
171181
// new request is added if the response does not match all the requested range
172182
findNewBeginElementInRange(getRootHash(), taskElement.proofs(), taskElement.keys(), endKeyHash)
173183
.ifPresentOrElse(

ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ public Stream<SnapDataRequest> getChildRequests(
164164

165165
final StackTrie.TaskElement taskElement = stackTrie.getElement(startKeyHash);
166166

167+
// if the proof is valid, but there are no entries, that implies the range is complete
168+
if (taskElement.proofs().isEmpty()) {
169+
return Stream.empty();
170+
}
171+
167172
findNewBeginElementInRange(storageRoot, taskElement.proofs(), taskElement.keys(), endKeyHash)
168173
.ifPresent(
169174
missingRightElement -> {

0 commit comments

Comments
 (0)