Add ZMQ hashblock subscriber for sub-second chain refresh
New internal/zmqmon package subscribes to bitcoind's hashblock ZMQ topic and emits TipEvents. Uses github.com/go-zeromq/zmq4 (pure Go, builds with CGO_ENABLED=0). Exponential backoff on connection failure so bitcoind restarts don't kill the subscriber permanently; event channel drops rather than blocks if the consumer is slow (signals are advisory, not logs). Aggregator.Run now takes a <-chan TipEvent; when a tip arrives it fires an immediate refresh() outside the normal ticker cadence. With a 5s poll interval and 0.5-1s ZMQ latency from bitcoind, dashboards now reflect new tips roughly 4x faster. Endpoint comes from BITCOIN_ZMQ_BLOCK — empty disables ZMQ entirely and the aggregator just runs on the ticker alone.
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/kamadopool/kamado-api/internal/logmon"
|
||||
"github.com/kamadopool/kamado-api/internal/state"
|
||||
"github.com/kamadopool/kamado-api/internal/store"
|
||||
"github.com/kamadopool/kamado-api/internal/zmqmon"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -69,9 +70,14 @@ func main() {
|
||||
// real-time updates without polling.
|
||||
agg.OnRefresh = api.Hub.Broadcast
|
||||
|
||||
go agg.Run(ctx)
|
||||
// Optional: bitcoind hashblock ZMQ subscription for sub-second
|
||||
// chain-tip refreshes. Empty endpoint disables it.
|
||||
zmq := zmqmon.New(cfg.BitcoinZMQBlock, log)
|
||||
go zmq.Run(ctx)
|
||||
|
||||
// Tail the ckpool log for block-solve events.
|
||||
go agg.Run(ctx, zmq.Events)
|
||||
|
||||
// Tail the ckpool log for block-solve events (our own solves).
|
||||
tailer := logmon.New(cfg.CKPoolLogFile, log)
|
||||
go tailer.Run(ctx)
|
||||
go agg.IngestBlockEvents(ctx, tailer.Events)
|
||||
|
||||
Reference in New Issue
Block a user