Choose what this site may use

This site uses strictly necessary cookies to work and to remember your privacy choices. With your permission it would also load content hosted by other services, such as videos, maps and fonts, which then receive your network address and device data. We do not sell or share your personal information and we run no advertising. Choose Accept all, Reject all or Customise. You can change your mind at any time through Privacy choices at the foot of every page.

  • Always on

    Needed for the site to work and to remember your privacy choices. Always on.

  • Remembers settings you choose, such as the light or dark display, in your browser.

  • Loads videos, maps and other content hosted by other services. Those services receive your address and device data.

Menu Close
In this section: Build
Start
Reference code
Tools
API reference
Public services
Agents
Bindings and crosswalks

obsp-federation

REFERENCE Source reference/rust/obsp-federation/README.md

On this page
  1. What it covers
  2. Checking the model’s invariants on randomised runs
  3. Trace-check: TLC counterexamples against the state machine
  4. Copied 0.5 material
  5. Findings for the editors of OIP-0004 (observations from building this; none changes a requirement here)
  6. Usage policies (draft OIP-0014)
  7. Does not cover
  8. Running
FieldValue
StatusReference service for a draft proposal against the 0.5 candidate (DRAFT); accepts no proposal; no conformance claim
Version0.0.1
SourceRust reference workspace

A reference federation service for the draft proposal OIP-0004 (federation: bindings, authority leases and partition behaviour), written against the schemas of the 0.5 candidate (make integration SERIES=0.5). Every contract it uses is DRAFT. Nothing here is a conformance claim: passing these tests says nothing about any implementation’s conformance level (see registers/conformance-profiles.yaml).

What it covers

Rule of OIP-0004 Where it is implemented Where it is tested
FED-1 no exchange without a valid binding signed once by each party docs::check_binding, Peer::binding_at, Peer::countersign tests/documents.rs, tests/scenarios.rs
FED-2 nothing exported outside the binding’s classes, namespaces, direction; holders are parties Peer::export_bundles, receive_write, docs::check_lease_terms scenarios.rs, http.rs, simulation (NoUnlistedExport)
FED-3 https exchange, event or evidence endpoints only docs::check_binding (and the schema) documents.rs
FED-4 command authority only under a lease voted by a quorum of distinct listed grantors, votes no later than the start Peer::vote, docs::check_lease, Peer::try_complete documents.rs, scenarios.rs
FED-5 one holder per epoch; a grantor waits for expiry plus the allowance; receivers reject older epochs Peer::vote, Peer::learn_lease simulation (SingleHolderPerEpoch, ExclusiveAuthority, EpochNeverDecreases), mutant, skew scenarios
FED-6 act only from the start until expiry less the allowance Peer::holds, Peer::receive_write simulation (NoWriteWithoutLease), mutant
FED-7 renewal keeps holder, epoch and scope; an expired lease is replaced by a grant at a higher epoch Peer::begin_renewal, Peer::vote documents.rs, scenarios.rs
FED-8 a holder that cannot renew goes read-only; PARTITION event names the scopes Peer::holds, Peer::note_contact, Peer::make_partition scenarios.rs, http.rs, simulation
FED-9 rejoin reconciles per record by epoch, then digest order; conflicting writes are correction candidates with a notice, never lost Peer::recompute, Peer::merge, Peer::make_rejoin simulation (NoLostWrite, NoErasure, Convergence), mutant, scenarios.rs
FED-10 joins, leaves, partitions, rejoins are signed events; LEAVE applies the exit terms Peer::make_*, receive_event, apply_exit scenarios.rs, http.rs
Draft OIP-0014 usage policies on transfers (off unless a Governance is configured): a record leaves or is taken in only when its policy permits distribute to FEDERATION_PEER and the binding’s honouredPolicies names that policy by UNI and RFC 8785 digest Peer::transfer_check, Peer::export_report, receive_write, Node::write tests/policy.rs

