The consensus committee¶
How consensus_committee runs a CometBFT network of virtual relayer nodes in one container, decides what to order, and hands each committed event to the executor exactly once.
You will learn / You need
You will learn: the process layout, the ingest path, what each ABCI call does on honest and Byzantine nodes, the three formulas that size the committee, and how deliveries are authenticated. You need: The committee (in particular BFT in one page), Running the committee, and the handler deep dive.
Where the code lives¶
| File | What it holds |
|---|---|
stealth_name_service/backend/testing_backend/src/bin/consensus_committee.rs |
The binary: startup, ingest HTTP route, broadcast workers, liveness, /api/status. |
stealth_name_service/backend/testing_backend/src/consensus/config.rs |
CommitteeConfig, roles, the BFT formulas, ports. |
stealth_name_service/backend/testing_backend/src/consensus/app.rs |
The ABCI application: NodeState, CommitteeApp, the ACL view. |
stealth_name_service/backend/testing_backend/src/consensus/strategy.rs |
Byzantine strategies. |
stealth_name_service/backend/testing_backend/src/consensus/node.rs |
CometBFT homes, config.toml edits, genesis, process spawning, RPC client. |
stealth_name_service/backend/testing_backend/src/consensus/sink.rs |
CommitTracker and the delivery loop. |
stealth_name_service/backend/testing_backend/src/consensus/tx.rs |
CommitteeTx, TxKey, ConsensusMeta. |
stealth_name_service/backend/testing_backend/src/consensus/auth.rs |
DeliveryKey: HMAC-SHA256 of each delivery. |
stealth_name_service/backend/testing_backend/src/consensus/recent.rs |
RecentMap / RecentSet: bounded memory with oldest-first eviction. |
Process layout¶
Everything runs in one container (docker-compose.consensus.yml, service consensus_committee). The
Rust process hosts one ABCI application per validator; each validator is a real cometbft child
process on localhost.
flowchart LR
L["event_listener"] -->|"POST /api/handle_event"| I["ingest route"]
subgraph C["consensus_committee container"]
I --> Q["ingest queue"]
Q --> W["broadcast workers"]
W -->|"broadcast_tx_sync"| N0["cometbft node0"]
W --> N1["cometbft node1"]
W --> N2["cometbft node2"]
W --> N3["cometbft node3"]
N0 <-->|ABCI| A0["app 0"]
N1 <-->|ABCI| A1["app 1"]
N2 <-->|ABCI| A2["app 2"]
N3 <-->|ABCI| A3["app 3"]
A0 --> T["CommitTracker"]
A1 --> T
A2 --> T
A3 --> T
T --> D["delivery loop"]
end
D -->|"signed POST"| H["event_handler"]
Startup¶
main() in src/bin/consensus_committee.rs runs these steps in order:
CommitteeConfig::from_env()andvalidate(). Impossible configurations are errors; exceeding the BFT bound is only a warning (bound_warning()), because that is an experiment you may want.DeliveryKey::from_env():CONSENSUS_DELIVERY_KEYmust be at least 32 bytes.- Bind the HTTP listener on
CONSENSUS_LISTEN_ADDR(default0.0.0.0:5000), so the healthcheck does not kill a slow start. load_acl(): the first ACL snapshot (see ACL view).prepare_homes()insrc/consensus/node.rs: wipeCONSENSUS_HOME,cometbft initone home per validator (faulty ones included: they are in the validator set but never run), one extra home per equivocation twin with a copy of the primary's validator key, one shared genesis with every validator at equal power (VOTING_POWER10), andconfig.tomledits for the live nodes.- Start one ABCI server per process on its own thread, then spawn the
cometbft startchildren. Each logs to<home>/cometbft.log, is killed when the parent drops it, and receivesSIGKILLif the parent dies. - Wait until every node answers RPC (
NODE_READY_TIMEOUT, 60 s). - Start the tracker, the delivery loop and
CONSENSUS_INGEST_WORKERSbroadcast workers, then the routes/api/handle_event,/api/status,/health. - Watch the children. A dead process is not restarted. When every one has exited, the binary exits with an error.
configure_toml() binds RPC and P2P to 127.0.0.1, disables PEX and empty blocks, sets the timeouts
from the environment, and turns the tx indexer off.
Ports¶
Process i (validators first, then twins) gets a block of PORT_STRIDE (10) ports from
CONSENSUS_BASE_PORT (default 26656), from ports() in src/consensus/config.rs:320-323:
| Port | Offset |
|---|---|
| P2P | base + 10·i |
| RPC | base + 10·i + 1 |
| ABCI | base + 10·i + 2 |
Roles¶
role() (config.rs:268-277) assigns indices in order: honest first, then
CONSENSUS_BYZANTINE_NODES Byzantine nodes, then CONSENSUS_FAULTY_NODES faulty ones. With equal power
CometBFT rotates the proposer over all validators, so the order does not change who proposes.
The formulas¶
n is CONSENSUS_NODES, live = n − faulty.
| Quantity | Code | Formula |
|---|---|---|
Tolerated faults f |
max_tolerated(), config.rs:244-246 |
(n − 1) / 3, rounded down |
| Quorum | has_quorum(live), config.rs:281-283 |
live × 3 > n × 2 |
| Delivery threshold | delivery_threshold(), config.rs:306-308 |
min(f + 1, live), at least 1 |
Worked examples:
| Setup | f |
Quorum? | Threshold | What happens |
|---|---|---|---|---|
n=1 |
0 | yes (3 > 2) | 1 | One node orders everything. No fault tolerance. |
n=4 |
1 | yes, needs live ≥ 3 |
2 | Survives one crash or one Byzantine node. |
n=7 |
2 | yes, needs live ≥ 5 |
3 | Survives two. |
n=4, 3 faulty |
1 | no (3 > 8 is false) | 1 | Nothing commits. The committee stays healthy because it was configured that way. |
The threshold is f + 1 so that at least one report comes from a node the BFT assumption counts as
correct. It is capped at live so a committee configured past its bound still delivers, and the
unsafe commit it was built to show is visible.
Ingest¶
sequenceDiagram
participant L as event_listener
participant I as ingest()
participant S as NodeState (every node)
participant Q as ingest queue
participant W as broadcast worker
participant N as cometbft
L->>I: POST event
I->>I: liveness, validate_event, committed?, ACL
I->>S: observe(tx) on every node
I->>Q: queue
I-->>L: 202 queued
W->>Q: take
W->>N: broadcast_tx_sync (round robin)
N-->>W: accepted / duplicate / rejected
ingest() encodes the body as a CommitteeTx (deterministic JSON, no ingest timestamp, so a retry is
byte-identical) and answers:
| Condition | Response |
|---|---|
| Body does not encode | 400 |
| Liveness lost | 503 unavailable |
validate_event() fails (the handler's own intent_from_event() check) |
202 rejected |
| Already committed | 202 duplicate |
| Source sender not in the ACL | 202 rejected |
| Already in flight | 202 duplicate |
Ingest queue full (CONSENSUS_INGEST_QUEUE) |
503 overloaded |
| Otherwise | 202 queued |
Every node observes the event before it is broadcast. Observation is what an honest node later checks a proposal against: it accepts only events it saw itself. A broadcast worker retries an unreachable node forever, with backoff from 100 ms doubling to 5 s. Once a node answers, the event is forgotten from every node's pending set if it was rejected.
The ABCI application¶
CommitteeApp in src/consensus/app.rs implements four calls. NodeState holds a Ledger of
pending and committed keys (RecentSets of RECENT_CAPACITY) and a ChainState { height, app_hash },
both defined in src/consensus/app.rs.
| ABCI call | Honest node | Purpose |
|---|---|---|
check_tx |
check(): decodes, validates, checks the ACL, and requires the event to be pending (observed, not committed). Refusal is code 1 with a reason. |
Mempool admission. |
prepare_proposal |
honest_proposal(): mempool order, no repeats, within max_tx_bytes. |
The block this node proposes. |
process_proposal |
honest_verdict(): every tx must pass check(), no tx may repeat. |
Vote on someone else's block. |
finalize_block |
Moves keys from pending to committed, sends Commit to the tracker, reports misbehaviour as Evidence. The app hash changes only on non-empty blocks. |
Apply the decided block. |
An honest node that finalises an event it never observed logs committed an event this node never
observed; that is the visible sign of a committee past its bound.
Byzantine strategies¶
CONSENSUS_BYZANTINE_STRATEGY picks one StrategyKind for all Byzantine nodes (src/consensus/strategy.rs).
| Strategy | Proposes | Votes |
|---|---|---|
forge |
A tampered copy of every mempool tx plus one fabricated event. | Accepts everything; check_tx accepts everything. |
censor |
Empty blocks. | Honestly. |
delay |
Honestly, after CONSENSUS_BYZANTINE_DELAY_MS. |
Honestly. |
equivocate |
The primary proposes honestly; its twin proposes empty blocks. | The primary accepts everything, the twin rejects everything, with the same validator key. |
Tampering flips the last byte of the first argument, or appends 0xde 0xad when there are no
arguments; the claimed identity (digest, sequence) stays. An honest node rejects the copy because it
does not match what it observed. Equivocation produces double-sign evidence, which finalize_block
forwards to the tracker. See Committee experiments.
From commit to delivery¶
CommitTracker in src/consensus/sink.rs collects Commit messages from all nodes:
- It counts distinct reporters per event. When the count reaches
delivery_threshold()it delivers once; later reports are ignored. Delivered keys live in aRecentSet. - An event committed but never observed through ingest is logged
UNSAFE COMMIT: the committee committed an event it never observed. - Evidence is de-duplicated on (height, kind, offender).
- It builds
ConsensusMeta(height, first observation, commit and delivery times, reporters, committee shape and strategy), which becomes theconsensus_*CSV columns.
The delivery loop sends one event at a time to CONSENSUS_EXECUTOR_URL, signed with
x-committee-signature (hex HMAC-SHA256 of the body), with a per-attempt timeout of
CONSENSUS_DELIVERY_TIMEOUT_MS. It retries forever with backoff from 100 ms to 5 s. The handler
de-duplicates by body hash, so a retry after a lost reply is harmless.
The HMAC authenticates the committee process, not individual nodes. The key never appears in Debug
output.
ACL view¶
With CONSENSUS_CHECK_ACL on, load_acl() reads the BridgeAA ACL (BRIDGE_AA_ACCOUNT_ID,
BRIDGE_AA_PACKAGE_ID) with acl_senders() and refreshes it every CONSENSUS_ACL_REFRESH_SECS. A failed
refresh keeps the last snapshot. Until the first load succeeds, every event is refused (ACL not loaded
yet). With the check off, every sender passes.
Liveness¶
Liveness::check() in src/bin/consensus_committee.rs counts validators with at least one running
process (a twin counts with its primary):
| State | /health and ingest |
|---|---|
| Every process exited | Unhealthy: every CometBFT process has exited. |
| Configured with quorum, lost it at runtime | Unhealthy: only N of M validators are still running: below the quorum, nothing can commit. |
| Configured without quorum | Healthy; nothing commits. That stall is the experiment. |
While unhealthy, ingest answers 503 and the listener keeps its cursor.
Configuration knobs¶
All variables are in Configuration: Consensus committee.
The ones that shape the committee: CONSENSUS_NODES, CONSENSUS_FAULTY_NODES,
CONSENSUS_BYZANTINE_NODES, CONSENSUS_BYZANTINE_STRATEGY, CONSENSUS_TIMEOUT_PROPOSE_MS,
CONSENSUS_TIMEOUT_COMMIT_MS, CONSENSUS_SKIP_TIMEOUT_COMMIT. BRIDGE_SOURCE_CHAIN_ID and
BRIDGE_TARGET_CHAIN_ID are required, because validate_event() needs them.
Tests that pin the behaviour¶
| File | Tests |
|---|---|
src/consensus/config.rs |
bound_is_floor_of_n_minus_one_over_three, exceeding_the_bound_warns_but_is_not_an_error, impossible_configurations_are_errors, roles_are_honest_then_byzantine_then_faulty, delivery_needs_one_report_beyond_the_tolerated_faults, strategy_label_is_none_without_byzantine_nodes, quorum_needs_more_than_two_thirds, booleans_and_numbers_are_parsed_strictly, ports_do_not_overlap_and_twins_get_their_own_block |
src/consensus/app.rs |
a_disabled_acl_lets_every_sender_through, an_enabled_acl_refuses_everything_until_loaded, a_loaded_acl_allows_listed_senders_only, an_event_without_a_readable_sender_is_refused, an_honest_node_rejects_an_observed_event_whose_sender_is_not_in_the_acl, a_forgotten_observation_is_no_longer_accepted |
src/consensus/mod.rs |
honest_majority_rejects_forged_proposals, forged_proposals_commit_once_the_bound_is_exceeded, a_tampered_copy_of_an_observed_event_is_still_rejected, censorship_only_delays_events, a_delaying_proposer_still_proposes_honestly, an_equivocator_signs_conflicting_votes_and_is_caught, an_equivocator_cannot_push_through_an_invalid_proposal, an_equivocator_cannot_block_a_valid_proposal, equivocators_past_the_bound_can_commit_an_invalid_proposal, a_committed_event_cannot_be_replayed, a_retry_after_the_commit_never_becomes_pending_again, empty_blocks_do_not_change_the_app_hash, a_proposal_repeating_a_transaction_is_rejected, crashed_nodes_up_to_the_bound_do_not_stop_progress, observation_is_per_node |
src/consensus/strategy.rs |
strategy_names_round_trip, tampering_changes_the_call_but_keeps_the_claimed_identity, forger_replaces_real_events_and_adds_a_fabricated_one, censor_and_delay_vote_honestly, equivocating_twins_always_disagree |
src/consensus/sink.rs |
delivers_once_at_the_threshold_and_ignores_late_reports, evidence_is_counted_once_however_many_nodes_report_it, observation_time_is_the_first_one |
src/consensus/tx.rs |
encoding_is_deterministic_so_retries_are_duplicates, decodes_the_listeners_payload_shape, validation_is_the_executors_own_intent_check, delivered_event_is_a_superset_of_the_listener_payload |
src/consensus/auth.rs |
a_signature_verifies_only_for_its_body_and_key, short_or_missing_keys_are_refused, the_key_never_appears_in_debug_output |
src/consensus/recent.rs |
forgets_the_oldest_past_capacity, a_reinserted_key_is_not_evicted_by_its_stale_copy, removal_returns_the_value_and_keeps_order_bounded |
src/consensus/node.rs |
config_edits_land_in_the_right_sections, clearing_keeps_the_directory_itself, genesis_lists_every_validator_at_equal_power |
src/bin/consensus_committee.rs |
losing_the_quorum_at_runtime_makes_the_committee_unhealthy, a_committee_configured_below_quorum_stays_healthy, a_twin_counts_with_its_primary |
The mod.rs tests drive several NodeStates through simulated rounds without CometBFT. The end-to-end
check with real CometBFT processes is consensus_smoke.sh.