Seedelf-Wallet

seedelf-data

Seedelf Wallet reads Cardano mainnet through this API, at https://mainnet.seedelf.logicalmechanism.io. Seedelf Wallet is a Cardano wallet for Chrome with Seedelf built in; Seedelf is a stealth wallet that hides who receives and who spends (what Seedelf is). The API sits in front of its own Cardano node, db-sync (the chain in a Postgres database) and Kupo (an index of only the outputs it’s set to match).

Mainnet only, for the chain. On preprod the wallet reads Koios (koios.rest, a public Cardano API). On mainnet it reads Koios alone when Settings → Read Cardano through Koios only is on. Seedelf Messaging’s relay keeps a preprod pool beside mainnet’s, since its envelopes need no chain; its preprod list of certificates is checked against Koios preprod.

The wallet falls back to Koios part by part. When a part of this API can’t answer, the wallet reads that part from Koios instead. The parts are the three the wallet’s Settings name: the private balance, the public account, and sending. The public routes and the submit part take Koios’s own paths and JSON, so for them the fallback is only a change of base URL.

What it serves

Every request passes the edge first: a bucket per IP, a monthly traffic ceiling, and CORS for the wallet’s origins only. The relay has buckets and a ceiling of its own.

Run it

It’s its own Cargo workspace, with the Rust that rust-toolchain.toml pins.

cp .env.example .env     # then fill it in; git ignores it
cargo run -p seedelf-data-api
curl http://127.0.0.1:8099/health

cargo build --release -p seedelf-data-api builds the binary. It reads its settings from the environment, or from a .env file in the folder it runs from or any folder above it:

Variable What it is
MAINNET_DATABASE_URL db-sync’s Postgres, through a read-only role. The only one required.
MAINNET_KUPO_URL a Kupo that matches the contract and the mix box: the private index’s second source. Without it, the private index reads db-sync alone.
PREPROD_KOIOS_URL Koios preprod’s API, which the relay asks at each preprod certificate post (below): https://preprod.koios.rest/api/v1 unset. Anything but an https:// URL is refused at start: Koios is reached over TLS alone, and no redirect is followed.
MAINNET_SUBMIT_API_URL, MAINNET_OGMIOS_URL cardano-submit-api and Ogmios, for the submit part. submittx needs both and ogmios needs Ogmios; a route missing one answers 503.
DATA_LISTEN where it listens: 127.0.0.1:8099 by default
DATA_ORIGINS, DATA_TRUST_PROXY, DATA_EGRESS_GB_MONTH, DATA_MESSAGING_GB_MONTH, DATA_STATE_DIR the edge’s settings (below)
DATA_IN_FLIGHT_MESSAGING_ADDRESS, DATA_IN_FLIGHT_DATA_ADDRESS, DATA_IN_FLIGHT_MESSAGING, DATA_IN_FLIGHT_DATA, DATA_ANSWERS_MIB, DATA_COMPRESSING, DATA_CONNECTIONS the edge’s caps (below)
DATA_MESSAGING_READ_MIB_DAY, DATA_MESSAGING_READ_POOLS_DAY, DATA_MESSAGING_RESERVE_PERCENT, DATA_MESSAGING_RESERVE_PAGE_KIB, DATA_MESSAGING_RESERVE_READ_MIB_DAY, DATA_MESSAGING_OFF the relay’s reading, its reserve, and its off switch (below)
RUST_LOG the log level: info by default

What the services need, as templates in deploy/home/:

It listens on loopback by default. On the VPS, Caddy is in front of it, for TLS. Never expose it without TLS.

Tests:

cargo test                                    # offline
cargo test -- --ignored --test-threads=1      # live, against the services in .env
cargo clippy --all-targets -- -D warnings
cargo fmt --check

The live tests run one at a time: the database role allows 10 connections, and a running server holds some of them.

What it reads

The API runs on a VPS, behind Caddy. The services it reads run on a separate machine, which the VPS reaches through a WireGuard tunnel.

What it sees and keeps

What the code does is in this repository; what runs on the servers isn’t something a user can check. The deployed binary is built from main by .github/workflows/data-layer-deploy.yml, whose run prints its SHA-256.

The edge

What stands between the internet and the routes, in api/src/edge.rs, and the listener under them, in api/src/serve.rs. Caddy in front does TLS and its own timeouts, over HTTP/1.1 and HTTP/2 alone (deploy/edge/Caddyfile), so every limit on what a client may ask is in this repository’s code.

