Skip to content

refactor(event-watcher): drop Deno.KV state store; boot syncs from oldest available#123

Merged
AquiGorka merged 1 commit into
mainfrom
refactor/drop-kv-cursor
Jun 19, 2026
Merged

refactor(event-watcher): drop Deno.KV state store; boot syncs from oldest available#123
AquiGorka merged 1 commit into
mainfrom
refactor/drop-kv-cursor

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

Why

provider-platform kept a second state store outside Postgres: the event-watcher cursor and the channel registry lived in a Deno.KV file (./.data/memory-kvdb.db), and that same file also backed in-flight auth sessions. A store outside the DB means wiping Postgres doesn't reset the instance (a testnet-reset blocker), and the KV cursor advance wasn't transactional with the state it gated — a crash (or the ephemeral .data dir vanishing on a Fly redeploy) could silently skip the gap.

Everything the watcher derives is authoritatively re-queryable, so provider-platform doesn't need a durable cursor or a persisted registry — it converges by querying the council on boot (existing path) and watches forward.

What

  • EventWatcher holds no durable cursor. A fresh watcher syncs all available history from the oldest ledger the RPC still retains (getHealth.oldestLedger); BOOT_SYNC_START_LEDGER_BLOCK overrides the start. Never defaults to "latest" (that would skip the gap). Out-of-retention recovery still re-queries the council.
  • ChannelRegistry rebuilt in-memory each boot — converge-by-query + this PP's own DB are the sources of truth. No KV persistence.
  • Sessions moved to a plain in-memory Map; deleted persistence/kv/config.ts's disk KV and its entity. No Deno.openKv / .data / memory-kvdb anywhere in the running path (--unstable-kv dropped from serve).
  • Inject rpc + startLedgerBlock into EventWatcher (decouples process.ts from env so the boot-ledger behavior is deterministically testable).

Net: a wipe of Postgres alone now fully resets the instance — no surviving state file.

Tests

fmt / lint / check / test green on Deno 2.8.2 (CI pin). New deterministic unit tests cover: boot start = oldest-available when the override is unset, = the exact ledger when set, and the no-durable-cursor / re-sync-on-restart property.

Companion

Paired with council-platform's cursor→Postgres relocation (the event-only root that genuinely needs a durable cursor). Independent at runtime — council still exposes the same public query; this provider still queries it.

Version bump 0.8.0 → 0.9.0.

…dest available

Removes the second state store so a Postgres wipe fully resets the instance.

- EventWatcher holds no durable cursor. A fresh watcher syncs ALL available
  history from the oldest ledger the RPC still retains (getHealth.oldestLedger);
  BOOT_SYNC_START_LEDGER_BLOCK overrides the start. Never defaults to "latest".
- ChannelRegistry is rebuilt in-memory each boot (converge-by-query + this PP's
  own DB are the authoritative sources) — no KV persistence.
- Sessions move to a plain in-memory Map; delete persistence/kv/config.ts disk
  KV and its entity. No Deno.openKv / .data / memory-kvdb anywhere in the path.
- Inject rpc + startLedgerBlock into EventWatcher (decouples process.ts from env
  so the boot-ledger behavior is deterministically testable).

Version bump 0.8.0 -> 0.9.0.
@AquiGorka

Copy link
Copy Markdown
Contributor Author

Companion PR (council cursor → Postgres): Moonlight-Protocol/council-platform#48

@AquiGorka
AquiGorka merged commit d071b51 into main Jun 19, 2026
7 checks passed
@AquiGorka
AquiGorka deleted the refactor/drop-kv-cursor branch June 19, 2026 11:52
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