-
Notifications
You must be signed in to change notification settings - Fork 841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapserver responses to return at least one response #7190
Changes from all commits
86ba925
339f622
69907fa
c74a520
8776fa3
6fe0c5d
524f9cf
8827c0d
0bf52da
148cadd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,8 +456,9 @@ MessageData constructGetBytecodesResponse(final MessageData message) { | |
} else { | ||
Optional<Bytes> optCode = worldStateStorageCoordinator.getCode(Hash.wrap(codeHash), null); | ||
if (optCode.isPresent()) { | ||
if (sumListBytes(codeBytes) + optCode.get().size() > maxResponseBytes | ||
|| stopWatch.getTime() > StatefulPredicate.MAX_MILLIS_PER_REQUEST) { | ||
if (!codeBytes.isEmpty() | ||
&& (sumListBytes(codeBytes) + optCode.get().size() > maxResponseBytes | ||
|| stopWatch.getTime() > StatefulPredicate.MAX_MILLIS_PER_REQUEST)) { | ||
break; | ||
} | ||
codeBytes.add(optCode.get()); | ||
|
@@ -511,8 +512,9 @@ MessageData constructGetTrieNodesResponse(final MessageData message) { | |
var optStorage = | ||
storage.getTrieNodeUnsafe(CompactEncoding.decode(triePath.get(0))); | ||
if (optStorage.isPresent()) { | ||
if (sumListBytes(trieNodes) + optStorage.get().size() > maxResponseBytes | ||
|| stopWatch.getTime() > StatefulPredicate.MAX_MILLIS_PER_REQUEST) { | ||
if (!trieNodes.isEmpty() | ||
&& (sumListBytes(trieNodes) + optStorage.get().size() > maxResponseBytes | ||
|| stopWatch.getTime() > StatefulPredicate.MAX_MILLIS_PER_REQUEST)) { | ||
break; | ||
} | ||
trieNodes.add(optStorage.get()); | ||
|
@@ -536,7 +538,9 @@ MessageData constructGetTrieNodesResponse(final MessageData message) { | |
storage.getTrieNodeUnsafe( | ||
Bytes.concatenate(accountPrefix, CompactEncoding.decode(path))); | ||
if (optStorage.isPresent()) { | ||
if (sumListBytes(trieNodes) + optStorage.get().size() > maxResponseBytes) { | ||
if (!trieNodes.isEmpty() | ||
&& sumListBytes(trieNodes) + optStorage.get().size() | ||
> maxResponseBytes) { | ||
break; | ||
} | ||
trieNodes.add(optStorage.get()); | ||
|
@@ -614,11 +618,14 @@ public boolean test(final Pair<Bytes32, Bytes> pair) { | |
return false; | ||
} | ||
|
||
var hasNoRecords = recordLimit.get() == 0; | ||
var underRecordLimit = recordLimit.addAndGet(1) <= MAX_ENTRIES_PER_REQUEST; | ||
var underByteLimit = | ||
byteLimit.accumulateAndGet(0, (cur, __) -> cur + encodingSizeAccumulator.apply(pair)) | ||
< maxResponseBytesFudgeFactor; | ||
if (underRecordLimit && underByteLimit) { | ||
// Only enforce limits when we have at least 1 record as the snapsync spec | ||
// requires at least 1 record must be returned | ||
if (hasNoRecords || (underRecordLimit && underByteLimit)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a "pathological" hive test case where the byteLimit is set too low to allow any records through? 👍 This seems a reasonable fix if the spec says there must always be at least one record in the response, but we should add a comment about why we are doing this, because it isn't obvious why we would do this otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There wasn't any "pathological" test for the responses that use this predicate, well none obvious anyway. The "pathological" test was for getByteCodes with a limit too small to allow any response. But since the spec does state we need to return at least one response I made the changes anyway to be compliant. |
||
return true; | ||
} else { | ||
shouldContinue.set(false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sumListBytes operates on the stream, with an orElse(0). it shouldn't matter whether the list is empty or not right? what am I missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sumListBytes will work fine on an empty list. This change isn't to guard against calling sumListBytes with an empty list but to ensure we only do the
sumListBytes(codeBytes) > maxReponseBytes
check once we have at least one record in the response. So that we always send at least once record in the response.