Status#

Reference · Operators

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.latest

view.

keepalive_latest FINAL joined to nodes: the newest record of every node with node_id and trust.

shirudo.node_label_items

view.

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_labels

view.

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_conflicts

view.

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_conflicts

view.

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_mv

refreshable 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_mv

refreshable 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_mv

materialized view, on insert.

node_ops (code 1) joined to tree_ops → node_sets.

shirudo.node_status_mv

refreshable MV, every 1 minute.

Runs checks 1–7 for all nodes and replaces node_status.

shirudo.node_ops#

Derived by a view

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_mv into node_sets

Queried by:

history_conflicts (view); node_ops_mv into node_ops; node_status_mv into node_status; node_vulns_mv into node_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

ak_name

String

Node.

tree_id

String

Tree.

seq

UInt64

Operation.

code

UInt8

1 applied, 2 selector did not match, 3 attach module not loaded, 0 gap.

root

FixedString(32)

The node’s projection root after this seq (raw SHA-256 bytes).

shirudo.node_sets#

Derived by a view

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_mv on insert into node_ops

Fires on insert:

nothing

Queried by:

node_status_mv into node_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

ak_name

String

Node.

tree_id

String

Tree.

id

String

Upatch.

last_seq

UInt64

Newest applied operation for that upatch.

last_op

Enum8('add' = 1, 'delete' = 2)

Whether it was loaded or removed.

last_payload

String

payload_sha256 of that operation.

shirudo.history_contradictions#

Derived by a view

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_mv into node_ops; history_contradictions_mv into history_contradictions; node_status_mv into node_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

ak_name

String

Node.

tree_id

String

Tree whose history it contradicted.

seq

UInt64

First seq where it differed. Shown in check 4 as ‘marked: contradicted history at seq <seq>’.

reason

Enum8('base' = 1, 'window' = 2)

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.

marked_at

DateTime

When the mark was set; default now().

DEFAULT now()

shirudo.node_status#

Derived by a view, read by the UI

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_mv into node_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

node_id

String

Label from nodes.

ak_name

String

Identity.

host_name

String

Host name the newest record claimed.

status

Enum8('healthy' = 1, 'unhealthy' = 2, 'stale' = 3)

stale wins over everything; unhealthy if any of checks 3–7 fails.

trust

Enum8('untrusted' = 0, 'enrolled' = 1)

From nodes. Never part of status.

failed_check

UInt8

First failing check: 2 for stale, 3–7 for unhealthy, 0 for healthy.

log

Array(String)

Seven lines, one per check, e.g. ‘5 head: pass, seq 3 of 3, generation 3’.

last_seen

DateTime64(3)

received of the newest record.

generation

Nullable(UInt64)

From the newest record. NULL with no tree.

last_seq

Nullable(UInt64)

From the newest record.

head_seq

Nullable(UInt64)

Head of the newest loaded publication of the node’s tree.

loaded

UInt64

count from the record.

set_sha256

String

From the record.

updated_at

DateTime

When the row was computed.