Setting What it does
DATA_ORIGINS the origins CORS lets read answers, comma-separated: the wallet’s chrome-extension://<id>. The wallet then needs no host permission. Retry-After is exposed, and a 429 carries CORS too, so the wallet can read why it waits. None by default.
DATA_TRUST_PROXY=true behind Caddy on loopback: the client is the last X-Forwarded-For address. From anywhere else the header is ignored. Any value but true or false is refused at start.
DATA_EGRESS_GB_MONTH the API’s own traffic a calendar month (UTC), in GB, before every route but /health answers 503. Each day gets an equal share of what’s left, so a flood costs a day, not the rest of the month. The count is kept in egress.json in DATA_STATE_DIR, or systemd’s StateDirectory, so a restart doesn’t forget it; with neither, the count starts from zero at each restart. Unset, there’s no ceiling. It counts response bodies alone: TLS and headers come on top. A value that isn’t a number above 0, 0 included, is refused at start, and the API doesn’t run.
DATA_IN_FLIGHT_MESSAGING_ADDRESS, DATA_IN_FLIGHT_DATA_ADDRESS the most requests one client has in flight at once on the relay’s routes and on the rest, from 1 to 4,096: 16 and 64 unset. Below 16 on the relay, Caddy’s own idle connections can hold a client’s last answers counted for up to 2 minutes (below).
DATA_IN_FLIGHT_MESSAGING, DATA_IN_FLIGHT_DATA the most in flight from every client together, from 1 to 65,536: 512 and 2,048 unset
DATA_ANSWERS_MIB the most bytes of the data routes’ answers held at once, not yet handed to a connection, in MiB, from 1 to 4,096: 256 unset, at least 8 times the largest answer
DATA_COMPRESSING the most answers compressed at once, from 0 (none) to 4,096: 64 unset
DATA_CONNECTIONS the most connections open at once, from 16 to 60,000: 8,192 unset
DATA_MESSAGING_GB_MONTH the relay’s share of that, at most, counted the same way (in messaging-egress.json). Past it, the relay’s routes answer 503 and every other route goes on: a flood of messages can spend messaging’s allowance, never the wallet’s reads. The last tenth of each day’s share is a reserve for posts and short pages. Its traffic counts toward DATA_EGRESS_GB_MONTH too. Unset, the relay has no ceiling of its own, and no reserve: it spends the API’s allowance, and /health says "ceiling":false. As with that one, 0 is refused at start and the API doesn’t run, so it never stops Messages alone: DATA_MESSAGING_OFF does (the relay).

A bucket per client: 300 units, refilled at 10 a second. IPv6 addresses are taken by their /64.

Request Costs
the private index, /health, and the public answers that are the same for everyone: tip, epoch_params, totals, pool_list, proposal_list 1
any other public route: one user’s live SQL 4
submittx, ogmios 10

The relay’s routes have buckets of their own, the same size, so catching up on messages never makes the wallet’s other reads wait: a page costs 1 and a post 4, and a page’s bytes are charged as every answer’s are.

Health

GET /health says each part’s state:

It answers 200 while the private index and the public routes answer and the month’s traffic is under its ceiling, and 503 otherwise. The submit part’s and the relay’s states are said but don’t change the status.

The private index

It lists every UTxO at two payment credentials (api/src/constants.rs): the Seedelf wallet contract, 94bca9c099e84ffd90d150316bb44c31a78702239076a0a80ea4a469, and the mix box of Lovejoin’s classic pool, c145c10ff4bcaef7f5a4dbb3fcbfddca4b6c7b08191b0690b12f1fad. The routes take no parameter but a cursor (api/src/private.rs), so no request says which rows are the asker’s.

What a cursor is: a point on the chain the server hands out, written <slot>.<block hash>. Its slot is a multiple of 200, at least 200 slots below the tip (about 10 blocks), and its hash is the newest block’s at or before that slot. The server refuses any other slot with a 400. 200 slots is deeper than the forks mainnet usually sees, so a cursor almost never rolls back; when one does, the answer says reset. Wallets that read within the same 200 slots hold the same cursor, so one answer serves them all, and a request shows only roughly when its wallet last read.

Every route is under /seedelf/v1/mainnet/, and every answer carries network and the source’s tip (its slot, hash and time).

Route Answer
contract/snapshot the contract’s rows unspent as of the stable cursor
contract/since/{cursor} what changed after that cursor, which the answer repeats as from: created (each with its spent, if it’s gone since) and spent (older rows spent after it, each its ref, slot, time and by), plus the new stable cursor
names every Seedelf unspent at the tip, with the row that holds it. A Seedelf is a token under the Seedelf policy, 84967d911e1a10d5b4a38441879f374a07f340945bcf9e7697485255, whose name starts with 5eed0e1f
lovejoin/pool and lovejoin/since/{cursor} the same for Lovejoin’s classic pool, at its mix box. Each box carries made_by: whether its transaction spent a box itself, and each input’s payment and stake credentials

For example, the contract’s rows, then what changed since:

api=https://mainnet.seedelf.logicalmechanism.io
curl -s "$api/seedelf/v1/mainnet/contract/snapshot"         # {"network", "tip", "cursor", "rows"}
curl -s "$api/seedelf/v1/mainnet/contract/since/<cursor>"   # <cursor> from the answer above

How a wallet reads it:

  1. A snapshot gives the settled view as of a stable cursor C.
  2. since/C gives the changes after it. The settled view plus created minus every spend is the view at the tip.
  3. The answer’s cursor is the new settled point C'. Apply only the entries at or below C' to the settled view. Everything above it is recomputed from the next answer, so a fork above a cursor never needs undoing.
  4. reset: true means the cursor’s own block was rolled back: start again from a snapshot. A reset carries no cursor, so none can be taken by mistake.

An answer’s cursor never goes back. A source a little behind the one that handed out from answers with from itself as the cursor.

Two sources, one answer. db-sync answers first. Kupo answers instead while db-sync is down, its tip over 3 minutes old, or more than 60 slots (about 3 blocks) behind Kupo’s, and whenever a db-sync read fails.

Caching: each source’s answers are kept until its tip moves. Both tips are read every 2 s, so one set of reads per block serves every request.

