node

package
v0.0.0-...-141c82c Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoNodeConfigured       = errors.New("no node configured on round-robin selector")
	ErrNoHealthyNodeAvailable = errors.New("no healthy node available")
)

Functions

This section is empty.

Types

type ErrorCode

type ErrorCode codes.Code

type GRPCAdapter

type GRPCAdapter interface {
	Host() string
	Statistics(ctx context.Context) (nodetypes.Statistics, error)
	SpamStatistics(ctx context.Context, pubKey string) (nodetypes.SpamStatistics, error)
	SubmitTransaction(ctx context.Context, in *apipb.SubmitTransactionRequest) (*apipb.SubmitTransactionResponse, error)
	LastBlock(ctx context.Context) (nodetypes.LastBlock, error)
	Stop() error
}

type Node

type Node interface {
	Host() string
	Stop() error
	SendTransaction(context.Context, *commandspb.Transaction, apipb.SubmitTransactionRequest_Type) (string, error)
	Statistics(ctx context.Context) (nodetypes.Statistics, error)
	LastBlock(context.Context) (nodetypes.LastBlock, error)
	SpamStatistics(ctx context.Context, pubKey string) (nodetypes.SpamStatistics, error)
}

Node is the component used to get network information and send transactions.

type ReportType

type ReportType string

ReportType defines the type of event that occurred.

var (
	InfoEvent    ReportType = "Info"
	WarningEvent ReportType = "Warning"
	ErrorEvent   ReportType = "Error"
	SuccessEvent ReportType = "Success"
)

type RetryingNode

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

func BuildRetryingNode

func BuildRetryingNode(log *zap.Logger, grpcAdapter GRPCAdapter, retries uint64) *RetryingNode

func NewRetryingNode

func NewRetryingNode(log *zap.Logger, host string, retries uint64) (*RetryingNode, error)

func (*RetryingNode) Host

func (n *RetryingNode) Host() string

func (*RetryingNode) LastBlock

func (n *RetryingNode) LastBlock(ctx context.Context) (nodetypes.LastBlock, error)

LastBlock returns information about the last block acknowledged by the node.

func (*RetryingNode) SendTransaction

func (*RetryingNode) SpamStatistics

func (n *RetryingNode) SpamStatistics(ctx context.Context, pubKey string) (nodetypes.SpamStatistics, error)

func (*RetryingNode) Statistics

func (n *RetryingNode) Statistics(ctx context.Context) (nodetypes.Statistics, error)

func (*RetryingNode) Stop

func (n *RetryingNode) Stop() error

type RoundRobinSelector

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

RoundRobinSelector uses a classic round-robin algorithm to select a node. When requesting the next node, this is the node right behind the current one that is selected. When the last node is reached, it starts over the first one.

func NewRoundRobinSelector

func NewRoundRobinSelector(log *zap.Logger, nodes ...Node) (*RoundRobinSelector, error)

func (*RoundRobinSelector) Node

func (ns *RoundRobinSelector) Node(ctx context.Context, reporterFn SelectionReporter) (Node, error)

Node returns the next node in line among the healthiest nodes.

Algorithm:

  1. It gets the statistics of the nodes configured
  2. It filters out the nodes that returns data different from the majority, and label those left as the "healthiest" nodes.
  3. It tries to resolve the next node in line, based on the previous selection and availability of the node. If the next node that should have selected is not healthy, it skips the node. It applies this logic until it ends up on a healthy node.

Warning: We look for the network information that are the most commonly shared among the nodes, because, in decentralized system, the most commonly shared data represents the truth. While true from the entire network point of view, on a limited subset of nodes, this might not be true. If most of the nodes set up in the configuration are late, or misbehaving, the algorithm will fail to identify the truly healthy ones. That's the major reason to favour highly trusted and stable nodes.

func (*RoundRobinSelector) Stop

func (ns *RoundRobinSelector) Stop()

Stop stops all the registered nodes. If a node raises an error during closing, the selector ignores it and carry on a best-effort.

type SelectionReporter

type SelectionReporter func(ReportType, string)

type Selector

type Selector interface {
	Node(ctx context.Context, reporterFn SelectionReporter) (Node, error)
	Stop()
}

Selector implementing the strategy for node selection.

func BuildRoundRobinSelectorWithRetryingNodes

func BuildRoundRobinSelectorWithRetryingNodes(log *zap.Logger, hosts []string, retries uint64) (Selector, error)

type StatusError

type StatusError struct {
	Code    codes.Code
	Details []string
}

func (*StatusError) Error

func (e *StatusError) Error() string

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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