fix(db): make token transfer insert idempotent#49
Conversation
|
Warning Review limit reached
More reviews will be available in 55 minutes and 44 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@crates/db/src/token_transfers.rs`:
- Around line 7-8: Add a regression test that verifies the single-row insert is
retry-safe by calling the insert function in crates/db/src/token_transfers.rs
twice with the same (tx_hash, log_index) and asserting the second call returns
Ok(()) and that the table still has only one row for that key; specifically
create a test that inserts a decoded transfer via the same insert function twice
and then queries the token_transfers table (or uses the existing fetch helper)
to assert row count is 1, since crates/sync/src/block_writer.rs:41-66 depends on
this conflict-handling behavior.
🪄 Autofix (Beta)
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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8c743f2e-1268-440f-8584-9229695ae9e1
📒 Files selected for processing (1)
crates/db/src/token_transfers.rs
| /// Insert a single decoded transfer. Retry-safe via `(tx_hash, log_index)` | ||
| /// ON CONFLICT DO NOTHING — matches the batch insert path. |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Add a duplicate-insert regression test.
This change makes the single-row path rely on DB conflict handling for retry safety. Please add coverage that calls insert twice with the same (tx_hash, log_index) and asserts the second call still returns Ok(()) without creating a second row; crates/sync/src/block_writer.rs:41-66 depends on that behavior during retries.
Also applies to: 16-17
🤖 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 `@crates/db/src/token_transfers.rs` around lines 7 - 8, Add a regression test
that verifies the single-row insert is retry-safe by calling the insert function
in crates/db/src/token_transfers.rs twice with the same (tx_hash, log_index) and
asserting the second call returns Ok(()) and that the table still has only one
row for that key; specifically create a test that inserts a decoded transfer via
the same insert function twice and then queries the token_transfers table (or
uses the existing fetch helper) to assert row count is 1, since
crates/sync/src/block_writer.rs:41-66 depends on this conflict-handling
behavior.
4579837 to
67df636
Compare
Summary
What changed and why. 1-3 sentences.
Scope
Checks
forge buildcleanforge testgreen (including fuzz + invariant)forge fmt --checkcleanslither --no-fail-pedanticreviewed (no new high-severity findings)make storageand inspectdocs/storage/*.json)Linked issue
Closes #
Deploy impact
RELEASES.mdSummary by CodeRabbit