Lovejoin’s token pools

Beside the classic pool, anyone can launch a Lovejoin pool, each with its own box value: ADA, or ADA and a token. These routes are under /seedelf/v1/mainnet/lovejoin/ too, and db-sync alone answers them: Kupo indexes neither the pools nor the holder, where every launch puts its pool’s reference UTxO (below). While db-sync can’t answer, they answer 503, the wallet reads the token pools from Koios, and the classic pool’s routes go on answering from Kupo.

Route Answer
lovejoin/pools every shown pool as of the stable cursor: its id, its version (its template set, below: v2 or tokenV1), its reference UTxO, the seed its launch spent, its mix_box and mix_logic reference scripts at the holder (each row with its script_hash; the wallet derives the bytes), where its launch is (tx, block, index in the block, slot and time), and its crowd; and the classic pool’s crowd
lovejoin/tokens and lovejoin/tokens/since/{cursor} the boxes of every shown pool, read as lovejoin/pool and lovejoin/since are, with pools: the mix_box hashes covered, those shown as of the cursor (or from’s). A box’s made_by.mixed is whether its transaction spent from its own pool

What a launch is: it spends a seed UTxO, and the seed fixes the pool’s scripts. Applied to the seed, one_shot_mint hashes to P, mix_logic to L and mix_box to M. P is the policy of the pool’s lovejoin NFT and the pool’s id; M is where the boxes sit. The launch puts the pool’s reference UTxO at the holder, reference_holder: an always-false script with no parameters, so whatever is put there stays for good.

Two template sets: the versions of Lovejoin’s token-pool scripts the API recognises. v2 is the one the wallet launches pools on. tokenV1 is an older set: the wallet no longer launches on it, and only brings boxes back from its pools. They differ only in mix_logic, and a seed makes the same P on either, so a pool’s datum’s L says which set it runs.

A pool is shown (listed here, and offered by the wallet) when it’s standard and the earliest standard pool launched with its values on its template set (its box’s ADA and token), ordered by block, then place in the block, then id. A later standard pool with the same values on the same set is a copy, and isn’t shown. The sets are separate: a v2 pool is never a copy of a tokenV1 pool, and a tokenV1 pool shown stays shown, for the boxes the wallet brings back from it. Standard means:

The rule is in api/src/lovejoin/standard.rs. None of it changes once it’s on chain, so each candidate is checked once and its verdict kept in memory, and a pool shown stays shown. Everything at the holder is locked for good, so spam there is burned, and costs this server one check.

A pool’s crowd is its boxes, the deposits they could have come from, and how many of the boxes a mix made (mixed). A transaction that pays a pool’s mix_box without spending from it is a deposit; one that spends from it is a mix, and each box it makes could have come from any deposit behind any of its inputs. The deposits counted are those some box in the pool now could have come from, worked backwards from the boxes through each mix. A box is an output at the pool’s mix_box script, whatever its stake part, holding exactly the box value, under a datum that’s constructor 0 of two different 48-byte values, written either way the ledger reads it (tag 121, or 102([0, fields])). The key address under mix_box’s hash holds no box: nothing can spend it. The two values are meant as BLS12-381 G1 points; checking that they’re on the curve is left to the wallet. The crowd is the same for everyone; the wallet leaves its own boxes out of the count it shows.

For example, every shown pool and its crowd:

curl -s "https://mainnet.seedelf.logicalmechanism.io/seedelf/v1/mainnet/lovejoin/pools"   # {"network", "cursor", "classic", "pools"}

Kept: a cursor’s pool list, for an hour. It’s worked out once per cursor, in the background rather than inside a request, with a minute’s budget. A request waits at most 5 s; past that, or when its cursor or the list can’t be read, it gets the last list worked out, and a 503 only before the first one exists. The boxes’ feed is kept for db-sync’s tip.

The public routes

Koios’s paths and JSON, so a wallet falls back by changing its base URL. The code is api/src/public/.

Route What the wallet asks Kept
credential_utxos up to 75 payment credentials’ unspent outputs, 1,000 a page by outpoint, optionally only blocks after a height; at most 20,000 in all (but the contract’s and mix box’s) a block, for the contract’s or mix box’s; otherwise never
address_utxos up to 20 addresses’ unspent outputs, paged the same way; at most 20,000 in all never
utxo_info up to 60 outputs, spent or not never
datum_info up to 60 datums’ CBOR never
tip the newest block read every 2 s
tx_status up to 100 transactions’ confirmations never
epoch_params the newest epoch’s parameters a block
totals the newest epoch’s supply a block
account_addresses up to 20 stake keys’ addresses, empty ones too never
account_info one stake key’s standing never
account_reward_history one stake key’s rewards, oldest first, 1,000 a page: the wallet’s Staking screen, Rewards history, read only when it’s opened never
account_update_history one stake key’s certificates (registered, staked, vote delegated, stopped), oldest first, 1,000 a page: the Staking screen’s Delegation history, read only when it’s opened never
account_txs one stake key’s transactions: a page of 20, at most 10,000 in, or up to 1,000 from a block on; for a key with at most 200,000 outputs. The wallet’s restore scan never
credential_txs up to 75 payment credentials’ transactions, whatever their addresses’ staking part, paged as account_txs is; for at most 200,000 outputs in all. The wallet’s Activity screen for the public account, by its payment keys never
tx_info up to 20 transactions, in Activity’s shape or inputs alone never
pool_list the registered pools, 1,000 a page an hour, within its epoch
pool_info up to 5 pools’ details and live stake 10 minutes, within its epoch
pool_history one pool’s last 18 epochs whose rewards are final: active stake, blocks, and what it paid its stake. A pool’s Return on stake every pool’s epoch, worked out once and kept for the server’s life
drep_info up to 5 DReps’ standing 10 minutes, within its epoch; the account’s own (deposit,meta_url,meta_hash selected) never
drep_metadata up to 5 DReps’ profile names 10 minutes; the account’s own profile (is_valid selected) never
proposal_list the live governance actions 5 minutes, within its epoch
vote_list one DRep’s votes on up to 40 actions never
asset_nft_address the address holding one NFT (an ADA Handle) never
asset_info one token’s CIP-25 and CIP-68 metadata never

