p2p

package
v1.18.27 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var (
	ErrRequestPending = errors.New("request pending")
	ErrNoPeers        = errors.New("no peers")
)
View Source
var (
	// ErrUnexpected should be used to indicate that a request failed due to a
	// generic error
	ErrUnexpected = &core.AppError{
		Code:    -1,
		Message: "unexpected error",
	}
	// ErrUnregisteredHandler should be used to indicate that a request failed
	// due to it not matching a registered handler
	ErrUnregisteredHandler = &core.AppError{
		Code:    -2,
		Message: "unregistered handler",
	}
	// ErrNotValidator should be used to indicate that a request failed due to
	// the requesting peer not being a validator
	ErrNotValidator = &core.AppError{
		Code:    -3,
		Message: "not a validator",
	}
	// ErrThrottled should be used to indicate that a request failed due to the
	// requesting peer exceeding a rate limit
	ErrThrottled = &core.AppError{
		Code:    -4,
		Message: "throttled",
	}
)
View Source
var (
	ErrExistingAppProtocol = errors.New("existing app protocol")
	ErrUnrequestedResponse = errors.New("unrequested response")
)

Functions ¶

func ParseMessage ¶

func ParseMessage(msg []byte) (uint64, []byte, bool)

Parse a gossip or request message.

Returns: - The protocol ID. - The unprefixed protocol message. - A boolean indicating that parsing succeeded.

func PrefixMessage ¶

func PrefixMessage(prefix, msg []byte) []byte

PrefixMessage prefixes the original message with the protocol identifier.

Only gossip and request messages need to be prefixed. Response messages don't need to be prefixed because request ids are tracked which map to the expected response handler.

func ProtocolPrefix ¶

func ProtocolPrefix(handlerID uint64) []byte

Types ¶

type AppResponseCallback ¶

type AppResponseCallback func(
	ctx context.Context,
	nodeID ids.NodeID,
	responseBytes []byte,
	err error,
)

AppResponseCallback is called upon receiving an AppResponse for an AppRequest issued by Client. Callers should check [err] to see whether the AppRequest failed or not.

type AppSenderWrapper ¶ added in v1.17.2

type AppSenderWrapper struct {
	appsender.AppSender
}

AppSenderWrapper wraps a consensus AppSender to provide CrossChain methods

func (*AppSenderWrapper) SendCrossChainAppError ¶ added in v1.17.2

func (w *AppSenderWrapper) SendCrossChainAppError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error

SendCrossChainAppError is not implemented for wrapped senders

func (*AppSenderWrapper) SendCrossChainAppRequest ¶ added in v1.17.2

func (w *AppSenderWrapper) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error

SendCrossChainAppRequest is not implemented for wrapped senders

func (*AppSenderWrapper) SendCrossChainAppResponse ¶ added in v1.17.2

func (w *AppSenderWrapper) SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, appResponseBytes []byte) error

SendCrossChainAppResponse is not implemented for wrapped senders

type Client ¶

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

func (*Client) AppGossip ¶

func (c *Client) AppGossip(
	ctx context.Context,
	config core.SendConfig,
	appGossipBytes []byte,
) error

AppGossip sends a gossip message to a random set of peers.

func (*Client) AppRequest ¶

func (c *Client) AppRequest(
	ctx context.Context,
	nodeIDs set.Set[ids.NodeID],
	appRequestBytes []byte,
	onResponse AppResponseCallback,
) error

AppRequest issues an arbitrary request to a node. [onResponse] is invoked upon an error or a response.

func (*Client) AppRequestAny ¶

func (c *Client) AppRequestAny(
	ctx context.Context,
	appRequestBytes []byte,
	onResponse AppResponseCallback,
) error

AppRequestAny issues an AppRequest to an arbitrary node decided by Client. If a specific node needs to be requested, use AppRequest instead. See AppRequest for more docs.

func (*Client) CrossChainAppRequest ¶ added in v1.1.11

func (c *Client) CrossChainAppRequest(
	ctx context.Context,
	chainID ids.ID,
	appRequestBytes []byte,
	onResponse CrossChainAppResponseCallback,
) error

CrossChainAppRequest sends a cross chain app request to another vm. [onResponse] is invoked upon an error or a response.

type ClientOption ¶

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption configures Client

func WithValidatorSampling ¶

func WithValidatorSampling(validators *Validators) ClientOption

WithValidatorSampling configures Client.AppRequestAny to sample validators

type CrossChainAppResponseCallback ¶ added in v1.1.11

type CrossChainAppResponseCallback func(
	ctx context.Context,
	chainID ids.ID,
	responseBytes []byte,
	err error,
)

CrossChainAppResponseCallback is called upon receiving an CrossChainAppResponse for a CrossChainAppRequest issued by Client. Callers should check [err] to see whether the AppRequest failed or not.

type ExtendedAppSender ¶ added in v1.17.2

type ExtendedAppSender interface {
	appsender.AppSender

	// SendCrossChainAppRequest sends a cross-chain app request
	SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error

	// SendCrossChainAppResponse sends a cross-chain app response
	SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, appResponseBytes []byte) error

	// SendCrossChainAppError sends a cross-chain app error
	SendCrossChainAppError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error
}

ExtendedAppSender extends the consensus AppSender with cross-chain methods

func NewAppSenderWrapper ¶ added in v1.17.2

func NewAppSenderWrapper(sender appsender.AppSender) ExtendedAppSender

NewAppSenderWrapper creates a new wrapper that adds CrossChain methods

type FakeSender ¶ added in v1.17.2

type FakeSender struct {
	SendAppRequestF            func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendAppResponseF           func(context.Context, ids.NodeID, uint32, []byte) error
	SendAppErrorF              func(context.Context, ids.NodeID, uint32, int32, string) error
	SendAppGossipF             func(context.Context, set.Set[ids.NodeID], []byte) error
	SendAppGossipSpecificF     func(context.Context, set.Set[ids.NodeID], []byte) error
	SendCrossChainAppRequestF  func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainAppResponseF func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainAppErrorF    func(context.Context, ids.ID, uint32, int32, string) error

	// Test channels
	SentAppRequest           chan []byte
	SentAppResponse          chan []byte
	SentAppGossip            chan []byte
	SentCrossChainAppRequest chan []byte
}

FakeSender is a test implementation of AppSender

func (*FakeSender) SendAppError ¶ added in v1.17.2

func (f *FakeSender) SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error

func (*FakeSender) SendAppGossip ¶ added in v1.17.2

func (f *FakeSender) SendAppGossip(ctx context.Context, nodeIDs set.Set[ids.NodeID], gossip []byte) error

func (*FakeSender) SendAppGossipSpecific ¶ added in v1.17.2

func (f *FakeSender) SendAppGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], gossip []byte) error

func (*FakeSender) SendAppRequest ¶ added in v1.17.2

func (f *FakeSender) SendAppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, request []byte) error

func (*FakeSender) SendAppResponse ¶ added in v1.17.2

func (f *FakeSender) SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error

func (*FakeSender) SendCrossChainAppError ¶ added in v1.17.2

func (f *FakeSender) SendCrossChainAppError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error

func (*FakeSender) SendCrossChainAppRequest ¶ added in v1.17.2

func (f *FakeSender) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, request []byte) error

func (*FakeSender) SendCrossChainAppResponse ¶ added in v1.17.2

func (f *FakeSender) SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error

type Handler ¶

type Handler interface {
	// AppGossip is called when handling an AppGossip message.
	AppGossip(
		ctx context.Context,
		nodeID ids.NodeID,
		gossipBytes []byte,
	)
	// AppRequest is called when handling an AppRequest message.
	// Sends a response with the response corresponding to [requestBytes] or
	// an application-defined error.
	AppRequest(
		ctx context.Context,
		nodeID ids.NodeID,
		deadline time.Time,
		requestBytes []byte,
	) ([]byte, *core.AppError)
	// CrossChainAppRequest is called when handling a CrossChainAppRequest
	// message.
	// Returns the bytes for the response corresponding to [requestBytes]
	CrossChainAppRequest(
		ctx context.Context,
		chainID ids.ID,
		deadline time.Time,
		requestBytes []byte,
	) ([]byte, error)
}

Handler is the server-side logic for virtual machine application protocols.

