Skip to content

Follow-loop: source blocks via the node's own P2P instead of the mempool.space REST API #20

@melvincarvalho

Description

@melvincarvalho

_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.jsPeer (TCP, version handshake, send/waitFor/collect, getdata/block).
  • src/download-testnet4.jsfirstPeer() (connect to a testnet4 peer), getheaders, fetchWindow (getdata WITNESS_BLOCK).

Plan:

  1. Connect to a testnet4 peer (firstPeer).
  2. getheaders with a locator at our tip → learn canonical headers beyond our tip (maps height → hash; P2P fetches by hash, not height).
  3. getdata WITNESS_BLOCK each new block by hash → validate forward + apply (existing follow-loop logic).
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions