Cleanup, refactor and add trace logs to DownloadSyncReceiptsStep#9802
Cleanup, refactor and add trace logs to DownloadSyncReceiptsStep#9802fab-10 wants to merge 3 commits intohyperledger:mainfrom
Conversation
c0b79ae to
b8e1946
Compare
There was a problem hiding this comment.
Pull request overview
Refactors receipt-download flow for fast sync by deduplicating requests up-front, adding trace-level correlation logs, and adding retry/backoff behavior; updates the peer task and related tests to match the new request/response shape.
Changes:
- Refactored
DownloadSyncReceiptsStepto request receipts bySyncBlock, dedup by receipts-root, and emit structured trace logs. - Updated
GetSyncReceiptsFromPeerTaskto return ordered receipt lists and moved validation intovalidateResult. - Added/updated unit tests and test utilities; adjusted
BlockDataGeneratorto support configurable transaction counts.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java | New receipt download loop with dedup, correlation logs, and retry/backoff. |
| ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetSyncReceiptsFromPeerTask.java | Changes task input/output shape and strengthens validation logic. |
| ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/GetReceiptsMessage.java | Changes hashes() return type to List<Hash>. |
| ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java | Improves invalid-response logging and exception messaging. |
| ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/AbstractDownloadReceiptsStep.java | Removes the old generic receipt-download abstraction. |
| ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java | Adjusts mocks to match new receipts task output type. |
| ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java | Adjusts mocks to match new receipts task output type. |
| ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStepTest.java | Adds unit tests for receipts download/combination behavior. |
| ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetSyncReceiptsFromPeerTaskTest.java | Adds unit tests for request construction, parsing, and validation. |
| ethereum/eth/src/test-support/java/org/hyperledger/besu/ethereum/eth/core/Utils.java | Adds test-support helpers for receipts and block conversions/comparisons. |
| ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java | Adds configurable transaction count and honors blockOptionsSupplier in block(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Outdated
Show resolved
Hide resolved
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/GetReceiptsMessage.java
Show resolved
Hide resolved
...ava/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetSyncReceiptsFromPeerTask.java
Outdated
Show resolved
Hide resolved
...ava/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetSyncReceiptsFromPeerTask.java
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Outdated
Show resolved
Hide resolved
f8cb786 to
0d7bdc8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ava/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetSyncReceiptsFromPeerTask.java
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Show resolved
Hide resolved
ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java
Show resolved
Hide resolved
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/GetReceiptsMessage.java
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Show resolved
Hide resolved
.../src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadSyncReceiptsStep.java
Outdated
Show resolved
Hide resolved
9e38aac to
32ff103
Compare
macfarla
left a comment
There was a problem hiding this comment.
LGTM. couple of comments from claude that I think are worth reviewing.
2. resolvedBlocks.clear() on subList — At line ~740 in the new DownloadSyncReceiptsStep, resolvedBlocks is a subList view, and resolvedBlocks.clear() mutates the backing blocksToRequest list (removing the first N elements). This is correct but subtle — a comment would help future readers understand this isn't a no-op.
5. Ordering assumption in response matching — The new code assumes receipts come back in the same order as requested blocks (blocksToRequest.get(i) matched with blocksReceipts.get(i)). The old code matched by receipt root hash, which
was order-independent. If a peer returns receipts in a different order than requested, this would silently associate wrong receipts with wrong blocks. However, per the Eth protocol spec, Receipts responses should be in the same
order as the GetReceipts request, so this should be safe. The validateResult() check via receiptsRootMatches would catch any mismatch.
6. prepareRequest returns ArrayList (mutable) — The collect to ArrayList is intentional since downloadReceipts mutates the list via resolvedBlocks.clear(). This coupling between the two methods is a bit fragile — if someone
refactored prepareRequest to return an unmodifiable list, downloadReceipts would break at runtime.
7. receiptsRootMatches uses .getBytes().equals() — Hash extends Bytes32 which extends Bytes, so calculatedReceiptsRoot.getBytes().equals(blockHeader.getReceiptsRoot().getBytes()) could be simplified to just .equals() on the Hash
objects directly. The current approach works but is unnecessarily verbose.
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
… empty requests Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
added a comment to explain what is happening
The protocol enforces the order, so the response matching has been simplified.
This is to avoid an extra allocation and work, and since the code is in private methods a single class, I think we could take this shortcut, and there will always be unit tests to surface any issue in case of refactoring
I know but |
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
32ff103 to
baff5db
Compare
PR description
Summary of the changes in the PR
Fixed Issue(s)
Thanks for sending a pull request! Have you done the following?
doc-change-requiredlabel to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew spotlessApply./gradlew build./gradlew acceptanceTest./gradlew integrationTest./gradlew ethereum:referenceTests:referenceTests