Skip to content

feat(blocks): record every block since genesis - #16

Merged
aeddi merged 79 commits into
mainfrom
feat/block-history
Nov 19, 2026
Merged

aeddi merged 79 commits into
mainfrom
feat/block-history

Conversation

@aeddi

@aeddi aeddi commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

gnockpit records every block since genesis in its SQLite database, at about 100 bytes a block (about 130 MB for onyx's 1.25M blocks). It fills the history back from the first -rpc in paced JSON-RPC batches, then follows the chain head. Each block keeps:

  • its time, proposer and round;
  • its validator set, with public keys;
  • who did not sign it for the block, and how: absent, nil, or a precommit for another block;
  • each validator's vote delays, as daily histograms;
  • for late blocks, the expected proposer of each round, and a flag when the proposer check fails;
  • the events behind each validator-set change.

What it changes:

  • Missed-block counts (the validators table's Missed 24h, and /api/stats' windows) come from this history. They are complete as soon as the fill covers the window, rather than counted from gnockpit's start. The forward-only, 31-day signing history is removed. The live 100-block window counts a precommit for another block as missed, as the history does.
  • /api/history gives how far the history reaches and the fill rate; ?from=&to= the blocks of up to 1,000 heights with their validator sets; ?days=N the daily vote-delay histograms.
  • --history-pace and --history-batch set the fill's load on the source, per network.
  • While the history fills, Network State's header shows the share filled and the time left. The indicator disappears once the history is complete.

Why: the validator page and the ranking (next steps) are computed from these facts.

Changes

  • RPC: commits read in JSON-RPC batches through the single-call path; validator sets with priorities; block events. The live window keeps final commits across refreshes, forgets an earlier chain's, and counts a precommit for another block as missed. — 8cdb764, 65507e2, ffb962d, d908213, 9a2a1de, 51b85bd, 4989e61

  • Block history: a port of tm2's proposer priorities, the per-block record, the store and the fill loop. — 5f2dafa, 321e080, b9bee92, 16dd053, 9c9a568

  • Compact store, about 11× smaller: each validator address stored once, keyed tables without row ids and no secondary index; a window's misses counted from per-day counters, its first block found by bisecting heights. — c151134, b55967f, ae27f4f, 6465d36, 838a35f

  • Missed-block counts from the history, and /api/history with every fact the history keeps. — 7aa57db, 644e762, 92b3a3a, 314908e

  • The fill flags. — 8a76bd6

  • A fill that holds behind load balancers and rate limits:

    • only final commits are stored; a backend behind the head is waited for quietly, and reported after 2 minutes;
    • the oldest block the source serves is set only on proof (served right before a refusal, in two answers) and checked again at each start; a refusal that proves nothing pauses the backfill instead;
    • a batch refused whole halves the batch size until restart, one that times out for 10 minutes;
    • HTTP 429 waits Retry-After on every read; catching up after downtime goes at the pace;
    • set-change events that could not be read are retried; a late block whose set below the source does not keep is flagged rather than stalling the fill; an empty validator set is refused.

    — 7955682, e4609e3, 1ac89dd, 518fb52, 08f7864, e437a55, 16e45ac, ef0057b, 9fb499b, 85156c4, b04535a, 879cdd1, d34af06, 6e1215d, bc699fe, 4312b7e

  • The sync indicator in Network State's header, with a server-side fill rate. — 4e5f691, 2c03e25, f28ddc4, d29759a

  • Docs: README (block history, flags, /api/history) and AGENT.md. — fe35a22, 8390283, fa4b0ed

Testing

  • go test ./... covers:
    • the fill loop against a fake chain: lagging backends, batch limits, timeouts, 429s, refusals, floors, chain changes. Each failure-path test was checked to fail on a mutant of the line it guards;
    • the store's query plans (EXPLAIN QUERY PLAN) and its size;
    • the proposer port, on mainnet validator sets, including round-1 blocks.
  • Live on onyx, through a local SSM tunnel, from an empty history:
    • the fill ran at 13–15 blocks/s (capped by the tunnel), with no errors;
    • the per-day counters equal the raw absences (7,425), and the 1h window equals a direct count;
    • a round-1 block's expected proposers match the chain;
    • 106 bytes a block.
  • UI checked on desktop and in the iOS Simulator.

On first start, the old signing_blocks and signing_misses tables are dropped and the fill begins: at the defaults, at most about 100 blocks a second, so 1.6M blocks take at least 4.5 hours. --db-path should be persistent.

Screenshots

aeddi added 30 commits November 19, 2026 08:35
aeddi added 29 commits November 19, 2026 12:37
…ch refusal and the pause reset on a chain change
@aeddi
aeddi merged commit 815ab4f into main Nov 19, 2026
1 check passed
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