type Network ¶

type Network struct {
	Peers *Peers
	// contains filtered or unexported fields
}

Network exposes networking state and supports building p2p application protocols

func NewNetwork ¶

func NewNetwork(
	log log.Logger,
	sender core.AppSender,
	registerer metric.Registerer,
	namespace string,
) (*Network, error)

NewNetwork returns an instance of Network

func (*Network) AddHandler ¶

func (n *Network) AddHandler(handlerID uint64, handler Handler) error

AddHandler reserves an identifier for an application protocol

func (*Network) AppGossip ¶

func (n *Network) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error

func (*Network) AppRequest ¶

func (n *Network) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte) error

func (*Network) AppRequestFailed ¶

func (n *Network) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *core.AppError) error

func (*Network) AppResponse ¶

func (n *Network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error

func (*Network) Connected ¶

func (n *Network) Connected(_ context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error

func (*Network) CrossChainAppRequest ¶ added in v1.1.11

func (n *Network) CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, request []byte) error

func (*Network) CrossChainAppRequestFailed ¶ added in v1.1.11

func (n *Network) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, appErr *core.AppError) error

func (*Network) CrossChainAppResponse ¶ added in v1.1.11

func (n *Network) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error

func (*Network) Disconnected ¶

func (n *Network) Disconnected(_ context.Context, nodeID ids.NodeID) error

func (*Network) NewClient ¶

func (n *Network) NewClient(handlerID uint64, options ...ClientOption) *Client

NewClient returns a Client that can be used to send messages for the corresponding protocol.

type NoOpHandler ¶

type NoOpHandler struct{}

NoOpHandler drops all messages

func (NoOpHandler) AppGossip ¶

func (NoOpHandler) AppGossip(context.Context, ids.NodeID, []byte)

func (NoOpHandler) AppRequest ¶

func (NoOpHandler) AppRequest(context.Context, ids.NodeID, time.Time, []byte) ([]byte, *core.AppError)

func (NoOpHandler) CrossChainAppRequest ¶ added in v1.1.11

func (NoOpHandler) CrossChainAppRequest(context.Context, ids.ID, time.Time, []byte) ([]byte, error)

type NodeSampler ¶

type NodeSampler interface {
	// Sample returns at most [limit] nodes. This may return fewer nodes if
	// fewer than [limit] are available.
	Sample(ctx context.Context, limit int) []ids.NodeID
}

NodeSampler samples nodes in network

type PeerTracker ¶

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

Tracks the bandwidth of responses coming from peers, preferring to contact peers with known good bandwidth, connecting to new peers with an exponentially decaying probability.

func NewPeerTracker ¶

func NewPeerTracker(
	log log.Logger,
	metricsNamespace string,
	registerer metric.Registerer,
	ignoredNodes set.Set[ids.NodeID],
	minVersion *version.Application,
) (*PeerTracker, error)

func (*PeerTracker) Connected ¶

func (p *PeerTracker) Connected(nodeID ids.NodeID, nodeVersion *version.Application)

Connected should be called when [nodeID] connects to this node.

func (*PeerTracker) Disconnected ¶

func (p *PeerTracker) Disconnected(nodeID ids.NodeID)

Disconnected should be called when [nodeID] disconnects from this node.

func (*PeerTracker) RegisterFailure ¶

func (p *PeerTracker) RegisterFailure(nodeID ids.NodeID)

Record that a request failed to [nodeID].

Adds the peer's bandwidth averager to the bandwidth heap.

func (*PeerTracker) RegisterRequest ¶

func (p *PeerTracker) RegisterRequest(nodeID ids.NodeID)

Record that we sent a request to [nodeID].

Removes the peer's bandwidth averager from the bandwidth heap.

func (*PeerTracker) RegisterResponse ¶

func (p *PeerTracker) RegisterResponse(nodeID ids.NodeID, bandwidth float64)

Record that we observed that [nodeID]'s bandwidth is [bandwidth].

Adds the peer's bandwidth averager to the bandwidth heap.

func (*PeerTracker) SelectPeer ¶

func (p *PeerTracker) SelectPeer() (ids.NodeID, bool)

SelectPeer that we could send a request to.

If we should track more peers, returns a random untracked peer, if any exist. Otherwise, with probability [randomPeerProbability] returns a random peer from [p.responsivePeers]. With probability [1-randomPeerProbability] returns the peer in [p.bandwidthHeap] with the highest bandwidth.

Returns false if there are no connected peers.

func (*PeerTracker) Size ¶

func (p *PeerTracker) Size() int

Returns the number of peers the node is connected to.

type Peers ¶

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

Peers contains metadata about the current set of connected peers

func (*Peers) Sample ¶

func (p *Peers) Sample(limit int) []ids.NodeID

Sample returns a pseudo-random sample of up to limit Peers

type SenderTest ¶ added in v1.17.2

type SenderTest struct {
	T *testing.T

	CantSendAppGossip, CantSendAppGossipSpecific,
	CantSendAppRequest, CantSendAppResponse, CantSendAppError,
	CantSendCrossChainAppRequest, CantSendCrossChainAppResponse, CantSendCrossChainAppError bool

	SendAppGossipF             func(context.Context, set.Set[ids.NodeID], []byte) error
	SendAppGossipSpecificF     func(context.Context, set.Set[ids.NodeID], []byte) error
	SendAppRequestF            func(context.Context, set.Set[ids.NodeID], uint32, []byte) error
	SendAppResponseF           func(context.Context, ids.NodeID, uint32, []byte) error
	SendAppErrorF              func(context.Context, ids.NodeID, uint32, int32, string) error
	SendCrossChainAppRequestF  func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainAppResponseF func(context.Context, ids.ID, uint32, []byte) error
	SendCrossChainAppErrorF    func(context.Context, ids.ID, uint32, int32, string) error
}

SenderTest implements ExtendedAppSender for testing with configurable behavior

func (*SenderTest) SendAppError ¶ added in v1.17.2

func (s *SenderTest) SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error

func (*SenderTest) SendAppGossip ¶ added in v1.17.2

func (s *SenderTest) SendAppGossip(ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte) error

func (*SenderTest) SendAppGossipSpecific ¶ added in v1.17.2

func (s *SenderTest) SendAppGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte) error

func (*SenderTest) SendAppRequest ¶ added in v1.17.2

func (s *SenderTest) SendAppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, appRequestBytes []byte) error

func (*SenderTest) SendAppResponse ¶ added in v1.17.2

func (s *SenderTest) SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, appResponseBytes []byte) error

func (*SenderTest) SendCrossChainAppError ¶ added in v1.17.2

func (s *SenderTest) SendCrossChainAppError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error

func (*SenderTest) SendCrossChainAppRequest ¶ added in v1.17.2

func (s *SenderTest) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error

func (*SenderTest) SendCrossChainAppResponse ¶ added in v1.17.2

func (s *SenderTest) SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, appResponseBytes []byte) error

type SlidingWindowThrottler ¶

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

SlidingWindowThrottler is an implementation of the sliding window throttling algorithm.

func NewSlidingWindowThrottler ¶

func NewSlidingWindowThrottler(period time.Duration, limit int) *SlidingWindowThrottler

NewSlidingWindowThrottler returns a new instance of SlidingWindowThrottler. Nodes are throttled if they exceed [limit] messages during an interval of time over [period]. [period] and [limit] should both be > 0.

func (*SlidingWindowThrottler) Handle ¶

func (s *SlidingWindowThrottler) Handle(nodeID ids.NodeID) bool

Handle returns true if the amount of calls received in the last [s.period] time is less than [s.limit]

This is calculated by adding the current period's count to a weighted count of the previous period.

type TestAppSender ¶ added in v1.17.2

type TestAppSender struct {
	SentAppGossip            chan []byte
	SentAppRequest           chan []byte
	SentCrossChainAppRequest chan []byte
	SentAppResponse          chan []byte
	SentAppError             chan error
}

TestAppSender implements ExtendedAppSender for testing

func (*TestAppSender) SendAppError ¶ added in v1.17.2

func (f *TestAppSender) SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error

func (*TestAppSender) SendAppGossip ¶ added in v1.17.2

func (f *TestAppSender) SendAppGossip(ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte) error

func (*TestAppSender) SendAppGossipSpecific ¶ added in v1.17.2

