Skip to content

feat: implement adaptive log scanning for escrow transfers - #163

Closed
manishdex25 wants to merge 3 commits into
mainfrom
feature/endorsement-chain
Closed

feat: implement adaptive log scanning for escrow transfers#163
manishdex25 wants to merge 3 commits into
mainfrom
feature/endorsement-chain

Conversation

@manishdex25

@manishdex25 manishdex25 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

What is the background of this pull request?

Changes

  • What are the changes made in this pull request?
  • Change this and that, etc...

Issues

What are the related issues or stories?

Summary by CodeRabbit

  • Bug Fixes
    • Improved escrow transfer retrieval across supported provider versions.
    • Added adaptive handling for provider log-range limits, including Alchemy Free-tier restrictions.
    • Prevented incompatible logs from interrupting event processing while preserving errors for incomplete logs.
    • Improved timestamp retrieval performance by avoiding duplicate block requests.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@manishdex25, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cf3addc-e3d8-4639-bf36-2a07cbe85cd2

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6d333 and 9596cfa.

📒 Files selected for processing (2)
  • src/core/endorsement-chain/fetchEscrowTransfer.ts
  • src/core/endorsement-chain/fetchLogsChunked.ts
📝 Walkthrough

Walkthrough

V5 escrow transfer retrieval now uses adaptive backward log scanning with mint-event termination and ethers v5/v6 address support. Log parsing skips incompatible ABI logs. Event timestamp retrieval deduplicates block requests and limits concurrency to five workers.

Changes

Escrow retrieval and timestamp processing

Layer / File(s) Summary
Adaptive backward log scanning
src/core/endorsement-chain/fetchLogsChunked.ts
scanLogsBackward scans block windows from newest to oldest, reduces windows after range-limit errors, grows them after empty results, and returns logs oldest-first.
Escrow transfer scan integration
src/core/endorsement-chain/fetchEscrowTransfer.ts
V5 retrieval passes the provider to fetchAllTransfers. The flow derives escrow addresses across ethers versions, stops at mint logs, and skips ABI-incompatible logs while preserving missing block-number errors.
Bounded event timestamp retrieval
src/core/endorsement-chain/retrieveEndorsementChain.ts
Timestamp retrieval fetches each unique block once with up to five concurrent workers and restores timestamps to the original event order.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant fetchEscrowTransfersV5
  participant fetchAllTransfers
  participant scanLogsBackward
  participant Provider
  fetchEscrowTransfersV5->>fetchAllTransfers: pass provider and transfer data
  fetchAllTransfers->>scanLogsBackward: scan escrow address to block zero
  scanLogsBackward->>Provider: request adaptive eth_getLogs window
  Provider-->>scanLogsBackward: return logs or range-limit error
  scanLogsBackward-->>fetchAllTransfers: return logs after mint boundary
  fetchAllTransfers-->>fetchEscrowTransfersV5: return parsed escrow transfers
Loading

Possibly related PRs

  • TrustVC/trustvc#161: Modifies the same escrow transfer retrieval, adaptive log scanning, and endorsement-chain timestamp logic.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description contains only the template questions and placeholders, with no background, detailed changes, or related issues. Replace the template placeholders with the PR background, a specific list of changes, and related issue or story references.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adaptive log scanning for escrow transfers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/endorsement-chain

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/core/endorsement-chain/retrieveEndorsementChain.ts (1)

21-35: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression tests for timestamp batching.

Test repeated block numbers to confirm that each block is fetched once. Test more than five unique blocks and assert that concurrent provider requests never exceed five. Also verify that timestamps remain aligned with the sorted logChain.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/endorsement-chain/retrieveEndorsementChain.ts` around lines 21 - 35,
Add regression tests around the timestamp batching logic using repeated block
numbers to verify each block is fetched only once, and more than five unique
blocks to verify provider concurrency never exceeds five. Assert the returned
timestamps remain aligned with the sorted logChain order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/endorsement-chain/fetchLogsChunked.ts`:
- Around line 9-17: Update the chunk-size constants and range-limit retry logic
in fetchLogsChunked: use 1 as the minimum request size while preserving 10 as
the free-tier maximum window size, and ensure a range-limit error still invokes
shrinkForRangeLimit when chunkSize is 10 so dense ranges can retry with smaller
windows instead of rethrowing.
- Around line 111-112: Update the chunk scanning logic around chunkGroups.push
and isMintLog to locate the latest matching mint log in chunkLogs, append only
the suffix starting at that log, then stop scanning; retain the full chunk when
no mint log is present.

---

Nitpick comments:
In `@src/core/endorsement-chain/retrieveEndorsementChain.ts`:
- Around line 21-35: Add regression tests around the timestamp batching logic
using repeated block numbers to verify each block is fetched only once, and more
than five unique blocks to verify provider concurrency never exceeds five.
Assert the returned timestamps remain aligned with the sorted logChain order.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a33ca9d8-6d3c-4f63-8db0-ab608b3d182b

📥 Commits

Reviewing files that changed from the base of the PR and between c03628d and 5b6d333.

📒 Files selected for processing (3)
  • src/core/endorsement-chain/fetchEscrowTransfer.ts
  • src/core/endorsement-chain/fetchLogsChunked.ts
  • src/core/endorsement-chain/retrieveEndorsementChain.ts

Comment thread src/core/endorsement-chain/fetchLogsChunked.ts Outdated
Comment thread src/core/endorsement-chain/fetchLogsChunked.ts Outdated
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant