Documentation ¶
Index ¶
- Variables
- type ErrorCode
- type GRPCAdapter
- type Node
- type ReportType
- type RetryingNode
- func (n *RetryingNode) Host() string
- func (n *RetryingNode) LastBlock(ctx context.Context) (nodetypes.LastBlock, error)
- func (n *RetryingNode) SendTransaction(ctx context.Context, tx *commandspb.Transaction, ...) (string, error)
- func (n *RetryingNode) SpamStatistics(ctx context.Context, pubKey string) (nodetypes.SpamStatistics, error)
- func (n *RetryingNode) Statistics(ctx context.Context) (nodetypes.Statistics, error)
- func (n *RetryingNode) Stop() error
- type RoundRobinSelector
- type SelectionReporter
- type Selector
- type StatusError
Constants ¶
This section is empty.
Variables ¶
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 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) LastBlock(ctx context.Context) (nodetypes.LastBlock, error) Stop() error }
type Node ¶ added in v0.56.0
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 ¶ 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) *RetryingNode
func NewRetryingNode ¶ added in v0.62.0
func (*RetryingNode) Host ¶ added in v0.62.0
func (n *RetryingNode) Host() string
func (*RetryingNode) LastBlock ¶ added in v0.62.0
LastBlock returns information about the last block acknowledged by the node.
func (*RetryingNode) SendTransaction ¶ added in v0.62.0
func (n *RetryingNode) SendTransaction(ctx context.Context, tx *commandspb.Transaction, ty apipb.SubmitTransactionRequest_Type) (string, error)
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:
- It gets the statistics of the nodes configured
- It filters out the nodes that returns data different from the majority, and label those left as the "healthiest" nodes.
- 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.
type StatusError ¶
func (*StatusError) Error ¶
func (e *StatusError) Error() string