core

package
v0.31.2-arabica Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 42 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultTestConfig added in v0.6.2

func DefaultTestConfig() *testnode.Config

DefaultTestConfig returns the default testing configuration for Tendermint + Celestia App tandem.

It fetches free ports from OS and sets them into configs, s.t. user can make use of them(unlike 0 port) and allowing to run multiple tests nodes in parallel.

Additionally, it instructs Tendermint + Celestia App tandem to setup 10 funded accounts.

func StartTestNode added in v0.3.0

func StartTestNode(t *testing.T) testnode.Context

StartTestNode simply starts Tendermint and Celestia App tandem with default testing configuration.

func StartTestNodeWithConfig added in v0.6.2

func StartTestNodeWithConfig(t *testing.T, cfg *testnode.Config) testnode.Context

StartTestNodeWithConfig starts Tendermint and Celestia App tandem with custom configuration.

func StartTestNodeWithConfigAndClient added in v0.23.5

func StartTestNodeWithConfigAndClient(t *testing.T) (testnode.Context, *cmthttp.HTTP)

StartTestNodeWithConfigAndClient initializes a test node with default configuration and a WebSocket HTTP client.

Types

type BlockEvent

type BlockEvent struct {
	Height int64
	// contains filtered or unexported fields
}

BlockEvent is a new-block notification carrying the height plus which source announced it. The block body is fetched on demand via GetSignedBlockFrom, which routes to the announcing source — the peer fastest to notify this height, a fresh signal that it's the most responsive peer.

type BlockFetcher

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

func NewBlockFetcher

func NewBlockFetcher(conn *grpc.ClientConn) *BlockFetcher

NewBlockFetcher returns a new `BlockFetcher`.

func (*BlockFetcher) ChainID added in v0.30.2

func (f *BlockFetcher) ChainID(ctx context.Context) (string, error)

ChainID returns the chain ID (network name) that the Core node is connected to. This can be used to validate that the node is connected to the correct network.

func (*BlockFetcher) Commit

func (f *BlockFetcher) Commit(ctx context.Context, height int64) (*types.Commit, error)

Commit queries Core for a `Commit` from the block at the given height. If the height is nil, use the latest height.

func (*BlockFetcher) GetBlock

func (f *BlockFetcher) GetBlock(ctx context.Context, height int64) (*SignedBlock, error)

GetBlock queries Core for a `Block` at the given height. if the height is nil, use the latest height

func (*BlockFetcher) GetBlockByHash

func (f *BlockFetcher) GetBlockByHash(ctx context.Context, hash libhead.Hash) (*types.Block, error)

func (*BlockFetcher) GetBlockInfo added in v0.2.0

func (f *BlockFetcher) GetBlockInfo(ctx context.Context, height int64) (*types.Commit, *types.ValidatorSet, error)

GetBlockInfo queries Core for additional block information, like Commit and ValidatorSet.

func (*BlockFetcher) GetSignedBlock added in v0.7.2

func (f *BlockFetcher) GetSignedBlock(ctx context.Context, height int64) (*SignedBlock, error)

GetSignedBlock queries Core for a `Block` at the given height. if the height is nil, use the latest height.

func (*BlockFetcher) GetSignedBlockFrom

func (f *BlockFetcher) GetSignedBlockFrom(ctx context.Context, ev BlockEvent) (*SignedBlock, error)

GetSignedBlockFrom fetches the block for the given event. A single BlockFetcher has only one source, so the event's source hint is irrelevant and it simply fetches by height.

func (*BlockFetcher) IsSyncing added in v0.3.0

func (f *BlockFetcher) IsSyncing(ctx context.Context) (bool, error)

IsSyncing returns the sync status of the Core connection: true for syncing, and false for already caught up. It can also return an error in the case of a failed status request.

func (*BlockFetcher) IsSyncingFrom

func (f *BlockFetcher) IsSyncingFrom(ctx context.Context, _ BlockEvent) (bool, error)

IsSyncingFrom reports the sync status for the source that announced the event. A single BlockFetcher has only one source, so the event's source hint is irrelevant and it simply reports its own status.

func (*BlockFetcher) SubscribeNewBlockEvent

func (f *BlockFetcher) SubscribeNewBlockEvent(ctx context.Context) (chan BlockEvent, error)

SubscribeNewBlockEvent subscribes to new block heights from Core, returning a channel of BlockEvents. The full block is intentionally NOT fetched here: the consumer (Listener) pulls the block on demand via GetSignedBlockFrom, so a MultiSource fanning N endpoints downloads each block once rather than once per source.

func (*BlockFetcher) ValidatorSet

func (f *BlockFetcher) ValidatorSet(ctx context.Context, height int64) (*types.ValidatorSet, error)

ValidatorSet queries Core for the ValidatorSet from the block at the given height. If the height is nil, use the latest height.

func (*BlockFetcher) Verify

func (f *BlockFetcher) Verify(ctx context.Context, expected string) error

Verify checks the core endpoint is on the expected network. The expected chain ID must be set: a node must know which network it serves.

