isOpenSource was matching things like Braiins OS, cgminer, bfgminer,
and a generic "esp32" — software that's open but runs on closed
hardware (Antminer, unknown rigs). public-pool's UI reserves the
star for open-source HARDWARE, with open firmware on top, and that's
the convention to match. New regex covers the family verbatim from
public-pool-ui's user-agent-link switch table:
bitaxe, bitaxeHex, NerdMiner, NerdNOS, NerdAxe, NerdAxeGamma,
NerdOCTAXE, NerdEKO, NerdQAxe+, NerdQAxe++, PiAxe, QAxe, QAxe+,
0xAxe, LeafMiner
Also extend detectHardware so all those user-agents get a recognised
label instead of "esp32" / raw token.
Replace the squished "TLS" pill with an inline-flex badge: 0.78em
text, 5px corners, padlock SVG, generous left/right padding so it
reads at a glance instead of looking like a typo.
Custom block explorer: new optional union under StartOS Advanced
config ("Block Explorer" — defaults to "mempool.space"). Picking
"Custom URL" surfaces the value as MEMPOOL_BASE_URL on the
container env. config.Config picks it up, the aggregator copies
it into every Snapshot (mempool_base_url field), and the UI's
shared explorerBaseFor() helper trusts the custom URL verbatim
when present (no /testnet4 / /signet path appended — a self-hosted
instance is presumably single-network already). Falls back to the
public mempool.space mirrors per chain when unset, which is the
default behaviour.
107 lines
3.2 KiB
Go
107 lines
3.2 KiB
Go
// kamado-api is the middleware that sits between ckpool-solo and the
|
|
// Kamado dashboard. It polls ckpool's Unix socket API, calls bitcoind
|
|
// over JSON-RPC, and serves the merged state over REST (WebSocket push,
|
|
// SQLite persistence, ZMQ and log-tailer-based block detection land in
|
|
// a follow-up commit).
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/kamadopool/kamado-api/internal/bitcoind"
|
|
"github.com/kamadopool/kamado-api/internal/ckpool"
|
|
"github.com/kamadopool/kamado-api/internal/config"
|
|
"github.com/kamadopool/kamado-api/internal/httpapi"
|
|
"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() {
|
|
log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
|
|
slog.SetDefault(log)
|
|
|
|
cfg, err := config.FromEnv()
|
|
if err != nil {
|
|
log.Error("config", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
log.Info("kamado-api starting",
|
|
"listen", cfg.ListenAddr,
|
|
"sockdir", cfg.CKPoolSockDir,
|
|
"bitcoind", cfg.BitcoinRPCURL,
|
|
"poll_interval", cfg.PollInterval,
|
|
)
|
|
|
|
ck := ckpool.New(cfg.CKPoolSockDir)
|
|
rpc := bitcoind.NewRPC(cfg.BitcoinRPCURL, cfg.BitcoinRPCUser, cfg.BitcoinRPCPassword, cfg.BitcoinRPCTimeout)
|
|
|
|
// Persistent block history. Non-fatal if it can't be opened — the
|
|
// aggregator falls back to an in-memory ring so the pool keeps
|
|
// running even with a broken data volume.
|
|
var blockStore *store.BlockStore
|
|
if cfg.DBPath != "" {
|
|
if s, err := store.Open(cfg.DBPath); err != nil {
|
|
log.Warn("block store open failed, running without persistence", "path", cfg.DBPath, "err", err)
|
|
} else {
|
|
blockStore = s
|
|
defer blockStore.Close()
|
|
log.Info("block store opened", "path", cfg.DBPath)
|
|
}
|
|
}
|
|
|
|
agg := state.New(ck, rpc, cfg.PollInterval, log)
|
|
agg.Store = blockStore
|
|
agg.MempoolBaseURL = cfg.MempoolBaseURL
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
api := httpapi.New(agg, log)
|
|
|
|
// Wire snapshot refreshes into the WebSocket hub so subscribers get
|
|
// real-time updates without polling.
|
|
agg.OnRefresh = api.Hub.Broadcast
|
|
|
|
// 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)
|
|
|
|
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)
|
|
|
|
srv := &http.Server{
|
|
Addr: cfg.ListenAddr,
|
|
Handler: api.Handler(),
|
|
ReadHeaderTimeout: 5 * time.Second,
|
|
}
|
|
|
|
// Shutdown on ctx cancel
|
|
go func() {
|
|
<-ctx.Done()
|
|
log.Info("shutting down")
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
_ = srv.Shutdown(shutdownCtx)
|
|
}()
|
|
|
|
log.Info("http listening", "addr", cfg.ListenAddr)
|
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
log.Error("http server", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|