zap

package
v1.37.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

Package zap provides ZAP transport implementation for VM RPC.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected    = errors.New("zap: not connected")
	ErrInvalidResponse = errors.New("zap: invalid response")
)

Functions

func Dial

func Dial(ctx context.Context, addr string, config *zapwire.Config) (*zapwire.Conn, error)

Dial connects to a ZAP VM server

func NewListener

func NewListener() (net.Listener, error)

NewListener creates the listener a plugin VM dials back on during ZAP handshake bootstrap.

The same-host fast path is a unix-domain socket — no TCP/UDP stack, no ephemeral-port exhaustion, filesystem-namespaced. The api/zap Dial infers "unix" from the socket-path addr, so a plugin rebuilt against that api connects back over the socket with zero code change on its side.

The node and the plugins it runs are one build and ship together, so both sides move at once. Windows has no unix sockets and gets TCP; so does a host where the socket cannot be bound, because a chain that will not start is worse than one on a slower transport.

Types

type Client

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

Client implements chain.ChainVM over ZAP transport

func NewClient

func NewClient(conn *zapwire.Conn, logger log.Logger) *Client

NewClient creates a new ZAP-based VM client

func (*Client) BuildBlock added in v1.23.4

func (c *Client) BuildBlock(ctx context.Context) (block.Block, error)

BuildBlock implements chain.ChainVM

func (*Client) Close

func (c *Client) Close() error

Close closes the connection

func (*Client) Connected added in v1.23.4

func (c *Client) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error

Connected implements chain.ChainVM

func (*Client) CreateHandlers added in v1.23.4

func (c *Client) CreateHandlers(ctx context.Context) (map[string]http.Handler, error)

CreateHandlers calls the VM's CreateHandlers and returns reverse proxy handlers

func (*Client) Disconnected added in v1.23.4

func (c *Client) Disconnected(ctx context.Context, nodeID ids.NodeID) error

Disconnected implements chain.ChainVM

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, blkID ids.ID) (block.Block, error)

GetBlock implements chain.ChainVM

func (*Client) GetBlockIDAtHeight added in v1.23.4

func (c *Client) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error)

GetBlockIDAtHeight implements chain.ChainVM

func (*Client) GetLastStateSummary added in v1.36.126

func (c *Client) GetLastStateSummary(ctx context.Context) (chain.StateSummary, error)

GetLastStateSummary names the most recent summary the plugin holds. This is what a node offers when a peer asks what it can serve.

func (*Client) GetOngoingSyncStateSummary added in v1.36.126

func (c *Client) GetOngoingSyncStateSummary(ctx context.Context) (chain.StateSummary, error)

GetOngoingSyncStateSummary names the summary of a sync already under way, so a node that was interrupted resumes the one it started rather than beginning again at whatever the network now offers.

func (*Client) GetStateSummary added in v1.36.126

func (c *Client) GetStateSummary(ctx context.Context, height uint64) (chain.StateSummary, error)

GetStateSummary names the summary at a height, which is how a node checks whether it holds the summary its peers have settled on.

func (*Client) HealthCheck added in v1.23.4

func (c *Client) HealthCheck(ctx context.Context) (block.HealthCheckResult, error)

HealthCheck implements chain.ChainVM

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, init block.Init) error

Initialize implements chain.ChainVM

func (*Client) LastAccepted

func (c *Client) LastAccepted(ctx context.Context) (ids.ID, error)

LastAccepted implements chain.ChainVM. Returns the cache refreshed on every Accept (NOT a frozen Initialize snapshot) under the read lock.

func (*Client) LastQuasarHeight added in v1.36.1

func (c *Client) LastQuasarHeight() uint64

LastQuasarHeight returns the plugin VM's accept-tip-CLAMPED Quasar EXPORT-FINAL height across the ZAP boundary (0 before the first export forms). Returns 0 if the plugin did not advertise CapQuasarExport or if the call fails — so the chain manager's boot re-seed of the consensus export frontier treats an unavailable/absent height as "empty" (advance-only; a fresh cert refines it).

