blockchain

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blockchain

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

Blockchain provides Neo blockchain services consumed by NeoFS Inner Ring (hereinafter node). By design, Blockchain does not implement node specifics: instead, it provides the generic functionality of the Neo blockchain, and narrows the rich Neo functionality to the minimum necessary for the node's operation.

Blockchain must be initialized using New constructor. After initialization Blockchain becomes a single-use component that can be started and then stopped. All operations should be executed after Blockchain is started and before it is stopped (any other behavior is undefined).

func New

func New(cfg Config) (res *Blockchain, err error)

New returns new Blockchain configured by the specified Config. New panics if any required Config field is zero or unset. Resulting Blockchain is ready to run. Launched Blockchain should be finally stopped.

func (*Blockchain) BuildWSClient

func (x *Blockchain) BuildWSClient(ctx context.Context) (*rpcclient.WSClient, error)

BuildWSClient initializes rpcclient.WSClient with direct access to the underlying blockchain.

func (*Blockchain) Run

func (x *Blockchain) Run(ctx context.Context) (err error)

Run runs the Blockchain and makes all its functionality available for use. Context break fails startup. Run returns any error encountered which prevented the Blockchain to be started. If Run failed, the Blockchain should no longer be used. After Blockchain has been successfully run, all internal failures are written to the configured listener.

Run should not be called more than once.

Use Stop to stop the Blockchain.

func (*Blockchain) Stop

func (x *Blockchain) Stop()

Stop stops the running Blockchain and frees all its internal resources.

Stop should not be called twice and before successful Run.

type Config

type Config struct {
	// Writer of the Blockchain's logs and internal errors.
	//
	// Optional: by default, Blockchain doesn't write logs.
	Logger *zap.Logger

	// Application level error listener. Blockchain writes any internal error to the
	// channel. Error returns of functions (e.g. New) are not pushed. The channel
	// should be regularly checked in order to prevent blocking. Any pop-up error
	// does not allow the Blockchain to fully work, therefore, if it is detected,
	// the blockchain should be stopped.
	//
	// Required.
	ErrorListener chan<- error

	// Identifier of the Neo network.
	//
	// Required.
	NetworkMagic netmode.Magic

	// Initial committee staff.
	//
	// Required.
	Committee keys.PublicKeys

	// Time period (approximate) between two adjacent blocks.
	//
	// Optional: defaults to 15s. Must not be negative.
	BlockInterval time.Duration

	// Neo RPC service configuration.
	//
	// Optional: see RPCConfig defaults.
	RPC RPCConfig

	// Length of the chain accessible to smart contracts.
	//
	// Optional: defaults to 2102400.
	TraceableChainLength uint32

	// Maps hard-fork's name to the appearance chain height.
	//
	// Optional: by default, each known hard-fork is applied from the zero
	// blockchain height.
	HardForks map[string]uint32

	// List of nodes' addresses to communicate with over Neo P2P protocol in
	// 'host:port' format.
	//
	// Optional: by default, node runs as standalone.
	SeedNodes []string

	// P2P settings.
	//
	// Required.
	P2P P2PConfig

	// Storage configuration. Must be set using one of constructors like BoltDB.
	//
	// Required.
	Storage StorageConfig

	// NEO wallet of the node. The wallet is used by Consensus and Notary services.
	//
	// Required.
	Wallet config.Wallet

	// Maps chain height to number of consensus nodes.
	//
	// Optional: by default Committee size is used. Each value must be positive and
	// must not exceed Committee length. Value for zero key (genesis height) is
	// required.
	ValidatorsHistory map[uint32]uint32

	// Whether to designate [noderoles.P2PNotary] and [noderoles.NeoFSAlphabet]
	// roles to the Committee (keep an eye on ValidatorsHistory) for genesis block
	// in the RoleManagement contract.
	//
	// Optional: by default, roles are unset.
	SetRolesInGenesis bool
}

Config configures Blockchain. All required fields must be set. Specified optional fields tune Blockchain's default behavior (zero or omitted values).

See docs of NeoGo configuration for some details.

type P2PConfig

type P2PConfig struct {
	// Specifies the minimum number of peers a node needs for normal operation.
	//
	// Required. Must not be larger than math.MaxInt32.
	MinPeers uint

	// Specifies how many peers node should try to dial when connection counter
	// drops below the MinPeers value.
	//
	// Optional: defaults to MinPeers+10. Must not be greater than math.MaxInt32.
	AttemptConnPeers uint

	// Limits maximum number of peers dealing with the node.
	//
	// Optional: defaults to 100. Must not be larger than math.MaxInt32.
	MaxPeers uint

	// Pinging mechanism.
	//
	// Optional: see P2PConfig defaults.
	Ping PingConfig

	// Maximum duration a single dial may take.
	//
	// Optional: defaults to 5s. Must not be negative.
	DialTimeout time.Duration

	// Interval between protocol ticks with each connected peer.
	//
	// Optional: defaults to 2s. Must not be negative.
	ProtoTickInterval time.Duration

	// Network addresses to listen Neo P2P on. Each element must be a valid TCP
	// address in 'host:port' format.
	//
	// Optional: by default, Neo P2P is not served.
	ListenAddresses []string
}

P2PConfig configures communication over Neo P2P protocol.

type PingConfig

type PingConfig struct {
	// Interval between pings.
	//
	// Optional: defaults to 30s. Must not be negative.
	Interval time.Duration

	// Time period to wait for pong.
	//
	// Optional: defaults to 1m. Must not be negative.
	Timeout time.Duration
}

PingConfig configures P2P pinging mechanism.

type RPCConfig added in v0.37.0

type RPCConfig struct {
	// Network addresses to listen Neo RPC on. Each element must be a valid TCP
	// address in 'host:port' format.
	//
	// Optional: by default, insecure Neo RPC is not served.
	Addresses []string

	// Additional addresses that use TLS.
	//
	// Optional.
	TLSConfig
}

RPCConfig configures RPC serving.

type StorageConfig

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

StorageConfig configures Blockchain storage.

func BoltDB

func BoltDB(path string) StorageConfig

BoltDB configures Blockchain to use BoltDB located in given path.

func InMemory

func InMemory() StorageConfig

InMemory configures Blockchain to use volatile RAM storage.

func LevelDB

func LevelDB(path string) StorageConfig

LevelDB configures Blockchain to use LevelDB located in given path.

type TLSConfig added in v0.37.0

type TLSConfig struct {
	// Additional TLS serving switcher.
	//
	// Optional: by default TLS is switched off.
	Enabled bool

	// Network addresses to listen Neo RPC on if Enabled. Each element must be a valid TCP
	// address in 'host:port' format.
	Addresses []string

	// TLS certificate file path.
	//
	// Required if Enabled and one or more addresses are provided.
	CertFile string

	// TLS private key file path.
	//
	// Required if Enabled and one or more addresses are provided.
	KeyFile string
}

TLSConfig configures additional RPC serving over TLS.

Jump to

Keyboard shortcuts

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