Skip to content

refactor: optimize event timestamp fetching and enhance escrow transf… - #161

Closed
manishdex25 wants to merge 4 commits into
mainfrom
TT-1496/enhance-endorsement-chain
Closed

refactor: optimize event timestamp fetching and enhance escrow transf…#161
manishdex25 wants to merge 4 commits into
mainfrom
TT-1496/enhance-endorsement-chain

Conversation

@manishdex25

@manishdex25 manishdex25 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

…er handling

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

  • Performance

    • Improved escrow transfer retrieval across larger block ranges.
    • Reduced duplicate blockchain timestamp requests for faster endorsement-chain loading.
  • Reliability

    • Added automatic retries for temporary blockchain provider errors.
    • Improved handling of oversized or empty block-range queries.
    • Kept log requests within safe limits after provider errors.
  • Bug Fixes

    • Improved detection of escrow mint events across supported provider versions.
    • Preserved fallback handling when registry addresses are unavailable.

@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: 4 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: 9f6ba014-f80c-4de7-b3cd-df360fb18849

📥 Commits

Reviewing files that changed from the base of the PR and between 6d4e6cc and 511facb.

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

Walkthrough

V5 escrow transfer retrieval now uses adaptive backward log scanning. RPC operations retry transient failures with bounded backoff. Timestamp lookups use cached block results and up to five concurrent workers.

Changes

Endorsement-chain retrieval resilience

Layer / File(s) Summary
Adaptive backward log scanning
src/core/endorsement-chain/fetchLogsChunked.ts, src/__tests__/core/fetchLogsChunked.test.ts
Adds provider-compatible backward scanning with adaptive block ranges, transient-error retries, optional mint-log termination, ascending log output, and range-cap regression coverage.
V5 escrow transfer retrieval
src/core/endorsement-chain/fetchEscrowTransfer.ts
Passes the provider into V5 retrieval, resolves the escrow address, parses TokenReceived logs, and replaces per-event filter queries with backward scanning.
Bounded timestamp retrieval
src/core/endorsement-chain/retrieveEndorsementChain.ts
Deduplicates block timestamp requests, limits concurrency to five workers, caches results, and maps timestamps back to logs.
Interface-check retry handling
src/core/endorsement-chain/useEndorsementChain.ts
Retries transient checkSupportsInterface failures up to three times with capped exponential backoff. Non-transient and exhausted failures return false.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant fetchEscrowTransfersV5
  participant fetchAllTransfers
  participant scanLogsBackward
  participant provider
  fetchEscrowTransfersV5->>fetchAllTransfers: pass provider
  fetchAllTransfers->>provider: resolve escrow address and current block
  fetchAllTransfers->>scanLogsBackward: scan escrow address for TokenReceived logs
  scanLogsBackward->>provider: request adaptive descending block windows
  scanLogsBackward-->>fetchAllTransfers: return ascending logs
Loading

Possibly related PRs

  • TrustVC/trustvc#70: Shares ethers v5/v6 provider compatibility and endorsement-chain log-fetching test coverage.
  • TrustVC/trustvc#153: Also modifies endorsement-chain log retrieval for escrow transfers.
  • TrustVC/trustvc#155: Also modifies fetchEscrowTransfer.ts and fetchEscrowTransfersV5 log scanning.

Suggested reviewers: rongquan1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the required headings but retains placeholder text and provides no background, change details, or related issues. Replace the placeholder text with the pull request background, a specific summary of the changes, and related issue or story references.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies event timestamp optimization and escrow transfer handling, which are central changes in the pull request.
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 TT-1496/enhance-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

🤖 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 48-106: Reduce cognitive complexity in scanLogsBackward by
extracting the provider.getLogs request/retry handling and successful-window
chunk-size adaptation into focused helpers. Preserve the existing
range-too-large behavior, transient-error retry limits and delays, empty-chunk
growth logic, and latest-first chunk ordering; keep scanLogsBackward responsible
for traversal and termination.
- Around line 72-75: In the range-too-large handling of fetchLogsChunked, reduce
maxChunkSize to a materially smaller bound based on the rejected chunk instead
of chunkSize - 1, while preserving the MIN_CHUNK_SIZE floor and existing
chunkSize reduction. Add a test covering a provider that rejects ranges above a
fixed limit and verify subsequent requests stay below that limit without
repeated near-size failures.
🪄 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: d5d0cb5e-8ba1-4ddb-8f15-67a2d63cfbe9

📥 Commits

Reviewing files that changed from the base of the PR and between c03628d and 9aad95d.

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

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

Copy link
Copy Markdown

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