fix(audit): token_transfers unique constraint + raise orphan log to warn#47
Merged
Conversation
Two audit follow-ups against the ERC-20 handler PR (#46): ## M-3: token_transfers unique constraint `token_transfers` had only `PRIMARY KEY (id)` when shipped. On reorg recovery + replay, the same `(tx_hash, log_index)` rows would re-insert without a uniqueness gate, producing duplicate transfer rows that double-count balances downstream. The atomic cursor advance in the steady-state writer prevented this in practice, but reorg / forensic- rerun paths bypass that protection. - New migration `0003_token_transfers_unique.sql` adds `transfers_tx_log_unique_idx` after deduping any existing duplicates. - `insert_batch` re-enabled `ON CONFLICT (tx_hash, log_index) DO NOTHING` so replay is now idempotent at the DB layer in addition to the cursor-based writer guard. The DELETE in the migration is a no-op for chains that have only run the indexer post-#46 (no duplicates accumulated); kept in place to keep the migration replay-safe on chains that did. ## M-5: raise orphan-log filter to warn `fetch_one` / `ingest_one` drop logs whose tx_hash isn't backed by a tx row in the same bundle (added in #46 to work around a Sentrix-side data inconsistency where reverted-tx log envelopes still come back from `eth_getLogs`). Original commit logged at `debug!`, which is silent at default log level. Sustained high-volume drops here signal a real chain bug worth investigating, so promote to `warn!` to make the gap visible without changing logging config. Verified locally: no compile changes, existing tests pass.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR establishes idempotency for token transfer records during blockchain reorganization replays. A SQL migration removes existing duplicates and creates a unique constraint on Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two audit follow-ups against the ERC-20 handler PR (#46) from internal bridge security audit.
Changes
M-3:
token_transfersunique constraint0003_token_transfers_unique.sqladdstransfers_tx_log_unique_idxafter deduping any existing duplicates (no-op on clean chains).insert_batchre-enablesON CONFLICT (tx_hash, log_index) DO NOTHINGso reorg / forensic-rerun replays stay idempotent at the DB layer.M-5: raise orphan-log filter from debug to warn
The drop-orphan-logs path (added in #46) was silent at default log level. Sustained high-volume drops signal a real chain-side data inconsistency, so promote to
warn!for visibility without changing log config.Test plan
cargo checkclean onindexer-sync+indexer-dbSummary by CodeRabbit
Bug Fixes
Chores