Liking cljdoc? Tell your friends :D

skuld.ledger.cluster

A datahike database per validator, kept in step by consensus over real sockets.

Everything else in this repository is a test. This is the thing the tests are about: N processes' worth of validators, each with its OWN file-backed datahike database, talking Tendermint over kabel websockets with Ed25519 identities, and nothing anywhere coordinating the databases. If they agree at the end it is because consensus made them agree.

What it exercises that the test suite does not

  • Tendermint over kabel. The kabel integration tests run round-robin; the conformance suite runs Tendermint over the in-process router. This is the first configuration where a BFT algorithm's own topic vocabulary has to survive the real pubsub registration path.
  • Real file stores, not :backend :memory, so datahike's commit graph is genuinely on disk and a restart would find it.
  • Wall-clock timers under real network latency, which is where the simulator's logical ticks stop being a model of anything.

Cost is reported, not enforced

skuld.ledger.cost prices every committed transaction against the database it lands in, and the run reports the totals. It does not REFUSE anything here, and that is deliberate: refusing needs a rejected vertex to be recorded as consumed, or it is retried forever, and the ledger's marks are keyed to transactions that actually happened. Wiring that properly is a change to the ledger's bookkeeping rather than a flag on this demo. Pricing is honest without it, and it is the half that answers "what would this have cost".

Running it

clj -M -m skuld.ledger.cluster            ; 4 validators, 20 seconds
clj -M -m skuld.ledger.cluster 5 30 48000 ; n, seconds, base port
A datahike database per validator, kept in step by consensus over real
sockets.

Everything else in this repository is a test. This is the thing the tests are
about: N processes' worth of validators, each with its OWN file-backed
datahike database, talking Tendermint over kabel websockets with Ed25519
identities, and nothing anywhere coordinating the databases. If they agree at
the end it is because consensus made them agree.

## What it exercises that the test suite does not

- **Tendermint over kabel.** The kabel integration tests run round-robin; the
  conformance suite runs Tendermint over the in-process router. This is the
  first configuration where a BFT algorithm's own topic vocabulary has to
  survive the real pubsub registration path.
- **Real file stores**, not `:backend :memory`, so datahike's commit graph is
  genuinely on disk and a restart would find it.
- **Wall-clock timers under real network latency**, which is where the
  simulator's logical ticks stop being a model of anything.

## Cost is reported, not enforced

`skuld.ledger.cost` prices every committed transaction against the database it
lands in, and the run reports the totals. It does not REFUSE anything here,
and that is deliberate: refusing needs a rejected vertex to be recorded as
consumed, or it is retried forever, and the ledger's `marks` are keyed to
transactions that actually happened. Wiring that properly is a change to the
ledger's bookkeeping rather than a flag on this demo. Pricing is honest
without it, and it is the half that answers "what would this have cost".

## Running it

    clj -M -m skuld.ledger.cluster            ; 4 validators, 20 seconds
    clj -M -m skuld.ledger.cluster 5 30 48000 ; n, seconds, base port
raw docstring

-mainclj

(-main & args)

crash!clj

(crash! {:keys [validators ledgers]} id)

Stop one validator and close its local consensus store and database.

Stop one validator and close its local consensus store and database.
raw docstring

fault-runclj

(fault-run {:keys [n dir base-port before during after victim-idx]
            :or {n 4 before 8000 during 6000 after 14000 victim-idx 1}})

Start, run, crash one node, keep going, restart it, and see what its database looks like when it comes back.

Returns a map describing what happened, for a caller to assert on.

Start, run, crash one node, keep going, restart it, and see what its
database looks like when it comes back.

Returns a map describing what happened, for a caller to assert on.
raw docstring

reportclj

(report {:keys [ledgers costs]})

Print what happened, and return true when every database agrees.

Print what happened, and return true when every database agrees.
raw docstring

restart!clj

(restart! {:keys [validators ledgers cfgs config-for ids costs]} id)

Reopen the same database and consensus WAL with this validator’s original identity. The Datahike cursor tells Tendermint which decisions to deliver.

Reopen the same database and consensus WAL with this validator’s original
identity. The Datahike cursor tells Tendermint which decisions to deliver.
raw docstring

snapshotclj

(snapshot ledgers)

What each node's database holds, in the order it applied it.

Ordered by transaction entity id, not by content: datahike allocates those monotonically, so sorting by them recovers the sequence each node actually applied. Comparing SETS would pass for four databases that agree on content and disagree on order, which is exactly the failure the runtime's out-of-order on-finalize bug produced.

What each node's database holds, in the order it applied it.

Ordered by transaction entity id, not by content: datahike allocates those
monotonically, so sorting by them recovers the sequence each node actually
applied. Comparing SETS would pass for four databases that agree on content
and disagree on order, which is exactly the failure the runtime's
out-of-order `on-finalize` bug produced.
raw docstring

start!clj

(start! {:keys [n dir base-port gossip-interval]
         :or {n 4 dir "/tmp/urd-cluster" base-port 47600}})

Bring up n validators over kabel, each on its own datahike database.

Returns {:validators :ledgers :cfgs :costs :ids}.

Bring up `n` validators over kabel, each on its own datahike database.

Returns `{:validators :ledgers :cfgs :costs :ids}`.
raw docstring

stop!clj

(stop! {:keys [validators ledgers cfgs]})

valid-proposal?clj

(valid-proposal? {:keys [tx-data] :as proposal})

The socket demo accepts one numbered fact per proposal, under a content ID.

The socket demo accepts one numbered fact per proposal, under a content ID.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close