fix(claims): set claim.id to the real chain id instead of a DB serial#49
Merged
Conversation
claimAction inserted claims without an id, letting the DB serial assign it. The chain claim id is not in the claimaction payload (the contract generates it via get_available_id), so the serial only matched the chain id while it stayed in lockstep — any duplicate/orphan insert drifted it ahead, and from that point on new claims got ids that don't exist on chain, so the frontend's verifyclaim(claim.id) failed with 'Can't find claim' and admins couldn't approve them. Recover the real id from chain: claims are never deleted (verifyclaim only mutates status) and ids are assigned in creation order, so the nth chain claim for a (action, claimer) pair is the nth claimaction we process for it. chain.js queries the claim table via the byaction index and returns that id; claimAction inserts with it explicitly. On any failure it falls back to the serial (which the one-time claims-id-reconciliation realigned to the chain) rather than throw, so a chain hiccup can't crash-loop the indexer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
claimActioninserts claims without an id, so the DB serial (claims_id_seq) assigns it. The chain claim id is not in theclaimactionpayload (the contract generates it viaget_available_id), so the serial only equals the chain id while it stays in perfect lockstep. Any duplicate/orphan insert (e.g. a block-range reindex) advances the serial, and from that point every new claim gets a DB id that doesn't exist on chain → the frontend signsverifyclaim(claim.id)→ contract "Can't find claim with given claim_id" → admins can't approve.This is the root cause of the muda "can't approve claims" reports (DB claims
20999–24138mapped to chain19833–19866).Fix
Recover the real id from chain. Claims are never deleted (
verifyclaimonly mutates status) and ids are assigned in creation order, so the nth chain claim for a(action, claimer)pair is the nthclaimactionwe process for that pair — true for live and replay.src/chain.js—resolveClaimId()queries theclaimtable via thebyactionindex and returns the ordinal-th id.claimActioncomputes the ordinal from the DB and inserts with the explicit chain id.unhandledRejection→logExit→ pm2 crash-loop. The serial is realigned to the chain by the one-timeclaims-id-reconciliation(run separately on prod), so the fallback stays correct; the explicit-id path is what makes it robust going forward.Deploy ordering
The DB reconciliation (delete 289 orphan claims + renumber the 2 drifted +
setval) has already been run on prod, soclaims.id == chain ideverywhere and ids > 19866 are free. This code keeps new claims aligned. No schema change. StandardJS clean.🤖 Generated with Claude Code