Pieces:

  • docs: the three contracts as documents (build, sign, verify, validate against the copied schemas); signatures are the draft OIP-0008 envelopes of obsp-core (Ed25519 here; the library signs and verifies the register’s other algorithms).
  • state: the deterministic state machine of one peer. No clock, network or randomness of its own: every input carries the peer’s trusted time and every effect is a change of the struct or a returned document. Rule switches (Rules) mirror the TLA+ model’s constants and exist for mutation tests.
  • node: message dispatch (POST /federation/v0.1/<operation>: ping, binding/propose, binding/install, lease/vote, lease/announce, write, event, reconcile, leave) and the driver that runs the protocol over a Transport: binding exchange, lease request and renewal by quorum, replicated writes with an outbox, partition detection, rejoin.
  • http: an axum server on the pattern of obsp-gateway (one fallback handler, every failure an RFC 9457 problem document with OBS-FED-0001 to OBS-FED-0005) and a minimal blocking HTTP/1.1 client implementing Transport.
  • drive: the timer driver of serve --drive propose|join for a deployed peer (binding proposal and the hand-over to grantors that are no party, join, lease upkeep, writes every --write-every seconds, probes that record PARTITION and REJOIN); --peer <uni>=<host:port> gives the routes and --keys test-fixture the simulation’s test identities. Used by the reference stack (infra/); tested in tests/drive.rs.
  • metrics (feature metrics): GET /metrics in the Prometheus text format (binding, writes, events by type, partitioned contacts, lease epoch and holding per namespace).
  • sim: 3 to 5 peers in one process (two parties, every peer a grantor, quorum a majority) over an in-process network with injectable partitions, message loss and per-peer clock skew, driven by a seeded generator.
  • trace: replay of TLC output (below).

Checking the model’s invariants on randomised runs

tests/simulation.rs runs 48 fixed seeds (3, 4 and 5 peers in turn, 300 random actions each, then heal and settle) and checks after every step, on the true-time history, the invariants of the proposal’s TLA+ model by name (SingleHolderPerEpoch, ExclusiveAuthority, NoWriteWithoutLease, NoLostWrite, NoErasure) and three more (NoUnlistedExport, EpochNeverDecreases, and Convergence once the network has healed), with clock skew injected within the binding’s allowance. The runs are asserted to have exercised the rules (leases granted and renewed, writes refused for no lease and for an expired one, partitions recorded and rejoined, conflicts kept as candidates, grantors refusing to vote while a lease is unexpired). As in the model, each rule is shown to be needed by a mutant (Rules) that must violate the invariant it protects: grantor wait off breaks ExclusiveAuthority, stop-on-expiry off breaks NoWriteWithoutLease, conflict flag off breaks NoLostWrite. A run is a function of its seed, so a failure is reproduced from the seed in its message: obsp-federation simulate --seeds 17..17 --peers 4.

Trace-check: TLC counterexamples against the state machine

obsp-federation trace-check <tlc-output.txt> (or --tla2tools <jar> --config <name>) parses TLC’s text output, infers the model’s action at each step from the difference of two states and runs it on three simulated peers. The mutant configurations switch a rule off, so their counterexamples are expected to be refused by the state machine at the step that depends on the rule; the witness of the unmodified model must apply in full and end with the conflicting write as a correction candidate. The traces under tests/data/integration-0.5/traces/ were produced by reference/rust/tools/tlc-traces.sh (TLC 2.19 of the TLA+ tools release v1.7.4; one worker); tests/trace.rs replays them. With TLA2TOOLS=<path to tla2tools.jar> the same test also runs TLC itself. The jar is never stored in the repository. Download it from the TLA+ project’s releases at the pinned version; the SHA-256 of the v1.7.4 jar is 936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88 (the value recorded in formal/federation/README.md of the proposal).

The mapping is the one a model forces (three domains, at most two holders, one scope, a tick of ten seconds, skew allowance zero); a trace outside it is reported as skipped, not passed.

Copied 0.5 material

tests/data/integration-0.5/ holds copies of every schema of the integrated 0.5 tree, the algorithm register, the federation examples of the proposal and its TLA+ model, written by reference/rust/tools/copy-0.5.mjs (it applies the series to a temporary copy; --check exits 1 when a copy is stale, and tests/documents.rs runs it). They keep their source licence (CC-BY-4.0) and are not part of the protocol.

