Consensus builds nothing until WaitForEvent returns, so a VM that accepts work has to report it, and this is the one way to do that. Signalling twice before the signal is taken is the same as once: a builder needs to know that there is work, not how much. Co-authored-by: Hanzo Dev <[email protected]>
4.6 KiB
vm
Overview
Go package for Lux blockchain virtual machines. Provides the core interfaces and implementations for VM communication with the Lux node.
Package Information
- Type: go
- Module: github.com/luxfi/vm
- Repository: github.com/luxfi/vm
Build System
Transport Selection
The package uses ZAP-native (LP-200) as the ONLY transport for VM<->Node
communication. The historical gRPC fallback (and -tags=grpc opt-in) was
retired in v1.26.31; ZAP is the canonical and exclusive wire protocol.
# Build — ZAP only, no build tags
go build ./...
Factory Pattern:
rpc/factory_zap.go— ZAP-based plugin factory (the only factory)
VM Client:
rpc/vm_client_zap.go— ZAP-based VM client (ZAPClient + zapBlock)
Subprocess Bootstrap:
rpc/runtime/subprocess/runtime_zap.go— Binary handshake protocolrpc/runtime/subprocess/config.go— Shared Config and Status types
Sender Package
The rpc/sender package provides p2p.Sender implementations:
// ZAP transport (the only transport)
s := sender.ZAP(zapConn)
Key Packages
Core
chain/- ChainVM interface and implementationscomponents/- Shared components (chain state, messages)manager/- VM factory and management
RPC Layer
rpc/- VM<->Node communicationsender/- p2p.Sender implementations (ZAP-native, LP-200)runtime/- VM runtime management
Storage
internal/database/rpcdb/- Remote database client
Proto
proto/pb/- Generated protobuf messagessender/- Sender service definitions
Development
Prerequisites
- Go 1.21+
Build
# Build (ZAP only — no build tags exist)
go build ./...
Test
# Run tests
go test -v ./...
Verify Zero gRPC
# Confirm zero gRPC in the dep graph
go list -deps ./rpc | grep grpc # Must be empty
ZAP Wire Protocol
The ZAP (Zero-copy App Proto) transport uses a binary wire protocol from github.com/luxfi/api/zap:
Handshake Protocol
VM → Node:
[4 bytes: length][4 bytes: protocol version][vm addr string]
Node → VM:
[1 byte: ACK (0x01)]
Message Format
[4 bytes: length][1 byte: message type][payload...]
Message types (zapwire.Msg*):
- MsgInitialize, MsgShutdown, MsgSetState
- MsgBuildBlock, MsgParseBlock, MsgGetBlock
- MsgBlockVerify, MsgBlockAccept, MsgBlockReject
- MsgVersion, MsgHealth, etc.
State sync
Six messages carry chain.StateSyncableVM across the boundary:
MsgStateSyncEnabled, MsgGetOngoingSyncStateSummary, MsgGetLastStateSummary,
MsgParseStateSummary, MsgGetStateSummary, MsgStateSummaryAccept.
newZAPVMServer probes the wrapped VM for the surface once, the same way it
probes for Quasar export. A VM without it answers ErrorStateSyncNotImplemented
on all six, so a node knows to bootstrap that chain block by block.
Accept is the asymmetric one. A summary is an object on the plugin side and only
its id crosses, so the server records every summary it hands out and resolves
MsgStateSummaryAccept against that map. An id the server never produced is
refused — rebuilding one from caller-supplied bytes would accept a state the
network never ratified. The map is cleared on a successful accept (the sync that
starts supersedes every other candidate) and capped at maxSummaries.
Key Types
// State constants
zapwire.StateStateSyncing
zapwire.StateBootstrapping
zapwire.StateNormalOp
// Error constants — ErrorUnspecified is SUCCESS, never a failure's fallback
zapwire.ErrorClosed → database.ErrClosed
zapwire.ErrorNotFound → database.ErrNotFound
zapwire.ErrorStateSyncNotImplemented → block.ErrStateSyncableVMNotImplemented
zapwire.ErrorInternal → anything else
Integration with Lux Ecosystem
This package is part of the Lux blockchain ecosystem:
- GitHub: https://github.com/luxfi
- Docs: https://docs.lux.network
Last updated: 2026-01-24
Latch
Latch is how a VM tells consensus there is work. Consensus calls
WaitForEvent and builds nothing until it returns, so a VM that accepts work
has to report it, and this is the one way to do that.
Signal() says there is work and never blocks, so it is safe to call under a
lock. WaitForEvent(ctx) blocks until there is work or the context ends, which
is exactly what the ChainVM method of the same name owes consensus — a VM
delegates to it. Signalling twice before the signal is taken is the same as
signalling once: what a builder needs to know is that there is work, not how
much. The zero value is ready to use.