What one request may cost is bounded. Any credential, address or stake key may be asked about, and some on mainnet hold hundreds of thousands of outputs. So a listing gathers at most 20,000 unspent outputs, and account_txs and credential_txs at most 200,000 outputs, with a page starting at most 10,000 transactions in. Past any of these, the answer is a 503, {"error":"too large for this server"}, with no Retry-After: it would be as large again, so the wallet reads Koios, for that request alone. They’re set far above what one wallet’s own accounts hold. Requests are also held to the wallet’s own sizes (one account’s standing, 20 keys probed).

Answers kept for a time are kept within their epoch, since a pool’s status, a DRep’s activity and the live actions turn at an epoch’s start. Not-found answers aren’t kept: anyone can ask about made-up IDs. When the store is full, the answer due to expire soonest makes room. A request waits at most 5 s for a shared answer, its queue included, then gets a 503.

An ID has one spelling: the lowercase bech32 the wallet sends. The server re-encodes what it decodes and takes the ID only if the two match: the decoder alone would also take a Bech32m checksum and stray padding bits, which would let one pool be asked for, cached and worked out under several names.

Only the wallet’s requests. Each route takes exactly the query string and body the wallet’s koios.ts sends: its parameters, in its order, at its sizes. Anything else is a 400, {"error":"not a request Seedelf Wallet makes"}, before any query runs, so no caller can compose an expensive one. A POST’s body is application/json. api/tests/public_grammar.rs holds a request each route takes, and ones it refuses. For example:

api=https://mainnet.seedelf.logicalmechanism.io
curl -s "$api/api/v1/tip"
curl -s "$api/api/v1/epoch_params?limit=1"
# one stake key's standing
curl -s -X POST -H 'content-type: application/json' \
  -d '{"_stake_addresses":["stake1u9c0yhlklkdd7vcwkvv2cjrgnw48y82jmm2ulk3vxe2qupsv2va8g"]}' \
  "$api/api/v1/account_info"
# the Seedelf contract's first 1,000 UTxOs
curl -s -X POST -H 'content-type: application/json' \
  -d '{"_payment_credentials":["94bca9c099e84ffd90d150316bb44c31a78702239076a0a80ea4a469"],"_extended":true}' \
  "$api/api/v1/credential_utxos?order=tx_hash.asc,tx_index.asc&limit=1000"
# a pool's last 18 epochs
curl -s "$api/api/v1/pool_history?_pool_bech32=pool1gaztx97t53k47fr7282d70tje8323vvzx8pshgts30t9krw62tm&select=epoch_no,active_stake,block_cnt,deleg_rewards&order=epoch_no.desc&limit=18"

Answers use Koios’s names and types for every field the wallet reads. Fields it never reads are left out:

The SQL is written after Koios’s grest functions (koios-artifacts, CC-BY-4.0): an account’s standing, a pool’s state and live stake, a DRep’s activity and delegators, a token’s minting metadata. The live tests hold some answers to Koios’s recorded ones: a token’s metadata, a delegation history, a pool’s history (api/tests/live_public.rs). CIP-129 DRep, committee and governance action IDs are made in Rust (api/src/ids.rs).

What stands in for Koios’s caches:

The public routes have their own connections: 6, beside the private index’s 2 and the tip’s own 1, so a burst of them never holds the private index up.

The histories are read oldest first, sorted in SQL by the order the wallet asks for, so the pages stay still while db-sync adds rows; the wallet shows them newest first.

pool_history follows Koios’s pool history function (grest.get_pool_history_data_bulk), with every pool’s epoch worked out at once and kept. Each row is an epoch’s active stake, the blocks made by slot leader, and deleg_rewards: the members’ rewards earned in it and the leader’s, less the pool’s fees by the terms active then, rounded half to even. The 18 epochs are those whose rewards are final: the 18 ending two epochs ago.

The submit part

Route Upstream The server’s own checks
POST /api/v1/submittx cardano-submit-api, POST /api/submit/tx the body is application/cbor (415 if not) and at most 16 KiB, the ledger’s max_tx_size (413 if more); at most 4 in flight (503 past it)
POST /api/v1/ogmios Ogmios, POST / application/json (415 if not: a text/plain POST needs no CORS preflight, so a web page could send one); a JSON-RPC 2.0 evaluateTransaction and no other method (400); at most 64 KiB; at most 2 in flight

Seedelf Messaging’s relay

