Skip to content

p2p: move to kernel-node bitcoin-p2p on bitcoin 0.32 (SNB-854) - #84

Open
setavenger wants to merge 3 commits into
integrationfrom
snb-854-kernel-node-p2p
Open

setavenger wants to merge 3 commits into
integrationfrom
snb-854-kernel-node-p2p

Conversation

@setavenger

@setavenger setavenger commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Step 1 of SNB-853 (SNB-854): a pure dependency switch, no intended behaviour change.

What changed and why

The block download used 2140-dev/bitcoin-p2p (archived, not pinned). It needs a rust-bitcoin 0.33 pre-release (16cc257c, our bitcoin-rev dependency), so blocks, headers and transactions were re-encoded between two rust-bitcoin versions, and bitcoin_rev::Network leaked into the public API.

  • blindbit-lib depends on kernel-node's bitcoin-p2p (crates/p2p), pinned to rev = d421e330. It uses bitcoin 0.32, so a received block is already a bitcoin::Block and goes straight to check_block (the decode, re-encode, decode step is gone).
  • bitcoin::Network is used everywhere: ScannerConfig, Scanner::new / from_changeset, BlockFetcher, BlockFetchError, FetchFailure::WrongNetwork, blindbit-cli --network, friglet ResolvedConfig. scanner::convert_network is removed. Testnet3 is Network::Testnet and testnet4 is Network::Testnet4.
  • friglet's own Electrum P2P peer (friglet/src/electrum/p2p.rs, kept because it needs relay = true) is ported to bitcoin 0.32's bitcoin::p2p message types. friglet no longer depends on bitcoin-p2p: it only used that crate's message re-export.
  • bitcoin-rev is removed from all three crates. Cargo.lock now has one bitcoin: 0.32.7 → 0.32.8, the minimum kernel-node requires. hex-conservative also moves 0.2.1 → 0.2.3, pulled in by that bump.

Behaviour differences found

Timeouts, retries, ping/getdata logic, service requirement (none), block checks and error messages are unchanged. The new crate's net.rs and handshake.rs work the same way as the old crate's: the same blocking reader, the same writer thread with a 30 s ping, the same strict pre-verack message set, the same ≥ 70016 version floor and the same error enum. Only the types differ. Differences:

  1. Version message defaults. kernel-node defaults to user agent /bitcoin-p2p:0.1.0/ and feefilter 0. We now set /SwiftSync:0.1.0/ and 1000 sat/kvB explicitly, so peers see the same values as before. A new test, the_handshake_shows_the_node_the_same_client_as_before, checks this.
  2. Version address fields. kernel-node's version message sends 127.0.0.1:1 as addr_recv / addr_from; the old crate sent all zeros. The crate does not let us override this. Bitcoin Core ignores both values because neither is routable. friglet's own peer now sends 127.0.0.1:1 too (commit 4ab2cda), so both stacks look like one client to a peer.
  3. Wire decoding moves from rust-bitcoin 0.33-alpha to 0.32.8.
    • A frame with a non-ASCII command: 0.33-alpha rejected it, which broke the fetch attempt as a "connection broke". With 0.32.8 the scanner now skips it as an unknown message. friglet's peer keeps the old explicit check.
    • A non-Bitcoin service whose first bytes are non-ASCII with a wrong magic: the handshake now fails with "peer does not speak Bitcoin P2P" (UnexpectedMagic) instead of "handshake failed: Command string must be ASCII". Both are non-transient, so retries are unchanged.
    • A block that fails to decode is still FetchFailure::Broken. The message is now the decoder's error instead of undecodable block: ….
    • feefilter is an i64 in 0.32. friglet maps it to the same u64 as before, including the saturation for values outside u32.
  4. friglet relay. The transaction handed to the peer is the bitcoin 0.32 encoding of the candidate (the same bytes). The transaction re-encoding failed error path is gone.
  5. Final alert dropped. The old crate sent a final alert to peers below protocol version 70016. Such peers were rejected anyway, so nothing changes in practice.

