node

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 25 Imported by: 2

Documentation

Overview

Package node provides tooling for creating a ScPrime node. ScPrime 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 ScPrime nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllModulesTemplate is a template for a ScPrime node that has all modules
	// enabled.
	AllModulesTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    true,
		CreateMiner:                   true,
		CreateRenter:                  true,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// FeeManagerTemplate is a template for a ScPrime node that has a functioning
	// FeeManager. The node has a FeeManager and all dependencies, but no other
	// modules.
	FeeManagerTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    false,
		CreateMiner:                   false,
		CreateRenter:                  false,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// GatewayTemplate is a template for a ScPrime node that has a functioning
	// Gateway. The node has a Gateway but no other modules.
	GatewayTemplate = NodeParams{
		CreateConsensusSet:            false,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    false,
		CreateMiner:                   false,
		CreateRenter:                  false,
		CreateTransactionPool:         false,
		CreateWallet:                  false,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// HostTemplate is a template for a ScPrime node that has a functioning host.
	// The node has a host and all dependencies, but no other modules.
	HostTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    true,
		CreateMiner:                   false,
		CreateRenter:                  false,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// MinerTemplate is a template for a ScPrime node that has a functioning miner.
	// The node has a miner and all dependencies, but no other modules.
	MinerTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    false,
		CreateMiner:                   true,
		CreateRenter:                  false,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// RenterTemplate is a template for a ScPrime node that has a functioning
	// renter. The node has a renter and all dependencies, but no other
	// modules.
	RenterTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    false,
		CreateMiner:                   false,
		CreateRenter:                  true,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
	// WalletTemplate is a template for a ScPrime node that has a functioning
	// wallet. The node has a wallet and all dependencies, but no other
	// modules.
	WalletTemplate = NodeParams{
		CreateConsensusSet:            true,
		CreateExplorer:                false,
		CreateGateway:                 true,
		CreateHost:                    false,
		CreateMiner:                   false,
		CreateRenter:                  false,
		CreateTransactionPool:         true,
		CreateWallet:                  true,
		CheckTokenExpirationFrequency: 5 * time.Second,
	}
)

Functions

This section is empty.

Types

type Node

type Node struct {
	// The modules of the node. Modules that are not initialized will be nil.
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	MiningPool      modules.Pool
	StratumMiner    modules.StratumMiner
	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 ScPrime modules operating together as a ScPrime 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.
	CreateConsensusSet    bool
	CreateExplorer        bool
	CreateGateway         bool
	CreateHost            bool
	CreateMiner           bool
	CreateMiningPool      bool
	CreateStratumMiner    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).
	ConsensusSet    modules.ConsensusSet
	Explorer        modules.Explorer
	Gateway         modules.Gateway
	Host            modules.Host
	Miner           modules.TestMiner
	MiningPool      modules.Pool
	StratumMiner    modules.StratumMiner
	Renter          modules.Renter
	TransactionPool modules.TransactionPool
	Wallet          modules.Wallet

	// Dependencies for each module supporting dependency injection.
	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 modules
	Allowance   modules.Allowance
	Bootstrap   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

	// Configuration settings for the Mining pool.
	PoolConfig config.MiningPoolConfig

	HostAPIAddr                   string
	CheckTokenExpirationFrequency time.Duration
	OnlyFirstDir                  bool
}

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 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.0

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.0

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