node

package
v0.0.0-...-e495fa0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: GPL-3.0, LGPL-3.0 Imports: 45 Imported by: 0

Documentation

Overview

Package eth implements the Shx protocol.

Package node sets up multi-protocol Shx nodes.

In the model exposed by this package, a node is a collection of services which use shared resources to provide RPC APIs. Services can also offer devp2p protocols, which are wired up to the devp2p network when the node instance is started.

Resources Managed By Node

All file-system resources used by a node instance are located in a directory called the data directory. The location of each resource can be overridden through additional node configuration. The data directory is optional. If it is not set and the location of a resource is otherwise unspecified, package node will create the resource in memory.

To access to the devp2p network, Node configures and starts p2p.Server. Each host on the devp2p network has a unique identifier, the node key. The Node instance persists this key across restarts. Node also loads static and trusted node lists and ensures that knowledge about other hosts is persisted.

JSON-RPC servers which run HTTP, WebSocket or IPC can be started on a Node. RPC modules offered by registered services will be offered on those endpoints. Users can restrict any endpoint to a subset of RPC modules. Node itself offers the "debug", "admin" and "web3" modules.

Service implementations can open LevelDB databases through the service context. Package node chooses the file system location of each database. If the node is configured to run without a data directory, databases are opened in memory instead.

Node also creates the shared store of encrypted Shx account keys. Services can access the account manager through the service context.

Sharing Data Directory Among Instances

Multiple node instances can share a single data directory if they have distinct instance names (set through the Name config option). Sharing behaviour depends on the type of resource.

devp2p-related resources (node key, static/trusted node lists, known hosts database) are stored in a directory with the same name as the instance. Thus, multiple node instances using the same data directory will store this information in different subdirectories of the data directory.

LevelDB databases are also stored within the instance subdirectory. If multiple node instances use the same data directory, openening the databases with identical names will create one database for each instance.

The account key store is shared among all node instances using the same data directory unless its location is changed through the KeyStoreDir configuration option.

Data Directory Sharing Example

In this example, two node instances named A and B are started with the same data directory. Mode instance A opens the database "db", node instance B opens the databases "db" and "db-2". The following files will be created in the data directory:

data-directory/
     A/
         nodekey            -- devp2p node key of instance A
         nodes/             -- devp2p discovery knowledge database of instance A
         db/                -- LevelDB content for "db"
     A.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance A
     B/
         nodekey            -- devp2p node key of node B
         nodes/             -- devp2p discovery knowledge database of instance B
         static-nodes.json  -- devp2p static node list of instance B
         db/                -- LevelDB content for "db"
         db-2/              -- LevelDB content for "db-2"
     B.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance A
     keystore/              -- account key store, used by both instances

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatadirUsed    = errors.New("datadir already used by another process")
	ErrNodeStopped    = errors.New("node not started")
	ErrNodeRunning    = errors.New("node already running")
	ErrServiceUnknown = errors.New("unknown service")
)

Functions

func NewBloomIndexer

func NewBloomIndexer(db shxdb.Database, size uint64) *bc.ChainIndexer

NewBloomIndexer returns a chain indexer that generates bloom bits data for the canonical chain for fast logs filtering.

Types

type BloomIndexer

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

BloomIndexer implements a bc.ChainIndexer, building up a rotated bloom bits index for the Shx header bloom filters, permitting blazing fast filtering.

func (*BloomIndexer) Commit

func (b *BloomIndexer) Commit() error

Commit implements bc.ChainIndexerBackend, finalizing the bloom section and writing it out into the database.

func (*BloomIndexer) Process

func (b *BloomIndexer) Process(header *types.Header)

Process implements bc.ChainIndexerBackend, adding a new header's bloom into the index.

func (*BloomIndexer) Reset

func (b *BloomIndexer) Reset(section uint64)

Reset implements bc.ChainIndexerBackend, starting a new bloombits index section.

type ConsensuscfgF

type ConsensuscfgF struct {
	HpNodesNum       int      //`json:"HpNodesNum"` 			//hp nodes number
	HpVotingRndScope int      //`json:"HpVotingRndScope"`		//hp voting rand selection scope
	FinalizeRetErrIg bool     //`json:"FinalizeRetErrIg"`	 	//finalize return err ignore
	Time             int      //`json:"Time"`					//gen block interval
	Nodeids          []string //`json:"Nodeids"`				//bootnode`s nodeid only add one
}

type DuplicateServiceError

type DuplicateServiceError struct {
	Kind reflect.Type
}

DuplicateServiceError is returned during Node startup if a registered service constructor returns a service of the same type that was already started.

