node

package
v0.0.0-...-3b2d471 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// core space fullnode groups
	GroupCfxHttp     = "cfxhttp"
	GroupCfxWs       = "cfxws"
	GroupCfxLogs     = "cfxlog"
	GroupCfxArchives = "cfxarchives"

	// evm space fullnode groups
	GroupEthHttp = "ethhttp"
	GroupEthWs   = "ethws"
	GroupEthLogs = "ethlogs"

	// debug space fullnode groups
	GroupDebugHttp = "debughttp"
)

Variables

View Source
var (
	ErrClientUnavailable = errors.New("no full node available")
)

Functions

func EthFactory

func EthFactory() *factory

EthFactory returns evm space instance factory

func Factory

func Factory() *factory

Factory returns core space instance factory

func NewServer

func NewServer(nf nodeFactory, groupConf map[Group]UrlConfig) *rpc.Server

NewServer creates node management RPC server

Types

type CfxClientProvider

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

CfxClientProvider provides core space client by router.

func NewCfxClientProvider

func NewCfxClientProvider(router Router) *CfxClientProvider

func (*CfxClientProvider) GetClientByIP

func (p *CfxClientProvider) GetClientByIP(ctx context.Context) (sdk.ClientOperator, error)

GetClientByIP gets client of normal HTTP group by remote IP address.

func (*CfxClientProvider) GetClientByIPGroup

func (p *CfxClientProvider) GetClientByIPGroup(ctx context.Context, group Group) (sdk.ClientOperator, error)

GetClientByIPGroup gets client of specific group by remote IP address.

type CfxNode

type CfxNode struct {
	sdk.ClientOperator
	// contains filtered or unexported fields
}

CfxNode represents a core space fullnode with friendly name and health status.

func NewCfxNode

func NewCfxNode(group Group, name, url string, hm HealthMonitor) *CfxNode

NewCfxNode creates an instance of core space fullnode and start to monitor node health in a separate goroutine until node closed.

func (*CfxNode) Close

func (n *CfxNode) Close()

func (*CfxNode) LatestEpochNumber

func (n *CfxNode) LatestEpochNumber() (uint64, error)

LatestEpochNumber returns the latest epoch height of the core space fullnode

func (CfxNode) Name

func (n CfxNode) Name() string

func (CfxNode) Status

func (n CfxNode) Status() Status

func (CfxNode) String

func (n CfxNode) String() string

func (CfxNode) Url

func (n CfxNode) Url() string

type EthClientProvider

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

EthClientProvider provides evm space client by router.

func NewEthClientProvider

func NewEthClientProvider(router Router) *EthClientProvider

func (*EthClientProvider) GetClientByIP

func (p *EthClientProvider) GetClientByIP(ctx context.Context) (*Web3goClient, error)

GetClientByIP gets client of normal HTTP group by remote IP address.

func (*EthClientProvider) GetClientByIPGroup

func (p *EthClientProvider) GetClientByIPGroup(ctx context.Context, group Group) (*Web3goClient, error)

GetClientByIPGroup gets client of specific group by remote IP address.

func (*EthClientProvider) GetClientRandom

func (p *EthClientProvider) GetClientRandom() (*Web3goClient, error)

func (*EthClientProvider) GetClientRandomByGroup

func (p *EthClientProvider) GetClientRandomByGroup(group Group) (*Web3goClient, error)

type EthNode

type EthNode struct {
	*web3go.Client
	// contains filtered or unexported fields
}

EthNode represents an evm space node with friendly name and health status.

func NewEthNode

func NewEthNode(group Group, name, url string, hm HealthMonitor) *EthNode

NewEthNode creates an instance of evm space node and start to monitor node health in a separate goroutine until node closed.

func (EthNode) Close

func (n EthNode) Close()

func (*EthNode) LatestEpochNumber

func (n *EthNode) LatestEpochNumber() (uint64, error)

LatestEpochNumber returns the latest block height of the evm space fullnode

func (EthNode) Name

func (n EthNode) Name() string

func (EthNode) Status

func (n EthNode) Status() Status

func (EthNode) String

func (n EthNode) String() string

func (EthNode) Url

func (n EthNode) Url() string

type Group

type Group string

Group allows to manage full nodes in multiple groups.

func (Group) Space

func (g Group) Space() string

Space parses space from group name

func (Group) String

func (g Group) String() string

type HealthMonitor

type HealthMonitor interface {
	// HealthyEpoch returns the healthy epoch number among full nodes.
	// Usually, it is the middle epoch number of all full nodes.
	HealthyEpoch() uint64

	// ReportEpoch fired when epoch changes.
	ReportEpoch(nodeName string, epoch uint64)

	// ReportUnhealthy fired when full node becomes unhealthy or unrecovered for a long time.
	ReportUnhealthy(nodeName string, remind bool, reason error)

	// ReportHealthy fired when full node becomes healthy.
	ReportHealthy(nodeName string)
}

HealthMonitor is implemented by any objects that support to monitor full node health.

type LocalRouter

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

LocalRouter routes RPC requests based on local hash ring.

func NewLocalRouter

