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 ¶
- Variables
- func NewBloomIndexer(db shxdb.Database, size uint64) *bc.ChainIndexer
- type BloomIndexer
- type ConsensuscfgF
- type DuplicateServiceError
- type LesServer
- type Node
- func (s *Node) APIAccountManager() *accounts.Manager
- func (s *Node) APIs() []rpc.API
- func (n *Node) AccountManager() *accounts.Manager
- func (n *Node) Attach(ipc *rpc.Server) (*rpc.Client, error)
- func (s *Node) BlockChain() *bc.BlockChain
- func (s *Node) ChainDb() shxdb.Database
- func (n *Node) DataDir() string
- func (s *Node) Engine() consensus.Engine
- func (n *Node) GetAPI() error
- func (n *Node) InstanceDir() string
- func (s *Node) IsListening() bool
- func (s *Node) IsMining() bool
- func (s *Node) Miner() *worker.Miner
- func (s *Node) NetVersion() uint64
- func (n *Node) NewBlockMux() *sub.TypeMux
- func (n *Node) Nodeapis() []rpc.API
- func (n *Node) RPCHandler() (*rpc.Server, error)
- func (s *Node) ResetWithGenesisBlock(gb *types.Block)
- func (n *Node) ResolvePath(x string) string
- func (n *Node) Restart() error
- func (n *Node) SetNodeAPI() error
- func (s *Node) SetOpt(maxtxs, peorid int)
- func (self *Node) SetShxerbase(hpberbase common.Address)
- func (s *Node) ShxVersion() int
- func (s *Node) Shxerbase() (eb common.Address, err error)
- func (hpbnode *Node) Start(conf *config.ShxConfig) error
- func (s *Node) StartMining(local bool) error
- func (n *Node) Stop() error
- func (s *Node) StopMining()
- func (s *Node) TxPool() *txpool.TxPool
- func (n *Node) Wait()
- func (hpbnode *Node) WorkerInit(conf *config.ShxConfig) error
- type PrivateAdminAPI
- type PrivateDebugAPI
- type PrivateMinerAPI
- type PublicAdminAPI
- type PublicDebugAPI
- type PublicShxAPI
- type PublicWeb3API
- type ShxApiBackend
- func (b *ShxApiBackend) AccountManager() *accounts.Manager
- func (b *ShxApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
- func (b *ShxApiBackend) BloomStatus() (uint64, uint64)
- func (b *ShxApiBackend) ChainConfig() *config.ChainConfig
- func (b *ShxApiBackend) ChainDb() shxdb.Database
- func (b *ShxApiBackend) CurrentBlock() *types.Block
- func (b *ShxApiBackend) EventMux() *sub.TypeMux
- func (b *ShxApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
- func (b *ShxApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
- func (b *ShxApiBackend) GetPoolTransaction(hash common.Hash) *types.Transaction
- func (b *ShxApiBackend) GetPoolTransactions() (types.Transactions, error)
- func (b *ShxApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
- func (b *ShxApiBackend) GetTd(blockHash common.Hash) *big.Int
- func (b *ShxApiBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
- func (b *ShxApiBackend) ProtocolVersion() int
- func (b *ShxApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error
- func (b *ShxApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
- func (b *ShxApiBackend) SetHead(number uint64)
- func (b *ShxApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)
- func (b *ShxApiBackend) Stats() (pending int, queued int)
- func (b *ShxApiBackend) SubscribeChainEvent(ch chan<- bc.ChainEvent) sub.Subscription
- func (b *ShxApiBackend) SubscribeChainHeadEvent(ch chan<- bc.ChainHeadEvent) sub.Subscription
- func (b *ShxApiBackend) SubscribeLogsEvent(ch chan<- []*types.Log) sub.Subscription
- func (b *ShxApiBackend) SubscribeRemovedLogsEvent(ch chan<- bc.RemovedLogsEvent) sub.Subscription
- func (b *ShxApiBackend) SubscribeTxPreEvent(ch chan<- bc.TxPreEvent) sub.Subscription
- func (b *ShxApiBackend) TxPoolContent() (types.Transactions, types.Transactions)
- type StopError
- type StorageRangeResult
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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 (*Node) APIAccountManager ¶
func (s *Node) APIAccountManager() *accounts.Manager
func (*Node) APIs ¶
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) BlockChain ¶
func (s *Node) BlockChain() *bc.BlockChain
func (*Node) DataDir ¶
DataDir retrieves the current datadir used by the protocol stack. Deprecated: No files should be stored in this directory, use InstanceDir instead.
func (*Node) InstanceDir ¶
InstanceDir retrieves the instance directory used by the protocol stack.
func (*Node) IsListening ¶
func (*Node) NetVersion ¶
func (*Node) NewBlockMux ¶
EventMux retrieves the event multiplexer used by all the network services in the current protocol stack.
func (*Node) RPCHandler ¶
RPCHandler returns the in-process RPC request handler.
func (*Node) ResetWithGenesisBlock ¶
func (*Node) ResolvePath ¶
ResolvePath returns the absolute path of a resource in the instance directory.
func (*Node) Restart ¶
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 (*Node) SetShxerbase ¶
set in js console via admin interface or wrapper from cli flags
func (*Node) ShxVersion ¶
func (*Node) StartMining ¶
func (*Node) Stop ¶
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()
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
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) 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.
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.
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
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
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) GetPoolNonce ¶
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 (*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 ¶
StopError is returned if a Node fails to stop either any of its registered services or itself.
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.