_follow.mjs currently sources blocks and the tip height from the mempool.space testnet4 REST API — a third-party dependency with rate limits. Replace it with the node's own P2P, which already exists:
src/peer.js — Peer (TCP, version handshake, send/waitFor/collect, getdata/block).
src/download-testnet4.js — firstPeer() (connect to a testnet4 peer), getheaders, fetchWindow (getdata WITNESS_BLOCK).
Plan:
- Connect to a testnet4 peer (
firstPeer).
getheaders with a locator at our tip → learn canonical headers beyond our tip (maps height → hash; P2P fetches by hash, not height).
getdata WITNESS_BLOCK each new block by hash → validate forward + apply (existing follow-loop logic).
- Stay live by re-
getheaders (or inv/headers announcements). Header sync naturally reveals reorgs.
Result: the node self-sources blocks — no third-party API, no rate limits, more trustless. First step: prove a single block fetch over P2P (connect → getheaders → getdata one block → verify it links to our tip) before integrating into the loop.
_follow.mjscurrently sources blocks and the tip height from themempool.spacetestnet4 REST API — a third-party dependency with rate limits. Replace it with the node's own P2P, which already exists:src/peer.js—Peer(TCP, version handshake,send/waitFor/collect,getdata/block).src/download-testnet4.js—firstPeer()(connect to a testnet4 peer),getheaders,fetchWindow(getdata WITNESS_BLOCK).Plan:
firstPeer).getheaderswith a locator at our tip → learn canonical headers beyond our tip (maps height → hash; P2P fetches by hash, not height).getdata WITNESS_BLOCKeach new block by hash → validate forward + apply (existing follow-loop logic).getheaders(orinv/headersannouncements). Header sync naturally reveals reorgs.Result: the node self-sources blocks — no third-party API, no rate limits, more trustless. First step: prove a single block fetch over P2P (connect → getheaders → getdata one block → verify it links to our tip) before integrating into the loop.