cluster

package
v0.0.0-...-620b3f8 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams   = errors.New("invalid parameters")
	ErrUndefinedMethod = errors.New("undefined method")
	ErrZeroNode        = errors.New("no backend available for requests")
	ErrNotFound        = errors.New("data unavailable")
)

Functions

This section is empty.

Types

type Cluster

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

Cluster represents the whole infrastructure for ethflare. It's responsible for following things.

  • Create tile indexes The whole ethereum state will be cut into several chunks referenced together with each other. Each chunk is called "tile". Since each Geth node can have totally different state(out of sync, synced, fresh new), so cluster will maintain a global tile indexes based on all underlying Geth nodes. The indexes(metadata) can be used for validating the tile request and for request distribution.
  • Serve actual requests All requests received in the httpserver will be processed here including chain requests and state requests.

func NewCluster

func NewCluster(config *Config) (*Cluster, error)

NewCluster returns a cluster instance

func (*Cluster) ServeRequest

func (c *Cluster) ServeRequest(ctx context.Context, method string, args ...interface{}) (interface{}, error)

ServeRequest performs the request serving with given arguments.

func (*Cluster) Start

func (c *Cluster) Start()

Start starts the whole cluster, track the latest ethereum state and crawl the missing tile.

func (*Cluster) Stop

func (c *Cluster) Stop()

func (*Cluster) Wait

func (c *Cluster) Wait()

type Config

type Config struct {
	// Datadir the file path points to the database. If the value is empty,
	// an in-memory temporary database is applied.
	Datadir string

	// HTTPHost is the host interface on which to start the HTTP RPC server. If this
	// field is empty, no HTTP API endpoint will be started.
	HTTPHost string `toml:",omitempty"`

	// HTTPPort is the TCP port number on which to start the HTTP RPC server. The
	// default zero value is/ valid and will pick a port number randomly (useful
	// for ephemeral nodes).
	HTTPPort int `toml:",omitempty"`

	// Nodes is a list of node config(web socket endpoint).
	Nodes []NodeConfig

	// Log the logger for system, nil means default logger.
	Log log.Logger `toml:"-"`
}

func (Config) MarshalTOML

func (c Config) MarshalTOML() (interface{}, error)

MarshalTOML marshals as TOML.

func (*Config) UnmarshalTOML

func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error

UnmarshalTOML unmarshals from TOML.

type Node

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

Node represents an Ethereum node with the ethflare RPC API implemented and exposed via WebSockets (we need notification support for new heads).

The necessary ethflare APIs includes:

  • cdn_tile
  • cdn_nodes
  • cdn_receipts

func NewNode

func NewNode(id string, conn *rpc.Client, ratelimit uint64) (*Node, error)

NewNode takes a live websocket connection to a Node and starts to monitor its chain progression and optionally request chain and state data.

func (*Node) GetBlockByHash

func (n *Node) GetBlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

GetBlockByHash sends a RPC request for retrieving specified block with given hash.

func (*Node) GetNodes

func (n *Node) GetNodes(ctx context.Context, hash common.Hash, number uint16, cutoff []common.Hash) ([][]byte, error)

GetNodes sends a RPC request for retrieving specified nodes with with given node hash list.

func (*Node) GetReceiptsByHash

func (n *Node) GetReceiptsByHash(ctx context.Context, hash common.Hash) (types.Receipts, error)

GetReceiptsByHash sends a RPC request for retrieving specified receipts with given block hash.

func (*Node) GetTile

func (n *Node) GetTile(ctx context.Context, hash common.Hash) ([][]byte, error)

GetTile sends a RPC request for retrieving specified tile with given root hash.

func (*Node) HasBlock

func (n *Node) HasBlock(hash common.Hash) bool

HasBlock checks whether a block is available from this Node. If the block is too old, return false also.

func (*Node) HasState

func (n *Node) HasState(root common.Hash) bool

HasState checks whether a state is available from this Node. If the state is too old, then regard it as unavailable.

func (*Node) ID

func (n *Node) ID() string

ID returns the identity of node

func (*Node) Logger

func (n *Node) Logger() log.Logger

ID returns the identity of node

func (*Node) SubscribeNewHead

func (n *Node) SubscribeNewHead(sink chan *types.Header) event.Subscription

SubscribeNewHead subscribes to new chain head events to act as triggers for the task tiler.

type NodeConfig

type NodeConfig struct {
	ID        string // The unique identity of node
	Endpoint  string // The RPC endpoint which enables the websocket
	RateLimit uint64 // The rate limit for sending requests to the node
}

NodeConfig includes all settings of node.

type NodeSet

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

NodeSet is a set of connected nodes

func NewNodeSet

func NewNodeSet() *NodeSet

func (*NodeSet) AddNode

func (set *NodeSet) AddNode(id string, n *Node) error

AddNode adds new Node to set, return error if it's already registered.

func (*NodeSet) ForEach

func (set *NodeSet) ForEach(callback func(id string, node *Node) bool)

ForEach iterates the whole Node set and applies callback on each of them. Stop iteration when the callback returns false.

func (*NodeSet) HasBlock

func (set *NodeSet) HasBlock(hash common.Hash) []*Node

HasBlock returns a list of suitable nodes which has the specified block.

func (*NodeSet) HasState

func (set *NodeSet) HasState(root common.Hash) []*Node

HasState returns a list of suitable nodes which has the specified state.

func (*NodeSet) Len

func (set *NodeSet) Len() int

Len returns the total node number of set

func (*NodeSet) Node

func (set *NodeSet) Node(id string) *Node

Node returns the node instance by id.

func (*NodeSet) Random

func (set *NodeSet) Random() *Node

Random returns a random node based on map iteration

func (*NodeSet) RemoveNode

func (set *NodeSet) RemoveNode(id string) error

RemoveNode removes the node from set, return error if it's non-existent.

Jump to

Keyboard shortcuts

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