node

package
v1.5.9-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package node provides tooling for creating a Sia node. Sia nodes consist of a collection of modules. The node package gives you tools to easily assemble various combinations of modules with varying dependencies and settings, including templates for assembling sane no-hassle Sia nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllModulesTemplate is a template for a Sia node that has all modules
	// enabled.
	AllModulesTemplate = NodeParams{
		CreateAccounting:      true,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           true,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// AccountingTemplate is a template for a Sia node that has a functioning
	// Accounting module. The node has an Accounting module and all dependencies,
	// but no other modules.
	AccountingTemplate = NodeParams{
		CreateAccounting:      true,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           true,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// GatewayTemplate is a template for a Sia node that has a functioning
	// Gateway. The node has a Gateway but no other modules.
	GatewayTemplate = NodeParams{
		CreateAccounting:      false,
		CreateConsensusSet:    false,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: false,
		CreateWallet:          false,
	}
	// HostTemplate is a template for a Sia node that has a functioning host.
	// The node has a host and all dependencies, but no other modules.
	HostTemplate = NodeParams{
		CreateAccounting:      false,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            true,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// MinerTemplate is a template for a Sia node that has a functioning miner.
	// The node has a miner and all dependencies, but no other modules.
	MinerTemplate = NodeParams{
		CreateAccounting:      false,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           true,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// RenterTemplate is a template for a Sia node that has a functioning
	// renter. The node has a renter and all dependencies, but no other
	// modules.
	RenterTemplate = NodeParams{
		CreateAccounting:      false,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          true,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
	// WalletTemplate is a template for a Sia node that has a functioning
	// wallet. The node has a wallet and all dependencies, but no other
	// modules.
	WalletTemplate = NodeParams{
		CreateAccounting:      false,
		CreateConsensusSet:    true,
		CreateExplorer:        false,
		CreateGateway:         true,
		CreateHost:            false,
		CreateMiner:           false,
		CreateRenter:          false,
		CreateTransactionPool: true,
		CreateWallet:          true,
	}
)

Functions

This section is empty.

Types

type Node

type Node struct {
	// The mux of the node.
	Mux *siamux.SiaMux

	// The modules of the node. Modules that are not initialized will be nil.
	Accounting      modules.Accounting
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	Renter          modules.Renter
	TransactionPool modules.TransactionPool
	Wallet          modules.Wallet

	// The high level directory where all the persistence gets stored for the
	// modules.
	Dir string
}

Node is a collection of Sia modules operating together as a Sia node.

func New

func New(params NodeParams, loadStartTime time.Time) (*Node, <-chan error)

New will create a new node. The inputs to the function are the respective 'New' calls for each module. We need to use this awkward method of initialization because the siatest package cannot import any of the modules directly (so that the modules may use the siatest package to test themselves).

func (*Node) Close

func (n *Node) Close() (err error)

Close will call close on every module within the node, combining and returning the errors.

type NodeParams

type NodeParams struct {
	// Flags to indicate which modules should be created automatically by the
	// server. If you are providing a pre-existing module, do not set the flag
	// for that module.
	//
	// NOTE / TODO: The code does not currently enforce this, but you should not
	// provide a custom module unless all of its dependencies are also custom.
	// Example: if the ConsensusSet is custom, the Gateway should also be
	// custom. The TransactionPool however does not need to be custom in this
	// example.
	CreateAccounting      bool
	CreateConsensusSet    bool
	CreateExplorer        bool
	CreateGateway         bool
	CreateHost            bool
	CreateMiner           bool
	CreateRenter          bool
	CreateTransactionPool bool
	CreateWallet          bool

	// Custom modules - if the modules is provided directly, the provided
	// module will be used instead of creating a new one. If a custom module is
	// provided, the 'omit' flag for that module must be set to false (which is
	// the default setting).
	Accounting      modules.Accounting
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	Renter          modules.Renter
	TransactionPool modules.TransactionPool
	Wallet          modules.Wallet

	// Dependencies for each module supporting dependency injection.
	AccountingDeps   modules.Dependencies
	ConsensusSetDeps modules.Dependencies
	ContractorDeps   modules.Dependencies
	ContractSetDeps  modules.Dependencies
	GatewayDeps      modules.Dependencies
	HostDeps         modules.Dependencies
	HostDBDeps       modules.Dependencies
	RenterDeps       modules.Dependencies
	TPoolDeps        modules.Dependencies
	WalletDeps       modules.Dependencies

	// Dependencies for storage monitor supporting dependency injection.
	StorageManagerDeps modules.Dependencies

	// Custom settings for siamux
	SiaMuxTCPAddress string
	SiaMuxWSAddress  string

	// Custom settings for modules
	Allowance   modules.Allowance
	Bootstrap   bool
	UseUPNP     bool
	HostAddress string
	HostStorage uint64
	RPCAddress  string

	// Initialize node from existing seed.
	PrimarySeed string

	// The following fields are used to skip parts of the node set up
	SkipSetAllowance     bool
	SkipHostDiscovery    bool
	SkipHostAnnouncement bool
	SkipWalletInit       bool

	// The high level directory where all the persistence gets stored for the
	// modules.
	Dir string
}

NodeParams contains a bunch of parameters for creating a new test node. As there are many options, templates are provided that you can modify which cover the most common use cases.

Each module is created separately. There are several ways to create a module, though not all methods are currently available for each module. You should only use one method for creating a module, using multiple methods will cause an error.

  • Indicate with the 'CreateModule' bool that a module should be created automatically. To create the module with custom dependencies, pass the custom dependencies in using the 'ModuleDependencies' field.
  • Pass an existing module in directly.
  • Set 'CreateModule' to false and do not pass in an existing module. This will result in a 'nil' module, meaning the node will not have that module.

func Accounting added in v1.5.7

func Accounting(dir string) NodeParams

Accounting returns an AccountingTemplate filled out with the provided dir.

func AllModules

func AllModules(dir string) NodeParams

AllModules returns an AllModulesTemplate filled out with the provided dir.

func Gateway added in v1.4.0

func Gateway(dir string) NodeParams

Gateway returns a GatewayTemplate filled out with the provided dir.

func Host

func Host(dir string) NodeParams

Host returns a HostTemplate filled out with the provided dir.

func Miner added in v1.5.7

func Miner(dir string) NodeParams

Miner returns a MinerTemplate filled out with the provided dir.

func Renter

func Renter(dir string) NodeParams

Renter returns a RenterTemplate filled out with the provided dir.

func Wallet

func Wallet(dir string) NodeParams

Wallet returns a WalletTemplate filled out with the provided dir.

func (NodeParams) NumModules added in v1.5.7

func (np NodeParams) NumModules() (n int)

NumModules returns how many of the major modules the given NodeParams would create.

Directories

Path Synopsis
api
server
Package server provides a server that can wrap a node and serve an http api for interacting with the node.
Package server provides a server that can wrap a node and serve an http api for interacting with the node.

Jump to

Keyboard shortcuts

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