Status: implemented, with one open defect that is not in this project. What is
built, what its tests prove and what they do not is in docs/STATUS.md; every
number below is marked measured, derived or assumed, and the staged gates say
which measurements turn an assumption into a design decision. The one gate that
still fails is TestDaemonFillsFromANode, on btcd's v2transport:
docs/upstream/v2transport-garbage-terminator.md.
A process that pulls blocks from the peer-to-peer networks of two chains that share history up to a hardfork, keeps the parts of that history the two chains share once, keeps both chains' headers, generates the compact filters the swap client scans, and serves all of it over HTTP so that a second instance can be populated from the first in hours instead of syncing from the network for weeks.
The consumer is blake-swap's light client: headers, filter headers and compact
filters for btc and xbt, and a place to send the transactions it signs. It
needs a data source with filters, headers and blocks, and it does not need a
validator, a wallet or a full UTXO set of either chain. It does need a relay,
and that is a feature of the service, not a consequence of the data.
| btc | xbt (blake) | |
|---|---|---|
| genesis | 000000000019d668...a8ce26f | the same block, the same hash |
| magic, port | f9beb4d9, 8333 | f9beb4d9, 8333 |
| shared history | 0..961631 | 0..961631 |
| header from 961640 | 80 bytes, double SHA-256 | 164 bytes, ForkHash (pkg/btcwire/fork.go in nostrino) |
| difficulty at 961640 | Bitcoin rules | one-off shift of 22 bits (target_shift) |
| retarget boundaries | 961632, then 978,144 | 961648, then 978,160 (first boundary at or after 961640) |
| filter type | BIP158 basic | BIP158 basic, over the same scripts (unverified against a node) |
The fork changes three things and nothing else: header bytes and their hash from 961640, the difficulty at 961640, and the tagged-hash signature scheme. The signature scheme is the pivot's business, not this one's: block bodies, transactions and filter contents are the same format on both chains, which is what makes one body serve two positions.
Heights 961632..961639 have 80-byte headers on both chains and Bitcoin's difficulty rule on both (the 22-bit shift applies at 961640, not at the window boundary). The two header chains are the same bytes there: one store holds them.
The constants above are from nostrino's pkg/chain/chain.go and
docs/profiles/xbt.json. pkg/btcwire/fork_test.go also holds a test that
exercises the fork rules against the alliance nodes; I have not run it or the
nodes this session, so the fork path is taken as given, not re-verified here.
The fork is not scheduled on regtest, so no fork behaviour can be tested there:
it needs the alliance network over p2p, or a node source to run against.
Electrs already serves headers, a height index of block hashes, transaction lookups and address indexing, and its UTXO side has the property this plan needs no time machine for. It does not serve compact filters, it is biased towards its own RPC node rather than p2p, the XBT half would be a fork of it, and a UTXO diff API is not among the things it offers. There is no electrs for XBT at all.
Nostrino's neutrino already does the neutrino side of this: headers from a
peer with proof-of-work, XBT v2 header shape, target shift and difficulty
checks, filter headers, filters with verification, reorg truncation, and an
import path for backed-up records (ApplyHeaders, Backup/Restore on its
Store). It is the client, and it is where the verification already lives.
The right split of work. btcd-lite reuses neutrino rather than rebuilds it:
neutrino.Client pulls headers per chain into a store, ChainSource supplies
blocks from a source before the peer, and anything a checkpoint pins is never
re-pulled. What btcd-lite adds is the store, the filler, the UTXO spine, the
checkpoints, the diff format and the HTTP service. That is the code below.
btcd is the source library, not the ancestor. Its block parsing and script
encoding are copied in (internal/wire) to keep versions under control here,
after the architectures are shown to be able to avoid a second copy of those
bytes. See "the second copy of every block" below.
This is a data service, not a node, and it does not execute scripts. That is a scope decision with a large compute consequence and one honest limitation.
What is verified:
| thing | how |
|---|---|
| the header chain | neutrino's rules: proof of work, linking, difficulty, the fork's v2 form. Already in the header store |
| each body against its header | the merkle root in the header commits to the transaction list; a body whose transactions do not root there is rejected by hash |
| each body against the hash it was asked for | the store refuses bytes that do not hash to the key |
| each spend's prevout | a range that spends an outpoint the set does not hold is refused, so the set cannot silently lose an output |
| each filter against its filter header | the filter hash is committed by the folding chain |
What is not verified: script execution of any kind. No signature checks, no script interpreter, no amount-conservation rule beyond what the set needs, no locktime, no sigops, no standardness, no coinbase maturity.
Why that is sound here. The blocks come from a chain whose headers were verified, and the merkle root in each header commits that header to its exact transaction list. A party that hands over a body that is not the block the header names is caught by a hash, and a party that mines a different block is not mining this chain. So the transaction-level validity of a block is inherited from the chain, not re-derived: re-deriving it would be re-doing the node's work with the node's own answer already in hand.
What it saves. The plan's filter and UTXO work walks 0.94 G transactions and about 1.5 G inputs. At the measured 162,759 ns for one secp256k1 verification, one input per verification is 244,000 seconds, about 68 hours of one core, before any script logic on top. That is the cost this decision declines, and it recurs on every rebuild because a rebuild walks the blocks again.
The limitation, stated rather than buried. An instance cannot tell a
consensus-invalid chain from a valid one. It trusts the chain it followed. That
is the same trust a checkpoint served by an instance already implies, and it is
why the service publishes what it verified: docs/ARCHITECTURE.md, "The
boundaries". A client that needs more than that needs a node.
**One divergence a client must know about: coinbase maturity is a rule, not a constant, and it is not the same on both chains.** The set records a coinbase output as unspent from the block it appears in, because maturity is a consensus rule and nothing here replays scripts. A client asking "what can I spend at height H" has to apply the rule itself, and the rule is per chain and per height.
The fork's own chainparams, read from its source, schedule a long-maturity window rather than a different flat number:
| parameter | btc | xbt |
|---|---|---|
| base requirement | 100 | 100 |
| long requirement | none | 6480 |
| window opens, by spend height | never | 973,440 |
| window closes, by spend height | never | 979,920 |
| coinbases affected | none | those created at or after 973,440 |
The comparison is asymmetric and that is the node's rule, not a simplification: whether a coinbase gets the long requirement depends on the coin's own height against 973,440, and whether the window is open depends on the **spending block's height** against the same number and against 979,920. After 979,920 the requirement returns to 100, including for coinbases created inside the window.
internal/chains carries this as MaturityRule, with `RequiredAt(coinHeight,
spendHeight), and TestCoinbaseMaturityIsPerChain` checks it at every boundary:
a coinbase one block before the window, the window's first height, one block
short of the long requirement, the last enforcing block, and the release.
Regtest schedules nothing unless the node is started with
-coinbase-maturity-long-*, which the rig does not do, so a regtest chain's
requirement is the base 100 and the gate that cross-checks against gettxout
uses the chain's own number rather than a literal.
The claim under test: pre-fork blocks are stored once for both chains, and the UTXO set is collapsed to a set of checkpoints from which diffs are served.
| chain | body bytes released 0..961644 | share of history |
|---|---|---|
| btc | 555.8 GB (derived: 402 GB at 2024-04 to 956,000, plus 153.8 GB for heights 956,001..961644 at ~300 GB/yr) | |
| xbt | 15 GB (derived: the fork's post-fork blocks, 961641..984346, at ~0.65 MB/block from the 2026-12-01 measurements) | |
| naive total | 570.8 GB | |
| shared stored once | the btc figure (the shared prefix is its bulk) plus the two chains' divergent post-fork region, 15.1 GB | 97.4% of the naive total |
Derived, not measured. The blocks/ backfill task (gate 3) measures real sizes
per 10,000 blocks and corrects both figures.
A chain of shared blocks has two positions. A refs table maps
(chain, height) -> (spine_block_id), so a block that is one 32-byte hash is
one row per chain, and a block on only one chain is a spine entry with one
ref. That is the collision collapse: 97.4% of the stored bodies carry two
positions for one block id.
Canonical layout. The pre-fork UTXO set is stored once, as a set of
canonical entries per height: (txid, vout, value, script hash), sorted by
outpoint, in the layout of Bitcoin Core's hash mode. Post-fork each chain has
its own set. A UTXO query for either chain at a pre-fork snapshot height is
answered from the canonical entry; between snapshots it is answered by applying
the per-block diffs, which is expressible at every height and not yet cheap.
The per-chain (height, created, consumed) index this section first proposed
does not exist. It is the index question at the end of this section, and without
it a query at an arbitrary height costs a scan bounded by one epoch.
The indexes cannot exploit the shared prefix: an output created at 500,000 on btc may be spent at 600,000 on btc and 970,000 on xbt, so the spending ranges overlap but differ. The headers do exploit the prefix; the indexes do not. The collapse is partial at the UTXO layer and total only at the block layer.
Snapshot cadence: the difficulty retarget. A full canonical snapshot is
taken at every height that is a multiple of the chain's retarget_interval
(2016 on btc, 144 on regtest, from the chain profile). Between snapshots there
is one diff per block, not one diff per range.
Why that cadence and not an arbitrary spacing: the retarget boundary is where
the chain itself changes its rule, it is a height every other piece of software
already names, and it divides the chain into epochs of roughly two weeks. A
client names a set by epoch, height / interval, and the heights inside an
epoch are diff heights.
The client path for the set at arbitrary height H: take the snapshot at
floor(H/interval)*interval, apply the per-block diffs for the heights between,
at most interval-1 of them. To keep that from being one round trip per block,
a utxo.diff chunk carries a contiguous run of per-block diffs, so a client
asks for 100 heights at a time and applies 100 small diffs to its copy of the
set. Storage granularity is one block; transport granularity is a range.
What that costs, derived and to be measured before it is believed. The cadence
and the per-block diffs are built; the sizes below are still derivations and
STATUS.md says so:
| term | derivation | pre-fork total |
|---|---|---|
| snapshots | 477 retarget heights below 961,632; the snapshot at height h holds about h/961,631 of the 70.98 M entries, so the mean is about 35.5 M entries; at 57 bytes an entry | ~965 GB |
| per-block diffs | every creation and every spend is one touch; 0.9 G creations and their spends is about 1.8 G touches at ~50 bytes encoded | ~90 GB |
The snapshot term dominates and it is five times what a 10,000-block cadence would cost, because there are five times as many snapshots. That is the price of naming a set by retarget epoch, and it is a deliberate trade: epochs are what a client can talk about, and a diff chain of 2016 is the most it should ever have to apply. The 3.62 TB checkpoint total in the table below was derived for a 10,000-block cadence with one diff per range, not for this; it is left in place as the record of the earlier reasoning and must be replaced by a measurement at this cadence before any instance size is committed.
The older spacing table, kept for the reasoning about what a rebuild streams, not as the current design. A checkpoint at height H used to be one diff against the last boundary, with the boundaries at an arbitrary spacing. Derived from the writing: 975k blocks, 0.94G transactions, 0.9G unique outpoints created, 14.6 MB of block per height on average:
| step | checkpoints | diff record | rebuild volume per checkpoint | checkpoint total | CPU at 2.5M touched/s |
|---|---|---|---|---|---|
| 1,000 | 975 | ~62 MB | 36.76 GB | too large, discarded | ~25 min on 2 cores |
| 10,000 | 97 | ~62 MB | 37.37 GB | 3.62 TB | ~2 h on 2 cores |
| 100,000 | 9 | ~62 MB | 43.47 GB | 0.39 TB | ~1.3 h on 2 cores |
The diff size is not why the rebuild volume is what it is. Between checkpoints 1.5% of all outpoints are touched, but the touched records have to be merged against the complete set, and that merge is what streams tens of GB. At 2.5M touched entries/s a 10,000-block diff costs 245k touched against 70.6M set entries: 288 set entries for each touched one, so the set dominates. Spacing trades disk for CPU almost linearly: 10x the spacing is 10x the diff and 10x the RAM a rebuild needs.
Two tests, in two packages, both live:
| half | test | measured | at the pre-fork size |
|---|---|---|---|
| merge in memory | internal/utxo TestHavocProbe | 9.1 M entries/s, 636 MB/s | ~8 s on one core |
| merge from disk to disk, streaming | internal/utxo/store TestDiskMergeRate | 2.1 M entries/s, 118 MB/s on ext4 | ~35 s on one core |
The disk number is a 2-million-entry base and a 4,000-touch diff, merged by streaming the base once and the diff once. At 70.98 M entries and 0.98 M touches it is 2.1 M entries/s, which is 35 seconds per 10,000-block rebuild, not the ~2 h the first estimate put there. The estimate was wrong about what a rebuild is: nothing sorts the set, and the merge is a sequential read.
So the merge is not the reason the rebuild is unaffordable; the 37 GB of streamed state is. A rebuild is affordable when the set is a memory-mapped sorted file read at disk speed, ~600 MB/s on NVMe, rather than a Go slice built by the merge. That makes the canonical holder a machine with ~8 GB of RAM and a fast disk, and it makes a rebuild on any other instance a disk-streamed operation. The plan's "~2 h" figure stands for the on-disk case and is wrong for the in-memory one; phase 4's gate replaced it, and the two numbers above are what that gate measured. This section is the only place the numbers appear.
Checkpoints at height H need the canonical sets for all 98 heights before H. Computing a canonical and a per-chain layout at every 10,000 boundary means walking every pre-fork block: 975,000 blocks, 0.94 billion transactions, 900 million unique outpoints ever created, 0.56 TB of block bodies (derived). That is the "slow setup" that the HTTP seeding is for: the spine is built once, in that backfill phase, in the same pass that stores the blocks, and shipped as checkpoints.
The spine's own checkpoint bytes are one entry per touched outpoint, 900M of them: a 900 million-row table of 28 bytes is 25 GB. That cannot be shipped. Hence the second layer below.
A client that needs the canonical chain's UTXO set at an *arbitrary pre-fork height* that is not a spine checkpoint pays up to 37 GB from the last checkpoint. The canonical chain can serve it off its working set; nobody else can. So:
btc at a probed subset of heights, verified against the btc header, filtered and
hashed. A published fork of BTC's headers from height 961631 therefore costs
exactly the post-fork work, and the client's shared prefix carries it.
This is the one case the architecture is built for.
btc-reachable seedends at the shared prefix. Its pre-fork history has the same outpoints with different spent sets, so neither the canonical checkpoint offsets, the coinbase of the shared prefix, nor any diff computed on btc describes it. A new chain from pre-fork history needs: the raw blocks (part of them will be fetched from btc peers anyway), its own filters over them (the filter is a pure function of the block, so block availability is the bind), and its own UTXO spine (code path shares, 0.56 TB streamed, roughly a 12-24 h job). Coins that spend differently may be detected at the gap between the two spent-range layouts, never predicted cheaply. **Offering "BCH support" is one line of code and one month of downloads.**
The collapse below is what the storage claim above is counting. It was design when this section was written and it is the code now: the paragraph at the end of this subsection that said otherwise has been replaced with what was built.
The topology that the collapse conflicts with: a filler instance holds the canonical chain as a multi-file, per-connection ordered stream of raw blocks, and the checkpoint builder needs ordered whole blocks. For 97.4% of bodies there are two positions (btc and xbt) and one disk copy.
Prose was not enough last time, so here it is as a table:
| path | keyed by | why |
|---|---|---|
blocks/ | block hash | a body is a body. Two chains that both have block H hold one blob, and the hash is what identifies it |
blocks/index | block hash -> (segment, offset, length) | one lookup serves both positions |
headers/btc/, headers/xbt/ | height | heights diverge at the fork, and the header encoding differs (80 vs 164 bytes) |
filters/by-block/ | block hash | a filter is a function of the body, so both chains read the same filter record |
filters/<chain>/fh | height | filter headers fold over a chain's own sequence, so they are per chain |
utxo/canonical/ | height | one set for the shared prefix, both chains query it |
utxo/chain-<chain>/ | height | each chain pays for its own post-fork work |
utxo/diff/shared/ | (from, to) | one block's touches, written once for the prefix |
utxo/diff/<chain>/ | (from, to) | one block's touches, past the prefix |
blocks/staging/<chain>/ | (height, hash) | the fill's unverified log; nothing serves it |
blocks/missing/<chain>.log | dropped heights | what a processing pass refused |
The refs table an earlier draft of this section proposed is not needed. The
header store already maps (chain, height) -> hash; that is the ref index. A
body keyed by hash plus two per-chain header chains gives the collapse with no
second structure to keep consistent, and it means a block that both chains share
has one blob and two header records, which is what the numbers were always
counting.
What was built, in the order it landed (docs/CONSOLIDATION_PLAN.md has the
phases and gates, docs/STATUS.md the evidence):
internal/store's block store has no network field and no height: a body is filed under the hash it commits to, and headers/<chain> is the only place a
height means anything. TestOneStoreTwoChains measures the collapse: 21
shared heights plus one chain's own block are 22 bodies.
blocks/staging/<chain>, and hashes nothing; internal/process is the pass that checks them and files them.
filters/by-block, and served as the flt chunk kind. The filter-header
fold is per chain, in that chain's header store.
One deviation from the table above: utxo/<chain>/spent does not exist. The
served artifact is the snapshot and the per-block diffs, and a per-chain spent
index would answer "spent at which height" without a scan. It is the index
question named at the end of this section and it is still open.
The fill does two kinds of work at once today: it pulls bytes over the network and it hashes each block, writes an index record and a tail record before the next request goes out. The network waits on the disk, and a slow hash is a slow download.
Split it. The pipeline has two phases with one artifact between them.
Phase 1, sync. Dial, take the header chain, then ask for bodies by hash in
whatever order peers serve them. Append each body to a staging log with a side
length frame and a sidecar of (height, hash) claims. **No hashing, no index, no
chain semantics.** The header chain is still fetched here because it is the only
way to know what to ask for, and at 80 bytes a block it is 1% of the traffic.
Phase 2, process. After the download reaches its target, walk the staging log once: hash each body, check it against the header chain's hash at its height, write the hash-keyed index, and feed the block to the UTXO builder, which builds that block's filter on the same walk because it is the pass that holds the scripts a filter needs. A body that does not hash to what was asked for is dropped and its height goes back on the request list; the next sync re-fetches it.
This is not a trust hole, and it must be stated that way: during phase 1 the bytes are untrusted and nothing serves from them. The store that answers queries is the processed one. The deferral buys three things:
line rate;
is a portable artifact, so a thin-pipe host can pull and a big machine can process, which composes with the seeding path in the next section;
filter, two header chains verifying it.
The cost the split adds is a second read of every body, 570 GB at the full pre-fork size, once. That is the price of not doing random writes during the download, and it is the trade the rebuild numbers above already argue for: a sequential second pass at disk speed is cheaper than making the network wait.
Gate: measure phase 1 bytes per second with hashing removed from the loop, and
assert that a shared height asked for as btc and as xbt resolves to one blob
and one filter.
What was built: the split is internal/staging and internal/process, with
-process-after-fill and -process-only on the instance. The gates are
TestStagingIsNotServed (21 bodies staged, zero served) and
TestProcessIsSeparate (a corrupt body dropped and its height recorded). The
throughput measurement the gate asks for has not been made: nobody has run the
fill over a real 570 GB prefix, so the claim that the download runs at line rate
is still an argument rather than a number, and STATUS.md does not make it.
The filter build needs the scriptPubKey of every output a block spends, and a canonical entry does not carry one: 57 bytes hold the outpoint, value, height, flags and an 8-byte script hash. The walk therefore keeps the scripts in memory beside the set, and that is what makes the build impossible on a small host:
| term | derivation | size |
|---|---|---|
| the set | 70.98 M entries at 57 bytes | 4.05 GB |
| the scripts | 70.98 M outpoints plus a script per entry, in a Go map | about 10 to 14 GB |
A 5 GiB VPS cannot do either half. Neither number is a property of the problem; both are properties of holding the set in memory.
The design that removes the memory bound. The script belongs in the set, and the set belongs on disk. Two shapes are possible and the second is better:
[outpoint 36][len u16][script]sorted by outpoint, written beside each snapshot.
Either way the builder stops holding a set. It walks an epoch at a time: read the snapshot at the epoch's start, stream it through a merge against the epoch's per-block diffs, and write the next snapshot while emitting each block's filter at that block's boundary. The join that produces a filter is two sorted streams: the base entries (sorted by outpoint) and the epoch's spends (sorted by outpoint, each carrying the height that spent it), so a spent entry's script is handed to the block that spent it as it passes. Memory is one epoch's touch list, about 250 MB at 2016 blocks and 2,500 touches each, plus IO buffers. The whole chain never exists in memory at one height.
What it costs. The scripts are about 7 GB on top of 16.7 GB of entries, so a snapshot grows by roughly 40 percent: the derived snapshot total moves from about 965 GB to about 1.4 TB. With 600 GB of bodies, 90 GB of diffs and 120 GB of filters, a full dataset lands near 2.2 TB, which is what a 3 TB box is for.
What it changes. On the entry-in-set shape: utxo.Entry gains the script,
Encode and Decode become variable width, utxo/store stops assuming 57-byte
records, the diff's creations carry the script, fetch stops checking a set's
length against a fixed width, and utxobuild is replaced by the epoch merge.
On the parallel-table shape: none of that, plus a new store and the same epoch
merge.
The stopgap, and its limits. Filters are committed by the block header chain
through the filter-header fold, so an instance does not have to compute them: it
can sync filter headers and filter bodies from a peer and verify every filter
against the fold, which is what neutrino's SyncFilters already does. That works
on any host, in bounded memory, and a node cannot forge a filter that passes.
What it costs is independence: an instance that syncs filters needs a peer that
kept the filter index, which is -blockfilterindex=1 on Core and not universal
(the eight peers this instance uses on the VPS do not advertise the service bit).
| class | what it holds | disk (derived) | what it does |
|---|---|---|---|
| A: canonical | both chains' blocks, both headers, snapshots at every retarget, one diff per block, filters | bodies ~571 GB, filters ~120 GB, snapshots ~965 GB, per-block diffs ~90 GB, indexes ~40 GB, all derived and none measured at full size | p2p fill or ftool fill, filter build, checkpoint build, serve everything, relay |
| B: mirror | every block it pulled, optional UTXO spine (default off) | bodies ~571 GB, filters optional | p2p fill or ftool fill from A, serve blocks, headers, filters, relay |
| C: client | headers, filter headers, filters it needs | tens of GB | fill from A, fetch from A, no UTXO, no blocks |
Storage VPS instances run as a hybrid: A at the tip if they can hold ~1 TB, otherwise a mirror; the canonical holder is the machine with the disk, and the compute per new block is the constant post-fork work.
headers and Bitcoin's difficulty rule on both chains. The filler treats those eight heights as tip-like: a reorg there is handled by the tip path, not the spine, because they are the newest heights the two chains write identically. The spine builder records which pre-fork blocks it saw orphaned and excludes them.
a p2p downloader sees a reorg when a peer announces a competing header, so the depth is bounded by the peer that announces it, and a node that was disconnected during the reorg cannot find it below its stored tip until the next header it sees forks. The prune rule is therefore "orphans below tip-6 are deleted; orphans above tip-6 are kept and matched against new headers". The last 6 blocks' filters are recomputed, not reused.
The service relays transactions that clients have signed. It holds no keys, signs nothing, and keeps no wallet. Its job is to get a client's bytes onto the right network and to tell the client the truth about what it knows of them.
A mempool is a set of unconfirmed transactions for block construction. This service builds no templates, replaces no policy, and needs none of it. It needs four things around a client transaction:
POST /v1/chains/{chain}/tx): parse, sanity-check, accept intoa bounded relay window.
tx to a set of full node peers and to the chain's ownlanes.
inputs, and what its own served chain says about them since (announced,
seen, spent). In memory,
bounded, default 128 MiB, evicted oldest-first.
GET /v1/chains/{chain}/tx/{txid} answers it.
still in the window, re-announce every 30 to 60 minutes with jitter. That is the part that matters for swaps: a transaction relayed once and not mined within an hour is usually a transaction that no peer kept.
What is cheap and enough: the transaction parses as a transaction, its inputs are not already spent according to the UTXO sets the instance holds (where it holds them, see below), its txid is not already in the window, and its serialized size is under the payload cap. A body that fails these is refused with the reason. A body that passes is relayed.
What is not checked: script execution, fee policy, standardness, sigops, finality. A full node that receives the tx decides those. The response carries that distinction in one word:
200 {"txid": "...", "state": "relayed"}
422 {"error": "input spent", "txid": "...", "outpoint": "..."}
relayed means: this instance checked what it can check without a mempool, and
the bytes are on their way to peers that will decide the rest. It does not mean
accepted by the network.
A swap is two transactions, one on each chain, and the failure that costs money is a relayed spend against coins that are already spent on the chain where the client is trying to spend them. In a minute-scale HTLC both parties act against the same outpoint, so spent is the state the second submission is most likely to be in, and the service is the one party that can see it before the second signature is broadcast. The check is therefore worth having wherever the store exists:
depends_on) in the request.or unknown, on both chains when both are served.
client's stated anchor, the request is refused and the offending outpoint is named. The client learns about its broken swap before it broadcasts a claim instead of after.
The check needs the canonical store, so it exists only on instances of class A.
A relay-only VPS answers unknown for those outpoints. It relays without the
check, and the client sees that it did.
Neither chain's node accepts a transaction that spends a coin only the other chain has, or one signed under the other chain's rule: SIGHASH_UNIFIED is what makes an XBT spend invalid on Bitcoin, so replay is the swap's own concern and the service does not try to enforce it. What the service does enforce is that a request names exactly one chain. A client that needs both legs sends two requests. Nothing is accepted for one chain and relayed to the other.
The instance announces a client's txid to its full-node peers with inv, which
is a hint and not a submission. A peer that wants the transaction asks for it
with getdata, and only then does the instance send the bytes. This keeps
every peer's answer traceable to a request. It is an announce-and-serve loop
the instance has to own: neutrino's Broadcast sends a bare tx on a
connection it only ever reads for replies to its own requests, and
p2p.Conn.ReadUntil drops every frame that is not the command it is waiting
for, so a getdata aimed back at the connection would be consumed and
dropped. Relay peers get their own connection, their own reader and their own
queue. The block lanes are not touched.
Two limits on that trust, both facts about the protocol:
its own mempool, or ignores them, and says nothing either way. The window records "announced", not "accepted".
failure.** A rebroadcast is idempotent from the network's point of view.
The one assertion the service can make from inside is the one it owns, and it is weaker than it reads. A BIP158 basic filter is built from script pubkeys, not outpoints, and does not contain the txid, so no filter can answer "is my tx in this block". What the filter does commit to is the scripts each block touches. So for a relayed tx whose inputs the instance can resolve:
script of the tx. It is evidence, not proof: a script is not unique and the block may hold someone else's payment to it.
set recording the funded outpoints as spent at that height. Where the store
exists, that is the exact answer; where it does not, the window stops at
seen.
Filter verification is the same as everywhere else: the filter hash against the filter header, the filter header against the header chain.
Relay peers are full nodes with NODE_NETWORK on the same chain, a separate
pool from the block-fetch lanes so a slow relay peer cannot hold a block lane.
Each instance carries a small list of relay peers in config and dials them
once, holding two to four connections. A peer that drops a connection is
retried with backoff and scored the same way block lanes are.
This is a change of posture, and it costs something. The block lanes only read from peers that have agreed to serve them. A relay node publishes a client's transaction to strangers by design. That is the service, not a side effect, and it belongs in the documentation the operator reads before turning it on. The instance relays for any client that reaches it; there is no allowlist by identity, because there is no identity to allow.
The ftool fill path does not relay. It copies records and nothing else.
Every artifact is content-addressed by double SHA-256 of its bytes. The manifest chain is signed and pinned by hash in the profile, or, failing that, accepted on first use with the hash recorded. Kinds:
| kind | content | byte budget | in internal/chunk |
|---|---|---|---|
hdrs | 10k headers for one chain, raw | 1.64 MB (xbt fork range) | yes |
fh | 10k filter hashes and filter headers | 640 KB | yes |
flt | contiguous filters, byte-budgeted | 512 KiB | yes |
blk | 100 blocks of one chain, in height order | 256 MiB | yes |
utxo.diff | one diff record | 32 MiB | yes |
utxo.base | a canonical full set | 128 MiB | yes |
utxo.known | the known set for a branch range | 64 MiB | yes, unused so far |
utxo.branch | the per-chain (touch, created, consumed) range for 10k heights | 64 MiB | no |
utxo.cp | a canonical checkpoint | 128 MiB | no |
The last two are design entries that never became kinds: the checkpoint chain is
served as sets and diffs by internal/utxo/serve, and there is no branch mode.
docs/ARCHITECTURE.md lists the kinds the code defines.
Chunks tile their ranges with no gap and no repeat. A range is [from, to), and
the chunker is deterministic so the same range from two instances produces the
same boundaries and the same hashes. The client asks for a range and gets
the chunk names to fetch; one HTTP range request per chunk, Range-resumable.
The routes the code registers, and the ones this document names that the code
does not, are listed in docs/ARCHITECTURE.md, "The HTTP contract". They are
not repeated here; this section is the reasoning about them.
/utxo/query answers spent-and-unspent correctly for any pre-fork height from
the canonical store, which is the thing a light client cannot do from filters
alone and the reason this service exists at all. /tx is the relay: it checks
what it can check, relays the bytes, and reports the window's state of that
txid. Everything else is read-only.
Every write endpoint is rate-limited per source address and bounded in body size. An instance that relays is a node someone can spam; the bound is the answer, not an allowlist.
The instance takes far more from the network than it gives: it pulls 570 GB of bodies and serves whatever a client asks for. Long-lived peers deprioritise a peer that never serves, and a metered host does not want an open-ended bill, so egress is budgeted rather than unlimited.
-upload-bytes-per-day, default 1 GiB. It is a byte budget, not a rate: a
day's worth can leave in five minutes if a client asks for it, and when the
budget is spent the instance serves nothing more until the window rolls over.
What it covers and what it does not:
| path | counted | why |
|---|---|---|
GET /v1/chunks/*, /v1/chains/*/{kind}/*, /v1/utxo/* | yes | the bulk of egress, and the path a seeding client pulls |
| p2p messages to relay peers and full nodes | yes | version, inv, tx, headers, getdata answers |
GET /v1/status, /v1/manifest, /v1/utxo/checkpoints | no | a few hundred bytes of metadata; refusing them makes the instance look dead |
POST responses | no | a submit's answer is its input's size |
The counter is wall-clock hours in UTC, persisted beside the data directory so a
restart does not reset the budget, and it is reported in /v1/status as bytes
used and bytes left, so an operator can see the window rather than discover it.
Above the budget the answer is 429 with the reset time, and on p2p the instance
stops answering getdata and keeps its connections: a peer that reads a busy
node is not a peer a node bans.
Whether this costs download throughput is a real question and it is not settled
by assertion. Bitcoin Core does not gate block service on a peer's upload, so the
budget is not expected to slow the fill; it is there for reciprocity and for the
metered host. Gate: fill from a node with the budget spent and assert the fill
completes, then assert the budget refuses a chunk request with 429.
ftool syncftool sync -from URL -to-dir <dir> -chains btc,xbt fills a new instance. What
it does, per chain, in this order:
/v1/status, the signed manifests for every kind inthe chain's coverage, and the chunk lists. Every chunk hash is checked at fetch time and again at apply time.
validateHeader)against the previous header, so a serving instance is a peer that cannot forge a header. It uses a proof-of-work anchor from the manifest.
0..961631 are fetched for btc only unless the local store already has them;
the local store's refs gives the shared height its xbt record without
a second body.
the filter-header chain that step 2 built. A filter that does not verify is re-fetched from the range, not accepted.
the base set and every diff in order, verifying each boundary's name
(internal/fetch's UTXO, ftool utxo).
A repeat of the same chunk is a no-op.
The time is the export's disk read plus the client's verification; for 570 GB
at 100 MB/s that is about 1.6 hours on the served side plus the verify. Derived,
to be measured on gate 5 with the rig as the export. The flt and utxo.*
kinds are smaller by an order of magnitude and are the fast path for class C.
A client that fetches filters from the service has the same trust position as
with nostrino's filter source: a filter hash is committed by the filter header,
which is committed by the header chain it verified. The service can withhold
and cannot forge. SourceOnly in neutrino refuses a miss rather than falling
back to the peer; btcd-lite's HTTP client uses FilterSource with the service
as the only source for class C instances.
A canonical store is the set of entries (outpoint, value, script_hash), sorted
by outpoint bytes, in chunks. Each chunk is 128 MiB, sorted, three-tiered
(the last 32 entries, the middle page, the first 128 entries of every page,
as Core's hash mode), and served by binary search over a header loaded once
(amounts per chunk: entries, bytes, midhash, pps). Bitcoin Core's hash mode
is 110 bytes/entry: 8 (txid) + 4 (vout) + 8 (value) + a fractional script hash
(4-16 bytes). At 70M pre-fork outputs, the canonical set is about 7.7 GB.
The chain stores:
canonical/{H}/base and a known set canonical/{H}/known (bitvector for created/heights, core-chain checklist,
counts): the gossip and checkpoint formats are the same set of records.
canonical/{a}/{b} is sorted by outpoint and carries `(outpoint, height, kind, offset). Applying it to canonical/{a}` needs a writable copy
of base only for the written runs, plus a position vector that maps a
canonical offset to a linear one, so a diff applies without a binary-search
walk. The anchor instance validates the result by recomputing the 32-byte
tip hash given by the diff record (kind 9).
(touch, created, consumed) sorted trim lists, merged by hands. For branches the (branch, hash) form is a file
on disk, so 4 GB of branch for one chain can be held offline.
outpoint (36B) | height (4B) | kind (1B) | offset (4B) | script_hash (var)
kind is created, spent, or (for the known set) neither. The off-by-one record
is 22 bytes without the script hash. The known set for a branch range is the
serialized bitvector pair, not a key set, because a light client wants a yes/no
answer, not 33M keys.
The client asks for two things: whether an outpoint is unspent at height H, and the filters in a range. The first is answered from the canonical branch for the shared prefix, from the chain's own branch after the fork.
A checkpoint is served as its component chunks (base, known), and a diff as
one artifact. The canonical holder is the only instance that answers a spent-at-arbitrary-
height question for the shared prefix; everything else answers it at checkpoint
heights, or by a copy of the canonical store it was given. A mirror that holds
checkpoints and diffs can hand a client the lower checkpoint and the diffs for
the boundaries in between, but the client is the one that assembles them, and
the 37 GB per boundary is paid by whoever assembles. The service's job is to
hand over records, not to run a client's set for it.
There is no partial export. A client is given coverage: start_height,
start_block_hash and start_filter_header, all three signed in the manifest.
A chunk below start_height does not exist, and a request for one is refused
with the coverage, not served from something the instance happens to hold.
After the spine exists, a new block costs: header verify (microseconds), block parse (~0.3 ms/block, 965 tx/block), filter build (~2.5 ms at 40 KiB/block), filter hash and header fold, canonical UTXO diff at the 10,000 boundary or the next checkpoint gap (the working set of a 10k block is at most a few hundred MB of touched outpoints, no set stream), and the diff append. Derived, to be measured by gate 6. The steady-state cost is one block parse and one filter build per chain per block, which is a second or less per block on one core: the storage VPS does not have to be a fast machine for the tip.
What is copied, and from where:
v0.24.2 (wire/msgblock.go, wire/msgtx.go, wire/blockheader.go, wire/common.go), cut to the parse path and nothing
else. Bitcoin's objections to a body stay: more than 1 MB, a txid that does
not find the merkle root, a coinbase that does not have one input with a null
outpoint, a block number in the coinbase that disagrees with the height. What
goes is everything after the body is accepted as bytes: script checks,
sigop counts and policy. XBT's txcount in a v2 header is a miner-supplied
count and may not match the body; it is not used to size a read and a
disagreement is a warning, not a refusal.
pkg/filter (BIP158, vectors included)unless the instance needs a second copy to avoid the module; the module is a single dependency.
pow.go and import.go, notcopied: imported as the module so there is one implementation of the XBT header rule, which is the rule most likely to drift.
Truncate and SyncHeaders semantics, notcopied, for the same reason.
Do not copy: btcd's blockchain (validation), the database layer (bbolt
is not a reason to run a database here), the indexers, the mempool and
blockManager's relay logic. The outpoint store and checkpoint code is new,
because its layout is new. The relay loop is new and small; it is not btcd's
peer manager, and it does not need to be.
Licences: btcd is ISC and nostrino is the repository's own terms; both go in
NOTICE with the exact files copied and no modification history invented.
The phases this built were: source audit, wire and filter, the block and header
stores, the filler, the checkpoint build, the checkpoint service, and the relay.
Then the consolidation's six: the chain-neutral body store, per-chain headers
and a multi-chain view, headers served out of bodies, filters keyed by block,
retarget snapshots with one diff per block, and the sync/process split. They are
done; the evidence per phase is docs/STATUS.md, and
docs/CONSOLIDATION_PLAN.md's "Where this landed" records where the built thing
differs from the plan.
linkage, refuses a body whose txids do not find its header's merkle root, and builds filters, which are a function of the body and need no script evaluation. Beyond that it stores bytes.
holding the snapshot at or below H and applying the diffs, or scanning an
epoch's worth of them. The ordered (outpoint, height) index that would make
it cheap is the open question at the end of this document, not a promise.
makes a drop for them: the post-checkpoint filters of both chains at the tip.
signature the service makes is the manifest's, whose key is a hash in the client's config.
tx the network took, and the response says so.
total is derived from the 2026 filter-size survey, which samples at 20-block steps and is already bandwidth-aware; what gate 3 adds is the sum over every stored block rather than a sample.
enter the filter: gate 1 answers both against the node. Without a node, the XBT filter stays unverified and the service cannot claim to serve it.
to be validated against the network, not the box.
how long. The window holds bytes for the re-relay window only and the client keeps its own copy; a client that wants a third-party store of its signed tx is asking for something else and it is not in this design.
checkpoint at a height the service is also holding as a diff, i.e. whether the checkpoint+diff pair can be served as one artifact to cut the client's fetch count. This is a client decision, not a storage one.