Enrich found-block records with real coinbase reward

Adds RPC.GetBlock(hash, verbosity=2) and a CoinbaseReward
helper that sums the first tx's outputs. IngestBlockEvents
now does getblockhash -> getblock -> sum(vout) so
BlockRecord.RewardBT carries the actual BTC paid out on
solve instead of always being zero. Both RPC calls share a
single 5s deadline and are best-effort — bitcoind being
down just leaves the reward at zero.
This commit is contained in:
satoshi
2026-04-14 17:02:39 +03:00
parent b786f489a1
commit 89904d5e08
2 changed files with 54 additions and 1 deletions
+10 -1
View File
@@ -35,11 +35,20 @@ func (a *Aggregator) IngestBlockEvents(ctx context.Context, events <-chan logmon
FoundAt: ev.SeenAt,
Source: "logmon",
}
// Best-effort enrich with hash via bitcoind.
// Best-effort enrich with hash + coinbase reward via bitcoind.
// We look up the hash from height, then fetch the full block
// (verbosity 2) to sum the coinbase outputs. Both are fire-
// and-forget — if bitcoind is down we still record the block
// with whatever we have.
if a.RPC != nil {
lookupCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
if hash, err := a.RPC.GetBlockHash(lookupCtx, ev.Height); err == nil {
rec.Hash = hash
if blk, err := a.RPC.GetBlock(lookupCtx, hash); err == nil {
rec.RewardBT = blk.CoinbaseReward()
} else {
a.Log.Warn("bitcoind getblock failed", "hash", hash, "err", err)
}
} else {
a.Log.Warn("bitcoind getblockhash failed", "height", ev.Height, "err", err)
}