Seedelf Messaging’s relay, in api/src/messaging/ (web wallet chunk 54’s 54c). The protocol is protocol.md: §10 says what the relay is for, and §17 every byte of what it takes and gives.

Route Takes Answers
POST /messaging/v1/{pool}/envelopes nonce (8, big-endian) ‖ envelope, as application/octet-stream, at most 32,776 bytes 200 {"kept": "new" \| "already", "expires": <Unix time>}
GET /messaging/v1/{pool}/envelopes?after=<cursor> the cursor from the last page; none for the first a page, as application/octet-stream: below
POST /messaging/v1/{pool}/certificates nonce (8, big-endian) ‖ certificate, as application/octet-stream, at most 312 bytes 200 {"kept": "new" \| "already"}
GET /messaging/v1/{pool}/certificates?after=<cursor> the cursor from the last page; none for the first a page of the list, as application/octet-stream: below
POST /messaging/v1/{pool}/withdrawals nonce (8, big-endian) ‖ withdrawal, as application/octet-stream, exactly 106 bytes 200 {"withdrawn": true}

A post is checked, cheapest first:

  1. The shape: version 1, and exactly 512, 2,048, 8,192 or 32,768 bytes long, the session layer’s four sizes. Else 400.
  2. Already held? Then 200 already, whatever its stamp: a wallet re-posts the same bytes after a restart. Its expires is the copy’s, rounded down to 10 minutes; a new post’s is exact, the relay’s now and 36 hours.
  3. The price and the window: past the price’s ceiling, or past what the address may have in the pool (below), a 429 with Retry-After: too many posts from this address for now when its own posts took the price there, too many posts to this pool for now when everyone’s did. Then the proof of work over the envelope’s bytes and the pool’s name (§17): too little is a 402 with the price in bits. The 429 comes first, so a post with nonce 0 learns how long to wait without solving.
  4. Room: a pool holds at most 64 MiB (preprod 8 MiB). Past it, 503 with Retry-After, until the oldest expire, rounded up to 10 minutes and at most an hour. Before the points, so a post to a full pool costs no point check, however often it comes; looked at again as the post is kept.
  5. The points: p (bytes 1 to 48) and c (bytes 81 to 128) each a valid point of G1, so a reader never meets garbage. Else 400, counted against the address’s own price (below), so one solved stamp pays for only so many point checks. Checked last, since it’s the costly check. The 32 bytes between them (49 to 80) are a tag, which isn’t checked: only the envelope’s reader can tell it from any other 32 bytes.

The price is a number of bits: 2^bits SHA-256 attempts on average, about 425 ns each in a browser’s WebAssembly. Mainnet’s base is 18 bits (about 0.1 s), and its ceiling 24 (about 7 s). What’s counted is units, an address’s and everyone’s, halving every 10 minutes (api/src/messaging/price.rs): 1 for an envelope of 512 or 2,048 bytes, so a short message padded to 2 KiB costs what a short one does, 16 for 8,192 bytes and 64 for 32,768. A bit more for every 32 of the address’s recent units, this post’s included, and a bit more for every doubling of everyone’s past 1,000. A kept post counts in both; one refused at its points in its address’s alone, so nobody raises the price everyone pays with posts that are never kept. An IPv6 address is counted by its /56, so the /64s of one allocation are one address (the edge’s buckets take a /64). The counts live in memory, an address’s while it’s above a hundredth of a unit, and nothing logs them.

The window (api/src/messaging/window.rs): what one address may have in a pool over its 36 hours, whatever work it does, since every reader downloads and scans every envelope. At most 1,000 envelopes and 4,096 units of 512 bytes (2 MiB), whatever the price counts, on both pools (POOLS in api/src/messaging/mod.rs, the owner’s to tune). The relay counts each address’s kept posts in hourly buckets, envelopes and units, and drops a bucket 36 hours after its hour ends, when all it counted has expired. Past either limit, a 429 whose Retry-After is when enough of the oldest buckets age out: at most 37 hours. Checked again as the post is kept, so posts at once can’t pass it together. The buckets are counts, never which envelopes; in memory only, never in the pool’s file, so a restart starts them empty. At most 200,000 addresses each, the prices’ and the window’s; past it, a new address’s post is a 503 busy.

A page holds whole envelopes, at most 256 KiB of them (always at least one), in the order they came:

version (1) = 1 | flags (1) | cursor (8) | prices (4) | count (2) | count × (length (4) | envelope)

A day’s reading (api/src/messaging/reading.rs): a page costs no work, so what one address is sent of a pool is bounded instead, over the last 24 hours in hourly buckets: at most 256 MiB, or 8 times the pool’s cap where that’s more, so 512 MiB of mainnet’s and 256 MiB of preprod’s. An honest reader downloads each envelope once; the rest is room for the wallets behind one address, and a fresh sync or two each. Keyed as posts are, an IPv4 address whole and an IPv6 address by its /56. A page counts as it’s made, whether or not its reader downloads it. The page that passes the budget is sent; after it, a page is a 429 whose Retry-After is when enough of the address’s oldest hours have aged out, at most 25 hours. Posts are counted apart, and go on. A page of the list counts in the same day as the pool’s pages. The counts are bytes an hour, never which pages or cursors, in memory only, so a restart starts every reader’s day again. At most 200,000 addresses; past it, the one seen least recently goes and its day starts again, so no reader is refused for the table’s sake.

