Commit graph

8 commits

Author SHA1 Message Date
bitromortac
e852394bdd
db: add channel event pruning query and index
Add a PruneChannelEvents query that bounds the channel_events table by both
size and age in a single statement: an id-keyset offset enforces a maximum
event count and a timestamp filter enforces a retention window, OR-joined so
each limit applies independently. The query returns the number of rows deleted
so callers can surface pruning activity.

Add a standalone timestamp index so the global age-based prune does not scan
the full table. The existing composite index leads with channel_id and cannot
serve a channel-agnostic timestamp filter.
2026-06-22 10:10:00 +02:00
bitromortac
85f0a261a4 chanevents+db: widen test fixtures to testing.TB
Promote the existing test-store and test-DB constructors from
*testing.T to testing.TB so the upcoming EffectiveUptime benchmark can
share the same fixture path as the existing tests. testing.TB is the
shared interface of *testing.T and *testing.B, so every current caller
keeps type-checking unchanged.
2026-06-03 17:55:30 +02:00
bitromortac
2363173325 chanevents+db: add scid-to-peer index
Add ScidToPeerMap, which materialises a snapshot of every short channel
id paired with the pubkey of the channel's remote peer. Forwarding-data
sources index events by short channel id, but downstream analyses need
to attribute behaviour to the peer, not the channel. The map skips
channels whose short channel id is still zero (unconfirmed), so callers
see only fully advertised channels. Coverage extends TestStore with a
two-channel fixture pinning the join.
2026-05-13 14:32:12 +02:00
bitromortac
7431bb5d67 chanevents+db: add latest-event-before lookup
Add GetLatestChannelUpdateBefore, which fetches the most recent
EventTypeUpdate strictly before a given instant. Forwarding-ability
analyses that summarise behaviour over a window must seed their state
from the channel's balance at the window's lower bound; without the
ability to look back past that bound, the first events in the window
have no baseline to compare against. The lookup tolerates missing
predecessors by returning (nil, nil), letting callers distinguish "no
prior update" from a genuine error. Coverage exercises both the present
and absent cases against the existing TestStore fixture.
2026-05-13 14:01:43 +02:00
bitromortac
c1ada7a4a3 db+chanevents: change to paginated GetChannelEvents
Switches the GetChannelEvents query from a timestamp-ordered scan to an
id-keyset cursor (WHERE id > $cursor ORDER BY id ASC LIMIT $n). The
keyset cursor is stable under concurrent inserts and survives a future
retention job that prunes the oldest rows: a positional OFFSET would
silently skip events whenever rows below the cursor are deleted, while
"id > $cursor" keeps advancing past whatever the caller has already
seen. The id field is documented in the proto as a server-assigned
monotonic identity, so callers persist last_id as their sync watermark.

Adds a (channel_id, id) composite index to back the new query; the
existing (channel_id, timestamp) index does not cover it and would
force a per-channel filter after a global id scan.
2026-05-08 20:13:58 +02:00
bitromortac
53148c5232
chanevents+db: add sync row
We want to know if an update came from an initial sync. This also helps
us to identify data gaps and one can be sure it was not due to an actual
event. Modify the migration as it's unreleased.
2026-04-02 12:25:36 +02:00
bitromortac
3157dbc870
db: add chanevents tables and queries 2026-04-01 15:06:37 +02:00
bitromortac
768f2d3019
mod: add sqldbv2 and boilerplate 2026-03-30 11:50:52 +02:00