# Status The record of where execution stands. **This file is the single source of truth for status**; `docs/ARCHITECTURE.md` is the single source of truth for what the components are, and `docs/PLAN.md` for the design and the budget arithmetic. Where this file and either of those disagree, this file wins for status and the other is a bug. Measured at `main`, `go test ./...` green in all thirty packages of the module, with the two-chain rig up for the tests that dial it. ## Built and tested | piece | where | what the tests prove | |---|---|---| | block and transaction parse | `internal/wire` | the ten official BIP158 vector blocks decode, hash to their own hashes and their merkle roots match; segwit transactions re-serialize to the same txid; a truncated block, a trailing byte and a block-as-transaction are all refused | | fork headers | `internal/wire` | 24 harvested XBT version 2 headers link, hash by the fork construction, state their own heights and pass proof of work; a block with a fork header is read at the 164-byte offset | | BIP158 filter | `internal/filter` | all ten official vectors rebuild byte for byte; the filter hash and the header fold are what BIP157 says | | blob store | `internal/store` | bytes are filed under a 32-byte key, verified against it on write and again at open; a reopen verifies every record; a torn append is dropped and the next append lands at the last good record; a directory in an older record format is refused with its version named | | block store | `internal/store` | it is a blob store keyed by block hash and it knows nothing about chains or heights: the fork's 164-byte bodies hash by the fork construction, a body that does not commit to its name is refused, and two chains' bodies coexist in one directory | | header store | `internal/store` | it is a full neutrino `Store`: anchor, contiguous headers, filter headers and hashes folded per chain, filters checked against their hash, `Truncate` for a reorg, all of it surviving a reopen; header records are variable width, so a fork header is stored and read back at 164 bytes; and a chain whose filters this instance builds itself keeps its fold dense from height 0 | | UTXO kernel | `internal/utxo` | a chain walk one block at a time; a range applied to a checkpoint equals the same blocks applied one at a time at every split tried; diff encode/decode round trips, carries each creation's own height, and refuses a truncated one; a spend or a creation of something absent is refused; an output created and spent inside one block is net zero; one outpoint order for the merge, the set and the key files | | chain profiles | `internal/chains` | the two profiles load and their fork constants agree with the harvested fixture; regtest carries the network magic the node on this machine accepts; the coinbase maturity rule is per chain and the fork's long-maturity window is checked at every boundary against the numbers in its own chainparams | | node parity | `internal/gate` | run against a node: every regtest block's filter bytes match `getblockfilter`, every sampled header hashes to the node's, and a rebuild of the node's whole chain agrees | | chunker | `internal/chunk` | the same range cuts to the same boundaries and names twice; a byte budget, not a count, cuts filters; the chunks tile the range with no gap | | service contract | `internal/service`, `internal/serve` | a range names its chunks, each name serves bytes that hash to that name, a range past the coverage and a chunk nobody filed are refused; a view that holds no filters refuses a filter range rather than serving an empty one | | seeding A to B | `internal/gate` | a store filled from a node's bytes is served over the service contract, and a second store seeded from it by chunk name holds the node's bytes | | manifest | `internal/manifest` | a signed manifest verifies against the pinned key, one changed byte in a chunk name, range, coverage or instance fails it, and runs added in either order encode to the same canonical bytes | | one store, two chains | `internal/gate`, `internal/serve` | two chains over one body store: 21 shared heights plus one chain's own block are 22 bodies, not 42; height 10 resolves to the same hash through both header stores; a reopen finds the same store and both tips; and a block chunk for a shared range is the same chunk whichever chain asked | | multi-chain view | `internal/serve` | one view holds any number of chains over one body store; a chain it does not hold is refused naming the ones it has; a version 2 header is served at 164 bytes from the body and hashes by the fork construction | | two chains, one process | `internal/gate` | `btcd-lited -chains btc,xbt` fills from two nodes, reports both chains and their own tips, stores the shared prefix once, and serves `blk/0-6` as one chunk for both | | staging log | `internal/staging` | appended bodies and claims come back in order; a torn claim is dropped and the file is cut to the good records; a claim whose body never finished is dropped and the segment cut back; a drained log reopens empty | | sync, then process | `internal/gate`, `internal/process` | a fill writes the staging log and the instance serves zero blocks: a block range is refused, and `claims.dat` holds one claim per height; `-process-only` needs no peer, stores the bodies, drains the log, and drops a body whose header byte was corrupted, recording its height in `blocks/missing/btc.log`; every stored block is the node's bytes | | UTXO checkpoints on disk | `internal/utxo/store` | a set named by double SHA-256 of its entries; a diff applied by streaming the base and the diff once; the streaming merge reproduces the replay's set name at every boundary of a chain walk; and a client with only the base and the diffs reaches every boundary under the name the chain recorded | | snapshot cadence | `internal/gate` | a 301-height regtest chain built at the 144-block retarget has snapshots at 0, 144 and 288 and at no other height; 301 filters are byte-identical to the node's; and the filter-header fold reaches the tip with every record committing to its filter's hash | | snapshot names | `internal/utxo/store`, `internal/utxo/serve` | a snapshot's name is recorded beside it when it is written, so a manifest costs one small file rather than a read of the whole dataset; a set file edited behind that index is still refused when it is served | | a resumed walk's filters | `internal/utxobuild` | a walk that starts above height 0 filters spends of outputs created before it started, from the scripts the earlier walk hands it, and its filters are byte-identical to one walk over the whole chain | | client at any height | `internal/gate`, `internal/utxo/serve` | a client fetches three snapshots, reproduces the builder's name at each, and applying the run from 144 to 200 gives the builder's name at 200; a run that crosses a snapshot is refused and one that ends on it is served; a proxy that corrupts a diff's entry stops the client at the next boundary | | streamed set build | `internal/utxobuild`, `internal/utxo/store`, `internal/gate` | the dataset built without the set in memory: 301 blocks in three epochs, and every snapshot file and every per-block diff byte-identical to the replay's; a fork chain continues from the shared snapshot where it was written, so the prefix's largest file is not copied | | filters without a set | `cmd/btcd-lite-serve`, `internal/gate` | `-filters-only` builds every chain's filters from bodies and serves them with no UTXO set built at all: 21 filters computed, then fetched as `flt` chunks and compared byte for byte to `getblockfilter` | | filter build | `internal/filterbuild`, `internal/gate` | 301 filters computed from the bodies alone, every byte and every fold record identical to the node's, including a spend whose input was created in an earlier epoch; the scripts come from a sorted file that is streamed, and the set is never in memory | | filter sync | `internal/filtersync`, `internal/gate` | a filter chain fetched from a node, every filter byte-identical to `getblockfilter` and every fold record identical to the node's filter header; the request needs a stop hash that names a block, and a node that does not advertise `NODE_COMPACT_FILTERS` refuses the request and drops the connection | | filters built and shared | `internal/filterstore`, `internal/serve` | a filter is keyed by its block's hash, so the same range of two chains over the same blocks cuts to one chunk and serves one set of bytes; the chunk is filters length-prefixed in height order | | shared prefix walked once | `internal/utxobuild`, `internal/gate` | the prefix is walked once and each chain continues from the set it ended with: two chains of 301 heights read 101 prefix bodies and 200 each, and the second chain writes no copy of the prefix's base | | checkpoint service | `internal/utxo/serve` | the manifest names every snapshot and its set's hash; a snapshot is served with its name and a height between two is refused naming the one below; a client that fetches the set and the diffs over HTTP reaches every boundary | | no script replay | everywhere | nothing executes a script: the gates that build a UTXO set do it from blocks whose headers were verified and whose bodies hash to their keys, which is what the plan commits to. There is no script interpreter in the tree to leave out | | relay | `internal/relay` | the window is bounded by bytes and evicts oldest first; admission parses the transaction and refuses a dependency the instance's set has as spent, naming the outpoint; a relayed txid is answered with `announced`, never with a claim of acceptance; a peer that asks with getdata gets exactly the bytes; settlement reads the instance's own verified filter chain; rebroadcast repeats unconfirmed entries; two chains relay from one mux with the chain segment as the dispatch | | relay transport | `internal/relay`, `internal/v2peer` | the relay negotiates BIP324 through the same transport the instance syncs over, so it can talk to a node with v1 off | | sources for a neutrino client | `internal/serve` | the view supplies headers by height window and blocks by hash through its own header chain, so a client can fill from an instance where a peer is slow | | the instance | `cmd/btcd-lited` | `internal/gate` starts it against a node of each chain: it dials, syncs headers, fills bodies into the staging log, processes them, then serves | | the serve command | `cmd/btcd-lite-serve` | `internal/gate` fills an instance from a node, starts this, and a client fetches the checkpoint chain over HTTP with every boundary matching, beside the filters that are the node's | | the broadcast path | `cmd/btcd-lited`, `internal/relay` | `TestRelayAnnouncesToTheNode`: a signed transaction the node has never seen is submitted over HTTP, announced to one peer, and the node's mempool holds it afterwards | | p2p diagnosis | `internal/v2peer`, `internal/litedial`, `internal/filler` | a connection logs what it negotiated, what the peer claims to serve and what height it claims before it is asked for anything; the header sync reports every 100,000 headers with a rate and a height it stopped at; the fill reports on a timer with count, percentage, rate and estimate, so a stall shows as a static count and `eta never`; and the end of a connection says whether the instance or the peer closed it | | logging | `internal/logging`, both server commands | a line below the level is not written and a line at it is, with its level in front; a success is a debug line, a 4xx a warning, a 5xx an error and a slow success an info line; the refused response's own text is carried in the line; the counters add up to what left the process; a file destination keeps appending after a rotation | | the commands | `cmd/ftool`, `cmd/btcd-lite-serve` | `ftool keygen` makes a key, `btcd-lite-serve` serves a dataset with a signed manifest, and `ftool sync -key` fills a second instance from it; the gate runs both binaries and compares every block to the node's | ## Running the tests ```bash go test ./... # everything ``` `internal/gate` starts its own nodes on free ports, one per test, and stops them when the test ends. It looks for `bitcoind` on `PATH` and then at `/home/mleku/s/bitcoin-core/bin/bitcoind`; the fork's gate uses the fork's own build at `/home/mleku/s/bitcoin-knots/bin/`. A gate skips only when there is no node to start. Two groups dial a node that must already be running at `127.0.0.1:18444` (or `BTCD_LITE_P2P_TEST`): `internal/v2peer`'s four node tests and `internal/gate`'s `TestInstanceHandshakeWithTheNode`. They fail rather than skip when nothing is listening, because a handshake that never happened is the claim they exist to make. Start the two-chain rig first: ```bash /home/mleku/s/gjbrr/blake-swap/scripts/test-nodes start ``` ## Fill rate One block request is in flight per peer, so the wall clock is round-trip bound: on a 984,346-block chain, one peer costs 5.5 hours at 20 ms RTT and 27 hours at 100 ms, and the rate scales with peers. Measured on loopback against the rig's node, 3,106 blocks in 459-513 ms with one worker (6,100-6,800 blocks/s, bodies of about 250 bytes) and the same with four, because loopback's round trip is not the limit there. No WAN measurement has been made, and the bandwidth bound on a real prefix (about 600 GB) is 13 hours at 100 Mbps. ## Data directory ``` / blocks/ .blk .bidx tail.dat format bodies by hash, one store, both chains staging// unverified fills, claims, never served missing/.log heights a processing pass dropped headers/ btc/ xbt/ one header store per chain filters/ by-block/ filters by block hash, both chains utxo/ canonical/ chain-/ snapshots, shared prefix and per chain canonical/index, chain-/index each snapshot's height and name diff/shared/ diff// one diff per block built.json how far the dataset covers per chain ``` ## Not built Stated as gaps, not as workarounds. This is the only list of them; the architecture document names only the structural absences and points here. - **No egress budget.** The design is in `docs/PLAN.md`, "Egress: an upload budget": `-upload-bytes-per-day`, default 1 GiB, counted across the HTTP chunk paths and p2p, persisted, reported in status, answered with `429` when spent. None of it exists: the service counts nothing and limits nothing but a submit's body size. - **Following the tip.** The fill and the dataset build are one pass at startup. A node that mines after the instance starts is not seen until the next start, and the UTXO dataset's `built.json` makes the next start skip a dataset it thinks is complete until `-rebuild-utxo` is passed. - **Incremental dataset builds.** A dataset that is short of the tip is rebuilt from the first snapshot the code can trust, which is height 0. The walk is resumable (`utxobuild.Config.Start` and `From`) but no caller resumes it: the command either finds `built.json` current or rebuilds. - **The memory-ceiling gate for the filter build.** The build streams an epoch at a time and is tested for byte-equality against a node, but nothing yet builds a chain under a memory limit that would kill the old in-memory path. That is the half of phase 7's gate that proves the bound moved rather than the arithmetic changing. - **No branch mode for the UTXO set.** The set is canonical and linear: a diff applies to one base at one height. The plan draft's `utxo.branch` and `utxo.cp` kinds were never built and are not in `internal/chunk`. - **Rate limiting on the write endpoints.** `MaxBody` bounds a submit's body; there is no per-address limiter, which the plan promises. - **The canonical store as a memory-mapped sorted file.** The plan's rebuild argument assumes one; the implementation streams files and holds the set in memory while building. - **`ftool sync` for the header store.** It fills bodies only. - **A test for the relay against an in-process peer.** It cannot exist until the btcd transport defect below is fixed. The relay is covered by `TestRelayAnnouncesToTheNode` against a real node instead, and `internal/relay`'s old v1 fixture is kept as a documented, unrun function. - **The alliance network.** The fork's headers and filters over p2p against a fork node are covered by `TestDaemonFillsFromTheForkNode`; the block sequence behind the real XBT fork is not in this repository, so the post-fork path is exercised on regtest only, with the 164-byte header fixture standing in for a fork block. - **Filter memory at mainnet scale.** The filter build keeps the scriptPubKey of every unspent output in memory while it walks, which is what a BIP158 filter needs and what the block does not carry. At the derived UTXO counts that is several gigabytes on top of the set itself. It is measured for a 301-block chain and not for a mainnet one; the number is on the list of things a real run would establish, not estimated here. ## Known defect in a dependency btcd's `v2transport`, as pinned, drops a peer's first packet when that packet is already buffered as `CompleteHandshake` returns: the terminator scan reads past the terminator and discards the rest. Measured with byte counts at the socket in `docs/upstream/v2transport-garbage-terminator.md`. It does not fire against a node; it fires between two btcd peers on loopback. Nothing in this repository depends on it, because the only in-process peers were test fixtures and the relay is tested against a node. ## Corrections to earlier status These were wrong in earlier versions of this file and of `README.md`, and are recorded so the same claims are not made again. - "The p2p fill is blocked on a handshake no node completes" - it was the instance's regtest network magic. Fixed; the fill works against both nodes. - "The canonical store on disk (phase 4) is not built" - it is: `internal/utxo/store` writes sets and diffs, `internal/utxobuild` builds the chain, `internal/utxo/serve` publishes it. - "The relay is not a running service" - it is: `btcd-lited -relay` wires it to a peer list, and the gate measures a transaction through it to a node's mempool. - "The gate's filter check does not compare the node's `getblockfilter` header field" - it compares filter bytes and the node's filter hashes, which is the independent check that matters; the `header` field is not the filter hash on a regtest node and is not used. - "Nothing builds filters" - it did not, and now it does: the UTXO walk builds one per block and the fold is written into each chain's header store. The correction is here because the earlier gap was quoted in the plan. - "A filter build belongs in the processing pass" - it does not. The pass sees one block at a time and a filter needs the scriptPubKey of outputs spent by later blocks, so the build is in the UTXO walk, which is the only place that holds them. That is a correction to `docs/CONSOLIDATION_PLAN.md`'s phase 4, made there.