Status#
Once a minute: extend each node’s operation history, mark nodes whose records contradict it, then run checks 1–7 for every node and replace node_status in one step. Nothing here reads shirudo.keepalive.
Schema: tools/backend/sql/40-status.sql
Views, functions and jobs#
mask_code(mask, i)SQL function (global).
Outcome pair of the i-th operation of a mask’s window: 1, 2, 3, or 0 for not reached. Bad base64 or a short mask reads as 0, so one forged record can’t break the refresh.
shirudo.latestview.
keepalive_latest FINAL joined to nodes: the newest record of every node with node_id and trust.
shirudo.node_label_itemsview.
label_sets FINAL joined to nodes and keepalive_latest: one row per node, set and label, from the sets put under the node’s ak_name, its node_id and the config_root of its newest record, with rank 3, 2 and 1.
shirudo.node_labelsview.
node_label_items per node: labels, the union of its sets, where a key in several takes the value of the highest rank; sources, per key, the name that value was put under; conflicts, how many keys the sets gave different values.
shirudo.label_conflictsview.
node_label_items per node and key whose sets give different values: the value of the highest rank, by, its name, and given, every (rank, by, value), highest first.
shirudo.history_conflictsview.
Nodes whose newest record contradicts their stored history: base_root against the root at base_seq, and every code and folded root of the window against the stored rows it overlaps. Gives the first differing seq and reason base or window.
shirudo.node_ops_mvrefreshable MV, every 1 minute, APPEND.
Appends to node_ops what each node’s newest record adds past its stored history, folding roots once per distinct path. Skips nodes in history_conflicts or history_contradictions.
shirudo.history_contradictions_mvrefreshable MV, every 1 minute, APPEND.
Adds a mark to history_contradictions for each node and tree in history_conflicts that has none yet.
shirudo.node_sets_mvmaterialized view, on insert.
node_ops (code 1) joined to tree_ops → node_sets.
shirudo.node_status_mvrefreshable MV, every 1 minute.
Runs checks 1–7 for all nodes and replaces node_status.
shirudo.node_ops#
Each node’s history: what it did at every tree operation the backend has seen it reach. Lets checks 4 and 6 and node_vulns look below the 512-operation window a keepalive covers.
code 0 is a gap: the node’s record started past the stored history, so nothing below that seq is known. The gap row holds the unverified base_root of that record.
Rows are only appended when every operation is in tree_ops, none up to last_seq is unreached, and the fold ends at the record’s projection_root. An inconsistent record adds nothing.
A record that contradicts the stored rows (history_conflicts) adds nothing, and neither does any record of a node marked in history_contradictions, gap rows included.
Projection reach keeps max(seq), argMax(root, seq) and the first gap per (ak_name, tree_id), so a refresh reads one row per node. deduplicate_merge_projection_mode = ‘rebuild’ is required for a ReplacingMergeTree to keep it.
- Engine:
ReplacingMergeTree- Order by:
(ak_name, tree_id, seq)- TTL:
None: rows are never removed (README.md, History, explains the cost)
- Settings:
deduplicate_merge_projection_mode = 'rebuild'- Defined in:
tools/backend/sql/40-status.sql- Written by:
node_ops_mv(refresh every 1 minute, append)- Fires on insert:
node_sets_mvintonode_sets- Queried by:
history_conflicts(view);node_ops_mvintonode_ops;node_status_mvintonode_status;node_vulns_mvintonode_vulns- Row size:
~34 B (README), mostly the 32-byte root, which does not compress.
- Scale:
Nodes × operations each node reaches, every outcome counted, including selector misses. No TTL. Grows with publishing, not with keepalive rate.
- Reference fleet:
650M rows ≈ 22 GB (README)
Columns (5)
Column |
Type |
Meaning |
|---|---|---|
|
|
Node. |
|
|
Tree. |
|
|
Operation. |
|
|
1 applied, 2 selector did not match, 3 attach module not loaded, 0 gap. |
|
|
The node’s projection root after this seq (raw SHA-256 bytes). |
shirudo.node_sets#
Per node, the newest operation of every upatch it applied, from node_ops rows with code 1. This is what the node’s history leaves loaded, used by check 6 when a window starts past seq 0.
- Engine:
ReplacingMergeTree(last_seq)- Order by:
(ak_name, tree_id, id)- TTL:
None
- Defined in:
tools/backend/sql/40-status.sql- Written by:
node_sets_mvon insert intonode_ops- Fires on insert:
nothing
- Queried by:
node_status_mvintonode_status- Row size:
~70 B (README).
- Scale:
Nodes × upatches each node ever applied. No TTL.
- Reference fleet:
1,000 upatches each: 10M rows ≈ 700 MB
Columns (6)
Column |
Type |
Meaning |
|---|---|---|
|
|
Node. |
|
|
Tree. |
|
|
Upatch. |
|
|
Newest applied operation for that upatch. |
|
|
Whether it was loaded or removed. |
|
|
payload_sha256 of that operation. |
shirudo.history_contradictions#
Marks on nodes whose record once contradicted their stored history, one row per node and tree. A mark fails check 4 and stops the node’s history from growing until an operator deletes it.
The mark is stricter than the record that set it. It holds whatever tree the node’s newest record follows and whatever boot it comes from, and it fails check 4 even when check 4 would otherwise skip the node (no tree, no mask, publication unknown).
Neither a reboot nor a gap clears it, so a node that lied once cannot launder the lie by staying silent until its window moves past the history.
Clear it after looking at the node, for example with shirudo attest: DELETE FROM shirudo.history_contradictions WHERE ak_name = ‘<ak_name>’.
- Engine:
MergeTree- Order by:
(ak_name, tree_id)- TTL:
None: cleared only by an operator’s
DELETE- Defined in:
tools/backend/sql/40-status.sql- Written by:
history_contradictions_mv(refresh every 1 minute, append)- Fires on insert:
nothing
- Queried by:
node_ops_mvintonode_ops;history_contradictions_mvintohistory_contradictions;node_status_mvintonode_status- Row size:
~80 B (estimate).
- Scale:
Marked nodes × trees. Grows only when nodes lie; cleared by the operator.
- Reference fleet:
negligible
Columns (5)
Column |
Type |
Meaning |
|---|---|---|
|
|
Node. |
|
|
Tree whose history it contradicted. |
|
|
First seq where it differed. Shown in check 4 as ‘marked: contradicted history at seq <seq>’. |
|
|
base: base_root differs from the stored root at base_seq. window: a code or folded root inside the window differs from a stored row. |
|
|
When the mark was set; default now().
|
shirudo.node_status#
One row per node with the outcome of all seven checks. This is what a UI reads, as often as it likes.
Checks: 1 signed, 2 fresh, 3 reported, 4 chain, 5 head, 6 set, 7 peers. Each only means something if the ones before it passed.
Check 7 compares an enrolled node with enrolled nodes only: untrusted keys cost nothing to make.
Checks 4–7 pass with a reason when the node cannot be held against a tree: no tree, no mask, or publication unknown (ingest is behind).
A node behind the head is healthy until stuck_seconds after the earliest publication it has not finished was loaded; line 5 reads behind.
Check 4 also fails when the record contradicts the stored history (‘base differs from history’, ‘window differs from history at seq N’) or the node carries a mark (‘marked: contradicted history at seq N’). A mark fails it even for a node check 4 would otherwise skip.
- Engine:
MergeTree- Order by:
(node_id, ak_name)- Defined in:
tools/backend/sql/40-status.sql- Written by:
node_status_mv(refresh every 1 minute, replaces the table)- Fires on insert:
nothing
- Queried by:
node_vulns_mvintonode_vulns; the UI- Row size:
~0.7 KB (estimate: seven log lines dominate).
- Scale:
Nodes. The whole table is rewritten every minute.
- Reference fleet:
10,000 rows ≈ 7 MB, rewritten every minute
Columns (14)
Column |
Type |
Meaning |
|---|---|---|
|
|
Label from nodes. |
|
|
Identity. |
|
|
Host name the newest record claimed. |
|
|
stale wins over everything; unhealthy if any of checks 3–7 fails. |
|
|
From nodes. Never part of status. |
|
|
First failing check: 2 for stale, 3–7 for unhealthy, 0 for healthy. |
|
|
Seven lines, one per check, e.g. ‘5 head: pass, seq 3 of 3, generation 3’. |
|
|
received of the newest record. |
|
|
From the newest record. NULL with no tree. |
|
|
From the newest record. |
|
|
Head of the newest loaded publication of the node’s tree. |
|
|
count from the record. |
|
|
From the record. |
|
|
When the row was computed. |