func (*Client) NewHTTPHandler added in v1.23.4

func (c *Client) NewHTTPHandler(ctx context.Context) (http.Handler, error)

NewHTTPHandler implements chain.ChainVM

func (*Client) ParseBlock

func (c *Client) ParseBlock(ctx context.Context, blockBytes []byte) (block.Block, error)

ParseBlock implements chain.ChainVM

func (*Client) ParseStateSummary added in v1.36.126

func (c *Client) ParseStateSummary(ctx context.Context, summaryBytes []byte) (chain.StateSummary, error)

ParseStateSummary reads summary bytes received from a peer. The plugin decides whether the bytes name a summary it can serve; a summary comes back only if they do.

func (*Client) SetLastQuasarFinalized added in v1.36.1

func (c *Client) SetLastQuasarFinalized(height uint64)

SetLastQuasarFinalized forwards a new Quasar (⅔-by-stake) EXPORT-FINAL height to the plugin VM across the ZAP boundary so the plugin's `finalized`/`safe` tags and warp export gate track ⅔-stake finality, not the reorgable Nova tip. No-op (no RPC) if the plugin did not advertise CapQuasarExport — so the chain manager can wire this unconditionally. Fire-and-forget: a transport error is logged, not returned, because the sole caller is the consensus export-frontier observer, which has no error channel (the durable height is re-seeded on boot).

func (*Client) SetPreference

func (c *Client) SetPreference(ctx context.Context, blkID ids.ID) error

SetPreference implements chain.ChainVM

func (*Client) SetState added in v1.23.4

func (c *Client) SetState(ctx context.Context, state uint32) error

SetState implements chain.ChainVM

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

Shutdown implements chain.ChainVM

func (*Client) StateSyncEnabled added in v1.36.126

func (c *Client) StateSyncEnabled(ctx context.Context) (bool, error)

StateSyncEnabled reports whether the plugin syncs state. A plugin that cannot answer has not answered false — the error travels and the caller decides.

func (*Client) SupportsQuasarExport added in v1.36.1

func (c *Client) SupportsQuasarExport() bool

SupportsQuasarExport reports whether the plugin advertised the Quasar (⅔-by-stake) EXPORT capability at Initialize. The chain manager gates the consensus export-frontier observer on this: false → the plugin is a generic VM with no export surface and the chain runs Nova-only (no cross-process no-op spam per finalization).

func (*Client) Version added in v1.23.4

func (c *Client) Version(ctx context.Context) (string, error)

Version implements chain.ChainVM

func (*Client) WaitForEvent added in v1.23.4

func (c *Client) WaitForEvent(ctx context.Context) (block.Message, error)

WaitForEvent implements chain.ChainVM

type Sender

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

Sender implements p2p.Sender over ZAP transport

func NewSender

func NewSender(conn *zapwire.Conn) *Sender

NewSender creates a new ZAP-based p2p.Sender

func (*Sender) SendError

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

SendError sends an error response to a previous request

func (*Sender) SendGossip

func (s *Sender) SendGossip(ctx context.Context, config p2p.SendConfig, msg []byte) error

SendGossip sends a gossip message

func (*Sender) SendRequest

func (s *Sender) SendRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, request []byte) error

SendRequest sends a request to the specified nodes

func (*Sender) SendResponse

func (s *Sender) SendResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error

SendResponse sends a response to a previous request

type Server

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

Server wraps a VM and serves it over ZAP transport

func NewServer

func NewServer(v vm.VM, logger log.Logger) *Server

NewServer creates a new ZAP server for a VM

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the listener's address

func (*Server) Close

func (s *Server) Close() error

Close closes the server

func (*Server) Listen

func (s *Server) Listen(addr string, config *zapwire.Config) error

Listen starts listening on the specified address

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve starts serving requests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL