node

package
v0.4.1-dirty Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = time.Second * 15

Variables

View Source
var (
	// ErrOpened is thrown on attempt to open already open/in-use Store.
	ErrOpened = errors.New("node: store is in use")
	// ErrNotInited is thrown on attempt to open Store without initialization.
	ErrNotInited = errors.New("node: store is not initialized")
)

Functions

func Init

func Init(path string, tp Type, options ...Option) error

Init initializes the Node FileSystem Store for the given Node Type 'tp' in the directory under 'path' with default Config. Options are applied over default Config and persisted on disk.

func IsInit

func IsInit(path string) bool

IsInit checks whether FileSystem Store was setup under given 'path'. If any required file/subdirectory does not exist, then false is reported.

func SaveConfig

func SaveConfig(path string, cfg *Config) error

SaveConfig saves Config 'cfg' under the given 'path'.

func TestKeyringSigner added in v0.3.0

func TestKeyringSigner(t *testing.T) *apptypes.KeyringSigner

Types

type Config

type Config struct {
	Core     core.Config
	Key      key.Config
	P2P      p2p.Config
	RPC      rpc.Config
	Services services.Config
}

Config is main configuration structure for a Node. It combines configuration units for all Node subsystems.

func DefaultConfig

func DefaultConfig(tp Type) *Config

DefaultConfig provides a default Config for a given Node Type 'tp'. NOTE: Currently, configs are identical, but this will change.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads Config from the given 'path'.

func (*Config) Decode

func (cfg *Config) Decode(r io.Reader) error

Decode decodes a Config from a given reader r.

func (*Config) Encode

func (cfg *Config) Encode(w io.Writer) error

Encode encodes a given Config into w.

type ConfigLoader

type ConfigLoader func() (*Config, error)

ConfigLoader defines a function that loads a config from any source.

type Node

type Node struct {
	fx.In `ignore-unexported:"true"`

	Type          Type
	Network       params.Network
	Bootstrappers params.Bootstrappers
	Config        *Config

	// CoreClient provides access to a Core node process.
	CoreClient core.Client `optional:"true"`

	// rpc components
	RPCServer *rpc.Server `optional:"true"`
	// p2p components
	Host         host.Host
	ConnGater    *conngater.BasicConnectionGater
	Routing      routing.PeerRouting
	DataExchange exchange.Interface
	BlockService blockservice.BlockService
	// p2p protocols
	PubSub *pubsub.PubSub
	// services
	ShareServ  *share.Service  // not optional
	HeaderServ *header.Service // not optional
	StateServ  *state.Service  // not optional
	FraudServ  fraud.Service   // not optional
	DASer      *das.DASer      `optional:"true"`
	// contains filtered or unexported fields
}

Node represents the core structure of a Celestia node. It keeps references to all Celestia-specific components and services in one place and provides flexibility to run a Celestia node in different modes. Currently supported modes: * Bridge * Light * Full

func New

func New(tp Type, store Store, options ...Option) (*Node, error)

New assembles a new Node with the given type 'tp' over Store 'store'.

func TestNode added in v0.3.0

func TestNode(t *testing.T, tp Type, opts ...Option) *Node

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

Run is a Start which blocks on the given context 'ctx' until it is canceled. If canceled, the Node is still in the running state and should be gracefully stopped via Stop.

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start launches the Node and all its components and services.

func (*Node) Stop

func (n *Node) Stop(ctx context.Context) error

Stop shuts down the Node, all its running Components/Services and returns. Canceling the given context earlier 'ctx' unblocks the Stop and aborts graceful shutdown forcing remaining Components/Services to close immediately.

type Option

type Option func(*settings)

Option for Node's Config.

func WithAdvertiseInterval added in v0.3.0

func WithAdvertiseInterval(interval time.Duration) Option

WithAdvertiseInterval sets interval between advertises.

func WithBootstrappers added in v0.3.0

func WithBootstrappers(peers params.Bootstrappers) Option

WithBootstrappers sets custom bootstrap peers.

func WithConfig

func WithConfig(custom *Config) Option

WithConfig sets the entire custom config.

func WithCoreClient added in v0.2.0

func WithCoreClient(client core.Client) Option

WithCoreClient sets custom client for core process

func WithDiscoveryInterval added in v0.3.0

func WithDiscoveryInterval(interval time.Duration) Option

WithDiscoveryInterval sets interval between discovery sessions.

func WithGRPCPort added in v0.3.0

func WithGRPCPort(port string) Option

WithGRPCPort configures Node to connect to given gRPC port for state-related queries.

func WithHeaderConstructFn added in v0.3.0

func WithHeaderConstructFn(construct header.ConstructFn) Option

WithHeaderConstructFn sets custom func that creates extended header

