node

package
v0.2.16-beta.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 58 Imported by: 0

Documentation

Overview

Package node contains the main executable for go-spacemesh node

Index

Constants

View Source
const (
	AppLogger              = "app"
	P2PLogger              = "p2p"
	PostLogger             = "post"
	StateDbLogger          = "stateDbStore"
	BeaconLogger           = "beacon"
	StoreLogger            = "store"
	PoetDbLogger           = "poetDb"
	MeshDBLogger           = "meshDb"
	TrtlLogger             = "trtl"
	AtxDbLogger            = "atxDb"
	MeshLogger             = "mesh"
	SyncLogger             = "sync"
	HareOracleLogger       = "hareOracle"
	HareLogger             = "hare"
	BlockGenLogger         = "blockGenerator"
	BlockHandlerLogger     = "blockHandler"
	TxHandlerLogger        = "txHandler"
	ProposalBuilderLogger  = "proposalBuilder"
	ProposalListenerLogger = "proposalListener"
	ProposalDBLogger       = "proposalStore"
	PoetListenerLogger     = "poetListener"
	NipostBuilderLogger    = "nipostBuilder"
	LayerFetcher           = "layerFetcher"
	TimeSyncLogger         = "timesync"
	SVMLogger              = "SVM"
	GRPCLogger             = "grpc"
	ConStateLogger         = "conState"
)

Logger names.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "node",
	Short: "start node",
	Run: func(cmd *cobra.Command, args []string) {
		conf, err := loadConfig(cmd)
		if err != nil {
			log.With().Fatal("failed to initialize config", log.Err(err))
		}

		if conf.LOGGING.Encoder == config.JSONLogEncoder {
			log.JSONLog(true)
		}
		app := New(
			WithConfig(conf),

			WithLog(log.RegisterHooks(
				log.NewWithLevel("", zap.NewAtomicLevelAt(zapcore.DebugLevel)),
				events.EventHook())),
		)
		starter := func() error {
			if err := app.Initialize(); err != nil {
				return fmt.Errorf("init node: %w", err)
			}

			if err := app.Start(); err != nil {
				return fmt.Errorf("start node: %w", err)
			}

			return nil
		}
		err = starter()
		app.Cleanup()
		if err != nil {
			log.With().Fatal("Failed to run the node. See logs for details.", log.Err(err))
		}
	},
}

Cmd is the cobra wrapper for the node, that allows adding parameters to it.

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Show version info",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Print(cmdp.Version)
		if cmdp.Commit != "" {
			fmt.Printf("+%s", cmdp.Commit)
		}
		fmt.Println()
	},
}

VersionCmd returns the current version of spacemesh.

Functions

func LoadConfigFromFile

func LoadConfigFromFile() (*config.Config, error)

LoadConfigFromFile tries to load configuration file if the config parameter was specified.

Types

type App

type App struct {
	*cobra.Command

	Config *config.Config
	// contains filtered or unexported fields
}

App is the cli app singleton.

func New

func New(opts ...Option) *App

New creates an instance of the spacemesh app.

func (*App) Cleanup

func (app *App) Cleanup()

Cleanup stops all app services.

func (*App) HareFactory

func (app *App) HareFactory(
	ctx context.Context,
	sgn hare.Signer,
	blockGen *blocks.Generator,
	nodeID types.NodeID,
	patrol *layerpatrol.LayerPatrol,
	syncer system.SyncStateProvider,
	msh *mesh.Mesh,
	proposalDB *proposals.DB,
	beacons system.BeaconGetter,
	pFetcher system.ProposalFetcher,
	hOracle hare.Rolacle,
	clock TickProvider,
	lg log.Log,
) HareService

HareFactory returns a hare consensus algorithm according to the parameters in app.Config.Hare.SuperHare.

func (*App) Initialize

func (app *App) Initialize() (err error)

Initialize sets up an exit signal, logging and checks the clock, returns error if clock is not in sync.

func (*App) LoadOrCreateEdSigner

func (app *App) LoadOrCreateEdSigner() (*signing.EdSigner, error)

LoadOrCreateEdSigner either loads a previously created ed identity for the node or creates a new one if not exists.

func (*App) SetLogLevel

func (app *App) SetLogLevel(name, loglevel string) error

SetLogLevel updates the log level of an existing logger.

func (*App) Start

func (app *App) Start() error

Start starts the Spacemesh node and initializes all relevant services according to command line arguments provided.

type HareService

type HareService interface {
	Service
	GetHareMsgHandler() pubsub.GossipHandler
}

HareService is basic definition of hare algorithm service, providing consensus results for a layer.

type Option

type Option func(app *App)

Option to modify an App instance.

func WithConfig

func WithConfig(conf *config.Config) Option

WithConfig overvwrites default App config.

func WithLog

func WithLog(logger log.Log) Option

WithLog enables logger for an App.

type Service

type Service interface {
	Start(ctx context.Context) error
	Close()
}

Service is a general service interface that specifies the basic start/stop functionality.

type TickProvider

type TickProvider interface {
	Subscribe() timesync.LayerTimer
	Unsubscribe(timesync.LayerTimer)
	GetCurrentLayer() types.LayerID
	StartNotifying()
	GetGenesisTime() time.Time
	LayerToTime(types.LayerID) time.Time
	Close()
	AwaitLayer(types.LayerID) chan struct{}
}

TickProvider is an interface to a glopbal system clock that releases ticks on each layer.

Jump to

Keyboard shortcuts

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