A transaction is ordinary datahike transaction data, signed.
{:chain :urd-net
:sender "<64 hex chars — the hash of your genesis record>"
:nonce 7
:tx-data [{:db/id "note" :<your-namespace>/text "hello"}]
:public-key <32 bytes>
:signature "<base64url Ed25519>"}
The sender signs canonical CBOR of {:chain :sender :nonce :tx-data}.
When the envelope includes :fuel, the signed map includes its exact value,
including an explicit zero. The verifier checks the public key against the
account's registered genesis. See the wire format.
:tx-data is an ordered vector. Each element is an entity map or one of
the following operation vectors. Datahike resolves entity IDs, tempids and
lookup refs against the candidate database.
| Form | Effect |
|---|---|
{:db/id e :app/name "Ada"} | Expand an entity map into assertions. Nested ref maps, reverse refs and cardinality-many collections follow the installed Datahike schema. |
[:db/add e a v] | Assert one value. A cardinality-one replacement also retracts the previous value. |
[:db/retract e a v] | Retract the matching value, if present. |
[:db/retract e a] | Retract all values of the attribute. |
[:db.fn/retractAttribute e a] | Retract all values, recursively retracting components where applicable. |
[:db/retractEntity e] or [:db.fn/retractEntity e] | Retract the entity, incoming references and component descendants. |
Attribute positions take keywords. :db/id identifies an entity in a map.
The two permitted Datahike metadata attributes are :db.valid/from and
:db.valid/to, which support Kontor's valid-time posting metadata. The ordinary signed-write profile forbids schema writes, CAS, purge,
entity predicates and transaction-function calls. It also rejects other
db and db.* attributes and explicit transaction IDs on operation vectors. Nested maps follow the same attribute rule. Datahike validates values
against the installed schema. Ownership and invariants still check the resolved
changes, including implicit retractions.
Clients can encode the complete signed envelope with skuld.wire/encode-envelope and put the resulting byte array in the block's :txs vector.
The envelope uses Boring's archival CBOR profile so Datalog lists and typed
values survive transport. The signing bytes for ordinary writes still use
Urd's canonical CBOR profile. Validators decode those verified bytes for
ordinary settlement. Thus a list and a vector that sign as the same CBOR array
have the same ledger meaning. In-process callers can supply decoded maps.
A binary frame contains exactly one CBOR map. Validators enforce 1 MiB
before envelope decoding and also limit the ordinary signing payload to 1 MiB. On a stream that
contains one request and ends at the frame boundary, use
(skuld.wire/read-frame stream skuld.wire/max-envelope-bytes). It reads at
most one extra byte to detect overflow. Transports with a length prefix
should check the declared size before allocating the frame.
chain match the configured chain
input validate fuel and the submitted transaction tree
known sender find the genesis registered for this namespace
key authorised verify the sender and the key against the genesis
signature verify the signed payload
nonce require the next account nonce
funds reserve the base fee
prepare apply the stamped forms under the expansion limit
scope check ownership of the resulting datoms
price check balance against the price and signed guard allowance
guards evaluate registered change guards on the candidate report
settlement add fee and nonce entries and run trusted invariants
storage check storage balances before committing
The genesis is read from the account, not the envelope. It is ~320 bytes against a 32-byte key and changes only on rotation, so holding it on chain is what lets an operational key rotate without the namespace moving.
Pricing, ownership checks and change guards share the speculative transaction
report. For example, :db/retractEntity names only the entity in the
submitted form. Its report identifies each removed attribute, including facts
removed from a component. Settlement then prepares the effects with their
accounting entries for trusted invariants and storage checks.
| reason | what happened | fee |
|---|---|---|
:wrong-chain | signed for another chain | 0 |
:invalid-fuel | signed guard allowance outside its permitted range | 0 |
:wire-limit | encoded envelope exceeds 1 MiB | 0 |
:invalid-envelope | invalid CBOR envelope, non-map, or trailing item | 0 |
:unsupported-transaction | authenticated write contains a form outside the ordinary profile | base |
:input-limit | decoded transaction exceeds its node, depth or scalar budget | 0 |
:unknown-sender | no genesis registered for that namespace | 0 |
:sender-key-mismatch | genesis does not hash to :sender, or does not authorise this key | 0 |
:bad-signature | Ed25519 verification failed | 0 |
:bad-nonce | not exactly one more than stored; carries :expected/:got | 0 |
:cannot-pay-base-fee | balance below the base fee | 0 |
:block-preparation-limit | block preparation capacity exhausted | 0, nonce available |
:block-settlement-limit | candidate fits a fresh block but exceeds the remaining datom allowance | 0, nonce available |
:settlement-limit | candidate exceeds the full per-block settlement size | authenticated refusal fee |
:preparation-limit | the pricing pass exhausted its logical expansion allowance | base |
:malformed | the d/with threw; carries an :error keyword | base |
:out-of-scope | wrote something not yours; carries [{:attr :reason}] | base |
:insufficient-funds | priced cost exceeds balance; carries :needed/:balance | base |
:invariant-violated | a guard refused; carries the attributes | base plus consumed guard fuel |
:insufficient-storage | the block's storage post-condition rolled it back | base plus consumed guard fuel |
The two tiers are deliberate. A refusal that names no authenticated payer costs nothing — charging a bad signature would take a fee from whoever the forger claimed to be. Block-capacity deferrals also leave the balance and nonce available for resubmission.
Measured on a fresh account with the default schedule:
{:ok? true :fee 1371}
{:ok? false :reason :bad-nonce :expected 2 :got 7 :fee 0}
{:ok? false :reason :out-of-scope :fee 1000
:violations [{:attr :<bob>/note :reason :other-users-namespace}]}
{:ok? false :reason :insufficient-funds :needed 2001366 :fee 1000}
{:ok? false :reason :invariant-violated :violations [:<alice>/note] :fee 1164}
An authenticated, charged refusal applies only the fee and nonce bump. A refusal that wrote nothing would leave the nonce unspent, and a transaction that can be retried for free after being refused is a free retry loop.
:invariant-violated is charged the price of the refusal rather than the
base fee, because reporting the base while applying a priced refusal left any
consumer reconciling on :fee off by a per-transaction constant.
The block reuses the ordinary write’s complete settlement report and checks that every affected account can still cover its residency. If not, the whole transaction is rolled back and the fee applied.
It is a post-condition rather than a per-datom check because a transaction that grows and shrinks internally is legitimate, and rather than an escrow because a refund is a payment — and a transaction that pays its own sender is a minting attack waiting to be found.
The ledger persists cumulative usage per account and checks the liquid balance
after fees. A charged refusal that would consume previously reserved collateral
returns :insufficient-spendable with zero fee and the nonce available.
An ownership change exceeding the shared storage scan budget returns
:storage-transfer-limit. Collateral and attribution
:db/fn — datahike resolves it, but it is definable in no schema, cannot be
installed under :schema-flexibility :write, and could not survive CBOR
anyway, since a function object has no encoding. Recorded because reading the
call site alone suggests the opposite.
Identity for how a sender is authenticated · Ownership for what "yours to write" means · Invariants for the guards · Economics for the fee schedule
Before signature verification or ownership stamping, the ordinary-write admission
path accepts at most 65,536 input nodes and 64 nesting levels. The outer
transaction collection is one node at depth zero. Each collection, scalar, map
key and map value is visited once per occurrence. Exceeding either limit gives
:input-limit, with zero fee and the nonce still available. The decoded transaction also has a combined 1 MiB scalar budget. Strings,
keywords and symbols count by their UTF-8 spelling, and byte arrays by their
length. Arbitrary-precision integers and decimal coefficients count by their
signed integer width, and ratios count both integers. Fixed-width values are
covered by the node limit.
The ledger gives Datahike 65,536 logical expansion units to prepare one ordinary signed write for pricing. Each form dispatched by the transactor costs one, including generated operations and redundant assertions. A retraction spends one more for each index lookup and each matching datom. Removing a component tree can therefore reach the limit with a single submitted form. Ownership stamps and transaction metadata are included.
If preparation exceeds the limit, the receipt records :preparation-limit.
Only the base fee and nonce advance. Guard evaluation starts after successful
preparation and draws from the separately signed :fuel allowance. The
expansion limit leaves successful transaction fees unchanged. It covers the
pricing pass. A separate block allowance also covers logical expansion in
speculative settlement. Decoding, ownership lookups, trusted invariant queries,
physical index work, and the final Datahike commit have costs outside this counter.
Every non-empty settlement commits its nonce, fee, effects and block progress
together. Progress includes the input digest, completed receipts, staking
intents and remaining budgets. A validator receiving the interrupted block
continues from that point. A conflicting block is refused. The final commit
applies staking movements and the height together after conservation checks.
Redelivering the most recently completed block returns its recorded outcome.
Use skuld.block/finalized-db for application reads across the interval;
the SDK account and guard accessors use it automatically. Confirmed receipts omit the internal settlement forms.
| Resource | Draft ceiling | Enforcement |
|---|---|---|
| Submitted envelopes | 8 | Check before touching the ledger. Every envelope occupies a slot. |
| Envelope bytes combined | 4 MiB | Sum actual frame lengths, including malformed frames. In-process maps use their archival CBOR encoding. |
| Logical preparation units | 131,072 | Share actual units across ordinary pricing and successful admission’s settlement preview, including attempted passes that throw or lead to a refusal. |
| Datoms in successful settlements | 1,024 | Count the complete preview, including fee, nonce and storage-counter datoms. Debit the allowance upon successful commit. |
A block exceeding either structural limit is invalid as a whole. Validators
can call skuld.block/transactions-fit? on the proposed envelope sequence.
The Tendermint adapter checks a proposal’s :txs before content hashing. A
custom proposal wrapper must check its enclosed sequence before voting.
apply-block repeats structural validation before changing the database.
For decoded map input the encoder first bounds the tree at 262,144 nodes,
depth 80 and 4 MiB of counted scalar material.
Execution follows envelope order. An envelope that exceeds the block's
remaining preparation allowance stops at that unit. A settlement that fits a
fresh block but exceeds the remaining datom allowance is deferred. Both
outcomes charge zero and preserve the nonce. Work already performed stays in
the block counter. Subsequent envelopes can use remaining capacity. A
settlement larger than 1,024 datoms on its own is refused permanently under
these limits and follows the same fee rule as a storage refusal. For an
ordinary write this is the price of an empty settlement plus consumed guard fuel. In all cases
:block-usage reports envelope count, bytes, preparation units and committed
settlement datoms.
Each charged refusal still needs a small protocol transaction to collect the fee and advance the nonce. The envelope-count limit bounds their number. Staking transitions, trusted application callbacks, conservation checks and Datahike's physical index writes have separate costs. The limits apply to a block's transaction payload. They provide no wall-clock deadline.
Three pairs of independently seeded file stores applied the same signed
frames and reopened to check persisted state. Each pair agreed on every fee,
resource counter, final balance, nonce, posting count and remaining tree facts.
The following times are local medians in milliseconds, measured around
apply-block through commit and conservation checking. Signing and initial
seeding happened before timing.
| Block | Envelope bytes | Preparation units | Settlement datoms | Apply ms | Replay ms |
|---|---|---|---|---|---|
| Eight two-leg Kontor invoices | 10,088 | 584 | 232 | 403 | 307 |
| Eight component roots, 32 children each | 2,984 | 5,336 | 568 | 279 | 270 |
| One invoice padded to 256 KiB | 262,144 | 73 | 29 | 46 | 54 |
| One invoice padded to 1 MiB | 1,048,576 | 73 | 29 | 110 | 61 |
| Four invoices filling a 4 MiB block | 4,194,304 | 292 | 116 | 317 | 245 |
The padded invoices use deterministic pseudorandom ASCII narration. Retaining the 1 MiB envelope limit accommodates the largest measured invoice. The 4 MiB block budget allows four such frames. The datom ceiling leaves headroom above the 568-datom cascade sample, and the preparation allowance is twice the existing per-write pricing limit. These are draft policy choices. The samples cover the listed workloads on one machine. To repeat the measurements from the Skuld checkout:
JAVA_TOOL_OPTIONS='-XX:ActiveProcessorCount=3 -Xmx1500m' clojure -Sdeps '{:paths ["src" "dev"]}' -M -m skuld.block-cost
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |