git clone https://git.smesh.lol/btcd-lite.git
Chain data for the BTC/XBT swap: one pull of blocks from both peer-to-peer networks, shared history stored once, compact filters generated locally, a UTXO set collapsed to checkpoints that serve diffs, and an HTTP service that lets a second instance fill from the first in hours instead of weeks. It also relays the transactions the swap's clients sign.
Status: implemented and run against live nodes on both chains. go test ./...
is green with the two-chain rig up; docs/STATUS.md records what
each test proves, what is still missing, and which figures are derived rather
than measured.
| document | it is the source of truth for |
|---|---|
| docs/ARCHITECTURE.md | what the system is made of: processes, packages, boundaries, endpoints, what is not built |
| docs/STATUS.md | status: what is built, what its tests prove, what is not built, corrections to earlier claims |
| docs/PLAN.md | design rationale, storage and cost arithmetic, phases and gates |
| docs/CONSOLIDATION_PLAN.md | execution plan for holding both chains in one directory and splitting the fill into download and process |
| docs/SOURCE_AUDIT.md | provenance: what was copied from btcd and nostrino, file by file |
Each fact has one home. Structure is in ARCHITECTURE, status is in STATUS, the reasons and the numbers are in PLAN, provenance is in SOURCE_AUDIT, and none of them restates another.
| need | answer here |
|---|---|
| headers and blocks for both chains | p2p fill, v2 headers for XBT |
| BIP158 filters | built locally from the stored blocks by the UTXO walk, keyed by block hash so both chains share one copy, served as the flt chunk kind |
| the same data on a second host, fast | ftool fills a new instance from an HTTP service |
| a UTXO set, cheaply | one snapshot per retarget height for the shared prefix, one diff per block; a client names any height in an epoch |
| a new Bitcoin fork | the shared prefix carries it; the fork pays for its own post-fork work only |
| relaying the swap's transactions | client-signed txs admitted, announced, tracked in a window, rebroadcast; no keys, no claim of acceptance |
Pre-fork block storage collapses to one copy for both chains: 97.4% of the naive
total is shared (derived, PLAN). The UTXO collapse is partial: the shared
prefix's snapshots and diffs are written once, and each chain's post-fork work
is its own. Answering "is this outpoint unspent at height H" quickly needs an
index ordered by (outpoint, height), which is named in PLAN as an open
question rather than built.
# both chains in one directory, filled from the two networks; repeat a chain to
# give it several peers, which is what makes a full chain a day's work
btcd-lited -chains btc,xbt -data ./data -listen 127.0.0.1:8080 \
-peer btc=10.0.0.1:8333,btc=10.0.0.2:8333,xbt=10.0.0.3:8333 \
-relay btc=10.0.0.1:8333,xbt=10.0.0.3:8333
# a mirror: serve the directory and build the UTXO and filter dataset
btcd-lite-serve -chains btc,xbt -data ./data -listen 127.0.0.1:8080
# fill another instance from it: bodies, then a chain's snapshots and diffs
ftool keygen -out instance.key
ftool sync -from http://host:8080 -key instance.key -chain btc \
-from-height 0 -to-height 100000 -data ./second
ftool utxo -from http://host:8080 -chain btc -data ./second
-regtest switches the instance to the local test chain's parameters and
network magic. -chain btc is the single-chain alias for -chains. A bare
-peer address is accepted only when the instance holds one chain, because an
address alone does not say which chain it serves.
Both server commands log every request, and take `-log-level
debug|info|warn|error|off (default info), -log-file PATH` (default stderr,
reopened on SIGHUP for a rotation) and -heartbeat 5m (0 disables it).
kill -USR1 <pid> turns debug on and kill -USR2 <pid> turns it back, so a run
that was started quiet can be diagnosed without a restart. A refusal is a
warning line that carries the response's own reason:
warn: access: remote=203.0.113.9 method=GET path="/v1/chains/btc/blk/500-510" status=400 bytes=35 dur_ms=0 note="serve: block 500: no header at 500"
go test ./...
internal/gate starts its own bitcoind on free ports for the node-backed
tests, from PATH or from the rig's install, and skips only when there is no
node to start.
Two groups need the two-chain rig already running, and fail rather than skip
without it because the handshake is the claim they make: internal/v2peer's
node tests and internal/gate's TestInstanceHandshakeWithTheNode. Start it
with /home/mleku/s/gjbrr/blake-swap/scripts/test-nodes start, or set
BTCD_LITE_P2P_TEST to another node's p2p address.