Documentation ¶
Index ¶
- Constants
- type AcceptedHandler
- type AcceptedSender
- type AppHandler
- type AppSender
- type Bootstrapable
- type BootstrapableTest
- type Bootstrapper
- func (b *Bootstrapper) Accepted(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (b *Bootstrapper) AcceptedFrontier(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (b *Bootstrapper) Connected(nodeID ids.ShortID) error
- func (b *Bootstrapper) Disconnected(nodeID ids.ShortID) error
- func (b *Bootstrapper) GetAccepted(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (b *Bootstrapper) GetAcceptedFailed(validatorID ids.ShortID, requestID uint32) error
- func (b *Bootstrapper) GetAcceptedFrontier(validatorID ids.ShortID, requestID uint32) error
- func (b *Bootstrapper) GetAcceptedFrontierFailed(validatorID ids.ShortID, requestID uint32) error
- func (b *Bootstrapper) Initialize(config Config) error
- func (b *Bootstrapper) RestartBootstrap(reset bool) error
- type Config
- type Engine
- type EngineTest
- func (e *EngineTest) Accepted(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (e *EngineTest) AcceptedFrontier(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (e *EngineTest) AppGossip(nodeID ids.ShortID, msg []byte) error
- func (e *EngineTest) AppRequest(nodeID ids.ShortID, requestID uint32, deadline time.Time, request []byte) error
- func (e *EngineTest) AppRequestFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) AppResponse(nodeID ids.ShortID, requestID uint32, response []byte) error
- func (e *EngineTest) Chits(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (e *EngineTest) Connected(nodeID ids.ShortID) error
- func (e *EngineTest) Context() *snow.Context
- func (e *EngineTest) Default(cant bool)
- func (e *EngineTest) Disconnected(nodeID ids.ShortID) error
- func (e *EngineTest) Get(nodeID ids.ShortID, requestID uint32, containerID ids.ID) error
- func (e *EngineTest) GetAccepted(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
- func (e *EngineTest) GetAcceptedFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) GetAcceptedFrontier(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) GetAcceptedFrontierFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) GetAncestors(nodeID ids.ShortID, requestID uint32, containerID ids.ID) error
- func (e *EngineTest) GetAncestorsFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) GetFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) GetVM() VM
- func (e *EngineTest) Gossip() error
- func (e *EngineTest) Halt()
- func (e *EngineTest) HealthCheck() (interface{}, error)
- func (e *EngineTest) IsBootstrapped() bool
- func (e *EngineTest) MultiPut(nodeID ids.ShortID, requestID uint32, containers [][]byte) error
- func (e *EngineTest) Notify(msg Message) error
- func (e *EngineTest) PullQuery(nodeID ids.ShortID, requestID uint32, containerID ids.ID) error
- func (e *EngineTest) PushQuery(nodeID ids.ShortID, requestID uint32, containerID ids.ID, container []byte) error
- func (e *EngineTest) Put(nodeID ids.ShortID, requestID uint32, containerID ids.ID, container []byte) error
- func (e *EngineTest) QueryFailed(nodeID ids.ShortID, requestID uint32) error
- func (e *EngineTest) Shutdown() error
- func (e *EngineTest) Timeout() error
- type ExternalHandler
- type FetchHandler
- type FetchSender
- type Fetcher
- type FrontierHandler
- type FrontierSender
- type Fx
- type Gossiper
- type HTTPHandler
- type Haltable
- type Halter
- type Handler
- type InternalHandler
- type LockOption
- type Message
- type QueryHandler
- type QuerySender
- type Requests
- func (r *Requests) Add(vdr ids.ShortID, requestID uint32, containerID ids.ID)
- func (r *Requests) Contains(containerID ids.ID) bool
- func (r *Requests) Len() int
- func (r *Requests) Remove(vdr ids.ShortID, requestID uint32) (ids.ID, bool)
- func (r *Requests) RemoveAny(containerID ids.ID) bool
- func (r Requests) String() string
- type Sender
- type SenderTest
- func (s *SenderTest) Default(cant bool)
- func (s *SenderTest) SendAccepted(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID)
- func (s *SenderTest) SendAcceptedFrontier(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID)
- func (s *SenderTest) SendAppGossip(appGossipBytes []byte) error
- func (s *SenderTest) SendAppGossipSpecific(nodeIDs ids.ShortSet, appGossipBytes []byte) error
- func (s *SenderTest) SendAppRequest(nodeIDs ids.ShortSet, requestID uint32, appRequestBytes []byte) error
- func (s *SenderTest) SendAppResponse(nodeID ids.ShortID, requestID uint32, appResponseBytes []byte) error
- func (s *SenderTest) SendChits(vdr ids.ShortID, requestID uint32, votes []ids.ID)
- func (s *SenderTest) SendGet(vdr ids.ShortID, requestID uint32, vtxID ids.ID)
- func (s *SenderTest) SendGetAccepted(nodeIDs ids.ShortSet, requestID uint32, containerIDs []ids.ID)
- func (s *SenderTest) SendGetAcceptedFrontier(validatorIDs ids.ShortSet, requestID uint32)
- func (s *SenderTest) SendGetAncestors(validatorID ids.ShortID, requestID uint32, vtxID ids.ID)
- func (s *SenderTest) SendGossip(containerID ids.ID, container []byte)
- func (s *SenderTest) SendMultiPut(vdr ids.ShortID, requestID uint32, vtxs [][]byte)
- func (s *SenderTest) SendPullQuery(vdrs ids.ShortSet, requestID uint32, vtxID ids.ID)
- func (s *SenderTest) SendPushQuery(vdrs ids.ShortSet, requestID uint32, vtxID ids.ID, vtx []byte)
- func (s *SenderTest) SendPut(vdr ids.ShortID, requestID uint32, vtxID ids.ID, vtx []byte)
- type Subnet
- type SubnetTest
- type TestVM
- func (vm *TestVM) AppGossip(nodeID ids.ShortID, msg []byte) error
- func (vm *TestVM) AppRequest(nodeID ids.ShortID, requestID uint32, deadline time.Time, request []byte) error
- func (vm *TestVM) AppRequestFailed(nodeID ids.ShortID, requestID uint32) error
- func (vm *TestVM) AppResponse(nodeID ids.ShortID, requestID uint32, response []byte) error
- func (vm *TestVM) Bootstrapped() error
- func (vm *TestVM) Bootstrapping() error
- func (vm *TestVM) Connected(id ids.ShortID) error
- func (vm *TestVM) CreateHandlers() (map[string]*HTTPHandler, error)
- func (vm *TestVM) CreateStaticHandlers() (map[string]*HTTPHandler, error)
- func (vm *TestVM) Default(cant bool)
- func (vm *TestVM) Disconnected(id ids.ShortID) error
- func (vm *TestVM) HealthCheck() (interface{}, error)
- func (vm *TestVM) Initialize(ctx *snow.Context, db manager.Manager, ...) error
- func (vm *TestVM) Shutdown() error
- func (vm *TestVM) Version() (string, error)
- type Timer
- type TimerTest
- type VM
Constants ¶
const ( // StatusUpdateFrequency is how many containers should be processed between // logs StatusUpdateFrequency = 5000 // MaxOutstandingGetAncestorsRequests is the maximum number of GetAncestors // sent but not responded to/failed MaxOutstandingGetAncestorsRequests = 10 // MaxOutstandingBootstrapRequests is the maximum number of // GetAcceptedFrontier and GetAccepted messages sent but not responded // to/failed MaxOutstandingBootstrapRequests = 50 // MaxTimeFetchingAncestors is the maximum amount of time to spend fetching // vertices during a call to GetAncestors MaxTimeFetchingAncestors = 50 * time.Millisecond )
const ( WriteLock = iota ReadLock NoLock )
List of all allowed options
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcceptedHandler ¶
type AcceptedHandler interface { // Notify this engine of a request to filter non-accepted vertices. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID. However, the validatorID is // assumed to be authenticated. // // This engine should respond with an Accepted message with the same // requestID, and the subset of the containerIDs that this node has decided // are accepted. GetAccepted( validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID, ) error // Notify this engine of a set of accepted vertices. // // This function can be called by any validator. It is not safe to assume // this message is in response to a GetAccepted message, is utilizing a // unique requestID, or that the containerIDs are a subset of the // containerIDs from a GetAccepted message. However, the validatorID is // assumed to be authenticated. Accepted( validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID, ) error // Notify this engine that a get accepted request it issued has failed. // // This function will be called if the engine sent a GetAccepted message // that is not anticipated to be responded to. This could be because the // recipient of the message is unknown or if the message request has timed // out. // // The validatorID, and requestID, are assumed to be the same as those sent // in the GetAccepted message. GetAcceptedFailed(validatorID ids.ShortID, requestID uint32) error }
AcceptedHandler defines how a consensus engine reacts to messages pertaining to accepted containers from other validators. Functions only return fatal errors if they occur.
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( nodeIDs ids.ShortSet, requestID uint32, containerIDs []ids.ID, ) // SendAccepted responds to a GetAccepted message with a set of IDs of // containers that are accepted. SendAccepted(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) }
AcceptedSender defines how a consensus engine sends messages pertaining to accepted containers
type AppHandler ¶ added in v0.2.3
type AppHandler interface { // Notify this engine of a request for data from [nodeID]. // This node should send an AppResponse to [nodeID] in response to // this message using the same request ID and before the deadline. // The VM may choose to not send a response to this request. // The meaning of [request], and what should be sent in response to it, // is application (VM) defined. // It is not guaranteed that [request] is well-formed/valid. // The VM must do this validation. // A non-nil return value causes this engine to shutdown. AppRequest(nodeID ids.ShortID, requestID uint32, deadline time.Time, request []byte) error // Notify this engine that an AppRequest message it sent to // [nodeID] with request ID [requestID] failed. // This may be because the request timed out or because the message // couldn't be sent to [nodeID]. // It is guaranteed that: // * This engine sent a request to [nodeID] with ID [requestID]. // * AppRequestFailed([nodeID], [requestID]) has not already been called. // * AppResponse([nodeID], [requestID]) has not already been called. // A non-nil return value causes this engine to shutdown. AppRequestFailed(nodeID ids.ShortID, requestID uint32) error // Notify this engine of a response to the AppRequest message it sent // to [nodeID] with request ID [requestID]. // The meaning of [response] is application (VM) defined. // It is guaranteed that: // * This engine sent a request to [nodeID] with ID [requestID]. // * AppRequestFailed([nodeID], [requestID]) has not already been called. // * AppResponse([nodeID], [requestID]) has not already been called. // It is not guaranteed that [response] contains the expected response, // or that [response] is well-formed/valid. // The VM must perform the validation of [response]. // If [response] is invalid or not the expected response, the VM chooses how to react. // For example, the VM may send another AppRequest, or it may give up // trying to get the requested information. // A non-nil return value causes this engine to shutdown. // Therefore, receipt of an unexpected or invalid [response] // should not cause this method to return a non-nil error! AppResponse(nodeID ids.ShortID, requestID uint32, response []byte) error // Notify this engine of a gossip message from [nodeID]. // This message is not expected in response to any event, and it does // not need to be responded to. // The meaning of [msg] is application (VM) defined, and the VM defines // how to react to this message. // A node may gossip the same message multiple times. That is, // AppGossip([nodeID], [msg]) may be called multiple times. // A non-nil return value causes this engine to shutdown. AppGossip(nodeID ids.ShortID, msg []byte) error }
type AppSender ¶ added in v0.2.3
type AppSender interface { // Send an application-level request. // A nil return value guarantees that for each nodeID in [nodeIDs], // the VM corresponding to this AppSender eventually receives either: // * An AppResponse from nodeID with ID [requestID] // * An AppRequestFailed from nodeID with ID [requestID] // Exactly one of the above messages will eventually be received per nodeID. // A non-nil error should be considered fatal. SendAppRequest(nodeIDs ids.ShortSet, 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]. // A non-nil error should be considered fatal. SendAppResponse(nodeID ids.ShortID, requestID uint32, appResponseBytes []byte) error // Gossip an application-level message. // A non-nil error should be considered fatal. SendAppGossip(appGossipBytes []byte) error SendAppGossipSpecific(nodeIDs ids.ShortSet, appGossipBytes []byte) error }
AppSender sends application (VM) level messages. See also common.AppHandler.
type Bootstrapable ¶
type Bootstrapable interface { // Returns the set of containerIDs that are accepted, but have no accepted // children. CurrentAcceptedFrontier() ([]ids.ID, error) // Returns the subset of containerIDs that are accepted by this chain. FilterAccepted(containerIDs []ids.ID) (acceptedContainerIDs []ids.ID) // Force the provided containers to be accepted. Only returns fatal errors // if they occur. ForceAccepted(acceptedContainerIDs []ids.ID) error }
Bootstrapable defines the functionality required to support bootstrapping
type BootstrapableTest ¶
type BootstrapableTest struct { T *testing.T CantCurrentAcceptedFrontier, CantFilterAccepted, CantForceAccepted bool CurrentAcceptedFrontierF func() (acceptedContainerIDs []ids.ID, err error) FilterAcceptedF func(containerIDs []ids.ID) (acceptedContainerIDs []ids.ID) ForceAcceptedF func(acceptedContainerIDs []ids.ID) error }
BootstrapableTest is a test engine that supports bootstrapping
func (*BootstrapableTest) CurrentAcceptedFrontier ¶
func (b *BootstrapableTest) CurrentAcceptedFrontier() ([]ids.ID, error)
CurrentAcceptedFrontier implements the Bootstrapable interface
func (*BootstrapableTest) Default ¶
func (b *BootstrapableTest) Default(cant bool)
Default sets the default on call handling
func (*BootstrapableTest) FilterAccepted ¶
func (b *BootstrapableTest) FilterAccepted(containerIDs []ids.ID) []ids.ID
FilterAccepted implements the Bootstrapable interface
func (*BootstrapableTest) ForceAccepted ¶
func (b *BootstrapableTest) ForceAccepted(containerIDs []ids.ID) error
ForceAccepted implements the Bootstrapable interface
type Bootstrapper ¶
type Bootstrapper struct { Config Halter // Tracks the last requestID that was used in a request RequestID uint32 // True if RestartBootstrap has been called at least once Restarted bool // contains filtered or unexported fields }
Bootstrapper implements the Engine interface.
func (*Bootstrapper) Accepted ¶
func (b *Bootstrapper) Accepted(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
Accepted implements the Engine interface.
func (*Bootstrapper) AcceptedFrontier ¶
func (b *Bootstrapper) AcceptedFrontier(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
AcceptedFrontier implements the Engine interface.
func (*Bootstrapper) Connected ¶
func (b *Bootstrapper) Connected(nodeID ids.ShortID) error
Connected implements the Engine interface.
func (*Bootstrapper) Disconnected ¶
func (b *Bootstrapper) Disconnected(nodeID ids.ShortID) error
Disconnected implements the Engine interface.
func (*Bootstrapper) GetAccepted ¶
func (b *Bootstrapper) GetAccepted(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error
GetAccepted implements the Engine interface.
func (*Bootstrapper) GetAcceptedFailed ¶
func (b *Bootstrapper) GetAcceptedFailed(validatorID ids.ShortID, requestID uint32) error
GetAcceptedFailed implements the Engine interface.
func (*Bootstrapper) GetAcceptedFrontier ¶
func (b *Bootstrapper) GetAcceptedFrontier(validatorID ids.ShortID, requestID uint32) error
GetAcceptedFrontier implements the Engine interface.
func (*Bootstrapper) GetAcceptedFrontierFailed ¶
func (b *Bootstrapper) GetAcceptedFrontierFailed(validatorID ids.ShortID, requestID uint32) error
GetAcceptedFrontierFailed implements the Engine interface.
func (*Bootstrapper) Initialize ¶
func (b *Bootstrapper) Initialize(config Config) error
Initialize implements the Engine interface.
func (*Bootstrapper) RestartBootstrap ¶
func (b *Bootstrapper) RestartBootstrap(reset bool) error
type Config ¶
type Config struct { Ctx *snow.Context Validators validators.Set Beacons validators.Set SampleK int StartupAlpha uint64 Alpha uint64 Sender Sender Bootstrapable Bootstrapable Subnet Subnet Timer Timer // Should Bootstrap be retried RetryBootstrap bool // Max number of times to retry bootstrap before warning the node operator RetryBootstrapWarnFrequency int // Max time to spend fetching a container and its ancestors when responding // to a GetAncestors MaxTimeGetAncestors time.Duration // Max number of containers in a multiput message sent by this node. MultiputMaxContainersSent int // This node will only consider the first [MultiputMaxContainersReceived] // containers in a multiput it receives. MultiputMaxContainersReceived int }
Config wraps the common configurations that are needed by a Snow consensus engine
func DefaultConfigTest ¶
func DefaultConfigTest() Config
DefaultConfigTest returns a test configuration
func (*Config) IsBootstrapped ¶
IsBootstrapped returns true iff this chain is done bootstrapping
type Engine ¶
type Engine interface { Handler // Return the context of the chain this engine is working on Context() *snow.Context // Returns true iff the chain is done bootstrapping IsBootstrapped() bool // Returns nil if the engine is healthy. // Periodically called and reported through the health API health.Checkable // GetVM returns this engine's VM GetVM() VM }
Engine describes the standard interface of a consensus engine
type EngineTest ¶
type EngineTest struct { T *testing.T CantIsBootstrapped, CantTimeout, CantGossip, CantHalt, CantShutdown, CantContext, CantNotify, CantGetAcceptedFrontier, CantGetAcceptedFrontierFailed, CantAcceptedFrontier, CantGetAccepted, CantGetAcceptedFailed, CantAccepted, CantGet, CantGetAncestors, CantGetFailed, CantGetAncestorsFailed, CantPut, CantMultiPut, CantPushQuery, CantPullQuery, CantQueryFailed, CantChits, CantConnected, CantDisconnected, CantHealth, CantAppRequest, CantAppResponse, CantAppGossip, CantAppRequestFailed, CantGetVM bool IsBootstrappedF func() bool ContextF func() *snow.Context HaltF func() TimeoutF, GossipF, ShutdownF func() error NotifyF func(Message) error GetF, GetAncestorsF, PullQueryF func(nodeID ids.ShortID, requestID uint32, containerID ids.ID) error PutF, PushQueryF func(nodeID ids.ShortID, requestID uint32, containerID ids.ID, container []byte) error MultiPutF func(nodeID ids.ShortID, requestID uint32, containers [][]byte) error AcceptedFrontierF, GetAcceptedF, AcceptedF, ChitsF func(nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID) error GetAcceptedFrontierF, GetFailedF, GetAncestorsFailedF, QueryFailedF, GetAcceptedFrontierFailedF, GetAcceptedFailedF, AppRequestFailedF func(nodeID ids.ShortID, requestID uint32) error ConnectedF, DisconnectedF func(nodeID ids.ShortID) error HealthF func() (interface{}, error) GetVMF func() VM AppRequestF, AppResponseF func(nodeID ids.ShortID, requestID uint32, msg []byte) error AppGossipF func(nodeID ids.ShortID, msg []byte) error }
EngineTest is a test engine
func (*EngineTest) AcceptedFrontier ¶
func (*EngineTest) AppGossip ¶ added in v0.2.3
func (e *EngineTest) AppGossip(nodeID ids.ShortID, msg []byte) error
func (*EngineTest) AppRequest ¶ added in v0.2.3
func (*EngineTest) AppRequestFailed ¶ added in v0.2.3
func (e *EngineTest) AppRequestFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) AppResponse ¶ added in v0.2.3
func (*EngineTest) Context ¶
func (e *EngineTest) Context() *snow.Context
func (*EngineTest) Default ¶
func (e *EngineTest) Default(cant bool)
func (*EngineTest) Disconnected ¶
func (e *EngineTest) Disconnected(nodeID ids.ShortID) error
func (*EngineTest) GetAccepted ¶
func (*EngineTest) GetAcceptedFailed ¶
func (e *EngineTest) GetAcceptedFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) GetAcceptedFrontier ¶
func (e *EngineTest) GetAcceptedFrontier(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) GetAcceptedFrontierFailed ¶
func (e *EngineTest) GetAcceptedFrontierFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) GetAncestors ¶
func (*EngineTest) GetAncestorsFailed ¶
func (e *EngineTest) GetAncestorsFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) GetFailed ¶
func (e *EngineTest) GetFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) GetVM ¶
func (e *EngineTest) GetVM() VM
func (*EngineTest) Gossip ¶
func (e *EngineTest) Gossip() error
func (*EngineTest) Halt ¶
func (e *EngineTest) Halt()
func (*EngineTest) HealthCheck ¶
func (e *EngineTest) HealthCheck() (interface{}, error)
func (*EngineTest) IsBootstrapped ¶
func (e *EngineTest) IsBootstrapped() bool
func (*EngineTest) Notify ¶
func (e *EngineTest) Notify(msg Message) error
func (*EngineTest) QueryFailed ¶
func (e *EngineTest) QueryFailed(nodeID ids.ShortID, requestID uint32) error
func (*EngineTest) Shutdown ¶
func (e *EngineTest) Shutdown() error
func (*EngineTest) Timeout ¶
func (e *EngineTest) Timeout() error
type ExternalHandler ¶
type ExternalHandler interface { FrontierHandler AcceptedHandler FetchHandler QueryHandler }
ExternalHandler defines how a consensus engine reacts to messages and requests from other validators
type FetchHandler ¶
type FetchHandler interface { AppHandler // Notify this engine of a request for a container. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID. It is also not safe to // assume the requested containerID exists. However, the validatorID is // assumed to be authenticated. // // There should never be a situation where a virtuous node sends a Get // request to another virtuous node that does not have the requested // container. Unless that container was pruned from the active set. // // This engine should respond with a Put message with the same requestID if // the container was locally available. Otherwise, the message can be safely // dropped. Get(validatorID ids.ShortID, requestID uint32, containerID ids.ID) error // Notify this engine of a request for a container and its ancestors. // The request is from validator [validatorID]. The requested container is [containerID]. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID. It is also not safe to // assume the requested containerID exists. However, the validatorID is // assumed to be authenticated. // // This engine should respond with a MultiPut message with the same requestID, // which contains [containerID] as well as its ancestors. See MultiPut's documentation. // // If this engine doesn't have some ancestors, it should reply with its best effort attempt at getting them. // If this engine doesn't have [containerID] it can ignore this message. GetAncestors(validatorID ids.ShortID, requestID uint32, containerID ids.ID) error // Notify this engine of a container. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID or even that the containerID // matches the ID of the container bytes. However, the validatorID is // assumed to be authenticated. // // This engine needs to request and receive missing ancestors of the // container before adding the container to consensus. Once all ancestor // containers are added, pushes the container into the consensus. Put( validatorID ids.ShortID, requestID uint32, containerID ids.ID, container []byte, ) error // Notify this engine of multiple containers. // Each element of [containers] is the byte representation of a container. // // This should only be called during bootstrapping, and in response to a GetAncestors message to // [validatorID] with request ID [requestID]. This call should contain the container requested in // that message, along with ancestors. // The containers should be in BFS order (ie the first container must be the container // requested in the GetAncestors message and further back ancestors are later in [containers] // // It is not safe to assume this message is in response to a GetAncestor message, that this // message has a unique requestID or that any of the containers in [containers] are valid. // However, the validatorID is assumed to be authenticated. MultiPut( validatorID ids.ShortID, requestID uint32, containers [][]byte, ) error // Notify this engine that a get request it issued has failed. // // This function will be called if the engine sent a Get message that is not // anticipated to be responded to. This could be because the recipient of // the message is unknown or if the message request has timed out. // // The validatorID and requestID are assumed to be the same as those sent in // the Get message. GetFailed(validatorID ids.ShortID, requestID uint32) error // Notify this engine that a GetAncestors request it issued has failed. // // This function will be called if the engine sent a GetAncestors message that is not // anticipated to be responded to. This could be because the recipient of // the message is unknown or if the message request has timed out. // // The validatorID and requestID are assumed to be the same as those sent in // the GetAncestors message. GetAncestorsFailed(validatorID ids.ShortID, requestID uint32) error }
FetchHandler defines how a consensus engine reacts to retrieval messages from other validators. Functions only return fatal errors if they occur.
type FetchSender ¶
type FetchSender interface { // Request that the specified node send the specified container to this // node. SendGet(nodeID ids.ShortID, requestID uint32, containerID ids.ID) // SendGetAncestors requests that node [nodeID] send container [containerID] // and its ancestors. SendGetAncestors(nodeID ids.ShortID, requestID uint32, containerID ids.ID) // Tell the specified node that the container whose ID is [containerID] has // body [container]. SendPut( nodeID ids.ShortID, requestID uint32, containerID ids.ID, 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. SendMultiPut(nodeID ids.ShortID, requestID uint32, containers [][]byte) }
FetchSender defines how a consensus engine sends retrieval messages to other nodes.
type FrontierHandler ¶
type FrontierHandler interface { // Notify this engine of a request for the accepted frontier of vertices. // // The accepted frontier is the set of accepted vertices that do not have // any accepted descendants. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID. However, the validatorID is // assumed to be authenticated. // // This engine should respond with an AcceptedFrontier message with the same // requestID, and the engine's current accepted frontier. GetAcceptedFrontier(validatorID ids.ShortID, requestID uint32) error // Notify this engine of an accepted frontier. // // This function can be called by any validator. It is not safe to assume // this message is in response to a GetAcceptedFrontier message, is // utilizing a unique requestID, or that the containerIDs from a valid // frontier. However, the validatorID is assumed to be authenticated. AcceptedFrontier( validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID, ) error // Notify this engine that a get accepted frontier request it issued has // failed. // // This function will be called if the engine sent a GetAcceptedFrontier // message that is not anticipated to be responded to. This could be because // the recipient of the message is unknown or if the message request has // timed out. // // The validatorID, and requestID, are assumed to be the same as those sent // in the GetAcceptedFrontier message. GetAcceptedFrontierFailed(validatorID ids.ShortID, requestID uint32) error }
FrontierHandler defines how a consensus engine reacts to frontier messages from other validators. Returned errors should be treated as fatal and require the chain to shutdown.
type FrontierSender ¶
type FrontierSender interface { // SendGetAcceptedFrontier requests that every node in [nodeIDs] sends an // AcceptedFrontier message. SendGetAcceptedFrontier(nodeIDs ids.ShortSet, requestID uint32) // SendAcceptedFrontier responds to a AcceptedFrontier message with this // engine's current accepted frontier. SendAcceptedFrontier( nodeID ids.ShortID, requestID uint32, containerIDs []ids.ID, ) }
FrontierSender defines how a consensus engine sends frontier messages to other nodes.
type Gossiper ¶
type Gossiper interface { // Gossip the provided container throughout the network SendGossip(containerID ids.ID, container []byte) }
Gossiper defines how a consensus engine gossips a container on the accepted frontier to other nodes
type HTTPHandler ¶
type HTTPHandler struct { LockOptions LockOption Handler http.Handler }
type Handler ¶
type Handler interface { ExternalHandler InternalHandler }
Handler defines the functions that are acted on the node
type InternalHandler ¶
type InternalHandler interface { // Notify this engine that a registered timeout has fired. Timeout() error // Gossip to the network a container on the accepted frontier Gossip() error // Halt this engine. // // This function will be called before the environment starts exiting. This // function is slightly special, in that it does not expect the chain's // context lock to be held before calling this function. Halt() // Shutdown this engine. // // This function will be called when the environment is exiting. Shutdown() error // Notify this engine of a message from the virtual machine. Notify(Message) error // Notify this engine of a new peer. Connected(validatorID ids.ShortID) error // Notify this engine of a removed peer. Disconnected(validatorID ids.ShortID) error }
InternalHandler defines how this consensus engine reacts to messages from other components of this validator. Functions only return fatal errors if they occur.
type LockOption ¶
type LockOption uint32
LockOption allows the vm to specify their lock option based on their endpoint
type Message ¶
type Message uint32
Message is an enum of the message types that vms can send to consensus
type QueryHandler ¶
type QueryHandler interface { // Notify this engine of a request for our preferences. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID. However, the validatorID is // assumed to be authenticated. // // If the container or its ancestry is incomplete, this engine is expected // to request the missing containers from the validator. Once the ancestry // is complete, this engine should send this validator the current // preferences in a Chits message. The Chits message should have the same // requestID that was passed in here. PullQuery( validatorID ids.ShortID, requestID uint32, containerID ids.ID, ) error // Notify this engine of a request for our preferences. // // This function can be called by any validator. It is not safe to assume // this message is utilizing a unique requestID or even that the containerID // matches the ID of the container bytes. However, the validatorID is // assumed to be authenticated. // // This function is meant to behave the same way as PullQuery, except the // container is optimistically provided to potentially remove the need for // a series of Get/Put messages. // // If the ancestry of the container is incomplete, this engine is expected // to request the ancestry from the validator. Once the ancestry is // complete, this engine should send this validator the current preferences // in a Chits message. The Chits message should have the same requestID that // was passed in here. PushQuery( validatorID ids.ShortID, requestID uint32, containerID ids.ID, container []byte, ) error // Notify this engine of the specified validators preferences. // // This function can be called by any validator. It is not safe to assume // this message is in response to a PullQuery or a PushQuery message. // However, the validatorID is assumed to be authenticated. Chits(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID) error // Notify this engine that a query it issued has failed. // // This function will be called if the engine sent a PullQuery or PushQuery // message that is not anticipated to be responded to. This could be because // the recipient of the message is unknown or if the message request has // timed out. // // The validatorID and the requestID are assumed to be the same as those // sent in the Query message. QueryFailed(validatorID ids.ShortID, requestID uint32) error }
QueryHandler defines how a consensus engine reacts to query messages from other validators. Functions only return fatal errors if they occur.
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 not only // the ID of the container but also its body. SendPushQuery( nodeIDs ids.ShortSet, requestID uint32, containerID ids.ID, container []byte, ) // Request from the specified nodes their preferred frontier, given the // existence of the specified container. SendPullQuery(nodeIDs ids.ShortSet, requestID uint32, containerID ids.ID) // Send chits to the specified node SendChits(nodeID ids.ShortID, requestID uint32, votes []ids.ID) }
QuerySender defines how a consensus engine sends query messages to other nodes.
type Requests ¶
type Requests struct {
// contains filtered or unexported fields
}
Requests tracks pending container messages from a peer.
func (*Requests) Add ¶
Add a request. Assumes that requestIDs are unique. Assumes that containerIDs are only in one request at a time.
func (*Requests) Contains ¶
Contains returns true if there is an outstanding request for the container ID.
func (*Requests) Remove ¶
Remove attempts to abandon a requestID sent to a validator. If the request is currently outstanding, the requested ID will be returned along with true. If the request isn't currently outstanding, false will be returned.
type Sender ¶
type Sender interface { FrontierSender AcceptedSender FetchSender QuerySender Gossiper AppSender }
Sender defines how a consensus engine sends messages and requests to other validators
type SenderTest ¶
type SenderTest struct { T *testing.T CantSendGetAcceptedFrontier, CantSendAcceptedFrontier, CantSendGetAccepted, CantSendAccepted, CantSendGet, CantSendGetAncestors, CantSendPut, CantSendMultiPut, CantSendPullQuery, CantSendPushQuery, CantSendChits, CantSendGossip, CantSendAppRequest, CantSendAppResponse, CantSendAppGossip, CantSendAppGossipSpecific bool SendGetAcceptedFrontierF func(ids.ShortSet, uint32) SendAcceptedFrontierF func(ids.ShortID, uint32, []ids.ID) SendGetAcceptedF func(ids.ShortSet, uint32, []ids.ID) SendAcceptedF func(ids.ShortID, uint32, []ids.ID) SendGetF func(ids.ShortID, uint32, ids.ID) SendGetAncestorsF func(ids.ShortID, uint32, ids.ID) SendPutF func(ids.ShortID, uint32, ids.ID, []byte) SendMultiPutF func(ids.ShortID, uint32, [][]byte) SendPushQueryF func(ids.ShortSet, uint32, ids.ID, []byte) SendPullQueryF func(ids.ShortSet, uint32, ids.ID) SendChitsF func(ids.ShortID, uint32, []ids.ID) SendGossipF func(ids.ID, []byte) SendAppRequestF func(ids.ShortSet, uint32, []byte) error SendAppResponseF func(ids.ShortID, uint32, []byte) error SendAppGossipF func([]byte) error SendAppGossipSpecificF func(ids.ShortSet, []byte) error }
SenderTest is a test sender
func (*SenderTest) Default ¶
func (s *SenderTest) Default(cant bool)
Default set the default callable value to [cant]
func (*SenderTest) SendAccepted ¶ added in v0.2.3
SendAccepted calls SendAcceptedF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendAcceptedFrontier ¶ added in v0.2.3
func (s *SenderTest) SendAcceptedFrontier(validatorID ids.ShortID, requestID uint32, containerIDs []ids.ID)
SendAcceptedFrontier calls SendAcceptedFrontierF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendAppGossip ¶ added in v0.2.3
func (s *SenderTest) SendAppGossip(appGossipBytes []byte) error
SendAppGossip calls SendAppGossipF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendAppGossipSpecific ¶ added in v0.2.3
func (s *SenderTest) SendAppGossipSpecific(nodeIDs ids.ShortSet, appGossipBytes []byte) error
SendAppGossipSpecific calls SendAppGossipSpecificF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendAppRequest ¶ added in v0.2.3
func (s *SenderTest) SendAppRequest(nodeIDs ids.ShortSet, requestID uint32, appRequestBytes []byte) error
SendAppRequest calls SendAppRequestF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendAppResponse ¶ added in v0.2.3
func (s *SenderTest) SendAppResponse(nodeID ids.ShortID, requestID uint32, appResponseBytes []byte) error
SendAppResponse calls SendAppResponseF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendChits ¶ added in v0.2.3
SendChits calls SendChitsF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendGet ¶ added in v0.2.3
SendGet calls SendGetF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendGetAccepted ¶ added in v0.2.3
SendGetAccepted calls SendGetAcceptedF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendGetAcceptedFrontier ¶ added in v0.2.3
func (s *SenderTest) SendGetAcceptedFrontier(validatorIDs ids.ShortSet, requestID uint32)
SendGetAcceptedFrontier calls SendGetAcceptedFrontierF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendGetAncestors ¶ added in v0.2.3
SendGetAncestors calls SendGetAncestorsF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendGossip ¶ added in v0.2.3
func (s *SenderTest) SendGossip(containerID ids.ID, container []byte)
SendGossip calls SendGossipF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendMultiPut ¶ added in v0.2.3
func (s *SenderTest) SendMultiPut(vdr ids.ShortID, requestID uint32, vtxs [][]byte)
SendMultiPut calls SendMultiPutF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendPullQuery ¶ added in v0.2.3
SendPullQuery calls SendPullQueryF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SenderTest) SendPushQuery ¶ added in v0.2.3
SendPushQuery calls SendPushQueryF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
type Subnet ¶
type Subnet interface { // Returns true iff the subnet is done bootstrapping IsBootstrapped() bool // Bootstrapped marks the named chain as being bootstrapped Bootstrapped(chainID ids.ID) }
Subnet describes the standard interface of a subnet description
type SubnetTest ¶
type SubnetTest struct { T *testing.T CantIsBootstrapped, CantBootstrapped bool IsBootstrappedF func() bool BootstrappedF func(ids.ID) }
SubnetTest is a test subnet
func (*SubnetTest) Bootstrapped ¶
func (s *SubnetTest) Bootstrapped(chainID ids.ID)
Bootstrapped calls BootstrappedF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail.
func (*SubnetTest) Default ¶
func (s *SubnetTest) Default(cant bool)
Default set the default callable value to [cant]
func (*SubnetTest) IsBootstrapped ¶
func (s *SubnetTest) IsBootstrapped() bool
IsBootstrapped calls IsBootstrappedF if it was initialized. If it wasn't initialized and this function shouldn't be called and testing was initialized, then testing will fail. Defaults to returning false.
type TestVM ¶
type TestVM struct { T *testing.T CantInitialize, CantBootstrapping, CantBootstrapped, CantShutdown, CantCreateHandlers, CantCreateStaticHandlers, CantHealthCheck, CantConnected, CantDisconnected, CantVersion, CantAppRequest, CantAppResponse, CantAppGossip, CantAppRequestFailed bool InitializeF func(*snow.Context, manager.Manager, []byte, []byte, []byte, chan<- Message, []*Fx, AppSender) error BootstrappingF, BootstrappedF, ShutdownF func() error CreateHandlersF func() (map[string]*HTTPHandler, error) CreateStaticHandlersF func() (map[string]*HTTPHandler, error) ConnectedF func(ids.ShortID) error DisconnectedF func(ids.ShortID) error HealthCheckF func() (interface{}, error) AppRequestF func(nodeID ids.ShortID, requestID uint32, deadline time.Time, msg []byte) error AppResponseF func(nodeID ids.ShortID, requestID uint32, msg []byte) error AppGossipF func(nodeID ids.ShortID, msg []byte) error AppRequestFailedF func(nodeID ids.ShortID, requestID uint32) error VersionF func() (string, error) }
TestVM is a test vm
func (*TestVM) AppRequest ¶ added in v0.2.3
func (*TestVM) AppRequestFailed ¶ added in v0.2.3
func (*TestVM) AppResponse ¶ added in v0.2.3
func (*TestVM) Bootstrapped ¶
func (*TestVM) Bootstrapping ¶
func (*TestVM) CreateHandlers ¶
func (vm *TestVM) CreateHandlers() (map[string]*HTTPHandler, error)
func (*TestVM) CreateStaticHandlers ¶
func (vm *TestVM) CreateStaticHandlers() (map[string]*HTTPHandler, error)
func (*TestVM) HealthCheck ¶
func (*TestVM) Initialize ¶
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 TimerTest ¶
TimerTest is a test timer
func (*TimerTest) RegisterTimeout ¶
type VM ¶
type VM interface { AppHandler // Returns nil if the VM is healthy. // Periodically called and reported via the node's Health API. health.Checkable // Connector represents a handler that is called on connection connect/disconnect validators.Connector // Initialize this VM. // [ctx]: Metadata about this VM. // [ctx.networkID]: The ID of the network this VM's chain is running on. // [ctx.chainID]: The unique ID of the chain this VM is running on. // [ctx.Log]: Used to log messages // [ctx.NodeID]: The unique staker ID of this node. // [ctx.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 *snow.Context, dbManager manager.Manager, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, toEngine chan<- Message, fxs []*Fx, appSender AppSender, ) error // Bootstrapping is called when the node is starting to bootstrap this chain. Bootstrapping() error // Bootstrapped is called when the node is done bootstrapping this chain. Bootstrapped() error // Shutdown is called when the node is shutting down. Shutdown() error // Version returns the version of the VM this node is running. Version() (string, error) // Creates the HTTP handlers for custom VM network calls. // // This exposes handlers that the outside world can use to communicate with // a static reference to the VM. Each handler has the path: // [Address of node]/ext/VM/[VM ID]/[extension] // // Returns a mapping from [extension]s to HTTP handlers. // // Each extension can specify how locking is managed for convenience. // // For example, it might make sense to have an extension for creating // genesis bytes this VM can interpret. CreateStaticHandlers() (map[string]*HTTPHandler, 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. // // Each extension can specify how locking is managed for convenience. // // 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() (map[string]*HTTPHandler, error) }
VM describes the interface that all consensus VMs must implement