node

package
v0.0.0-...-4e90b69 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: GPL-3.0, LGPL-3.0 Imports: 37 Imported by: 0

Documentation

Overview

Package node assembles a consensus node: configuration parsing and start-up checks, profiles, the start-up handshake with the application, the node life cycle, the implementation of the Consensus service and of the RPC backend.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfig reports an unusable node configuration.
	ErrConfig = errors.New("node: invalid configuration")
	// ErrStartRefused reports a start-up check that refuses to start.
	ErrStartRefused = errors.New("node: start refused")
)

Errors of the node.

View Source
var LogDefaults = logcat.Settings{Base: logcat.LevelInfo}

LogDefaults are the log settings of a node whose Config.Log is nil: every module at info.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DataDir holds the durable state of the node: the write-ahead log in
	// wal/, the sign state in privval/state and the message journal in
	// journal/.
	DataDir string
	// KeyFile is the node key in the go-stablenet nodekey format (64 hex
	// characters). Empty runs a node that never signs: it verifies headers
	// but runs no consensus core.
	KeyFile string
	// TakeoverGuard sets the sign floor at head + 1 when the sign state is
	// empty and the head is above genesis, so that a node that takes over
	// a key without its sign record signs nothing at that height
	// (privval.takeover_guard).
	TakeoverGuard bool
	// RunID names this run in the event records; empty derives one from the
	// start time.
	RunID string
	// Mempool configures the transaction pool; used when Deps.Admission is
	// set.
	Mempool MempoolConfig
	// Standalone runs the node in standalone mode, where the authority may
	// come from a native module of the application. In the default
	// (embedded) mode the node refuses an authority source marked as native
	// (source.Native): an embedded chain takes its authority from the state
	// it shares with the reference implementation.
	Standalone bool
	// Journal configures the message journal of a validator.
	Journal JournalConfig
	// Log is the base log level and the levels of single modules
	// (observe.md 7.1); nil uses LogDefaults. An unknown module name
	// refuses the start.
	Log *logcat.Settings
	// LogUnmapped lists log settings of the application that name no
	// module (wbft-stablenet's --log.vmodule patterns of single files);
	// they are recorded with the settings in force (LOG_CONFIG unmapped).
	LogUnmapped []string
}

Config configures a Node.

type Deps

type Deps struct {
	// App is the application. Required.
	App app.Application
	// Authority gives the authority snapshot of the head at start-up and
	// the epoch candidates during block execution. Required.
	Authority source.AuthoritySource
	// Transport carries consensus messages; nil runs a node without peers.
	Transport transport.Transport
	// Admission validates transactions for the pool; nil runs no pool.
	Admission mempool.AdmissionHook
	// TxTransport gossips transactions; nil keeps them local.
	TxTransport mempool.TxTransport
	// Orderings are ordering policies besides the built-in "fifo".
	Orderings []mempool.OrderingPolicy
	// Events receives the event records as JSON Lines; nil drops them.
	Events io.Writer
	// Logger is where the node's log lines go; nil discards. Each module
	// logs through it with a module attribute, at the level the log
	// settings give the module, so its handler should accept every level.
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Deps are the collaborators of a Node.

type JournalConfig

type JournalConfig struct {
	Disabled bool
	// KeepHeights and MaxBytes bound the journal; zero takes the defaults
	// of journal.DefaultOptions (100000 heights, 8 GiB).
	KeepHeights uint64
	MaxBytes    int64
}

JournalConfig configures the message journal (package observe/journal): the steps of the consensus core and the outcomes of received messages, in DataDir/journal, for analysis and replay. A validator keeps it unless Disabled is set (journal.DefaultEnabled); a node without a key runs no core and keeps none.

type MempoolConfig

type MempoolConfig struct {
	// Ordering names the ordering policy: "fifo" (the default) or one of
	// Deps.Orderings. An unknown name refuses the start.
	Ordering string
	// Limits bound the pool.
	Limits mempool.Config
}

MempoolConfig configures the transaction pool of a node.

type Node

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

Node is a consensus node: it runs the consensus core for the application and offers the application the Consensus service.

func New

func New(cfg Config, d Deps) (*Node, error)

New returns a node that is not started.

func (*Node) APIs

func (n *Node) APIs() []rpc.API

APIs returns the RPC services of the node for the application's RPC server.

func (*Node) Address

func (n *Node) Address() types.Address

Address returns the address of the node key, or the zero address for a node without a key. It is known after Start.

func (*Node) AdminAPIs

func (n *Node) AdminAPIs() []rpc.API

AdminAPIs returns the administrative methods of the node (admin_wbftSetLogLevels); the application registers them only on IPC or an authenticated endpoint.

func (*Node) AppEvents

func (n *Node) AppEvents() event.AppEmitter

AppEvents returns the channel through which application modules put their records into the node's event stream (event.AppEmitter). Records emitted before Start, or when the node writes no events, are dropped.

func (*Node) Consensus

func (n *Node) Consensus() app.Consensus

Consensus returns the service the application calls.

func (*Node) LogLevels

func (n *Node) LogLevels() logcat.Applied

LogLevels returns the log settings in force.

func (*Node) Logger

func (n *Node) Logger(m logcat.Module) *slog.Logger

Logger returns a logger of module m (logcat.Register for application modules, before the node is made) that writes where the node's lines go, at the level the node's log settings give m.

func (*Node) Mempool

func (n *Node) Mempool() mempool.Pool

Mempool returns the transaction pool, or nil for a node without an admission hook or before Start.

func (*Node) Metrics

func (n *Node) Metrics() *metrics.Registry

Metrics returns the node's metric registry (observe.md 5). The application serves it (metrics.Registry.Handler) or reads it (Gather) and may register its own metrics in it.

func (*Node) Runner

func (n *Node) Runner() *runner.Runner

Runner returns the consensus runner, or nil for a node without a key or before Start.

func (*Node) SetLogLevels

func (n *Node) SetLogLevels(s logcat.Settings, source string) (logcat.Applied, error)

SetLogLevels applies new log settings while the node runs (source: rpc, or config for a reload) and records them; an unknown module changes nothing and returns an error.

func (*Node) SignFloor

func (n *Node) SignFloor() (types.Height, bool)

SignFloor returns the sign floor of the node key and true if one is set. It is known after Start.

func (*Node) Start

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

Start runs the start-up handshake and starts the consensus core:

  1. read the application's Info and check its interface version;
  2. parse and check the chain configuration;
  3. open the write-ahead log and the sign state, and set the sign floor of a taken-over key;
  4. compare the application head with the log and the sign state, and finalize again a decided block the application did not store;
  5. load the authority snapshot of the head;
  6. connect the transport and start the core at head + 1.

func (*Node) Stop

func (n *Node) Stop() error

Stop stops the core, waits for a FinalizeBlock in progress and closes the logs. Notifications after Stop are dropped.

Jump to

Keyboard shortcuts

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