Skip to content

fix(bridge-history-api): return consistent results from cache - #1821

Merged
Thegaram merged 1 commit into
developfrom
fix-bridge-history-api-cache
Oct 21, 2026
Merged

Thegaram merged 1 commit into
developfrom
fix-bridge-history-api-cache

Conversation

@Thegaram

@Thegaram Thegaram commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Purpose or design rationale of this PR

POST /api/txsbyhashes returned different results for the same query. The cache stored each row under the row's own hash, not under the queried hash. Lookups by a counterpart hash (L1 claim tx, L2 relay tx) returned the row once and then an empty result for 60s. Txs with several messages or batch-deposit events lost all but one row after the first call.

Changes:

  • Cache a list of rows per queried hash, under both the row's hash and its counterpart hash.
  • On any cache miss, query the DB for all requested hashes. Cached and fresh rows never mix, so the response has no duplicates and no stale copies.
  • If two cache entries hold the same row (same MessageHash, or same tx hash for batch deposits), treat the request as a miss. The DB then returns the row once, in its current state. This covers a message queried by both chain hashes and a failed relay queried with its retry.

Compatibility:

  • Cache format: each value changes from a JSON object to a JSON array. Old and new pods cannot read each other's entries and treat them as misses. Results stay correct; the extra DB load ends within 60 s, when the old entries expire.
  • DB load: a partly cached request now queries all of its hashes, not only the missing ones. A request with both hashes of one message (for example [W, C]) always queries the DB. The worst case per request is unchanged: at most 100 hashes and two indexed IN queries.

PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • fix: A bug fix

Deployment tag versioning

Has tag in common/version.go been updated or have you added bump-version label to this PR?

  • No, this PR doesn't involve a new deployment, git tag, docker image tag
  • Yes

Breaking change label

Does this PR have the breaking-change label?

  • No, this PR is not a breaking change
  • Yes

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction history retrieval when cached results are missing, invalid, empty, or inconsistent.
    • Ensured queries return complete results across related transaction hashes, including batch deposits.
    • Refreshed cached history for all requested hashes to keep subsequent lookups accurate.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59be77da-78b1-44a3-b822-9af23c61c140
📥 Commits

Reviewing files that changed from the base of the PR and between f84b124 and 7504d10.

📒 Files selected for processing: 2
  • bridge-history-api/internal/logic/history_logic.go
  • common/version/version.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The history API now detects conflicting cached transaction rows and refreshes results from storage when needed. The package version tag changes from v4.8.1 to v4.8.2.

Changes: History API cache handling

Layer / File(s) Summary
Cache conflict detection and refresh
bridge-history-api/internal/logic/history_logic.go
GetTxsByHashes tracks which queried hash supplied each cached row and detects duplicate row ownership. When a cache miss, invalid entry, or conflict requires refresh, it queries both storage sources for all requested hashes, indexes results by transaction and counterpart hashes, and refreshes cache entries for every requested hash.

Package version

Layer / File(s) Summary
Version tag update
common/version/version.go
The package version tag changes from v4.8.1 to v4.8.2. Commit and ZK version composition remain unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: colinlyguo, georgehao

Merge Risk: ⚪ Minimal · up to 7504d

The cache change appears ready to merge after normal checks; no actionable issue remains identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description explains what the PR changes, why the change is needed, and how the implementation works. It also documents compatibility, database-load impact, the conventional commit title, deployme…
Title check Passed The title uses the required conventional commit format and clearly describes the primary change: fixing inconsistent cache results in bridge-history-api.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
Full details: Description check

Explanation

The description explains what the PR changes, why the change is needed, and how the implementation works. It also documents compatibility, database-load impact, the conventional commit title, deployment versioning, and breaking-change status.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.56%. Comparing base (f84b124) to head (7504d10).

Files with missing lines Patch % Lines
bridge-history-api/internal/logic/history_logic.go 0.00% 28 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1821      +/-   ##
===========================================
- Coverage    35.59%   35.56%   -0.03%     
===========================================
  Files          263      263              
  Lines        22733    22751      +18     
===========================================
  Hits          8091     8091              
- Misses       13793    13811      +18     
  Partials       849      849              
Flag Coverage Δ
bridge-history-api 8.00% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Thegaram
Thegaram merged commit a5d61e4 into develop Oct 21, 2026
6 checks passed
@Thegaram
Thegaram deleted the fix-bridge-history-api-cache branch October 21, 2026 14:31
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.

2 participants