Documentation ¶
Index ¶
- Variables
- type AcceptedFrontierHandler
- type AcceptedHandler
- type AcceptedSender
- type AcceptedStateSummaryHandler
- type AcceptedStateSummarySender
- type AllGetsServer
- type AncestorsHandler
- type AppError
- type AppGossipHandler
- type AppHandler
- type AppRequestHandler
- type AppResponseHandler
- type AppSender
- type BootstrapTracker
- type BootstrapableEngine
- type ChitsHandler
- type Engine
- type FetchSender
- type FrontierSender
- type Fx
- type GetAcceptedFrontierHandler
- type GetAcceptedHandler
- type GetAcceptedStateSummaryHandler
- type GetAncestorsHandler
- type GetHandler
- type GetStateSummaryFrontierHandler
- type Haltable
- type Halter
- type Handler
- type InternalHandler
- type Message
- type PutHandler
- type QueryHandler
- type QuerySender
- type Request
- type SendConfig
- type Sender
- type StateSummaryFrontierHandler
- type StateSummarySender
- type StateSyncer
- type Timer
- type VM
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUndefined indicates an undefined error ErrUndefined = &AppError{ Code: 0, Message: "undefined", } // ErrTimeout is used to signal a response timeout ErrTimeout = &AppError{ Code: -1, Message: "timed out", } )
Functions ¶
This section is empty.
Types ¶
type AcceptedFrontierHandler ¶
type AcceptedFrontierHandler interface { // Notify this engine of the response to a previously sent // GetAcceptedFrontier message with the same requestID. AcceptedFrontier( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, ) error // Notify this engine that a GetAcceptedFrontier request it issued has // failed. // // This function will be called if a GetAcceptedFrontier message with // nodeID and requestID was previously sent by this engine and will not // receive a response. GetAcceptedFrontierFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpAcceptedFrontierHandler ¶
func NewNoOpAcceptedFrontierHandler(log logging.Logger) AcceptedFrontierHandler
type AcceptedHandler ¶
type AcceptedHandler interface { // Notify this engine of the response to a previously sent GetAccepted // message with the same requestID. // // It is not guaranteed that the containerIDs are a subset of the // containerIDs provided in the request. Accepted( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerIDs set.Set[ids.ID], ) error // Notify this engine that a GetAccepted request it issued has failed. // // This function will be called if a GetAccepted message with nodeID and // requestID was previously sent by this engine and will not receive a // response. GetAcceptedFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpAcceptedHandler ¶
func NewNoOpAcceptedHandler(log logging.Logger) AcceptedHandler
type AcceptedSender ¶
type AcceptedSender interface { // SendGetAccepted requests that every node in [nodeIDs] sends an Accepted // message with all the IDs in [containerIDs] that the node thinks are // accepted. SendGetAccepted( ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, containerIDs []ids.ID, ) // SendAccepted responds to a GetAccepted message with a set of IDs of // containers that are accepted. SendAccepted(ctx context.Context, nodeID ids.NodeID, requestID uint32, containerIDs []ids.ID) }
AcceptedSender defines how a consensus engine sends messages pertaining to accepted containers
type AcceptedStateSummaryHandler ¶
type AcceptedStateSummaryHandler interface { // Notify this engine of the response to a previously sent // GetAcceptedStateSummary message with the same requestID. // // It is not guaranteed that the summaryIDs have heights corresponding to // the heights in the request. AcceptedStateSummary( ctx context.Context, nodeID ids.NodeID, requestID uint32, summaryIDs set.Set[ids.ID], ) error // Notify this engine that a GetAcceptedStateSummary request it issued has // failed. // // This function will be called if a GetAcceptedStateSummary message with // nodeID and requestID was previously sent by this engine and will not // receive a response. GetAcceptedStateSummaryFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpAcceptedStateSummaryHandler ¶
func NewNoOpAcceptedStateSummaryHandler(log logging.Logger) AcceptedStateSummaryHandler
type AcceptedStateSummarySender ¶
type AcceptedStateSummarySender interface { // SendGetAcceptedStateSummary requests that every node in [nodeIDs] sends an // AcceptedStateSummary message with all the state summary IDs referenced by [heights] // that the node thinks are accepted. SendGetAcceptedStateSummary(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, heights []uint64) // SendAcceptedStateSummary responds to a AcceptedStateSummary message with a // set of summary ids that are accepted. SendAcceptedStateSummary(ctx context.Context, nodeID ids.NodeID, requestID uint32, summaryIDs []ids.ID) }
type AllGetsServer ¶
type AllGetsServer interface { GetStateSummaryFrontierHandler GetAcceptedStateSummaryHandler GetAcceptedFrontierHandler GetAcceptedHandler GetAncestorsHandler GetHandler }
type AncestorsHandler ¶
type AncestorsHandler interface { // Notify this engine of the response to a previously sent GetAncestors // message with the same requestID. // // It is expected, but not guaranteed, that the first element in containers // should be the container referenced in the request and that the rest of // the containers should be referenced by a prior container in the list. Ancestors( ctx context.Context, nodeID ids.NodeID, requestID uint32, containers [][]byte, ) error // Notify this engine that a GetAncestors request it issued has failed. // // This function will be called if a GetAncestors message with nodeID and // requestID was previously sent by this engine and will not receive a // response. GetAncestorsFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpAncestorsHandler ¶
func NewNoOpAncestorsHandler(log logging.Logger) AncestorsHandler
type AppError ¶
type AppError struct { // Code is application-defined and should be used for error matching Code int32 // Message is a human-readable error message Message string }
AppError is an application-defined error
type AppGossipHandler ¶
type AppGossipHandler interface { // Notify this engine of a gossip message from nodeID. // // The meaning of msg is application (VM) specific, and the VM defines how // to react to this message. // // This message is not expected in response to any event, and it does not // need to be responded to. AppGossip( ctx context.Context, nodeID ids.NodeID, msg []byte, ) error }
type AppHandler ¶
type AppHandler interface { AppRequestHandler AppResponseHandler AppGossipHandler }
func NewNoOpAppHandler ¶
func NewNoOpAppHandler(log logging.Logger) AppHandler
type AppRequestHandler ¶
type AppRequestHandler interface { // Notify this engine of a request for an AppResponse with the same // requestID. // // The meaning of request, and what should be sent in response to it, is // application (VM) specific. // // It is not guaranteed that request is well-formed or valid. // // This function can be called by any node at any time. AppRequest( ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte, ) error }
type AppResponseHandler ¶
type AppResponseHandler interface { // Notify this engine of the response to a previously sent AppRequest with // the same requestID. // // The meaning of response is application (VM) specifc. // // It is not guaranteed that response is well-formed or valid. AppResponse( ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte, ) error // Notify this engine that an AppRequest it issued has failed. // // This function will be called if an AppRequest message with nodeID and // requestID was previously sent by this engine and will not receive a // response. AppRequestFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *AppError, ) error }
type AppSender ¶
type AppSender interface { // Send an application-level request. // // The VM corresponding to this AppSender may receive either: // * An AppResponse from nodeID with ID [requestID] // * An AppRequestFailed from nodeID with ID [requestID] // // A nil return value guarantees that the VM corresponding to this AppSender // will receive exactly one of the above messages. // // A non-nil return value guarantees that the VM corresponding to this // AppSender will receive at most one of the above messages. SendAppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, appRequestBytes []byte) error // Send an application-level response to a request. // This response must be in response to an AppRequest that the VM corresponding // to this AppSender received from [nodeID] with ID [requestID]. SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, appResponseBytes []byte) error // SendAppError sends an application-level error to an AppRequest SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error // Gossip an application-level message. SendAppGossip( ctx context.Context, config SendConfig, appGossipBytes []byte, ) error }
AppSender sends VM-level messages to nodes in the network.
type BootstrapTracker ¶
type BootstrapTracker interface { // Returns true iff done bootstrapping IsBootstrapped() bool // Bootstrapped marks the named chain as being bootstrapped Bootstrapped(chainID ids.ID) OnBootstrapCompleted() chan struct{} }
BootstrapTracker describes the standard interface for tracking the status of a subnet bootstrapping
type BootstrapableEngine ¶
type BootstrapableEngine interface { Engine // Clear removes all containers to be processed upon bootstrapping Clear(ctx context.Context) error }
func TraceBootstrapableEngine ¶
func TraceBootstrapableEngine(bootstrapableEngine BootstrapableEngine, tracer trace.Tracer) BootstrapableEngine
type ChitsHandler ¶
type ChitsHandler interface { // Notify this engine of the response to a previously sent PullQuery or // PushQuery message with the same requestID. // // It is expected, but not guaranteed, that preferredID transitively // references preferredIDAtHeight and acceptedID. Chits( ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, preferredIDAtHeight ids.ID, acceptedID ids.ID, ) error // Notify this engine that a Query request it issued has failed. // // This function will be called if a PullQuery or PushQuery message with // nodeID and requestID was previously sent by this engine and will not // receive a response. QueryFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpChitsHandler ¶
func NewNoOpChitsHandler(log logging.Logger) ChitsHandler
type Engine ¶
type Engine interface { Handler // Return the context of the chain this engine is working on Context() *snow.ConsensusContext // Start engine operations from given request ID Start(ctx context.Context, startReqID uint32) error // Returns nil if the engine is healthy. // Periodically called and reported through the health API health.Checker }
Engine describes the standard interface of a consensus engine.
All nodeIDs are assumed to be authenticated.
A consensus engine may recover after returning an error, but it isn't required.
type FetchSender ¶
type FetchSender interface { // Request that the specified node send the specified container to this // node. SendGet(ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID) // SendGetAncestors requests that node [nodeID] send container [containerID] // and its ancestors. SendGetAncestors(ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID) // Tell the specified node about [container]. SendPut(ctx context.Context, nodeID ids.NodeID, requestID uint32, container []byte) // Give the specified node several containers at once. Should be in response // to a GetAncestors message with request ID [requestID] from the node. SendAncestors(ctx context.Context, nodeID ids.NodeID, requestID uint32, containers [][]byte) }
FetchSender defines how a consensus engine sends retrieval messages to other nodes.
type FrontierSender ¶
type FrontierSender interface { // SendGetAcceptedFrontier requests that every node in [nodeIDs] sends an // AcceptedFrontier message. SendGetAcceptedFrontier(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32) // SendAcceptedFrontier responds to a AcceptedFrontier message with this // engine's current accepted frontier. SendAcceptedFrontier( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, ) }
FrontierSender defines how a consensus engine sends frontier messages to other nodes.
type GetAcceptedFrontierHandler ¶
type GetAcceptedFrontierHandler interface { // Notify this engine of a request for an AcceptedFrontier message with the // same requestID and the ID of the most recently accepted container. // // This function can be called by any node at any time. GetAcceptedFrontier( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
type GetAcceptedHandler ¶
type GetAcceptedHandler interface { // Notify this engine of a request for an Accepted message with the same // requestID and the subset of containerIDs that this node has accepted. // // This function can be called by any node at any time. GetAccepted( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerIDs set.Set[ids.ID], ) error }
type GetAcceptedStateSummaryHandler ¶
type GetAcceptedStateSummaryHandler interface { // Notify this engine of a request for an AcceptedStateSummary message with // the same requestID and the state summary IDs at the requested heights. // If this node doesn't have access to a state summary ID at a requested // height, that height should be ignored. // // This function can be called by any node at any time. GetAcceptedStateSummary( ctx context.Context, nodeID ids.NodeID, requestID uint32, heights set.Set[uint64], ) error }
type GetAncestorsHandler ¶
type GetAncestorsHandler interface { // Notify this engine of a request for an Ancestors message with the same // requestID, containerID, and some of its ancestors on a best effort basis. // // This function can be called by any node at any time. GetAncestors( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, ) error }
type GetHandler ¶
type GetHandler interface { // Notify this engine of a request for a Put message with the same requestID // and the container whose ID is containerID. // // This function can be called by any node at any time. Get( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, ) error }
type GetStateSummaryFrontierHandler ¶
type GetStateSummaryFrontierHandler interface { // Notify this engine of a request for a StateSummaryFrontier message with // the same requestID and the engine's most recently accepted state summary. // // This function can be called by any node at any time. GetStateSummaryFrontier( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
type InternalHandler ¶
type InternalHandler interface { // Notify this engine of peer changes. validators.Connector // Notify this engine that a registered timeout has fired. Timeout(context.Context) error // Gossip to the network a container on the accepted frontier Gossip(context.Context) error // Halt this engine. // // This function will be called before the environment starts exiting. This // function is special, in that it does not expect the chain's context lock // to be held before calling this function. This function also does not // require the engine to have been started. Halt(context.Context) // Shutdown this engine. // // This function will be called when the environment is exiting. Shutdown(context.Context) error // Notify this engine of a message from the virtual machine. Notify(context.Context, Message) error }
func NewNoOpInternalHandler ¶
func NewNoOpInternalHandler(log logging.Logger) InternalHandler
type Message ¶
type Message uint32
Message is an enum of the message types that vms can send to consensus
const ( // PendingTxs notifies a consensus engine that its VM has pending // transactions. // // The consensus engine must eventually call BuildBlock at least once after // receiving this message. If the consensus engine receives multiple // PendingTxs messages between calls to BuildBlock, the engine may only call // BuildBlock once. PendingTxs Message = iota + 1 // StateSyncDone notifies the state syncer engine that the VM has finishing // syncing the requested state summary. StateSyncDone )
type PutHandler ¶
type PutHandler interface { // Notify this engine of either the response to a previously sent Get // message with the same requestID or an unsolicited container if the // requestID is MaxUint32. // // It is not guaranteed that container can be parsed or issued. Put( ctx context.Context, nodeID ids.NodeID, requestID uint32, container []byte, ) error // Notify this engine that a Get request it issued has failed. // // This function will be called if a Get message with nodeID and requestID // was previously sent by this engine and will not receive a response. GetFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpPutHandler ¶
func NewNoOpPutHandler(log logging.Logger) PutHandler
type QueryHandler ¶
type QueryHandler interface { // Notify this engine of a request for a Chits message with the same // requestID. // // If the provided containerID is not processing, the engine is expected to // respond with the node's current preferences before attempting to issue // it. // // This function can be called by any node at any time. PullQuery( ctx context.Context, nodeID ids.NodeID, requestID uint32, containerID ids.ID, requestedHeight uint64, ) error // Notify this engine of a request for a Chits message with the same // requestID. // // If the provided container is not processing, the engine is expected to // respond with the node's current preferences before attempting to issue // it. // // It is not guaranteed that container can be parsed or issued. // // This function can be called by any node at any time. PushQuery( ctx context.Context, nodeID ids.NodeID, requestID uint32, container []byte, requestedHeight uint64, ) error }
func NewNoOpQueryHandler ¶
func NewNoOpQueryHandler(log logging.Logger) QueryHandler
type QuerySender ¶
type QuerySender interface { // Request from the specified nodes their preferred frontier, given the // existence of the specified container. // This is the same as PullQuery, except that this message includes the body // of the container rather than its ID. SendPushQuery( ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, container []byte, requestedHeight uint64, ) // Request from the specified nodes their preferred frontier, given the // existence of the specified container. SendPullQuery( ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, containerID ids.ID, requestedHeight uint64, ) // Send chits to the specified node SendChits( ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, preferredIDAtHeight ids.ID, acceptedID ids.ID, ) }
QuerySender defines how a consensus engine sends query messages to other nodes.
type Request ¶
func (Request) MarshalText ¶
type SendConfig ¶
SendConfig is used to specify who to send messages to over the p2p network.
type Sender ¶
type Sender interface { StateSummarySender AcceptedStateSummarySender FrontierSender AcceptedSender FetchSender QuerySender AppSender }
Sender defines how a consensus engine sends messages and requests to other validators.
Messages can be categorized as either: requests, responses, or gossip. Gossip messages do not include requestIDs, because no response is expected from the peer. However, both requests and responses include requestIDs.
It is expected that each [nodeID + requestID + expected response type] that is outstanding at any given time is unique.
As an example, it is valid to send `Get(nodeA, request0)` and `PullQuery(nodeA, request0)` because they have different expected response types, `Put` and `Chits`.
Additionally, after having sent `Get(nodeA, request0)` and receiving either `Put(nodeA, request0)` or `GetFailed(nodeA, request0)`, it is valid to resend `Get(nodeA, request0)`. Because the initial `Get` request is no longer outstanding.
This means that requestIDs can be reused. In practice, requests always have a reasonable maximum timeout, so it is generally safe to assume that by the time the requestID space has been exhausted, the beginning of the requestID space is free of conflicts.
type StateSummaryFrontierHandler ¶
type StateSummaryFrontierHandler interface { // Notify this engine of the response to a previously sent // GetStateSummaryFrontier message with the same requestID. // // It is not guaranteed that the summary bytes are from a valid state // summary. StateSummaryFrontier( ctx context.Context, nodeID ids.NodeID, requestID uint32, summary []byte, ) error // Notify this engine that a GetStateSummaryFrontier request it issued has // failed. // // This function will be called if a GetStateSummaryFrontier message with // nodeID and requestID was previously sent by this engine and will not // receive a response. GetStateSummaryFrontierFailed( ctx context.Context, nodeID ids.NodeID, requestID uint32, ) error }
func NewNoOpStateSummaryFrontierHandler ¶
func NewNoOpStateSummaryFrontierHandler(log logging.Logger) StateSummaryFrontierHandler
type StateSummarySender ¶
type StateSummarySender interface { // SendGetStateSummaryFrontier requests that every node in [nodeIDs] sends a // StateSummaryFrontier message. SendGetStateSummaryFrontier(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32) // SendStateSummaryFrontier responds to a StateSummaryFrontier message with this // engine's current state summary frontier. SendStateSummaryFrontier(ctx context.Context, nodeID ids.NodeID, requestID uint32, summary []byte) }
StateSummarySender defines how a consensus engine sends state sync messages to other nodes.
type StateSyncer ¶
type StateSyncer interface { Engine // IsEnabled returns true if the underlying VM wants to perform state sync. // Any returned error will be considered fatal. IsEnabled(context.Context) (bool, error) }
StateSyncer controls the selection and verification of state summaries to drive VM state syncing. It collects the latest state summaries and elicit votes on them, making sure that a qualified majority of nodes support the selected state summary.
func TraceStateSyncer ¶
func TraceStateSyncer(stateSyncer StateSyncer, tracer trace.Tracer) StateSyncer
type Timer ¶
type Timer interface { // RegisterTimeout specifies how much time to delay the next timeout message // by. If the subnet has been bootstrapped, the timeout will fire // immediately. RegisterTimeout(time.Duration) }
Timer describes the standard interface for specifying a timeout
type VM ¶
type VM interface { AppHandler // Returns nil if the VM is healthy. // Periodically called and reported via the node's Health API. health.Checker // Connector represents a handler that is called on connection connect/disconnect validators.Connector // Initialize this VM. // [chainCtx]: Metadata about this VM. // [chainCtx.networkID]: The ID of the network this VM's chain is // running on. // [chainCtx.chainID]: The unique ID of the chain this VM is running on. // [chainCtx.Log]: Used to log messages // [chainCtx.NodeID]: The unique staker ID of this node. // [chainCtx.Lock]: A Read/Write lock shared by this VM and the // consensus engine that manages this VM. The write // lock is held whenever code in the consensus engine // calls the VM. // [dbManager]: The manager of the database this VM will persist data to. // [genesisBytes]: The byte-encoding of the genesis information of this // VM. The VM uses it to initialize its state. For // example, if this VM were an account-based payments // system, `genesisBytes` would probably contain a genesis // transaction that gives coins to some accounts, and this // transaction would be in the genesis block. // [toEngine]: The channel used to send messages to the consensus engine. // [fxs]: Feature extensions that attach to this VM. Initialize( ctx context.Context, chainCtx *snow.Context, db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, toEngine chan<- Message, fxs []*Fx, appSender AppSender, ) error // SetState communicates to VM its next state it starts SetState(ctx context.Context, state snow.State) error // Shutdown is called when the node is shutting down. Shutdown(context.Context) error // Version returns the version of the VM. Version(context.Context) (string, error) // Creates the HTTP handlers for custom chain network calls. // // This exposes handlers that the outside world can use to communicate with // the chain. Each handler has the path: // [Address of node]/ext/bc/[chain ID]/[extension] // // Returns a mapping from [extension]s to HTTP handlers. // // For example, if this VM implements an account-based payments system, // it have an extension called `accounts`, where clients could get // information about their accounts. CreateHandlers(context.Context) (map[string]http.Handler, error) }
VM describes the interface that all consensus VMs must implement
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package commonmock is a generated GoMock package.
|
Package commonmock is a generated GoMock package. |