func (*DuplicateServiceError) Error

func (e *DuplicateServiceError) Error() string

Error generates a textual representation of the duplicate service error.

type LesServer

type LesServer interface {
	Start(srvr *p2p.Server)
	Stop()
	Protocols() []p2p.Protocol
}

type Node

type Node struct {
	Shxconfig      *config.ShxConfig
	Shxpeermanager *p2p.PeerManager
	Shxrpcmanager  *rpc.RpcManager
	Shxsyncctr     *synctrl.SynCtrl
	Shxtxpool      *txpool.TxPool
	Shxbc          *bc.BlockChain
	//ShxDb
	ShxDb shxdb.Database

	Shxengine consensus.Engine

	ApiBackend *ShxApiBackend

	RpcAPIs []rpc.API // List of APIs currently provided by the node
	// contains filtered or unexported fields
}

Node is a container on which services can be registered.

func New

func New(conf *config.ShxConfig) (*Node, error)

New creates a shx node, create all object and start

func (*Node) APIAccountManager

func (s *Node) APIAccountManager() *accounts.Manager

func (*Node) APIs

func (s *Node) APIs() []rpc.API

APIs returns the collection of RPC services the shx package offers. NOTE, some of these services probably need to be moved to somewhere else.

func (*Node) AccountManager

func (n *Node) AccountManager() *accounts.Manager

AccountManager retrieves the account manager used by the protocol stack.

func (*Node) Attach

func (n *Node) Attach(ipc *rpc.Server) (*rpc.Client, error)

Attach creates an RPC client attached to an in-process API handler.

func (*Node) BlockChain

func (s *Node) BlockChain() *bc.BlockChain

func (*Node) ChainDb

func (s *Node) ChainDb() shxdb.Database

func (*Node) DataDir

func (n *Node) DataDir() string

DataDir retrieves the current datadir used by the protocol stack. Deprecated: No files should be stored in this directory, use InstanceDir instead.

func (*Node) Engine

func (s *Node) Engine() consensus.Engine

func (*Node) GetAPI

func (n *Node) GetAPI() error

get all rpc api from modules

func (*Node) InstanceDir

func (n *Node) InstanceDir() string

InstanceDir retrieves the instance directory used by the protocol stack.

func (*Node) IsListening

func (s *Node) IsListening() bool

func (*Node) IsMining

func (s *Node) IsMining() bool

func (*Node) Miner

func (s *Node) Miner() *worker.Miner

func (*Node) NetVersion

func (s *Node) NetVersion() uint64

func (*Node) NewBlockMux

func (n *Node) NewBlockMux() *sub.TypeMux

EventMux retrieves the event multiplexer used by all the network services in the current protocol stack.

func (*Node) Nodeapis

func (n *Node) Nodeapis() []rpc.API

apis returns the collection of RPC descriptors this node offers.

func (*Node) RPCHandler

func (n *Node) RPCHandler() (*rpc.Server, error)

RPCHandler returns the in-process RPC request handler.

func (*Node) ResetWithGenesisBlock

func (s *Node) ResetWithGenesisBlock(gb *types.Block)

func (*Node) ResolvePath

func (n *Node) ResolvePath(x string) string

ResolvePath returns the absolute path of a resource in the instance directory.

func (*Node) Restart

func (n *Node) Restart() error

Restart terminates a running node and boots up a new one in its place. If the node isn't running, an error is returned.

func (*Node) SetNodeAPI

func (n *Node) SetNodeAPI() error

func (*Node) SetOpt

func (s *Node) SetOpt(maxtxs, peorid int)

func (*Node) SetShxerbase

func (self *Node) SetShxerbase(hpberbase common.Address)

set in js console via admin interface or wrapper from cli flags

func (*Node) ShxVersion

func (s *Node) ShxVersion() int

func (*Node) Shxerbase

func (s *Node) Shxerbase() (eb common.Address, err error)

func (*Node) Start

func (hpbnode *Node) Start(conf *config.ShxConfig) error

func (*Node) StartMining

func (s *Node) StartMining(local bool) error

func (*Node) Stop

func (n *Node) Stop() error

Stop terminates a running node along with all it's services. In the node was not started, an error is returned.

func (*Node) StopMining

func (s *Node) StopMining()

func (*Node) TxPool

func (s *Node) TxPool() *txpool.TxPool

func (*Node) Wait

func (n *Node) Wait()

Wait blocks the thread until the node is stopped. If the node is not running at the time of invocation, the method immediately returns.

func (*Node) WorkerInit

func (hpbnode *Node) WorkerInit(conf *config.ShxConfig) error