The reserve (Reserve in api/src/edge.rs): once nine tenths of today’s share of DATA_MESSAGING_GB_MONTH is spent, a page is at most 16 KiB, its framing included: as many whole envelopes as fit, with the flag that says another page follows now. An envelope longer than that by itself, one of 32 KiB, is a page alone, so no reader stops at it. Posts go on, and so do pages, until the share is gone. A fresh sync then takes 16 pages where it took one, while a conversation under way, whose wallet reads a few envelopes a page, reads as before. A page of the list is cut the same way, to whole entries, and counts against the same share. Each address reads at most 16 MiB of the reserve in a day, both pools together (about three days of a busy pool’s envelopes), counted as the day’s reading is: past it, its pages are the day’s reading’s 429, this address has read its share of the pool for the day, whose Retry-After is when enough of its oldest hours of the reserve age out, or a minute past midnight UTC, when the next day’s share begins and the reserve lifts, whichever is first. The wallet holds that pool’s pages until then, as for its day’s reading; a 503 would read as the relay out of reach, asked again at every sync. So one address can’t spend what’s kept for conversations, though many can: about 190 IPv4 addresses spend a 3.2 GB reserve, and about 40 to 45 the nine tenths before it, by asking alone. Without a ceiling of its own there’s no day’s share, and no reserve.

Setting What it does
DATA_MESSAGING_READ_MIB_DAY the least one address may read of a pool in a day, in MiB, from 1 to 1,048,576: 256 unset
DATA_MESSAGING_READ_POOLS_DAY and at least this many times the pool’s cap, from 0 to 1,000: 8 unset
DATA_MESSAGING_RESERVE_PERCENT the part of each day’s share kept for posts and short pages, from 0 (none) to 100: 10 unset
DATA_MESSAGING_RESERVE_PAGE_KIB the longest page the reserve sends, in KiB, from 1 to 512: 16 unset
DATA_MESSAGING_RESERVE_READ_MIB_DAY what one address may read of the reserve in a day, both pools together, in MiB, from 1 to 1,024: 16 unset
DATA_MESSAGING_OFF true stops Seedelf Messaging, as the off switch below says; false, or unset, runs it; a pool’s name, preprod or mainnet, stops that pool alone, and preprod,mainnet (either order, whitespace trimmed, each once) is true

A value that isn’t a whole number in its range, or true, false or a list of pools for the switch, is refused at start. All six are the owner’s to set, DATA_MESSAGING_OFF only through the runbook’s drop-in, never in the environment file, whose value would override it (Stopping Messages); the start’s log line says what the relay runs with.

The off switch. With DATA_MESSAGING_OFF=true, every route under /messaging/ answers 410 Gone, {"error":"messaging is stopped"}, with CORS, before any other limit. A post’s body isn’t read, so nothing is kept. Every other route answers as before, and /health says "relay":"off". By network: DATA_MESSAGING_OFF=preprod (or mainnet) stops that pool alone. Its routes, /messaging/v1/preprod/… (the envelopes, the list and withdrawals), answer the same 410, and the other pool’s answer as ever. A path that names no pool is the routes’ to answer, as with none stopped. A path under /messaging/ spelled with a percent-encoding is a 400 encoded paths aren't taken here, with CORS, before the switch is looked at, since the routes decode a pool’s name (the wallet never sends one); and each route checks the switch by the name as it decodes it too. /health says "relay":"partly", and each pool’s "stopped" says which. Preprod’s test ADA is free, so the price that bounds a flood on mainnet bounds none there: this lets preprod stop while mainnet goes on, or the reverse. The runbook’s Actions flip it one network at a time. The pools are still read at start and saved, and what they hold expires as ever. A wallet reads a 410 on a network’s relay routes as Messages stopped on that network, and shows that network’s Messages as paused: it solves and posts nothing there, keeps what’s queued, and asks one page an hour, and one at each unlock, until a page gets an answer other than the 410. So a stopped relay still sees those pages, and now and then a post a wallet made as it unlocked. The lever and its undo are the runbook’s Stopping Messages.

The pools are saved to the state directory (messaging-<pool>.pool) every minute and at shutdown, and read at start, so a deploy keeps what’s waiting. A pool that hasn’t kept anything yet is written too. A shutdown leaves a mark beside each file (messaging-<pool>.clean) saying it holds everything; without the mark, a pool read at start tells every earlier cursor of a gap, since what came after the last save is gone, and numbers what comes next far above that save’s numbers, should the clock have gone back. Where its numbering then stands is saved at once, at the first minute’s save, so a second crash numbers above it again. A pool whose file is there but can’t be read, or isn’t one this build reads, starts empty and leaves the file as it was, and gets no clean mark until a save of it succeeds: so the next start that reads the file tells every earlier cursor of a gap, rather than silently skipping what it held. A save writes to messaging-<pool>.partial (its mark to messaging-<pool>.clean.partial), syncs it, renames it into place and syncs the folder, so a power loss keeps the rename too, and leaves nothing behind when that fails; a start removes what one left. A folder that can’t be synced is a save that failed. Each pool’s list is saved the same way, in files of its own: messaging-<pool>.list, its mark messaging-<pool>.list.clean, and their partials .list.partial and .list.clean.partial. A list read at start has each certificate’s shape read again, to index it, but not its proof: the file is the relay’s own, and some 200,000 proofs would hold a start for minutes.

