txflow spec reference
A txflow spec describes a transaction-flow experiment: which transactions to build, which outputs each one spends, and where and when each one is sent. It never contains transaction ids, keys or amounts that depend on the chain; those are filled in when the experiment is built.
The field tables, pattern list, relays and limits on this page are generated from the same schema and configuration the editor checks against, so they cannot drift from what the site accepts.
JSON Schema, draft 2020-12, for tools and LLMs
Overview
A spec goes through four steps. The editor does the first two as you write; Run on Musashi does the last two.
- Check. The spec is validated against the JSON Schema (its shape) and then expanded (its meaning).
- Expand. Patterns become named funding outputs and transactions: the graph IR. Conflicts, orphans and a content hash are derived from which outputs each transaction spends; they are never declared.
- Materialise. Each transaction is built and signed on the server, funded from a lane of test ADA that the run leases.
- Submit. The schedule sends each transaction to its relays at its offset, and the run is watched until it settles; what is left is swept back to the lane.
A spec is built from four kinds of pieces:
- Atoms
- Funding outputs (
sources), transactions (txs) and their outputs. Every graph is made of these. - Patterns
- Named shapes that emit atoms: a chain, a fan-out, a double spend. Most specs are only patterns.
- Controls
params,countand pattern arguments that scale a shape without rewriting it.- Schedule
- Releases that send selected transactions to relays, at an offset and with spacing.
Your first experiment
Now that you know what a spec is made of, write one. You'll describe three transactions in a row, check the spec, and then turn it into a race between two continents.
Writing the spec
Make a file called chain.yaml and enter the spec in Listing 1.
version: 0
experiment: first-chain
seed: 1
wallets:
alice: {}
patterns:
- id: chain
use: chain
with: { length: 3 }
schedule:
releases:
- select: { pattern: chain }
target: frankfurt
Anatomy of a spec
Let's go through Listing 1 from the top.
The first line, version: 0, says which version of the format the spec is written in. Every spec starts with it, so an old spec can still be checked after the format moves on. experiment names the run, and seed makes everything derived from the spec, such as names and keys, come out the same each time it is built.
wallets lists who owns the coins. One wallet, alice, is enough for most experiments: every output pays back to her.
patterns is where the shape lives. This entry uses the chain pattern and names the instance chain. With length: 3 it emits a funding output chain/s and the transactions chain/t1, chain/t2 and chain/t3, each spending the one before.
schedule says where and when each transaction is sent. Its one release selects every transaction of the pattern and sends them to the Frankfurt relay. With no at, they go at once, in dependency order, so each parent reaches the relay before its child.
Checking it
Click Open in editor under Listing 1 to see its graph, or check it from a terminal:
$ txflow check --network networks/musashi.json chain.yaml
3 transactions funded by 1 source (10 ADA in total).
Pattern `chain` uses `chain`.
No conflicts: every output is spent at most once.
3 sends to 1 target:
frankfurt: 3 txs via n2c, at 0 ms
The check expands the patterns into the graph and reports what it found. A spec that passes is runnable: every name resolves, no path spends an output twice, and every send has a relay that takes it.
Racing two relays
Now add a double spend: two transactions that spend the same output, sent at the same moment to two continents. At most one of them can land. Listing 2 adds the conflict_set pattern and two releases; the new lines are highlighted.
version: 0
experiment: first-race
seed: 1
wallets:
alice: {}
patterns:
- id: chain
use: chain
with: { length: 3 }
- id: race
use: conflict_set
with: { k: 2 }
schedule:
releases:
- select: { pattern: chain }
target: frankfurt
- select: { names: [race/x1] }
target: frankfurt
- select: { names: [race/x2] }
target: tokyo
$ txflow check --network networks/musashi.json race.yaml
5 transactions funded by 2 sources (20 ADA in total).
Pattern `chain` uses `chain`.
Pattern `race` uses `conflict_set`.
1 conflict set (at most one tx of each can land):
race/x1, race/x2 all spend race/s
5 sends to 2 targets:
frankfurt: 4 txs via n2c, at 0 ms
tokyo: 1 tx via n2c, at 0 ms
The check now reports a conflict set: race/x1 and race/x2 both spend race/s. The conflict is never declared; it follows from what each transaction spends. Which side wins, and how fast the loser disappears from each mempool, is what this experiment measures.
Summary
- A spec is a version, a name, a seed, wallets, patterns and a schedule.
- Patterns emit named transactions; you refer to them as
pattern/name. - Conflicts come from what transactions spend, never from a flag.
- Releases send transactions to relays, parents first.
The rest of this page is the reference: every field, every pattern and every rule the check applies.
Example
Two chains whose transactions conflict pairwise, raced from two continents, and a three-way double spend with one copy sent to each relay at the same moment.
Loading…
Document
A spec is a YAML (or JSON) object with these fields. Unknown fields are errors.
Names and grammar
Everything is named, and transactions refer to each other only by name. Everything a pattern emits lives under its id: chains/a1. A pattern with count emits copies under <id>_0/, <id>_1/, and so on. .N after a transaction's name picks its output N, counting from 0.
name = lower , { lower | digit | "_" } ;
path = name , { "/" , name } ; (* chains/a1, p_2/s *)
ref = path , [ "." , index ] ; (* a source, or output index of a tx *)
index = "0" | nonzero , { digit } ; (* no leading zeros *)
label = ? any string ? ; (* free tag, e.g. side-a *)
arg = integer | '"' , integer , '"' | '"{{' , expr , '}}"' ;
expr = term , { ( "+" | "-" ) , term } ;
term = factor , { ( "*" | "/" ) , factor } ; (* "/" divides whole numbers *)
factor = integer | name | "(" , expr , ")" | "-" , factor ;
duration = "0" | digit , { digit } , ( "ms" | "s" ) ; (* at most one hour *)
amount = integer | "min" | "change" ; (* lovelace *)
lower = "a" | … | "z" ;
digit = "0" | … | "9" ;
nonzero = "1" | … | "9" ;
A name in expr is one of the spec's params. The result must be a whole number of at least 0, and is then held to the argument's range.
Patterns
Each entry of patterns is { id, use, count?, with? }. use names one of the shapes below; with sets its arguments, each of which may be a number or an expression over params.
Sources and transactions
For shapes no pattern covers, write funding outputs and transactions directly. They can spend pattern outputs by name, for example chains/a1.0.
Source
Transaction
Output
Schedule
The schedule says where and when each transaction is sent. Each release selects transactions and sends them to one relay. A transaction selected by several releases is sent by each, which is how one transaction reaches several relays; a transaction no release selects is not sent, and the check warns about it.
Release
Selecting transactions
Sends are ordered by time. Within one release, the selected transactions are sent in dependency order, spacing apart, starting at at.
A node accepts a transaction only when it already has every transaction it spends or reads from; it keeps no orphans. The check therefore warns when a transaction reaches a relay before one of its parents: if the parent has not been sent anywhere yet, the relay will reject it; if the parent went only to another relay, it lands only if propagation brings the parent there first. Send parents to the same relay earlier, or in the same release.
Options
Relays of this site
Metadata and colour
metadata puts transaction metadata of your own on the transactions, keyed by label (an integer). Values are written as in cardano-cli --json-metadata-no-schema: integers, text, lists and maps with text keys; text starting with 0x is a byte string. color is an RGB colour such as ff0000, written as metadata label 1022, three bytes, the way tx-firehose --color writes it, so mempool-monitor shows those transactions in that colour.
Both can be set on the whole spec, on one pattern instance (every transaction it emits) or on one hand-written transaction. The most specific wins: a transaction's own metadata replaces the pattern's or spec's label by label, and its own color replaces theirs. They go on the experiment's transactions only, never on the funding transactions, beside txflow's own message under label 674.
color: 00ff88 # every transaction
metadata:
1337: { study: mempool-fragmentation, round: 1 }
patterns:
- id: ds
use: conflict_set
with: { k: 3 }
color: ff0000 # the double spends in red
The ledger's own rules are checked before anything is built: text and byte strings hold at most 64 bytes (split longer text into a list), integers fit in 64 bits, and there are no fractions, booleans or null. Labels 674 and 1022 belong to txflow; use color for 1022. Lists and maps nest at most 8 deep, and one transaction carries at most 8 KB of metadata; this site allows less (below).
Script load
cost says how much Plutus execution a transaction carries, not which script runs: the work a node does to validate it. cpu is CPU steps and mem is memory units, each a share of the network's per-transaction limit (maxTxExecutionUnits) such as 25% or 12.5%, or a whole number of units. Give one or both; one left out is kept as low as possible. A share keeps the spec independent of the network: cpu: 25% is a quarter of whatever the network allows.
When the experiment is built, each such transaction runs txflow's burner, a small fixed script that hashes and counts as often as its redeemer says, chosen to use as much of the target as possible without going over (within about 0.01% of a CPU target). Every run is evaluated with the network's cost model before anything is signed, and the measured cost goes in the manifest. Funding adds one shared collateral output and, per script transaction, a fuel output at the burner's address that also pays that transaction's execution fee.
Like color, a cost can be set on the whole spec, on one pattern instance or on one hand-written transaction, and the most specific replaces the others whole. On the spec or a pattern, select: { label: … } limits it to the transactions with that label, so one side of a conflict can carry the load, and values can use params, "{{ dose }}%" for whole percent.
params: { dose: 25 }
cost:
cpu: "{{ dose }}%" # every transaction, a quarter of the CPU budget
patterns:
- id: pairs
use: conflicting_chains
with: { length: 10, conflict: per_step }
- id: light
use: chain
cost: { mem: 2% } # these, 2% of the memory budget instead
Some costs no script can reach: any script uses at least about 160 CPU steps per memory unit on Musashi, and the burner reaches about 240 to 25,000. A cost below the burner's smallest run, above the limit, or at a ratio it cannot reach fails, naming the transaction and what is reachable. A script transaction that never lands, such as the losing side of a conflict, leaves its fuel at the burner's address.
Validity windows
validity says in which slots a transaction is valid. from is the first slot it is valid in (the ledger's invalid_before) and until the first slot it no longer is (its invalid_hereafter, or time to live). Either can be left out, and until must be after from. Both count slots from an anchor, never absolute slots, so a spec means the same on every run. On Musashi a slot is one second.
anchor: start, the default, counts from the slot the schedule starts in, so a window and a release'satshare one clock.anchor: tipcounts from the slot of the tip block when the schedule starts.
A node checks a transaction against the slot after its tip, not against the clock: when it takes the transaction into its mempool, and again whenever a new block makes it revalidate the mempool. Its tip trails the clock by the time since the last block, about 20 seconds on average on Musashi. So a from counted from the start can be refused as not yet valid for a while, and a transaction past its until can still be taken in, and held, by a node whose tip is older; only a block forged at or after until can no longer carry it. Counted from the tip, small numbers mean what they say to a node, as long as its tip is still the one the run signed for: until: 2, anchor: tip is admitted and relayed by a node at that tip, only a block in the slot right after it could carry it, and once any new block lands a node refuses it. until: 1 or less with anchor: tip is refused at once.
Like cost, a window can be set on the whole spec, on one pattern instance or on one hand-written transaction, and the most specific replaces the others whole. On the spec or a pattern it takes two more fields, and values can use params. step moves the window that many slots later per generation: a transaction that spends only sources is generation 0 (the first of a chain), one that spends it is generation 1, and so on. select limits the window to transactions with a label, of one generation (depth), or both.
patterns:
- id: doomed # only the first tx expires; the rest fall with it
use: chain
with: { length: 5 }
validity: { until: 3, anchor: tip, select: { depth: 0 } }
- id: ladder # each tx must land within 25 slots more than its parent
use: chain
with: { length: 5 }
validity: { until: 25, step: 25, anchor: tip }
- id: turns # each tx valid for 4 slots of its own, one after the other
use: chain
with: { length: 4 }
validity: { from: 0, until: 4, step: 4 }
A run signs its funding first and its experiment transactions only once the funding is on chain at every relay it sends to, for the slot its schedule starts in and the tip then; the run's details show the slots each transaction was signed for. The check warns about a transaction that can never land: its window closes before the window of a transaction it follows opens (what it spends or reads, and theirs in turn), or by slot 1 after the tip. It also warns about a send outside its transaction's window by the network's clock, and about a script transaction whose window closes past the network's horizon (6480 slots on Musashi), the furthest a node can tell the time of.
Native assets
Transactions can mint and burn native assets, and outputs can hold them. A policy is declared under policies as { after_slot: N }: a native script that lets any transaction valid from slot N on mint or burn under it. It needs no key, which suits a test network, and each slot is a different script, so after_slot: 1, 2, 3, … give as many distinct policy ids as you like. A small slot is long past, so it only tells policies apart.
An asset is written <policy>.<asset>, with an asset name of 1 to 32 letters, digits, _ or - that is also its name on chain. A transaction's mint mints with a positive number and burns with a negative one; an output's tokens says what it holds. The change output takes every asset the other outputs do not, as it takes the leftover ADA, so a merge needs no tokens at all. A transaction that pays out or burns more than its inputs and mint hold is an error naming it.
policies:
gold: { after_slot: 1 }
silver: { after_slot: 2 }
sources:
s: { owner: alice, lovelace: 10000000 }
txs:
mint:
inputs: [s]
mint: { gold.a: 5, silver.b: 2 }
outputs: [{ to: alice, lovelace: change }]
split:
inputs: [mint.0]
outputs:
- { to: alice, lovelace: min, tokens: { gold.a: 3 } }
- { to: alice, lovelace: change } # gold.a: 2 and silver.b: 2
The asset_shuffle pattern does this at scale: utxos UTxOs of assets unique assets each, spread over policies policies, merged into one UTxO and split back out with the assets shuffled, rounds times, with burn: all to burn everything at the end. Its policies take the next free slots from 1 up, so every copy has its own policy ids.
An output with assets needs more ADA: min and the change are sized for what they hold. No output may hold a value larger than the network's maxValueSize, 5000 bytes on Musashi: 844 assets of one policy, or 137 policies of one asset. The merged UTxO of asset_shuffle holds utxos × assets. When a run ends, this site burns the assets it minted, so only ADA goes back to the funding slot.
Reference scripts
An output can carry a reference script (CIP-33), given by its size: reference_script: { bytes: N }. txflow builds a Plutus V3 script of exactly N bytes, as the ledger counts a script's size. Nothing ever runs the script. It is only there to be paid for. Every transaction that spends the output, or reads it through reference_inputs, pays the reference-script fee on top of the size fee: 15 lovelace a byte for the first 25 KiB of scripts it spends or reads, 1.2 times that for the next 25 KiB, and so on. That lets a spec fill the mempool with transactions whose validation resolves large scripts, without running any.
txs:
publish:
inputs: [s]
outputs:
- { to: alice, lovelace: min, reference_script: { bytes: 15000 } }
- { to: alice, lovelace: change }
reader:
inputs: [t]
reference_inputs: [publish.0] # pays for 15 000 bytes, spends nothing
outputs: [{ to: alice, lovelace: change }]
N is at least 8 and at most 204 800. 25, 258, 65 539 and 65 540 are refused because no Plutus script has those sizes. A script has to fit in the transaction that creates it, so on Musashi (16 KiB transactions) one is at most about 15 900 bytes. To make readers load more, publish several scripts and read them all. One transaction spends or reads at most 204 800 bytes of scripts. An output with a script needs more ADA, so min is sized for it: about 65 ADA for 15 000 bytes. Each output gets its own script, different in every run. When a run ends, this site sweeps outputs that still carry scripts back to the funding slot and pays their fee.
Validation
A spec is runnable when it passes all of these. The check reports the first problem it finds in each step, naming the pattern, transaction or field at fault.
- Shape. The document matches the schema: known fields only, names spelt as in the grammar, arguments within their ranges.
- Version.
versionis the version this site reads. - Unique names. Pattern ids are distinct, and no two sources or transactions end up with the same name.
- Wallets. Every owner is a declared wallet. With several wallets each pattern names its
wallet. - References resolve. Each input is a source, or output N of a transaction that has at least N+1 outputs. No transaction spends or reads its own output, or lists an input twice. There are no cycles.
- One change output. Every transaction has exactly one output whose amount is
change. - No double spend along a path. A transaction cannot depend on two transactions that spend the same output, and cannot read an output one of its ancestors spends: such a transaction could never land. Conflicts between independent branches are allowed, and are the point of many experiments.
- Schedule. Every release selects at least one transaction, targets a relay of this site's network that accepts its
via, and stays within one hour. - Metadata. Labels other than 674 and 1022, strings of at most 64 bytes, integers only, nesting at most 8 deep, and
coloras six hex digits. - Script load. A
costnamescpu,memor both, as a share from 0.01% to 100% or as units above zero, and aselectlabel reaches at least one transaction. - Validity windows. A
validitynamesfrom,untilor both,untilafterfrom, and aselectreaches at least one transaction. - Native assets. Every asset names a declared policy, no two policies share a slot, no
mintortokensquantity is 0, thechangeoutput lists notokens, and no transaction pays out or burns more of an asset than its inputs and mint hold. - Reference scripts. A
reference_scripthas a size a Plutus script can have: from 8 to 204 800 bytes, except 25, 258, 65 539 and 65 540. The check warns about a transaction that creates more script bytes than a transaction holds, or spends or reads more than 204 800. - Limits. The expanded graph fits this site's limits (below).
Derived, never declared: a conflict set is two or more transactions spending the same output (at most one can land); a transaction is orphanable when a conflict among its ancestors can go the other way; reference contention is an output spent by one transaction and read by another.
Limits of this site
Limits are this site's policy, not part of the format: a spec beyond them is valid txflow, but this site will not run it.
Versioning
Every spec starts with version. Adding a pattern, an optional argument or a wider range keeps the version: every valid spec stays valid and means the same. Removing or renaming anything, narrowing a range, changing a default or changing what a spec expands to is a new version, and the schema of every earlier version stays published so older specs can still be checked. Additions are released as revisions of the same version (Spec v0.1 added metadata and color, v0.2 added cost, v0.3 added validity, v0.4 native assets, v0.5 release waves and the release-tip anchor, v0.6 pad_bytes, v0.7 schedule offsets in minutes and hours, and v0.8 adds reference_script); specs keep version: 0.
Machine-readable: the JSON Schema (draft 2020-12) for this version, at a URL that stays the same while the version does.