func NewLocalRouter(group2Urls map[Group][]string) *LocalRouter

func NewLocalRouterFromNodeRPC

func NewLocalRouterFromNodeRPC(client *rpc.Client, groupConf map[Group]UrlConfig) (*LocalRouter, error)

func (*LocalRouter) Route

func (r *LocalRouter) Route(group Group, key []byte) string

type Manager

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

Manager manages full node cluster, including: 1. Monitor node health and disable/enable full node automatically. 2. Implements Router interface to route RPC requests to different full nodes in manner of consistent hashing.

func NewManager

func NewManager(group Group, nf nodeFactory, urls []string) *Manager

func NewManagerWithRepartition

func NewManagerWithRepartition(group Group, nf nodeFactory, urls []string, resolver RepartitionResolver) *Manager

func (*Manager) Add

func (m *Manager) Add(url string)

Add adds fullnode to monitor

func (*Manager) Distribute

func (m *Manager) Distribute(key []byte) Node

Distribute distributes a full node by specified key.

func (*Manager) Get

func (m *Manager) Get(url string) Node

Get gets monitored fullnode from url

func (*Manager) HealthyEpoch

func (m *Manager) HealthyEpoch() uint64

HealthyEpoch returns the middle epoch height collected from managed cluster nodes, which is also regarded as the overall health epoch height.

func (*Manager) List

func (m *Manager) List() []Node

List lists all monitored fullnodes

func (*Manager) Remove

func (m *Manager) Remove(url string)

Remove removes monitored fullnode

func (*Manager) ReportEpoch

func (m *Manager) ReportEpoch(nodeName string, epoch uint64)

ReportEpoch reports latest epoch height of managed node to manager.

func (*Manager) ReportHealthy

func (m *Manager) ReportHealthy(nodeName string)

ReportHealthy reports healthy status of managed node to manager.

func (*Manager) ReportUnhealthy

func (m *Manager) ReportUnhealthy(nodeName string, remind bool, reason error)

ReportUnhealthy reports unhealthy status of managed node to manager.

func (*Manager) Route

func (m *Manager) Route(key []byte) string

Route implements the Router interface.

func (*Manager) String

func (m *Manager) String() string

String implements stringer interface

type Node

type Node interface {
	consistent.Member

	Name() string
	Url() string
	Status() Status

	LatestEpochNumber() (uint64, error)

	Close()
}

Node represents a full node with friendly name and health status.

type NodeRpcRouter

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

NodeRpcRouter routes RPC requests via node management RPC service.

func NewNodeRpcRouter

func NewNodeRpcRouter(client *rpc.Client) *NodeRpcRouter

func (*NodeRpcRouter) Route

func (r *NodeRpcRouter) Route(group Group, key []byte) string

type RedisRepartitionResolver

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

RedisRepartitionResolver implements RepartitionResolver

func NewRedisRepartitionResolver

func NewRedisRepartitionResolver(client *redis.Client, ttl time.Duration, keyPrefix string) *RedisRepartitionResolver

func (*RedisRepartitionResolver) Get

func (r *RedisRepartitionResolver) Get(key uint64) (string, bool)

func (*RedisRepartitionResolver) Put

func (r *RedisRepartitionResolver) Put(key uint64, value string)

type RedisRouter

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

RedisRouter routes RPC requests via redis. It should be used together with RedisRepartitionResolver.

func NewRedisRouter

func NewRedisRouter(client *redis.Client) *RedisRouter

func (*RedisRouter) Route

func (r *RedisRouter) Route(group Group, key []byte) string

type RepartitionResolver

type RepartitionResolver interface {
	Get(key uint64) (string, bool)
	Put(key uint64, value string)
}

RepartitionResolver is implemented to support repartition when item added or removed in the consistent hash ring.

type Router

type Router interface {
	// Route returns the full node URL for specified group and key.
	Route(group Group, key []byte) string
}

Router is used to route RPC requests to multiple full nodes.

func MustNewRouter

func MustNewRouter(redisURL string, nodeRPCURL string, groupConf map[Group]UrlConfig) Router

MustNewRouter creates an instance of Router.

func NewChainedRouter

func NewChainedRouter(groupConf map[Group]UrlConfig, routers ...Router) Router

type SimpleRepartitionResolver

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

func NewSimpleRepartitionResolver

func NewSimpleRepartitionResolver(ttl time.Duration) *SimpleRepartitionResolver

func (*SimpleRepartitionResolver) Get

func (*SimpleRepartitionResolver) Put

func (r *SimpleRepartitionResolver) Put(key uint64, value string)

type Status

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

Status represents the node status, including current epoch number and health status.

func NewStatus

func NewStatus(group Group, nodeName string) Status

func (*Status) Close

func (s *Status) Close()

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Status) Update

func (s *Status) Update(n Node, monitor HealthMonitor)

Update heartbeats with node and updates health status.

type UrlConfig

type UrlConfig struct {
	Nodes    []string
	Failover string
}

type Web3goClient

type Web3goClient struct {
	*web3go.Client

	URL string
}

Jump to

Keyboard shortcuts

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