peerheads

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package peerheads records the chain heads libp2p peers announce to us (#154), so a bridge-off Lantern (--no-fallback-rpc) has a continuous, RPC-free head quorum instead of none.

Feeders:

  • Hello (/fil/hello/1.0.0): the peer's heaviest tipset at connect time.
  • Gossipsub /fil/blocks: every block a peer forwards (continuous, fresh).

Honest boundary: peer IDs are Sybil-cheap, so peers are grouped by network prefix (IPv4 /16, IPv6 /32). A swarm of sybils in one prefix is one voter. Peers without an IP address (relayed / unknown) are ignored. This raises the cost of an eclipse from "N peer IDs" to "N networks"; finality (F3) is what fully closes the unfinalized tip.

Index

Constants

View Source
const DefaultCap = 512

DefaultCap bounds how many peers the book remembers.

Variables

This section is empty.

Functions

func GroupOf

func GroupOf(ma multiaddr.Multiaddr) string

GroupOf returns the network-prefix voter key for an address: IPv4 /16, IPv6 /32. Loopback/private addresses keep their full IP (they are distinct local operators in a lab, and never reachable from outside). Non-IP or nil addresses return "".

Types

type Book

type Book struct {
	// contains filtered or unexported fields
}

Book is a bounded, concurrency-safe per-peer head record.

func New

func New(addrOf func(peer.ID) multiaddr.Multiaddr) *Book

New builds a Book. addrOf resolves a peer's current remote address (the daemon passes the first live connection's RemoteMultiaddr).

func (*Book) Observe

func (b *Book) Observe(p peer.ID, cids []cid.Cid, h abi.ChainEpoch)

Observe records that peer p announced a tipset (cids) at height h. Only moves forward per peer. Peers with no IP-derived group are dropped.

func (*Book) ObserveBlock

func (b *Book) ObserveBlock(p peer.ID, c cid.Cid, h abi.ChainEpoch, parents []cid.Cid)

ObserveBlock records a gossiped block (CID, height, parents) from peer p.

func (*Book) Recent

func (b *Book) Recent(maxAge time.Duration) []Head

Recent returns heads observed within maxAge, sorted by peer ID.

type Head struct {
	Peer   peer.ID
	Group  string // network prefix voter key, never empty
	Cids   []cid.Cid
	Height abi.ChainEpoch
	// Parents of the announced block (gossip only; nil for Hello). Lets
	// the head quorum check the peer is on OUR chain, not just our height.
	Parents []cid.Cid
	At      time.Time
}

Head is the latest head one peer announced.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址