Commit 05b43df
authored
Re-validate pending sol_purchases when blocknumber catches up (#818)
## Summary
- Adds a trigger on `tracks`/`playlists` that emits `NOTIFY
'pending_purchase_revalidation'` when `blocknumber` advances past any
pending `sol_purchases` row's `valid_after_blocknumber`. Cheap EXISTS
guard so the vast majority of track/playlist updates skip the notify
entirely.
- Adds a Go listener (`PurchaseRevalidator`) in the Solana indexer that
consumes notifications and re-runs the existing `validatePurchase` for
affected pending rows. A 5-minute sweep + startup sweep covers cases
where NOTIFY drops (no connected listener) or pending rows that predate
the trigger.
- Validation logic stays in `validatePurchase` as the single source of
truth — the trigger only signals which `content_id` changed. No SQL
port, no parity drift with config-driven values like `NetworkTakeRate`.
### Why
A `sol_purchases` row is inserted with `is_valid = NULL` ("pending")
when its `valid_after_blocknumber` hasn't been indexed by the local node
yet (`MAX(blocks.number) < valid_after_blocknumber` at insert time).
Before this PR there was no mechanism to flip pending rows to a final
verdict, so they stayed `NULL` indefinitely even after the indexer
caught up.
### Notes for reviewers
- `sql/01_schema.sql` diff is large because the dump hadn't been
regenerated since #815 merged — it picks up that PR's
`handle_sol_purchase` function and a few other already-merged trigger
updates alongside this PR's `notify_pending_purchase_revalidation`.
- Bumped `pgxpool.MaxConns` by 1 to budget for the revalidator's
persistent LISTEN connection (in addition to the existing artist_coins
listener).
- Lifecycle is purely ctx-driven — no explicit `Stop()`. Cancelling the
parent ctx unblocks `WaitForNotification`, the deferred `conn.Release()`
returns the LISTEN connection to the pool, both goroutines exit.
## Test plan
- [x] Trigger function applied via regenerated schema dump (`make
test-schema`)
- [x] `TestParseRevalidationPayload` — unit coverage for payload parsing
- [x] `TestRevalidatorRevalidateContent` — direct call: pending row +
matching `sol_payments` flips to `true`
- [x] `TestRevalidatorEndToEnd` — full trigger → NOTIFY → LISTEN →
revalidate chain via `UPDATE tracks SET blocknumber`
- [x] Existing `TestPurchaseValidation` still passes
- [ ] Deploy to stage and watch a pending row resolve in the wild
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent a284c53 commit 05b43df
6 files changed
Lines changed: 1059 additions & 133 deletions
File tree
- ddl/functions
- solana/indexer
- program
- sql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| 54 | + | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| |||
0 commit comments