Files
node/version/constants.go
T
Hanzo AI c3b398bc7b json: migrate every encoding/json import to json/v2 (go-json-experiment)
External (HTTP / JSON-RPC) is the only place JSON is legitimate. Every
existing encoding/json import in node/ moves to github.com/go-json-experiment/json
(v2 root, not the v1 sub-package). NewEncoder/NewDecoder rewrite to
MarshalWrite/UnmarshalRead. MarshalIndent rewrites to Marshal with
jsontext.WithIndent. json.RawMessage rewrites to jsontext.Value.
*json.SyntaxError rewrites to *jsontext.SyntacticError.

81 files migrated. LLM.md captures the rule + v1->v2 delta table.

Known v2 semantic deltas surfaced by existing tests (followups, not regressions):
- [N]byte fields with no MarshalJSON now marshal as base64 string (v1 marshalled
  as JSON array of byte numbers). Affects vms/platformvm/txs/*_test.go fixtures
  with embedded BLS proofOfPossession.
- time.Duration has no v2 default representation; configs that wire-format
  Duration as nanoseconds (vms/{xvm,platformvm}/config, config/spec) need to
  switch to string-form Duration or carry an explicit option. v2 root does not
  re-export FormatDurationAsNano.
- v2 enforces strict UTF-8 (vms/chainadapter/messaging fixture has non-UTF-8).
- json.MarshalWrite does not append a trailing '\n' (v1 NewEncoder.Encode did);
  service/auth/auth_test.go expectation updated.
- nil []byte round-trips to empty (not nil); config_test deep-equal fixtures
  surface this.

All affected sites are at the API boundary; ZAP wire envelope already covers
the internal data paths (state, P2P, consensus, MPC, threshold). Internal
JSON sites that should move to ZAP next (separate work):
- vms/da/store.go            (DA blob/cert storage as JSON)
- vms/platformvm/airdrop     (airdrop claims as JSON in db)
- vms/chainadapter/appchain  (SQLite materializer schema/data blobs)
- vms/chainadapter/messaging (conversation codec)
- staking/kms.go             (KMS HTTP client — external technically, leave)
- utils/{bimap,ips}          (small marshaler shims — low priority)
2026-06-06 22:26:02 -07:00

158 lines
3.6 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"github.com/go-json-experiment/json"
"strconv"
"time"
_ "embed"
)
const (
Client = "luxd"
// RPCChainVMProtocol should be bumped anytime changes are made which
// require the plugin vm to upgrade to latest node release to be
// compatible.
RPCChainVMProtocol uint = 42
)
// These variables are set at build time via ldflags from git tag:
//
// go build -ldflags "-X github.com/luxfi/node/version.VersionMajor=1 \
// -X github.com/luxfi/node/version.VersionMinor=22 \
// -X github.com/luxfi/node/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 = 30
defaultPatch = 4
)
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,
)
}