seed

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Apis

type Apis struct {
	RPC  []Node `json:"rpc"`
	Rest []Node `json:"rest"`
	GRPC []Node `json:"grpc"`
}

type Config

type Config struct {
	// SeedURL is the URL to fetch for server updates.
	SeedURL string

	// SeedRefreshInterval sets how frequently to fetch SeedURL for updates.
	SeedRefreshInterval time.Duration

	// ChainID is the ID of the chain.
	ChainID string

	// EnableRemote enables/disables remote seed fetching
	EnableRemote bool

	// AdditionalNodes contains additional configured nodes
	AdditionalNodes struct {
		RPC  []string
		REST []string
		GRPC []string
	}
}

Config specifies the required configuration to configure a Seeder.

type Node

type Node struct {
	Address  string `json:"address"`
	Provider string `json:"provider"`
	Status   Status
}

func (Node) Healthy

func (p Node) Healthy() bool

func (Node) WithStatus

func (p Node) WithStatus(status Status) Node

type Probe

type Probe interface {
	Probe(ctx context.Context, node Node) (Status, error)
}

Probe is the interface that wraps the Probe method.

Probe probes the given node for health. A healthy node must return a healthy status. Health is subject to the caller's interpretation of the returned Status.

type ProbeFunc

type ProbeFunc func(ctx context.Context, node Node) (Status, error)

ProbeFunc type is an adapter to allow the use of ordinary functions as probes. If a given function f is a function with the appropriate signature, ProbeFunc(f) is a Probe that calls f.

func (ProbeFunc) Probe

func (f ProbeFunc) Probe(ctx context.Context, node Node) (Status, error)

Probe implements the Probe interface for ProbeFunc to allow for defining probes as standalone function

type Seed

type Seed struct {
	Status  string `json:"status"`
	ChainID string `json:"chain_id"`
	APIs    Apis   `json:"apis"`
}

type Seeder

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

Seeder represents a seeder process responsible for updating Seed listeners on new changes to the node Seed.

func New

func New(cfg Config, log *slog.Logger, listeners ...chan<- Seed) *Seeder

New creates a Seeder instance. It takes an arbitrary number of listeners that will receive updated Seed structures.

func (*Seeder) Start

func (s *Seeder) Start(ctx context.Context)

Start executes a single goroutine to fetch and update seed listeners every Config.SeedRefreshInterval. It is only executed once for every Seeder instance.

type Status

type Status struct {
	// Reachable is whether a node was able to be reached or not.
	Reachable bool
	// CatchingUp whether a node is still trying to keep up with the network.
	CatchingUp bool
	// IsLatestBlock is true when the status of the node is caught up to the latest block.
	// This together with the block.BlockManager can be leveraged to confirm that the nodes are up-to-date on the latest block.
	// Because the seeding process takes time, the latest block on the start of the seeding process can be a different one from
	// the end of the seeding process so an absolute value of the latest block is not a good measurement of the node.
	// Instead, the singleton block.BlockManager must be used and set to the latest block height and if there is a
	// block.ErrBlockTooLow when setting the height, it means the node that we queried after was actually not on the latest block yet
	// and is removed from the seed temporarily.
	IsLatestBlock bool
	// Latency ...
	Latency time.Duration
}

Status represents the latest status of a node.

func GRPCProbe

func GRPCProbe(ctx context.Context, node Node) (Status, error)

GRPCProbe probes a gRPC Node. It checks if the node is catching up, queries the Node status through gRPC and tries to set the latest block height globally.

func RESTProbe

func RESTProbe(ctx context.Context, node Node) (Status, error)

RESTProbe probes a REST Node. It checks if the node is catching up querying the REST endpoint, queries the Node latest block and tries to set the height globally.

func RPCProbe

func RPCProbe(ctx context.Context, node Node) (Status, error)

RPCProbe probes an RPC Node. It queries the Node status through RPC and tries to set the latest block height globally.

Jump to

Keyboard shortcuts

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