func WithHost added in v0.2.0

func WithHost(hst host.Host) Option

WithHost sets custom Host's data for p2p networking.

func WithKeyringAccName added in v0.3.0

func WithKeyringAccName(name string) Option

WithKeyringAccName sets the `KeyringAccName` field in the key config.

func WithKeyringSigner added in v0.3.0

func WithKeyringSigner(signer *apptypes.KeyringSigner) Option

WithKeyringSigner overrides the default keyring signer constructed by the node.

func WithMetrics added in v0.3.0

func WithMetrics(enable bool) Option

WithMetrics enables metrics exporting for the node.

func WithMutualPeers added in v0.2.0

func WithMutualPeers(addrs []string) Option

WithMutualPeers sets the `MutualPeers` field in the config.

func WithNetwork added in v0.3.0

func WithNetwork(net params.Network) Option

WithNetwork specifies the Network to which the Node should connect to. WARNING: Use this option with caution and never run the Node with different networks over the same persisted Store.

func WithP2PKey added in v0.2.0

func WithP2PKey(key crypto.PrivKey) Option

WithP2PKey sets custom Ed25519 private key for p2p networking.

func WithP2PKeyStr added in v0.2.0

func WithP2PKeyStr(key string) Option

WithP2PKeyStr sets custom hex encoded Ed25519 private key for p2p networking.

func WithPeersLimit added in v0.3.0

func WithPeersLimit(limit uint) Option

WithPeersLimit overrides default peer limit for peers found during discovery.

func WithRPCAddress added in v0.3.0

func WithRPCAddress(addr string) Option

WithRPCAddress configures Node to listen on the given address for RPC queries.

func WithRPCPort added in v0.3.0

func WithRPCPort(port string) Option

WithRPCPort configures Node to expose the given port for RPC queries.

func WithRefreshRoutingTablePeriod added in v0.3.0

func WithRefreshRoutingTablePeriod(interval time.Duration) Option

WithRefreshRoutingTablePeriod sets custom refresh period for dht. Currently, it is used to speed up tests.

func WithRemoteCoreIP added in v0.3.0

func WithRemoteCoreIP(ip string) Option

WithRemoteCoreIP configures Node to connect to the given remote Core IP.

func WithRemoteCorePort added in v0.3.0

func WithRemoteCorePort(port string) Option

WithRemoteCorePort configures Node to connect to the given remote Core port.

func WithTrustedHash

func WithTrustedHash(hash string) Option

WithTrustedHash sets TrustedHash to the Config.

func WithTrustedPeers added in v0.3.0

func WithTrustedPeers(addr ...string) Option

WithTrustedPeers appends new "trusted peers" to the Config.

type Store added in v0.2.0

type Store interface {
	// Path reports the FileSystem path of Store.
	Path() string

	// Keystore provides a Keystore to access keys.
	Keystore() (keystore.Keystore, error)

	// Datastore provides a Datastore - a KV store for arbitrary data to be stored on disk.
	Datastore() (datastore.Batching, error)

	// Config loads the stored Node config.
	Config() (*Config, error)

	// PutConfig alters the stored Node config.
	PutConfig(*Config) error

	// Close closes the Store freeing up acquired resources and locks.
	Close() error
}

Store encapsulates storage for the Node. Basically, it is the Store of all Stores. It provides access for the Node data stored in root directory e.g. '~/.celestia'.

func MockStore added in v0.2.0

func MockStore(t *testing.T, cfg *Config) Store

MockStore provides mock in memory Store for testing purposes.

func NewMemStore added in v0.2.0

func NewMemStore() Store

NewMemStore creates an in-memory Store for Node. Useful for testing.

func OpenStore added in v0.2.0

func OpenStore(path string) (Store, error)

OpenStore creates new FS Store under the given 'path'. To be opened the Store must be initialized first, otherwise ErrNotInited is thrown. OpenStore takes a file Lock on directory, hence only one Store can be opened at a time under the given 'path', otherwise ErrOpened is thrown.

type Type

type Type uint8

Type defines the Node type (e.g. `light`, `bridge`) for identity purposes. The zero value for Type is invalid.

const (
	// Bridge is a Celestia Node that bridges the Celestia consensus network and data availability network.
	// It maintains a trusted channel/connection to a Celestia Core node via the core.Client API.
	Bridge Type = iota + 1
	// Light is a stripped-down Celestia Node which aims to be lightweight while preserving the highest possible
	// security guarantees.
	Light
	// Full is a Celestia Node that stores blocks in their entirety.
	Full
)

func ParseType

func ParseType(str string) Type

ParseType converts string in a type if possible.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid reports whether the Type is valid.

func (Type) String

func (t Type) String() string

String converts Type to its string representation.

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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