Times are the server’s clock. An envelope kept while the clock ran ahead counts its time as now at the next look after the clock is right, so it’s kept 36 hours from then and holds back nothing that came after it; a pool read from its file drops each envelope whose own 36 hours are over, wherever it is. A clock that’s behind at a start shortens what’s kept by as much: the waiting envelopes’ times count as that start’s now, so once the clock is put right each is that much older. A clock set back while the API runs, then put right, shortens the same way what came in the step’s length before it. So the API starts after time sync (the runbook’s block).

The checks are a copy of seedelf-messaging’s relay module, which the data layer can’t depend on. Both are held to seedelf-platform/seedelf-messaging/tests/vectors/messaging_relay_v1.json, which the crate writes: every envelope it holds, kept or refused and why, and stamps with their work. So are a certificate’s and a withdrawal’s (api/src/messaging/certificate.rs), of the crate’s session::certificate, held to messaging_certificate_v1.json: every good certificate and withdrawal in it checks and gives its h_S and digests, and every refusal is refused with its kind. A datum register is read as Lovejoin’s box is (api/src/lovejoin/datum.rs), held to the wallet’s register-spellings.json. The Seedelf policy they take is the data layer’s copy of variant 1’s (api/src/constants.rs), held to seedelf-core’s. Its G1 library, blst, is built portable, so one binary runs on any x86-64 server: it picks the ADX code at start where the CPU has it, and the plain code where it doesn’t.

A load test, on two cores, the droplet’s size: RELAY_LOAD=1 taskset -c 0,1 cargo test --release --locked --test messaging_load -- --nocapture. It runs the server in the test as main.rs serves it, on a local port, with no source. On an Intel Core i5-12400F, with the test’s clients on the same two cores: about 13,000 posts a second (p50 about 4.5 ms, p99 16 to 21 ms, 64 at once), and fresh syncs of a 3,000-envelope pool at about 600 MB/s. Before the listener’s 32 KiB send buffers and the edge’s pacing (the 1.10.0 gate), it was 2.0 GB/s, and posts as many. Traffic, not the relay, is the droplet’s limit: every reader downloads every envelope. It posts certificates, each one’s proof checked and each Seedelf looked up in a Koios on loopback at most 4 at once, as on preprod, and reads the list whole too: those figures are still to measure.

The list of certificates

api/src/messaging/list.rs, protocol.md §21.7. A certificate binds a Seedelf’s messaging register M_S = (h_S, m_S) to its datum’s register (g_S, u_S), with one proof of both keys (§21.4). Writers read the list to find whom to write to. A post, nonce (8, big-endian) ‖ certificate, is checked cheapest first, and the first that fails answers:

  1. A nonce, and no more than the longest certificate: 8 to 312 bytes. Shorter, a 400; longer, the edge’s 413 the body is larger than this route takes, unread, before the route.
  2. The shape (§21.4’s check 1): 273 to 304 bytes, its length its name’s; version 1; the pool’s network byte, 0 on preprod and 1 on mainnet; generation 0; and variant 1’s Seedelf policy. Else 400.
  3. Already held? A certificate for the same name, register and m_S: 200 {"kept":"already","digest":"<hex>"}, whatever its stamp or its proof, so a wallet’s own repost, or one with a fresh aux, isn’t asked to pay. digest is the listing digest of the certificate the list holds, which may be another posting’s bytes: a withdrawal must name it.
    • 3′, withdrawn? A listing digest a withdrawal took down for that name at its register, which the list keeps as its first 8 bytes: 409 withdrawn, whoever posts those bytes again (below).
    • Withdrawn too often? 128 certificates withdrawn and listed together for the name at its register: 409 this Seedelf was withdrawn too often at this register: move it to list it again. Listed ones count, since each could be withdrawn: at 127 withdrawn one more is listed and a second isn’t, so its withdrawn never pass 128. So a loop of posting and withdrawing, each time with a fresh aux, can’t fill the list; moving the Seedelf, a new register, starts it fresh.
  4. The price and the window, a 512-byte envelope’s from the same address: a certificate is priced, and counted once listed, as one. The 429s are an envelope’s.
  5. The stamp, over the listing digest, SHA-256("Seedelf-Messaging|v1|listing-stamp|" ‖ len(pool) ‖ pool ‖ certificate), which is also what a removal names it by: too little is a 402 with the price.
  6. Room: at most two certificates, each with its own m_S, for one name at one register, else a 409 two certificates for this Seedelf already; and the list under its cap, 64 MiB of entries on mainnet and 8 MiB on preprod, else a 503 the list is full, Retry-After an hour. A certificate held is never pushed out for another: a full list refuses. Before the proof, so a post that can’t be listed costs no proof check.
  7. The points and the proof (§21.4’s checks 2 to 5): g_S, u_S and m_S valid points of G1, c, z_x and z_m below the group order, h_S hashed to the curve, and the proof. Else 400. Last but the chain, since it’s the costly check: about five scalar multiplications and a hash to the curve.
  8. The chain (api/src/messaging/view.rs, chunk 55’s call 6): (g_S, u_S) is the datum register of the one contract UTxO that holds the Seedelf’s token now, under an inline datum read as a register is everywhere in the workspace. Else 409 not this Seedelf's register now. When the relay can’t read the chain, a 503 can't check the chain now, Retry-After 60, or on preprod however long Koios’s day’s budget, the address’s share of it or its back-off has to run (Where the chain is read, below): a certificate is never listed unchecked. On preprod an ask that would take the address past its window is check 4’s 429, Koios not asked. Last, since it reads another part of the API or another server.

Every post that reaches check 7 is counted against its address’s price, whatever comes of it: a bad proof, a 409 or a 503 from the chain, a request whose client hangs up while the chain is read (a guard counts it as it’s dropped), or a kept certificate. So one solved stamp can’t be posted again and again for proofs and reads of the chain. On preprod a post that asks Koios is counted in its address’s window as it asks, as a listed certificate is, whatever comes of it (a 409, a 503, a hang-up), and not again once listed; one whose answer is kept from the last minute asks nothing, and counts there only if it’s listed.

Listed, 200 {"kept":"new","digest":"<hex>"}, its own listing digest. Posts at once are checked again as they’re listed, so they can’t pass the window, a name’s two, the cap or a withdrawal together.

Where the chain is read:

A writer checks every certificate against its own read of the contract (§21.5): the relay’s checks keep garbage and crowds out of the list, and are never what a writer trusts.

A page of the list holds whole entries, at most 64 KiB of them, their framing aside (always at least one), in the order the list took them:

version (1) = 1 | flags (1) | cursor (8) | price (1) | count (2) | count × (kind (1) | length (2) | entry)

The cap counts the entries’ bytes, certificates’ and removals’, and for the withdrawn digests it keeps, 8 bytes each and their Seedelf’s name and register once (1 + its length + 96). The indexes beside them, by name and register and by listing digest, add about as much again: 647 bytes of heap for a 273-byte certificate, measured, so mainnet’s 64 MiB list would hold about 150 MiB. /health gives each pool’s certificates, withdrawn and chain.

Withdrawals

A wallet turning Messages or a Seedelf off withdraws each of its own certificates the list holds (chunk 55’s call 9). A withdrawal is version (1) = 1 ‖ network (1) ‖ digest (32) ‖ c (32) ‖ z (32), 98 bytes: the withdrawn certificate’s listing digest, and a proof of its messaging key x_m on that certificate’s own messaging register (h_S, m_S), never the Seedelf key. A post, nonce (8, big-endian) ‖ withdrawal, is checked cheapest first:

  1. 106 bytes: shorter, a 400; longer, the edge’s 413, unread.
  2. The shape: version 1, the pool’s network byte, c and z below the group order. Else 400.
  3. A held certificate under the digest, else 404 no such certificate, which tells a poster only what the list shows. One a withdrawal took that no save holds yet is checked as the first post was, against the certificate taken, and answered as that save says (below), never 404.
  4. The price and the window, a 512-byte envelope’s from the same address. The 429s are an envelope’s.
  5. The stamp, over SHA-256("Seedelf-Messaging|v1|unlisting-stamp|" ‖ len(pool) ‖ pool ‖ withdrawal): too little is a 402 with the price.
  6. The proof: T = [z]h_S − [c]m_S with the held certificate’s register, and c = SHA-256(Seedelf-Messaging|v1|withdrawal ‖ version ‖ network ‖ digest ‖ h_S ‖ m_S ‖ T) mod q. Else 400. Every post that reaches it is counted against the address’s own price, whatever comes after, a dropped request’s too.

Taken, 200 {"withdrawn": true}: the certificate goes, a removal entry naming it is the list’s next, its Seedelf has room for another, and the post counts as a kept short envelope. The list is saved before the answer, its folder synced too, so neither a crash nor a power loss after it can bring the certificate back. A save that fails puts the certificate back in memory, listed again after its removal (so a reader who read the removal reads it again) and its digest not kept, and the answer is 503 can't save now, Retry-After 60: a 200 is only given for a withdrawal the file holds. The save settles it itself, so a post whose client hung up meanwhile (the wallet’s own timeout) still has its certificate put back; and a post of the same withdrawal while the save runs, a retry or another browser’s, waits for it and is answered as it says, 200 or that 503, never the 404 the wallet takes for done. A withdrawal lasts: the digest is kept, as its first 8 bytes with its name and register, saved with the list and 8 bytes in the cap’s count, and a post of those same bytes is refused at check 3′, so whoever kept them while they were listed can’t list the Seedelf again. An owner who turns Messages on again posts a new certificate, with a fresh aux, so another digest: at most 128 times at one register (check 3’s withdrawn too often). The digest goes once the relay’s view of the chain has found its Seedelf elsewhere three times in a row, each on a view that changed since the last. The checks are a copy of the crate’s Withdrawal, held to messaging_certificate_v1.json’s withdrawals and their refusals.

A row

{
  "ref": "<tx hash>#<index>",
  "address": "addr1…",
  "lovelace": "1749860",
  "assets": [["<policy>", "<name>", "1", 0]],
  "datum": "d8799f5830…",
  "script": true,
  "created": { "slot": 144889937, "time": 1736456228 },
  "spent": { "slot": 199943000, "time": 1791509291, "by": "<tx hash>" },
  "made_by": { "mixed": true, "inputs": [["<payment cred>", "<stake cred or null>"]] }
}

Limits

Help

For support and bugs, open a GitHub issue or a support ticket in the Seedelf Discord. Security vulnerabilities go by email only: see SECURITY.md.

For contributors