type Exchange added in v0.6.3

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

func NewExchange added in v0.6.3

func NewExchange(
	fetcher *BlockFetcher,
	store *store.Store,
	construct header.ConstructFn,
	opts ...Option,
) (*Exchange, error)

func (*Exchange) Get added in v0.6.3

func (ce *Exchange) Get(ctx context.Context, hash libhead.Hash) (*header.ExtendedHeader, error)

func (*Exchange) GetByHeight added in v0.6.3

func (ce *Exchange) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)

func (*Exchange) GetRangeByHeight added in v0.6.3

func (ce *Exchange) GetRangeByHeight(
	ctx context.Context,
	from *header.ExtendedHeader,
	to uint64,
) ([]*header.ExtendedHeader, error)

func (*Exchange) Head added in v0.6.3

type Fetcher

type Fetcher interface {
	// Verify checks the source is on the expected network before any blocks are
	// consumed. The expected chain ID must be set — a node must know its network,
	// so an empty one is an error. A MultiSource may prune sources on the wrong
	// network here; it errors if none remain usable.
	Verify(ctx context.Context, expected string) error
	// SubscribeNewBlockEvent returns a channel of new-block events. Each event
	// carries the height and which source announced it; the block is fetched on
	// demand via GetSignedBlockFrom, so a MultiSource downloads each block once
	// instead of once per source.
	SubscribeNewBlockEvent(ctx context.Context) (chan BlockEvent, error)
	// GetSignedBlockFrom fetches the full signed block for the event from the
	// source that announced it — the peer fastest to notify this height. It does
	// NOT fall back to other sources on failure: an error is just an error.
	// Resilience is a property of the fan-in — another source announces the same
	// height, and the Listener retries the fetch from it (the failed attempt
	// stored nothing, so the duplicate is a store-miss, not a skip).
	GetSignedBlockFrom(ctx context.Context, ev BlockEvent) (*SignedBlock, error)
	// ChainID returns the network/chain ID of the source.
	ChainID(ctx context.Context) (string, error)
	// IsSyncingFrom reports whether the source that announced the event is still
	// catching up to the head. Sync state is per-source: the answer must come
	// from the same peer that served the block, since another source being
	// caught up says nothing about whether THIS block is a fresh head or a
	// replay of an old height from a peer mid-blocksync. Like
	// GetSignedBlockFrom, it does not fall back to other sources on failure.
	IsSyncingFrom(ctx context.Context, ev BlockEvent) (bool, error)
}

Fetcher abstracts the core block source consumed by the Listener. It is satisfied both by a single *BlockFetcher and by a *MultiSource, which fans several core endpoints into one new-block stream for resilience.

type Listener added in v0.6.3

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

Listener is responsible for listening to Core for new block events and converting new Core blocks into the main data structure used in the Celestia DA network: `ExtendedHeader`. After digesting the Core block, extending it, and generating the `ExtendedHeader`, the Listener broadcasts the new `ExtendedHeader` to the header-sub gossipsub network.

func NewListener added in v0.6.3

func NewListener(
	bcast libhead.Broadcaster[*header.ExtendedHeader],
	fetcher Fetcher,
	hashBroadcaster shrexsub.BroadcastFn,
	construct header.ConstructFn,
	store *store.Store,
	blocktime time.Duration,
	opts ...Option,
) (*Listener, error)

func (*Listener) Start added in v0.6.3

func (cl *Listener) Start(ctx context.Context) error

Start kicks off the Listener listener loop.

func (*Listener) Stop added in v0.6.3

func (cl *Listener) Stop(ctx context.Context) error

Stop stops the listener loop.

type MultiSource

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

MultiSource fans several core endpoints into one new-block stream. Each endpoint stays subscribed independently (the underlying BlockFetcher already resubscribes forever on its own), so a single failing endpoint cannot stall the others. Duplicate heights across sources are expected and must be deduplicated by the consumer.

func NewMultiSource

func NewMultiSource(grpcClients ...*grpc.ClientConn) *MultiSource

NewMultiSource builds a MultiSource over the given gRPC connections. With a single connection it behaves equivalently to a single-source BlockFetcher.

func (*MultiSource) ChainID

func (m *MultiSource) ChainID(ctx context.Context) (string, error)

ChainID returns the chain ID from the first responsive source. All sources are expected to be on the same network; the Listener verifies the result against the expected chain ID.

func (*MultiSource) GetSignedBlockFrom

func (m *MultiSource) GetSignedBlockFrom(ctx context.Context, ev BlockEvent) (*SignedBlock, error)

GetSignedBlockFrom fetches the block for the event from the single source that announced it — the fastest peer to notify this height, a fresh signal it's the most responsive peer. It does ONE thing and does not fall back to other sources: an error is returned as-is. Resilience is the fan-in's job — the same height is announced by other sources, and since a failed fetch stores nothing, the Listener re-fetches it from whichever source's duplicate event arrives next.

func (*MultiSource) IsSyncingFrom