Verification

  • Commit f54365e: the version address fields above, and the bitcoin floor raised to 0.32.8 in every manifest. Commit fa4f8ee: integration's new testkit T0 tests import bitcoin::Network instead of the removed bitcoin_rev::Network.
  • cargo build --workspace: ok.
  • cargo test -p blindbit-lib --features serde on top of integration 929419b: 86 passed; 0 failed (75 existing, 1 new, 10 testkit T0). Before the rebase: friglet 77 passed; 0 failed (+1 integration), friglet-ipc 27+1, friglet-tray 66+7; CI passes.
  • CI cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • cargo tree -i bitcoin --workspace: a single bitcoin v0.32.8. Before this change there were two: 0.32.7 and 0.33.0-alpha.0 (git).
  • Live signet (152.53.151.148:38333, https://signet.oracle.setor.dev, debug builds, before and after):
    • blindbit-cli range scan 274010–274060: exit 0 both times, and the state files are identical.
    • fetch_block of block 328628 (719,127 bytes, 227 txs): OK both times, so the checks pass (hash, merkle root, witness commitment).
    • Wrong-network error (mainnet against the signet node): the same message word for word.
    • friglet daemon on signet, which exercises the ported relay=true peer: blockchain.block.header 300000 comes over P2P getheaders and matches mempool.space byte for byte. blockchain.relayfee returns the peer's feefilter.
  • Performance (release builds, mainnet block 900000: 1,920,777 bytes, 1,562 txs):
    • Decode only: the old path (0.33-alpha decode + re-encode + 0.32 decode) took 5.1 ms; the new path (0.32 decode) takes 2.8–3.2 ms, about 0.55–0.64×.
    • Decode plus the check_block hashing: 9.0 ms → 6.8 ms, about 0.75×.
    • End to end through BlockFetcher::fetch from a loopback fake peer, 4 interleaved runs of 200 fetches each:
      • process CPU per fetch 16.2–18.8 ms → 11.3–13.2 ms, about 0.70×;
      • median wall time 15–19 ms → 10–13 ms, about 0.69×.
    • The box was shared (load average about 3–4), so the numbers are rough. The harness is not committed.

setavenger and others added 3 commits November 1, 2026 15:42
The block download used 2140-dev/bitcoin-p2p (archived, unpinned), which
needs a rust-bitcoin 0.33 pre-release (16cc257c, pulled in as
`bitcoin-rev`). Every block, header and transaction was therefore decoded
twice or re-encoded between the two rust-bitcoin versions, and
`bitcoin_rev::Network` leaked into the public API.

- blindbit-lib: depend on kernel-node's `bitcoin-p2p` (crates/p2p),
  pinned to d421e330, which uses bitcoin 0.32. Blocks arrive as
  `bitcoin::Block` and go straight to `check_block`.
- Use `bitcoin::Network` everywhere: `ScannerConfig`, `Scanner`,
  `BlockFetcher`, `BlockFetchError`, blindbit-cli and friglet config.
  `scanner::convert_network` is gone.
- Keep the handshake peers see: kernel-node defaults to user agent
  "/bitcoin-p2p:0.1.0/" and feefilter 0, so set "/SwiftSync:0.1.0/" and
  1000 sat/kvB as before (new test checks the version message).
- friglet's own relay=true Electrum peer now uses bitcoin 0.32's
  `bitcoin::p2p` message types; friglet no longer depends on bitcoin-p2p.
- Remove the `bitcoin-rev` dependency; Cargo.lock now holds one bitcoin
  (0.32.8, the version kernel-node requires).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… bitcoin 0.32.8 (SNB-854)

friglet's own P2P peer sent all-zero address fields in its version
message while the scanner's kernel-node connections send 127.0.0.1:1,
which kernel-node does not let us override. Send 127.0.0.1:1 from both
stacks so a peer sees one client, as the shared user agent intends.

Raise the bitcoin floor in every manifest to 0.32.8, the version
kernel-node bitcoin-p2p needs and the lockfile already resolves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…B-854)

integration gained testkit_t0.rs, which imports bitcoin_rev::Network; this branch removes the bitcoin-rev dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@setavenger
setavenger force-pushed the snb-854-kernel-node-p2p branch from 4ab2cda to fa4f8ee Compare November 1, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant