Skip to content

fix(claims): set claim.id to the real chain id instead of a DB serial#49

Merged
lucca65 merged 1 commit into
masterfrom
fix/claim-id-from-chain
Jul 1, 2026
Merged

fix(claims): set claim.id to the real chain id instead of a DB serial#49
lucca65 merged 1 commit into
masterfrom
fix/claim-id-from-chain

Conversation

@lucca65

@lucca65 lucca65 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Problem

claimAction inserts claims without an id, so the DB serial (claims_id_seq) assigns it. The chain claim id is not in the claimaction payload (the contract generates it via get_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 signs verifyclaim(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–24138 mapped to chain 19833–19866).

Fix

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 that pair — true for live and replay.

  • src/chain.jsresolveClaimId() queries the claim table via the byaction index and returns the ordinal-th id.
  • claimAction computes the ordinal from the DB and inserts with the explicit chain id.
  • Fail-safe: on any error (chain unreachable, unexpected count) it logs and falls back to the serial instead of throwing — a throw in an updater becomes unhandledRejectionlogExit → pm2 crash-loop. The serial is realigned to the chain by the one-time claims-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, so claims.id == chain id everywhere and ids > 19866 are free. This code keeps new claims aligned. No schema change. StandardJS clean.

🤖 Generated with Claude Code

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>
@lucca65
lucca65 merged commit ba0e9a3 into master Jul 1, 2026
1 check passed
@lucca65
lucca65 deleted the fix/claim-id-from-chain branch July 1, 2026 10:26
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