func (m *MultiSource) IsSyncingFrom(ctx context.Context, ev BlockEvent) (bool, error)

IsSyncingFrom reports whether the source that announced the event is still catching up. Sync state is per-source: the same peer that announced and served the block answers whether it is a fresh head or a catch-up replay — another source being caught up says nothing about this block. Like GetSignedBlockFrom, it does not fall back to other sources: the Listener calls it before storing the height, so on error the duplicate announcement from another source retries the height whole.

func (*MultiSource) SubscribeNewBlockEvent

func (m *MultiSource) SubscribeNewBlockEvent(ctx context.Context) (chan BlockEvent, error)

SubscribeNewBlockEvent fans every source's subscription into one channel, closed once all source goroutines exit (i.e. ctx is canceled). It forwards BlockEvents, not full blocks: each event is tagged with its source's addr so the consumer fetches the block once from the announcing peer via GetSignedBlockFrom instead of every source downloading it independently.

func (*MultiSource) Verify

func (m *MultiSource) Verify(ctx context.Context, expected string) error

Verify checks every source against the expected network and keeps only those that confirmed the expected chain ID. Both wrong-chain AND unreachable sources are pruned (logged with their address): sources are operator-curated endpoints, so an endpoint that cannot vouch for its network at startup has no business in the active set — letting it join later would defer a wrong-chain failure to a mid-run panic instead of a startup log. The operator restores a pruned endpoint by fixing it and restarting. It errors if no source could be confirmed, so a fully misconfigured or unreachable set refuses to start. The expected chain ID must be set: a node must know which network it serves.

Verify mutates m.sources and is safe only because Listener.Start calls it synchronously before SubscribeNewBlockEvent spawns goroutines and before ChainID/IsSyncingFrom run. Pruning is keyed by addr, so it no longer matters that indices would shift — but concurrent mutation would still race the reads.

type Network added in v0.21.9

type Network struct {
	testnode.Context
	// contains filtered or unexported fields
}

Network wraps `testnode.Context` allowing to manually stop all underlying connections. TODO @vgonkivs: remove after https://github.com/celestiaorg/celestia-app/issues/4304 is done.

func NewNetwork added in v0.21.9

func NewNetwork(t testing.TB, config *testnode.Config) *Network

func (*Network) Start added in v0.21.9

func (n *Network) Start() error

func (*Network) Stop added in v0.21.9

func (n *Network) Stop() error

type Option added in v0.12.1

type Option func(*params)

func WithArchivalMode added in v0.21.5

func WithArchivalMode() Option

func WithAvailabilityWindow added in v0.14.0

func WithAvailabilityWindow(window time.Duration) Option

func WithChainID added in v0.13.0

func WithChainID(id p2p.Network) Option

func WithMetrics added in v0.12.1

func WithMetrics() Option

WithMetrics is a functional option that enables metrics inside the core package.

func WithP2PExchange added in v0.30.2

func WithP2PExchange(ex libhead.Exchange[*header.ExtendedHeader]) Option

WithP2PExchange sets the P2P exchange for fallback when core doesn't have blocks. When core is unavailable, only headers will be fetched via P2P. The EDS data will be downloaded later by the DASer component.

type RoutingExchange added in v0.30.2

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

RoutingExchange combines core and P2P exchanges to optimize header syncing for Bridge nodes. It routes requests based on whether headers fall within the availability window:

  • Inside window: uses core exchange (fetches full blocks from consensus)
  • Outside window: uses P2P exchange (fetches headers only from network)

func NewRoutingExchange added in v0.30.2

func NewRoutingExchange(
	coreEx libhead.Exchange[*header.ExtendedHeader],
	p2pEx libhead.Exchange[*header.ExtendedHeader],
	window time.Duration,
	blockTime time.Duration,
) (*RoutingExchange, error)

NewRoutingExchange creates a new RoutingExchange that wraps core and P2P exchanges.

func (*RoutingExchange) Get added in v0.30.2

Get retrieves a header by hash.

func (*RoutingExchange) GetByHeight added in v0.30.2

func (h *RoutingExchange) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)

GetByHeight retrieves a header by height. Uses the availability window to determine which exchange to use.

func (*RoutingExchange) GetRangeByHeight added in v0.30.2

func (h *RoutingExchange) GetRangeByHeight(
	ctx context.Context,
	from *header.ExtendedHeader,
	to uint64,
) ([]*header.ExtendedHeader, error)

GetRangeByHeight retrieves a range of headers. Splits the range based on the availability window cutoff.

func (*RoutingExchange) Head added in v0.30.2

Head returns the latest header from the core exchange. We always use core for Head() to get the authoritative latest block. Also updates the cached cutoff height for routing decisions.

type SignedBlock added in v0.21.5

type SignedBlock struct {
	Header       *types.Header       `json:"header"`
	Commit       *types.Commit       `json:"commit"`
	Data         *types.Data         `json:"data"`
	ValidatorSet *types.ValidatorSet `json:"validator_set"`
}

Jump to

Keyboard shortcuts

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