func (f *TestAppSender) SendAppGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte) error

func (*TestAppSender) SendAppRequest ¶ added in v1.17.2

func (f *TestAppSender) SendAppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, appRequestBytes []byte) error

func (*TestAppSender) SendAppResponse ¶ added in v1.17.2

func (f *TestAppSender) SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, appResponseBytes []byte) error

func (*TestAppSender) SendCrossChainAppError ¶ added in v1.17.2

func (f *TestAppSender) SendCrossChainAppError(ctx context.Context, chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) error

func (*TestAppSender) SendCrossChainAppRequest ¶ added in v1.17.2

func (f *TestAppSender) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error

func (*TestAppSender) SendCrossChainAppResponse ¶ added in v1.17.2

func (f *TestAppSender) SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, appResponseBytes []byte) error

type TestHandler ¶

type TestHandler struct {
	AppGossipF            func(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)
	AppRequestF           func(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *core.AppError)
	CrossChainAppRequestF func(ctx context.Context, chainID ids.ID, deadline time.Time, requestBytes []byte) ([]byte, error)
}

func (TestHandler) AppGossip ¶

func (t TestHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)

func (TestHandler) AppRequest ¶

func (t TestHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *core.AppError)

func (TestHandler) CrossChainAppRequest ¶ added in v1.1.11

func (t TestHandler) CrossChainAppRequest(ctx context.Context, chainID ids.ID, deadline time.Time, requestBytes []byte) ([]byte, error)

type Throttler ¶

type Throttler interface {
	// Handle returns true if a message from [nodeID] should be handled.
	Handle(nodeID ids.NodeID) bool
}

type ThrottlerHandler ¶

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

func NewThrottlerHandler ¶

func NewThrottlerHandler(handler Handler, throttler Throttler, log log.Logger) *ThrottlerHandler

func (ThrottlerHandler) AppGossip ¶

func (t ThrottlerHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)

func (ThrottlerHandler) AppRequest ¶

func (t ThrottlerHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *core.AppError)

func (ThrottlerHandler) CrossChainAppRequest ¶ added in v1.1.11

func (t ThrottlerHandler) CrossChainAppRequest(ctx context.Context, chainID ids.ID, deadline time.Time, requestBytes []byte) ([]byte, error)

type ValidatorHandler ¶

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

ValidatorHandler drops messages from non-validators

func NewValidatorHandler ¶

func NewValidatorHandler(
	handler Handler,
	validatorSet ValidatorSet,
	log log.Logger,
) *ValidatorHandler

func (ValidatorHandler) AppGossip ¶

func (v ValidatorHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)

func (ValidatorHandler) AppRequest ¶

func (v ValidatorHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *core.AppError)

func (ValidatorHandler) CrossChainAppRequest ¶ added in v1.1.11

func (v ValidatorHandler) CrossChainAppRequest(ctx context.Context, chainID ids.ID, deadline time.Time, requestBytes []byte) ([]byte, error)

type ValidatorSet ¶

type ValidatorSet interface {
	Has(ctx context.Context, nodeID ids.NodeID) bool // TODO return error
}

type ValidatorSubset ¶

type ValidatorSubset interface {
	Top(ctx context.Context, percentage float64) []ids.NodeID // TODO return error
}

type Validators ¶

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

Validators contains a set of nodes that are staking.

func NewValidators ¶

func NewValidators(
	peers *Peers,
	log log.Logger,
	netID ids.ID,
	validators validators.State,
	maxValidatorSetStaleness time.Duration,
) *Validators

func (*Validators) Has ¶

func (v *Validators) Has(ctx context.Context, nodeID ids.NodeID) bool

Has returns if nodeID is a connected validator

func (*Validators) Sample ¶

func (v *Validators) Sample(ctx context.Context, limit int) []ids.NodeID

Sample returns a random sample of connected validators

func (*Validators) Top ¶

func (v *Validators) Top(ctx context.Context, percentage float64) []ids.NodeID

Top returns the top [percentage] of validators, regardless of if they are connected or not.

Directories ¶

Path Synopsis
Package lp118 implements LP-118 message handling
Package lp118 implements LP-118 message handling
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