node

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: AGPL-3.0 Imports: 19 Imported by: 1

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 added in v0.62.0

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)
	CheckTransaction(ctx context.Context, in *apipb.CheckTransactionRequest) (*apipb.CheckTransactionResponse, error)
	LastBlock(ctx context.Context) (nodetypes.LastBlock, error)
	Stop() error
}

type Node added in v0.56.0

type Node interface {
	Host() string
	Stop() error
	CheckTransaction(context.Context, *commandspb.Transaction) 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 added in v0.56.0

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 added in v0.62.0

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

func BuildRetryingNode added in v0.62.0

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

func NewRetryingNode added in v0.62.0

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

func (*RetryingNode) CheckTransaction added in v0.69.0

func (n *RetryingNode) CheckTransaction(ctx context.Context, tx *commandspb.Transaction) error

func (*RetryingNode) Host added in v0.62.0

func (n *RetryingNode) Host() string

func (*RetryingNode) LastBlock added in v0.62.0

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

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

func (*RetryingNode) SendTransaction added in v0.62.0

func (*RetryingNode) SpamStatistics added in v0.68.0

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

func (*RetryingNode) Statistics added in v0.62.0

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

func (*RetryingNode) Stop added in v0.62.0

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 added in v0.56.0

type SelectionReporter func(ReportType, string)

type Selector added in v0.56.0

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

Selector implementing the strategy for node selection.

func BuildRoundRobinSelectorWithRetryingNodes added in v0.56.0

func BuildRoundRobinSelectorWithRetryingNodes(log *zap.Logger, hosts []string, retries uint64, requestTTL time.Duration) (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