type PrivateAdminAPI

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

PrivateAdminAPI is the collection of Shx full node-related APIs exposed over the private admin endpoint.

func NewPrivateAdminAPI

func NewPrivateAdminAPI(shx *Node) *PrivateAdminAPI

NewPrivateAdminAPI creates a new API definition for the full node private admin methods of the Shx service.

func (*PrivateAdminAPI) ExportChain

func (api *PrivateAdminAPI) ExportChain(file string) (bool, error)

ExportChain exports the current blockchain into a local file.

func (*PrivateAdminAPI) ImportChain

func (api *PrivateAdminAPI) ImportChain(file string) (bool, error)

ImportChain imports a blockchain from a local file.

type PrivateDebugAPI

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

PrivateDebugAPI is the collection of Shx full node APIs exposed over the private debugging endpoint.

func NewPrivateDebugAPI

func NewPrivateDebugAPI(config *config.ChainConfig, hpb *Node) *PrivateDebugAPI

NewPrivateDebugAPI creates a new API definition for the full node-related private debug methods of the Shx service.

func (*PrivateDebugAPI) GetBadBlocks

func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]bc.BadBlockArgs, error)

GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network and returns them as a JSON list of block-hashes

func (*PrivateDebugAPI) Preimage

func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hexutil.Bytes, error)

Preimage is a debug API function that returns the preimage for a sha3 hash, if known.

type PrivateMinerAPI

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

PrivateMinerAPI provides private RPC methods tso control the miner. These methods can be abused by external users and must be considered insecure for use by untrusted users.

func NewPrivateMinerAPI

func NewPrivateMinerAPI(e *Node) *PrivateMinerAPI

NewPrivateMinerAPI create a new RPC service which controls the miner of this node.

func (*PrivateMinerAPI) SetExtra

func (api *PrivateMinerAPI) SetExtra(extra string) (bool, error)

SetExtra sets the extra data string that is included when this miner mines a block.

func (*PrivateMinerAPI) SetOpt

func (api *PrivateMinerAPI) SetOpt(maxtxs int, peorid int) error

func (*PrivateMinerAPI) SetShxerbase

func (api *PrivateMinerAPI) SetShxerbase(shxerbase common.Address) bool

SetShxerbase sets the shxerbase of the miner

func (*PrivateMinerAPI) Start

func (api *PrivateMinerAPI) Start(threads *int) error

Start the miner with the given number of threads. If threads is nil the number of workers started is equal to the number of logical CPUs that are usable by this process. If mining is already running, this method adjust the number of threads allowed to use.

func (*PrivateMinerAPI) Stop

func (api *PrivateMinerAPI) Stop() bool

Stop the miner

type PublicAdminAPI

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

PublicAdminAPI is the collection of administrative API methods exposed over both secure and unsecure RPC channels.

func NewPublicAdminAPI

func NewPublicAdminAPI(node *Node) *PublicAdminAPI

NewPublicAdminAPI creates a new API definition for the public admin methods of the node itself.

func (*PublicAdminAPI) Datadir

func (api *PublicAdminAPI) Datadir() string

Datadir retrieves the current data directory the node is using.

func (*PublicAdminAPI) NodeInfo

func (api *PublicAdminAPI) NodeInfo() (*p2p.NodeInfo, error)

NodeInfo retrieves all the information we know about the host node at the protocol granularity.

func (*PublicAdminAPI) Peers

func (api *PublicAdminAPI) Peers() ([]*p2p.PeerInfo, error)

Peers retrieves all the information we know about each individual peer at the protocol granularity.

type PublicDebugAPI

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

PublicDebugAPI is the collection of Shx full node APIs exposed over the public debugging endpoint.

func NewPublicDebugAPI

func NewPublicDebugAPI(hpb *Node) *PublicDebugAPI

NewPublicDebugAPI creates a new API definition for the full node- related public debug methods of the Shx service.

func (*PublicDebugAPI) DumpBlock

func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error)

DumpBlock retrieves the entire state of the database at a given block.

type PublicShxAPI

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

PublicShxAPI provides an API to access Shx full node-related information.

func NewPublicShxAPI

func NewPublicShxAPI(e *Node) *PublicShxAPI

NewPublicShxAPI creates a new Shx protocol API for full nodes.

func (*PublicShxAPI) Coinbase

func (api *PublicShxAPI) Coinbase() (common.Address, error)

Coinbase is the address that mining rewards will be send to (alias for Shxerbase)

func (*PublicShxAPI) Mining

func (api *PublicShxAPI) Mining() bool

Mining returns the miner is mining

func (*PublicShxAPI) Shxerbase