Findings for the editors of OIP-0004 (observations from building this; none changes a requirement here)

  1. FED-9’s equal-epoch tie-break must apply to concurrent writes only. Read literally (“equal epochs: the greater digest is current”), a holder’s own later write at the same epoch loses to its earlier one whenever the earlier digest is greater, and is then flagged as a conflict. The TLA+ model hides this: its write identifier, which stands in for the digest, grows with time. Here the current version is chosen among the heads (writes no other write is based on) by epoch, then digest; current and candidates are then functions of the set of writes held, so two parties holding the same writes agree (found by the simulation: the parties did not converge before this).
  2. The model starts a lease at completion; FED-4 fixes the start in the request. In the model a grantor may vote any time before the proposed expiry and the holder acts from completion; in FED-4 each vote is cast no later than the start, which the vote signs. The shortest TLC traces vote after a tick, and replaying them needs per-request timing that follows the model (see trace.rs).
  3. The skew allowance covers a pairwise difference of twice its value. A holder stops an allowance before expiry and a grantor waits an allowance after it, so authority stays exclusive while two clocks differ by at most twice maxClockSkewSeconds (offsets within plus or minus the allowance); the boundary and a case beyond it are in tests/scenarios.rs. The proposal’s text can say which it means.
  4. A write is not signed by its writer. RecordWrite carries no signature; its authority is its lease. The state machine checks the write against the lease it names, but the identity of the sender rests on the transport (mutual TLS), which this reference does not provide.
  5. A grantor that voted for a request that never completed waits out its term, even for the same holder at a higher epoch (FED-5 as written and as modelled). The simulation shows many refusals for this reason; whether to allow a same-holder re-grant is an open design question, not decided here.

Usage policies (draft OIP-0014)

Off unless configured: Peer::governance (serve --policy-dir <dir> --policy-purpose <term> --policy-region <code>, with --default-policy, --policy-aggregation and --policy-consent optional), and the rule switch Rules::enforce_policy (on by default; it has an effect only with a governance). With a governance, a write is sent live (Node::write), exported (Peer::export_bundles; Peer::export_report also lists what was left out and why) and received (Peer::receive_write) only when the record’s policy, found by the obsp-policy enforcement point (extensions["obsp.policy"].policyUni of the content, or the default policy), permits action distribute to recipient class FEDERATION_PEER for the configured purpose, region and aggregation at the peer’s trusted time, and the binding’s honouredPolicies names that policy by UNI and RFC 8785 SHA-256 digest. A refusal changes nothing; its code is the first OBS-GOV reason code (Code::Governance, HTTP 403, POLICY_DENIED) with the rule named in the detail, or OBS-FED-0002 when the binding does not honour the policy. The state machine stays deterministic: the decision reads the peer’s trusted time, never a clock. Where a peer takes the purpose and region of a transfer from is not stated by the drafts; it is configuration here (see the open questions in ../obsp-policy/README.md).

Does not cover

  • No conformance claim. There is no conformance level, case or evidence here; the crate is a reference aid.
  • Transport security and caller authentication: the server listens on plain HTTP and takes the caller from a header. Put mutual TLS in front of it. FED-3 asks for https endpoints in the binding; the binding check enforces that, the server does not terminate TLS.
  • Key distribution and lifecycle: peers are given each other’s key records out of band; revocation, rotation and the time-quality of the clocks (OIP-0004 open question 1) are not handled. Ed25519 test keys derived from seeds are for tests only.
  • Retention: the binding’s retention is carried and not evaluated (usage policies and honouredPolicies are, when a Governance is configured: see “Usage policies” below); only exit terms DELETE and RETURN_AND_DELETE act on data at LEAVE, and RETAIN_UNDER_TERMS keeps it without checking the terms.
  • More than one binding per peer, more than two parties, the version-change flow of a binding, and the functions of section 5 beyond federate (a lease’s functions are checked against the binding; what a holder does with them is not modelled). Data is opaque JSON under a record UNI; the observation record shape is not produced.
  • Liveness. The model checks safety for small bounds and so does the simulation; that a lease is eventually granted after a heal is not checked, and a TLC run or a seed set is evidence for what it ran, not a proof.
  • The wire is this crate’s own (POST /federation/v0.1/<operation>); the proposal leaves the peer operations to a later OpenAPI proposal (open question 5), so nothing here is an interface a deployment may rely on.
  • The correction notices produced are CURRENT to DISPUTED notices signed by the observer; their handling downstream (section 5.9) is not modelled.

Running

cd reference/rust
cargo test -p obsp-federation                 # about a minute; or `make rust-federation` from the root
cargo run -p obsp-federation -- simulate --seeds 1..48
cargo run -p obsp-federation -- trace-check obsp-federation/tests/data/integration-0.5/traces/MutantGrantorNoWait.txt
node tools/copy-0.5.mjs --check               # the copied material is current

Set CARGO_PROFILE_DEV_DEBUG=0 on a small disk. The workspace profile optimises the signature and JSON Schema crates in debug builds so that the simulation runs in seconds.

Licence: Apache-2.0, except tests/data/ (copied draft material and TLC output, CC-BY-4.0).