chainxchg

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRequestLength = 900

MaxRequestLength is the protocol cap on tipsets per request.

View Source
const ProtocolID protocol.ID = "/fil/chain/xchg/0.0.1"

ProtocolID is the libp2p protocol ID for Filecoin ChainExchange.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a ChainExchange requester bound to a libp2p host.

func NewClient

func NewClient(h host.Host) *Client

NewClient constructs a ChainExchange client on h. Register() is NOT required; the client only opens outbound streams.

func (*Client) ClientStats

func (c *Client) ClientStats() ClientStats

ClientStats returns a snapshot.

func (*Client) FetchTipsetChain

func (c *Client) FetchTipsetChain(ctx context.Context, head []cid.Cid, length int) ([][]*ltypes.BlockHeader, error)

FetchTipsetChain requests up to length tipsets of HEADERS starting at the tipset whose block CIDs are head, walking parent-ward. The result is ordered as received: index 0 = the head tipset, increasing index = older. Every header is CID-verified and every level is verified to be the parent set of the level above; the first level must match head exactly. Returns at least one tipset on success (partial responses are legal and returned as-is).

func (*Client) SetPreferredPeers

func (c *Client) SetPreferredPeers(f func() []peer.ID)

SetPreferredPeers wires a provider of first-choice peers (trusted floor / quorum peers). Optional.

type ClientStats

type ClientStats struct {
	Requests  uint64 `json:"requests"`
	Succeeded uint64 `json:"succeeded"`
	Failed    uint64 `json:"failed"`
	PeerTries uint64 `json:"peer_tries"`
}

ClientStats reports observable activity for the dashboard.

type Service

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

Service is the ChainExchange responder bound to a libp2p host.

func NewService

func NewService(h host.Host) *Service

NewService constructs a Service. Caller must call Register() to attach the stream handler.

func (*Service) Register

func (s *Service) Register()

Register attaches the ChainExchange stream handler to the host. Idempotent.

func (*Service) SetSource

func (s *Service) SetSource(src Source)

SetSource wires an optional local source of tipsets. When called with a non-nil src, the Service will serve real header chains instead of NotFound. Idempotent. Passing nil reverts to the NotFound-only mode.

func (*Service) Stats

func (s *Service) Stats() Stats

Stats returns a snapshot.

type Source

type Source interface {
	GetTipSet(tsk ltypes.TipSetKey) (*ltypes.TipSet, error)
}

Source is the read surface a ChainExchange server needs from the local header store. Small enough that store.Store satisfies it out of the box (see chain/header/store/store.go), and small enough that an in-memory test source is trivial to write.

GetTipSet MUST return a *TipSet whose blocks match the given key exactly, or an error. Callers use ErrNotFound-style errors (or any non-nil error) to mean "not served"; the server responds with statusNotFound in that case.

type Stats

type Stats struct {
	Received uint64 `json:"received"`
	Rejected uint64 `json:"rejected"`
}

Stats reports observable activity. Exposed for the dashboard.

Jump to

Keyboard shortcuts

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