Files
zeekayandHanzo Dev 9befc611e3 version: strengthen RPCChainVMProtocol single-source mandate (comment)
Document that RPCChainVMProtocol here (=42) is the canonical single source and MUST be bumped on any
VM wire-struct change. Value unchanged (the length-tolerant Initialize decode in api v1.1.2 IS the
evolvability fix; the Capabilities field already shipped at 42 in v1.36.12+ plugins, so a bump now
would reject deployed plugins).

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-16 12:31:36 -07:00

179 lines
5.0 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"encoding/json"
"strconv"
"time"
_ "embed"
)
const (
Client = "luxd"
// RPCChainVMProtocol is the node<->plugin (rpcchainvm) wire-protocol version
// and the ONE canonical definition of it: github.com/luxfi/api/zap and the
// github.com/luxfi/vm plugin server both read RPCChainVMProtocol from here.
// (github.com/luxfi/node/version carries an independent copy of the same
// value; that duplicate should be collapsed to re-export THIS constant —
// node already requires github.com/luxfi/version and this module never
// imports node, so there is no cycle — so a future bump can never land on
// only one of the two. Both are 42 today, so no skew exists.)
//
// BUMP THIS on ANY change to a ZAP VM-wire struct (github.com/luxfi/api/zap
// Encode/Decode: Initialize/SetState/Block/Quasar/...) that an existing peer
// cannot decode without the new code — a field inserted mid-struct, a
// reorder, a type change, or a removed field. APPENDING a new TRAILING field
// is EXEMPT iff its Decode is length-tolerant (guarded on Reader.Remaining());
// that is the forward-safe evolution path and needs no bump. History: api
// v1.0.16 appended InitializeResponse.Capabilities WITHOUT length-tolerance
// AND without bumping this constant → stale plugins hit "unexpected EOF"
// decoding Initialize (the v1.36.11 incident). InitializeResponse.Decode is
// length-tolerant as of that fix, so 42 now safely spans both the pre- and
// post-Capabilities wire.
RPCChainVMProtocol uint = 42
// RPCDAGVMProtocol should be bumped anytime changes are made which
// require the DAG plugin vm to upgrade to latest node release to be
// compatible.
RPCDAGVMProtocol uint = 1
)
// These variables are set at build time via ldflags from git tag:
//
// go build -ldflags "-X github.com/luxfi/version.VersionMajor=1 \
// -X github.com/luxfi/version.VersionMinor=22 \
// -X github.com/luxfi/version.VersionPatch=19"
//
// Build with scripts/build.sh to automatically inject version from git tags.
var (
VersionMajor = ""
VersionMinor = ""
VersionPatch = ""
)
// These are globals that describe network upgrades and node versions
var (
Current *Semantic
CurrentApp *Application
MinimumCompatibleVersion = &Application{
Name: Client,
Major: 1,
Minor: 13,
Patch: 0,
}
PrevMinimumCompatibleVersion = &Application{
Name: Client,
Major: 1,
Minor: 12,
Patch: 0,
}
CurrentDatabase = DatabaseVersion1_4_5
PrevDatabase = DatabaseVersion1_0_0
DatabaseVersion1_4_5 = &Semantic{
Major: 1,
Minor: 4,
Patch: 5,
}
DatabaseVersion1_0_0 = &Semantic{
Major: 1,
Minor: 0,
Patch: 0,
}
//go:embed compatibility.json
rpcChainVMProtocolCompatibilityBytes []byte
// RPCChainVMProtocolCompatibility maps RPCChainVMProtocol versions to the
// set of node versions that supported that version. This is not used
// by node, but is useful for downstream libraries.
RPCChainVMProtocolCompatibility map[uint][]*Semantic
)
// Default version for tests/development when not set via ldflags
// These should match the latest git tag
const (
defaultMajor = 1
defaultMinor = 22
defaultPatch = 75
)
func init() {
// Version is set via ldflags at build time from git tag
// If not set, use defaults (for tests and go run)
var major, minor, patch int
if VersionMajor != "" {
var err error
major, err = strconv.Atoi(VersionMajor)
if err != nil {
panic("invalid VersionMajor: " + VersionMajor)
}
} else {
major = defaultMajor
}
if VersionMinor != "" {
var err error
minor, err = strconv.Atoi(VersionMinor)
if err != nil {
panic("invalid VersionMinor: " + VersionMinor)
}
} else {
minor = defaultMinor
}
if VersionPatch != "" {
var err error
patch, err = strconv.Atoi(VersionPatch)
if err != nil {
panic("invalid VersionPatch: " + VersionPatch)
}
} else {
patch = defaultPatch
}
Current = &Semantic{
Major: major,
Minor: minor,
Patch: patch,
}
CurrentApp = &Application{
Name: Client,
Major: Current.Major,
Minor: Current.Minor,
Patch: Current.Patch,
}
// Parse RPC compatibility map
var parsedRPCChainVMCompatibility map[uint][]string
if err := json.Unmarshal(rpcChainVMProtocolCompatibilityBytes, &parsedRPCChainVMCompatibility); err != nil {
panic(err)
}
RPCChainVMProtocolCompatibility = make(map[uint][]*Semantic)
for rpcChainVMProtocol, versionStrings := range parsedRPCChainVMCompatibility {
versions := make([]*Semantic, len(versionStrings))
for i, versionString := range versionStrings {
version, err := Parse(versionString)
if err != nil {
panic(err)
}
versions[i] = version
}
RPCChainVMProtocolCompatibility[rpcChainVMProtocol] = versions
}
}
func GetCompatibility(minCompatibleTime time.Time) Compatibility {
return NewCompatibility(
CurrentApp,
MinimumCompatibleVersion,
minCompatibleTime,
PrevMinimumCompatibleVersion,
)
}