Documentation
¶
Overview ¶
Package node is the main entry point, where the Node struct, which represents a full node, is defined.
Adding new p2p.Reactor(s)
To add a new p2p.Reactor, use the CustomReactors option:
node, err := NewNode(
config,
privVal,
nodeKey,
clientCreator,
genesisDocProvider,
dbProvider,
metricsProvider,
logger,
CustomReactors(map[string]p2p.Reactor{"CUSTOM": customReactor}),
)
Replacing existing p2p.Reactor(s)
To replace the built-in p2p.Reactor, use the CustomReactors option:
node, err := NewNode(
config,
privVal,
nodeKey,
clientCreator,
genesisDocProvider,
dbProvider,
metricsProvider,
logger,
CustomReactors(map[string]p2p.Reactor{"BLOCKSYNC": customBlocksyncReactor}),
)
The list of existing reactors can be found in CustomReactors documentation.
Index ¶
- func BootstrapState(ctx context.Context, config *cfg.Config, dbProvider cfg.DBProvider, ...) (err error)
- func LoadStateFromDBOrGenesisDocProvider(stateDB dbm.DB, genesisDocProvider GenesisDocProvider, ...) (sm.State, *types.GenesisDoc, error)
- func LoadStateFromDBOrGenesisDocProviderWithConfig(stateDB dbm.DB, genesisDocProvider GenesisDocProvider, ...) (sm.State, *types.GenesisDoc, error)
- type ChecksummedGenesisDoc
- type CliParams
- type ErrorLoadOrGenFilePV
- type GenesisDocProvider
- type IChecksummedGenesisDoc
- type MetricsProvider
- type Node
- func DefaultNewNode(config *cfg.Config, logger log.Logger, cliParams CliParams, ...) (*Node, error)
- func NewNode(ctx context.Context, config *cfg.Config, privValidator types.PrivValidator, ...) (*Node, error)
- func NewNodeWithCliParams(ctx context.Context, config *cfg.Config, privValidator types.PrivValidator, ...) (*Node, error)
- func NewNodeWithServices(config *cfg.Config, genDoc *types.GenesisDoc, nodeInfo p2p.NodeInfo, ...) *Node
- func (n *Node) BlockStore() *store.BlockStore
- func (n *Node) Config() *cfg.Config
- func (n *Node) ConfigureRPC() (*rpccore.Environment, error)
- func (n *Node) ConsensusReactor() *cs.Reactor
- func (n *Node) EventBus() *types.EventBus
- func (n *Node) EvidencePool() *evidence.Pool
- func (n *Node) GenesisDoc() *types.GenesisDoc
- func (n *Node) IsListening() bool
- func (n *Node) Listeners() []string
- func (n *Node) Mempool() mempl.Mempool
- func (n *Node) MempoolReactor() p2p.Reactor
- func (n *Node) NodeInfo() p2p.NodeInfo
- func (n *Node) NodeKey() *p2p.NodeKey
- func (n *Node) OnStart() error
- func (n *Node) OnStop()
- func (n *Node) PEXReactor() *pex.Reactor
- func (n *Node) PrivValidator() types.PrivValidator
- func (n *Node) ProxyApp() proxy.AppConns
- func (n *Node) SetPrivValidator(pv types.PrivValidator)
- func (n *Node) SetWalFile(walFile string)
- func (n *Node) Switch() *p2p.Switch
- type Option
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BootstrapState ¶
func BootstrapState(ctx context.Context, config *cfg.Config, dbProvider cfg.DBProvider, genProvider GenesisDocProvider, height uint64, appHash []byte) (err error)
BootstrapState synchronizes the stores with the application after state sync has been performed offline. It is expected that the block store and state store are empty at the time the function is called.
If the block store is not empty, the function returns an error.
func LoadStateFromDBOrGenesisDocProvider ¶
func LoadStateFromDBOrGenesisDocProvider( stateDB dbm.DB, genesisDocProvider GenesisDocProvider, operatorGenesisHashHex string, ) (sm.State, *types.GenesisDoc, error)
Note that if you don't have a version of the key layout set in your DB already, and no config is passed, it will default to v1.
Types ¶
type ChecksummedGenesisDoc ¶
type ChecksummedGenesisDoc struct {
GenesisDoc *types.GenesisDoc
Sha256Checksum []byte
}
ChecksummedGenesisDoc combines a GenesisDoc together with its SHA256 checksum.
func (*ChecksummedGenesisDoc) DefaultGenesisDoc ¶
func (c *ChecksummedGenesisDoc) DefaultGenesisDoc() (*types.GenesisDoc, error)
DefaultGenesisDoc() implements IChecksummedGenesisDoc.
func (*ChecksummedGenesisDoc) GenesisDocByChainID ¶
func (c *ChecksummedGenesisDoc) GenesisDocByChainID(_ string) (*types.GenesisDoc, error)
GenesisDocByChainID() implements IChecksummedGenesisDoc.
func (*ChecksummedGenesisDoc) GetChecksum ¶
func (c *ChecksummedGenesisDoc) GetChecksum() []byte
GetChecksum() implements IChecksummedGenesisDoc.
type CliParams ¶
type CliParams struct {
// SHA-256 hash of the genesis file provided via the command line.
// This hash is used is compared against the computed hash of the
// actual genesis file or the hash stored in the database.
// If there is a mismatch between the hash provided via cli and the
// hash of the genesis file or the hash in the DB, the node will not boot.
GenesisHash []byte
}
Introduced to store parameters passed via cli and needed to start the node. This parameters should not be stored or persisted in the config file. This can then be further extended to include additional flags without further API breaking changes.
type ErrorLoadOrGenFilePV ¶
ErrorLoadOrGenFilePV is returned when the node fails to load or generate priv validator file.
func (ErrorLoadOrGenFilePV) Error ¶
func (e ErrorLoadOrGenFilePV) Error() string
func (ErrorLoadOrGenFilePV) Unwrap ¶
func (e ErrorLoadOrGenFilePV) Unwrap() error
type GenesisDocProvider ¶
type GenesisDocProvider func() (IChecksummedGenesisDoc, error)
GenesisDocProvider returns a GenesisDoc together with its SHA256 checksum. It allows the GenesisDoc to be pulled from sources other than the filesystem, for instance from a distributed key-value store cluster.
func DefaultGenesisDocProviderFunc ¶
func DefaultGenesisDocProviderFunc(config *cfg.Config) GenesisDocProvider
DefaultGenesisDocProviderFunc returns a GenesisDocProvider that loads the GenesisDoc from the config.GenesisFile() on the filesystem. Default behavior expects *singular mode* such that config.GenesisFile() contains the JSON of just *one* genesis instance.
type IChecksummedGenesisDoc ¶
type IChecksummedGenesisDoc interface {
DefaultGenesisDoc() (*types.GenesisDoc, error)
GenesisDocByChainID(chainID string) (*types.GenesisDoc, error)
GetChecksum() []byte
}
IChecksummedGenesisDoc provides at least with a default genesis doc and its SHA256 checksum.
type MetricsProvider ¶
type MetricsProvider func(chainID string) (*cs.Metrics, *p2p.Metrics, *mempl.Metrics, *sm.Metrics, *store.Metrics, *proxy.Metrics, *blocksync.Metrics, *statesync.Metrics)
MetricsProvider returns a consensus, p2p and mempool Metrics.
func DefaultMetricsProvider ¶
func DefaultMetricsProvider(config *cfg.InstrumentationConfig) MetricsProvider
DefaultMetricsProvider returns Metrics build using Prometheus client library if Prometheus is enabled. Otherwise, it returns no-op Metrics.
type Node ¶
type Node struct {
service.BaseService
// contains filtered or unexported fields
}
Node is the highest level interface to a full CometBFT node. It includes all configuration information and running services.
func DefaultNewNode ¶
func DefaultNewNode( config *cfg.Config, logger log.Logger, cliParams CliParams, keyGenF func() (crypto.PrivKey, error), ) (*Node, error)
DefaultNewNode returns a CometBFT node with default settings for the PrivValidator, ClientCreator, GenesisDoc, and DBProvider. It implements Provider.
func NewNode ¶
func NewNode(ctx context.Context, config *cfg.Config, privValidator types.PrivValidator, nodeKey *p2p.NodeKey, clientCreator proxy.ClientCreator, genesisDocProvider GenesisDocProvider, dbProvider cfg.DBProvider, metricsProvider MetricsProvider, logger log.Logger, options ...Option, ) (*Node, error)
NewNode returns a new, ready to go, CometBFT Node.
func NewNodeWithCliParams ¶
func NewNodeWithCliParams(ctx context.Context, config *cfg.Config, privValidator types.PrivValidator, nodeKey *p2p.NodeKey, clientCreator proxy.ClientCreator, genesisDocProvider GenesisDocProvider, dbProvider cfg.DBProvider, metricsProvider MetricsProvider, logger log.Logger, cliParams CliParams, options ...Option, ) (*Node, error)
func NewNodeWithServices ¶
func NewNodeWithServices( config *cfg.Config, genDoc *types.GenesisDoc, nodeInfo p2p.NodeInfo, nodeKey *p2p.NodeKey, privValidator types.PrivValidator, addrBook pex.AddrBook, transport *p2p.MultiplexTransport, sw *p2p.Switch, eventBus *types.EventBus, proxyApp proxy.AppConns, mempool mempl.Mempool, evidencePool *evidence.Pool, pruner *sm.Pruner, indexerService *txindex.IndexerService, stateStore sm.Store, blockStore *store.BlockStore, consensusState *cs.State, stateSync bool, stateSyncGenesis sm.State, ) *Node
NewNodeWithServices returns a new, ready to go, CometBFT node.
This method creates a Node instance of which all services are created asynchronously. It permits to externalize (or export) the initialization of required node services.
Note that p2p.BaseReactor implementing instances are retrieved from the switch instance defined with p2p.Switch. This drastically reduces the amount of memory allocated when creating the instance.
func (*Node) BlockStore ¶
func (n *Node) BlockStore() *store.BlockStore
BlockStore returns the Node's BlockStore.
func (*Node) ConfigureRPC ¶
func (n *Node) ConfigureRPC() (*rpccore.Environment, error)
ConfigureRPC makes sure RPC has all the objects it needs to operate.
func (*Node) ConsensusReactor ¶
ConsensusReactor returns the Node's ConsensusReactor.
func (*Node) EvidencePool ¶
EvidencePool returns the Node's EvidencePool.
func (*Node) GenesisDoc ¶
func (n *Node) GenesisDoc() *types.GenesisDoc
GenesisDoc returns the Node's GenesisDoc.
func (*Node) IsListening ¶
func (*Node) MempoolReactor ¶
MempoolReactor returns the Node's mempool reactor.
func (*Node) NodeKey ¶
NodeKey returns the node's p2p key as defined with p2p.NodeKey.
func (*Node) PEXReactor ¶
PEXReactor returns the Node's PEXReactor. It returns nil if PEX is disabled.
func (*Node) PrivValidator ¶
func (n *Node) PrivValidator() types.PrivValidator
PrivValidator returns the Node's PrivValidator. XXX: for convenience only!
func (*Node) ProxyApp ¶
ProxyApp returns the Node's AppConns, representing its connections to the ABCI application.
func (*Node) SetPrivValidator ¶
func (n *Node) SetPrivValidator(pv types.PrivValidator)
SetPrivValidator sets the types.PrivValidator instance.
func (*Node) SetWalFile ¶
SetWalFile sets the WAL file path in the [config.ConsensusConfig].
type Option ¶
type Option func(*Node)
Option sets a parameter for the node.
func CustomReactors ¶
CustomReactors allows you to add custom reactors (name -> p2p.Reactor) to the node's Switch.
WARNING: using any name from the below list of the existing reactors will result in replacing it with the custom one.
- MEMPOOL
- BLOCKSYNC
- CONSENSUS
- EVIDENCE
- PEX
- STATESYNC
func StateProvider ¶
func StateProvider(stateProvider statesync.StateProvider) Option
StateProvider overrides the state provider used by state sync to retrieve trusted app hashes and build a State object for bootstrapping the node. WARNING: this interface is considered unstable and subject to change.