SOURCE_AUDIT.md raw

Phase 0: the source audit

What was copied, from where, and what was deliberately left behind. The plan (docs/PLAN.md, "Copying from btcd and nostrino") commits to this list; this file is the record that it was done, with the file names.

Copied from btcd v0.24.2 (~/go/pkg/mod/github.com/btcsuite/btcd@v0.24.2)

filewhat was takenwhat was left
wire/msgblock.gothe header-then-CompactSize-transactions shape; the 4 MB MaxBlockPayload ceiling; the coinbase-first checkBtcDecode's MerkleRoot computation on the header struct; the btcutil-level failure builders
wire/msgtx.gothe segwit marker/flag rule (zero input count, then flag 0x01), the witness stack per input, the txid over the non-witness form, the 10,000-byte script ceilinginput/output value range checks, TxHash without witness, btcutil hashing helpers
wire/blockheader.gothe 80-byte header layout: version, prev, merkle root, time, bits, noncethe header codec's error taxonomy; the 164-byte XBT header is not in btcd at all
wire/common.goCompactSize read/write, canonical-encoding rejection, DoubleSha256Idx for merkle levelsthe per-field decoder and error path for each message
wire/message.go (concepts)the validation that a block's transaction stream ends at its last tx and has no trailing bytesthe message registry and dispatcher

btcd's blockchain, database, indexers, mempool and blockManager relay logic are not copied: the first three are validation and storage this program does not do, and the relay loop here is smaller than btcd's because it has no orphan pool and no block-request bookkeeping to keep.

Imported from nostrino (not copied)

packagewhy it is imported rather than copied
pkg/neutrinothe header chain, the XBT v2 header rule (checkForkHeader), the 22-bit TargetShift at HeaderV2Height, difficulty and median-time-past, Truncate for reorgs, ApplyHeaders for imports. One implementation of the fork rules, in the repository that already has the fork's vectors.
pkg/chainthe Profile type and the xbt profile's constants.
pkg/crypto/chainhashthe hash type both sides agree on.
pkg/filterthe Golomb-coded set, BIP158 N=19, M=784931, with the official vectors. Reimplementing it would give two implementations of a wire format that must be byte-identical.

Not copied, and why

A filter needs the raw scriptPubKey bytes and the OP_RETURN first-opcode test; nothing else.

164-byte header, its ForkHash and its retarget shift live in nostrino's pkg/btcwire/fork.go and pkg/neutrino/pow.go, which this program imports.

surface. This program returns fmt.Errorf-wrapped sentinels (internal/wire's ErrShort, ErrTrailing, and the rest).

Nostrino's read loop, and why the relay needs its own connection

pkg/p2p.Conn.ReadUntil reads frames until it finds the command it is waiting for and silently drops everything else. That is right for a client that only ever receives replies to its own requests, and it is why the transaction relay cannot share a lane's connection: a peer answering an inv with getdata would have that request read and discarded while the lane waits for a headers or a block. The replay/relay pool therefore owns its connections, its reader and its queue, and never calls into a lane. That decision is what phase 5's relay builds on.