func (api *PublicShxAPI) Shxerbase() (common.Address, error)

Shxerbase is the address that mining rewards will be send to

type PublicWeb3API

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

PublicWeb3API offers helper utils

func NewPublicWeb3API

func NewPublicWeb3API(stack *Node) *PublicWeb3API

NewPublicWeb3API creates a new Web3Service instance

func (*PublicWeb3API) ClientVersion

func (s *PublicWeb3API) ClientVersion() string

ClientVersion returns the node name

func (*PublicWeb3API) Sha3

func (s *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes

Sha3 applies the hpb sha3 implementation on the input. It assumes the input is hex encoded.

type ShxApiBackend

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

ShxApiBackend implements ethapi.Backend for full nodes

func (*ShxApiBackend) AccountManager

func (b *ShxApiBackend) AccountManager() *accounts.Manager

func (*ShxApiBackend) BlockByNumber

func (b *ShxApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)

func (*ShxApiBackend) BloomStatus

func (b *ShxApiBackend) BloomStatus() (uint64, uint64)

func (*ShxApiBackend) ChainConfig

func (b *ShxApiBackend) ChainConfig() *config.ChainConfig

func (*ShxApiBackend) ChainDb

func (b *ShxApiBackend) ChainDb() shxdb.Database

func (*ShxApiBackend) CurrentBlock

func (b *ShxApiBackend) CurrentBlock() *types.Block

func (*ShxApiBackend) EventMux

func (b *ShxApiBackend) EventMux() *sub.TypeMux

func (*ShxApiBackend) GetBlock

func (b *ShxApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)

func (*ShxApiBackend) GetPoolNonce

func (b *ShxApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)

func (*ShxApiBackend) GetPoolTransaction

func (b *ShxApiBackend) GetPoolTransaction(hash common.Hash) *types.Transaction

func (*ShxApiBackend) GetPoolTransactions

func (b *ShxApiBackend) GetPoolTransactions() (types.Transactions, error)

func (*ShxApiBackend) GetReceipts

func (b *ShxApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)

func (*ShxApiBackend) GetTd

func (b *ShxApiBackend) GetTd(blockHash common.Hash) *big.Int

func (*ShxApiBackend) HeaderByNumber

func (b *ShxApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)

func (*ShxApiBackend) ProtocolVersion

func (b *ShxApiBackend) ProtocolVersion() int

func (*ShxApiBackend) SendTx

func (b *ShxApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error

func (*ShxApiBackend) ServiceFilter

func (b *ShxApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

func (*ShxApiBackend) SetHead

func (b *ShxApiBackend) SetHead(number uint64)

func (*ShxApiBackend) StateAndHeaderByNumber

func (b *ShxApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)

func (*ShxApiBackend) Stats

func (b *ShxApiBackend) Stats() (pending int, queued int)

func (*ShxApiBackend) SubscribeChainEvent

func (b *ShxApiBackend) SubscribeChainEvent(ch chan<- bc.ChainEvent) sub.Subscription

func (*ShxApiBackend) SubscribeChainHeadEvent

func (b *ShxApiBackend) SubscribeChainHeadEvent(ch chan<- bc.ChainHeadEvent) sub.Subscription

func (*ShxApiBackend) SubscribeLogsEvent

func (b *ShxApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) sub.Subscription

func (*ShxApiBackend) SubscribeRemovedLogsEvent

func (b *ShxApiBackend) SubscribeRemovedLogsEvent(ch chan<- bc.RemovedLogsEvent) sub.Subscription

func (*ShxApiBackend) SubscribeTxPreEvent

func (b *ShxApiBackend) SubscribeTxPreEvent(ch chan<- bc.TxPreEvent) sub.Subscription

func (*ShxApiBackend) TxPoolContent

func (b *ShxApiBackend) TxPoolContent() (types.Transactions, types.Transactions)

type StopError

type StopError struct {
	Server   error
	Services map[reflect.Type]error
}

StopError is returned if a Node fails to stop either any of its registered services or itself.

func (*StopError) Error

func (e *StopError) Error() string

Error generates a textual representation of the stop error.

type StorageRangeResult

type StorageRangeResult struct {
	Storage storageMap   `json:"storage"`
	NextKey *common.Hash `json:"nextKey"` // nil if Storage includes the last key in the trie.
}

StorageRangeResult is the result of a debug_storageRangeAt API call.

Directories

Path Synopsis
Package filters implements an shx filtering system for block, transactions and log events.
Package filters implements an shx filtering system for block, transactions and log events.

Jump to

Keyboard shortcuts

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