Phase 2b: log tailer, block history, stdlib WebSocket push

Adds real-time block detection via ckpool log tailing and a push
channel for the upcoming Svelte UI, all stdlib-only:

- logmon.Tailer follows ckpool.log with rotation/truncation survival
  (inode + size tracking) and parses "Solved and confirmed block N"
  into BlockEvent values.
- state.Aggregator grows a 256-entry block ring, an OnRefresh hook,
  and IngestBlockEvents which best-effort enriches events with the
  block hash via bitcoind getblockhash.
- httpapi.Hub implements RFC 6455 from scratch (SHA1 handshake,
  unmasked text frames out, masked frames in, ping keepalive,
  per-client write mutex, slow-client drop) so we don't pull in a
  ws dependency before we can go mod tidy.
- New routes: GET /api/blocks and GET /api/ws. Snapshot pushes fire
  on every poll tick and immediately on block-solve.

ZMQ hashblock subscription and SQLite persistence are deferred to
Phase 2b.5 once the s9pk packaging repo exists and we have a real
build environment for adding Go deps.
This commit is contained in:
satoshi
2026-04-13 02:53:27 +03:00
parent bd0b1b0318
commit 0a40b8f84f
9 changed files with 633 additions and 14 deletions
+13 -10
View File
@@ -40,7 +40,8 @@ Three main components:
- [x] **Phase 1** — Fork & fix CKPool, build infrastructure
- [~] **Phase 2** — Go API middleware
- [x] Phase 2a: CKPool socket client, bitcoind RPC, state aggregator, REST API
- [ ] Phase 2b: ZMQ block notifier, WebSocket push, SQLite persistence, log tailer
- [x] Phase 2b: CKPool log tailer, block history, stdlib WebSocket push
- [ ] Phase 2b.5: ZMQ block notifier, SQLite persistence (deferred until s9pk repo exists — need real Go build env for new deps)
- [ ] **Phase 3** — Svelte UI dashboard
- [ ] **Phase 4** — Monorepo Docker build, full stack integration
- [ ] **Phase 5** — Testing (regtest, testnet4), polish
@@ -54,16 +55,18 @@ curl localhost:8080/api/health
curl localhost:8080/api/pool
```
REST endpoints (Phase 2a):
REST endpoints:
| Route | Returns |
| -------------------- | ---------------------------------------------------- |
| `GET /api/health` | CKPool + bitcoind health |
| `GET /api/pool` | Pool stats + derived hashrate windows + chain info |
| `GET /api/users` | All users from `users` socket command |
| `GET /api/workers` | All workers from `workers` socket command |
| `GET /api/clients` | All connected stratum sessions (useragent, IP, diff) |
| `GET /api/snapshot` | Full merged snapshot (everything) |
| Route | Returns |
| -------------------- | ----------------------------------------------------------- |
| `GET /api/health` | CKPool + bitcoind health |
| `GET /api/pool` | Pool stats + derived hashrate windows + chain info |
| `GET /api/users` | All users from `users` socket command |
| `GET /api/workers` | All workers from `workers` socket command |
| `GET /api/clients` | All connected stratum sessions (useragent, IP, diff) |
| `GET /api/blocks` | Recent solved blocks (in-memory ring, SQLite in Phase 2b.5) |
| `GET /api/snapshot` | Full merged snapshot (everything) |
| `GET /api/ws` | WebSocket push: full snapshot on every refresh + on solve |
StartOS packaging lives in a separate repository.