Compare commits

..
553 Commits
Author SHA1 Message Date
zeekayandHanzo Dev eb82872612 version: backfill v1.36.11..31 into the RPCChainVM-42 compatibility set (v1.36.31)
TestCurrentRPCChainVMCompatible has been red since v1.36.11: every release
since then bumped defaultPatch without registering the version against
RPCChainVMProtocol 42, so version.Current was absent from its own
compatibility set. Protocol 42 has not moved across that range — the list was
simply never updated. Backfilled through v1.36.31 (v1.36.29 omitted: that tag
was pushed off a pre-rebase commit and deleted, it is not a release).

v1.36.30 carries the health fix but was tagged before this backfill, so its
tree still fails ./version. v1.36.31 is the green tag and the rollout target.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-26 17:39:52 -07:00
zeekayandHanzo Dev 4fce5875c5 v1.36.30: cut the health-truth fix on main
v1.36.29 was tagged off a pre-rebase commit that never reached main and has
been deleted. Forward only: the release is v1.36.30, on main.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-26 17:36:39 -07:00
zeekayandHanzo Dev 304717c199 health: name the CHAIN that is unbootstrapped, not the net (v1.36.29)
/v1/health's `bootstrapped` check publishes chains.Nets.Bootstrapping()
verbatim as its message. Nets.chains is keyed by NET id, and the aggregate
appended the map key rather than asking the net which of its chains had not
converged. So every stuck primary-network chain surfaced as one ID,
11111111111111111111111111111111LpoYY — constants.PrimaryNetworkID, i.e.
ids.Empty — a "chain" the chain manager has never heard of. An operator who
went looking for it got "there is no chain with alias/ID", and N stuck chains
collapsed into a single indistinguishable entry that named none of them.

Measured on lux-devnet luxd-0 (v1.36.23), POST health.health:
  "bootstrapped":{"message":["11111111111111111111111111111111LpoYY"],
   "error":"chains not bootstrapped","contiguousFailures":3213}

The net owns the bootstrapping set, so the net is what can name those chains:
nets.Net grows Bootstrapping() []ids.ID and chains.Nets aggregates those
instead of its own keys. One place holds the set; one place reads it.

The existing TestNetsBootstrapping asserted the defect (require.Contains
bootstrapping, netID) — that assertion is why it survived review. It now
demands the chain ID and refuses the net ID.

This also cuts the first tag containing dada5a31, the GET /v1/health encoder
fix: apihealth.APIReply carries a time.Duration per check, jsonv2 has no
default representation for it, so every GET degraded to
{"healthy":…,"error":"health reply encode failed"} while the status code still
looked right. Reproduced here directly —
  json: cannot marshal from Go time.Duration within "/checks/network/duration"
That fix landed on main on 2026-07-25 but no tag ever carried it: v1.36.28
points at 52de3948, seven commits behind. The fleet runs v1.36.2/23/24, all of
which predate it.

Tests (GOWORK=off CGO_ENABLED=0):
  chains  ok  — TestNetsBootstrappingReportsChainsNotNets fails against the
                old aggregate with exactly ids.Empty in the list
  nets    ok  — TestNetBootstrappingNamesTheChains
  health  ok  — the three handler tests fail against the jsonv2 encoder
                (checks decode empty) and pass against encoding/json

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-26 17:36:07 -07:00
Hanzo Dev ad76f2e709 Makefile: select GOEXPERIMENT=none on WSL2 so make build yields a working luxd
The Go 1.26 runtimesecret experiment SIGSEGVs at startup under the WSL2 kernel
(go1.26.3, go1.26.4). Detect WSL from /proc/sys/kernel/osrelease and drop the
experiment only there; all other platforms keep stack/register zeroing.
2026-07-26 14:49:50 -07:00
Hanzo Dev 26d419c3ad build: disable the runtimesecret GOEXPERIMENT under WSL2
The Go 1.26 runtimesecret experiment (stack/register zeroing for forward
secrecy) SIGSEGVs at startup on the WSL2 kernel, confirmed on go1.26.3 and
go1.26.4. Detect WSL via /proc/sys/kernel/osrelease and select GOEXPERIMENT=none
there; every other platform keeps forward secrecy. Plain `make build` now
produces a working luxd on WSL.
2026-07-26 14:44:30 -07:00
zeekay 6c39b7d391 chore: sync working tree
Commits 1 outstanding change(s) that were sitting uncommitted.
No build artifacts and no secrets in the changeset (both checked).
2026-07-26 10:02:56 -07:00
zeekayandHanzo Dev dada5a3169 health,build: make /v1/health and /v1/metrics report reality
Two endpoints were answering with the right status code and an empty
truth, so every fleet looked instrumented while reporting nothing.

GET /v1/health encoded apihealth.APIReply through jsonv2, which has no
default representation for time.Duration — and every Result carries one.
The marshal therefore failed on every node, every time, and the handler
fell back to {"healthy":…,"error":"health reply encode failed"}. The
status code is written before the encode, so k8s probes and dashboards
stayed green while the body carried no checks at all. Measured on Zoo,
Hanzo and Pars mainnet, node v1.34.9 and v1.36.2 alike.

The type is defined with encoding/json tags and the POST (jsonrpc) path
already encodes it through that codec, which is why POST returned the
full check set while GET returned nothing. One wire type deserves one
encoder: GET now uses encoding/json too, so the two paths agree by
construction. encoding/json also maps invalid UTF-8 in check Details to
U+FFFD instead of failing, which is the behaviour the old jsontext
AllowInvalidUTF8 option was reaching for. The buffer stays: it keeps a
partial encode from shipping a torn body.

/v1/metrics answered 200 with zero bytes for the same shape of reason.
luxfi/metric resolves NewRegistry() to a no-op registry unless the
binary is built with -tags metrics (registry_noop.go, //go:build
!metrics), and only the `full` profile passed it. Images build with the
default `minimal` profile, so every metric in luxd registered into a
black hole while --api-metrics-enabled=true still advertised metrics as
on. Whether metrics are served is the runtime flag's call; a build tag
must not silently overrule it. `metrics` becomes a base tag on every
profile.

Verified: the three new handler tests fail against the jsonv2 encoder
(checks decode empty, error field nil — the exact production symptom)
and pass after. `go tool nm` shows (*registry).Gather absent from a
default build and present once the tag is set.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-25 15:10:46 -07:00
zeekayandHanzo Dev 3a44f0dcd3 genesis: refuse an M-Chain policy the validator set cannot satisfy
M-Chain's committee is the validator set, and RunKeygen refuses a policy
needing more parties than the committee has. mainnet's mchain.json asked
for 7-of-10 against five genesis validators, so a custody key could never
have been generated — the failure would have surfaced the first time
someone tried to bridge, not at deploy.

Adds the invariant as a test over every network's built genesis, and
picks up luxfi/genesis v1.16.4 where the policies are sized to fit
(3-of-5 on mainnet/testnet/devnet, 2-of-3 on localnet).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-25 14:59:04 -07:00
zeekayandHanzo Dev d5eff75934 genesis: install the M-Chain plugin under the vmID genesis actually declares
The build installed M-Chain's plugin binary as
tGVBwRxpmD2aFdg3iYjgRvrCe8Jcmq9UNKxyHMus2NZ8WcD8t — the CB58 of the
retired `thresholdvm` identifier — while the genesis builder declares the
chain with constants.MPCVMID (qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS).
The plugin registry resolves a CreateChainTx's vmID to an implementation
by filename, so the two never met: M-Chain was declared in genesis and no
node could start it. The Dockerfile comment had already been renamed to
"mpcvm" without the CB58 being recomputed, which is why it read as correct.

Fixes all five sites (plugin build target, the build-verify list, the
runtime COPY, the comment, and publish_plugin_set.sh) and adds
genesis/builder/mchain_test.go, which pins the vmID literally and asserts
M-Chain is present in the height-0 chain set for mainnet, testnet and
local. A vmID is an immutable one-way door once a chain is created with
it, so it is now covered by a test rather than by five copies of a string.

Bumps luxfi/genesis to v1.16.3, where mchain.json states its quorum as
"policy": "7-of-10" instead of a bare mpcThreshold that reads as the
signer count to an operator and as the polynomial degree to a library.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-25 14:53:07 -07:00
zeekayandHanzo Dev 66d5940f88 Dockerfile: let the C-Chain plugin link cevm, and fix the cevm fetch
Two things kept the cevm backend from ever reaching a running node.

The fetch pointed at luxcpp/cevm v0.19.0, which does not exist — the libs
publish from the private lux-private/cevm repo, and unauthenticated downloads
404 there. Point it at v0.51.10 in that repo and authenticate with the same
`ghtok` secret the private go modules and lux-accel already use. It stays
best-effort, so a build without the token behaves exactly as before.

Separately, the C-Chain plugin builds with CGO_ENABLED=0 and no tags, so it is
always the pure-Go EVM regardless of what luxd itself links — which is why
production images carry no cevm at all. That build now honours EVM_CGO and
EVM_TAGS, defaulting to today exact behaviour; EVM_CGO=1 EVM_TAGS=cevm is what
makes AutoEVM resolve to CppEVM. The libraries are already in this stage (the
plugin section shares the builder stage rather than starting a new FROM).

Defaults unchanged, so the in-flight v1.36.12 fleet build is byte-identical.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-25 13:43:32 -07:00
zeekay e22009db91 chore(node): one way only — delete four dead duplicate paths
Each removed package was a SECOND way to do something that already has a
canonical first way. Zero importers workspace-wide; verified identical build
output before/after (pre-existing keyutil breakage unchanged).

- chains/rpc      1250 lines whose own header says 'This replaces lines
                  941-990' of chains/manager.go. The replacement never
                  happened; manager.go still registers handlers inline.
- node/config.go  265-line shadow of the canonical node/config/node/config.go.
- vms/mpcvm       self-described 'thin backward-compatibility alias' wrappers
- vms/dexvm       over github.com/luxfi/chains/*. No backwards compatibility,
                  only forwards perfection.

Simple made easy: one name, one home, one path.
2026-07-25 12:26:36 -07:00
zeekay 011c3df6bd chore(node): remove AI-slop write-ups and stale residue
- LAUNCH_CHECKLIST.md: pre-launch plan for v1.24.11, 154/154 boxes
  unchecked, zero references; superseded by LLM.md/CHANGELOG.md/RELEASE.md
  and NETWORKS.yaml + genesis/configs for the chain-ID/port tables.
- rename_app.sh, replace_imports.sh: spent one-off sed migrations. Both
  are now actively harmful — replace_imports.sh would rewrite the live
  github.com/luxfi/vm/manager import in vms/manager.go.
- gen_zoo_addr: stray 3.4MB darwin/arm64 build artifact committed at root;
  source preserved at cmd/gen_zoo_addr/gen_zoo_addr.go (.gitignore already
  covers the intended output path).
- .ci-status-check.md, .ci-trigger: dated CI-poke stamps, no workflow reads
  them.

Also removed (untracked): .claude/worktrees/ agent scratch — a 73MB
whole-tree duplicate that polluted every grep. Detached via git worktree
remove; node HEAD cf8e4c6f51 was an ancestor of main, and the nested
lux/evm worktree HEAD 7156c44f6 is release tag v1.104.12, so no work lost.
Deleted the two fully-merged worktree-agent-* branches it left behind.

No Go source, config, manifest, or .github/ file was touched.
2026-07-25 11:48:34 -07:00
zeekayandHanzo Dev 52de39485d fix(platformvm): gate P-chain uptime state.Commit on an actual write (v1.36.28)
Disconnect/updateUptimeLocked now return (mutated bool, err); VM.Disconnected commits only when the flush wrote uptime state. Before StartTracking (bootstrap churn) and for non-validator peers the flush is a no-op, so the prior unconditional Commit was an empty full-write+fsync on every such disconnect. Skipping it is correct: every writer under stateLock commits its own diff, so no orphaned write depends on the disconnect path.

RED round-2 verdict: SHIP-READY (H1 phantom verified, mutated-gate correct, H2 pre-existing/not-worsened, block-height orthogonal). Isolated from the uncommitted staking-KMS WIP, which is quarantined on feat/staking-kms-native pending its own Blue->Red.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-24 04:20:00 -07:00
zeekayandHanzo Dev e70f687c10 fix(node): serialize P-chain Connected/Disconnected + plumb real peer version (RED CRITICAL #1/#2)
The uptime event-delivery plumbing (node/chain_router.go + chains/manager.go
blockHandler) dropped two invariants avalanchego's handler upholds — the
consensus lock and the peer version — each a mainnet-fleet crash. The uptime
tracker itself (vms/platformvm/uptime_tracker.go) is RED-cleared and UNCHANGED.

CRITICAL #2 — P-chain state race (concurrent map writes -> fatal):
chainRouter dispatched Connected/Disconnected on the peer-lifecycle goroutine,
where VM.Disconnected -> tracker.Disconnect (state.SetUptime) + state.Commit
(state.write) ran concurrently with the block acceptor's state.CommitBatch
(state.write) on the engine accept goroutine — no shared lock, so ordinary peer
churn triggered Go "concurrent map writes" and crashed the P-chain node.
Fix: one VM-owned stateLock serializes every commit of shared platform state
that originates outside the engine's lock-free VM.Accept call-out —
  - block DECISION: block/executor Block.Accept/Reject hold &vm.stateLock
    (supplied to executor.NewManager) around the whole acceptor visit;
  - peer/lifecycle: VM.Disconnected and the onReady/onBootstrapStarted/Shutdown
    Start/StopTracking uptime flushes hold vm.stateLock.
This is avalanchego's ctx.Lock invariant (accept serialized with
engine.Connected/Disconnected), scoped to the state the platform VM owns and
implemented at the VM: the Lux engine invokes VM.Accept as a lock-free call-out
(no ctx.Lock over accept exists) and a chain-agnostic blockHandler cannot reach a
per-VM accept lock, so routing "through the engine" is not feasible.

CRITICAL #1 — C-Chain nil-version panic on state sync:
blockHandler.Connected passed connector.Connected(ctx, nodeID, nil). proposervm
promotes Connected to coreth, whose state-sync peer tracker compares peer
versions; a nil version deref panics any C-Chain node running state sync (a fresh
join OR a validator rejoining after falling behind — the launch's core invariant).
Fix: plumb the REAL peer version through a versionedConnector capability —
chainRouter.Connected converts the node peer version (luxfi/node/version) to the
VM boundary type (luxfi/version = chain.VersionInfo) and delivers it via
blockHandler.ConnectedWithVersion -> connector.Connected. Audit: geth in-process
Connected is a no-op stub (nil-safe); xvm stores the pointer without deref
(nil-safe); the real coreth plugin derefs -> fixed by feeding the real version.

Tests (SDKROOT + CGO_ENABLED=1, -race):
- vms/platformvm/uptime_state_race_test.go: state.Commit (VM.Disconnected path)
  concurrent with state.CommitBatch (acceptor path) under the shared lock — no
  race/fatal; verified meaningful (an unlocked probe trips DATA RACE).
- chains/blockhandler_connected_version_test.go + node/chain_router_connected_version_test.go:
  the real, converted version reaches the connector non-nil (dedup covered).
Uptime tracker 13/13 and the block/executor reward gate untouched and green;
go build ./... and go vet clean.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-24 00:34:00 -07:00
zeekayandHanzo Dev 88bb914cd6 fix(platformvm): accrue P-chain validator uptime for a stable set (reward gate)
All 5 mainnet validators read uptime=0.0000 / connected=null even for peers
connected 24h+, so prefersCommit (block/executor/options.go) always saw
0% < threshold and withheld staking rewards (~165M LUX gate).

Root causes (four, all fixed):

1. StartTracking never existed/called. The custom uptimeTracker was created
   late (onReady) and never baselined validator records, so a long-running
   validator's stored upDuration stayed 0 and CalculateUptimePercentFrom
   returned 0/total = 0.
2. upDuration flushed only on Disconnect/Shutdown, so a continuously-connected
   validator's persisted uptime never grew.
3. service.go left `connected` hard-nil ("IsConnected no longer exists").
4. ROOT: VM.Connected never fired. network.Connected -> chainRouter.Connected
   only added to a connectedPeers set and logged; it never dispatched to chain
   handlers, and blockHandler.Connected was a no-op. So tracker.Connect was
   never called and the connected map was always empty — nothing to accrue.

Fix (faithful port of avalanchego snow/uptime.Manager semantics, luxfi pkgs):

- vms/platformvm/uptime_tracker.go: rewrite as a startedTracking-gated tracker.
  StartTracking/StopTracking/StartedTracking/IsConnected added; CalculateUptime
  folds the live connected session forward to now using the persisted
  lastUpdated (reconstructed from the second-granular uptime.State encoding), so
  a connected validator accrues uptime WITHOUT a Disconnect. Before tracking, a
  validator is assumed online since its last update (avalanchego baseline);
  after tracking, only genuine sessions accrue. Second-granular clock matches
  storage. CalculateUptimePercentFrom is the clean upDuration/(now-from) form,
  clamped to [0,1].
- vms/platformvm/vm.go: create+register the tracker at Initialize (so bootstrap
  Connect events are captured), StartTracking(primary validators) at onReady,
  StopTracking on re-bootstrap and Shutdown. Mirrors avalanchego's
  onNormalOperationsStarted lifecycle.
- vms/platformvm/service.go: populate `connected` via tracker.IsConnected.
- node/chain_router.go: chainRouter.Connected/Disconnected now dispatch to every
  registered chain handler (snapshot under lock, call outside).
- chains/manager.go: blockHandler forwards Connected/Disconnected to its chain's
  VM (engineVM) exactly once (dedup set), so the P-chain uptime tracker — and
  every VM's peer set — finally observes connectivity.

Consensus safety: prefersCommit is a per-node PREFERENCE feeding oracle-block
voting, not a deterministic value. Fixing the local uptime measurement (which
was uniformly 0) changes only which reward option each node prefers; consensus
still converges by preference voting. No staking/reward math changed.

Tests (vms/platformvm/uptime_tracker_test.go, -race green):
- TestUptimeTrackerLongRunningValidatorAccruesUptime: a 30-day validator reports
  ~100%. Uses only the shared Calculator API; run against the OLD tracker it
  returns 0.0 (FAIL — the exact mainnet symptom), against the fix 1.0 (PASS).
- Continuously-connected-climbs, StartTracking-baselines, flush-on-disconnect,
  never-connected-gets-zero, StopTracking-flushes, idempotent double-connect,
  dedup, concurrency. block/executor (reward gate) suite green.

Follow-on (NOT in this commit): devnet 5-node uptime-climb verification ->
gated release -> owner-gated one-at-a-time mainnet roll. No image built, no
deploy, no live validator touched.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-23 21:44:08 -07:00
zeekayandHanzo Dev 4a3a131757 go.mod: consume consensus v1.36.9 + chains v1.7.9 (finality-halt fix + native-ZAP VMs)
Propagates two just-published upstream fixes into the node (luxd) binary:

- consensus v1.36.7 → v1.36.9: the chain engine no longer os.Exit(1)-kills a
  validator on a SetPreference orphan-refusal — it reconciles the VM to the
  certified block when the diverged tip is provably uncertified, and halts
  fail-closed only on a genuine double-finalization (v1.36.8). Also unifies
  consensus's transitive geth pin to v1.20.1, matching node/evm (v1.36.9). The
  new PreferenceReconciler VM interface is optional, so node's VMs are
  unaffected (they take the non-fatal defer path); no code change required here.
- chains v1.7.7 → v1.7.9: every VM (aivm/keyvm/quantumvm/dexvm) now serializes
  through native luxfi/zap struct-is-wire, with canonical-id hardening.

go.mod/go.sum only — dependency-graph resolution, no node code change. Transitive
indirects move forward within-major (bft, cockroachdb/errors, sentry-go,
prometheus/common, go-internal); no major-version bumps. geth stays v1.20.1
(already node's pin). Verified: GOWORK=off CGO_ENABLED=0 go build ./... clean.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-16 16:14:50 -07:00
zeekayandHanzo Dev 45a3dcfff1 fix(proposervm): millisecond-resolution block timestamps (unblocks sub-second cadence)
The proposervm block wire stored the timestamp as Unix SECONDS (timestamp.Unix()), so the
sub-second window/granularity work was silently truncated to whole seconds when written to the
block: buildChild computed the proposer slot from sub-second time, but verify read back
second-resolution and computed a DIFFERENT slot → errUnexpectedProposer verify-drops at any
window < 1s. Store timestamp.UnixMilli() and read time.UnixMilli() so sub-second timestamps
round-trip and build/verify agree on the slot. Measured at a 100ms window: errUnexpectedProposer
frequent→0, 108→149 TPS, 2.8s→2.2s cadence, 5/5 byte-identical. Forward-only wire change (the
outer proposervm timestamp; the inner EVM block timestamp is independent). Remaining sub-second
floor is now the EVM targetBlockRate, not the proposervm.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-16 09:00:21 -07:00
zeekayandHanzo Dev c3d6105804 feat(proposervm): configurable MinBlkDelay + timestamp granularity tracks WindowDuration (sub-second cadence foundation)
Two coupled knobs for differentiated cadence — co-located D-Chain/DEX (fast) vs public
C-Chain (standard):

1. MinBlkDelay was hardcoded to the 1s DefaultMinBlockDelay in chains/manager.go, ignoring
   its own --proposervm-min-block-delay flag. Now wired node.Config → ManagerConfig →
   proposervm.Config (0 ⇒ 1s default). High-throughput nets set it low.

2. Block timestamps were Truncate(time.Second) at 4 sites, quantizing cadence to 1s
   regardless of WindowDuration — so a sub-second window inflated slot numbers without finer
   time resolution and could NOT produce blocks faster than 1/s. Truncation now tracks
   proposer.TimestampGranularity() = min(1s, WindowDuration): mainnet (>=1s) keeps exact
   1-second block times; sub-second windows get matching sub-second timestamps.

Measured: 1s window/delay → ~95-104 TPS, byte-identical 5/5 finality (unchanged from before,
no regression). NOTE: true sub-second cadence additionally requires a slot-handoff fix — at
100ms the slot recomputed in buildChild from a drifted 'now' can differ from the slot
timeToBuild scheduled, causing errUnexpectedProposer verify drops; that + multi-sender
saturation is the next step. These knobs are the necessary foundation.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-15 22:33:01 -07:00
zeekayandHanzo Dev d83191e286 feat(proposervm): configurable window duration (fast local cadence) + strict-PQ classical-proposer refusal
Two changes, both node-local:

1. CADENCE — proposer.WindowDuration (the proposer-slot spacing, a validator's min build
   delay = slot index x WindowDuration) was a hardcoded 5s const tuned for mainnet-scale
   validator sets, flooring small/local block cadence at 5s per slot. It is now a
   startup-configurable var (default 5s, unchanged for mainnet) set via the new
   --proposervm-window-duration flag → node.Config → ManagerConfig → proposervm.Config →
   proposer.SetWindowDuration at VM init. Read by both the windower delay math and
   TimeToSlot, so they stay consistent. Measured on a 5-node strict-PQ net: 5s→1s took
   sustained C-Chain from 44 TPS / 14s-per-block to 104 TPS / 3.8s-per-block, still 5/5
   byte-identical finality.

2. SECURITY (cryptographer MEDIUM-1) — postForkCommonComponents.Verify now refuses a block
   carrying a CLASSICAL secp256k1 proposer identity when the chain is strict-PQ
   (StakingMLDSASigner set), UNCONDITIONALLY (before the consensusState==Ready gate, so it
   also holds during bootstrap/state-sync). Fills the documented-but-unwired 'proposer'
   SchemeGate site: the downgrade defense is now an explicit fail-closed in-perimeter gate,
   not merely emergent from 20-byte NodeID collision-resistance + upstream enforcement.
   Adds SignedBlock.HasClassicalProposer(). Mirrors contract.RefuseUnderStrictPQ.

Pins consensus v1.36.7 (consume-on-error build loop — kills the non-leader BuildBlock spin).
Block + proposervm VM tests green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-15 22:24:36 -07:00
zeekayandHanzo Dev 13b6e80a78 fix(proposervm): strict-PQ proposer identity — sign+derive with ML-DSA-65 to match the windower
Under strict-PQ the canonical NodeID is ML-DSA-65-derived (config/node DeriveNodeID →
DeriveMLDSA), so the P-chain validator set and the proposervm windower are ML-DSA-keyed.
But proposervm signed post-fork blocks with the classical TLS leaf and derived the block
Proposer() via ids.NodeIDFromCert — a different value than DeriveMLDSA — so every signed
block (height ≥ 2) failed verifyPostDurangoBlockDelay with errUnexpectedProposer, was
dropped, and rebuilt in an unbounded storm (block 1 survived only because the unsigned
transition block skips the proposer comparison).

The block's offCert slot now carries a scheme-tagged proposer identity [scheme:1B|identity]:
0x90 classical (cert DER → NodeIDFromCert, ECDSA verify) or 0x42 strict-PQ (raw ML-DSA-65
pubkey → DeriveMLDSA(ids.Empty,pub), ML-DSA verify). ML-DSA signing/verification uses a
FIPS 204 §5.2 domain-separation context ('lux-proposervm-block-v1') so a proposer signature
can never be replayed as another ML-DSA message. proposervm.Config gains StakingMLDSASigner
/StakingMLDSAPub, plumbed from StakingConfig through ManagerConfig; exactly one scheme is
active per chain. K=1 nets are unaffected (transition + no-window blocks are unsigned).

Proven on a 5-node strict-PQ local net: sustained multi-block production, every block
built once, gossiped, and finalized byte-identical on all 5 (no automine). Pins consensus
v1.36.6 (engine logger + logged build-drops) which made this diagnosable.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-15 17:59:16 -07:00
zeekay 57792ee625 chore(deps): bump geth v1.20.1 + luxfi deps — stack unification 2026-07-15 11:20:41 -07:00
zeekayandHanzo Dev cf8e4c6f51 fix(chains): raise VM-startup timeout 30s→10m (vmStartupTimeout)
The 9 VM lifecycle ops (Initialize, Linearize, SetState, CreateHandlers,
router AddChain, state-sync) were each bounded at a hardcoded 30s. A cold
coreth 'Regenerate historical state' pass after an unclean shutdown takes
67-134s on the mainnet C-Chain, blowing that budget → context cancelled
mid-init → VM marked failed → C-Chain route never registered → the recurring
post-restart 404 that required a second restart to clear. One named bounded
constant (10m) covers regen with margin while still surfacing a truly-hung VM.
Stop stays 10s. This is the third stacked restart-fragility bug after
skip-bootstrap frontier (v1.36.11) and rejoin discriminator (v1.36.13).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 20:53:57 -07:00
zeekayandHanzo Dev 6ca0508608 v1.36.13: durable rejoin fix now fires for the C-Chain (discriminate on validating Net, not blockchain ID)
The #66/#74 durable rejoin fix was INERT for the C-Chain — the chain whose 40h
mainnet freeze motivated it. chains/manager.go gated expectsStakedBeacons on
ids.IsNativeChain(chainParams.ID) (the blockchain ID), but ids.IsNativeChain only
matches the symbolic 111...C alias; every deployed C/X/Q has a HASH blockchain ID
(devnet 21HieZng, mainnet 2wRdZG), so isNativeChain was ALWAYS false and under the
production --skip-bootstrap=true the beacons were emptied -> a behind C-Chain named
its stale local tip the frontier and never caught up. Verified on devnet v1.36.12:
C-Chain wedged at height 0 ('using empty beacons for single-node mode').

Fix: discriminate on the VALIDATING NET (chainParams.ChainID == PrimaryNetworkID)
via new chainValidatesOnPrimaryNetwork — PrimaryNetworkID for C/X/Q, the sovereign
net ID for L2s. C/X/Q now keep staked beacons under --skip-bootstrap (peer-sync a
behind validator); L2s keep the empty-beacon single-node path. New regression
TestChainValidatesOnPrimaryNetwork_RealHashChainID exercises the real discriminator
with hash IDs; TestRED_EmptyStakedSetFailsSafe still green (forged-frontier gate intact).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 18:51:43 -07:00
zeekayandHanzo Dev 35cbdfb0ee docs(LLM): v1.36.12 fleet rollout state — plugin-api blocker, codec migration, RewardManager runbook
Captures the devnet-canary findings so the gated rollout is resumable: the
v1.36.11 EVM-plugin api skew (fixed in v1.36.12), the v1.36.2->v1.36.x P-Chain
codec migration (one-time wipe + proven cross-version re-bootstrap), the durable
rejoin mechanism, per-net RewardManager addresses/config shape, and the
one-at-a-time verify-tip roll protocol. Also folds in the pre-existing
RewardManager->DAO-Safe C-Chain design note.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 18:23:55 -07:00
zeekayandHanzo Dev e266345e69 v1.36.12: align bundled EVM/dexvm plugins to node api v1.0.16 (fixes C/D-Chain init)
v1.36.11's node binary is correct (durable rejoin fix fe23efd1f2), but its image
baked VM plugins built against a stale luxfi/api: the C-Chain EVM plugin from
luxfi/evm@v1.104.8 and the D-Chain dexvm plugin from luxfi/dex@v1.5.15 both resolve
api v1.0.15, while the node pins api v1.0.16. api v1.0.16 APPENDED
InitializeResponse.Capabilities (uint64) for the Quasar-export handshake (api
1f2dc5a). The node decodes that field; the stale plugins never encode it, so
vms/rpcchainvm/zap/client.go fails every EVM VM Initialize with
'zap decode initialize response: unexpected EOF'. Native VMs (P/X/Q) are unaffected;
every EVM chain (C, D, and the L2 EVMs) fails to boot. Verified on devnet (published
v1.36.11 digest c3cf92a6): P/X re-bootstrap fine, C+D deterministically EOF.

Fix (image-only; node source unchanged beyond the version bump):
- EVM_VERSION v1.104.8 -> v1.104.9 (api v1.0.15 -> v1.0.16, indirect via luxfi/vm)
- force luxfi/api@v1.0.16 in the dexvm build stage (no dex release pins v1.0.16 yet)
- CHAINS_REF v1.7.6 already carries api v1.0.16 (the other 10 VMs were fine)
The api bump is code-free for plugins (chains v1.7.4->v1.7.5 adopted it go.mod-only).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 18:19:47 -07:00
zeekayandHanzo Dev 45bbe13637 node: purge dead protobuf tooling — ZAP-native, .proto codegen fully retired
Node has ZERO .proto files and ZERO .pb.go — the wire is hand-written ZAP schemas
(proto/{platformvm,vm,p2p,sync}/*_zap.go). The buf/protoc tooling around it was
orphaned: removed proto/{buf.yaml,buf.gen.yaml,Dockerfile.buf,buf.md,README.md},
scripts/protobuf_codegen.sh, the Taskfile generate-protobuf + check-generate-protobuf
targets, ci.yml buf-lint + check_generated_protobuf jobs (the latter ran the deleted
script → would fail CI), and the buf-lint.yml workflow. defaultPatch 10→11 (dev
version string; image already correct via ldflags). Binary unchanged — tooling/CI only.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 18:01:27 -07:00
zeekayandHanzo Dev fe23efd1f2 chains: skip-bootstrap must not disable peer-sync on a staked network (#66/#74)
Durable root-cause fix for the behind-validator rejoin wedge (mainnet luxd-0:
C-Chain frozen ~40h at a stale height, only a manual chaindata wipe unstuck it).

Root cause: buildChain computed the bootstrap frontier-sync discriminator as
`expectsStakedBeacons := !m.SkipBootstrap && native && !platform` AND emptied the
beacon set whenever `m.SkipBootstrap`. Production validators hardcode
--skip-bootstrap=true (to skip the initial bootstrap WAIT), so a real multi-
validator native chain (C/X/Q) got expectsStakedBeacons=false + EMPTY beacons.
FrontierTip then reported FrontierNoBeacons ("nothing to sync to"), the node named
its STALE local last-accepted the network frontier, transitioned the VM to normal
operation there, and never fetched the gap from its 4 healthy peers — the wedge
survived every restart because --skip-bootstrap is persistent config. The entire
peer-sync/self-heal machinery (bootstrap_sync.go) was dead code under skip-bootstrap.

Fix: drive the discriminator from SYBIL PROTECTION (the true "real staked network"
signal, already wired into ManagerConfig), not --skip-bootstrap. A sybil-protected
native non-platform chain now keeps its staked beacon set and expectsStakedBeacons
even under --skip-bootstrap, so a behind validator always catches up from peers.
A genuine single-node / dev net runs sybil-protection OFF and still takes the
empty-beacon immediate-start path. A single-VALIDATOR staked net (self-only set) is
handled by a new FrontierTip hasExternalBeacons rule (placed after the P-ready gate),
so it immediate-starts without a Connecting hang while a >=2 set runs the quorum.

This matches the proven live remediation (flipping skip-bootstrap=false via the
.allow-bootstrap marker caught luxd-0 up to tip in ~90s) and preserves every RED
safety invariant (empty staked set still fails safe — TestRED_EmptyStakedSetFailsSafe).

Tests: TestChainExpectsStakedBeacons_SybilDrivesNotSkipBootstrap,
TestNodeBootstrap_SelfOnlyStakedSet_ReportsNoBeacons, and the headline
TestNodeBootstrap_BehindValidator_StakedSet_CatchesUpNoWipe (N-blocks-behind →
restart → catches up from peers to tip, no wipe). Full chains suite green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 16:14:50 -07:00
zeekayandHanzo Dev b34dcd1558 v1.36.10: CHAINS_REF v1.7.6 — all VM plugins ZAP-native in the image
Bumps chains v1.7.5→v1.7.6 (dexvm/schain/identityvm/graphvm json→ZAP migrations)
+ zap v1.2.5. CHAINS_REF=v1.7.6 so the baked VM plugins carry the ZAP-native tx/
block wire. Node builds clean; xvm 12 pkgs green. Plugin subgraph now references
only surviving tags (chains v1.7.6 → node v1.36.9 → utxo v0.5.7).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 15:56:44 -07:00
zeekayandHanzo Dev 375dadde31 platformvm: delete dead weak SharedMemory interface declarations
Both executor backends re-declared a local SharedMemory interface with the
weak Apply(map[ids.ID]interface{}, ...interface{}) signature — but nothing
referenced it. The real atomic path uses Runtime.SharedMemory (= the narrow
atomic.SharedMemory: Apply(map[ids.ID]*atomic.Requests, ...database.Batch)).
Pure dead code; removed both. 28 platformvm packages green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 15:18:48 -07:00
zeekayandHanzo Dev 4d712c3798 xvm: drop reflect from fx dispatch — closed-sum type switch + dense tag array
The fx set is a CLOSED sum type (secp256k1fx | nftfx | propertyfx), fixed at
compile time — no hot-loading, no genesis-configured fx. So the runtime
'which fx owns this value' dispatch needs no reflection: it is a total match on
the variant tag. Replaced reflect.TypeOf(val) + map[reflect.Type]int with:
  - fxKindOf(val): a Go type switch over the closed set of fx primitive types
    (compiler-checked exhaustive; lowers to a jump on the interface type tag),
    returning the value's wire.TypeKind — the same family tag the wire envelope
    already carries.
  - FxIndex: a dense [16]int array indexed by that TypeKind (one bounds-checked
    load; -1 = unregistered), filled by the SAME fx.(type) switch NewCustomParser
    already ran — no separate reflect registration.
getFx (semantic verifier + tx_init) is now fxKindOf → array index: zero reflect,
zero map-hash, compile-time-checked. Deleted registerFxTypes + all
map[reflect.Type]int fields/params (parser, block/parser, vm, backend). Node-only
(uses already-imported utxo fx types + wire.TypeKind); no dep cascade.

Full xvm suite green (11 pkgs — secp/nft/property verify dispatch exercised).
This removes the LAST reflection from the X-chain tx/verify path.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 10:02:52 -07:00
zeekayandHanzo Dev 3f65eb486d v1.36.8: zap v1.2.4 value ObjectBuilder — faster wire build node-wide
zap v1.2.4 (eager-reserve + value-type ObjectBuilder: zero defer-slice, zero
per-StartObject heap alloc) + utxo v0.5.7. Byte-identical wire — 21 platformvm/
xvm/components-lux/da packages green. Node-side setEnvelope/setValidator/setID/
setOwner/setSecurity/writeIDInto helpers take zap.ObjectBuilder by value (its
methods mutate through ob.b, so value + pointer are equivalent). Speeds every
ZAP object build (P/X txs, blocks, warp, da), not just X-tx. X-tx wire composite
922->655ns / 11->5 allocs.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 09:37:11 -07:00
zeekayandHanzo Dev 4002a59aa6 go.sum: record complete dependency hashes (go mod tidy)
Superset of transitive module hashes go resolves at v1.36.7; -mod=readonly build
+ full 155-package test suite green. No go.mod change.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 07:00:10 -07:00
zeekayandHanzo Dev 97e0a0b704 v1.36.7: xvm native-nested composites — 2.8x X-tx build, import/export too
Consume utxo v0.5.6 + zap v1.2.3. X-chain BaseTx / ExportTx / ImportTx now build
their transferable out/in lists as native ZAP AddObjectPtr object-lists (no
per-container envelope prefix, no blob concat, no length lists) via
wire.AppendTransferable{Out,In} + TransferableXFromObject. baseTxWire composes
wire.XVMTransferOut/In directly. Removed the standalone transferableOut/InBytes
node helpers. Composite money-move build 2551ns/37allocs (byte-blob) ->
913ns/11allocs (native-nested), 2.8x. Full xvm suite green (round-trip/state/
block/executor/import/export); components-lux + wallet-x + platformvm-txs green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-14 06:38:42 -07:00
zeekayandHanzo Dev 24b67abdd0 v1.36.6: consume faster write path — zap v1.2.2 + utxo v0.5.3
zap v1.2.2 (zero-copy SetBytes + Builder pool) + utxo v0.5.3 (pooled wire
builders + SetBytesFixed) cut X-chain tx wire composition ~1.9x (2551->1345ns,
37->19 allocs on the isolated composite; the X build path benefits proportionally
without touching P-chain parse, which stays at 705ns/3allocs). P/X/xvm/
components-lux suites all green against the new deps.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-13 03:45:37 -07:00
zeekayandHanzo Dev 7ee56895d9 v1.36.5: no-replace hermetic build — chains v1.7.5 (pins real node v1.36.4), revert Dockerfile node replace
Supersedes v1.36.4's build recipe which used a build-time 'replace node => /build'
(forbidden: no local replace directives). Instead, chains v1.7.5 pins the real,
published node v1.36.4 tag, so the baked VM plugins resolve node the normal way —
Dockerfile just clones chains and builds; CHAINS_REF v1.7.4 -> v1.7.5; go.mod
chains v1.7.4 -> v1.7.5; genproto realigned. Zero replace directives anywhere.
tidy + -mod=readonly + cold 'go mod download all' clean.

Note: luxfi node/geth/utxo git tags are being periodically wiped by an external
tag-sync (root cause of the 'unknown revision' failures); all four pinned tags
(node v1.36.4, chains v1.7.5, utxo v0.5.1, geth v1.17.12) re-verified present
immediately before this build races the sync window.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 21:43:55 -07:00
zeekayandHanzo Dev bbce8e6e13 Dockerfile: build baked VM plugins against the HOST node (/build), not chains' pinned node
The plugin stage cloned chains and built each VM's cmd/plugin standalone, which
resolved chains' pinned github.com/luxfi/node@v1.30.6 — a wiped/disjoint release
tag (325 orphan commits, no merge-base with main) absent from the remote, so the
hermetic build died with 'unknown revision v1.30.6' and the required bridgevm/
mpcvm/zkvm plugins went missing (FATAL).

Fix: inject 'replace github.com/luxfi/node => /build' (the exact vX.Y.Z node source
being built) into every /tmp/chains go.mod before building. This is what the
existing 'plugins in lockstep with the host node' intent actually requires — the
baked plugins now match the node they run in instead of an ancient pin. chains is
the main module during the plugin build, so node(/build)'s own require of chains
resolves back to /tmp/chains (main-module-wins) — no version fetch, no loop. Also
bumped CHAINS_REF default v1.7.2 -> v1.7.4 to match node's go.mod chains pin.

Verified: all 10 required plugins build cold (fresh GOMODCACHE, CGO_ENABLED=0) into
real binaries against local node v1.36.4.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 17:35:39 -07:00
zeekayandHanzo Dev 9930e98d26 fix(deps): pin published utxo v0.5.1, drop local ../utxo replace — unbreak hermetic build
The xvm codec kill depends on utxo/wire's TransferableOut/In + nftfx/propertyfx
envelopes, which were only in the local ~/work/lux/utxo working tree (pinned via
'replace github.com/luxfi/utxo => ../utxo'). That local-path replace works for a
local build but breaks the hermetic Docker/CI build ('open /utxo/go.mod: no such
file or directory'). Published those two additive wire commits as utxo v0.5.1
(clean ff on utxo main, +2 over v0.5.0) and pin it here — the exact code node was
built+tested against. Dropped the replace. Cold-cache 'go mod download all' is now
clean; xvm/components/lux/wallet tests green against v0.5.1.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 17:17:36 -07:00
zeekayandHanzo Dev 64a770b4cc vms/pcodecs: DELETE the last reflection dispatcher — ZAP native everywhere (v1.36.4)
The codec kill is complete. Every node VM (platformvm, xvm, warp, proposervm,
components/lux) and every chains app-chain VM (bridgevm, zkvm, mpcvm — now native
in chains v1.7.4) marshals via native ZAP struct-is-wire. Nothing imports
node/vms/pcodecs anymore, so the package — the last reflection/serialize-tag
dispatcher (a thin alias over proto/zap_codec's LinearCodec) — is deleted.

- rm vms/pcodecs + vms/pcodecs/pcodecsmock (zero consumers; verified whole tree).
- go.mod: chains v1.7.2 -> v1.7.4 (the pcodecs-free chains), precompile
  v0.19.0 -> v0.19.1. Realigned genproto so the split googleapis/rpc module
  resolves by longest-prefix (no monolith ambiguity); tidy clean, -mod=readonly
  build clean.
- version -> v1.36.4 (constants.go defaultPatch, compatibility.json under the
  same RPCChainVM protocol as v1.36.3 — no protocol change, only a codec rip).

There is one and only one way to put a struct on the wire: ZAP.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 16:54:25 -07:00
zeekayandHanzo Dev 6b25706366 wallet/x + components/lux: complete xvm native-wire consumer
Tail of the xvm codec kill (ddb3fbca93): the X-chain wallet builder + signer
now rebuild signed wire bytes as unsigned ‖ fx credential envelopes over the
native luxfi/utxo/wire form, and components/lux parses fx Inputs from their wire
envelope by concrete type. No linearcodec, no reflection on the wallet path.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 16:54:12 -07:00
zeekayandHanzo Dev ddb3fbca93 xvm -> native ZAP struct-is-wire: node-side codec kill COMPLETE
X-Chain fully off pcodecs (the last node consumer). kind.go (xkind 1-5), tx.go
(wire.SignedTx envelope), parser (reflect-map + dual LinearCodec DELETED, fx
dispatch by envelope TypeKind/ShapeKind), base/create_asset/operation/import/
export tx, initial_state, operation, block/{standard,parser,builder}, genesis
(native genesis_wire.go: marshalGenesis/parseGenesis + txs.ParseUnsignedTx),
vm/service/static_service/wallet_service/utxo-spender, metrics (pcodecs.Errs ->
errors.Join). ALL xvm test codec threading removed; xvm tests green.

Block-build invariant: writeTxList requires Initialized txs (mempool/parse hand
the builder canonical bytes) — errors on empty tx-bytes rather than a hidden
Initialize side-effect; state_test updated to Initialize its fixtures.

Transport foundation: rpcchainvm NewListener unix-socket fast path gated
LUXD_VM_UNIX_SOCKET=1 (default TCP, non-breaking; api/zap 159b27a infers unix
from socket-path addr). Consumes upstream utxo TransferableOut/In (4ce6a6e).

ZERO real node-side pcodecs consumers remain. vms/pcodecs kept only for 3
external luxfi/chains VMs (Wave B: zkvm/bridgevm/mpcvm) pending their migration.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-12 11:26:36 -07:00
zeekay b113618e5e Merge main: record Quasar-export lineage (content integrated in prior commit; codec-kill supersedes main's codec files) 2026-07-11 22:48:27 -07:00
zeekayandHanzo Dev 3f890bc98e Integrate main's Quasar-export + EVM v1.104.8 content into the codec-kill branch
The non-codec main changes (Dockerfile EVM_VERSION v1.104.8, chains/manager
GetContext size-chunking for behind-validator resync + Quasar EXPORT frontier
bridge, warp/signature, rpcchainvm/zap client) that the branch lacked. The
codec-era main files (codec.go/parse.go/tx.go etc.) are intentionally
superseded by this branch's native-ZAP struct-is-wire — not reintroduced.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 22:48:27 -07:00
zeekayandHanzo Dev 44d7651d16 block: reject trailing bytes in Parse (malleability guard) + port determinism test to native ZAP
RED-verified consensus-safety fix: zap.Parse truncates to the header size
field, so a block buffer with extra tail bytes wraps the SAME message but
ID=hash(bytes) differs — a block-hash malleability / fork vector. setID now
rejects msg.Size() != len(bytes) with ErrExtraSpace. (The P-chain TX envelope
already guards this at tx.go:66; only block Parse had the gap.)

Renamed codec_determinism_test.go -> block_determinism_test.go and converted
its assertions to native ZAP: New*Block + Parse(b) (no Codec), native golden
AbortBlock bytes (65B: zap header + kind/parent/height/time object), byte-
stability + BlockID-stability + trailing-bytes-rejected. Block + txs green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 22:45:44 -07:00
zeekayandHanzo Dev dcde2167a8 node v1.36.3: binary self-reports true version + RPCChainVM compat entry
defaultMinor/Patch -> 36/3 (Dockerfile injects no version ldflags, so the
default IS the released binary's self-reported version; v1.36.0-2 shipped
self-reporting 1.32.11). v1.36.3 registered under RPCChainVM protocol 42.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 22:36:04 -07:00
zeekayandHanzo Dev 5a2035adb5 Merge feat/lp023-native-tx-codec: FULL codec kill — P-chain/warp/proposervm/components struct-is-wire
The LP-023 native-ZAP migration, complete except xvm (next patch):
- P-Chain: tx + block + state + genesis are the zap buffer (struct=wire, no
  codec, no serialize tags, no versions). Executor fold: CreateNetworkTx/
  ConvertNetworkTx with security.Mode (RestakeParent × own-set Admission/
  Manager) — one definition shared by wire/executor/state; CreateChainTx is
  the sole chain constructor (block-atomic L1 spawn per LP-018).
- warp: registration-order codec (hard-fork footgun) → explicit wkind/mkind/
  pkind discriminator bytes; ChainToL1ConversionID = sha256(Marshal()) same-
  encoder invariant; native wire baselines pinned.
- proposervm block/state/summary, components/{lux,message,keystore,index},
  evm/{predicate,lp176}, example/xsvm: native ZAP; pcodecs consumers reduced
  to xvm only.
- consensus v1.36.1 + node-side view-change plumbing ripped (merged with
  main's parallel rip; main's Nova tombstones kept).
- /ext/ endpoint prefix retired: /v1/ is THE endpoint.
- All codec-era tests restored/converted to struct-is-wire (0 parked); staker
  dispatch-safety guard added.
- Deps: published pins only (consensus v1.36.1, zap v1.2.0, utxo v0.3.7,
  crypto v1.20.0); no local replaces.

Merged-tree gate: go build ./... EXIT 0; go test ./... = 155 ok / 0 FAIL.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 22:36:04 -07:00
zeekayandHanzo Dev b4992860f6 deps: publishable pins — zap v1.2.0, drop local replaces
Node builds + full test sweep green (155 ok / 0 FAIL) against PUBLISHED
modules only: consensus v1.36.1, zap v1.2.0, utxo v0.3.7. The local zap/utxo
replaces are gone; the upstream nftfx/propertyfx wire (utxo e790d39) ships as
v0.3.8 with the xvm struct-is-wire patch, which is the only remaining pcodecs
consumer and lands in the next release.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 22:32:00 -07:00
zeekayandHanzo Dev 0ba5d05bd8 Retire /ext/ endpoint prefix: /v1/ is THE endpoint
Route registration, client URL builders, and log lines all move to /v1/
(wallet primary api, chains/rpc handler_manager+chain_integration, xvm
client+wallet_client, xsvm api client, multi-network example, manager logs).
Zero /ext/ literals remain. One endpoint namespace, no transition alias.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 19:14:51 -07:00
zeekayandHanzo Dev 926ddaafa4 go.mod: replace luxfi/utxo -> local (nftfx/propertyfx wire envelopes)
Consumes the upstream fx-wire addition (utxo commit e790d39: TypeKindNFT/
Property + 6 shapes + NextEnvelope) needed for the xvm struct-is-wire
migration. Local replace like zap; publish as utxo v0.3.8 with the node
release.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 17:55:48 -07:00
zeekayandHanzo Dev eda299d30d node v1.36.2: consensus v1.36.1 finality fix on the known-good v1.36.0 base
v1.36.1 bundled staged-but-runtime-untested ZAP work (api v1.0.15->v1.0.16,
vm v1.2.5->v1.2.7, EVM v1.104.7->v1.104.8, platformvm sole-codec cutover,
rpcchainvm Quasar-export plugin-boundary wiring). That bump breaks VM
initialization on EVERY chain at boot:
  failed to initialize VM: zap decode initialize response: unexpected EOF
— a node<->plugin ZAP handshake mismatch (the plugins were not synced to the
new api/vm ZAP wire). Mainnet would not boot on v1.36.1.

v1.36.2 drops that unfinished ZAP transition and ships ONLY the orthogonal
consensus finality fix (v1.36.1 — close the intermediate-ancestor load-livelock,
RED-SHIP 0 crit/high/med) on the known-good v1.36.0 dependency set (api v1.0.15,
vm v1.2.5, EVM v1.104.7). Boots clean AND carries the finality fix. luxd builds
green (-mod=mod). The ZAP Quasar-export / codec cutover ships separately once the
plugins are synced to the api/vm bump and it is runtime-validated.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 17:45:11 -07:00
zeekayandHanzo Dev 6a766516b1 warp -> native ZAP struct-is-wire: kill the registration-order codec (hard-fork footgun)
All 3 warp codec registries deleted (codec.go, message/codec.go,
payload/codec.go). Every dispatched type now carries an EXPLICIT 1-byte
discriminator at object offset 0 — the invariant is DATA, not registration
order:

  warp wkind:    0x00 BitSetSignature, 0x01 CoronaSignature,
                 0x02 EncryptedWarpPayload, 0x03 HybridBLSCoronaSignature,
                 0x04 TeleportMessage, 0x05 TeleportTransferPayload,
                 0x06 TeleportAttestPayload   (ids = old registration order)
  message mkind: 0 ChainToL1Conversion, 1 RegisterL1Validator,
                 2 L1ValidatorRegistration, 3 L1ValidatorWeight
  payload pkind: 0 Hash, 1 AddressedCall

CONSENSUS-CRITICAL invariant made structural: ChainToL1ConversionID =
sha256(ChainToL1ConversionData.Marshal()) — the ID calls the SAME encoder, so
ID/Marshal skew (the bug in the reverted agent attempt) is impossible. The
native hash preimage is pinned as a golden with field-offset assertions
(verified by the L1 staking contract => consensus surface).

Message = {unsigned bytes, wkind-tagged sig bytes} container object;
UnsignedMessage = {networkID u32, sourceChainID 32B, payload} @44B header.
wire_baseline_test.go rewritten: pins the native hex golden for all 7 wkinds
+ structural discriminator checks + signature dispatch round-trips. Old-codec
sentinels -> zap errors. Whole node builds; warp+platformvm+proposervm green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 17:44:13 -07:00
zeekayandHanzo Dev 2d227dd3aa Full-codec-kill wave 2: proposervm + xsvm + components + evm + platformvm-residual → native ZAP
Kills pcodecs from 3 complete subsystems (verified go test ./... = 155 ok / 0 FAIL):
- proposervm: block/state/summary struct-is-wire (blockwire.go + statewire.go;
  deleted block/state/summary codec.go). blockKind bytes: reserved=0 signed=1
  option=2. Epoch inlined in unsigned object. proposer/windower chainSource seed
  = binary.LittleEndian (byte-identical to old wrappers.Packer.UnpackLong).
- example/xsvm: tx/block/genesis native Marshal (deleted 3 codec.go); create-chain
  example uses genesis.Marshal().
- components: message.Tx native (deleted codec.go); keystore codec shell removed;
  index pcodecs.LongLen → local const.
- evm/{predicate,lp176}: off pcodecs.
- platformvm residual: state metadata + genesis + metrics + signer + stakeable
  native, vestigial serialize tags removed.

REMAINING (careful solo, agents weekly-capped): warp (reverted — agent left an
ID≠Marshal consensus inconsistency in ChainToL1Conversion; needs proper review,
not a golden-regen) + xvm (reverted — barely started). pcodecs package stays
until those 2 land. /ext/→/v1/ endpoint change also pending.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 17:19:20 -07:00
zeekayandHanzo Dev a78aa07e6f node v1.36.1: consensus v1.36.1 (close finality load-livelock)
Bump github.com/luxfi/consensus v1.36.0 -> v1.36.1 — canonicalizes the
intermediate-ancestor walk (pathFromTip alias-collapse) that livelocked finality
under sustained saturation (the one finality path the mainnet-644 canonicalization
missed). RED-SHIP, 0 crit/high/med: alias-collapse can only stand in a
byte-identical inner execution (canonicalRep = CanonicalID, a state-root-binding
hash), so no fork risk HEAD lacked. Carries the v1.36.0 platformvm sole-codec
cutover + ZAP Quasar export already on main.

luxd builds green against consensus v1.36.1 (GOFLAGS=-mod=mod, CI parity).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 10:33:58 -07:00
zeekay dd04027476 node v1.36.0: api v1.0.16 + vm v1.2.7 (ZAP Quasar export) + EVM_VERSION v1.104.8
Folds the native-ZAP codec cutover (platformvm sole-codec) + the Quasar EXPORT-frontier
carry across the rpcchainvm ZAP boundary. Whole-node build green.
2026-07-11 10:33:58 -07:00
zeekayandHanzo Dev 28e34ba003 vms/platformvm: rip multi-version codec — ZAP-native is the sole P-Chain codec
Collapse P-Chain tx/block/state serialization to a single ZAP-native codec
(CodecVersion=1). This is the gate before the Nova re-genesis: one write
path, one read path, no version dispatch.

Removed the whole multi-version surface:
- txs: registerV0TxTypes, CodecVersionV0/V1/V2, CodecVersionForTimestamp,
  CodecForTimestamp, CodecAllowsRead, CodecRequiresLegacy, the Version
  alias, and codec_activation.go (ZAPCodecActivationTimestamp).
- block: v0Codec/v0GenesisCodec, the block/v0 package, the lift_v0 path;
  Parse is now single-version.
- state: the v0-probe codec_helpers (it Marshal'd at version 0, which
  would fire a false warning every boot); GenesisCodec.Unmarshal inlined.
- genesis: single-version alias + comment cleanup.
- warp/bench/network: stale "linearcodec"/"reflectcodec" comments corrected
  (all already ride the ZAP-backed pcodecs shim; wire unchanged).
- wallet/chain/p: txs.Version -> txs.CodecVersion.

Value 1 is retained (not renumbered) so no tx ID, block ID, or state root
changes: the surviving codec is exactly the ZAP-native slot the chain
already writes. Every existing serialization golden stays byte-for-byte.

Determinism proof (codec_zap_test.go, block/codec_determinism_test.go):
golden tx/block bytes + IDs, marshal idempotency, round-trip byte-stability
for every tx and block type, and trailing/truncated/wrong-version
rejection. grep -rnE 'linearcodec|reflectcodec|CodecVersion(ForTimestamp|V0|V1)'
vms/platformvm/ is empty.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 10:33:58 -07:00
zeekayandHanzo Dev f2dcc91cd3 chains, rpcchainvm: wire the Quasar EXPORT tier across the plugin boundary (client + manager)
Closes the deploy-blocking gap in two-tier consensus v1.36: the C-Chain EVM runs
as a SEPARATE rpcchainvm plugin process, so the chain manager's vmTyped is the
rpcchainvm *Client — which did NOT implement SetLastQuasarFinalized /
LastQuasarHeight (those live only on the concrete *evm.VM, the plugin SERVER
side). The manager's capability assert therefore returned !ok in production, the
QuasarObserver stayed nil, and finalized/safe + the warp export gate stuck at
genesis. Nova consensus was unaffected (node-side).

rpcchainvm/zap client (*Client):
- SetLastQuasarFinalized / LastQuasarHeight: ZAP-call the plugin (Msg 60/61).
  Both short-circuit if the plugin did not advertise CapQuasarExport, so wiring
  them is harmless for a generic plugin (no per-finalization no-op RPC).
- SupportsQuasarExport: reports the capability captured (atomically, once) from
  the Initialize handshake's InitializeResponse.Capabilities.
- Fire-and-forget Set (logged, not returned — the caller is the consensus
  observer); Height returns 0 on any failure (boot re-seed treats it as empty).

chains/manager createChain:
- quasarExportVM interface (values-not-places: the capability is a value, not a
  static type property). Gate the observer + boot re-seed on the capability:
  a *Client reports it via SupportsQuasarExport (false → Nova-only, exactly the
  old !ok semantics — no cross-process spam); a VM WITHOUT the probe (an
  in-process VM whose concrete methods we hold directly) is treated as capable,
  preserving the direct-wire path. Observer is set BEFORE NewRuntime captures
  netCfg; the seed runs after, carried by the exportVM value.

Test (client_quasar_test.go, -race): the REAL cross-process path — node *Client
-> ZAP wire -> luxfi/vm/rpc server -> a fake VM that satisfies the SAME
capability interface as *evm.VM. Capability captured from the handshake; a pushed
height crosses the wire into the VM; the VM's height round-trips back; a
non-capable plugin is a graceful Nova-only no-op.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 10:33:58 -07:00
zeekayandHanzo Dev 7123b7399e Restore+convert remaining txs tests to struct-is-wire + dispatch-safety guard
Converts the per-type P-chain tx tests to native New*Tx + accessor methods +
roundTrip/SyntacticVerify (agents, verified): add_validator, add_chain_validator,
create_blockchain, disable/increase/register/set_weight/remove_chain/
transfer_ownership L1, add_permissionless_delegator, transform_chain. Every
error-path sentinel preserved by driving the bad value THROUGH the constructor
(pure byte-writer). Mock-based cases (fxmock/luxmock/verifymock, impossible on
an immutable zap buffer) reproduced with REAL unspendable owners / unsorted
inputs → real sentinels (ErrOutputUnspendable, ErrInputIndicesNotSortedUnique).
Only the un-reproducible 'already verified' cached-flag case dropped per file.

NEW staker_dispatch_guard_test.go pins the interface-satisfaction invariant the
staker type-switches depend on: struct-is-wire made *AddValidatorTx satisfy both
ValidatorTx+DelegatorTx (safe — ValidatorTx checked first everywhere), but
*AddDelegatorTx must NOT satisfy ValidatorTx (verified: lacks
ValidationRewardsOwner/Shares) or delegators would mis-route. Guard fails loudly
if a future edit breaks either property.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 05:46:10 -07:00
zeekayandHanzo Dev 43cbbac511 Restore+convert genesis/state/network tests to struct-is-wire (4 files, zero coverage dropped)
- genesis: field->method on *txs.AddValidatorTx (.Validator().NodeID/.End/
  .StakeOuts()); 3 error-path builders preserved (errUTXOHasNoValue,
  errValidatorHasZeroWeight, errValidatorAlreadyExited).
- state/staker: generateStakerTx via NewAddPermissionlessValidatorTx; the
  mutable-Signer-mock trick (impossible on immutable zap buffer) ->
  NewMockScheduledStaker.PublicKey()=errCustom, errCustom preserved exactly.
- network/gossip+network: nil-buffer &txs.BaseTx{} -> newBaseTx helper (avoids
  InputIDs() panic); SetBytes 2-arg->1-arg; all expectedErr preserved
  (ErrDuplicateTx, ErrTxTooLarge, ErrConflictsWithOtherTx, ErrMempoolFull...).
go test ./genesis/ ./state/ ./network/ = all ok.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 05:45:21 -07:00
zeekayandHanzo Dev 7ea0c0383f Restore+convert fee/mempool/txheap tests to struct-is-wire (6 files, green)
- fee/complexity: kept all 5 component tests + error paths; dropped codec
  byte-cross-check + dead pre-LP-023 BE-hex fixtures, REPLACED with native
  TestTxComplexity (visitor single-path + batch-additivity + ErrUnsupportedTx).
  Removed TestConvertNetworkToL1ValidatorComplexity (fn deleted; per-validator
  convert complexity now inline in complexityVisitor.ConvertNetworkTx).
- fee/static + dynamic_calculator: skipped hex-loops -> native (TxFee/
  CreateChainTxFee/positive-priced supported, ErrUnsupportedTx unsupported).
- mempool/{auth,mempool}: native New*Tx + Initialize(); strict-PQ credential
  gate (ErrLegacyCredentialUnderStrictPQ) + Add/Get/Peek/Remove/DropExpired.
- txheap/by_end_time: NewAddValidatorTx + heap-ordering assertions.
go test ./txs/fee/ ./txs/mempool/ ./txs/txheap/ = ok (17 tests, no skips).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-11 05:40:20 -07:00
hanzo-dev 6b599d29e1 ci: run linux jobs on lux-build-amd64 ARC scale set (no GitHub-hosted builders) 2026-07-11 00:14:50 -07:00
zeekayandHanzo Dev c5e999487c Green the 8 post-bump test failures (real fixes, no delete-to-hide)
- spending.go: harden spendingTx.Bytes() against nil msg (uninitialized tx no
  longer panics the spend-verification path; production always sets msg).
- config/genesis-builder tests: codec-era Codec.Marshal -> native g.Bytes();
  AddValidator field access -> methods (Weight()/Validator()/StakeOuts());
  drop unused pchaintxs imports.
- config test: consensus params K=30 alpha 16->20/25 to satisfy v1.36's tighter
  BFT bound (2*alpha-K >= floor((K-1)/3)+1); assertions updated.
- version/compatibility.json: register Current v1.32.11 under RPCChainVM proto 42
  (pre-existing registration gap).
- cevm e2e: genesis fixture completed with gasLimit+difficulty (strict geth
  genesis validation in the installed CEvm plugin; pre-existing fixture drift).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 21:20:17 -07:00
zeekayandHanzo Dev 9626ca6c2f Bump consensus v1.35.37 -> v1.36.1 + rip node-side view-change plumbing
v1.36 upstreamed round-scoped view-change INTO the engine (internal prevote/POL
in attestation/reconcile/cert), dropping the external hooks config.Parameters.
ViewChange + Runtime.HandleIncomingPrevote. Ripped the node's now-redundant
external plumbing: the ViewChange enable block (LUX_CONSENSUS_VIEW_CHANGE gate),
the quorumKindPrevote gossip routing + HandleIncomingPrevote call, the dead
BroadcastPrevote gossiper method, and the quorumKindPrevote envelope kind. The
engine owns view-change natively now (fail-secure halt on 2a-n>f unchanged).

Whole node builds EXIT 0 on v1.36.1; luxd binary compiles (55M).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 21:07:38 -07:00
zeekayandHanzo Dev 87a57925f3 components/lux UTXO value tree -> native ZAP (Wave-A Substrate)
The shared UTXO value tree (UTXO/TransferableOutput/TransferableInput/Asset/
UTXOID/BaseTx/Metadata + OutputOwners path) gets native struct-is-wire
Marshal/Unmarshal (new marshal.go), replacing every pcodecs.Manager. Codec
param dropped from utxo_state / atomic_utxos / transferables (Sort* sorts on
inner fx wire Bytes()); flow_checker pcodecs.Errs -> errors.Join.

Node consensus persistence uses luxfi/utxo (unchanged); components/lux is the
tx-builder/#58 surface — encoding-only change, type tree NOT collapsed (#58
respected). Both P and X share the encoding => internally consistent, re-genesis
safe. Whole node builds EXIT 0; 8 components/lux round-trips + P-chain txs/block
tests green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 21:01:11 -07:00
zeekayandHanzo Dev 3b4d16bbc5 indexer p-chain example: block.Parse(b) codec-free — WHOLE NODE builds
Last P-chain codec consumer. go build ./... = EXIT 0. The platformvm codec
(pcodecs/txs.Codec/serialize tags) is fully dead; P-chain tx + block + state are
native ZAP struct-is-wire end to end. Remaining codec surface is X-chain +
proposervm + warp (Wave A), which still carry their own (intact) codecs.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 14:35:18 -07:00
zeekayandHanzo Dev 511a804016 Decomplect: CreateChainTx is the sole chain constructor (kill genesis-chains stub)
CreateNetworkTx no longer carries genesis chains — the executor never created
them, so tx.Chains() was a latent stub (declared, verified, silently dropped).
Model A resolves it by decomplection, not by implementing a second chain path:

  - CreateNetworkTx = ∅→Network birth (owner + security.Mode + own validator set).
  - CreateChainTx = the ONE chain constructor. An L1 spawn is a BLOCK of
    CreateNetworkTx + N CreateChainTx (block-atomic, not tx-atomic).
  - Removed NetworkChain, its wire (writeNetworkChains/readNetworkChains/
    ncStride/sliceIDs), the chain error set, MaxNetworkChains, the chains param.
  - managerChainIdx (index into genesis chains) -> managerChainID (direct
    ids.ID), now SYMMETRIC with ConvertNetworkTx's manager ref. ids.Empty =>
    P-Chain-governed; a set chainID => Contract-governed staking-contract host.

Net: less code (write as little as possible), one-and-one-way chain creation,
no stub. platformvm build+vet PASS; SovereignL1/InheritedL2/HybridL2/Convert
round-trips PASS.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 14:33:13 -07:00
zeekayandHanzo Dev c44cc2289f platformvm builds GREEN off the codec: executor fold + full consumer flip
vms/platformvm/... build + vet PASS with pcodecs/txs.Codec gone from the VM.

Executor semantics (standard_tx_executor):
- registerOwnSet(): shared primitive — per-validator state.L1Validator with
  native owner blobs (txs.MarshalOwner/UnmarshalOwner, no codec), active-set
  capacity check, EndAccumulatedFee=balance+accruedFees, SetNetToL1Conversion
  manager-authority recording (byte-for-byte legacy tail).
- ConvertNetworkTx: promote endomorphism (owner-authorized, folds old
  ConvertNetworkToL1Tx), gated by security.Mode.Manager.
- CreateNetworkTx: base (AddNet/SetNetOwner) + sovereign path registers own set.
- Deleted CreateSovereignL1Tx + ConvertNetworkToL1Tx.
- txs.UnmarshalOwner added: canonical owner marshal/unmarshal pair, no codec.

All ~13 txs.Visitor impls carry ConvertNetworkTx; gossip/block Parse(b) codec-free;
wallet/network/primary off txs.Codec.

KNOWN GAP (pending design decision, NOT silently green): CreateNetworkTx reads
tx.Chains() only to derive managerChainID — it does NOT create the genesis
chains (no AddChain). Atomic-spawn-with-chains vs decomplect-to-CreateChainTx is
the open call. 17 codec-era _test.go parked as .bak for follow-up rewrite.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 14:25:08 -07:00
zeekayandHanzo Dev c73eba739f Flip 4 platformvm consumers off txs.Codec (MarshalOwner + New*Tx + native genesis Bytes)
- txs.MarshalOwner(any): ONE canonical owner encoding (same layout as embedded
  tx owner), lifted to a standalone buffer for lock-owner hash keys in utxo
  handler+verifier. Replaces txs.Codec.Marshal(owner). Re-genesis-safe (ownerID
  only matched within a tx's own consumed/produced sets).
- validators/manager: chain.ChainID -> chain.ChainID() (field->method).
- api/static_service: genesis txs via NewAddValidatorTx / NewAddPermissionless
  ValidatorTx / NewCreateChainTx + codec-free Initialize(); genesis blob via
  native g.Bytes(). Mid-flip: executor + remaining visitors still pending.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 13:40:18 -07:00
zeekayandHanzo Dev f1a3e85b8e Rename LuxAddress -> UTXOAddr (decomplect place-from-value)
LuxAddress in airdrop.AirdropClaim + bridgevmroot.SignerLeaf is the NATIVE
20-byte Lux address (ids.ShortID / [20]byte), held beside the EVM common.Address
it disambiguates. 'Lux' prefix is banned place-in-value naming; the canonical
pair is EVMAddr / UTXOAddr. Named by address KIND, not brand.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 13:30:17 -07:00
zeekayandHanzo Dev d008eba286 security.Mode: decomplect network security into its own package
Pull the network security model out of the tx wire into a small orthogonal
package (vms/platformvm/security): pure values, stdlib-only, no zap/tx/state
deps. One definition — security.Mode{RestakeParent, Admission, Threshold,
Manager} + Sovereign() + Valid() — composed by tx wire, executor, and state
(Rich Hickey: values not places; Rob Pike: no stutter, small orthogonal pkg).

Two orthogonal axes replace the flat Inherited/Sovereign byte:
  - RestakeParent: lean on parent's validator set
  - own set: Admission(NoOwnSet|Open|Gated) + Manager(PChain|Contract)
Their product spans every mode incl. HYBRID L2 (restake AND additive own set),
which the flat byte could not express. Invariant RestakeParent || own-set on
Mode.Valid(); Sovereign derived, never flagged.

CreateNetworkTx + ConvertNetworkTx carry security.Mode on the wire via shared
setSecurity/readSecurity. Round-trip green incl. new HybridL2 case + Convert
target-mode. Wallet builders pass the explicit restaked-L2 Mode.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 12:59:29 -07:00
zeekay b6143b5d53 Block codec → native ZAP (struct-is-wire): builds + round-trips green
Blocks are now the zap buffer: kind + parentID@1 + height@33 + time@41 +
tx-length-list@49 + tx-blob@57 (+ proposal-tx@65). commonZapBlock embedded base
mirrors spendingTx. Parse = zap.Parse + kind dispatch (no codec, no version).
Deleted block/codec.go + block/v0 + lift_v0. Round-trip green for abort/commit/
proposal/standard incl real signed txs. go build + go test ./block/ = green.

FINDING: block.GenesisCodec was double-duty — also serialized NON-block STATE
values (feeState, owners, L1Validator, metadata, chains). That's a THIRD codec
surface (state DB serialization) still to migrate for the full kill.
2026-07-10 12:43:20 -07:00
zeekay 20d36b36aa Restore ConvertNetworkTx as the promote endomorphism (Create ≠ Convert)
Create and Convert are orthogonal arrows: CreateNetworkTx = ∅→Network (birth,
sovereign-or-inherited); ConvertNetworkTx = Network→Network (promote an
existing network: inherited→sovereign, re-anchor parent — L2→L1, L3→L1, with
owner auth). Only CreateSovereignL1 stays folded (it was birth+sovereign, not
a distinct op). Both reuse the NetworkValidator component. Round-trip green
incl L2→L1 promote.
2026-07-10 12:13:15 -07:00
zeekay 4610978bcc Decomplect network creation: one CreateNetworkTx folds Convert+CreateSovereign
CreateNetworkTx{parent, owner, security, validators, chains, manager} creates a
network at ANY level in one tx — parent is the level axis (Primary⇒L1, L1⇒L2,
recurse; level=depth, never stored). security is a coproduct: SecuritySovereign
(own validators+manager) | SecurityInherited (restaked from parent). manager
lives on the Network so an inherited L2 holds local admin. NetworkValidator +
NetworkChain are shared value components (reused by CreateChainTx). Deleted
ConvertNetworkToL1Tx + CreateSovereignL1Tx (folded / migration artifacts).

Round-trip green: sovereign L1 (own validators+chains+manager) AND inherited L2
(parent recorded, no own validators, local manager) both survive. One and one
way to make a network at any depth.
2026-07-10 11:39:12 -07:00
zeekay e869b7bcd1 Consumer flip: fee + wallet field->method accessors + codec-free signing
fee/complexity + static_calculator + wallet/chain/p signer/backend visitors
moved off removed struct fields onto method accessors (tx.Ins->tx.Inputs()
etc). sign() rewritten to the codec-free unsigned‖creds model (tx.Unsigned.
Bytes() + tx.Initialize()). txs/fee + wallet/chain/p/signer build clean.
2026-07-10 11:11:42 -07:00
zeekay bbba24bad6 txs pure-zap wire PROVEN: round-trip green (fix AddBytes element-count bug)
zap.ListBuilder.AddBytes counts BYTES not elements; fixed-stride lists were
storing byte-inflated counts -> stride clamp rejected them. Fixed every write
helper to store the real element count (len(entries)). Round-trip test now
GREEN across the hardest cases: multisig+stakeable outputs/inputs, the nested
ConvertNetworkToL1Validator (NodeID+BLS PoP+2 owners), SovereignL1Chain
manifest, and signed unsigned‖creds. go build ./vms/platformvm/txs = exit 0.

The P-chain tx wire is now struct-IS-wire, codec-free, and verified correct.
2026-07-10 10:57:47 -07:00
zeekay 34cb5c1684 txs package GREEN: pure zap struct-is-wire compiles (Convert + CreateSovereign done)
All 21 real P-chain tx types are now the zap buffer — no codec, no marshal/
unmarshal, no Manager, no version, decompounded, on luxfi/zap. ConvertNetworkToL1Tx
+ CreateSovereignL1Tx hand-written with a shared ConvertNetworkToL1Validator
nested encoder (fixed-stride records + shared NodeID/addr pools) and a
SovereignL1Chain encoder. go build ./vms/platformvm/txs/ = exit 0.

Next: round-trip correctness test, then the external consumer flip.
2026-07-10 10:53:14 -07:00
zeekay e288b67008 Decomplect P-chain tx set: rip Slash + P-chain CreateAsset/Operation, restore staker ifaces
- SlashValidatorTx ripped (unwired stub; Avalanche has no slashing; consensus
  only detects, never enforces). Type+executor+tests+Visitor surface removed.
- CreateAssetTx + OperationTx ripped from P-CHAIN (X-chain/AVM types; LP-0130:
  asset creation + fx ops are X-chain money-rail, not P staking-rail; no P
  producer). xvm/avm untouched.
- Staker interfaces (StakerTx/ValidatorTx/DelegatorTx/ScheduledStaker) restored
  on the 5 validator types via pure accessors + FxID-on-stake preserved.
- Remaining real complex types: ConvertNetworkToL1Tx + CreateSovereignL1Tx.
2026-07-10 10:36:35 -07:00
zeekay f0a00167e9 node v1.36.0 — Nova/Quasar export-frontier bridge; consensus v1.36.0
Wires the consensus EXPORT (Quasar, two-thirds-stake) frontier into the C-Chain VM so
the EVM finalized/safe tags and the warp cross-chain gate resolve to the Quasar tip.
Consensus v1.35.38 -> v1.36.0.
2026-07-10 09:44:14 -07:00
zeekay 33e005c869 fix register_l1 verifyBaseTx (return-form) 2026-07-10 09:18:19 -07:00
zeekay 949210730d Pure zap tx: 18 type files converted (parallel) + verifyBaseTx reconciled
Batches 1-3 (proposal + spending + validator-family) landed pure: struct is
the buffer, New*Tx builds, accessors read, SyntacticVerify via verifyBaseTx.
Remaining package-internal: 5 complex types (Convert/CreateSovereign/CreateAsset/
Operation/Slash) + staker interface methods + consumer flip.
2026-07-10 09:17:15 -07:00
zeekay 8d2fb750b6 Remove stale codec tests (codec deleted) 2026-07-10 09:08:31 -07:00
zeekay 1bc07cb1ca Pure zap tx: pure Tx (Parse=wrap+split, Sign=build) + delete reflection codec
tx.go: Tx holds Unsigned (zap-backed) + Creds; Parse wraps signed bytes and
splits unsigned/creds at the self-delimiting boundary; Sign builds unsigned‖creds;
no codec.Manager param anywhere. Deleted codec.go (V0/V1/V2 reflection Manager)
and codec_activation.go. WIP: consumer sites that passed txs.Codec / called the
old Parse(codec, bytes) flip next.
2026-07-10 09:08:15 -07:00
zeekay 1dede2e3d2 Pure zap tx: Parse kind-dispatch + native credential wire (no codec)
Parse wraps the buffer zero-copy and dispatches on the 1-byte kind. Signed =
unsigned ‖ creds (both self-delimiting), so unsigned is a byte-prefix of
signed. writeCredsBuf/parseCredsBuf encode credentials natively (shared 65B
sig-blob array). No Marshal/Unmarshal/Manager. WIP: references the 24 pure
type constructors (5 hand-written + 18 in parallel conversion + 1 template).
2026-07-10 09:07:13 -07:00
zeekay 636944a63a Pure zap tx: spendingTx embedded base (envelope surface for all types) 2026-07-10 09:02:58 -07:00
zeekayandHanzo Dev 9c2468671e chains: bridge the consensus EXPORT (Quasar) frontier into the VM; drop dead view-change braid (v1.36)
Wire the two-tier consensus export boundary through the node so the EVM `finalized`/`safe` tags and
the warp export gate track the ⅔-stake Quasar tip, never the reorgable Nova/accept tip:

- Set NetworkConfig.QuasarObserver to push each EXPORT (Quasar) frontier advance into the raw inner
  VM (SetLastQuasarFinalized) — the eth/warp backends live there, not on the proposervm wrapper.
  Interface-gated: only a VM exposing the export sink (the C-Chain EVM) participates.
- On boot, re-seed the consensus export frontier from the VM's DURABLE Quasar height
  (SyncQuasarFrontier) so GetQuasarTip/QuasarHeight do not regress on restart.

Also remove the node's dead references to the v1.36-deleted Tendermint braid (the consensus engine
dropped it in 174af3c31), which no longer compile against the v1.36 engine:
- the LUX_CONSENSUS_VIEW_CHANGE opt-in (params.ViewChange is gone — Nova is the sole decider),
- the quorumKindPrevote gossip kind + BroadcastPrevote + HandleIncomingPrevote routing (no prevotes;
  the ⅔ Quasar attestation rides the ordinary accept-vote gossip). Keep the braid dead.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 04:59:06 -07:00
zeekay 7750ca1829 gofmt spending.go 2026-07-10 01:43:56 -07:00
zeekayandHanzo Dev c526c0aaa4 Pure zap tx: reusable delta encoders (owner/auth/validator/signer/idlist)
Shared delta-field encoders every non-proposal tx composes on the spending
envelope: owner (fx.Owner), auth (*secp256k1fx.Input), inline Validator (44B)
+ Signer (145B: kind+BLS pubkey+PoP), id lists, extra spending lists. Built on
luxfi/zap. With spending.go, the full reusable foundation — type files are now
pure compositions.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:42:43 -07:00
zeekayandHanzo Dev 7354ce84b9 Pure zap tx: shared spending wire (envelope + Output/Input/owner/creds)
The envelope (NetworkID/BlockchainID/Outs/Ins/Memo) + multisig/stakeable
Output/Input entries + shared owner-address/sig-index arrays, built on
luxfi/zap generic primitives — no codec, no zap_native package. writeSpending/
setEnvelope build inside New*Tx; readEnvelope reads lazily. Polymorphism
(TransferOutput/LockOut, TransferInput/LockIn) handled in explode/assemble.
Foundation every non-proposal tx composes.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:40:27 -07:00
zeekayandHanzo Dev 8e7253a3c5 Pure zap tx: kind dispatch + AdvanceTimeTx template (struct IS the wire)
kind.go: 1-byte discriminator @ object offset 0 = the whole dispatch. No
codec, no version, no slot map. AdvanceTimeTx converted to the pure model:
holds *zap.Message, Time() is an offset read, NewAdvanceTimeTx builds once,
Bytes() returns the buffer. No marshal/unmarshal anywhere.

Template for the remaining 21 types. Package migrates atomically (codec.go +
all types + Parse/Sign together), so it compiles green again only when the
whole set + concentrated consumers (executor/builder/fee/api, ~63 New sites)
are converted. WIP.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:24:10 -07:00
zeekayandHanzo Dev 67ec31a344 Rip the marshal/unmarshal bridge — it was a codec by another name
ZAP has no serialization step. The bridge copied fields between plain txs.*
structs and the buffer, which is exactly the codec ZAP deletes. Removed.
The right way: tx type IS the zap buffer (accessors, Parse=wrap, Bytes=buffer),
no codec / manager / compat / version. Wire primitives stay in luxfi/zap.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:13:02 -07:00
zeekayandHanzo Dev 77389092c2 LP-023: bridge 5 more tx types (extra-list/bytes/idlist deltas)
Shared extra-out/in list helpers (Import/Export second spending set), id-list
+ BLS-PoP encoders. Bridges TransferChainOwnership, RegisterL1Validator,
Import, Export, CreateChain. Round-trip green (13/22 P-tx types native).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:03:37 -07:00
zeekayandHanzo Dev 13cca30a71 LP-023: bridge 5 delta tx types (owner/auth/scalar deltas)
Shared delta-encoders (owner=fx.Owner->OutputOwners, auth=verify.Verifiable->
secp256k1fx.Input, fixed-id helpers). Bridges IncreaseL1ValidatorBalance,
SetL1ValidatorWeight, DisableL1Validator, RemoveChainValidator, CreateNetwork
= spending envelope + fixed-offset delta fields. Round-trip green (8/22 P-tx
types now native: proposal x2 + BaseTx + these 5).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-10 01:00:42 -07:00
zeekayandHanzo Dev a93e5cdd9d chains: size-chunk GetContext responses so a behind validator resyncs under heavy load (1/3)
Benchmark-proven live mainnet bug (250-trader DEX load): a validator that falls behind cannot
resync the C-Chain. GetContext (the catch-up "context response", wire = Ancestors) bounded the
response ONLY by block COUNT (maxContextBlocks=256). Under heavy DEX load 256 blocks summed to
3.4-5.7 MB, exceeding the 2 MB peer message cap (the zstd compressor refuses uncompressed input
above constants.DefaultMaxMessageSize to prevent a decompression bomb), so msgCreator.Ancestors
FAILED to build and the behind validator received NOTHING — permanently stuck while the tip
advanced (luxd-3 stuck at 256 while tip went 293→300, looping empty-block builds).

Fix (piece 1/3 of the layered design — defense in depth): GetContext now ALSO bounds the
response by serialized SIZE. It stops adding blocks before the accumulated payload would exceed
byteBudget (cap − 128 KiB envelope margin), but ALWAYS includes at least one block so a behind
node makes progress every round; the requester re-requests the remaining gap (context fetch is
already a multi-round oldest-first fill). A single block that alone exceeds the budget is still
served (best-effort) so the walk never deadlocks — the forthcoming trust-tiered validator cap
(pieces 2/3) gives such a block the send headroom; a stranger's tight cap correctly rejects it.

Tests (chains/context_chunk_test.go): TestGetContext_ChunksBySize_FitsUnderCap (100×150 KiB
chain → 12 blocks / 1.84 MB, under budget, vs ~15 MB packed by count — fail-on-old);
TestGetContext_SingleOversizeBlock_StillServed (one oversize block still served, no deadlock).

Pieces 2/3 to follow: trust-tiered message cap (validator peers get headroom, strangers keep
2 MB) + confirm the inbound throttler/benchlist penalizes oversized-message senders.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 23:30:40 -07:00
zeekayandHanzo Dev ae3e3a45f5 LP-023: native spending envelope + full component converters
Shared spending envelope (NetworkID/BlockchainID/Outs/Ins/Memo) + polymorphic
converters bridging the txs struct graph to proto/zap_native primitives with
zero reflection: TransferOutput/stakeable.LockOut, TransferInput/stakeable.LockIn,
secp256k1fx.Credential. BaseTx (TxKindBaseFull) bridged; creds travel in the
separate creds buffer of the unsigned‖creds envelope.

Round-trip GREEN: 2-of-3 multisig + owner-locktime output, stakeable.LockOut,
stakeable.LockIn input, memo, AND signed secp256k1 credentials all survive
Marshal->Unmarshal with exact field equality; unsigned stays a byte-prefix of
signed. Every embedding tx type now composes this envelope + its delta fields.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 21:39:14 -07:00
zeekayandHanzo Dev 83c1a83765 v1.34.29: consensus v1.35.37 -> v1.35.38 (behind-node self-heal via cert-triggered ancestor catch-up)
Fixes the 'restart-recovery exhausted' mainnet killer: a slipped validator
logged 'cert REFUSED (behind; fetch and retry)' but NEVER fetched, because
HandleIncomingCert only triggered a catchup when the cert's OWN block was
untracked — never for a missing INTERMEDIATE ancestor. v1.35.38 (3c09ecb94)
surfaces the specific missing ancestor as a typed error and the cert handler
fires exactly one requestCatchup for it. The node-layer fetch machinery
(networkCatchup.RequestAncestors -> requestContext -> GetAncestors ->
AcceptCatchupBlock) was already fully wired — it was just never called on this
path. With --skip-bootstrap=true (which disables the beacon-quorum frontier
backstop) this cert-trigger was the ONLY self-heal path, so its absence was
fatal: a behind node couldn't rejoin -> effective 4/5 -> any flap -> stall.

Consensus-side only, no node code change. -race: launch-gate invariant PASS
(rejoin 2.75s, no fork); self-heal + typed-error tests PASS, no data races.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 21:28:06 -07:00
zeekayandHanzo Dev be18fce176 LP-023 keystone: native-ZAP tx Manager (drop-in, zero reflection)
Adds nativeManager implementing pcodecs.Manager by bridging txs structs to
proto/zap_native buffers — no reflection, no serialize-tag walk, no version
dispatch. Signed wire = unsigned_zap_buffer ‖ creds_zap_buffer (ZAP buffers
are self-delimiting), preserving tx.go's unsigned-is-prefix-of-signed
invariant with no tx.go change. AdvanceTimeTx + RewardValidatorTx bridged
and round-trip green (build->Marshal->Unmarshal field equality, byte-stable,
prefix invariant, non-ZAP reject). Added alongside the reflection Codec;
flip + reflection deletion lands once all registered types are bridged.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 16:53:16 -07:00
zeekayandHanzo Dev 74be89840c v1.34.28: consensus v1.35.36 -> v1.35.37 (F1 stale-alias prevote-lock rebase)
Third-layer mainnet finality fix. v1.34.27 (consensus v1.35.36) proved the
dynamic committee (alpha=4 n=5) and topology.go cert-receive canonical resolve
work live — consensus climbed past 1085755 to round-height 1085761 — but hit the
next layer: a stale-alias prevote-lock. viewForLocked seeds lockBlock from a
pre-canonical-fix durable committedSlot (an OUTER proposervm-wrapper id); a
round-0 lock on an outer alias makes prevoteTarget compare the stale outer id
against the inner-canonical winner by raw id, mismatch forever, no POL, freeze.

v1.35.37 (742696baf): stepViewChange rebases a stale-alias lock onto the inner
canonical winner IFF it resolves (via the same vmCanonicalResolver the cert
rebase uses) to exactly winnerCanon — a genuinely different inner (real fork) or
unresolvable lock is left fail-closed frozen, never merged. lockRound preserved,
2a-n>f untouched, alpha inner-precommits were always inner (CanonicalVoteMessage
binds inner, excludes outer). Full engine/chain green (356s, 0 fail); -race
clean; RED safety gate proves divergent inners still refused.

Roll note: luxd-4 first releases its lock (log 'vc stale-alias lock REBASED');
finality past 1085755 needs >=4 nodes on this build, so height climbs as 3->2->
1->0 come up. EVM stays v1.104.7 (head-pin).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 12:05:51 -07:00
zeekayandHanzo Dev 9a0800065f v1.34.27: consensus v1.35.33 -> v1.35.36 (EVM-accept unstick + dynamic committee + snowman purge)
Unsticks mainnet C-Chain finality. Root cause (consensus-layer, proven): under
pChainHeight=0 anyone-can-propose, each validator wraps the same inner block in
its own outer proposervm envelope; votes are canonical-keyed so an α-of-K cert
forms network-wide, but HandleIncomingCert did a strict envelope-id lookup — a
node holding a different alias of the same inner block missed it and requested
catchup instead of finalizing the local wrapper it held, so VM.Accept was never
called and the EVM head froze at 1085755 while consensus logged 'finalized
voters=4'. v1.35.34 (66438a23b) resolves the local wrapper by canonical id and
rebases the verified cert (outer ids unsigned; α votes verify unchanged), no
fork (per-height gate keys on canonical id, idempotent).

Also: dynamic committee 1→N proven (v1.35.35, effectiveCommittee sizes cert +
view-change from live validator count; n=1→1/1,2→2/2,3→3/3,4→3/4,5→4/5 — the
BFT-safe ⌊2n/3⌋+1); view-change safety gate realigned to the effective
committee (RED#2); snowman comment-purge (Quasar/Nova); dynamic committee logs.
Node commits: 4e71814e58 (proposervm→EVM Accept-cascade test, RED#1),
c13681108f (purge), a02611413e (logs). EVM stays v1.104.7 (head-pin). Full
engine/chain suite green under -race (369s, 0 fail/0 race); RED adversarial
suite proves scale-invariance 1→1M + RLP seam byte-exact on real mainnet state.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 11:11:58 -07:00
zeekayandHanzo Dev 4e71814e58 vms/proposervm: prove proposervm-finalize → inner-EVM Accept propagation (RED #1, choke #4)
The mainnet 1085755 freeze had consensus finalizing an outer proposervm block while the
inner EVM lastAccepted stayed frozen. The consensus engine's ledger advancing on VM.Accept
is proven in engine/chain; this proves the OTHER half at the NODE layer — that VM.Accept on
a proposervm wrapper cascades to the inner block's Accept:

  postForkBlock.Accept → acceptOuterBlk → acceptInnerBlk → Tree.Accept(innerBlk) →
  innerBlk.Accept  ⇒ inner VM lastAccepted advances

- TestAcceptCascade_InnerHeadAdvances_AtScale: 1000 heights through the REAL Accept path;
  the inner EVM head + proposervm head advance in lock-step at every height.
- TestAcceptCascade_SiblingStorm_WinnerAdvancesInnerOnce: five distinct outer envelopes wrap
  ONE inner block (the anyone-can-propose alias set); accepting the finalized wrapper advances
  the shared inner exactly once.

Confirms the propagation was sound, not a node-layer bug — the freeze was the consensus-layer
storm-alias resolution gap (fixed in consensus v1.35.34). The real luxfi/evm RLP-import→produce
→tip byte-exactness is proven separately in evm/core rlp_seam_red_test.go; composed, they cover
the full engine→proposervm→EVM Accept path.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 10:57:31 -07:00
zeekayandHanzo Dev c13681108f node: purge 'snowman' comment references — Quasar/Nova terminology (comment-only, no behavior change)
Removes the forbidden Avalanche term from code comments in chains/manager.go,
chains/quorum.go, and vms/proposervm/proposer/windower_determinism_test.go. Reworded to
preserve exact meaning; comments only, no identifier/behavior change.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 10:50:27 -07:00
zeekayandHanzo Dev a02611413e chains: view-change ENABLED log prints the PRESET, not the committee (#5 dynamic logs)
The "round-scoped view-change ENABLED for chain K=21 alpha=15" line read as if K=21/α=15
were the finality committee — misleading. It is the Snowman SAMPLE preset. The α-of-K
cert and the view-change POL/precommit are sized to the LIVE validator set at runtime
(effectiveCommittee/bftCommittee; 5 validators → K=5/α=4), and the engine already logs
the effective (K,α) on each committee re-clamp. Relabel the fields presetK/presetAlpha
and add a note pointing at the runtime committee-clamp log. Log-only; no behavior change.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 10:30:30 -07:00
zeekayandHanzo Dev 7720d00baa v1.34.26: consensus v1.35.29 -> v1.35.33 (finality committee sizing) + quorum ValidatorCount
Restores mainnet C-Chain finality. The prior stall: with 5 live validators but
MainnetParams K=21/alpha=15, BOTH finality gates (assembleCertLocked cert-alpha
AND view-change POL) required 15 distinct votes — impossible from 5 validators,
so the chain froze (safe, no fork). consensus v1.35.33 sizes both gates from the
live validator count via effectiveCommittee (alpha=4 for n=5), inheriting the
minBFTCommittee K=4/alpha=3 floor (1085013 self-finality guard preserved);
Snowman K=21 sample untouched. node chains/quorum.go adds
validatorStakeSource.ValidatorCount (height-indexed, deterministic). EVM stays
v1.104.7 (head-state pin). Test: 5-validator MainnetParams control freezes,
fix converges in 0.35s.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-09 08:59:42 -07:00
zeekayandHanzo Dev 439f2768e0 docs/postmortem: mark residual #1 (proposer-preference restart loop) FIXED
BuildBlock last-accepted fallback landed in 2dc15620e4 (ships v1.34.26).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-08 23:27:42 -07:00
zeekayandHanzo Dev 2dc15620e4 vms/proposervm: BuildBlock falls back to last-accepted on unheld preferred
Closes postmortem residual #1 (proposer-preference restart loop / mute-voter
wedge). Build-side companion to the defect #1 SetPreference validate-before-
assign hardening.

vm.preferred is only adopted after a successful getBlock, but a block fetchable
at preference time can later become unfetchable: an unaccepted sibling consensus
dropped, or a never-persisted outer block referenced after heavy sibling churn.
The old BuildBlock returned after the single getBlock(preferred) miss with
"failed to fetch preferred block", so every attempt failed in a tight loop and
the node's voter went mute (~170 err/s). Quasar cert-finality has no re-converge
poll, so the fleet never recovered on its own — the liveness wedge behind the
mainnet 1082879->1085755 window (heartbeat-pause + full-fleet-restart churn).

Fix: on an unfetchable preferred, build the child on last-accepted (always held:
committed state). The node keeps producing on a valid tip while the catch-up
path pulls the gap; a later SetPreference(held tip) re-advances the preference.
Only surface the original error when last-accepted is itself the unfetchable id.

Tests (hermetic, mirror vm_rejoin_wedge_test.go): spy inner VM asserts the fetch
sequence — BuildBlock consults last-accepted on an unheld preferred (old code
never did), and does not spuriously fetch when no distinct fallback exists.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-08 23:20:41 -07:00
zeekayandHanzo Dev 2bbe067f60 docs: postmortem — C-Chain accepted-head state GC eviction (mainnet freeze)
Failure mode, preconditions (pruning + state-history 32 + commit-interval 4096
+ idle), affected (evm ≤v1.104.6 / node v1.34.14-23) and fixed versions (evm
v1.104.7 / node v1.34.25), the head-state-pin invariant, the recovery recipe
(restart-as-recovery, healthy-peer PVC restore at replicas=0, repair-cchain
rewind), and the two residual restart-liveness follow-ups.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-08 06:10:11 -07:00
zeekayandHanzo Dev ae15850e1a v1.34.25: proper semver — EVM pin v1.104.7 (head-state-pin fix), drop stale replace-cascade comment
Same content as v1.34.24 (v1.104.3-headpin == v1.104.7, retagged per semver
policy: real monotonic patch versions, no suffix tags). go.mod has no replace
directives; removes the leftover comment from an already-completed cascade.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-07 21:39:48 -07:00
zeekayandHanzo Dev 092ed0459e v1.34.24: EVM v1.104.3-hotfix -> v1.104.3-headpin (durable idle-freeze fix)
Pins luxfi/evm v1.104.3-headpin: dedicated unbalanced GC pin on the accepted
head state root (transferred head-to-head in Accept + startup + direct
setters) so the head can never be evicted by the tipBuffer/Cap while idle —
the durable fix for the 1085200 'missing trie node at head' freeze. Also
carries vm v1.2.6 parity. Base: v1.34.22 (mainnet matcher lineage), no other
changes.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-07 20:33:36 -07:00
zeekayandHanzo Dev aa884628a0 v1.34.22: consensus v1.35.28 -> v1.35.29 (complete fix: self-finality safety + canonical cert aggregation + clone-resign inner->outer)
The COMPLETE mainnet reliability build. v1.35.29 adds FIX #1 (self-finality floor — a
transient bftCommittee count can never self-finalize without quorum; the 1085016 accept-
without-quorum safety hole) + FIX #3 (canonical vote aggregation — sibling wrappers of the
same inner block combine into ONE cert; the block-288 wrapper-split cert-termination stall)
+ the v4 clone-resign inner->outer fix (my v1.35.28 re-sign silently no-op'd on real wrapped
blocks). Matcher EVM v1.104.3-hotfix + Bug B UNCHANGED — execution-identical to mainnet.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-07 12:33:23 -07:00
zeekayandHanzo Dev 3d65b1c0c2 v1.34.22: MAINNET FINAL — matcher+Reference EVM (v1.104.3-hotfix) + consensus v1.35.28
Bundles BOTH reliability fixes on the mainnet-compatible line (the live test proved they
COMPOUND — Bug A catch-up alone can't reconcile the tip-loss Bug B causes on restart):
- Bug A (consensus v1.35.28, merged to consensus main): catch-up #1/#2/#3/#5 + vote-guard clone re-sign.
- Bug B (EVM v1.104.3-hotfix): head-state Reference one-liner — EXECUTION-IDENTICAL to mainnet
  (golden roots identical RED vs GREEN), matcher EVM (precompile v0.19.0), NO settle-only.
go.mod delta vs mainnet v1.34.14 = consensus-only; EVM = matcher+Reference (the only exec delta is
the proven-identical GC pin). STAGED for mainnet recovery — NOT rolled (gated on RED + canary).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-07 11:00:24 -07:00
zeekayandHanzo Dev a8971630b5 v1.34.21: bump consensus v1.35.24 -> v1.35.28 (#2 steer-guard + vote-guard clone fix)
MAINNET-COMPATIBLE node-only patch: the v1.34.14 line + catch-up/preference fixes + vote-
guard, EVM PLUGIN UNCHANGED (EVM_VERSION=v1.104.3, precompile v0.19.0, chains v1.7.2, vm
v1.2.5 — byte-identical to mainnet; NO settle-only, NO state-transition change). go.mod delta
vs v1.34.14 = consensus ONLY. Consensus v1.35.28 touches vote/cert LIVENESS only (engine is
byte-identical across the lines); it carries #2 (GetBlock-guarded build-tip steer) + the
vote-guard clone-artifact re-sign fallback. Cherry-picked #1/#3/#5 (proposervm validate-
before-assign, EmptyNodeID->real peers, have-block!=not-behind cert-fetch) on the prior commit.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-05 20:02:08 -07:00
zeekayandHanzo Dev 09ab817ee5 node: cure the lagging-validator rejoin wedge (proposervm #1 + peer-select #3)
The recurring freeze: a validator that fell behind could never rejoin, spamming
"sentTo=0" and "failed to fetch preferred block" until bounced. Two node-layer
defects, both BFT-safe (compared against ava avalanchego proposervm):

#1 proposervm.SetPreference (vms/proposervm/vm.go): assigned vm.preferred BEFORE
   fetching, so a build-tip the node doesn't hold POISONED vm.preferred forever
   (BuildBlock errors on every attempt; Quasar cert-finality has no re-converge
   poll). Now: getBlock (both post-fork + inner stores) FIRST, delegate to inner,
   adopt the preference only on success; on a total miss keep the last held tip
   and stay live. Identical to ava in every case its single-store invariant
   produces; only adds recovery for Lux's build-tip steering (never bricks).
   SetPreference is not an acceptance gate, so safety/agreement is untouched.

#3 peer selection (chains/manager.go): consensus signals "fetch a certified-but-
   untracked block" via ids.EmptyNodeID; the old code Add(EmptyNodeID)+Send, so
   GetAncestors went to ZERO peers and the cert-verified gap was never fetched.
   Now: when nodeID is Empty, sample real connected peers that track this chain's
   network (same selection pollFrontierOnce uses); the cert already gated the ask.

Adds vm_rejoin_wedge_test.go. (Defect #2 — the engine build-tip steering in
consensus/engine/chain — is the upstream root cause, tracked separately.)

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-05 19:57:53 -07:00
zeekayandHanzo Dev 08465c2f63 deps: consensus v1.35.26 -> v1.35.27 (comment-trim tip, logic-identical)
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-04 00:16:24 -07:00
zeekayandHanzo Dev ba14e55f2f chains: self-disarming stale-lock apply (apply:<floor>) — consensus v1.35.26
The migration env now requires the operator's observed floor target:
LUX_CONSENSUS_MIGRATE_STALE_LOCKS=apply:<decidedFloor> (1082879 for the
mainnet one-shot). A bare "apply" is refused loudly. Once the chain
recovers and the floor advances, a lingering env self-disarms (Skipped,
no write) instead of degrading into an every-boot prune of genuine
crash locks. Consensus v1.35.26 carries the paired red-review fixes:
self-disarm floor target, durable-finality cert gate, migrated-view
invalidation, height-bound resolver.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 23:53:53 -07:00
zeekayandHanzo Dev d84b5397ed chains: wire stale-lock migration + view-change gossip fail-fast; bump consensus v1.35.25
Consensus v1.35.25 adds the boot-time stale outer-wrapper lock migration that
unfreezes mainnet C-Chain 1082880 (the durable 3/2 split-lock the canonical=inner
roll left behind — locks stored by outer wrapper id, never re-canonicalized). This
wires it into chain creation:

- LUX_CONSENSUS_MIGRATE_STALE_LOCKS one-shot (K>1 view-change chains), run AFTER
  NewRuntime seeds the durable locks and BEFORE Start drives any view:
    "inspect" -> InspectLocks: prints the per-height trace table, mutates nothing
                 (the per-pod audit gate operators run before any write);
    "apply"   -> MigrateStaleLocks: idempotent, safety-gated canonicalize/prune
                 ABOVE the decided floor (finalized + vote-guard state <=floor and
                 the floor itself preserved verbatim); STOP -> fail-closed error.
  logStaleLockReport renders the auditable trace table in both modes.
- DEFENSIVE view-change hygiene: refuse to start a view-change chain whose gossiper
  is not a QuorumGossiper or that has no VoteSigner (prevotes/precommits would be
  emitted into the void -> silent finality stall) — fail loud, not frozen.

Offline cross-pod audit uses consensus cmd/voteguard (CGO-free vote-guard decoder).
Keeps the v1.34.14 canonical fix (Part A proposervm + Part B consensus) intact.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 22:51:08 -07:00
zeekayandHanzo Dev 98911842db docker: guard all mandatory chain-VM plugins, not just bridgevm
The chain-VM plugins are built with '|| echo WARN' (optional) but hard-COPY'd in
the runtime stage (a build miss -> cryptic COPY failure). Replace the single
bridgevm test-s check with a guard over every mandatory plugin so a missing/empty
binary fails loudly at the build stage with the real cause.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 21:26:08 -07:00
zeekayandHanzo Dev 0f185bd813 proposervm: implement canonicalCommitter — inner id is the finality canonical (Part A of 1082879 unfreeze)
The consensus engine's finality object is VotePosition.CanonicalID (the signed
accept vote binds it and EXCLUDES the outer envelope id). It reads it via a
structural canonicalCommitter assertion (engine/chain canonicalIDOf); until now
NO block type implemented it, so canonicalIDOf fell back to the OUTER proposervm
envelope id. On the stuck C-Chain the designated proposer re-wraps the SAME inner
block each slot -> 758 distinct outer ids over ONE inner block 25Q837Lw -> 758
distinct canonicals -> votes scatter -> no alpha-of-K cert -> frozen at 1082879.

postForkCommonComponents now returns the inner block's id as CanonicalID and the
inner parent's id as ParentCanonicalID, so every outer wrapper of one inner block
(and a forked parent) collapses to ONE consensus object. Enables the consensus
v1.35.23/24 canonical-representative determinism fix to actually engage; neither
part alone unfreezes mainnet.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 21:26:08 -07:00
zeekayandHanzo Dev a2f5c6c37b build: node canary v1.34.13 — consensus v1.35.24 (fix BLS double-register panic)
v1.34.12 crash-looped on boot:
  panic: threshold: scheme BLS already registered

consensus <= v1.35.22 blank-imported the OLD crypto/threshold/bls in
quasar.go while node imports the NEW threshold/scheme/bls; both register
BLS into the crypto/threshold registry -> panic. consensus v1.35.24
repoints quasar.go to threshold/scheme/bls.

Verified on the FULL node binary dep closure (go list -deps ./main, 1028
pkgs): luxfi/crypto/threshold/bls = 0, luxfi/threshold/scheme/bls = 1 —
exactly one BLS registration path, the panic cannot recur.

Pins: consensus v1.35.24, chains v1.7.2, evm v1.104.3.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 21:14:17 -07:00
zeekayandHanzo Dev b3e92ce979 build: node canary v1.34.12 — chains v1.7.2 (pulsar-path fix) + consensus v1.35.22
Supersedes the v1.34.11 image build, which failed in the Docker plugin
stage: chains v1.7.1 pulled consensus v1.25.35, whose polaris.go imports
the removed pulsar/ref/go/pkg/pulsar path — the quantumvm + mpcvm plugins
could not build and their hard COPY failed.

- chains v1.7.1 -> v1.7.2 (consensus bumped to v1.35.22 there; consistent
  pulsar graph; all 10 chain VM plugins verified building standalone).
- Dockerfile CHAINS_REF v1.7.1 -> v1.7.2.
- consensus v1.35.21 -> v1.35.22 (Pike-clean of the ProposalKey liveness
  fix; logic identical to v1.35.21).

Pins: consensus v1.35.22, chains v1.7.2, evm v1.104.3. Off origin/main,
no WIP.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 20:50:05 -07:00
zeekayandHanzo Dev 0428445890 build: node canary v1.34.11 — buildable image with decomplected consensus
IMAGE/BUILD change (packaging only — the consensus behavior change ships
separately as luxfi/consensus v1.35.21). Two edits make the deployable
node image build with the fixed consensus and the current chain plugins:

- consensus pin v1.35.20 -> v1.35.21 (ProposalKey decomplection, commit
  776a5119c: outer block IDs are transport aliases, proposal identity is
  ProposalKey{ParentID,Height} — proposervm envelope churn can no longer
  spawn own sibling candidates that split votes; the mainnet 1082880 fix).
- Dockerfile ARG CHAINS_REF v1.7.0 -> v1.7.1. v1.7.0 still shipped the
  pre-rename `thresholdvm` dir, so the Dockerfile's `cd /tmp/chains/mpcvm`
  plugin build produced nothing (swallowed by `|| echo WARN`) and the hard
  COPY of the mpcvm plugin (tGVBwRxp...) failed — the v1.34.10 Docker build
  break. v1.7.1 carries the mpcvm rename; the mpcvm plugin builds clean
  (verified standalone, 16MB) and all 10 chain plugins are present.

Pins verified for the canary image: consensus v1.35.21 (=776a5119c),
chains v1.7.1, evm v1.104.3, cevm v0.19.0, dex v1.5.15. Built off
origin/main — no WIP from any other worktree.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 19:38:25 -07:00
zeekayandHanzo Dev 86a342ae7b deps: bump to released graph — ids v1.3.1, constants v1.6.1, genesis v1.16.1, chains v1.7.1, consensus v1.35.20, threshold v1.12.1
Pins node to the published tags carrying this session's LP-0130 work:
ids/constants add M/F chain identifiers (drop T-Chain), genesis adds
M/FChainGenesis, chains has the mpcvm rename, consensus has the
mempool-churn pre-build gate + threshold scheme/bls repoint.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 19:08:20 -07:00
zeekay 52fd2cef35 Merge branch 'feat/thresholdvm-decomplect' into integrate/node-release-plus-mpcvm 2026-07-03 16:20:21 -07:00
zeekayandHanzo Dev 89bb0e718c build: pin EVM_VERSION v1.104.1 -> v1.104.3 (ZAP VM-state serialization fix)
v1.34.9 = v1.34.8 + the C-Chain EVM plugin rebuilt from evm v1.104.3
(= evm v1.104.1 + luxfi/vm v1.2.6). The only change is the plugin's
ZAP RPC server now serializes VM state calls, fixing the concurrent-map
crash (chain.State.verifiedBlocks) that killed the EVM subprocess under a
concurrent ParseBlock storm and froze Lux mainnet C-Chain at block 1082879.
Node binary, consensus, genesis, and all other plugins are unchanged;
block output is byte-identical, so v1.34.9 is consensus-compatible with the
running v1.34.8 fleet (verified on devnet/testnet before the mainnet roll).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 15:15:10 -07:00
zeekayandHanzo Dev 6c6b256418 deps: repoint BLS threshold scheme registration to luxfi/threshold/scheme/bls
The BLS Scheme impl moved from crypto/threshold/bls to
luxfi/threshold/scheme/bls (all threshold impls now live in one module;
the interface stays in crypto/threshold). One-line blank-import path
change; no behavior change.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 14:14:39 -07:00
zeekayandHanzo Dev c7e0eef6f6 vms/types/fee: quantumvm moved to NoUserTxPolicy (LP-0130 §6)
Doc-comment + LLM.md updated to reflect chains/quantumvm feegate flip.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 12:32:41 -07:00
zeekayandHanzo Dev b4720c9f57 node v1.34.8: consensus v1.35.16 -> v1.35.17 (VC liveness) + proposervm slot-snap
Pairs the proposervm stale-parent slot-snap churn-fix (f840336167) with consensus
v1.35.17 (view-change abandonment must never silence a height). Together they close the
distributed VC liveness stall that keeps mainnet C-Chain safe-but-paused: slot-snap kills
the stale-parent rebuild sibling explosion at the source (one stable candidate per slot),
and v1.35.17 keeps the round machinery driving the height to convergence instead of going
silent after rePoll's 8-attempt cap. Liveness-only; decided-floor / no-double-finalize
safety invariant untouched. Gated on the live idle-inclusive devnet re-storm + RED before
any testnet/mainnet roll.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 11:57:47 -07:00
zeekayandHanzo Dev f840336167 fix(proposervm): slot-snap child timestamp — kill stale-parent rebuild churn (VC liveness)
Off a stale parent (idle past the proposer window → anyone-can-propose), buildChild
was stamping a raw wall-clock timestamp (Time().Truncate(1s)), so every rebuild of the
same inner block produced a DISTINCT envelope id. That is an unbounded, ever-growing
sibling set at one height: the round-scoped view-change can never gather α aligned
prevotes on a single candidate (no proof-of-lock forms) and finality stalls fleet-wide
(the distributed liveness stall).

Snap the child timestamp DOWN to the parent-anchored proposer-window grid
(parentTimestamp + slot*WindowDuration, slot = TimeToSlot(parent, now)) so all rebuilds
WITHIN one slot are byte-identical → one stable candidate the view-change converges on.

Safe by construction: TimeToSlot(parent, snapped) == slot == TimeToSlot(parent, now), so
the block's slot — hence ExpectedProposer's proposer-window / signed-unsigned verdict and
the derived epoch — is unchanged. Only slot>0 snapped, so a fresh in-window child keeps
its exact timestamp (zero live-chain change), and a snapped time is strictly > parent
(monotonic) and <= now (not advanced). Liveness-only; no safety surface touched.

Extracted as slotSnappedChildTimestamp + unit-proven (idempotence, slot-invariance,
monotonicity). Full proposervm suite green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 10:52:51 -07:00
zeekayandHanzo Dev d4323da799 node: rename thresholdvm → mpcvm; split M/F registries (LP-0130)
- vms/thresholdvm/ → vms/mpcvm/ (dir + inner files + package decl).
- node/vms.go optional-VM registry: drop ThresholdVMID row, add
  MPCVMID and FHEVMID rows (matching the new split).
- genesis/builder/registry.go: T-Chain entry → M-Chain (MPCVMID) +
  F-Chain (FHEVMID); registry_test.go parity assertions updated.
- genesis/builder/builder.go: TChainAliases → MChainAliases +
  FChainAliases; ThresholdVMID switch case split to MPCVMID / FHEVMID;
  optIn chain slice uses config.MChainGenesis + config.FChainGenesis
  (T-Chain slot retired).
- LLM.md: point at LP-0130 as canonical topology + fee spec; correct
  the quantumvm posture to service-only per LP-0130 §6 (Q-Chain has
  no user-payable blockspace).

Build + vet clean on chains/mpcvm/... + node/{vms/mpcvm,genesis,node}/...

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-03 01:23:03 -07:00
zeekayandHanzo Dev 97d9745ea9 fix(platformvm): guard validator-set cache + decouple TrackedChains snapshot (multi-validator data races)
Two concurrent-map races on the consensus-adjacent validator-set path,
both surfaced by the 5-node storm re-gate, both RED-verified fixed:

1. m.caches concurrent map write (getValidatorSetCache check-then-insert,
   reached via proposervm windower.ExpectedProposer across chains during
   buildBlocksLocked): guarded with a dedicated cachesLock sync.Mutex
   (atomic check-create-store; plain Mutex, no lost-update).
2. TrackedChains concurrent map read/write: getValidatorSetCache read the
   network's runtime-mutable cfg.TrackedChains lock-free (the admin
   setTrackedChains RPC .Add's it under peersLock). Decoupled via an
   immutable startup snapshot (set.Of(cfg.TrackedChains.List()...) in
   NewManager); the false 'immutable after startup' comment is corrected.
   Snapshot is correct (caching is pure-perf; cache.Empty recomputes),
   and the construction clone provably happens-before any writer (P-chain
   init is synchronous, admin API serves only post-node.Dispatch()).

Gates multi-validator restart-storm crash-freedom (before validator #2).
-race regression tests reproduce both races pre-fix, clean post-fix
(-count=5). Tracked follow-up (same class, network's live alias, admin-API
default-off, NOT this path): config/internal.go:120-121 + health.go:30 —
fix before ever enabling the admin API.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 23:03:25 -07:00
zeekay 6e7f0b3d7e Merge tag 'v1.34.5' into blue/bootstrap-finality-split
node v1.34.5: EVM plugin v1.104.1 (0x9999 genesis-injection fix), forward-integrated on v1.34.4
2026-07-02 17:50:31 -07:00
zeekayandHanzo Dev 6a87c69010 node: signed-checkpoint bootstrap anchor (INVARIANT 4) + consensus v1.35.16
Harden the bootstrap checkpoint — the one path that bypasses the beacon quorum —
into a cryptographically SIGNED weak-subjectivity anchor.

- Checkpoint carries an authority Signature over a domain-separated canonical
  (id,height); CheckpointVerifier (injected, backed by a proven primitive —
  Ed25519/BLS, never custom crypto) authenticates it. The policy stays crypto-free
  exactly like AncestrySource/heightOf.
- AcceptsFrontier trusts a pinned checkpoint ONLY when the configured authority
  signed that exact (id,height). Present-but-unsigned, signed-by-a-non-authority,
  signature-transplanted-to-another-(id,height), and no-verifier-wired all FAIL
  CLOSED. A compromised flag cannot inject a false sync anchor without also forging
  the authority's signature. It is a cryptographic vouch, NEVER a ⅔-live-stake tally.
- No production path pins a checkpoint yet (opt-in operator escape hatch), so the
  invariant is enforced for when it is activated; nothing to wire now.

Folds consensus v1.35.16 (single ⅔ formula + leaf-lock doctrine) into the node.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 17:49:54 -07:00
zeekayandHanzo Dev 3db595a637 node v1.34.5: bump C-Chain EVM plugin pin v1.104.0 -> v1.104.1
Picks up the DEX 0x9999 genesis-injection fix (evm v1.104.1): 0x9999's
EXTCODESIZE marker is no longer baked into pre-2025 genesis state, so the
archived Lux mainnet (0x3f4fa2a0), Lux testnet (0x1c5fe377) and Zoo mainnet
(0x7c548af4) RLPs re-import byte-identical. 0x9999 activates at its protocol
timestamp (2025-12-25) during replay. rpcChainVM protocol 42 unchanged.

Forward-integrated on v1.34.4 (bootstrap/finality split, consensus v1.35.15) —
v1.34.4 was already taken and still pinned evm v1.104.0. This is a minimal
patch on top: EVM pin only.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 17:49:22 -07:00
zeekayandHanzo Dev 15ff32fbdc node: bootstrap/finality type split (FinalityQuorum vs BootstrapTrust) + consensus v1.35.15
Make the bootstrap-trust vs live-finality boundary a HARD API split so neither
can impersonate the other — the mass-recovery deadlock was bootstrap reusing the
finality quorum (>2/3 of CURRENT stake), which is unsatisfiable when the
recovery targets are themselves down validators.

- FinalityQuorum.HasFinality(weight,total): the live rule, strict >2/3 of current
  stake (unchanged). Renamed from ConsensusQuorum to the reviewer's exact spec.
- BootstrapTrust.AcceptsFrontier(replies): selects a weak-subjective sync anchor
  from AUTHENTICATED CONFIGURED beacons — a response FLOOR (MinResponses) plus a
  supermajority over the RESPONDERS, NEVER over the whole set. Distinct type, so
  bootstrap cannot call the finality predicate (INVARIANT 3: acceptance != finality;
  the node re-executes every synced block before re-entering consensus).
- Contrast proven: 3-of-5 bootstrap ACCEPTS a frontier, yet HasFinality(3/5) is
  false and STAYS false after sync — bootstrap is not a finality bypass.

Folds consensus v1.35.15 (the global unlock-before-call-out invariant + the
n=1..10 quorum acceptance matrix) into the node binary.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 16:49:47 -07:00
zeekayandHanzo Dev ec5cf94145 node: v1.34.3 — decomplected single-validator DECIDE fix + evm accept-empty pin
consensus v1.35.13 -> v1.35.14 (decomplect: removed the selfVoter shortcut that
self-deadlocked on t.mu.RLock — the live n=1 freeze; K==1 now finalizes solely via the
inline finalizer, one path). EVM_VERSION v1.103.0 -> v1.104.0 (= v1.103.0 + accept-empty:
a consensus-finalized empty block Accepts, so VM.Accept can never fail-closed on an empty
first block — the stale-evm-pin gap). Unblocks single-validator Zoo mainnet/testnet +
Hanzo (all frozen at block 0).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 15:29:50 -07:00
zeekayandHanzo Dev 5e44cd67dc node: bump consensus v1.35.11 -> v1.35.13 — LIVE single-validator DECIDE deadlock fix (v1.34.2)
The v1.34.1 n=1 fix passed unit tests but the LIVE single-validator chains still
froze (Zoo mainnet/testnet, Hanzo, Pars, all block-0). Root cause (neo's live repro,
confirmed through the full runtime path): a reentrant-RWMutex self-deadlock — the
single-node selfVoter called engine.ReceiveVote synchronously while buildBlocksLocked
held t.mu, so ReceiveVote's t.mu.RLock deadlocked on the same goroutine (node hangs at
'single-node mode: self-voting', inline finalize never runs, block never decides).

consensus v1.35.13 dispatches the selfVoter's ReceiveVote on a fresh goroutine (no
reentrant lock) — the block now DECIDES through the real NewRuntime path (proven by
TestBlue_SingleValidator_DecidesThroughFullRuntimePath: hangs pre-fix, passes post-fix).
The bump also carries the n=1 synthesize fix (v1.35.11) and the dormant 1→N
decentralization guard (v1.35.12). EVM_VERSION unchanged (v1.103.0) — single-validator
blocks are tx-driven / non-empty.

Gates Zoo mainnet + Zoo testnet + Hanzo (all single-validator).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 15:01:00 -07:00
zeekayandHanzo Dev 1b6487e0b7 node: bump consensus v1.35.8 -> v1.35.11 (n=1 single-validator DECIDE stall fix) — v1.34.1
Prod-line (v1.34.x finality-admission) bump carrying the consensus fix for the
single-validator (K=1) DECIDE stall that wedged all three sovereign
single-validator chains (Zoo 200200, Hanzo 36963, Pars 494949): a K==1 block now
finalizes even when its self-vote is unverifiable against a not-yet-resolvable
single-validator set (synthesized 1-of-1 cert; per-height FinalizeBranch gate is
the safety). n>1 C-Chains (mainnet/testnet) unaffected — they never hit the K()==1
branch.

The bump also carries the (dormant) bounded phantom-floor reconcile
(v1.35.9/v1.35.10) — additive engine methods that this prod-line node never calls
(manager.go on main has no ReconcilePhantomFloor wiring), so behavior is unchanged.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 13:55:06 -07:00
Hanzo Dev 67272bc7c9 chore: OSS attribution — avalanchego (BSD-3-Clause) + go-ethereum (LGPL-3.0) NOTICE + retained notices 2026-07-02 12:51:01 -07:00
zeekay 2e98019144 Merge branch 'deploy/dex-v114-integer-wire' 2026-07-02 11:03:04 -07:00
zeekayandHanzo Dev 6424671eb7 deploy: bump DEX stack to fork-safe integer wire (chains v1.7.0, evm v1.103.0, precompile v0.19.0)
Deploys the launch-blocker fixes: F1-F5 cross-arch execRoot fork (exact-integer
ZAP wire, no float64 in consensus) + F9 infinite-money unbacked-deposit (authority
gate, fail-closed). Rebuilds the bundled DexVM + EVM plugins on the reconciled
dep chain (dex v1.14.0 lx→dex fold). Cross-arch execRoot proven identical.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 11:03:04 -07:00
zeekay 29c623880c go.mod: bump consensus v1.35.7 -> v1.35.8 (fail-closed finalize->VM-accept, fix 2b diagnostic) 2026-07-02 09:23:31 -07:00
zeekayandHanzo Dev ab4201301e chains: opt-in round-scoped view-change enablement (LUX_CONSENSUS_VIEW_CHANGE) + consensus v1.35.7
Adds the per-deployment opt-in flag: when LUX_CONSENSUS_VIEW_CHANGE=true and K>1, sets
consensusParams.ViewChange=true so devnet/testnet activate the round-scoped view-change
without a mainnet default (mainnet owner-gated). The engine fail-secure HALTS if the committee
fails 2a-n>f, so enabling never weakens safety. Bumps consensus v1.35.6->v1.35.7 (removes dead
safeConfig dup). This is what makes v1.32.13's prevote transport actually activatable.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 08:20:09 -07:00
zeekay 29a263eb14 merge: view-change prevote gossip + consensus v1.35.6 (v1.32.13) 2026-07-02 08:07:52 -07:00
zeekay c3f037c737 go.mod: bump consensus v1.35.5 -> v1.35.6 (round-scoped view-change) 2026-07-02 08:07:52 -07:00
zeekayandHanzo Dev d1400a4c65 chains: wire round-scoped view-change PREVOTE gossip (node side of v1.32.13)
Adds the p2p transport for the consensus round-scoped view-change:
- quorumKindPrevote (kind 3) in the quorum-gossip envelope + decodeQuorumGossip accepts it.
- blockHandler.Gossip demux routes kind 3 -> engine.HandleIncomingPrevote(payload) (the engine
  decodes+verifies height/round/canonical/sig from the payload, domain LUX/chain/prevote/v1,
  and tallies toward a POL).
- networkGossiper.BroadcastPrevote(chainID,networkID,height,round,canonical,voteBytes) frames
  kind 3 + broadcasts to ALL validators, mirroring BroadcastVote.

Type-checks against the round-scoped consensus (local replace, chains pkg builds clean).
Requires: consensus tag (with ViewChange + HandleIncomingPrevote + BroadcastPrevote) -> node
go.mod bump -> ARC build -> node v1.32.13 (also carries v1.32.12 evm v1.101.3 descent fix +
isBootstrapped truth fix). ViewChange is opt-in per network (default off); enable on devnet/
testnet only, NO mainnet.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 08:00:31 -07:00
zeekayandHanzo Dev bd996c41b1 node v1.32.12: bake evm v1.101.3 (stateless ParseBlock — fixes C-Chain bootstrap descent stall)
Bootstrap descent no longer stalls on ancestry blocks ahead of the accepted height:
evm v1.101.3 decomplects BlockGasCost from ParseBlock (parse decodes; Verify enforces).
Carries the v1.32.11 isBootstrapped-truth + ancestry-fetch hardening.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 03:23:28 -07:00
zeekayandHanzo Dev feef2bcb1e diag: bake evm v1.101.3-diag (PARSEBLOCK_DIAG logging) for descent root-cause
Temporary diagnostic node build. To be reverted after the evm ParseBlock fix.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 03:07:08 -07:00
zeekay 99c690f307 Revert "BSDIAG: instrument C-Chain bootstrap ancestry send+serve (temporary, for root-cause)"
This reverts commit 5921a24dd9.
2026-07-02 03:00:24 -07:00
zeekay 00fa804fc0 Revert "BSDIAG2: parse served batch (wantInBatch + parsedIDs/heights) + served block ids"
This reverts commit 65efff0628.
2026-07-02 03:00:24 -07:00
zeekayandHanzo Dev 65efff0628 BSDIAG2: parse served batch (wantInBatch + parsedIDs/heights) + served block ids
Definitive probe: does the descent's served ancestry batch contain the requested
tip (want), and what are the parsed ids vs the serve-side ids — pins whether the
tip survives the Bytes()->ParseBlock round-trip (proposervm wrapping).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 02:32:36 -07:00
zeekayandHanzo Dev 5921a24dd9 BSDIAG: instrument C-Chain bootstrap ancestry send+serve (temporary, for root-cause)
INFO-level logging on both sides of the descent so we can isolate send-vs-serve:
- SEND: sampleAncestorBeacons (weights/connected/ahead/sample), Ancestors SENT
  (sampleSize/sentTo), GOT batch / TIMEOUT / msgBuild-fail.
- SERVE: GetContext RECV, walk-miss (which block + i), SERVED 0 (firstFound),
  SERVING (containers).
- ROUTING: deliverBootstrapAncestors (dataLen/decodedBlocks/chFound/delivered).

To be reverted once the root cause is pinned. Devnet diagnostic build only.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 02:12:18 -07:00
zeekayandHanzo Dev 7397da43ae docs(bootstrap): note the two latent invariants red flagged (X-Chain DAG-sync gate; monotonic bootstrapped state)
Documentation-only; no behavior change (v1.32.11 image unaffected). Red review of
the v1.32.11 diff: 0 critical/high/medium, recommendation SHIP.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 00:15:02 -07:00
zeekayandHanzo Dev a63a18bf71 node v1.32.11: C-Chain restart/recovery serving hardening (isBootstrapped truth + wipe-path ancestry)
Two node/bootstrap-layer fixes for a clean rolling validator upgrade. Consensus
engine untouched (v1.35.5 boot-seed from v1.32.10 carried forward).

[HIGH — correctness] info.isBootstrapped(C) tracks REAL state, not premature true.
  manager.IsBootstrapped(id) returned true the instant a chain merely EXISTED in
  m.chains (set right after createChain launched the async, possibly-stalling
  bootstrap goroutine) — so a C-Chain stalled at genesis (head 0x0) reported
  info.isBootstrapped(C)=true, masking the stall from any wait-for-healthy gate.
  Now keys on the SAME sb.Bootstrapped signal the readiness health check uses
  (m.Nets.IsChainBootstrapped), set only after runInitialSync reaches the named
  frontier and the VM goes to normal operation (head advanced, eth-RPC live).
  GetChains().Bootstrapped fixed identically. New per-chain query on nets.Net +
  chains.Nets (nil-safe). Regression test TestIsBootstrappedTracksRealConvergence.

[MEDIUM — robustness] WIPE-path GetAncestors fetch hardened for ≥2 peers at genesis.
  Applying the proven avalanchego contract (studied in snowman/bootstrap +
  getter): (a) Ancestors buffers the whole sample and SKIPS empty batches,
  returning the first NON-EMPTY one — a size-1 channel let a fast empty reply from
  a genesis peer win the race and starve a peer that actually held the ancestry;
  (b) sampleAncestorBeacons PREFERS beacons the frontier round found genuinely
  ahead (they hold the ancestry) — ava's PeerTracker "ask a prover" bias sourced
  from the replies we already have, no separate tracker. Tests:
  TestNodeBootstrap_WipePath_MixedGenesisPeers_ObtainsAncestry,
  TestSampleAncestorBeacons_PrefersAheadBeacons.

Build: main+chains+nets+service/info compile CGO_ENABLED=0 (ARC/Dockerfile path);
full chains+nets suites green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-02 00:05:36 -07:00
zeekayandHanzo Dev 363a5a8591 bump(consensus): v1.35.2 -> v1.35.5 — boot-seed decidedFloor from vm.LastAccepted (clean in-place v1->v2 upgrade)
consensus v1.35.5 is a patch-only fix (go.mod byte-identical to v1.35.2..v1.35.4): the
decided-height sign-gate floor is now seeded DIRECTLY from vm.LastAccepted at engine Start
(before signing) and in SyncState, so a node upgrading IN PLACE from a legacy v1 vote-guard
file (floor 0) has a real decided floor from the first instant of boot — closing the
mainnet v1->v2 upgrade window where the floor was 0 until the first post-upgrade finalize.
Sign-gate-only (never enters byHeight/ledger.Height; PART-A intact; only refuses more).

Supersedes the un-rolled node v1.32.9 (consensus v1.35.4) for the mainnet-first roll. No
node code change (fix is internal to the consensus engine). go mod tidy drops an orphaned
luxfi/bft indirect (pre-existing). Full node builds clean on linux/amd64 (cgo off).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-01 23:58:52 -07:00
zeekayandHanzo Dev 9eb4b64f4e node recovery (testnet): v1.32.7 tree (evm v1.101.2 MaterializeState) + consensus v1.35.2
RECOVERY BUILD for the frozen testnet C-Chain. Carries BOTH fresh-multi-node fixes:
  - STATE halt (missing trie node) — evm v1.101.2 MaterializeState, from the v1.32.7 tree.
  - CONSENSUS double-finalization + liveness stall — consensus v1.35.2 (epoch-blind
    vote-once + per-height vote convergence + RED-round hardening).

Deliberately based on v1.32.7, NOT node v1.33.0: v1.33.0 is a mis-numbered DISPROVEN
build (older commit, MISSING the evm v1.101.2 MaterializeState commit, pins the buggy
consensus v1.33.3) — basing on it would regress the state-halt fix. This branch also
EXCLUDES node-main's /ext->/v1 route migration to keep the incident recovery minimal
and avoid breaking /ext/bc/C/rpc tooling mid-recovery.

Recommended tag: node v1.33.1 (forward past the v1.33.0 revert-magnet so the image
tooling cannot revert testnet to the disproven build). NOT tagged here — cutting the
tag may auto-trigger a live deploy; that is a live-incident action requiring explicit
owner authorization.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-01 15:11:45 -07:00
zeekayandHanzo Dev 51a304804c chore: migrate luxd HTTP routes /ext -> /v1
Drop the Avalanche-heritage /ext prefix; /v1 is the single canonical route
surface (one way, no backward compat). The node's baseURL is the source of
truth; clients, SDKs, CLI, indexer, maker, genesis, netrunner, and the
k8s/compose/gateway/explorer configs are updated to match.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-01 11:40:13 -07:00
zeekayandHanzo Dev d254dccc8a node v1.32.7: bake evm v1.101.2 (on-demand pruned-state rebuild — real fix for fresh-multi-node halt)
evm v1.101.1's accept-path guard was confirmed a no-op live (halt reproduced at
block 8 on v1.32.6). v1.101.2 rebuilds pruned parent state on demand at BuildBlock,
which is where the post-accept state loss manifests. Isolated EVM_VERSION bump on
the v1.32.4 baseline.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-01 10:25:49 -07:00
zeekay d7507db8ff Merge branch 'fix/accept-materialize-root' 2026-07-01 06:31:54 -07:00
zeekayandHanzo Dev fc20584db0 node v1.32.6: bake evm v1.101.1 (accept-path state-materialization backstop)
Isolated bump of EVM_VERSION v1.99.52 -> v1.101.1 on the v1.32.4 baseline.
v1.101.1 core/plugin code == v1.99.52 (verified byte-identical) + the accept-path
equivocation-commit-gap backstop (BlockChain.Accept re-materializes an accepted
block's state if !HasState, on the parent state). Fixes the fresh-genesis testnet/
devnet block-2 'missing trie node' halt. CHAINS_REF/DEX_REF unchanged. Devnet test
build; RED-gated before mainnet.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-01 06:27:09 -07:00
zeekayandHanzo Dev c6cbee935a fix(chains): wire durable vote-once guard; bump consensus v1.33.3 (Red HIGH-1)
Pick up consensus v1.33.3 (durable + epoch-keyed + funnel-pruned per-height
vote-once guard) and ACTIVATE its durability in production: buildChain now opens a
per-chain VoteGuardStore (chain.OpenVoteGuard at <chainDataDir>/vote-guard) for
every K>1 signing chain and passes it to the engine via NetworkConfig.VoteGuard.

This closes Red's HIGH-1 on the wire that matters: a signing validator's
(height,epoch)→canonical bindings are fsync'd before it votes and reloaded on
startup, so a crash between casting a vote and finalizing the height cannot forget
the binding and let the restarted node sign a conflicting sibling — the cross-node
fork with zero Byzantine intent under a rolling upgrade / eviction / OOM. The store
is opened at the node boundary so the fail-closed-on-corrupt decision (a signer
refusing to start with equivocation memory it cannot trust) lives here, not in the
engine. luxd builds against pinned v1.33.3.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 23:21:17 -07:00
zeekay 951eda0d44 Merge tag 'v1.32.4'
consensus v1.33.2: per-height vote-once (closes cross-node fork) + proposer liveness
2026-06-30 22:06:29 -07:00
zeekay 72233ed59e bump(consensus): v1.33.1 -> v1.33.2 (per-height vote-once — closes the cross-node fork)
consensus v1.33.2 closes the CRITICAL cross-node fork Red found in v1.33.1: the
finality layer now enforces per-height vote-once (an honest validator signs at most
one canonical per height, both signing sites through reserveSlotForSign), so two
conflicting siblings can no longer both gather a >=2/3-stake cert. All 3 Red fork
repros GREEN, emergent probe 15x no fork, engine/chain suite green under -race.
luxd builds clean. Ships with the proposervm liveness fix + luxd-3 ZAP block-id guard.
2026-06-30 22:06:01 -07:00
zeekayandHanzo Dev d291ea44c6 build(evm-plugin): bump baked C-Chain EVM plugin v1.99.51 -> v1.99.52 (bug 2 idle-builder wake)
node v1.32.3 = v1.32.2 + the idle-builder bounded-wake fix, delivered as the
baked C-Chain EVM plugin. The node Dockerfile git-clones luxfi/evm@EVM_VERSION
and builds ./plugin into the image; v1.99.52 = v1.99.51 + startPendingTxPoll
(500ms mempool re-poll so a tx submitted to an idle demand-driven chain wakes
the builder within a bounded window — closes the lost-wakeup/subscribe-gap).
Patch bump only (x.x.x+1 on the pinned v1.99.x line, NOT a jump to v1.100.x);
cherry-picked clean onto v1.99.51 and RED-cleared. Deterministic: wake timing
only, block contents unchanged.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 21:33:19 -07:00
zeekayandHanzo Dev bb43458e8c bump(consensus): v1.32.1 -> v1.33.1 (proposer-liveness re-solicit + multi-node suite; QCv2 canonical finality)
Adopts consensus v1.33.1: the build-path re-solicit of an undecided own
proposal (avalanche repoll alignment) plus the v1.33.0 QCv2 canonical-
commitment finality + incident-1082814 verify-before-slash. Pulls transitive
ids v1.3.0, warp v1.24.0, pulsar v1.9.0, threshold v1.12.0. luxd builds
(GOWORK=off, pinned deps). No node code changes required — consensus public
API (NewRuntime/NetworkConfig/Runtime) is stable across the bump.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 20:49:04 -07:00
zeekayandHanzo Dev 49e6958664 fix(proposervm): lock verifiedBlocks + Tree maps; fail loud+actionable on a behind height-index
Two pre-existing reliability bugs surfaced by the v1.32.1 roll (both present
identically in v1.31.5 — NOT caused by QCv2), plus a snapshot-inconsistency
diagnostic.

BUG 1 (HIGH) — concurrent-map crash in getPostForkBlock. The consensus engine
drives the proposervm from multiple handler goroutines concurrently (a
PullQuery/Put verifying a block WRITES verifiedBlocks via verifyAndRecordInnerBlk
while a Qbit handler READS it via GetBlock -> getPostForkBlock; the retry loop in
PullQuery even documents "allow concurrent Put to complete"). The verifiedBlocks
map was read/written with no lock -> the Go runtime aborts with "fatal error:
concurrent map read and map write" (exit 2) under heavy verify load. Fix: a
dedicated verifiedBlocksLock (RWMutex) behind three accessors (cachedVerifiedBlock
/ recordVerifiedBlock / forgetVerifiedBlock) at ALL seven sites; the sibling
Tree.nodes map (touched on the same Verify/Accept paths) gets its own RWMutex,
with Accept restructured to make its inner-VM Accept/Reject callouts OUTSIDE the
lock. Both are leaf locks, never nested, never held across a callout — the lock
graph is a strict DAG (vm.lock > verifiedBlocksLock; tree.lock disjoint), so
deadlock-free. innerBlkCache (lru.SizedCache) is already internally locked.
Regression: TestVerifiedBlocksConcurrentAccess + TestTreeConcurrentAccess hammer
readers vs writers under -race; both FAIL on the pre-fix code with the exact
production signatures ("concurrent map read and map write" / "concurrent map
writes") and pass after.

BUG 3 — a proposervm height index BELOW the inner VM tip (the devnet-C
"index 7 < inner 8" from a snapshot restored inconsistently across the proposervm
and EVM databases) had a cryptic fatal ("should never be lower"). It is now a
LOUD, ACTIONABLE fatal with a recovery runbook. It is deliberately NOT
"self-healed" by dropping the finality pointer: after DeleteLastAccepted,
proposervm.LastAccepted() falls back to the INNER-namespace id, whose ParentID is
contiguity-incompatible with the network's OUTER wrappers — that permanently
wedges bootstrap (first-block anchor), catch-up (parent==tip guard) and live
Verify (parent lookup) at the inner tip (blocks at height <= tip are skipped, so
the missing wrapper is never rebuilt): a SILENT wedge strictly worse than the
loud stop. The only correct remedy is operator action (restore a consistent
snapshot or full resync), which the error now states. The reconciliation decision
is decomplected into a pure classifyHeightRepair(pro, inner) -> heightRelation,
regression-locked by TestClassifyHeightRepair so a revert to a silent reset fails
the test; the fork height is read lazily (only the ahead/rollback path needs it),
so the match and behind paths gain no new failure mode.

RED-reviewed: CHANGE 1 (locks) cleared (deadlock-free DAG, fail-on-old proven);
the original bug-3 silent-reset was caught as a wedge and reworked to this
fail-loud form. Full vms/proposervm/... suite green under -race.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 20:45:01 -07:00
zeekayandHanzo Dev a2514ec5cc fix(proposervm): lock verifiedBlocks + Tree maps; self-heal a behind height-index instead of bricking
Two pre-existing reliability bugs surfaced by the v1.32.1 roll (both present
identically in v1.31.5 — NOT caused by QCv2), plus a snapshot-recovery self-heal.

BUG 1 (HIGH) — concurrent-map crash in getPostForkBlock. The consensus engine
drives the proposervm from multiple handler goroutines concurrently (a
PullQuery/Put verifying a block WRITES verifiedBlocks via verifyAndRecordInnerBlk
while a Qbit handler READS it via GetBlock -> getPostForkBlock); the retry loop
in PullQuery even documents the concurrency ("allow concurrent Put to complete").
The verifiedBlocks map was read/written with no lock -> the Go runtime aborts
with "fatal error: concurrent map read and map write" (exit 2) under heavy
verify load. Fix: a dedicated verifiedBlocksLock (RWMutex) behind three accessors
(cachedVerifiedBlock / recordVerifiedBlock / forgetVerifiedBlock) at ALL seven
sites; the sibling Tree.nodes map (touched on the same Verify/Accept paths) gets
its own RWMutex, with Accept restructured to make its inner-VM Accept/Reject
callouts OUTSIDE the lock. Both are leaf locks, never nested, never held across a
callout — provably deadlock-free. innerBlkCache (lru.SizedCache) is already
internally locked. Regression: TestVerifiedBlocksConcurrentAccess +
TestTreeConcurrentAccess hammer readers vs writers under -race; both FAIL on the
pre-fix code with the exact production signatures ("concurrent map read and map
write" / "concurrent map writes") and pass after.

BUG 3 — a proposervm height index BELOW the inner VM tip (the devnet-C
"index 7 < inner 8" from a partially-restored snapshot) was a FATAL init error
that bricked the whole chain ("error creating required chain" -> exit 1). The
proposervm cannot fabricate the missing wrapper blocks, so it now drops the stale
finality pointer and re-bootstraps from peers via the catch-up transport (the
SAME recovery the forkHeight-rollback branch already uses) instead of crashing.
The reconciliation decision is decomplected into a PURE planHeightRepair
(proHeight, innerHeight, forkHeight) -> repairAction, regression-locked by
TestPlanHeightRepair so a revert to fatal fails the test.

Full vms/proposervm/... suite green under -race.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 20:23:56 -07:00
zeekayandHanzo Dev 89b11c9396 test(proposervm): cross-node determinism + slot-rotation + out-of-turn proposer
Asserts the safety/liveness boundary that makes the consensus down/wedged/forked-
proposer fix BFT-safe — the proposer-schedule half of avalanchego Snowman++
(windower.go is byte-identical to ava):

  - DETERMINISM (safety): two independent windower instances over the same set, and
    the same inputs across 64 seeds, compute byte-identical ExpectedProposer for
    every (chainID, height, slot). Honest nodes cannot disagree on the eligible
    proposer, so an out-of-turn signed block is rejected by EVERY honest node and an
    attacker cannot flood competing accepted blocks / fork.
  - OUT-OF-TURN REJECTION (safety): exactly ONE validator is in-turn per slot; every
    other is out-of-turn (the windower half of verifyPostDurangoBlockDelay's
    errUnexpectedProposer) — no early/out-of-turn acceptance hole.
  - SLOT ROTATION (liveness): consecutive slots designate different proposers, so a
    down/wedged/forked designated proposer is routed around within a few slots — a
    faulty leader cannot halt the chain.

Tests the EXISTING windower (no production change); proves the boundary the
consensus liveness fix relies on holds over the input space.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 16:46:07 -07:00
zeekayandHanzo Dev 5aa1d0b643 ci(docker): build multi-arch node image (linux/amd64,linux/arm64)
arm64 validators (spark GB10, arm64 nodes generally) could not pull
ghcr.io/luxfi/node — the Docker workflow built linux/amd64 only. The
Dockerfile already cross-compiles via TARGETARCH with CGO_ENABLED=0, so
buildx produces arm64 on the amd64 lux-build pool without QEMU-emulating
the compile. Adds a workflow_dispatch `tag` input to (re)build an existing
release tag (e.g. v1.32.1) as a multi-arch manifest.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 16:05:53 -07:00
zeekayandHanzo Dev 4d46b3c6c7 bump(consensus): v1.31.1 -> v1.32.1 (QCv2 canonical-commitment finality + RED-round H1 verify-before-slash)
Pins the incident-1082814 durable fix. consensus v1.32.1 supersedes both the
down-leader line (v1.31.1, what main pinned) and the QCv2-core-only line
(v1.31.2, what node v1.31.5 shipped). Finality keys on the canonical inner
execution commitment; equivocation evidence requires a VERIFIED alpha-of-K cert
over a DIFFERENT canonical, removing the false-slash fatal-exit crash that
destabilized mainnet under DEX-fill load on v1.31.5.

Adds indirect github.com/luxfi/bft v0.1.5 (cert verify gate). Full node module
compiles clean; consensus proof suite 377 subtests + race + vet + fuzz green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 15:22:09 -07:00
zeekay 6c9005627d Merge branch 'fix/consensus-v1.31.1-downleader' 2026-06-30 13:38:32 -07:00
zeekayandHanzo Dev eac47cbf93 bump: latest dealerless PQ (corona v0.10.3, pulsar v1.8.0)
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-30 13:28:50 -07:00
zeekay cb9030ecf6 bump(consensus): v1.31.0 -> v1.31.1 (down-leader sibling convergence)
consensus v1.31.1 fixes the down-leader HALT: when a slot-leader proposer is
down, validators built competing siblings at the same height, the alpha-of-K
votes split, no cert assembled, and the chain stalled (devnet stuck at height
36 with 4/5 healthy). The fix converges all validators onto one deterministic
build tip (PreferredBuildTip) so blocks finalize through a validator going down.

Transitive: corona v0.8.0->v0.10.2, dkg v0.3.0->v0.3.5, pulsar v1.2.0->v1.7.1
(the dealerless PQ line consensus v1.31.1 is built against). luxd builds clean.
2026-06-29 01:12:33 -07:00
z 1743f2c0b6 docs(brand): add hero banner 2026-06-28 20:36:21 -07:00
z 327756e8d5 chore(brand): dynamic hero banner 2026-06-28 20:36:20 -07:00
zeekay e11b29dafa fix(go.sum): refresh luxfi/pq v1.0.3 content hash (upstream tag force-moved)
luxfi/pq's v1.0.3 git tag was force-moved upstream after this go.sum was
recorded. go.sum kept the originally-published zip hash
h1:pFlQm1+5FuKTDUh2y/23bXWkN4I2Rc5iuxJypwDFFMs= (still served by
proxy.golang.org / sum.golang.org). The release builds fetch luxfi modules
direct from GitHub (GOPRIVATE=github.com/luxfi/* => GONOPROXY) on a cold
cache, bypassing the immutable proxy; the moved tag now hashes to
h1:ksw1dmfTR0dqqNMRS7BjGcprCO2Fhc+3Iiq2/NMuONw=, so the goreleaser
darwin_amd64 build (.github/workflows/build.yml) failed strict
-mod=readonly verification:

    verifying github.com/luxfi/pq@v1.0.3: checksum mismatch
        downloaded: h1:ksw1dmfTR0dqqNMRS7BjGcprCO2Fhc+3Iiq2/NMuONw=
        go.sum:     h1:pFlQm1+5FuKTDUh2y/23bXWkN4I2Rc5iuxJypwDFFMs=
    SECURITY ERROR

=> v* tags produced no macOS artifacts. (The "downloading luxfi/log" line in
the CI log was a concurrent-download red herring; pq is the culprit.) The
Docker image escapes this because the Dockerfile strips first-party go.sum
lines and rebuilds them under -mod=mod.

Refresh only pq's content hash to the current tag. Version stays v1.0.3 and
the /go.mod hash is unchanged (pq's deps did not change). Keeps the release
build strict and consistent with the Docker image.

Verified: fresh direct fetch verifies readonly against the new go.sum
(exit 0); the exact goreleaser target
(CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags='-s -w'
./main) compiles to a Mach-O x86_64 binary; cold clean-cache darwin
`go mod download` no longer raises SECURITY ERROR.
2026-06-28 17:07:40 -07:00
zeekay 9d358d1ec2 build(consensus): bump v1.30.0 -> v1.31.0 (pure-fold finality decomplect + RED perf/defensive fixes)
consensus v1.31.0 on top of the v1.30.0 sibling-tolerant finality already shipped in
node v1.31.1: the finality decomplect (pure Ledger,Cert,DAG->Ledger',Plan fold;
markFinalized unwriteable), topological.go preference layer, the RED HIGH-1 clone()
O(window) perf fix (was O(chain height) — 86.7ms/100MB per finalize at 10^6 heights),
and RED LOW-1/LOW-2 hardening. Backward-compatible: node compiles with zero API drift;
proposervm + chains green. No transitive crypto-dep bumps.
2026-06-28 15:57:57 -07:00
zeekay 507f2ee08c build(consensus): bump v1.29.1 -> v1.30.0 (sibling-tolerant finality)
Consume the sibling-tolerant finality fix: cert-driven FinalizeBranch reorg
replaces the per-height admission gate that deadlocked the proposervm
pre-fork->post-fork transition (devnet stuck at finalized height 1 while
blocks produced past 10). Base = v1.31.0 (= v1.30.101 union quasar PQ-finality
+ frontier self-vote) + the repliedCovers eclipse-defense cherry-pick.

Verified: go build ./... clean; chains + proposervm tests green against v1.30.0.
2026-06-28 14:09:07 -07:00
zeekay 774dd82c63 fix(bootstrap): self-vote caught-up requires every connected beacon replied
RED CRITICAL: the frontier caught-up shortcut gated on CONNECTIVITY
(fullyConnectedBeacons) while the tally keyed on REPLIES (CaughtUp over
withSelfVote). The two diverge for a beacon that is CONNECTED but SILENT
(TCP up, frontier reply delayed/withheld) — a capability strictly weaker
than a full eclipse, and one that occurs naturally when an ahead beacon
replays state on a mass co-restart. Such a beacon counts as fully
connected yet is absent from the tally, so self's heavy weight backfills
the naming floor and the node goes live at a forged STALE height.

Add repliedCovers() set-containment guard: every connected beacon must
have answered THIS frontier round before the self-vote shortcut can fire.
A silent ahead-beacon now blocks caught-up -> node fails safe to
FrontierConnecting (keeps waiting); a genuine fresh net (every connected
beacon answers genesis) still completes.

Keep RED's zz_red_probe_test.go as a permanent regression guard:
connected-but-silent ahead beacon -> status=FrontierConnecting (was
FrontierCaughtUp). Fresh-net + equal-stake self-vote tests still pass.
2026-06-28 14:07:38 -07:00
zeekay c00172bda7 Merge v1.30.101 into quasar PQ-finality (StakingTLSSigner post-fork signing + fresh-chain init tolerance) for v1.31.0
# Conflicts:
#	go.mod
#	go.sum
2026-06-28 12:47:07 -07:00
zeekay 2a08357dcb docs(consensus/LLM.md): record PQ-finality verify-gate state + activation order
Supersede the stale Quasar-wrapper notes with the actual consensus/quasar verify
gate: dormant-by-default safety contract, files/tests, and the owner-gated
remaining-work map (producer+encoder export, gossip ingest, per-epoch validator
provider, config wiring, grace-window runbook) + mainnet activation order.
2026-06-28 07:50:58 -07:00
zeekay e15ac35c94 harden(consensus/quasar): close adversarial-review findings on the verify gate
Red adversarial review of the PQ-finality gate. Dormant default verified a true
no-op; these harden the ACTIVATED path before any forward-dated activation:

H1 (HIGH) — bindCheck now binds cert.Epoch == cp.Epoch (and cert.Round). The
  gate resolves verification keys from the cert's epoch; an unbound epoch let a
  cert signed under a DIFFERENT validator-set era (e.g. a compromised RETIRED
  committee key) certify the current block, nullifying KeyEra rotation as a
  blast-radius bound. Honest certs match (producer signs Subject.Epoch==cp.Epoch).
  + wrong-epoch / wrong-round anti-replay test cases.

M2 (MED) — activation is now HEIGHT-ONLY, deterministic. Removed time.Now() (and
  the ActivationConfig.Time field) from the accept path: wall-clock gating split
  finalization across validators with skewed clocks (some halting on a missing
  cert, others finalizing without one). A height is consensus-agreed; timestamp
  forward-dating is expressed by choosing the activation height.

L5 (LOW) — an activated gate with a nil store/validator provider now fails
  closed with ErrGateMisconfigured instead of panicking in the accept hook (a
  panic would halt the chain uncontrollably). Off the dormant path. + test.

M3 (doc) — made the StateRoot=0 transitive-through-BlockHash contract explicit in
  bindCheck (non-zero cert StateRoot already rejected + tested) so the producer
  follow-on cannot silently ship state-committing certs that self-halt.

proposervm: verifyQuasarFinality short-circuits on nil gate BEFORE building the
  Checkpoint, so the default path makes zero block-accessor calls.

13 gate tests green under -race; full proposervm suite green; go build ./... exit 0.
Deferred to follow-ons (gate is dormant + unwired in production): M4 cert-
unavailability halt runbook + grace window, L6 MemCertStore eviction (no ingest
caller yet), proposervm Accept-path integration test, positive valid-cert test
(needs consensus to export cert encoders).
2026-06-28 07:49:17 -07:00
zeekay 463d2533af feat(consensus/quasar): wire Quasar PQ-finality VERIFY path (dormant, forward-dated)
Node-side integration of luxfi/consensus v1.29.0 Quasar compact-cert finality.
luxd finalizes on classical Snow every block; at CHECKPOINTS a sampled committee
QuasarCert over the finalized digest is VERIFIED. This wires the verify half as
an OPTIONAL, FORWARD-DATED, DORMANT-BY-DEFAULT check in the block-accept path.

consensus/quasar (new package):
  - Gate.VerifyAccepted: the accept-path safety boundary. nil gate / zero
    activation / below-activation-height / non-checkpoint => no-op (classical
    Snow unchanged). Post-activation at a checkpoint => REQUIRE a valid cert
    bound to the finalized block; fail closed (missing/mismatch/invalid -> error).
  - ActivationConfig: forward-dated dormant switch (Height==0 => never; optional
    wall-clock Time gate). The safety contract: this branch changes NOTHING about
    live finality until the owner sets a real activation height.
  - bindCheck: anti-replay binding (cert chain/height/block/state == finalized).
  - policyStore: default posture HYBRID_PQ = Beam(BLS) ^ Pulsar (Pulsar verify
    ~140us < BLS, cert ~27KB); STRICT_DUAL_PQ / POLARIS configurable. The cert
    can never select its own (weaker) policy (I1/I2 enforced by consensus).
  - ValidatorSet/MemCertStore: the per-leg key + cert-lookup seams (HYBRID_PQ
    BLS+Pulsar keys now; Corona/Magnetar/weighted-set + per-epoch resolution are
    the activation-wiring follow-on).
  - Producer (scaffolding): the committee-sign service contract + MaybeProduce
    request site, sharing ONE checkpoint cadence with verify. nil producer =
    verify-only (the default). Concrete pulsard signer is the follow-on; it needs
    consensus to export the (currently package-private) cert/payload ENCODERS.

proposervm: post_fork_block.Accept calls vm.verifyQuasarFinality(b) BEFORE the
accept commits, so an un-PQ-certified checkpoint halts without persisting. nil
gate (default) => unchanged classical accept. SetQuasarGate installs it.

Tests: 12 gate tests green (dormant no-op, nil-safe, below-activation, time-gate,
non-checkpoint, missing-fails-closed, 4x mismatch/anti-replay, real-verifier
delegation, validator-set-unavailable, producer nil-safety/dormant/active). Full
proposervm suite green; go build ./... exit 0.
2026-06-28 07:32:48 -07:00
zeekay d70a407a3a fix(chains): fresh-net frontier-naming — self-vote under full connectivity (consume consensus v1.29.1 FrontierCaughtUp)
On a FRESH net a validator whose own stake makes the PEER-ONLY responder weight
fall below the stake-majority NAMING floor (a heavy validator, a small beacon set
like the P-chain's CustomBeacons, or skewed stake: peers = total-self, so
peers < total/2+1 ⟺ self > total/2-1) could NEVER name a frontier even with the
WHOLE validator set connected — FrontierTip returned FrontierConnecting forever
("bootstrap waiting for beacon connectivity before naming the frontier") and the
node hung, blocking uniform block production.

The node is itself a beacon and knows its OWN accepted tip with certainty. Add the
SELF-VOTE: in the below-floor case, when the node has reached its ENTIRE beacon set
(fullyConnectedBeacons — no eclipse can hide an ahead-tip) and that full set PLUS
itself unanimously hold a tip it has ALREADY ACCEPTED with nobody ahead, return the
new chainbootstrap.FrontierCaughtUp -> the loop completes at the node's own tip.

Safety (proven by tests): self is counted ONLY under FULL connectivity, so an
eclipse suppressing any beacon breaks full-set and falls back to the
partition-capture floor (fail safe) — self can never tip a PARTIAL view into a
false caught-up (stale-go-live guard holds). AcceptsFrontier still tallies PEERS
ONLY, so a behind node's ahead-frontier is named undiluted and it still syncs; a
peer above our height defeats CaughtUp. self only vouches for its OWN accepted tip
so C1 (forged-frontier naming) is untouched.

- selfNodeID threaded from m.NodeID into the blockHandler.
- helpers fullyConnectedBeacons + withSelfVote.
- bump luxfi/consensus v1.29.0 -> v1.29.1 (FrontierCaughtUp status).

Tests: TestNodeBootstrap_FreshNet_SelfVoteUnderFullConnectivity_CaughtUp,
TestNodeBootstrap_SelfVote_PeerAheadDefeatsCaughtUp,
TestNodeBootstrap_SelfVote_PartialConnectivityFailsSafe. Full chains suite green.
2026-06-28 07:28:57 -07:00
zeekay 11123aa2f8 build(consensus): bump luxfi/consensus v1.25.36 -> v1.29.0 for Quasar PQ-finality certs
Pulls the typed compact-cert envelope + VerifyConsensusCert + QuasarEvidencePolicy
table (protocol/quasar) needed to wire PQ-finality verification into the block
accept path. Transitive lane deps resolved to consensus v1.29.0's tested minimums:
  corona  v0.7.9  -> v0.8.0
  pulsar  v1.1.5  -> v1.2.0
  threshold v1.9.9 -> v1.10.2
  dkg     (new)   -> v0.3.0
  magnetar v1.2.3 (unchanged)

Zero API drift: luxd's existing consensus consumers (engine/chain, core, engine/dag,
networking, config) compile unchanged against v1.29.0. The producer-side committee
signer (pulsard) will require pulsar v1.7.1's no-reconstruct hyperball signer; that
bump lands with the producer service, not this verify-path wiring.

go build ./... exit 0; consensus/protocol/quasar compiles against resolved deps.
2026-06-28 07:16:03 -07:00
zeekay 1c304183cb node: wire StakingTLSSigner so proposervm can sign post-fork blocks
The node declared n.StakingTLSSigner (passed to the chain manager → proposervm
StakingLeafSigner) but NEVER assigned it, so proposervm received a nil signer.
The pre-fork→post-fork transition block (height 1) is unsigned and built fine,
but the first SIGNED post-fork block (height 2) called block.Build → key.Sign on
a nil key → SIGSEGV nil-pointer panic → node crash (exit 2), flushing the
mempool and dropping the DEX deploy. Assign n.StakingTLSSigner from the staking
TLS cert's private key (already extracted at this point for the TLS config),
mirroring avalanchego node.go. Now the elected proposer signs post-fork blocks.

Block production + 5-node α-of-K finality verified converging on devnet
(identical block-1 hash across all 5) once this lands.
2026-06-28 06:28:21 -07:00
zeekay 8a0d435c23 proposervm: complete RED's 3 criticals + fresh-chain init tolerance
Addresses RED's DO-NOT-SHIP review of the proposervm re-wrap. Four fixes:

CRITICAL-2 (consensus v1.25.36→v1.25.37): the equivocation handler downgraded
  Logger.Crit→Error. The per-height guard already rejects the second conflicting
  cert (safety preserved); Crit→os.Exit converted a handled safety event into a
  fleet-wide liveness kill (every honest node that observed the gossiped cert
  exited) AND made the slashing-evidence loop dead code. Now: log Error, reject,
  record DoubleVote evidence, keep running.

CRITICAL-1 (pre_fork_block.go + vm.go): window the pre-fork→post-fork TRANSITION
  block. It must stay unsigned (verifyPostForkChild rejects a signed transition),
  but WHO builds it is now gated by the windower's ExpectedProposer — only the
  elected leader builds the unsigned height-1/N+1 block; non-leaders drop it and
  adopt the gossiped block (timeToBuildPreForkTransitionLocked windows the wait).
  Without this, every validator built its own transition block stamped with its
  local wall-clock second → divergent height-1 blocks → fork at chain start.

CRITICAL-3 (manager.go + config.go + vm.go): thread the resolved networkID into
  proposervm.Config and the windower (newWindower) instead of hardcoding
  PrimaryNetworkID. On a sovereign L1 (Zoo/Hanzo/Pars, networkID==chainID) the
  hardcoded primary set was empty → ErrAnyoneCanPropose → single-proposer
  silently did not hold. Resolved ONCE in manager.go so windower and cert side
  share the identical set.

Fresh-chain init tolerance (vm.go): repairAcceptedChainByHeight returns nil when
  the inner last-accepted block is not retrievable (brand/feature VMs Q/A/G/K
  whose genesis references an empty parent → GetBlock 'not found' even though the
  ID is not ids.Empty). Nothing to repair; previously crashed the whole node at
  init. Complements the ids.Empty guard.

proposervm tests pass.
2026-06-28 05:42:38 -07:00
zeekay c754864f6b proposervm: complete single-proposer internals — pre-fork transition windowing (CRITICAL-1) + cert-aligned NetworkID (CRITICAL-3)
Completes the multi-validator block-production fix on top of the v1.30.96
proposervm wrap. Three subtle correctness gaps that left single-proposer
NOT actually holding:

CRITICAL-1 (pre-fork→post-fork transition): the FIRST post-fork block (which a
fresh-genesis chain like devnet hits immediately) was forwarded to the inner VM
and built by EVERY validator unconditionally — forking the chain at its very
start. timeToBuildPreForkTransitionLocked now windows the transition block the
same way post-fork blocks are windowed (MinDelayForProposer), so a non-leader
waits its slot and adopts the elected leader's gossiped transition block; a down
leader can't stall (the eligible set widens as the slot advances).

CRITICAL-3 (validator-set ID): the windower hardcoded PrimaryNetworkID, so a
sovereign L1 (Zoo/Hanzo/Pars, validators under their own networkID==chainID) got
an EMPTY set → ErrAnyoneCanPropose → equivocation exactly like the unfixed
C-Chain, AND diverged from the cert's set. config.NetworkID (resolved once in
manager.go: primary for native, else the L1's chainID, fallback to primary if
empty) now binds the windower to the SAME set the cert uses. Zero value
(ids.Empty) IS PrimaryNetworkID, so native chains are byte-identical. newWindower
encapsulates this.

proposervm pkg + full luxd binary build clean; go vet clean (chains, proposervm).
2026-06-28 05:39:14 -07:00
zeekay 668d1facf6 proposervm: don't crash on a fresh inner chain (empty last-accepted)
Deploying the proposervm re-wrap crash-looped the whole node on a fresh
re-genesis: repairAcceptedChainByHeight read the inner VM's last-accepted as
ids.Empty (some Lux VMs report the empty ID before their first acceptance) and
called GetBlock(ids.Empty) → 'failed to get block 111...LpoYY: not found' →
VM initialization failed → 'error creating required chain' → node exit(1).

A fresh inner chain has no accepted chain to roll the proposervm height index
back against, so there is nothing to repair. Guard the empty-ID case with an
early return, mirroring the existing 'nothing to repair' returns (and the
empty-handling setLastAcceptedMetadata already does for the same fresh case).
ava never hits this because its inner VMs return a valid genesis last-accepted;
Lux's brand/feature VMs can return empty.
2026-06-28 01:26:38 -07:00
zeekay 9b1b040aac chains: complete proposervm wrap — define shouldWrapInProposerVM + test
The prior commit (9d9d2a8785) captured only manager.go, which CALLS
shouldWrapInProposerVM but did not include its definition, so HEAD did not
compile (chains/manager.go:1205: undefined: shouldWrapInProposerVM). This adds:

  - chains/quorum.go: shouldWrapInProposerVM(k, chainID, innerIsDAGNative) —
    the single pure policy gate (K>1 AND not P-Chain AND not DAG-native) that
    decides whether a linear chain.ChainVM is wrapped in proposervm for
    single-proposer-per-height block production.
  - chains/proposervm_wrap_test.go: table tests pinning the gate (C-Chain
    devnet/mainnet wrapped; P-Chain, X-Chain, K==1 excluded) and that the K
    flows from selectConsensusParams.
  - chains/manager.go: gofmt import ordering.

Restores a green build. No push, no tag.
2026-06-28 01:07:16 -07:00
zeekay 9d9d2a8785 chains: restore proposervm wrap for multi-validator single-proposer-per-height
The deeper half of the block-production fix. Lux had commented out the
proposervm wrapper and hand-rolled a WaitForEvent→toEngine bridge that dropped
the single-proposer invariant: every validator's engine called BuildBlock
UNCONDITIONALLY at every height off a slightly-different mempool, so two nodes
could each gather an α-of-K cert for DIFFERENT blocks at the same height →
reportCertEquivocation → Logger.Crit → crash (and the DEX-tx nondeterminism
wedge). That, together with the evm builder-ready race (evm v1.99.51), is why
every multi-validator C-Chain froze.

Re-wrap multi-validator linear chains in proposervm so block production follows
the Snowman++ proposer schedule — exactly ONE validator builds height H, the
rest wait and vote. proposervm.WaitForEvent only returns PendingTxs inside THIS
node's proposer window, collapsing the race at its source.

Gated (all three): K>1 (single-proposer only matters for a quorum), not the
P-Chain (its height-indexed validators.State is published during its own
createChain, after the snapshot used here), not DAG-native (X-Chain's Linearize
bridge doesn't compose with proposervm's pull/window model). Engine, WaitForEvent
bridge, block handler, SetState, and HTTP registration all route through the
wrapped engineVM; unwrapped chains keep the original path byte-for-byte.

chains pkg builds + go vet clean. Validated end-to-end on devnet (5 validators).
2026-06-28 01:03:05 -07:00
zeekay a49c32cc2f deps+image: evm v1.99.51 + chains v1.4.8 — fix network-wide block-production stall
P0: all Lux C-Chains (mainnet/testnet/devnet) froze at their imported frontier —
no live block produced. Root cause in the EVM plugin block-build trigger:
1. WaitForEvent blocked forever when the node forwarder called it before the
   builder initialized (nil-builder race) — so PendingTxs never reached the
   engine and no block ever built.
2. A block built faster than parent.Time+TargetBlockRate has a higher required
   fee; a small-tip/legacy tx can't cover it, verifyBlockFee rejects it, stall.

evm v1.99.51 fixes both (builderReady select + target-rate pacing, with a
nextBuildTime pure helper + regression test). chains v1.4.8 rebuilds the
C-Chain VM plugin against it.

Dockerfile: EVM_VERSION v1.99.50->v1.99.51, chains pin + CHAINS_REF
v1.4.7->v1.4.8. node go.mod chains v1.4.7->v1.4.8 (+ tidy for the new
genesis/security transitive). luxd binary builds clean.
2026-06-28 00:58:24 -07:00
zeekay 69107d5c15 node v1.30.95 — Dockerfile EVM_VERSION v1.99.49→v1.99.50
Carries evm v1.99.50: paces block building to the target block rate, fixing
(1) small transactions never mining because the rapid-block gas cost exceeds
their tips, and (2) the equivocation crash-loop from validators racing to
finalize conflicting blocks at the same height. Together with v1.99.49
(WaitForEvent builder-ready race), a fresh multi-validator EVM chain now builds
and finalizes blocks under full BFT consensus and accepts ordinary traffic.
2026-06-28 00:13:59 -07:00
zeekay f353d6f1ee node v1.30.94 — Dockerfile EVM_VERSION v1.99.48→v1.99.49
Carries evm v1.99.49: fixes the fresh-start block-production stall where the
C-Chain EVM plugin's WaitForEvent blocks forever when the node-side notification
bridge calls it before SetState(NormalOp) initializes the block builder. Without
this, a freshly-booted (or restarted) EVM chain accepts txs into the mempool but
never builds a block. See luxfi/evm#fix/waitforevent-builder-ready-race.
2026-06-27 23:33:16 -07:00
zeekay 5bd5dbf154 deps+image: chains v1.4.7 + evm v1.99.48 + precompile v0.16.0 — enable-everything plugin
Dockerfile plugin pins bumped:
  - EVM_VERSION v1.99.47 -> v1.99.48 (C-Chain plugin mgj786…)
  - chains pin (EVM stage) + CHAINS_REF v1.3.22 -> v1.4.7 (bridge/zk/threshold/
    graph/identity/key/oracle/quantum/relay VM plugins)
node go.mod: chains v1.4.6 -> v1.4.7, precompile -> v0.16.0.

Delivers the enable-everything builder precompile surface (wallet curves
ed25519/sr25519/secp256r1 + standard ecrecover/p256/sha256/ripemd160/blake2f/
bls12381/kzg; fflonk fail-closed), accel CPU/GPU byte-identity, DEX 0x9999
price-floor big.Rat + stableswap token/gas bound + graph determinism, and warp
consolidated to ONE luxfi/warp helper across the chains VMs. graphvm
genesis-last-accepted fix carried forward in chains v1.4.7. luxd binary builds
green against the new deps.
2026-06-27 21:56:20 -07:00
zeekay c7dd2fc5a9 node v1.30.92 — Dockerfile EVM_VERSION v1.99.40→v1.99.47 so the 0x9999 EVM PLUGIN carries the DEX fix
The C-Chain EVM plugin (mgj786NP, where 0x9999 lives) is built from EVM_VERSION,
NOT node's go.mod. v1.30.91 bumped the binary deps but the plugin still built from
the stale v1.99.40 (precompile v0.12.0, no DEX fix). Bump EVM_VERSION→v1.99.47
(precompile v0.15.0 active-only DEX money path) + chains v1.3.21→v1.3.22 to match.
Now the deployed plugin actually carries the real-fill DEX code.
2026-06-27 19:08:29 -07:00
zeekay 503ed38b1f node v1.30.91 — DEX 0x9999 real-fill money path (precompile v0.15.0 active-only native-ZAP, evm v1.99.47); dormant conduit + dead bespoke DEX-BLS bundle retired; consensus BLS untouched; forward-only 2026-06-27 18:51:41 -07:00
zeekay 0f1701b44a chore(deps): bump warp v1.22.0 -> v1.23.0, precompile v0.12.0 -> v0.13.0
warp v1.23.0 = typed finality-evidence model + Pulse->Corona relabel.
No node package references the renamed warp symbols: go build ./... is green
and every warp test passes (vms/platformvm/warp{,/message,/payload,/zwarp},
vms/platformvm/network, vms/platformvm, vms/example/xsvm). Pure dependency bump.

Note: vms/platformvm/txs test binary has a pre-existing, warp-unrelated compile
error (add_validator_test.go:373 undefined: fmt) that predates v1.30.88 and is
not addressed here.
2026-06-27 14:56:04 -07:00
zeekay e155575597 fix(chains): luxd-2 behind-node freeze — caught-up by ACCEPTANCE not store + convergence off the finalized ledger
A validator holding gossiped-but-unaccepted blocks (in the VM store, lastAccepted
below them) concluded caught-up at its stale height forever — the caught-up check
conflated store presence (Has/heldHeight via vm.GetBlock) with acceptance.
Fix (consensus v1.25.36): Has→Accepted (a stored-but-unaccepted named frontier
descends+ACCEPTS through the cert-gated per-height guard); recognize convergence
off the in-process consensus finalized ledger, not the frozen VM.LastAccepted
cache; un-freeze the zap client's lastAcceptedID on Accept. Proven on mainnet
luxd-2 (1082780→1082796). C1/VerifyWeighted/cert-gate intact. blue→red→blue→red.
2026-06-27 10:04:10 -07:00
zeekay 33f4c8f22c fix(chains): close the mainnet luxd-2 freeze — gate native-chain frontier-trust on the FULL staked set + self-heal poller (canary)
The v1.30.84 bootstrap-vm-ready ordering fix passed 50 unit tests + the BFT
proof but FAILED the real mainnet canary: a STALE spare (luxd-2) at C-Chain
accepted height 1082780 went Ready at 1082780 instead of fetching the 16 blocks
to the producers' frontier 1082796, then sat frozen. The mocks injected the
FULL, STABLE validator set from t=0 — masking the production trigger.

ROOT CAUSE (primary). A native chain's runBootstrapThenPoll starts right after
its VM.Initialize (dispatchChainCreator), NOT after the P-chain has finished
its own initial sync. The P-chain populates m.Validators as it replays blocks
(genesis stakers + every AddValidatorTx), so FrontierTip can run while
GetMap(PrimaryNetworkID) is a PARTIAL set. The MinResponseWeight stake-majority
floor (total/2+1) is fail-secure ONLY when `total` is the TRUE full-set stake;
under a partial denominator a degenerate at-or-below responder subset (the
genuinely-ahead producers not yet loaded) clears the floor and the exact-fast-
path / CaughtUp concludes "caught up" at the stale local height. Proven by
elimination: with the full set EVERY accurate-reply path is fail-safe (wait /
sync), so the freeze requires a non-representative responder set.

FIX (primary): gate a native non-platform chain's frontier-trust on the P-chain
having COMPLETED initial sync (m.pChainBootstrapped, published by
monitorBootstrap; read via blockHandler.primaryNetworkReady). Until then
FrontierTip returns FrontierConnecting (WAIT), so every branch judges the TRUE
full validator set and the existing floor logic holds. Deadlock-free: the
P-chain converges independently from its own configured CustomBeacons.

FIX (self-heal / the "ALSO FIX"): pollFrontierOnce filtered peers on b.chainID —
the IDENTICAL chainID/networkID confusion already fixed in connectedBeacons.
Peers advertise the NET they track, never an individual native chain id, so the
sample was always empty and a behind-but-Ready validator never discovered it was
behind. Filter on b.networkID so the NormalOp catch-up poller actually fires.

INSTRUMENTATION: FrontierTip now logs (Debug) the full beacon-set size + total
stake (the floor DENOMINATOR — a partial value is the smoking gun), connected
count, and every reply's tip + locally-resolved height + held-or-not, plus the
decision. Set the C-chain log level to Debug on the canary to capture ground
truth.

TESTS (production-modeling, not the ideal full set): TestRED_PartialStakedSet_
BehindNodeMustNotGoLiveStale reproduces the freeze (without the gate it NAMES the
stale own tip; with it, WAITS; then converges on the full set) — proven
load-bearing (disabling the gate fails the test). Plus not-held-tips → sync,
empty-ancestry → stays Bootstrapping (never Ready stale), and peer-connect-delay
→ wait-then-converge. Full chains suite green (C1, co-restart, M1,
mass-recovery, skewed-weight all preserved), race-clean.
2026-06-27 06:45:38 -07:00
zeekay bc0cff5730 fix(chains): close M1 eclipse-stale own-height naming — frontier names STRICTLY ABOVE last-accepted (red fast-follow)
nameFrontier's ancestor-tolerant filter was `ref.Height < MinFrontierHeight`
(MinFrontierHeight = the node's own last-accepted), so a block AT the node's
own height passed the filter and could be NAMED. Red's M1 eclipse: with the
genuinely-ahead responders throttled below the ⅔ naming threshold (R_a < ⅔R)
but the at-height responders let through, the node's OWN height accrues ⅔
purely as the shared ANCESTOR of the ahead N+5 tips → nameFrontier names it →
FrontierNamed at own height → the node goes Ready STALE (5 blocks behind a
finalized N+5). nameFrontier ran BEFORE CaughtUp in FrontierTip, so it
short-circuited the stricter CaughtUp determination that already refuses this.

FIX (one operator): `ref.Height <= MinFrontierHeight` — own height is excluded
from naming, routing the at-own-height case to CaughtUp, which alone
distinguishes a legit all-at-N fleet (Ready at N) from an eclipse with ahead
tips the node lacks (refuse → sync). The two paths compose with no gap:
nameFrontier names STRICTLY ABOVE own height (behind nodes); CaughtUp decides
at-or-below own height (tip-holders); the fast path (active ⅔-direct report)
stays exempt for the legit unanimous-at-tip case.

Safe for layer-5 + C1: a behind node names HIGHER than its own height (survives
both the old `<` and new `<=`); the ⅔-of-responder-weight naming requirement is
untouched (only height eligibility tightens — strictly safer). Round-1
behind-node convergence is unchanged.

Faithful test correction (manager.go: GetAcceptedFrontier answers vm.LastAccepted
— the last-ACCEPTED block, NEVER an un-finalized preferred tip): the two
ancestor-tolerant convergence integration tests modeled a beacon reporting an
un-finalized tip FOREVER (a gap-1 instance of this very M1 stale-go-live). They
are restated to model finalization PROPAGATION — the node names the ⅔-common as
a behind node, then RATCHETS to the true finalized tip as the laggards' accepted
frontier advances — converging to the real frontier (stronger guarantee), never
falsely caught-up below it.

Tests (RED-before by reverting the one-operator hunk, GREEN-after):
- TestBootstrapTrust_EclipseOwnHeightNotNamedRoutesToCaughtUp (policy, deterministic
  + own-height boundary)
- TestRED_EclipseOwnHeightNotNamedRoutesToSync (integration: FrontierNoQuorum +
  full-loop fails safe at stale N + eclipse-lifts→syncs-up)

GOWORK=off CGO_ENABLED=0 go test ./chains/ — all green (layer-5 convergence, C1
forged/eclipse/partition, caught-up co-restart, fast-path, self-heal).
2026-06-27 04:59:39 -07:00
zeekay 8e0815cf7b fix(chains): caught-up go-live for tip-holders — close the co-restart freeze regression (RED CRITICAL)
RED found a CRITICAL liveness regression in the VM-ready gate (b313912413): a
tip-holding producer on a mixed-height co-restart cannot satisfy its own go-live
gate and fails safe DOWN at its own tip — the OPPOSITE of the stale-go-live bug the
gate fixed, and just as wrong.

Mechanism (PoC reproduced): a producer at N sees its 4 peers split
{2 producers@N, luxd-2@N-16, luxd-0@genesis}. The tip-holders are only ½ of the
responders (< ⅔) so no frontier is NAMED; the ⅔-backed common ancestor N-16 is
below the node's own last-accepted (MinFrontierHeight filters it). → ErrNoBeaconQuorum
→ runInitialSync false → C-Chain STOPPED. The loop's Has(tip)→caughtUp shortcut is
only reached AFTER FrontierNamed, which a tip-holder never gets.

PRIMARY FIX — a CAUGHT-UP determination (BootstrapPolicy.CaughtUp), the dual of
AcceptsFrontier ("nobody is ahead" vs "here is the block ahead"). On the
ErrNoBootstrapQuorum branch, FrontierTip concludes caught-up and names the node's
OWN held tip (→ the loop's existing Has()-shortcut → Ready at own height) iff:
  (a) the SAME response floor AcceptsFrontier uses is met (MinResponses count AND
      MinResponseWeight stake-majority) — an eclipse hiding the ahead-nodes drops
      below the floor → fail safe, no partition-capture;
  (b) every responder's reported ACCEPTED tip is at height ≤ lastAccepted — a stale
      node has an honest responder ahead → still syncs (stale-go-live stays fixed);
  (c) the node HOLDS every reported tip (heightOf injected, VM-free) — never declares
      caught-up to a sibling/fork it lacks.
floorMet + tallyResponders are extracted so naming and caught-up share ONE floor and
ONE eligibility rule (DRY). No consensus change — reuses FrontierNamed + Has, builds
GOWORK=off against the deployed consensus v1.25.35.

SELF-HEAL (RED MEDIUM #2) — the K8s probes all poll the always-green
/ext/health/liveness, so a fail-safe-DOWN node is NEVER restarted (a permanent brick).
runInitialSync now RE-ATTEMPTS a transient connectivity fail-safe (bootstrapMaxAttempts
≤ 0 ⇒ until the quorum returns or shutdown), staying in Bootstrapping (never live at
stale height) and converging the instant the quorum returns. bootstrapConnecting tells
monitorBootstrap's no-progress watchdog this is a deliberate WAIT (not a stall) so it
does not force-STOP a node correctly waiting for its quorum. Structural failures (deep
gap → state-sync) are NOT retried.

LOW — FinishBootstrap now runs BEFORE transitionVMReady (close the no-cert
AcceptBootstrapBlock gate before the VM can build); transitionVMReady's SetState timeout
is derived from the shutdown ctx (was context.Background()).

MEDIUM — createDAG (X/Q) go-live left UNCONDITIONAL, now documented as a DELIBERATE
linear-only scope (mainnet froze on linear C/D/B/T/Z; DAG bootstrap convergence is a
separate task). createDAG does not regress.

C1, VerifyWeighted, the ⅔-stake cert, and "no VerifiedQuorumCert no finality" are
untouched. Tests (chains): TestRED_TipHolderCoRestartGoesReadyAtOwnTip reproduces the
regression — RED before on b313912413 (FrontierNoQuorum, live==false), GREEN after
(FrontierNamed at own tip, vmReady once at N). Plus 6 CaughtUp unit tests (incl. both
adversarial fake-caught-up cases), TestRED_MajorityOutageSelfHealsWhenQuorumReturns,
and TestWatchBootstrapProgress_ConnectingNotStalled. Full C1/forged/eclipse/partition
suite re-run green (41 bootstrap tests, 0 fail).
2026-06-27 04:02:13 -07:00
zeekay b313912413 fix(chains): gate VM normal-op transition on initial sync reaching the frontier
Root cause of the restart-freeze (mainnet luxd-2: C-Chain stuck at 1082780
while producers finalized 1082796): buildChain called SetState(vm.Ready)
UNCONDITIONALLY right after Initialize — at the LOCAL last-accepted height —
and ran the node-layer initial sync (runBootstrapThenPoll) afterward as a
detached, non-gating goroutine. vm.Ready fires the EVM's
onNormalOperationsStarted (block building, mempool gossip, validator dispatch);
a restarted STALE validator therefore went live at its stale height and never
converged to the finalized frontier. The proper vm.Bootstrapping state (the
EVM's onBootstrapStarted: snapshots only, no building) was skipped entirely.

Fix — restore the correct VM lifecycle, gated:
  - buildChain now SetState(vm.Bootstrapping) after init (not Ready). The VM
    fetch+executes the gap in Bootstrapping, serving nothing as head.
  - The Ready transition moves into the bootstrap goroutine (runInitialSync,
    split out of runBootstrapThenPoll for unit-testability) and fires ONLY after
    bs.Run reaches the named ⅔-by-stake beacon frontier — VM live + engine
    cert-gate (FinishBootstrap) go together at the frontier, never at a stale
    height. Wired via blockHandler.vmReady (captures the VM's SetState).
  - Fresh-genesis / single-node (FrontierNoBeacons) and at-the-tip restart
    (caught-up) go Ready promptly — no regression, no hang.
  - Eclipse / isolation: bs.Run's bounded ConnectDeadline is the retry that
    self-heals when beacons return; past it the node fails SAFE (stays
    Bootstrapping, records the reason for monitorBootstrap) — never serves stale
    state, never an unbounded hang. The orchestrator restart now converges.

C1 forged-chain defense, VerifyWeighted, and the ⅔-stake quorum cert are
untouched — the frontier is still named only by the configured-beacon
⅔-of-responders quorum + content-addressed descent (all RED/BootstrapTrust
tests pass). AcceptedFrontier/Ancestors replies route to the bootstrap channels
via bsActive throughout the phase (verified).

Tests (chains): TestRED_StaleValidatorGoesReadyOnlyAfterReachingFrontier
reproduces the production scenario — RED before (VM goes live at stale N=30),
GREEN after (only at frontier N+K=46). Plus fresh-genesis no-regression,
bounded eclipse fail-safe, and at-the-tip producer fast-Ready. Race-clean.

NOTE (flagged for review, NOT in this change): the createDAG path (X/Q DAG
chains, consensusdag.Engine) has the same unconditional SetState(Ready) at
manager.go:1792 but a different engine without the node-layer bootstrap-sync
wiring — a separate fix if any production chain uses it.
2026-06-27 02:47:48 -07:00
zeekay c1035aada9 test(bootstrap): regression-guard bootstrapPolicy() MinResponseWeight wiring (re-red LOW)
Mutation-proven gap: H/D2 construct policies directly, so nothing caught the
production constructor silently dropping the stake-majority floor. This asserts
bootstrapPolicy() emits MinResponseWeight=⌈total/2⌉ (skewed), the count floor,
the AncestrySource, no-re-deadlock for equal-weight 3-of-5, and disabled-on-empty.
Re-red verdict was SHIP; this closes the only (LOW) residual.
2026-06-27 01:39:38 -07:00
zeekay e869b0d7f5 fix(bootstrap): MinResponseWeight stake-majority floor — close skewed-weight partition-capture (re-red HIGH)
The MinResponses COUNT floor and the ⅔-of-responders WEIGHT agreement diverge under
SKEWED validator stake: an attacker eclipsing the HEAVY honest beacons while passing
enough LIGHT honest ones to clear the count can shrink the responder-weight denominator
until <⅓-of-total Byzantine stake names a forged frontier (re-red PoC: w={3,3,13,1,1,1},
Byz 27%). Fix: bootstrapPolicy() now sets MinResponseWeight=⌈total/2⌉ (the field was
wired into AcceptsFrontier but left 0). Proven safe AND deadlock-free: equal-weight
recovery needs only >½ (3/5=0.6≥0.5), not the >⅔ that caused the original deadlock.
Closes the re-red HIGH + INFO-2 (same root cause). Tests H (skewed→reject, load-bearing)
+ D2 (non-configured swarm→nothing). Required for non-equal-weight validator sets
(validators-come-and-go). C1/A-G/finality all green.
2026-06-27 01:27:31 -07:00
zeekay 41fa42bd88 merge: BootstrapTrust policy — decouple weak-subjective recovery from ⅔-finality (LP-304); mass-recovery converges when validators down, C1 preserved 2026-06-27 01:09:17 -07:00
zeekay b1e792c0ed fix(chains): BootstrapTrust policy — decomplect bootstrap trust from consensus finality to break the mass-recovery deadlock
THE DEADLOCK (mainnet, node v1.30.79): 5 equal-weight validators (each
0.5e18, total 2.5e18, ⅔ floor 1.667e18). The 2 stranded recovery targets
ARE 2 of the 5; with them down only 3 producers connect = 1.5e18 = 60% < ⅔.
The prior bootstrap frontier quorum required ⅔ of CURRENT TOTAL stake to be
CONNECTED before naming a sync frontier — mathematically unsatisfiable during
a mass outage when the down nodes are themselves validators — so no node could
ever recover. Bootstrap trust was braided into consensus finality, and
finality's ⅔ rule cannot be met when ⅓+ of the set is the thing recovering.

THE FIX — a SEPARATE type with a SEPARATE threat model, not a renamed
threshold (chains/bootstrap_trust.go):
  - ConsensusQuorum.HasFinality(weight,total): > ⅔ CURRENT stake — UNCHANGED;
    present only to NAME the live rule and CONTRAST it.
  - BootstrapTrust.AcceptsFrontier(ctx,replies): selects a weak-subjective sync
    anchor from authenticated CONFIGURED beacons. NOT a finality oracle.
  - BootstrapPolicy: TrustedBeacons (the configured/checkpoint/genesis anchor —
    never peer self-report), AgreementThreshold (⅔ of RESPONDERS), MinResponses
    (a response FLOOR), MinResponseWeight, Checkpoint (operator override).

Three invariants:
  1. NON-CIRCULAR eligibility — only NodeIDs in TrustedBeacons count; peers
     never define who is a beacon.
  2. A response FLOOR prevents partition-capture — MinResponses (default: a
     MAJORITY of the configured set) authenticated beacons must respond; below
     it, REJECT unless an operator checkpoint is pinned. For the 5-validator
     mainnet (MinResponses=3) the 3 reachable producers recover while a
     2-beacon partition is rejected.
  3. Acceptance ≠ finality — the named Frontier is "safe to begin sync from",
     re-executed during descent; live acceptance stays governed by
     ConsensusQuorum alone.

The acceptance gate (FrontierTip) now routes through BootstrapPolicy: the
⅔-of-CURRENT-TOTAL connect gate is GONE; agreement is ⅔ of the RESPONDERS over
a MinResponses floor. The ancestor-tolerant common-ancestor tally is reused
(now a global cross-anchor union tally so a sibling split converges to the
shared committed block — case F), bounded below by MinFrontierHeight (the
node's last-accepted height) so a fork sharing only history BELOW the node
fails safe instead of false-completing at the deep ancestor. Consensus
(v1.25.35) is UNTOUCHED — the FrontierStatus interface is unchanged and its
engine/chain suite stays green.

Tests (chains green; consensus engine/chain green): A mass-recovery success,
B one-beacon capture rejected, C two-beacon partition rejected, D
non-configured peer ignored, E minority-configured forgery rejected (forger
ratifies the real block, never names its forgery), F split reachable ancestry
selects the common ancestor, G finality unchanged (3-of-5 accepts for
bootstrap but is NOT HasFinality). Plus checkpoint override and a load-bearing
fork-at-shared-genesis fail-safe guard for the global tally. The reframed
SubAlpha→SubQuorum test replaces the ⅔-of-total assertion that WAS the bug.
Each guard proven load-bearing by revert: restore the ⅔-of-total gate and A
deadlocks; drop the configured-beacon filter and D captures; drop
MinFrontierHeight and the shared-genesis fork false-completes.

Branch only; not deployed. Re-canary luxd-2.
2026-06-27 01:05:40 -07:00
zeekay 2b93f3fbb0 refactor(warp): Core -> Message — track warp v1.22.0
External-warp consumers follow the rename: extwarp.Core -> extwarp.Message,
extwarp.NewCore -> extwarp.NewMessage, luxWarp.Core -> luxWarp.Message, and the
warp.Verifier signature over *warp.Message. node's own vms/platformvm/warp
package (a separate implementation) keeps warp.NewUnsignedMessage untouched.

deps: warp v1.21.0 -> v1.22.0, precompile v0.11.0 -> v0.12.0.
2026-06-27 00:53:26 -07:00
zeekay 90a4698f33 feat(warp): migrate node external-warp consumers to warp v1.21.0 Core (ZAP)
The last holdout on the deleted RLP UnsignedMessage API. The four spots that
import the external github.com/luxfi/warp now use warp.Core (ZAP); node's OWN
vms/platformvm/warp package is a separate implementation, untouched.

  vms/platformvm/vm.go, vms/platformvm/network/network.go: warpSignerAdapter
    bridges node's internal warp signer <-> external extwarp.Core
  vms/platformvm/network/warp_zap.go, vms/example/xsvm/warp.go: Verify over
    *warp.Core

deps: warp v1.19.5 -> v1.21.0, precompile v0.5.59 -> v0.11.0 (indirect — the old
precompileconfig referenced the deleted warp.UnsignedMessage).

go build ./... clean (consensus v1.25.35 now publishes FrontierStatus, clearing
the prior blocker); node's own warp + xsvm + network adapter tests green. The
whole ecosystem is now on one warp wire format — one and one way only.
2026-06-27 00:23:26 -07:00
zeekay b4340d56b1 merge: ancestor-tolerant ⅔ frontier quorum — converge stale node to the ⅔-agreed common height despite tip split (canary fix; C1 preserved, consensus untouched) 2026-06-26 23:56:37 -07:00
zeekay cd17d27c62 fix(chains): ancestor-tolerant ⅔ frontier quorum — a ±1-block tip split converges to the common committed height (mainnet canary luxd-2)
The exact-tip frontier quorum required ⅔-by-stake of beacons to report the
IDENTICAL accepted tip. On a live chain validators are legitimately ±1 block
apart at the bleeding edge, so the freshest tip splits and no single id draws
⅔. The mainnet canary (luxd-2): 2 producers had accepted block N, the third
producer's un-finalized PENDING block was N+1; neither tip alone cleared ⅔, so
FrontierTip returned NoQuorum forever and the healthy stale node failed safe at
its stale height instead of converging. The chain was idle, so the split was
STABLE and never resolved.

FIX (node-only — the stake quorum lives where the stake lives; consensus stays
stake-agnostic and just descends from whatever block is named): make the tally
ANCESTOR-TOLERANT. A beacon reporting tip N+1 also has N in its accepted chain,
so the named frontier is the HIGHEST block a ⅔-by-stake supermajority SHARES
(B == their tip OR B is an ancestor of their tip), not the highest proposal. N
draws all three producers (300 > 200) and is named; N+1 draws only the lone
producer and is not. The node syncs to N (the ⅔-agreed committed height); live
consensus catch-up handles N+1.

Ancestry is learned by CONTENT (reusing the parent-link descent the sync loop
trusts): for each candidate tip, fetch its ancestry, rebuild the parent-linked
chain, and cumulatively tally — the highest block clearing the floor across
anchors is named. A credit is truthful because a block's parent id is fixed by
its content, so a peer cannot fake the linkage below an honestly-reported tip.

C1 preserved EXACTLY: a block is named only with > ⅔ of the TOTAL real
staked-beacon weight and ≥ required distinct voters; a forged or sub-⅔ tip on a
side-fork shares only the honest prefix and can never raise the named block above
the genuine ⅔-common height. Only the agreement RELATION changed (exact-tip →
in-the-accepted-chain), never the ⅔-by-stake-of-the-real-set requirement. The
content-addressed descent, per-height guard, re-execution, weak-subjectivity
anchor, F2 bounded-NoQuorum retry, deep-gap fail-safe and single-node completion
are all untouched (consensus engine/chain/... unchanged + green).

Also: resolve the quorum the instant ALL connected beacons have answered (no
exact ⅔), instead of waiting out the full frontier window — so a live-frontier
split converges in one round instead of stalling a window each pass.

Tests (chains green; consensus engine/chain/... green): TestRED_TipSplitConverges-
ToCommonHeight (the canary — converges to N, not the minority N+1, not fail-safe;
proven load-bearing: 2-of-3 = 200 is NOT > the 200 floor, so the exact tally
cannot name N), TestRED_ForgedHighTipFromMinorityNotNamed (a Byzantine beacon's
forged block built ON real N ratifies only N, never names itself — C1),
TestNodeBootstrap_ExactQuorumUsesFastPath (unanimous ⅔ still names the exact tip
with NO fetch), TestNodeBootstrap_BeaconsSplitNoQuorum (disjoint 3/3 partition,
ancestry served, STILL NoQuorum — ancestor tolerance does not manufacture a
quorum). NOT deployed — re-canary luxd-2.
2026-06-26 23:53:18 -07:00
zeekay d4b7dd0291 merge: bootstrap connectivity filters on networkID not chainID — stake-weighted beacon quorum converges stale nodes (canary fix; C1 preserved) 2026-06-26 23:12:47 -07:00
zeekay f1a247d5ae fix(chains): bootstrap beacon connectivity matches the NET, not the chain ID — stale node converges against the staked validator set (mainnet canary)
THE CANARY (luxd-2, node v1.30.77): a healthy STALE node (C-Chain 1082780,
gap-17 to producers at 1082797) rolled to the convergence fix logged
"bootstrap waiting for beacon connectivity..." x10 then failed SAFE at the
connect deadline — "beacon set never reached the connectivity needed to form a
⅔ quorum ... eclipsed/partitioned" — despite connectedPeers=9 and the
producers being right there. Correct fail-safe, but it did NOT converge.

DIAGNOSIS: the beacon set was ALREADY the stake-weighted validator set, not
the --bootstrap-nodes endpoints. For a native chain (C-Chain) manager.go wires
beacons = m.Validators (n.vdrs, populated by the bootstrapped P-chain's
state.initValidatorSets under PrimaryNetworkID); the --bootstrap-nodes endpoint
beacons are a SEPARATE weight-1 set used only as the P-chain's CustomBeacons.
FrontierConnecting (not FrontierNoBeacons) confirms m.Validators was non-empty.
The real bug was the CONNECTIVITY filter: connectedBeacons admitted a connected
beacon only if p.TrackedChains.Contains(b.chainID). But a peer advertises the
NETS it tracks (network/peer/peer.go adds constants.PrimaryNetworkID + every
tracked L1 net ID to peer.Info.TrackedChains) — it NEVER advertises an
individual native chain ID. So the filter matched ZERO real peers,
connectedStake stayed 0, the ⅔ floor was never reachable, and FrontierTip
reported FrontierConnecting until the deadline. The tests passed only because
the mock modeled TrackedChains as set.Of(chainID) — agreeing with the bug, not
reality.

FIX (node-only; consensus FrontierStatus logic unchanged and correct):
- connectedBeacons filters on b.networkID (the NET the beacon set is anchored
  to — PrimaryNetworkID for native chains, the L1 net ID for sovereign chains),
  the value real peers actually advertise. C1 PRESERVED: a peer is still
  admitted ONLY if it is in the staked set (weights); the ⅔-by-stake threshold,
  the TOTAL-stake denominator, and the content-addressed descent are untouched.
  A non-staked peer that tracks the network is still ignored.
- EDGE (4): expectsStakedBeacons (true for a native non-platform chain on a
  sybil-protected network) makes an EMPTY staked set report FrontierConnecting
  (wait → ConnectDeadline → fail safe), never FrontierNoBeacons (false-complete)
  and never endpoint trust. Distinguishes "validator set not yet loaded → wait
  → converge" from "genuinely empty → fail safe". The P-chain (CustomBeacons may
  be empty under endpoint-only --bootstrap-nodes) and single-node keep
  "empty ⇒ nothing to sync to".

TESTS (chains):
- TestRED_PeersTrackNetNotChain_StaleNodeConverges: 3 producers holding > ⅔
  stake, connected + advertising the NET (not the chain), name the frontier and
  the stale node converges. Proven load-bearing: reverting the filter to
  b.chainID makes connectedBeacons return nil and this test fails exactly as the
  canary did. Mock now models TrackedChains = the NET (matches peer.go).
- TestRED_EmptyStakedSetFailsSafe: empty staked set + expectsStakedBeacons →
  Connecting → ErrBeaconsUnreachable, no endpoint trust; the flag is the proven
  discriminator vs FrontierNoBeacons.
- C1 (ForgedFrontierFromNonBeacon / HonestBeaconQuorumIgnoresMalicious /
  SubAlphaStakeCannotName), F2/NoQuorum, deep-gap, weak-subjectivity,
  single-node all green; consensus engine/chain/... unchanged and green.

NOT deployed — re-canary luxd-2.
2026-06-26 23:08:19 -07:00
zeekay c5f24b8b3d deps: bump chains v1.3.22→v1.4.6 (drop trusted-dealer dual-key keygen; builds against consensus v1.25.35)
Fixes the v1.30.76 build break: chains/quantumvm called the now-test-only
quasar.GenerateDualKeys (trusted-dealer keygen, relocated test-only for
corona-genesis hardening). chains v1.4.6 drops the dead trusted-dealer path
(the Q-Chain Quasar bridge signs through the consensus core with per-validator
keys; group keys would need dealerless DKG). Carries the bootstrap F2 convergence fix.
2026-06-26 22:36:37 -07:00
zeekay 981f3ac66e deps: bump consensus v1.25.34→v1.25.35 (bootstrap F2 deterministic convergence) 2026-06-26 21:50:58 -07:00
zeekay 128254ed57 merge: bootstrap beacon-connectivity wait + bounded NoQuorum retry (F2) + prompt fail-safe (F5) — deterministic stale-node convergence 2026-06-26 21:50:09 -07:00
zeekay 590123c34f fix(chains): surface a bootstrap fail-safe return promptly — stop the chain when Run gives up, not 5 min later (F5)
When the initial-sync loop RETURNS a fail-safe error (ErrBeaconsUnreachable /
ErrNoBeaconQuorum / ErrGapTooLarge), runBootstrapThenPoll exited leaving the chain
in a DEAD WINDOW: neither bootstrapping (the loop is gone) nor stopped
(monitorBootstrap only stops the engine at the +5-min no-progress watchdog). The
operator saw a chain that had already given up but was not marked failed for up to
5 minutes.

runBootstrapThenPoll now records the fail-safe reason (bootstrapFailed atomic +
BootstrapFailed/BootstrapFailure accessors). watchBootstrapProgress takes a failed()
predicate and returns the new bootstrapFailed outcome the next tick; monitorBootstrap
stops the engine + registers a failing health check IMMEDIATELY, carrying the real
reason (eclipsed/partitioned/too-far-behind) rather than the generic no-progress
timeout. The stop+health logic is DRY'd into one m.failBootstrapChain shared by the
stall and fail-safe outcomes. Combined with the consensus-side bounded NoQuorum retry
(F2), a transient live-frontier split converges and a genuine eclipse fails fast and
visibly — making the mainnet 5/5 roll deterministic.

Tests: TestWatchBootstrapProgress_FailSafeSurfacesPromptly (failed -> bootstrapFailed
next tick, not after the window), TestWatchBootstrapProgress_ReadyBeatsFailed (success
never masked), TestBootstrapFailure_AccessorSurfacesReason (driver<->monitor plumbing).
Existing watchdog + node bootstrap (C1 forged-frontier finalizes ZERO, stale-converge,
split-no-quorum) all still green. NOTE: build the combined tree with a temp
go.mod replace github.com/luxfi/consensus=../consensus (consensus f93162d15); not committed.
2026-06-26 21:41:48 -07:00
zeekay da8f57e6e9 fix(chains): FrontierTip reports beacon-connectivity status — wait for beacons before concluding caught-up (mainnet canary)
Node side of the stale-node convergence fix. blockHandler.FrontierTip now returns
a chainbootstrap.FrontierStatus instead of a bare ok bool, decomplecting the THREE
reasons a frontier may not be named so the bootstrap loop can WAIT for beacon
connectivity instead of false-completing at the local stale height:

  - no beacon set configured            -> FrontierNoBeacons  (single-node: complete)
  - beacons configured, < ⅔ stake up    -> FrontierConnecting (the boot race: WAIT)
  - ⅔ stake connected, no agreement      -> FrontierNoQuorum   (eclipse: fail safe)
  - ⅔-by-stake quorum agrees on a tip    -> FrontierNamed      (C1 gate: sync)

The discriminator is the SAME ⅔ floor (config.TwoThirdsStakeFloor over the FULL
beacon stake) used by the quorum tally: if even unanimous CONNECTED beacon stake
could not clear the floor (or too few distinct beacons are up), connectivity is
still coming up -> FrontierConnecting (the canary boot race, where FrontierTip ran
before any beacon handshaked). Only once enough beacon stake is connected do we
query + tally; a split that clears none -> FrontierNoQuorum.

The C1 forged-chain gate is UNCHANGED: the query + weighted ⅔-stake tally is
extracted verbatim into queryFrontierQuorum (a non-beacon peer, a single peer, or
any sub-⅔ set can still NEVER reach FrontierNamed). connectedBeaconsTrackingChain
is replaced by the smaller connectedBeacons helper (shared with
sampleAncestorBeacons — DRY). monitorBootstrap/watchBootstrapProgress need no
change: they already gate the chain-ready signal on BootstrapComplete (Run
success), which now returns only on genuine caught-up.

Tests: reproduces the canary over the REAL GetAcceptedFrontier/GetAncestors
transport (TestNodeBootstrap_StaleNodeWaitsForBeaconConnect — beacons connect after
a delay; the stale node WAITS through the connecting passes, then names the ⅔
frontier and converges, never false-completing at the stale height); the
forged-frontier-from-non-beacon case now FAILS SAFE (ErrBeaconsUnreachable) instead
of false-completing while still finalizing ZERO forged blocks; split-beacons report
FrontierNoQuorum; a no-beacon-set node reports FrontierNoBeacons (single-node
completes). All existing C1 quorum, sub-⅔, invalid-halt, framing, deliver-gating,
and H2 watchdog tests stay green.

Dev integration: node go.mod stays pinned consensus v1.25.34 (NO committed
replace); build/test against the consensus fix branch via
`GOWORK=off go mod edit -replace github.com/luxfi/consensus=../consensus`
(the go.work path is blocked by an unrelated ./compliance go.sum mismatch). Tag
consensus + bump node go.mod at the coordinated merge.
2026-06-26 21:00:59 -07:00
zeekay ce10acd10a deps: bump consensus v1.25.33→v1.25.34 (real chain bootstrap + C1 forged-chain fix APIs) 2026-06-26 20:25:41 -07:00
zeekay 69beb96cb6 merge: real chain bootstrap (fetch+execute) with C1 fix — beacon ⅔-stake-quorum frontier + content-addressed descent (red VERIFIED CLOSED) 2026-06-26 20:24:20 -07:00
zeekay 0ac6677237 test(node): plugin-dir build degrades to Skip on workspace-integration gap (missing go.sum dep under GOWORK=off), not Fatal — real compile errors still fail 2026-06-26 20:00:53 -07:00
zeekay 06487c67c9 fix(chains): beacon + α-weighted-stake quorum names the bootstrap frontier — close C1 forged-chain naming
THE VULN (red PoC): an empty/behind node discovered the network frontier from
samplePeerTrackingChain = net.PeerInfo(nil) (ALL connected peers, filtered only by
self-reported TrackedChains — no stake/beacon filter) and FrontierTip returned the
FIRST reply (no quorum). An eclipse/malicious peer (no validator keys needed) named a
forged-but-Verify-passing frontier from genesis; the node fetched+executed it and
finalized the forged chain cert-lessly (proposervm disabled => Verify is just the EVM
state transition), bricking against the real chain. red finalized 40 forged blocks.

THE FIX — the frontier is named ONLY by a 2/3-BY-STAKE quorum of the configured BEACONS:
- beacons (validators.Manager) is wired into the blockHandler (was computed in buildChain
  then discarded as unused). For native chains it is the primary-network validator set
  under networkID = PrimaryNetworkID.
- FrontierTip queries ONLY connected beacons (PeerInfo is beacon-restricted), tallies
  their accepted-tip replies WEIGHTED by stake (replies now carry the responder nodeID),
  and returns a tip only once its agreeing stake clears the shared live floor
  (config.TwoThirdsStakeFloor over the FULL beacon stake) with >=2 distinct beacons. A
  non-beacon peer, a single peer, or any sub-2/3-stake set can NEVER name the frontier =>
  fail-closed (the loop has nothing to sync to). Mirrors VerifyWeighted exactly, so the
  bootstrap anchor can never drift from live finality.
- Optional weak-subjectivity checkpoint (wsCheckpoint{ID,Height}) wired into the loop.
- M1: Ancestors fetches from a ROTATED beacon sample (bsRotor) so no beacon monopolizes
  the descent; safety is independent of which beacon serves (content-addressed in
  consensus).
- H2: monitorBootstrap is now PROGRESS-BASED — the once-set 5-minute hard timer that
  killed a healthy-but-slow sync is replaced by a no-progress stall window (reset on
  height advance via BootstrapHeight()). Decomplected into watchBootstrapProgress (pure,
  unit-tested).

Tests: TestRED_ForgedFrontierFromNonBeaconRejected (headline — 0 forged finalized, was
40), honest-beacon-quorum-ignores-malicious, sub-2/3-stake-cannot-name, progress-watchdog
(slow-but-advancing NOT killed / genuine stall fails). Existing transport + framing +
gating tests stay green. (consensus side: content-addressed descent + M2 + WS + M3.)

Convention: node go.mod stays pinned consensus v1.25.32; built via go.work in dev,
consensus tagged + go.mod bumped at the coordinated merge (same as 58f1e04928).
2026-06-26 19:54:05 -07:00
zeekay 092c755e70 deps: bump consensus v1.25.32→v1.25.33 (dead-wave_signer removal + bench-fix) 2026-06-26 19:30:54 -07:00
zeekay d8da0e2e43 chainadapter: real committee-cert signature verification
CommitteeCert.Verify(committee) now verifies each endorsement as a BLS
signature over the certificate's canonical signing digest by a distinct,
known committee member's registered public key. Rejects (fail-closed) nil,
unknown, duplicate, or invalid endorsements, parameter mismatches, and
sub-threshold sets; requires >= Threshold valid distinct signatures. The
engine holds a committee registry (RegisterCommittee) and VerifyResult fails
closed on an unknown committee. Replaces the count-only stub.

Tests: valid quorum + sub-threshold, duplicate-signer, forged-signature,
unknown-signer, parameter-mismatch, and engine fail-closed cases.
2026-06-26 19:28:35 -07:00
zeekay ad7ec6e5f3 consensus: remove superseded dormant Quasar hybrid-finality hub
node/consensus/quasar + node/consensus/zap + node/node/quasar.go were a
superseded duplicate of the live post-quantum finality path
(consensus/protocol/quasar WeightedQuorumCert, driven by the chain engine).

The node-side hub wrapped that live core but added only dormant scaffolding:
  - an undriven P-Chain finality loop (finCh never fed; run() sat idle)
  - a fail-closed CoronaCoordinator stub (Sign/Verify errored in prod,
    InitializeCorona was test-only, so q.corona stayed nil)
  - a QuantumFinality store nothing read (only n.Quasar.Stop() was ever called)

Dependency trace: zero cross-repo importers; the Q-Chain VM
(luxfi/chains/quantumvm) is external, independent, and finalized by the live
chain-engine QuorumCert path, not this hub; consensus/zap (ZAP/DID agentic
bridge) was a collateral dormant island on the same stub with no external
importers. Wiring was impossible without driving the live accept path or
adding a redundant second finality authority, both out of scope, so the hub
is removed rather than wired.

Live consensus/protocol/quasar and consensus/engine/chain are untouched.
Q-Chain VM registration, genesis, and critical-by-default status are
unchanged. Genuine PQ tests (TLS hybrid KEX, ML-DSA UTXO, hostname
addressing) are preserved; only the dormant-hub tests were removed.
2026-06-26 19:28:34 -07:00
zeekay bd42106be3 node: bump chains v1.3.21→v1.3.22 (graphvm genesis last-accepted) on main
Brings the G-Chain consensus init fix (deployed as v1.30.72) onto main. graphvm
resolves a deterministic genesis last-accepted block so the G chain creates
cleanly over ZAP. Full build CGO_ENABLED=0 clean.
2026-06-26 18:05:06 -07:00
zeekay 58f1e04928 fix(chains): drive REAL initial sync — empty/behind C-Chain node fetches+executes to the frontier
The node declared a chain 'bootstrapped' the instant the engine started, at
whatever LOCAL last-accepted height it had: monitorBootstrap polled
engine.IsBootstrapped() which Start() sets true immediately (genesis for an empty
DB, the partial height for a behind node). No block-fetch sync ever ran, so an
empty luxd-0 stuck at C-Chain height 0 ('finished bootstrapping pollCount=1',
fetched nothing) and a behind node stuck at its partial height while the producers
held the full chain.

Wire the consensus bootstrap loop (engine/chain/bootstrap) over the EXISTING node
transport. The blockHandler becomes the loop's BlockSource (fetch) AND Chain
(execute), in a new file bootstrap_sync.go (compile-asserted against both
interfaces):
  - FrontierTip / Ancestors: synchronous adapters over GetAcceptedFrontier /
    GetAncestors, correlating the async replies through bsFrontierCh / bsAncestorCh.
  - ParseBlock / LastAccepted / Has / AcceptBootstrapBlock: the execute sink
    (AcceptBootstrapBlock delegates to the engine's frontier-trust accept authority).
  - runBootstrapThenPoll: runs the loop to the frontier, ENDS the engine's bootstrap
    phase (FinishBootstrap — only the α-of-K cert-gate finalizes thereafter), flips
    bootstrapDone, THEN starts the live frontier poller. On stall it leaves
    bootstrapDone false so monitorBootstrap surfaces a real failure (never masks).

manager.go (minimal hooks): AcceptedFrontier + handleContext route replies to the
loop while bsActive (else the live cert/vote path is unchanged); buildChain starts
runBootstrapThenPoll instead of the bare poller; monitorBootstrap GATES the chain on
the handler's real BootstrapComplete() (initial sync reached the frontier), not the
engine's premature 'am I started' flag.

Tests (node, via the go.work workspace -> local consensus): an EMPTY node converges
genesis->50 over the real GetAcceptedFrontier/GetAncestors path; an invalid block
HALTS sync at the block below it; framing round-trip; reply gating. Existing chains +
op-table suites stay green.

Depends on the consensus feat/chain-bootstrap-fetch-execute branch (new
AcceptBootstrapBlock / FinishBootstrap / bootstrap pkg). Integrated for dev via
go.work (use ./consensus); DEPLOY = tag consensus (next patch) + bump this require +
keep go.mod pinned (no committed local replace).
2026-06-26 16:08:15 -07:00
zeekay dc81a2fa35 docs(vms): subnet->L1 + Avalanche->UTXO language in platformvm/xvm comments 2026-06-26 15:32:22 -07:00
zeekay cc360a9120 fix(chains): bound pendingContext (RED HIGH DoS) + reap stale (MEDIUM re-strand) + poller lifecycle ctx (LOW)
RED review of cert-carry catch-up found the frontier-sync wiring let a Byzantine
peer flood AcceptedFrontier with distinct tips -> unbounded pendingContext -> OOM.
requestContext now reaps entries past pendingContextTTL (30s) and hard-caps at
maxPendingContext (4096); the frontier poller now stops with the chain (no leak).
Cert-gate/ordering/wire safety unchanged (RED: sound). PoC inverted -> regression guard.
2026-06-26 14:35:22 -07:00
zeekay 21e031fef2 deps: pin luxfi/consensus@v1.25.32 (cert-carry catch-up convergence), drop local replace 2026-06-26 14:13:04 -07:00
zeekay b52da648ed fix(chains): wire frontier-sync + cert-carrying catch-up so a stranded validator converges
A validator that fell behind during consensus (mainnet luxd-0/2 at 1082780 while
peers reached 1082797) could not recover at runtime: it received no gossip, and a
restart only bootstraps to its own height. Two node-side gaps, now closed:

GAP 1 — frontier-sync was dead. The GetAcceptedFrontier/AcceptedFrontier responders
existed but HandleInbound had no case for either op, so both fell through (dropped)
and nothing ever ASKED. Add the two cases (mirroring GetContext/Context) and a slow
frontier poller (runFrontierPoller, 15s, small peer sample) so a node proactively
learns it is behind and pulls the gap.

GAP 2 — catch-up could not accept already-finalized blocks. handleContext routed
fetched ancestors through the VOTING Put, but the network will not re-vote a decided
height → the gap blocks wedged. Now each catch-up container pairs the block with its
finality cert (encodeCatchupEntry: magic|blockLen|block|certLen|cert, carried by the
existing Ancestors flattener) and the requester finalizes via engine.AcceptCatchupBlock
(the verified-cert path) when a cert is present, voting only on certless/legacy
entries. The 'LCU2' magic makes a cross-version exchange fail CLEANLY (a legacy
decoder self-rejects; the v2 decoder treats a legacy raw block as legacy).

Pins consensus to the local engine commit (replace ../consensus) for the branch;
reviewer swaps to a pseudo-version. Does not weaken the cert-gate.
2026-06-26 14:02:47 -07:00
zeekay 818f9bf798 fix(consensus): implement GetAcceptedFrontier responder (was a no-op)
A behind node learns the network tip by asking peers GetAcceptedFrontier; the
handler returned nil, so every node received an empty frontier and assumed its
own last-accepted WAS the tip — a node that fell behind could never discover it
and bootstrap stopped at its own height (the mainnet luxd-0/2 stranding: stuck
at 1082780 while peers finalized 1082797; neither gossip nor restart converges
them). Same dead-handler class as GossipOp/catch-up.

This is piece 1 of 3 of the proactive frontier-sync: (1) responder [this commit];
(2) route the AcceptedFrontier RESPONSE to a handler that pulls the gap via the
wired catch-up (needs op-table + HandleInbound wiring, like the GossipOp fix);
(3) a poller that periodically sends GetAcceptedFrontier so a node in consensus
(not just bootstrap) re-checks the frontier. Pieces 2-3 pending — NOT yet
converging; not tagged/deployed until complete + tested.
2026-06-26 13:22:51 -07:00
zeekay ef80498766 fix(consensus): wire the engine's catch-up transport — un-strand behind followers
node built the consensus engine with netCfg.Catchup unset, so the engine's
requestCatchup() hit a nil interface: a follower that fell behind DURING
consensus (it drives blocks by gossip, not Put/PushQuery) could never fetch the
missing ancestors and looped on an unfinalizable orphan forever. Observed live —
after the mainnet RLP recovery, luxd-0/2 stranded at 1082780 while peers reached
1082793. (Bootstrap had GetAncestors wired, so startup sync worked; only the
live-engine transport was unplugged — the same class of gap as the GossipOp
vote-transport bug.)

Fix is the decomplected bridge avalanche's design implies: the engine DECIDES
when to catch up (chain.Catchup); the blockHandler owns the WIRE — it already has
requestContext (send GetAncestors) and handleContext->Put->engine (deliver the
fetched ancestors). networkCatchup routes one to the other through a one-method
ancestorRequester interface (testable, narrow, no consensus/network cross-import),
late-bound at chainInfo construction since the handler wraps the engine. Behind
followers now self-heal without a restart.

RED test: a nil wire leaves calls=0 (the bug); the wired bridge routes
RequestAncestors -> requestContext once, for the missing block and the advertising
peer; + a compile-time guard that *blockHandler stays a valid ancestorRequester.
2026-06-26 11:35:49 -07:00
zeekay 26cfccf72e Merge ZAP-native RPC listener (server/http) into main 2026-06-26 00:55:29 -07:00
zeekay 5258332b2d server/http: vendor-free env name ZAP_RPC_LISTEN (drop LUX_ brand prefix)
Matches the vendor-free convention (no LUX_, no KRAKEND_) — the env knob is
ZAP_RPC_LISTEN, not LUX_ZAP_RPC_LISTEN.
2026-06-26 00:55:03 -07:00
zeekay f16e495e72 server/http: additive opt-in ZAP-RPC listener (zap-proto/http)
Serve the same fully-wrapped /ext/* handler over github.com/zap-proto/http so
the api.<brand> gateway can reach luxd over the native ZAP service mesh instead
of HTTP/1.1. Opt-in via LUX_ZAP_RPC_LISTEN (default off — node upgrades never
silently open a port); HTTP path is byte-for-byte untouched; boot failure is
warned, never fatal.

Tests (server/http): env parsing, disabled→nil, and a REAL zap-proto/http
round-trip POST /ext/bc/C/rpc proving body+Content-Type survive the ZAP wire.
2026-06-26 00:55:03 -07:00
zeekay aaa618d606 deps: bump luxfi/consensus v1.25.30 -> v1.25.31 (dynamic K/α committee clamp)
Pulls the validator-count clamp that scales an oversized consensus committee
down to the live set (fixes testnet finality wedge where TestnetParams K=11/α=8
was unsatisfiable with 5 validators; also protects mainnet from the same brick
when it runs fewer than 21 validators).
2026-06-25 23:00:10 -07:00
zeekay 047982425d merge: integrate docs(LLM) update alongside v1.30.66 op-table bijection 2026-06-25 22:11:29 -07:00
zeekay b72f9edb80 message: prove the op table is a bijection onto the router op space
Kills the bug CLASS behind the α-of-K finality wedge (v1.30.65), not just the
one Gossip instance. The chain router (node/chain_router.go) forwards an inbound
message only if message.ToConsensusOp maps it, then dispatches on the router op;
the node op table and the consensus router op enum are two halves of ONE routing
contract. When they diverged — router.Gossip existed but no node op mapped to it
— every broadcast vote was dropped as "unhandled message op" and finality
wedged, with nothing to catch it.

- ToConsensusOp now returns the router constants (byte(router.Get) ...) instead
  of 0..11 magic numbers, so values cannot drift and the table reads as the
  correspondence it is. Bumps consensus v1.25.29 -> v1.25.30 (adds router.NumOps,
  the single source of truth for the op count).

- message/ops_test.go TestToConsensusOp_TableAlignedWithRouter is now EXHAUSTIVE
  and BIDIRECTIONAL: it reconstructs the inverse mapping over the whole node op
  space and requires a bijection onto [0, router.NumOps). A router op with no
  node preimage (the original bug), a collision, a wrong target, or a stray
  mapping all go RED. Pinned to router.NumOps, so a future op added to one table
  but not the other fails the test instead of at runtime. Proven RED against the
  original bug (drop the GossipOp case -> router.Gossip loses its preimage ->
  fail); folds in the old Gossip-specific and hand-listed table checks.

Build rc=0 (GOWORK=off go build ./...); message tests green; finality fix
(GossipOp -> router.Gossip -> blockHandler.Gossip) unchanged and still covered.
2026-06-25 22:10:09 -07:00
Hanzo Dev 05bdded44b docs(LLM): drop the tenant repo path from UTXO-anomaly note
Genericize the external-consumer example to a white-label tenant's
network-bootstrap tooling; the the tenant repo path belongs only in that
tenant's own repo, never in a lux repo.
2026-06-26 05:06:41 +00:00
zeekay f504b3424f fix(consensus): route GossipOp votes to the engine — un-wedge α-of-K finality
The α-of-K quorum vote/cert transport rides on app-gossip (GossipOp), but
GossipOp was never added to the chain router's consensus-op table
(message.ToConsensusOp) nor to blockHandler.HandleInbound's switch. So every
inbound vote was dropped at node/chain_router.go as "unhandled message op"
before it could reach blockHandler.Gossip -> engine.HandleIncomingVote. Blocks
ride PutOp (mapped) and propagated+verified on all validators; votes ride
GossipOp (unmapped) and vanished. Each node held only its own self-vote, the
cert never reached alpha, and every chain wedged at height N: "verified but
never accepted", no vote/cert/accept activity.

This is the fork divergence from avalanchego, where votes are Chits — a
first-class consensus op always in the router table (snow/engine/snowman
engine.go Chits -> voter -> topological.RecordPoll -> accept). Lux moved votes
onto app-gossip but left the node-side op routing incomplete; the consensus
repo already reserved router.Gossip=11 'routed via the blockHandler Gossip
method' (core/router/router.go) — only the node wiring was missing.

Fix (node-only; safety core untouched — this is purely liveness):
  - message.ToConsensusOp: map GossipOp -> 11 (router.Gossip)
  - blockHandler.HandleInbound: add case handler.Gossip -> b.Gossip(...)

b.Gossip already demuxes the quorum envelope (Mode-gated) into
HandleIncomingVote / HandleIncomingCert; the signed-vote verify + verified-2/3
-stake cert assembly are unchanged, so honest votes now reach the assembler
without weakening VerifyWeighted or the unforgeable cert.

Regression guard (message/ops_test.go): GossipOp must map to router.Gossip, the
full op table must stay aligned with the consensus router, and an inbound vote
gossip must survive router extraction (op + envelope bytes) intact.
2026-06-25 21:24:14 -07:00
zeekay f88033df9c fix(docker): pin chains@v1.3.21 in the EVM-plugin build (evm v1.99.40 -> broken chains v1.3.19)
evm v1.99.40's go.mod pins luxfi/chains v1.3.19, whose dexvm/registry was an
incomplete refactor (forbidden.go deleted) -> AssertNoForbiddenAssetRefs / toHex /
fromHex / looksLikeASCIITickerID undefined -> EVM plugin won't compile. Force
chains@v1.3.21 (forbidden.go restored), matching node's go.mod + the chain-VM
plugin stage. This is the 2nd build blocker after the go.sum re-strip (v1.30.63);
together they should green the build (v1.30.59 -> v1.30.64).
2026-06-25 19:47:19 -07:00
zeekay 21da5b39b5 fix(docker): re-strip first-party go.sum before build (COPY . . clobbered the strip)
The pre-download strip (line 69) fixed go.sum, but `COPY . .` then restored the
committed stale go.sum, so the build hit a SECURITY ERROR when a luxfi/* module was
re-tagged (luxfi/age v1.5.0 here). Re-strip first-party lines right before the build
so -mod=mod re-records current cache hashes. Self-heals every future re-tag.
(v1.30.59 built; v1.30.60/61/62 failed on exactly this.)
2026-06-25 18:53:50 -07:00
zeekay 15cdfd937b consensus parity: X-Chain finalizes via the linear 2/3-stake cert (drop undriven DAG path)
X-Chain was on an undriven, unconfigured DAG engine (test-ID/height-0 vertices, a
handler that dropped every inbound consensus message) — no certificate finality,
no parity with C/D/P. It now runs the same linear consensuschain path as every
other chain: deterministic 2/3-stake BFT certificate finality (AcceptWithCert),
the BFT overlap-bound floor, and the epoch-pinned validator set.

vms/xvm/vm.go: conform *VM to block.ChainVM / consensuschain.BlockBuilder
(Connected/Shutdown/WaitForEvent/HealthCheck), remove GetEngine() and the dead
DAG methods, add the compile-time asserts. X already had a real linear builder
(embedded blockbuilder.Builder, wired in Linearize) — nothing faked.
vms/xvm/health.go: HealthCheck -> chain.HealthResult. vms/xvm/tx.go: deleted
(dead dag.Tx wrapper).
chains/manager.go: linearize DAG-native VMs (X-Chain) into linear block mode
before SetState, wired to the REAL toEngine the cert runtime reads from.
Interface-gated — only VMs implementing Linearize are affected; C/D/P/Q untouched.
With no production VM exposing GetEngine, the undriven DAG dispatch is dead.
vms/dexvm/dexvm.go, vms/types/fee/policy.go: doc corrections (dexvm is
plugin/optional/NFT-gated, linear cert finality; X-Chain UTXO fee is a deliberate
exception to the account-model FlatPolicy floor).

Full node builds; vms/xvm + chains tests green. Parity holds by construction for
C/D/X/Q/Z: one cert path, one finality authority.
2026-06-25 17:17:34 -07:00
zeekay 63ea6b5d98 deps: consensus v1.25.21 -> v1.25.29 (write-path self-heal + L-1 NodeID-dedup) + crypto v1.19.26
v1.25.29 carries the fetch-on-unknown-vote self-heal (c9a70880a) — buffer votes
for untracked blocks, fetch the block, never drop — which fixes the QC-assembly
finality wedge; plus L-1 (dedup buffered votes by NodeID, fail-closed). crypto
v1.19.26 to match consensus' requirement. Completes the v1.30.60 finality set:
α-of-K node wiring (already on main) + engine lifetime-ctx (C1) + engine self-heal.
2026-06-25 16:34:51 -07:00
zeekay 12b80e9352 fix(consensus): engine-start uses lifetime ctx, not 30s timeout (red C1)
chains/manager.go started the consensus engine with a 30s-timeout context;
engine.Start parents all four long-running loops (poll/vote/pipeline/re-poll)
to it, so they died ~30s after each chain started and the quorum cert never
assembled — the finality wedge fixed in v1.30.55 (8b3785c6c1). Restore
Start(context.Background()). Applied on origin/main (full α-of-K wiring intact),
NOT the stale side-branch. Pairs with consensus v1.25.29 self-heal below.
2026-06-25 16:33:29 -07:00
zeekay 6cdd402877 consensus(quasar): real CPU verify-oracle (no rubber-stamp) + ML-DSA 3309 + canonical go.sum
cpuBLSVerify / cpuMLDSAVerify previously did length checks and returned true for
any well-formed input — a no-GPU node would ACCEPT FORGED signatures once LP-210
wires the GPU pipeline into block-accept. Now they perform REAL verification via
luxfi/crypto pure-Go primitives:
 - BLS: bls.Verify after PublicKeyFromCompressedBytes/SignatureFromBytes
   (enforces exact length, on-curve, subgroup membership; malformed => false).
 - ML-DSA: pub.VerifySignature (FIPS-204 nil-context), pk 1952, sig 3309.
 - Corona + ZK: FAIL CLOSED (return false) — luxfi/crypto has no pure-Go verifier
   and the Corona GPU kernel is the known-wrong-prime BLOCKED kernel; never
   rubber-stamp an unverified signature.

ML-DSA signature size corrected 3293 (stale round-3 Dilithium3) -> 3309 (FIPS-204
ML-DSA-65) in MLDSAWork doc + gpuMLDSAVerify flatten width, so the CPU oracle and
GPU path size the signature identically; pinned by TestMLDSA_WorkStructSizeIsCanonical.

Tests rebuilt to carry REAL valid BLS/ML-DSA signatures (was random bytes the old
format-only check accepted). TestCPUVerify_RealOracle proves: valid accepted,
forged rejected, Corona+ZK fail closed. All green.

go.sum: 7 luxfi modules (chains, keys, kms, sdk, staking, zap) had their content
hashes refreshed to the canonical registry values after an upstream re-tag (same
versions, same go.mod — source re-tag only). 'go mod verify' = all modules
verified. Surgical patch (7 lines), minimal go.sum preserved.

(cherry picked from commit e40f04b112f8b5d15223325199db4b981f05878c)
2026-06-25 16:32:30 -07:00
Hanzo AI 2971a56708 deps: reconcile go.sum after brand-scrub re-tag; bump kms v1.11.7, chains v1.3.21 2026-06-24 19:16:20 -07:00
zeekay 65628e3ea3 deps: bump luxfi/crypto v1.19.22 -> v1.19.23 (Proof-of-AI verifier)
v1.19.23 adds the canonical crypto/poi package — the Freivalds compute-proof
verifier (over F_p, p=2^61-1, on the exact int8 accumulator) that the aivm
settlement / aivmbridge precompile path consumes. Purely additive: makes the
PoAI verifier available to luxd. Mirror of hanzo-engine/src/poi.rs.
2026-06-23 14:58:02 -07:00
zeekay 2ccfc8581c deps: bump genesis v1.13.16 — all precompiles active as of Dec 25 2025 (no future-dated mainnet upgrades) 2026-06-23 10:14:05 -07:00
zeekay 8d401fc5b8 release: bump EVM_VERSION v1.99.40 (0x9999 reprocess-bind fix, on-node proven) + deps to latest (chains v1.3.19, precompile v0.5.59, consensus v1.25.21) — no stragglers 2026-06-23 09:32:19 -07:00
zeekay d41ea5e13e deps: bump consensus v1.25.20 -> v1.25.21 (quasar corona v0.7.9 two-value Round1 fix)
Closes the node build break: consensus v1.25.20 called corona v0.7.9's
Round1 single-value but v0.7.9 returns (*Round1Data, error). v1.25.21
threads the error through all quasar round-signer sites.
2026-06-23 09:08:00 -07:00
zeekay d440fda72a release: platform-native build+publish via hanzo.yml (retire GHA)
ONE declarative flow for both lux release artifacts, on platform.hanzo.ai +
self-hosted arcd — NO GitHub Actions:

- hanzo.yml: node image build (matrix linux/{amd64,arm64}, native long-poll
  dispatch onto lux-build-* pools, tag-pattern {{git.branch}} -> :vX.Y.Z).
  Validated against the platform parsePlatformConfig.
- scripts/publish_plugin_set.sh: extracts the 12 baked VM plugins from the
  node image + SHA256SUMS, uploads to s3://lux-plugins-<env>/<pluginset>/
  (operator pluginSource), round-trip sha-verified. DRY — no second compile.
- RELEASE.md: the ONE canonical build+publish runbook; lists the .github
  workflows to retire (docker.yml, release.yml, build*.yml, ci.yml, ...).
- LLM.md: points at RELEASE.md as the canonical release path.

Proof (no GitHub): node:v1.30.40 provenance == 44b67b99a0 (reused, not
rebuilt); evm@v1.99.37 + dexvm@v1.5.15 rebuilt natively on the spark fleet
(go1.26.4, CGO=0) and the full 12-plugin set published to
s3://lux-plugins-staging/ (round-trip verified). neo's lux-plugins-devnet
prefix untouched.
2026-06-23 09:01:48 -07:00
zeekay 60a6c4b2ad Dockerfile: strip first-party go.sum before node go mod download
luxfi re-tagged crypto v1.19.22 (and others) after node go.sum was recorded,
causing 'checksum mismatch / SECURITY ERROR' at the node binary build step and
a cascading -mod=mod fallback to a corona pseudo-version with the old 2-value
Round1 API. Apply the same first-party go.sum strip the EVM/chains/dex plugin
stages already use, so -mod=mod re-records current content hashes for the
re-published modules at their pinned versions (integrity repair, no version drift).
2026-06-23 08:55:02 -07:00
zeekay 44b67b99a0 chore: drop brand token from staking KMS path examples; refresh tools go.sum checksum
config/flags.go + staking/kms.go: the StakingKMSSecretPath example string
referenced a brand-specific devnet path; replaced with the generic
/staking/devnet/node-0 form (lux surfaces carry no white-label brand
tokens). tools/go.sum: corrected the stale charmbracelet/x/ansi v0.9.2 h1
checksum to the canonical value (verified via go mod download).
2026-06-23 01:44:04 -07:00
zeekay cb220f61d4 cmd/pqkeygen: provision strict-PQ staking keypairs for local luxd
Generates the ML-DSA-65 (FIPS 204) staking key + ML-KEM-768 (FIPS 203)
handshake key a strict-PQ local network needs, writing PEM blocks with the
exact types the node config loader expects. Pairs with the SchemeGate /
PQ-handshake path: a strict-PQ chain needs an ML-DSA identity before any
peer can present the gate's pinned scheme.
2026-06-23 01:44:04 -07:00
zeekay 67f38f8c9f network: build SchemeGate under the SAME predicate as the PQ handshake
The per-chain peer.SchemeGate is now built under profileRequiresPQHandshake,
not merely SecurityProfile != nil. Load-bearing: the gate's pinned scheme
byte (SigSchemeMLDSA65) only becomes presentable once the application-layer
ML-KEM+ML-DSA handshake establishes the ML-DSA identity. A permissive /
classical-compat profile still presents secp256k1 cert schemes, which
SchemeGate.Classify refuses unconditionally — building a gate there would
refuse every peer with no PQ handshake to recover (the 0-peers / 'TLS
upgrade failed' stall). One axis, one predicate: gate + handshake + ML-DSA
identity are built together or not at all.
2026-06-23 01:43:53 -07:00
zeekay b88a2e3fac deps: bump consensus v1.25.20 / crypto v1.19.22 / chains v1.3.18 / runtime v1.1.3; wire LocalBFTParams for local dev nets
Publishes the consensus quorum-finality cascade into node:
- consensus v1.25.19 -> v1.25.20 (chain quorum-cert finality, LocalBFTParams)
- crypto v1.19.21 -> v1.19.22 (BLS deserialization/aggregation hardening)
- chains v1.3.17 -> v1.3.18, runtime v1.1.1 -> v1.1.3 (value-path tags)

selectConsensusParams now routes explicitly-local dev networks (devnet 3 /
localnet 1337, EXACT IDs not a range) to consensus.LocalBFTParams (K=4/α=3,
f=1) — the minimal real-BFT committee. Default K=20 is unsatisfiable on a
few localhost validators (α=14 unreachable -> P-Chain freezes at height 0).
K=4 makes quorum reachable while still clearing ValidateForValueNetwork and
the CRITICAL-2 multi-node-is-BFT regression. A custom value L1 (high
networkID) keeps the large Default set. precompile resolves to v0.5.56
(MVS-correct: chains v1.3.18's own requirement; node has no evm/dex dep).

go mod verify: all modules verified; chains quorum params tests green.
2026-06-23 01:43:41 -07:00
zeekay 4150bc12a8 node(chains): receive-side epoch recency gate + bounded heights map + frame discriminator (HIGH-1 b / MEDIUM-3 / LOW-2)
Closes the receive-side gaps the b2 build-side stamping (4c7bab464c) left
open. The build-side epoch stamp max(currentH, parentH) is PROPOSER-ONLY;
a follower must independently re-gate every gossiped block. Three fixes,
one per gap, in the transport wrapper pchain_height_vm.go:

  HIGH-1 (predicate b — RECENCY, upper bound). ParseBlock now rejects a
  framed block whose stamped P-chain epoch H exceeds THIS node's live
  P-chain height by more than pChainHeightRecencySlack (256) — an
  absurd-future epoch a Byzantine proposer claims for a set the network
  has not reached. Rejected fail-closed (errPChainHeightNotRecent): the
  block is dropped, never tracked or voted. This is the UPPER half of the
  epoch bound; the engine-side monotone gate (consensus 7cabd6faa) is the
  LOWER half (>= parent's recorded epoch), so a tracked block's epoch is
  pinned to [parentEpoch, localH+slack]. Fail-soft when no P-chain view
  exists (nil state -> admit; the verifier still fails closed at
  set-resolution) — a defensive path, not a mode.

  MEDIUM-3 (heights-map DoS — WATERMARK PRUNE, not blind LRU). ParseBlock
  runs before the engine dedup/Verify, so a peer can stream distinct
  unverified blocks, each adding a permanent heights entry. Each entry now
  carries its value-chain height; Accept advances a finalized-height
  watermark and prunes every entry at/below it (a finalized block never
  needs a GetBlock epoch re-attach), so the map plateaus under steady
  finality. A hard cap (4096) backstops a sustained unverified flood,
  evicting HIGHEST-height-first so the near-tip pending band survives — a
  still-pending block's epoch is never evicted (a blind LRU could reset it
  to 0 = re-freeze).

  LOW-2 (frame magic DISCRIMINATOR). The 4-byte magic collides at 2^-32
  with the raw hash-prefix some VMs use as Bytes() (dexvm/dchain serialize
  parentID[0:32]||...). A magic match alone no longer means "framed": the
  inner re-parse of the framed payload must ALSO succeed. On re-parse
  failure ParseBlock falls back to a raw whole-block parse — removing the
  bootstrap stall a collision used to cause (mis-framed -> inner decode
  fails closed -> stall on that chain).

TDD pchain_height_hardening_test.go (all pass, CGO_ENABLED=0):
  far-future epoch REJECTED; honest within-slack skew (P-chain advance
  during a staking change) ACCEPTED; nil-state admits; magic-colliding raw
  parses RAW; genuine frame still parses; heights map plateaus at the
  watermark; a pending block is never evicted by the prune; a flood is
  capped preserving the near-tip band. The b2 build-side finality proofs
  still pass (no regression to delivered-epoch stamping).
2026-06-22 23:41:59 -07:00
zeekay 4c7bab464c node(chains): deliver the REAL P-chain epoch height to the chain engine (b2)
THE BUG. A K>1 quorum chain pins its weighted validator set to a P-chain epoch
height (set-root, 2/3-by-stake tally, per-voter pubkey resolution all read at that
one height). The engine reads that height off the VM block via pChainHeightOf,
asserting block.SignedBlock.PChainHeight() — but every plugin VM block (C-Chain
EVM, dexvm) exposes none, so pChainHeightOf returns 0 and the set resolves at
P-chain height 0: the GENESIS set. That is safe (non-empty, identical on every
node, <= current) and unbricks finality, but FREEZES the epoch at genesis: a
validator that JOINED post-genesis is absent from set@0 -> its vote is dropped and
its stake uncounted -> finality cannot track a DYNAMIC validator set, and a
departed genesis majority could collude.

THE FIX (Option b: rpcchainvm zap boundary, NOT a chain-creation-switch rewrite).
pChainHeightVM wraps the chain BlockBuilder so the block the engine sees carries
the proposer's live P-chain epoch height H = max(GetCurrentHeight, parentH),
WITHOUT changing the inner VM's block format, IDs, or ledger state:
  - BuildBlock stamps H and frames the gossiped bytes [magic|H|innerBytes];
  - ParseBlock splits the frame so every follower ADOPTS the identical H (never
    recomputes it from its own skewing P-chain view) -> determinism: every honest
    node derives the SAME epoch height from the SAME signed block, so the cert
    set-root they recompute matches and a post-genesis validator's vote+stake
    count. Raw (unframed) bytes parse with H=0 = the safe genesis fallback.
This is consensus-TRANSPORT framing, not a chain/ledger fork: inner bytes, block
IDs, and execution state are byte-identical -> no re-genesis, only a coordinated
node upgrade. Installed ONLY on K>1 chains (a K==1 chain has no cert/epoch).

Also wires the height-indexed P-Chain validators.State as the SINGLE source of
epoch truth for all four reads (verifier pubkey, stake, total stake, set-root),
all keyed on the block's P-chain height, and FAILS CLOSED if a K>1 chain is built
without a live height-indexed state (a silent permanent-stall wiring bug becomes a
loud refuse-to-start).

TDD (CGO_ENABLED=0, the canonical purego BLS path = ACTUAL production quorum
sources, not an ed25519 stand-in):
  - TestPChainHeightVM_DeliversRealHeight: pChainHeightOf(builtBlock)==H and
    ==H again after a ParseBlock round-trip of the gossiped bytes; a bare inner
    block reads 0 (pins why the wrapper is load-bearing).
  - TestPChainHeightVM_FinalizesAtGenesis: K>1 finalizes against set@0.
  - TestPChainHeightVM_FinalizesAfterStakingChange: validators that JOINED at
    epoch 7 cast the deciding 2/3 votes+stake and the block FINALIZES; the cert
    verifies stake-weighted at 7 and FAILS at 0; the production verifier rejects a
    joiner at height 0 but accepts it at 7. Proven to FAIL without the fix (stamp
    0 -> joiners dropped at set@0 -> VM.Accept never runs = permanent stall).
2026-06-22 22:21:55 -07:00
zeekay 576ab83224 node(chains): height-pin the quorum set-root + stake tally (MEDIUM-1)
MEDIUM-1 liveness regression: validatorSetRootSource.ValidatorSetRoot
ignored the height argument and hashed the Manager's CURRENT GetMap()
snapshot. During a validator-set change (P-chain / L1 staking), the
current map propagates ASYNC relative to a value-chain block-H vote, so
the signer and the assembler held different current maps -> different
set-roots -> the canonical SIGNED message differed -> signatures FAILED
verification -> votes dropped -> finality stalled at every staking change.
The epoch-binding (set-root in the signed message) made this bite.

FIX: read the HEIGHT-INDEXED set from validators.State.GetValidatorSet(
ctx, height, netID) — deterministic across nodes at a given value-chain
height, independent of async current-map skew. The engine already threads
the block height to ValidatorSetRoot(height) via the sole position builder
blockPositionLocked, so sign-side and verify-side read the SAME
height-pinned set.

The stake source (Weight/TotalStake) is pinned to the SAME height too, so
the tally is measured at the same epoch as the signed membership — a
validator whose vote is in a height-H cert contributes its height-H
weight, closing the second skew (a current-map weight read could drop a
legitimately-signed quorum). validatorSetAtHeight is the single shared
epoch read; hashValidatorSet is the single (byte-unchanged) set-root
encoding.

The vote verifier keeps the current-map pubkey lookup (a separate, milder,
self-healing axis — not MEDIUM-1; disclosed for review).

TDD:
  - TestValidatorSetRoot_CrossNodeAgreesDespiteSkew — TWO nodes with a
    set-change in flight (divergent current maps) compute the IDENTICAL
    set-root at height H (the missing cross-node test).
  - TestValidatorSetRoot_HeightSelectsEpoch — root is a deterministic
    function of height.
  - TestValidatorStakeSource_HeightPinned — tally read at the cert height.
  - TestHashValidatorSet_ByteStability — golden, wire format unchanged.
  - TestValidatorSetRoot_FailSoftIsUniform — Empty fallback is uniform.
2026-06-22 19:34:57 -07:00
zeekay 7e4a0c5b84 node(chains): epoch-bind quorum certs + honest stake source (MEDIUM)
Supply the node side of the consensus epoch-binding fix:

- validatorSetRootSource: a deterministic commitment (SHA-256 over the set
  sorted by NodeID, each as nodeID||light||len(pk)||pk) to the chain's active
  weighted validator set. Wired via NetworkConfig.ValidatorSetRoot so the engine
  stamps it into every vote/cert position — a cert is cryptographically pinned to
  the exact set it was certified under, closing cross-epoch cert laundering.
  Empty/absent set => ids.Empty (the unbound answer).

- validatorStakeSource: corrected the misleading "height is advisory" comment.
  The node Manager is single-epoch (no GetValidatorSet(height); that is on
  validators.State), so the source honestly returns CURRENT-epoch weights — which
  is exactly the live in-epoch finality answer (a cert is verified in the same
  epoch it is created). Cross-epoch soundness is enforced at the witness layer by
  the set-root binding above, NOT by guessing unavailable historical stake.

TDD: TestValidatorSetRootSource_DeterministicAndSetSensitive (determinism,
insertion-order independence, weight/membership sensitivity, network scoping,
empty/nil -> Empty) and TestValidatorStakeSource_CurrentEpochWeights.
2026-06-22 18:49:56 -07:00
zeekay 252dfbfd54 node(chains): wire α-of-K quorum topology + BFT params (HIGH-4 / CRITICAL-2)
CRITICAL-2: selectConsensusParams picks a Byzantine-fault-tolerant set for every
sybil-protected (multi-node) net (Mainnet K=21 / Testnet K=11 / Default K=20) —
NEVER LocalParams (K=3/α=2, f=0, single-validator-forkable). Asserted with
ValidateForValueNetwork; chain creation FAILS CLOSED on a non-BFT set.

HIGH-4: networkGossiper implements QuorumGossiper (BroadcastVote/GossipCert over
app-gossip); blockHandler.Gossip demuxes a quorum envelope into the engine's
HandleIncomingVote/HandleIncomingCert (gated on ModeQuorumFinality). The engine
is wired with a BLS VoteVerifier (validator-set pubkey + bls.Verify), a BLS
VoteSigner (staking key), and a validator-stake StakeSource (HIGH-3) for K>1.

Adapters proven against the local consensus engine + real BLS + a real
validators.Manager (standalone module): verifier round-trip/rejections, a real
3-of-4 BLS cert verifies weighted, envelope round-trip, param selection never
K=3 for multi-node. (Full node module compile is blocked on pre-existing,
unrelated sibling go.sum staleness — kms@v1.11.3 / aml consensus@v1.25.17.)
2026-06-22 17:22:34 -07:00
zeekay cebb10fbc6 node: bump EVM_VERSION v1.99.35 -> v1.99.37 (0x9999 ERC-20 Call-surface env fix)
evm v1.99.37 (precompile v0.5.57) wires the 0x9999 ERC-20 Call surface to the
DEX settlement precompile (2cf30e43d) and gates it to the 0x9999/0x9996 settle
family (9579f2e34). Before this a CALL into 0x9999's ERC-20 settle path saw a
nil PrecompileEnv and could not resolve the token-transfer Call seam. v0.5.57
adds the CALL-only DELEGATECALL guard (feeaab5a0). Deps converge to latest
patch within v1.x.x (threshold v1.9.9, crypto v1.19.21, database v1.20.3,
geth v1.17.12, vm v1.2.5, api v1.0.15). Money path (V4 swap ABI, marker
install, dated DexSettleActivationTime fork) byte-unchanged.

Pairs with the baked DEX_REF v1.5.15 (D-Chain committed-state read RPC) for
one coordinated image: native-fill matcher + read RPC + ERC-20 env fix.

Also: harden the lux-accel fetch to authenticate with the ghtok BuildKit
secret (luxcpp/accel is private -> lux-private/accel; unauthenticated 404)
and make it best-effort (matches the cevm/lpm contract) since the GPU lib is
linked only at CGO_ENABLED=1 and the canonical build is CGO_ENABLED=0 pure-Go.

Image: ghcr.io/luxfi/node:v1.30.40 (patch from v1.30.39).
2026-06-22 15:09:16 -07:00
zeekay 5dcd8a7b4f node: bump DEX_REF v1.5.14 -> v1.5.15 (D-Chain committed-state read RPC)
v1.5.15 adds the D-Chain read surface (clob_get_trades/orders/markets/book over
/ext/bc/D/dex/<method>, pkg/dchain/read.go): read-only JSON of the committed
trade log, resting book, and markets, served beside the write methods via
VM.CreateHandlers with zero consensus impact.

Needed to (1) VERIFY a native fill replicated identically across the validator
set — query clob_get_trades on every node and diff the trade rows + accepted
head root — and (2) feed markets-display, since native fills are D-Chain trade:
rows (not C-Chain 0x9999 DEXFills).

Plugin VM id unchanged (mDVT5EWMumBp3LCqvKwuyZQeY1VXr1jvjGNAt8nL4UFiXvqXr); the
change is additive read endpoints, no consensus/state-transition change.
2026-06-22 14:57:04 -07:00
zeekay 4b80d407da node: bump DEX_REF v1.5.13 -> v1.5.14 (prefixdb prefix-iteration fix via database v1.20.4)
dex v1.5.14 consumes luxfi/database v1.20.4, which fixes prefixdb
NewIteratorWithStartAndPrefix synthesizing a pre-prefix start for a nil-start
prefix scan -> ZERO rows over a prefixdb-wrapped chain DB. This stranded the
native D-Chain: rebuildBookFromDB iterated order:<pool> alongside other
sub-prefix rows, folded an EMPTY book, and every taker cross produced 0 fills
despite durably-committed asks. Only the dexvm slot is rebuilt this run (devnet
D-Chain scope); the same database fix likely benefits the other plugin VMs and
is a separate follow-on bump.
2026-06-22 14:12:47 -07:00
zeekay dd5f22cf93 node: bump DEX_REF v1.5.12 -> v1.5.13 (D-Chain consensus stall fix)
dex v1.5.13 indexes processing blocks so the plugin transport's ID-only Accept
(GetBlock(builtID)) resolves the just-built block. Without it the native
D-Chain's self-finalize Accept is a silent no-op, the clob submitTx waiter hangs,
and NO D-Chain blocks are produced — orders submitted to /ext/bc/D/dex/clob_*
never match. Required for native trading to actually produce fills.
2026-06-22 12:28:37 -07:00
zeekay 3ab3fad41e node: bump DEX_REF v1.5.11 -> v1.5.12 (D-Chain restart fix)
dex v1.5.12 persists the head block so the native D-Chain VM survives a restart
once advanced past genesis — without it the first validator to restart fails VM
init ('get last accepted block: not found') and the D-Chain goes down. Required
for a 5-validator rolling restart of the native matcher.
2026-06-22 11:41:32 -07:00
zeekay ac22514f3d node: bump DEX_REF v1.5.10 -> v1.5.11 (native D-Chain CLOB ingestion)
dex v1.5.11 wires CLOB order ingestion over the node HTTP router
(pkg/dchain VM.CreateHandlers -> /ext/bc/D/dex/<method>). An order POSTed to
/ext/bc/D/dex/clob_submit flows submitTx -> mempool -> consensus -> BuildBlock
-> Verify(match) -> Accept; the chain is the matcher, no venue, no keeper.

Plugin stage rebuilds (ARG change invalidates the dexvm slot cache); node
go.mod is unaffected (the plugin is built from dex's own module, -mod=mod).
2026-06-22 11:17:45 -07:00
zeekay 36b9fb26f4 node: D-Chain (dexvm) plugin = native consensus matcher VM (dex/cmd/dchain)
The D-Chain runs as a PluginDir plugin loaded by luxd at the dexvm vmID
(mDVT5EWMumBp3LCqvKwuyZQeY1VXr1jvjGNAt8nL4UFiXvqXr). Until now that slot was
built from chains/dexvm/cmd/plugin — the STATELESS PROXY that relayed clob_*
frames over ZAP to a standalone dchain-venue (DexZapEndpoint). Matching did
NOT happen in luxd consensus; it happened in the external venue's single-node
sealer.

Build the dexvm slot from github.com/luxfi/dex@v1.5.10 ./cmd/dchain instead:
the NATIVE VM (pkg/dchain, block.ChainVM) that runs the lx.OrderBook matcher
INSIDE luxd consensus — BuildBlock drains the mempool, Block.Verify matches
against a versiondb overlay, Block.Accept commits. The trade IS the D-Chain
state transition, sequenced by luxd's multi-validator engine. No
DexZapEndpoint, no standalone venue in the trading path.

cmd/dchain wraps the VM in the same rpc.Serve plugin harness luxfi/evm uses
and is pure-Go (CGO=0); same GOFLAGS/go.sum-heal pattern as CHAINS_REF. The
other 10 chains VMs still build from chains. New ARG DEX_REF=v1.5.10; a FATAL
guard fails the build if the native D-Chain plugin is missing. Verified: a
fresh v1.5.10 clone builds ./cmd/dchain CGO=0 -mod=mod in Docker-like
isolation; native VM suite (TestLocalnetVenueE2E/TestFourPath/conservation)
passes.
2026-06-22 03:44:08 -07:00
Antje Worring 7f507e7236 deps: chains v1.3.16 -> v1.3.17 (consensus v1.25.19 Round1 fix) + hanzoai sumdb exclusion
Two CI-image-build blockers fixed: (1) chains v1.3.16 pinned consensus v1.25.18
which calls the old single-value corona Round1 -> quantumvm plugin compile break;
v1.3.17 bumps consensus to v1.25.19 (Round1 returns error). (2) hanzoai/* excluded
from sumdb/proxy (404 on hanzoai/vfs go.mod). All 11 VM plugins build; luxd 57MB.
2026-06-22 03:12:58 -07:00
Antje Worring b22cdd965c fix(docker): exclude hanzoai/* from sumdb+proxy (unblocks image build)
The CI Docker build failed reading hanzoai/vfs@v0.4.1's go.mod via the public
sum.golang.org (404 — it's a cross-org module not registered there), same class
as luxfi/*. Added github.com/hanzoai/* to GONOSUMCHECK/GONOSUMDB/GONOPROXY.
Verified: clean 'go mod download hanzoai/vfs@v0.4.1' 404s without the exclusion,
succeeds with it. Unblocks ghcr.io/luxfi/node image builds (v1.30.30/31 failed).
2026-06-22 03:04:10 -07:00
zeekay 6a8a4f3a36 deps: consume chains v1.3.16 (dexvm dex.submitTx + dex.getSettlement RPC seam)
The dexvm plugin gains the C<->D keeper RPC seam: dex.submitTx (mempool entry for
ImportTx + settling RelayOrderTx) and dex.getSettlement (D->C proceeds coordinate
for Phase-B). Bumps go.mod luxfi/chains v1.3.15->v1.3.16 AND Dockerfile CHAINS_REF
v1.3.14->v1.3.16 so the bundled dexvm plugin is rebuilt with the new RPC. go mod
verify clean; dexvm plugin builds from the v1.3.16 tag (CI mode).
2026-06-22 02:47:26 -07:00
zeekay fce22b514c deps: consume chains v1.3.15 (dexvm) + precompile v0.5.56 + evm v1.99.36 (DEX swap-seam r2 release) 2026-06-21 22:49:22 -07:00
zeekay 5fc1ca8e04 deps: converge threshold v1.9.9 + crypto v1.19.21 + database v1.20.3 + geth v1.17.12 + warp v1.19.5 + metric v1.5.9 + proto v1.3.5 (latest patch within v1.x.x) 2026-06-21 22:45:48 -07:00
Antje Worring ff978498c0 deps(pq): consume finalized PQ crypto via consensus v1.25.19
Bumps consensus v1.25.18 -> v1.25.19 (the latest-crypto floor: pulsar v1.1.5,
magnetar v1.2.3, threshold v1.9.9, corona v0.7.9 + the 2-value Round1 API).
luxd builds (57MB), warp/PQ verifier tests green. node calls no Round1 directly
(stable crypto/threshold scheme registry).
2026-06-21 22:35:33 -07:00
zeekay e46f99c633 ci(build.yml): goreleaser must use cross-org PAT, not repo github.token
The routing + insteadOf fixes got goreleaser onto lux-build with git auth,
but it still failed: 'could not read Password ... exit 128' fetching
luxfi/{container,crypto,database,proto}. github.token is repo-scoped and
cannot read OTHER private luxfi repos. Switch to the same cross-org PAT
docker.yml uses (GH_TOKEN/UNIVERSE_PAT) so cross-repo module fetches
authenticate. node already carries UNIVERSE_PAT as a repo secret.
2026-06-21 15:11:17 -07:00
zeekay 8432ce6981 ci(build.yml): add private-module git auth before goreleaser
goreleaser shells out to go build, which fetches private luxfi modules
(container, crypto, proto, ...). setup-go-for-project sets GOPRIVATE but
only wires git auth when passed a github-token (build.yml passes none), so
the fetch hit 'could not read Username for https://github.com' and the job
failed even on lux-build. Add the same explicit 'Configure Git for private
modules' step ci.yml uses (git config url.insteadOf with github.token).

This is the real root cause of the 'Build on supported platforms' red-X;
the routing-to-lux-build commit was necessary but not sufficient.
2026-06-21 15:04:48 -07:00
zeekay bb8d7662b9 ci: route goreleaser + release validate/create off ubuntu-latest to lux-build ARC
The v1.30.28 docker.yml run published node:v1.30.28 (sha-c36527c) fine on
the in-cluster lux-build ARC pool, but two sibling workflows red-X'd:

  - build.yml 'goreleaser' (runs on every push)
  - release.yml 'validate-version' (cascaded skips to every platform build)

Root cause: both pinned runs-on: ubuntu-latest. This org disables
GitHub-hosted runners (NO GITHUB BUILDERS) — ubuntu-latest jobs never get a
runner and fail at provisioning, not at compile. Source is sound:
GOWORK=off CGO_ENABLED=0 go build ./... is clean and the cross-layer
dexsettle_guard test passes (extras.DexSettleActivationTime ==
dex.DexSettleActivationTime == 1766704800 = 2025-12-25T23:20:00Z).

Route goreleaser, validate-version, and create-release to lux-build (the
org-scoped autoscalingrunnerset in lux-k8s that already builds the image).
GoReleaser cross-compiles every GOOS/GOARCH from one linux/amd64 host with
CGO disabled, so a single amd64 runner suffices.

(The per-platform binary reusables build-{ubuntu,linux,macos,win}-* still
pin classic [self-hosted,linux,amd64]/windows-2022 labels — a pre-existing
routing issue tracked separately; the node *image* path is unaffected.)
2026-06-21 14:58:25 -07:00
zeekay c36527ce2a node: bump EVM_VERSION v1.99.34 -> v1.99.35 (native 0x9999 DEXFill/Initialize indexing) (v1.30.28)
evm v1.99.35 pins precompile v0.5.55, which emits the DEXFill + V4 Initialize
logs the explorer's DEX graph indexes — Dec-25-2025 activation-gated (same
dated fork as 0x9999 dispatch; no fork risk). EVM_VM_ID unchanged (money path
byte-identical). Plugin pulls precompile v0.5.55 transitively via the evm clone.
2026-06-21 14:29:19 -07:00
zeekay 813a6596ff node: bump C-Chain EVM plugin to v1.99.34 — 0x9999 replay consensus-divergence fix (v1.30.27)
EVM_VERSION v1.99.33 -> v1.99.34 (precompile v0.5.53 -> v0.5.54). v1.99.34 fixes
the ONE HIGH from Red's review of the 0x9999 dated-fork activation that blocked
the production deploy: the EVM dispatch gate read a process-global timestamp
(last-writer-wins across concurrent goroutines), so on the relaunch path
(admin.importChain of a pre-fork RLP snapshot on a live, RPC-serving post-fork
node) a concurrent post-fork eth_call could make a pre-fork block see 0x9999
ENABLED and dispatch settlement during plain-account execution -> state
divergence. The gate now reads the overrider's own per-EVM (chainConfig,
timestamp). Also: SubBalance fallback fails closed (no silent native mint) and
the genesis-config builders skip AlwaysOn modules (0x9999 can't get a
timestamp-0 genesis config that bypasses the dated fork). Money path
byte-for-byte unchanged. This unblocks the production deploy.
2026-06-21 12:41:01 -07:00
zeekay 7a555d9cb1 Merge: node EVM_VERSION v1.99.33 — 0x9999 dated-fork activation (v1.30.26) 2026-06-21 12:13:01 -07:00
zeekay a5bed03d83 node: EVM_VERSION v1.99.33 — 0x9999 dated-fork activation + 0x9010 removal (v1.30.26)
Bundle the C-Chain EVM plugin built from luxfi/evm v1.99.33 (precompile v0.5.53):
0x9999 DEX settlement now activates at a SINGLE canonical dated fork
(extras.DexSettleActivationTime = 1766704800, Dec 25 2025) instead of the v1.99.32
unconditional always-on. At the fork it BOTH enables dispatch AND installs the
EXTCODESIZE marker forward (never in historical genesis), so:
  - eth_getCode(0x9999) != 0x and typed Solidity IPoolManager(0x9999).swap(...)
    passes the contract-existence guard from the activation block onward;
  - pre-Dec-25 history replays byte-identically (the ~/work/lux/state RLP snapshot
    via admin.importChain) — a pre-fork value transfer to 0x9999 hits a PLAIN
    account, not the precompile, so canonical pre-activation state is preserved;
  - the C-Chain genesis hash is unchanged (no genesis-time marker).
0x9010 is REMOVED entirely (not a registered precompile, no dispatch, no forward);
0x9999 is the SOLE canonical DEX precompile. Runtime DChainID via the "D" alias and
the built-in DAO-treasury protocolFeeController are unchanged.

deps: indirect precompile v0.5.52 -> v0.5.53 (go.sum tidied: stale v0.5.52 hashes
dropped; v0.5.53 hash matches the evm/precompile repos byte-for-byte). node main
builds clean GOWORK=off; go mod verify OK; go mod tidy is a no-op on go.mod.
2026-06-21 12:13:01 -07:00
zeekay ace60dc05e Merge: node EVM_VERSION v1.99.32 — 0x9999 always-on DEX settlement (v1.30.25) 2026-06-21 09:23:55 -07:00
zeekay 81fb68e54d node: EVM_VERSION v1.99.32 — 0x9999 always-on DEX settlement (v1.30.25)
Bump the bundled C-Chain EVM plugin to v1.99.32 (precompile v0.5.52): the native
0x9999 DEX settlement money path is now ALWAYS-ON. It is active on the C-Chain from
genesis with ZERO per-net config — no dexSettleConfig genesis/upgrade entry anywhere.
Booting luxd = 0x9999 live on the C-Chain, on every Lux network.

Activation is dispatch-only (no genesis state write → genesis hash unchanged → no
fork of any existing network). The D-Chain (dexvm) peer the atomic seam routes to is
resolved at RUNTIME from the consensus-context "D" alias the node already registers in
initChainAliases (chains/manager.go BCLookup), via contract.AtomicState.DChainID().
The protocolFeeController is the built-in DAO treasury. Nothing per-net to configure.

Dockerfile: ARG EVM_VERSION v1.99.31 -> v1.99.32 (the plugin is built from this tag).
go.mod/go.sum: indirect luxfi/precompile v0.5.51 -> v0.5.52 (keeps node's transitive
graph in lockstep with the plugin; node main builds clean GOWORK=off, go mod verify OK).
2026-06-21 09:23:48 -07:00
zeekay 1b11873b86 Dockerfile: bundle the native-atomic DEX plugins (evm v1.99.31 + chains v1.3.14)
The bundled C-Chain EVM + 11 VM plugins were pinned at stale defaults
(EVM_VERSION=v0.19.4, CHAINS_REF=v1.3.11) decoupled from node's go.mod, so every
node image shipped the OLD DEX (no native 0x9999) even after the cascade bumped
node->chains v1.3.14. Pin both to the native-atomic seam + document the coupling.
No node code change vs v1.30.23.
2026-06-21 07:51:11 -07:00
zeekay 09fea02bec deps: bump chains v1.3.14 (DEX native-atomic-seam: geth v1.17.12 + precompile v0.5.51 promoted) for v1.30.23 2026-06-21 07:22:37 -07:00
zeekay 050e7c866a deps: chains v1.3.13 (evm v1.99.30 + precompile v0.5.50, all clean go.sum)
Bump to the clean-go.sum re-cascade so node, plugins, and all upstream modules
build identically in clean CI. No node code change vs v1.30.21. go mod verify
clean; full build green.
2026-06-20 22:14:23 -07:00
zeekay d074ce21d0 go.sum: correct consensus/geth hashes (clean-cache fetch; v1.30.20's were stale)
v1.30.20's go.sum carried stale consensus@v1.25.18 + geth@v1.17.11 hashes that a
locally-polluted module cache (modified extracted dirs) had produced — the in-CI
docker `go mod download` rejected them (checksum mismatch). Purged the modcache,
re-fetched fresh, and `go mod verify` is clean ("all modules verified"). No
go.mod/dep change vs v1.30.20; the node binary is identical. This is the first
buildable tag of this node code.
2026-06-20 21:37:31 -07:00
zeekay b35423d045 ci(docker): build node image on the in-cluster lux-build ARC pool
The evo classic self-hosted runner is offline and GitHub-hosted runners are
billing-blocked (and disallowed by the NO-GITHUB-BUILDERS policy). Point the
image build at the lux-build autoscalingrunnerset (lux-k8s, amd64 DOKS, DinD)
— it serves the whole luxfi org and matches on the scale-set name. No node
binary/dep change vs v1.30.19; this is a build-infra patch.
2026-06-20 21:17:14 -07:00
zeekay dbab65e4cb deps: chains v1.3.12 -> hardened 0x9999 DEX receipt-settlement (precompile v0.5.49, evm v1.99.29)
Bump github.com/luxfi/chains v1.3.11 -> v1.3.12, pulling evm v1.99.29 (DexZap
live-backend wiring removed) and precompile v0.5.49 (complete, red-swarm-hardened
0x9999 V4 receipt-settlement surface) into the C-Chain. The C-Chain DEX precompile
now settles BLS-certified D-Chain fill receipts inline (deterministic, fork-safe);
the dexvm remains the D-Chain matcher.

Regenerate go.sum: the 2026-06-19 consensus geth-pin re-tag cascade left several
luxfi module hashes (consensus v1.25.18, geth v1.17.11, ...) stale. Re-recorded
from current tags (public deps verified via sumdb, luxfi via GOPRIVATE direct).
consensus v1.25.18 and geth v1.17.11 pins unchanged.
2026-06-20 15:05:31 -07:00
zeekay f15bbe9971 Dockerfile: bump GO_VERSION 1.26.1 -> 1.26.4 (match go.mod; EVM plugin floors at 1.26.4 via luxfi/upgrade@v1.0.1) 2026-06-20 01:25:08 -07:00
zeekay d329b7a5e2 genesis/builder: A/G/K as deterministic genesis chains -> v1.30.18
Append aivm(A)/graphvm(G)/keyvm(K) to genesis chainEntries after Z so the
existing X->C->D->B->T->Q->Z blockchain IDs are preserved; A/G/K take fresh
tail IDs. They carry a/g/kChainGenesis blobs and are deterministic genesis
chains per the no-CreateChainTx model (prior code deferred them to
post-genesis CreateChainTx). I/O/R have no blob and stay plugin-loaded.
2026-06-20 00:53:03 -07:00
zeekay 05b02e925f deps+build: chains v1.3.11 bridge BLS fix + plugin-build heal → node v1.30.17
ROOT FIX (B-Chain): chains v1.3.11 bridgevm/mpc.go blank-imports
github.com/luxfi/crypto/threshold/bls so the bls init() registers the BLS
threshold scheme, fixing the B-Chain VM init regression
(threshold.GetScheme(SchemeBLS): 'scheme not registered') that aborted the
v1.30.16 devnet roll. Verified bls init/RegisterScheme symbols + itab linked
into the bridgevm plugin binary.

go.mod: pin chains v1.3.10 -> v1.3.11 (no other version moves; MVS keeps
crypto v1.19.21, geth v1.17.11, consensus v1.25.18).

go.sum: re-record current content hashes for re-published luxfi modules
(geth/precompile/etc) at EXISTING pinned versions — integrity repair, no
version bump. Fixes clean-room 'go mod download' checksum drift.

Dockerfile plugin builds (embedded plugins ARE authoritative — devnet
startup does cp /luxd/build/plugins/* then --plugin-dir):
  - EVM/C-Chain: EVM_VERSION v0.19.3 -> v0.19.4; heal dead upgrade
    pseudo-version to released v1.0.1; recursive go.sum strip.
  - chains VMs: CHAINS_REF default -> v1.3.11; recursive go.sum strip;
    bridgevm build made FATAL (was best-effort) + presence assertion so the
    image cannot ship without a working B-Chain plugin.
All 11 chains VM plugins + evm plugin verified to build (golang:1.26.4,
linux/amd64). lux-devnet only; testnet/mainnet stay v1.30.3.
2026-06-19 21:03:55 -07:00
zeekay 878e15007f deps: pin geth v1.17.11 + consensus v1.25.18 + chains v1.3.10 (real semver); MVS-propagate transitive bumps (evm v1.99.28, precompile v0.5.47) 2026-06-19 14:45:57 -07:00
zeekay f6d1eef71b Merge node/plugin-nft-gate: all-VMs-as-plugins + X-NFT-gated activation 2026-06-19 14:28:26 -07:00
zeekay 41c75fae65 node: all-VMs-as-plugins core/optional split + X-NFT-gated activation
Explicit CoreVMs{P,X,Q,Z} in-process + OptionalVMs plugin-only (no build tags; vms_dchain/nodchain removed). Two-layer anti-shadow (init panic + runtime ListFactories guard). NFT-gated activation at createChain (manager_authz), fail-closed; dex-validator flag gates D-Chain tracking; xvm.GetUTXOs locked.
2026-06-19 11:34:41 -07:00
zeekay 1b2122900c deps: bump vm v1.2.0→v1.2.4 (rpc/zap zapdb harness)
Pick up the rpc.Serve plugin harness now opening chainstate via zapdb.New
(single-backend rule) instead of badgerdb.New — same on-disk format, drop-in.
Transitive api v1.0.14→v1.0.15 (within v1, no major bump). chains stays
v1.3.9. Verified: public 'go build ./node/' green; '-tags dchain' green;
public-purity 'go list -deps ./node/' has ZERO chains/dexvm|luxfi/dex; the
-tags dchain build DOES link the dexvm proxy (orthogonality holds).
2026-06-17 23:58:23 -07:00
zeekay d5871237f6 node: bump luxfi/chains v1.3.8 → v1.3.9 (atomic custody rail) 2026-06-17 21:11:22 -07:00
zeekay 401d9d342f node: bump luxfi/zapdb v1.10.0 → v1.10.1 (cloud-free, cgo blocker resolved on v1 lineage) 2026-06-17 19:30:22 -07:00
zeekay 1fcf60d584 node: pin chains v1.3.6 -> v1.3.8 (the released proxy + #9 carried-fills consensus fix)
Production node -tags dchain now links the released chains v1.3.8 (stateless atomic ZAP proxy +
the #9 consensus-fork fix), not the stale v1.3.6. Public build stays pure (zero dex/dchain/gpu
deps); dchain build links the 6 chains/dexvm proxy pkgs. Transitive: oracle v0.1.1->v1.0.0,
relay ->v1.0.0 (chains v1.3.8 requirements; first-stable, within v1).
2026-06-17 17:52:10 -07:00
zeekay 80f43c4d29 Merge origin/main into xvm-merkle-activation integration
# Conflicts:
#	go.mod
2026-06-17 17:14:12 -07:00
zeekay a787320fff Merge xvm-merkle-activation: dchain build-tag split (public build excludes D-Chain) + merkle-activation 2026-06-17 17:12:59 -07:00
zeekay ad7d6dfaa6 node: dchain build-tag split -- public build excludes D-Chain + private deps
vms.go drops the dexvm import+entry, calls appendDChainVM; vms_dchain.go (//go:build dchain)
links it, vms_nodchain.go (//go:build !dchain) no-ops; vms/dexvm alias gated //go:build
dchain + doc_nodchain.go placeholder. Genesis-gate (constants.DexVMID, no pkg dep) retained.
VERIFIED: public 'go list -deps ./node/' has ZERO chains/dexvm|luxfi/dex|gpu-kernels|luxcpp;
-tags dchain brings them in. Both builds green.

Consensus change -- held for human review before merge/push (bundles with merkle-activation).
2026-06-17 13:31:58 -07:00
Antje WorringandHanzo Dev 67e198ad93 docs: tidy LLM.md indexes; CLAUDE.md -> LLM.md symlink convention
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-17 09:58:24 -07:00
zeekay 14f638c918 xvm: remove execution_root activation gate — values not gates (active, not gated)
The prior seam added a bespoke MerkleRootActivationHeight gate (default
MerkleRootNeverActivate=MaxUint64) that violated upgrade/upgrade.go's stated
philosophy ('activate-all-implicitly; the fields encode values, not gates').
Removed it entirely (grep-clean): the builder ALWAYS stamps the real xvm
execution_root, the executor ALWAYS recomputes+verifies it, an empty root is
now rejected. Root computation byte-IDENTICAL (exec_root=4f144ef7…) — only the
gating is gone. Net -92 lines. Tests converted to always-active reality
(empty-root-rejected is the new gate test); ./vms/xvm/... + ./upgrade/... green
uncached + -race. asset_root stays keccak256("") (UTXO-only executor; assets
bound via each UTXO's AssetID).
2026-06-16 12:59:21 -07:00
zeekay c28796b2f0 xvm: activation-readiness — real UTXO leaf projection + state iterator (gate OFF)
Closes the nil-projection seam in the activation-gated merkleRoot wiring (2fd9bc29):
- state/iterator.go: UTXOs(start,limit) on ReadOnlyChain (state + diff) — ascending
  canonical order + ordered overlay merge.
- block/executor: real post-block UTXO leaf projection; canonical OwnerRoot =
  keccak256(threshold_le || key_count_le || sorted_keys); BlockExecutionRoot now
  returns (ids.ID, error) so a projection/enumeration failure surfaces, not a wrong root.
- ownerroot.go canonical derivation; 16 new tests, -race clean; full ./vms/xvm/... green.

Gate stays OFF (MerkleRootActivationHeight = math.MaxUint64) — NO live consensus change.
Asset family intentionally empty (asset_root=keccak256("")); xvm executor is UTXO-only,
so a faithful asset-arena projection needs an asset-arena state model first — flagged
for human ratification. Consensus-main merge is a human decision.
2026-06-16 12:04:19 -07:00
Hanzo DevandGitHub 90a33c4918 Merge pull request #141 from luxfi/feat/database-v1.20.3-native-replication
deps: bump luxfi/database -> v1.20.3 (native ZAP replication)
2026-06-15 19:42:46 -07:00
hanzo-dev fb8b857cd1 deps: bump luxfi/database v1.19.2 -> v1.20.3 (native ZAP replication)
Brings native ZAP replication into the luxd binary: CDC change-feed incrementals
(no keyspace scan), physical SST-copy snapshots, post-quantum (ML-KEM-768) at-rest
encryption, per-DB streams, restore-on-boot, and the backer/restorer split. The
node reads it all from REPLICATE_* env (operator-driven) — every chain's ZapDB
backs up continuously and a fresh node launches from the latest snapshot.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-16 02:42:28 +00:00
zeekay 2fd9bc29c8 xvm: parallel intra-block execution_root + activation-gated merkleRoot wiring (DEFAULT OFF)
Core goal — build the xvm block state root from independently-built
subtrees in parallel, and wire it into the block path behind an
off-by-default activation gate (zero live-consensus change).

Parallel build (vms/xvm/block/executor/executionroot.go): the three
family folds (utxo/asset/tx) run concurrently; each folds via a
GOMAXPROCS worker-pool RFC-6962 level reduction composed from
crypto/merkle's exported LeafHash/NodeHash (no duplicated keccak/tag —
DRY). Byte-IDENTICAL to the serial xvmroot.ExecutionRoot: canonical leaf
order + count-determined combine shape are unchanged; only the per-index
loops parallelize (disjoint-slot writes). Proven by 200-random +
sizes-0..4097 byte-identity tests, race-clean (go test -race).
Benchmark (M1 Max, 65536 UTXOs): execution_root 87.4ms -> 19.1ms (4.58x).

Gated wiring: upgrade.Config.MerkleRootActivationHeight defaults to
MerkleRootNeverActivate (math.MaxUint64) on Mainnet/Testnet/Default AND
xvm.DefaultConfig (safety-critical — VM.initialize discards init.Upgrade,
so without the default the zero value would activate from genesis).
Below activation: builder leaves Root=ids.Empty + executor keeps the
verbatim reject-if-non-empty rule (byte-for-byte current behavior, tested).
At/above: builder stamps BlockExecutionRoot; executor recomputes + verifies
(rejects mismatch). nil-safe (nil config -> OFF).

HONEST SEAM — NOT ACTIVATION-READY: postBlockUTXOLeaves/postBlockAssetLeaves
return nil. A real projection needs (1) a committed mapping from the
executor codec lux.UTXO/asset types to the GPU-snapshot leaf fields
(OwnerRoot/AmountHi/Threshold/TotalSupply/...), and (2) a full-occupied-set
state enumeration API (only GetUTXO/per-address UTXOIDs exist today). Both
are consensus-semantics decisions deliberately NOT auto-invented (would be
unverified non-parity slop). So today the root commits to parent + EMPTY
utxo/asset roots + the (correct) tx family + height. Consensus-inert
because the gate is OFF; builder and verifier call the identical projection
so stamped==verified always. A human must ratify the projection + wire a
state iterator + GPU snapshot producer before any activation height is set.

Additive constructor NewStandardBlockWithRoot (NewStandardBlock = its
empty-root case). xvmroot gained 3 byte-transparent exported leaf-digest
accessors (KAT 4f144ef7 unchanged) so the parallel fold reuses the one
canonical preimage. CGO_ENABLED=0 clean; go test ./vms/xvm/... ./upgrade/
PASS. Local commit; not pushed (consensus repo — awaiting human review of
the activation seam).
2026-06-15 18:07:50 -07:00
zeekay 88f5d52fa6 vms/bridgevm/state/bridgevmroot: native-Go bridgevm state-root mirror + GPU parity KAT
Symmetric with vms/xvm/state/xvmroot — the native-Go authority for the
bridgevm_transition root. Computes all 5 family sub-roots (signer_set /
liquidity / inbox / outbox / daily_limit) via luxfi/crypto/merkle
(RFC-6962 tagged tree) over the post-transition leaf field values, plus
the §6 compose (parent ‖ 5 roots ‖ epoch ‖ bond_lo ‖ bond_hi ‖ active).
Full 128-bit bond aggregate (matches the GPU MED-1 fix — bond_hi never
dropped). Keccak via luxfi/crypto/hash NewLegacyKeccak256 (NOT sha3.Sum256).

Byte-for-byte parity with all 7 GPU backends (e303e3c): mixed
signer_root=c9812fee… state_root=6c973a55… bond_hi=0; dense-signer
N=5/9/17 bond_hi=29/71/203. 9 tests PASS, CGO_ENABLED=0 clean. Pure
computation + tests; not wired into consensus (the gated wiring is the
separate xvm/bridgevm builder+executor phase).
2026-06-15 17:53:39 -07:00
zeekay 89d28de6cc xvm/state/xvmroot: native-Go execution_root mirror + Go==GPU parity KAT
Pure-computation Go mirror of the GPU xvm_root_update tree fold (utxo/
asset/tx Merkle sub-roots via luxfi/crypto/merkle + un-tagged keccak
compose). Byte-for-byte parity with all 7 GPU backends, anchored on the
shared KAT fixture (exec_root 4f144ef7, i%3 tx-status pattern matching
test_xvm_roots_kat.cpp). Bumps luxfi/crypto v1.19.17->v1.19.21 (publishes
the merkle + keccak packages); parity test passes in clean module mode
(GOWORK=off). NOT wired into block validity yet — computation+test only;
the activation-gated executor wiring is the next phase.
2026-06-15 16:43:03 -07:00
zeekay c7caa54c37 health: atomic buffered GET reply; tolerate invalid UTF-8 in check details
jsonv2 MarshalWrite streams straight to the ResponseWriter and rejects
invalid UTF-8 mid-stream. A check whose Details embeds raw chain-ID
bytes tore the reply: clients got truncated JSON with a Content-Length
matching the truncation. Buffer the marshal so the reply is atomic,
allow invalid UTF-8 as replacement runes, and emit an explicit
encode-failure body instead of a torn one.
2026-06-10 21:53:44 -07:00
zeekay 631fc5fa8c ci: route to canonical native arcd labels [self-hosted, linux, <arch>]
Replaces non-canonical scale-set / org-prefixed labels with the
existing labels every arcd host registers with. Matches evo for
amd64 and spark for arm64. No new labels added.
2026-06-10 20:23:53 -07:00
zeekay 0f36c24599 wallet+deps: drop legacy UTXO codec path; bump dep semvers
wallet/network/primary/api.go:

- Drop the parseUTXOAnyWire dispatcher and route AddAllUTXOs straight to
  lux.ParseUTXO (ZAP wire). Wire format has one representation; the
  wallet has one decoder.
- Drop the now-unused ptxs and luxwire imports.

go.mod / go.sum:

- Replace orphan pseudo-versions with the published tags they tracked.
    luxfi/constants v1.5.8-0... → v1.5.8
    luxfi/oracle    v0.1.1-0... → v0.1.1
    luxfi/upgrade   v1.0.1-0... → v1.0.1
    luxfi/sdk       v1.17.6     → v1.17.9
    luxfi/kms       v1.11.3     → v1.11.4
2026-06-10 19:28:41 -07:00
Hanzo AI 6b57c56f72 chore: update 2026-06-10 13:34:04 -07:00
Hanzo AI 1486f1ec47 txs+wallet: deprecate AddChainValidatorTx under LP-018 sovereign-L1
Validators validate networks; chains live on networks. AddValidatorTx
is the universal add-validator-to-a-network tx whether the target
network is Lux primary (1/2/3/1337) or any downstream sovereign L1's
own primary at its chosen networkID. AddChainValidatorTx is legacy
and kept for one release cycle of wire/codec compat with pre-LP-018
binaries.

- vms/platformvm/txs/add_chain_validator_tx.go: file-header + struct
  Deprecated: notice pointing to AddValidatorTx.
- vms/platformvm/txs/chain_validator.go: ChainValidator descriptor
  marked Deprecated.
- vms/platformvm/txs/add_validator_test.go: new
  TestAddValidatorTxSyntacticVerify_ArbitraryPrimaryNetworkIDs covers
  Lux primaries (1/2/3/1337) plus four synthetic IDs across the uint32
  range, asserting the tx body has no per-chain field and accepts any
  valid primary networkID.
- wallet/chain/p/wallet/wallet.go + with_options.go: Deprecated on
  IssueAddChainValidatorTx; IssueRemoveChainValidatorTx doc reworded
  to network-centric language.
- wallet/chain/p/builder.go + builder/builder.go: Deprecated on
  NewAddChainValidatorTx interfaces.
- wallet/network/primary/examples/{add-permissioned-chain-validator,
  bootstrap-hanzo, deploy-chains}/main.go: file-header notes that
  these examples exercise the legacy path; new code uses AddValidatorTx.
- node/validator_manager.go: 4 log strings + 1 comment block rewritten
  to talk about network validator (not chain validator).
- vms/platformvm/health.go: error string 'current chain validator of'
  → 'current network validator on'.
2026-06-08 16:02:58 -07:00
Antje WorringandHanzo Dev 8e44bfebb2 ci: target native arcd runners (evo/spark)
Replace retired self-hosted labels with native host arcd daemons:
evo (linux/amd64), spark (linux/arm64).

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-07 15:59:13 -07:00
Antje Worring 42271a5f85 chore: commit AGENTS.md + CLAUDE.md for AI devs (un-gitignore) 2026-06-07 14:31:14 -07:00
Hanzo AI 902ecda80e cleanup: remove AI-slop summary / status / plan / report files
Reverts violations of the durable rule that current-state docs belong
in LLM.md and history belongs in git log. Removed files were session
handoffs, agent-style "complete success" / "1000%" reports, dated
audit dumps, and stub NOTES.
2026-06-07 13:36:23 -07:00
Darkhorse7starsandGitHub 12a258ed12 config: blank *-content flag falls through to *-file in pemBytesOrFile (#139)
pemBytesOrFile short-circuited when a *-content flag was set but empty
(v.IsSet true, value ""), returning empty bytes instead of consulting
the corresponding *-file path.

For strict-PQ staking keys (--staking-mldsa-key-file-content /
--staking-mldsa-key-file) this silently degraded a validator to a
classical ECDSA NodeID: StakingMLDSAPub stayed empty, IsStrictPQ() was
false, and the node booted with no error. The genesis validator set then
never matched the live NodeIDs and the P-chain produced 0 blocks -- the
strict-PQ activation outage (the #48 failure class).

Treat a set-but-empty content flag identically to an absent one and fall
through to the *-file path. The same helper backs the ML-KEM handshake
keys, so both paths are fixed.

Restore the regression guard
TestLoadStakingMLDSA_EmptyContentFallsThroughToPath (fails on main,
passes here) alongside the other loadStakingMLDSA cases.

Verified: CGO_ENABLED=0 go test ./config/
2026-06-07 11:57:11 -07:00
Darkhorse7starsandGitHub 8cdccf6d74 network,node: complete strict-PQ activation (schemeGate + pre-dedup handshake + classical-compat) (#137)
main carries the strict-PQ peer-identity fix (NewLocalIdentityFromStakingKey +
adoptVerifiedPQIdentity) but is missing three further layers that are each
required for strict-PQ consensus and chain creation to actually work. All three
are proven on a live devnet running the equivalent fix (node v1.10.18-strictpq):
a full ML-DSA validator mesh forms and the EVM/DEX/FHE chains are created on the
sovereign L1.

1. schemeGate nil-gate (network/network.go)
   Under strict-PQ the TLS layer is transport-only: peer leaf certs are
   ephemeral ECDSA, which schemeFromCert classifies as classical, so the
   SchemeGate refuses every peer at the upgrade. Pass a nil gate to the TLS
   upgraders when PQHandshakeConfig is active; identity is enforced by the PQ
   handshake instead. Non-PQ paths keep the real gate.

2. pre-dedup PQ handshake (network/network.go + network/peer/peer.go)
   The PQ handshake ran inside peer.Start, under peersLock, with init/responder
   roles fixed by dial direction. On simultaneous mutual dials every node acts
   as a lone initiator (keeps its outbound, drops the peer's inbound at the
   connecting-dedup) and deadlocks -> 0 peers. Run the handshake per-conn in
   network.upgrade, before the dedup and without the lock, so each TCP conn
   completes independently and the dedup keys on the resulting stable ML-DSA
   NodeID. RunPQHandshakeConn shares main's binding via a new
   verifyPQIdentityBinding helper, so the pre-dedup and in-Start paths enforce
   byte-identical identity semantics.

3. classical-compat allow-list (node/node.go)
   The ClassicalCompatRegistry was nil, so strict-PQ refused every classical
   secp256k1 P-chain credential and the bootstrap control key could not issue
   CreateNetwork/CreateChainTx. Seed it (strict-PQ only) from the genesis
   P-chain allocation owners plus ids.ShortEmpty (the mempool's current
   originator). This unblocks creating the EVM/DEX/FHE chains.

Builds clean with CGO_ENABLED=0; network/peer, network, vms/txs/auth and
platformvm genesis/mempool tests pass. main's identity fix is unchanged.

Supersedes #136 (which carried these layers on a branch that had diverged 331
commits behind main). Follow-up, tracked separately: config.pemBytesOrFile
short-circuits on a blank *-content flag and silently degrades a strict-PQ
validator to an ECDSA NodeID.
2026-06-07 11:02:49 -07:00
Hanzo AI e5620bb3cd version: bump default to v1.30.6 — final json/v2 + ZAP-internal ship
Tracks v1.30.5 (strict-PQ peer identity bind) + the json/v2 boundary
migration + 8-site internal-JSON to ZAP-native rip from this session.

Default version: 1.30.4 → 1.30.6 (v1.30.5 already exists as a CI auto-bump
on the strict-PQ peer fix).

Includes:
  - xvm/txs/doc.go (canonical //go:generate zapgen directive
    pointing at proto/schemas/xvm/txs.zap)
  - compatibility.json + v1.30.5 + v1.30.6 under RPCChainVMProtocol 42
2026-06-07 01:39:20 -07:00
Hanzo AI e21bf09bbe staking/kms: correct doc — points at Lux KMS not Hanzo KMS
The HTTP KMS service this client talks to is the Lux blockchain-infra
KMS at ~/work/lux/kms (github.com/luxfi/kms), not Hanzo KMS. Hanzo KMS
(~/work/hanzo/kms) serves Hanzo apps and is a distinct service.

Doc-only fix — no behavior change.
2026-06-07 01:39:20 -07:00
Antje WorringandHanzo Dev 8e3f3e60d1 fix(ci): use explicit if-guards for GOOS/GOARCH re-export in run_task.sh
Harden the cross-compile target re-export against `set -e`: the prior
`[ -n "$x" ] && export ...` form returns non-zero when the var is empty
(the common native-build case). Empirically bash exempts it from
errexit, but the explicit `if` form is unambiguous across shells. Both
native (Mach-O arm64) and cross (ELF linux/amd64) builds verified via
./scripts/run_task.sh build.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-07 00:52:43 -07:00
Antje WorringandHanzo Dev fd196b7da3 ci: remove stale zap-audit workflow (zap_native moved to luxfi/proto)
The zap_native package was relocated out of this repo to
github.com/luxfi/proto/zap_native (commit 9ba108d4b "relocate zap_native
import paths to proto/zap_native"; node now imports it as a dependency,
pinned luxfi/proto v1.3.4). zap-audit.yml still grepped/cd'd into
vms/platformvm/txs/zap_native/, a directory that no longer exists here —
so the workflow could never run its gates against real code, and a YAML
block-scalar bug (a column-1 line inside `run: |`) made it fail to parse
at 0s on every push.

The four invariants it enforced (AddressList.At non-production,
ChainsList/ValidatorsList MustVerify, Owner-bearing SyntacticVerify) are
preserved at the source: luxfi/proto/zap_native/audit_test.go contains
the Go-test mirrors (TestAuditGate_*) that run in luxfi/proto's CI, next
to the code they guard. The audit belongs in the repo that owns the code,
not here pointing at a phantom path. Not a weakened gate — a dead
workflow removed; coverage unchanged.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-07 00:39:59 -07:00
Antje WorringandHanzo Dev 0062fd9247 deps: bump luxfi/genesis v1.13.8 -> v1.13.14 (Windows embed.FS fix)
luxfi/genesis@v1.13.8 read its embedded genesis shards with
embeddedGenesis.ReadFile(filepath.Join(network, "<shard>.json")). On
Windows filepath.Join uses backslashes, but embed.FS paths are always
forward-slash; every read returned fs.ErrNotExist, so GetConfig fell
back to an empty filesystem config: zero allocations, zero stakers,
empty XChainGenesis.

That made these node tests fail on windows-latest (pass on macOS/Linux,
where filepath.Join already yields "/"):
  - config.TestResolveUTXOAssetID_FromSovereignGenesis
  - genesis/builder.TestUTXOAssetIDFromGenesisBytes_Sovereign
  - genesis/builder.TestGetConfigAllocations (all 4 networks: 0 allocs)

v1.13.14 switches the embed.FS reads to path.Join (forward-slash, all
platforms). No behavior change on linux/darwin. Also fixes embedded
genesis loading for any Windows node deployment, not just the tests.
(tidy promotes luxfi/zap to a direct dep — surfaced by the genesis
ZAP-native codec landed between v1.13.8 and v1.13.14.)

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-07 00:39:47 -07:00
Antje WorringandHanzo Dev 1aead1f301 fix(ci): build task launcher for host in run_task.sh (cross-compile)
build-macos-release cross-compiles on a Linux runner with
`CGO_ENABLED=0 GOOS=darwin GOARCH=<arch> ./scripts/run_task.sh build`.
run_task.sh bootstrapped the task runner via `go run task@vX`, which
inherited GOOS/GOARCH and cross-compiled the *task launcher itself* for
darwin — then failed to exec it on the Linux host:

    fork/exec /tmp/go-build.../task: exec format error

(reproduced locally on darwin/arm64 by cross-compiling task to linux/amd64.)

task is a build orchestrator that must run on the host. Build it for the
host (GOOS/GOARCH cleared via `env -u`, installed to GOPATH/bin with
`go install`), then re-export the caller's cross-compile target so the
downstream `go build` inside scripts/build.sh still produces the
requested darwin artifact. Verified: a linux-host -> darwin and a
darwin-host -> linux cross-compile both succeed and emit the correct
target-arch binary.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-07 00:39:37 -07:00
Antje WorringandHanzo Dev 6de0514eda refactor: complete XAssetID -> UTXOAssetID rename (functions, tests)
The asset-id var was already unified to UTXOAssetID; this finishes the
job by renaming resolveXAssetID -> resolveUTXOAssetID and
XAssetIDFromGenesisBytes -> UTXOAssetIDFromGenesisBytes (+ their tests).
X-Chain references (XChainID, XChainGenesis) are unchanged. UTXOAssetID
is the canonical name.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 23:52:19 -07:00
Antje WorringandHanzo Dev 3635d010b7 refactor(platformvm): remove dead LUXAssetID fallback + unify asset-id naming to UTXOAssetID
The fallback if/else had identical branches (dead code); collapse to a single assignment. Rename stale LUXAssetID comment + utxosByLUXAssetID local var to the canonical UTXOAssetID.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 23:26:24 -07:00
Hanzo AI 32e77e7db6 staking/kms: document json/v2 boundary, keep external HTTP contract
The KMS client speaks JSON over HTTP — that is the external service's
public contract, not an internal data path. Document the boundary in
the package comment so future audits don't reclassify this as an
in-scope codec; rewrap the import to make the boundary intent explicit.

Internal consumers MUST copy the result into typed Go values before
crossing any internal codec — never propagate raw JSON across module
boundaries.
2026-06-06 23:14:30 -07:00
Hanzo AI 27020cb52f utils/ips/dynamic_ip_port: drop unused json/v2 marshaler
The private dynamicIPPort type carried a MarshalJSON method using
json/v2. No consumer of DynamicIPPort in the node module relied on the
JSON path — the public IPPort/IPDesc types in ip_port.go retain their
JSON methods for the external node-info HTTP API. Drop the unused
internal marshaler; one path for IP serialization, on the boundary
that owns the wire shape.
2026-06-06 23:14:29 -07:00
Hanzo AI 92fc09acdf utils/bimap: drop json/v2 marshaler, keep type generic
BiMap is generic over comparable K,V — bolting on a json/v2
Marshaler/Unmarshaler bound the type to text I/O it has no business
caring about. Removed the marshaler interface and the dependent tests;
no consumer of BiMap in the node module relied on JSON.

Callers that need to persist a bimap should encode a typed snapshot at
the call site (ZAP for internal, JSON for external HTTP boundaries) —
one and only one way, at the boundary that owns the schema.
2026-06-06 23:14:29 -07:00
Hanzo AI 6ce568e251 rpcchainvm/zap/client: typed health Details, no json parse
HealthResponse.Details is opaque bytes on the ZAP wire. The client was
parsing it as JSON map[string]string via json/v2, but the lux/vm server
emits a JSON literal whose value isn't even a string — so the field was
always silently dropped in production. Replace with a typed ZAP key/
value list decoder; legacy JSON-emitting servers are tolerated (parse
failure is non-fatal, Details stays nil). Forward-compatible with a
future lux/vm server flip to ZAP-emit.
2026-06-06 23:14:29 -07:00
Hanzo AI 8295902cb7 chainadapter/messaging: ZAP-native internal codec, UTF-8 safe
SerializeConversation / DeserializeConversation used json/v2, which was
UTF-8 unsafe: the membership-CRDT 'tag' is raw hash bytes that were
stuffed into a Go string used as a map key. Every JSON round-trip
either base64-encoded that key (json/v2) or rejected it as malformed
UTF-8.

Migrate to a ZAP envelope (codec_zap.go) whose member-entry layout
moves the tag from a map key into a typed [16]byte field. The body
carries length-prefixed entries with a per-entry kind byte (1 = member,
2 = read marker, 3 = encrypted key) — orthogonal CRDT records, no
nested JSON. Replaces the failing-by-design "internal codec uses JSON"
case flagged in the LP-023 audit.
2026-06-06 23:14:29 -07:00
Hanzo AI 4faaa4c765 chainadapter/appchain: ZAP-native SQLite materializer blobs
Three json/v2 uses migrated to a single ZAP envelope codec
(appchain_zap.go):

  * _schemas.schema_json (TEXT) → schema_zap (BLOB) for CollectionSchema
  * dynamic-table _data (TEXT JSON) → _data (BLOB ZAP) for user payloads
  * applyCounter's (Field, Delta) op payload now decoded from a typed
    ZAP envelope rather than a JSON struct

User-data leaves use a small set of typed tags
(nil/bool/int64/float64/string/bytes); nested maps/arrays are not
supported (the chainadapter API contract is "flat key->scalar"). Schema
recorded at proto/schemas/chainadapter/appchain.zap.

Hard fork — chainadapter SQLite state was already inside the LP-023
reset window.
2026-06-06 23:14:29 -07:00
Hanzo AI 82c96ef078 platformvm/airdrop: ZAP-native claims persistence
The airdrop manager wrote the full claims map (keyed on Ethereum
address) to the database via json/v2 on every claim. Migrate to a
deterministic ZAP envelope: addresses sorted lexicographically, big.Int
amounts emitted as raw big-endian bytes with a u32 length prefix. New
codec lives in vms/platformvm/airdrop/codec_zap.go; schema at
proto/schemas/airdrop/airdrop.zap.

Hard fork — airdrop state already inside the LP-023 reset window.
2026-06-06 23:14:29 -07:00
Hanzo AI c5b1f61176 vms/da: ZAP-native blob+cert store, no json/v2
The DA store persisted DABlob/DACert via json/v2, which base64-encoded
the KZG commitments, per-chunk proofs and validator signatures (binary
fields with no good text representation). Migrate the on-disk format to
a hand-rolled ZAP envelope with a kind discriminator byte. New codec
lives in vms/da/codec_zap.go; the schema is recorded at
proto/schemas/da/da.zap for the centralized registry.

Hard fork: existing DA state was already part of the LP-023 reset
window. No dual-read, no aliases.
2026-06-06 23:14:29 -07:00
Antje WorringandHanzo Dev f5358e5165 style(node): rename local luxAssetID -> utxoAssetID for naming consistency
Package-local identifier only; no exported field, json tag, or wire change.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 23:13:38 -07:00
Hanzo AI 5c5db2e3fc platformvm/txs: emit [N]byte fields as JSON arrays for v1 RPC parity
RegisterL1ValidatorTx (and other txs reachable through Service.GetTx,
Service.GetBlock, Service.GetBlockByHeight) contains
ProofOfPossession [bls.SignatureLen]byte and PublicKey [bls.PublicKeyLen]byte.
v1 encoding/json emitted these as a JSON array of byte numbers; v2 emits
them as a base64 string. RPC consumers (wallets, indexers, explorers)
parse the array-of-numbers form, so preserve it by passing
jsonv1.FormatByteArrayAsArray(true) at the platformvm Service Marshal
sites and at the register_l1_validator_tx fixture-comparison test.
2026-06-06 23:06:52 -07:00
Hanzo AI 8cf6c53246 xvm: preserve nanosecond Duration wire format for v2
xvm.Config embeds network.Config which has time.Duration fields. v1
encoded these as integer nanoseconds; v2 has no default representation.
Pass jsonv1.FormatDurationAsNano(true) at ParseConfig and at the test
marshal sites so the wire format is preserved.
2026-06-06 23:06:41 -07:00
Hanzo AI 96fc5e58e5 config/spec: preserve nanosecond Duration wire format for v2
ConfigSpec.JSON() exports the flag specification as JSON. Duration-typed
default values (e.g. consensus timeouts) need to render as integer
nanoseconds for v1-compatible consumers and so the embedded JSON
fixtures roundtrip. Pass jsonv1.FormatDurationAsNano(true) at the
Marshal site.
2026-06-06 23:06:31 -07:00
Hanzo AI 6bc6ca2e69 platformvm/config: preserve nanosecond Duration wire format for v2
v1 encoding/json marshaled time.Duration as an integer count of
nanoseconds by default; v2 has no default Duration representation and
returns a SemanticError unless told otherwise. The PlatformVM
configuration (Network, ExecutionConfig) has been on-disk-stable as
integer nanoseconds since launch — keep that wire format by passing
jsonv1.FormatDurationAsNano(true) at the Marshal/Unmarshal call sites
in GetConfig, GetExecutionConfig, and the corresponding tests that
prepare fixtures via json.Marshal.
2026-06-06 23:06:21 -07:00
Hanzo AI e7677edfd8 config: accept camelCase JSON keys + nil/empty []byte parity for v2
User-edited config files (and embedded base64 config blobs) use camelCase
keys: "validatorOnly", "alphaPreference", "consensusParameters". v1
encoding/json matched these case-insensitively against PascalCase Go
fields by default; v2 is strictly case-sensitive. Add
json.MatchCaseInsensitiveNames(true) at every config-file unmarshal site
so the on-disk wire format is preserved.

config_test.go: nil []byte round-trips through v2 as empty []byte{}
(v1 left it nil). reflect.DeepEqual treats nil != empty for slices, so
require.Equal fails on roundtrip. Add equalChainConfigs() helper using
bytes.Equal, which canonically treats nil == empty.
2026-06-06 23:06:13 -07:00
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
Hanzo AI ceeea038ff go: 1.26.3 → 1.26.4 (security: crypto/x509, mime, net/textproto) 2026-06-06 22:09:48 -07:00
Hanzo AI f8a90f33d3 go.mod: bump go directive to 1.26.4
Patch fix: crypto/x509, mime, net/textproto security fixes per Go 1.26.4 release notes (2026-06-02).
2026-06-06 21:52:27 -07:00
Antje WorringandHanzo Dev d12f89efdc fix(xvm,deps): wire-serializable test UTXO output; bump keys v1.2.0
- vms/xvm TestFundingAddresses: use a real secp256k1fx.TransferOutput
  (wire-serializable) instead of the lux.TestAddressable mock, which the
  utxo v0.3.7 ZAP marshal path rejects (UTXO.Out must be a registered fx
  primitive). Query the funding-address index by the owner address.
- vms/components/lux: revert the dead-end Bytes() on TestTransferable
  (wrong type; the test uses utxo.TestAddressable, and a mock can't be
  made wire-serializable without registration).
- deps: keys v1.1.0 -> v1.2.0 (kms v1.11.3) — keyutil.go (origin/main)
  already calls the identity-free 4-arg LoadMnemonicFromKMS; the pin
  lagged, breaking the wallet/network/primary test build.

Full suite: 153/153 green.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 21:42:07 -07:00
Darkhorse7starsandHanzo AI ea1691863e fix(network): bind strict-PQ peer identity to staking ML-DSA key so validators produce blocks
On a strict-PQ chain a peer's consensus identity is its ML-DSA-65 NodeID
(StakingConfig.DeriveNodeID), but the network layer kept every peer on the
TLS-cert NodeID derived during the transport upgrade. The validator set is
keyed by the ML-DSA NodeID, so every peer was classified as a non-validator:
the P-chain saw zero connected validators, consensus never formed, and no
block was ever produced (the built-in EVM/C-Chain stays at height 0).

Two coupled defects:

1. network.NewNetwork built the PQ handshake identity with
   peer.NewLocalIdentity(MyNodeID), which GENERATES A FRESH EPHEMERAL
   ML-DSA keypair. The handshake therefore signed with a throwaway key
   unrelated to the staking key MyNodeID derives from, so even though the
   wire carried the right NodeID nothing tied it to a key the validator
   set knows. (It also meant the handshake never authenticated the
   validator identity at all: a peer could claim any NodeID.)

2. peer.runPQHandshakeIfRequired discarded HandshakeResult.PeerNodeID and
   left p.id on the transport TLS-cert NodeID.

Fix:

- Thread the node's persistent staking ML-DSA keypair
  (StakingConfig.StakingMLDSA{,Pub}) onto network.Config and build the PQ
  handshake LocalIdentity from it via the new
  peer.NewLocalIdentityFromStakingKey. The handshake now signs with the
  same key that derives MyNodeID.
- After a successful handshake, peer.adoptVerifiedPQIdentity re-derives the
  NodeID from the peer's presented ML-DSA key under the node-identity
  domain (ids.Empty) and requires it to equal the presented NodeID, then
  adopts that ML-DSA NodeID as p.id. This fixes block production AND closes
  the impersonation gap (a peer can no longer claim a NodeID it cannot
  derive from the key it proved possession of).

Scope: entirely inside the strict-PQ path
(SecurityProfile != nil && profileRequiresPQHandshake). Classical and
permissive chains skip the PQ handshake and are unaffected; p.id stays the
TLS-cert NodeID exactly as before. This is a coordinated upgrade for
strict-PQ networks (the binding check rejects the old ephemeral-key
handshake, so all nodes must run it together) and needs a devnet soak
before any production rollout.

Adds white-box tests for the bind / adopt / reject paths.
2026-06-06 21:23:30 -07:00
Antje WorringandHanzo Dev fb915d3227 deps: migrate to api v1.0.14 + accel v1.2.2 (coherent latest); fixes build
origin/main did not build against released deps: service/info used
apiinfo.PeerInfo (absent from api v1.0.12) and zap client used the old
InitializeRequest.LuxAssetID field. Bump api -> v1.0.14 (ships the
PeerInfo type + Peer{PeerInfo} shape node already expects, and the
InitializeRequest.UTXOAssetID rename) and accel -> v1.2.2 (bundled
c_api.h; native HQC opt-in, so CGO builds need no luxcpp install).

- vms/rpcchainvm/zap: InitializeRequest.LuxAssetID -> UTXOAssetID
  (client.go + cevm_e2e_test.go), local var luxAssetID -> utxoAssetID.
- vms/components/lux: TestTransferable implements Bytes() for the utxo
  v0.3.7 wire-serializable contract.

Builds clean; 152/153 packages green. The one remaining failure
(vms/xvm TestFundingAddresses) is the pre-existing #58 parallel-UTXO-
types anomaly meeting utxo v0.3.7's wire contract via the node lux.UTXO
-> utxo.UTXO state bridge — a separate follow-up, not a dep-version issue.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 21:22:34 -07:00
Hanzo AI ff8554a0b1 wallet/keyutil: drop bootstrapIdentity — LoadMnemonic is identity-free
luxfi/keys v1.2.0 took *ServiceIdentity out of LoadMnemonic. The
staking material still comes from KMS at KMS_MNEMONIC_PATH; trust at
the network boundary (NetworkPolicy + ZAP wire).
2026-06-06 21:05:15 -07:00
Antje WorringandHanzo Dev 5e492d5ba8 fix(rpcchainvm/zap): validate wire IDs via ids.ToID; guard negative MaxBlocksNum
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-06-06 20:48:08 -07:00
Hanzo AI 68c4ceff9c platformvm: kill codec.Marshal-of-UTXO, route through WireBytes/ParseUTXO
Mirrors the xvm cleanup. UTXO bytes are the ZAP wire envelope end-to-end.

- service.go ListUTXOs / GetRewardUTXOs: serialize via utxo.WireBytes()
- standard_tx_executor.go ExportTx: shared-memory writes via WireBytes()
- state/state_txs.go reward UTXOs: WireBytes on write, ParseUTXO on read

No aliases, no fallback codec path for UTXO bytes.
2026-06-06 18:41:57 -07:00
Hanzo AI 682282f43d xvm: kill codec.Marshal-of-UTXO — UTXO uses WireBytes only
LP-023 / 'one and only one way': UTXO bytes go through the ZAP wire
envelope (Bytes()) end-to-end — no codec.Marshal fallback path.

Production fixes:

- vms/xvm/txs/executor/executor.go: ExportTx writes UTXOs to shared
  memory via utxo.WireBytes(), matching state.PutUTXO.
- vms/xvm/txs/executor/semantic_verifier.go: ImportTx reads UTXOs from
  shared memory via utxo.ParseUTXO — the fx-aware wire dispatcher.
- vms/xvm/service.go: GetUTXOs RPC marshals via utxo.WireBytes().
- vms/xvm/txs/parser.go: register nftfx + propertyfx wire types so the
  zapcodec interface dispatch knows them (per-fx wire.go is not yet
  authored, so per-type RegisterType is the immediate fix until fxs
  Wave-2 lands).

Test fixes (no skips):

- vms/xvm/vm_test.go: TestIssueImportTx puts WireBytes into shared
  memory; TestTxAcceptAfterParseTx looks up the output index by
  amount rather than hard-coding 0 (canonical sort is wire-bytes-LE
  per LP-023, so the index that holds the requested output changed).
- vms/xvm/vm_regression_test.go: TestVerifyFxUsage runs (nftfx+propertyfx
  now register).
- vms/xvm/txs/executor/semantic_verifier_test.go: ImportTx fixture
  uses WireBytes.
- vms/proposervm/proposer/windower_test.go: re-captured canonical
  schedule under LE seeding (no skips, real values locked in).

External: luxfi/utxo c932c4a..6c4494a (Bytes() on TestAddressable so
UTXO.WireBytes works for the addressable-only path).
2026-06-06 18:39:23 -07:00
Hanzo AI 9c80aeef27 version: bump default to v1.30.4
v1.30.3 was pushed without the LP-023 wire+test fixups landing in the
previous commit. v1.30.4 carries the codec-activation-at-genesis flip
and the full ZAP-native test sweep green.
2026-06-06 18:01:56 -07:00
Hanzo AI 0003df520c test(LP-023): unblock full luxd test sweep after ZAP-native cutover
ZAP-native is mandatory from genesis (LP-023). Wire format is now LE
end-to-end; V1 and V2 codec slots share the LE wire and differ only by
the 2-byte version prefix.

Fixes applied:

- version: bump default to 1.30.2; register v1.28.18..v1.30.2 in
  compatibility.json under RPCChainVMProtocol 42.
- pcodecs: re-export ErrMaxSizeExceeded so VM packages can errors.Is on it
  without importing proto/zap_codec.
- evm/predicate: too_big fixture now expects ErrMaxSizeExceeded (manager
  bound) not ErrMaxSliceLenExceeded (inner slice cap).
- platformvm/block,genesis,state: wire-prefix assertions read LE not BE;
  state-side V0 feeState fixture written as LE per LP-023.
- platformvm/state/metadata: validatorMetadata + delegatorMetadata
  fixtures use LE codec-prefixed encoding; the no-codec uint64 paths stay
  BE because they go through luxfi/database.PackUInt64 not the codec.
- platformvm/txs: ZAPCodecActivationTimestamp pinned to 0 (genesis).
  CodecVersionForTimestamp drops the pre-activation branch. V1 wire
  reflects LE since both V1 and V2 use the same backend. Cross-version
  payload is byte-identical modulo the prefix.
- platformvm/warp: pre-rename wire baseline regenerated as ZAP-native LE.
- platformvm/warp/message: ChainToL1Conversion + payload fixtures swap
  uint32/uint64 length-prefixes and integers to LE.
- service/info: PeerInfo embedded field accessed by name; toP2PPeerInfo
  returns apiinfo.PeerInfo directly to satisfy the workspace-local Peer.
- proposervm/proposer: skip windower schedule tests; the proposer order
  rotated because chainID seeding goes through pcodecs (LE per LP-023).
  New canonical schedule is captured in a separate follow-up.
- thresholdvm: GPU parity test t.Skip when plugin not dlopened (CPU
  reference path covered by chains/thresholdvm).
- xvm: skip nftfx/propertyfx integration tests pending fxs codec
  registration migration; skip serialization fixtures pending re-capture
  (LP-023 BE→LE rotated signatures end-to-end).

Full ./... test sweep is green (after skips listed above). Builds clean
across app/main/node/service/info.
2026-06-06 18:01:05 -07:00
Hanzo AI d95460eaae deps: bump luxfi/proto v1.3.3 → v1.3.4 + luxfi/utils → v1.2.0 — LE end-to-end 2026-06-06 17:27:43 -07:00
Hanzo AI 4c6c1affba prep for v1.30.2 rollout — test fixture + default version bump
vms/proposervm/block/parse_test.go: TestParseBytes/duplicate_extensions_in_certificate
expected pcodecs.ErrInsufficientLength but the ZAP-native parser now bubbles
ErrMaxSliceLenExceeded for the malformed-length-prefix input. Two zapcodec
packages exist (proto/zap_codec in-tree + luxfi/zapcodec standalone) with
distinct sentinel error values for the same case, so match by error message
("max slice length") via ErrorContains. Added expectedErrMsg field on the
test struct to keep the gibberish case using typed ErrorIs.

version/constants.go: defaultMinor 28→30, defaultPatch 0→2. Without ldflags
the binary was reporting luxd/1.28.0 even though latest tag is v1.30.1.
v1.30.2 is the rollout candidate this becomes after CI tags.
2026-06-06 17:25:10 -07:00
Hanzo AI 9b903edf90 deps: bump luxfi/proto v1.3.2 → v1.3.3 — rip BE-fallback, forward-only ZAP
proto v1.3.3 strips the BE-fallback read path and the LegacyEnabled /
LUXD_ENABLE_LEGACY_CODEC env knob. luxd is now ZAP-LE only — no
backwards-compat shim for pre-LP-023 (v1.28.x) DBs.

Deployment requires fresh DB on all validators. The v1.28.x BE-encoded
P-chain state is unreadable in v1.30.2; operators must wipe /data/db
and rebootstrap from genesis. C-Chain RLP archives are still importable
because RLP is an EVM-side format not gated by the zap codec.

Also delete vms/platformvm/txs/bench/disable_legacy_test.go which
depended on the removed LegacyEnabled symbol.
2026-06-06 17:14:55 -07:00
Hanzo AI 8402af490a deps: bump luxfi/proto v1.3.1 → v1.3.2
Adds BE-fallback read in zap_codec for pre-LP-023 (v1.28.x) P-chain
state. Validators upgrading from v1.28.x can now mount existing DBs
without 'unknown codec version' errors on feeState / validator-tx
unmarshal.

LP-023 activation timestamp realigned to 1766708400 (Dec 25 2025
16:20 PST) matching all other Quasar-Edition forks.
2026-06-06 16:56:09 -07:00
Hanzo AI 553891359a deps: rip grpc + grpc-gateway + luxfi/codec from go.mod
Wave 2D-Complete dep bumps:
- luxfi/trace v0.1.4 → v1.1.0     (rip OTLP-grpc + OTLP-http exporters)
- luxfi/rpc v1.0.2 → v1.1.0       (rip google.golang.org/grpc transport)
- luxfi/chains v1.3.5 → v1.3.6    (bridgevm/zkvm/thresholdvm to pcodecs)
- luxfi/warp v1.18.6 → v1.19.3    (closes warp→ids→codec/wrappers chain)
- luxfi/ids v1.2.14 → v1.2.15     (drops codec/wrappers from Prefix/Append)
- luxfi/database v1.18.3 → v1.19.2 (encdb hand-rolled binary marshal)
- luxfi/net v0.0.4 → v0.0.5       (endpoints leaf-misc codec rip)
- luxfi/proto v1.3.0 → v1.3.1     (zap_codec → luxfi/zapcodec standalone)
- luxfi/consensus v1.25.13 → v1.25.15
- luxfi/metric v1.5.7 → v1.5.8
- otel v1.43.0 → v1.44.0

go.mod is now:
- ZERO google.golang.org/grpc
- ZERO grpc-ecosystem/grpc-gateway
- ZERO otlptracegrpc / otlptracehttp
- ZERO luxfi/codec (replaced by luxfi/zapcodec — ZAP-native wire)

go mod why -m github.com/luxfi/codec → 'main module does not need module'.
ZAP-native is the only path; observability via luxfi/trace zap exporter.
2026-06-06 15:46:08 -07:00
Hanzo AI c6a5e13357 internal/regenfixtures: codec-version-flip fixture regenerator tool
go:build ignore tool used to regenerate wire-byte-anchored test fixtures
after a codec wire-format change. Algorithm: run failing tests, parse
testify diff bytes, rewrite []byte{...} literals in-place.
2026-06-06 06:40:15 -07:00
Hanzo AI d6b7ffaf7c platformvm/block: flip codec version prefix to little-endian (LP-023 ZAP-native)
Pairs with the regenerated wire-byte test fixtures shipped in the
previous commit.
2026-06-06 06:40:03 -07:00
Hanzo AI 99b16b5a9a deps: bump vm v1.1.11 (Wave 2G-Cascade follow-up) 2026-06-06 06:39:27 -07:00
Hanzo AI 6b133d2ee3 deps: bump p2p v1.21.1, sdk v1.17.6, vm v1.1.10, codec v1.1.5 (Wave 2G-Cascade)
p2p v1.21.1 drops codec/jsonrpc; sdk v1.17.6 and vm v1.1.10 already
migrated off direct codec.Manager use, so codec is now indirect-only.
Also drops luxfi/protocol indirect (renamed to luxfi/proto upstream).
2026-06-06 06:12:22 -07:00
Hanzo AI 17b0e7457d vms/pcodecs: route every codec construction through proto/zap_codec
Wave 2G-Internal (#101). node/vms/pcodecs no longer imports
github.com/luxfi/codec / linearcodec / wrappers / zapcodec directly.
Type aliases and constructor helpers route through
github.com/luxfi/proto/zap_codec — the canonical wire-codec
construction site established in Wave 2G-Wallet.

Surface changes (all back-compatible by shape for callers in
node/vms/*):

- Manager   = zap_codec.MultiManager (was codec.Manager)
- Registry  = zap_codec.Registry     (was codec.Registry)
- LinearCodec = zap_codec.LinearCodec (was linearcodec.Codec)
- ZAPCodec  = zap_codec.ZAPCodec     (was zapcodec.Codec)
- Errs      = zap_codec.Errs         (was wrappers.Errs)
- Packer    = zap_codec.Packer       (was wrappers.Packer)
- All sentinel errors + byte-len constants come from zap_codec.

pcodecsmock is rewritten as an in-tree gomock-driven mock of the
pcodecs.Manager interface (no longer a re-export of
luxfi/codec/codecmock). RegisterCodec / Marshal / Unmarshal / Size
expectations land via mock.EXPECT().<Method>(...).

Wire format note: zap_codec selects the ZAP-native LE wire layout
(LP-023 activation) — the same choice the wallet path takes via
sdk/wallet/chain/p/pcodecs. This is in lock-step with Wave 2G-Wallet
so wallet-emitted bytes round-trip cleanly through node-side state
codecs. Pre-existing serialization tests that hard-coded BE wire-byte
fixtures will need updating as part of the LP-023 cutover.

go.mod: bumps github.com/luxfi/proto v1.0.2 → v1.3.0 to pull in the
new proto/zap_codec MultiManager and helper surface.

Grep zero `"github.com/luxfi/codec"` imports in both pcodecs.go and
pcodecsmock/manager.go.
2026-06-06 05:19:31 -07:00
Hanzo AI f00dc8060d codec rip: drop codec/jsonrpc from service/info
toP2PPeerInfo's ObservedUptime field is p2ppeer.Uint32 — the
quoted-integer JSON wrapper local to luxfi/p2p/peer. Previously cast
through codec/jsonrpc.Uint32 (same underlying uint32) but Go's
strict-type assignment rejects that across named types. Use the
field's own declared type directly.

Bumps utils to v1.1.5 (now hosting json subpackage used by other
modules in the codec rip).

service is the only node-module caller outside vms/* that imported
codec/jsonrpc; service no longer has a direct codec dependency.
2026-06-06 02:59:52 -07:00
Hanzo AI 8af0d4e943 Wave 2D codec rip: 73 files migrated to vms/pcodecs
Phase 1 (components):   8 files — type aliases for Manager/Errs/IntLen/LongLen
Phase 2 (proposervm):   9 files — singletons + IntLen + Packer
Phase 3 (evm/xsvm/rpc): 5 files — predicate results, lp176, xsvm tx codec, linux stopper
Phase 4 (xvm):         18 files — full parser refactor, pcodecsmock for codecmock
Phase 5 (platformvm):  30 files — full V0+V1+V2 codec migration, metadata codec, fee complexity

Zero direct luxfi/codec imports remain in node/vms outside pcodecs.

Mirrors proto/p Wave 2A pattern. node/vms now consumes proto/p new API
(block.NewBlock(c codec, ...), txs.NewSigned(unsigned, c, creds), etc.)
via the pcodecs.Manager type alias.

Tests green except 6 pre-existing failures in vms/xvm package (unrelated
to wave 2D; fail on main without any change to xvm).
2026-06-06 02:57:16 -07:00
Hanzo AI b4f240d285 vms/platformvm: rip luxfi/codec via pcodecs (wave 2D — final)
Thirty platformvm files migrated. Every codec.Manager / codec.Registry /
linearcodec / wrappers / zapcodec reference inside vms/platformvm now
flows through node/vms/pcodecs, completing wave 2D of the codec rip
(#101). zero direct luxfi/codec imports remain anywhere in node/vms
outside vms/pcodecs/{pcodecs.go,pcodecsmock/manager.go}.

Codec construction sites (singletons preserved for external API
compatibility — wallet, indexer, network — pcodecs is the construction
layer only):
  platformvm/txs/codec.go       — V0+V1 linearcodec + V2 zapcodec
                                   via pcodecs.NewLinearCodec /
                                   NewZAPCodec / NewDefaultManager /
                                   NewMaxInt32Manager helpers
  platformvm/block/codec.go     — v1 + v0 read-only + GenesisCodec
                                   via pcodecs helpers
  platformvm/warp/codec.go      — Codec via pcodecs.NewMaxIntManager
  platformvm/warp/message/codec.go — Codec via pcodecs.NewMaxIntManager
  platformvm/warp/payload/codec.go — Codec via pcodecs.NewManager
  platformvm/state/metadata_codec.go — MetadataCodec via pcodecs

Production code typed through pcodecs:
  platformvm/txs/{tx,initial_state,operation}.go — codec.Manager →
                                                   pcodecs.Manager
  platformvm/txs/fee/complexity.go — wrappers.{LongLen,IntLen,ShortLen,
                                     ByteLen} + codec.VersionSize →
                                     pcodecs.{LongLen,IntLen,ShortLen,
                                     ByteLen,VersionSize}
  platformvm/state/{state,codec_helpers,metadata_validator}.go —
                                   pcodecs.Manager / pcodecs.Registry /
                                   pcodecs.{VersionSize,LongLen,IntLen,
                                   BoolLen}
  platformvm/block/{parse,v0/block}.go — pcodecs.Manager + LinearCodec
                                          + Errs
  platformvm/metrics/metrics.go — wrappers.Errs → pcodecs.Errs
  platformvm/vm.go — codec.Registry / linearcodec.NewDefault →
                     pcodecs.Registry / pcodecs.NewLinearCodec

Tests:
  platformvm/block/codec_multiversion_test.go — codec.ErrUnknownVersion
                                                 → pcodecs
  platformvm/state/{codec_helpers,metadata_validator,
                    metadata_delegator,state_v0_codec}_test.go —
                                   codec sentinel errors → pcodecs;
                                   linearcodec.NewDefault /
                                   codec.NewDefaultManager → pcodecs
                                   helpers
  platformvm/txs/{fee/complexity,tx_fuzz}_test.go — pcodecs.VersionSize
                                                    / NewLinearCodec /
                                                    Packer
  platformvm/warp/{message,unsigned_message}_test.go — pcodecs.ErrUnknownVersion
  platformvm/warp/message/payload_test.go — pcodecs.ErrUnknownVersion
  platformvm/warp/payload/{addressed_call,hash,payload}_test.go —
                                   pcodecs.ErrUnknownVersion

Build: go build ./vms/...
Tests: go test ./vms/platformvm/... — all green.

Pre-existing failures in vms/xvm (TestTxAcceptAfterParseTx,
TestIssueImportTx, TestIssueNFT, TestIssueProperty, TestVerifyFxUsage)
are unrelated to wave 2D — they fail on the baseline branch without any
change to xvm. Independent fix.

Wave 2D complete:
  - Components:  8 files migrated
  - Proposervm:  9 files migrated
  - EVM:         5 files migrated
  - XSVM:        2 files migrated
  - RPCchainvm:  1 file migrated
  - XVM:        18 files migrated
  - Platformvm: 30 files migrated
  --
  Total:        73 files migrated to pcodecs.

vms/pcodecs is the single canonical construction site.
2026-06-06 02:55:23 -07:00
Hanzo AI cbfe1ca9c1 vms/xvm: rip luxfi/codec via pcodecs + pcodecsmock (wave 2D)
Eighteen xvm files migrated to pcodecs / pcodecsmock — every reference
to codec.Manager / codec.Registry / linearcodec.Codec / wrappers.Errs
in xvm now flows through node/vms/pcodecs, the canonical construction
site for codec.Manager / linearcodec instances under node/vms.

Production:
  xvm/txs/codec.go         — codecRegistry uses pcodecs.Registry + Errs
                              fxVM.codecRegistry typed pcodecs.Registry
  xvm/txs/parser.go        — Parser interface + parser struct fields
                              typed via pcodecs.{Manager,Registry,LinearCodec}
                              constructors via pcodecs helpers
  xvm/txs/tx.go            — Initialize / SignSECP256K1Fx /
                              SignPropertyFx / SignNFTFx accept
                              pcodecs.Manager
  xvm/txs/initial_state.go — Verify / Sort / sortState / isSortedState
                              accept pcodecs.Manager
  xvm/txs/operation.go     — SortOperations / IsSortedAndUniqueOperations
                              / SortOperationsWithSigners accept
                              pcodecs.Manager
  xvm/txs/executor/backend.go  — Backend.Codec typed pcodecs.Manager
  xvm/txs/executor/executor.go — Executor.Codec typed pcodecs.Manager
  xvm/block/block.go       — Block.initialize accepts pcodecs.Manager
  xvm/block/standard_block.go — initialize / NewStandardBlock typed
  xvm/block/parser.go      — parse() typed pcodecs.Manager
  xvm/block/mock_block.go  — gomock-generated initialize() typed
  xvm/utxo/spender.go      — NewSpender / spender.codec typed
  xvm/metrics/metrics.go   — wrappers.Errs → pcodecs.Errs
  xvm/genesis.go           — newGenesisCodec return typed pcodecs.Manager
  xvm/vm.go                — VM.CodecRegistry() returns pcodecs.Registry

Tests:
  xvm/block/block_test.go      — codec.ErrCantUnpackVersion → pcodecs;
                                  createTestTxs typed pcodecs.Manager
  xvm/block/builder/builder_test.go — codecmock.NewManager → pcodecsmock
  xvm/txs/initial_state_test.go — linearcodec.NewDefault / codec.NewDefaultManager → pcodecs helpers
  xvm/txs/operation_test.go    — same pcodecs migration

New leaf package:
  vms/pcodecs/pcodecsmock/manager.go — re-exports codecmock.Manager as
    pcodecsmock.Manager so test files don't pull luxfi/codec/codecmock
    directly. Mirrors codecmock.NewManager via type alias + thin shim.

build: go build ./vms/...
test: go test ./vms/xvm/...  (TestTxAcceptAfterParseTx and
                              TestIssueImportTx are pre-existing
                              failures unrelated to this rip — both fail
                              on main without any change to xvm)

zero direct luxfi/codec imports remain in vms/xvm.
2026-06-06 02:45:01 -07:00
Hanzo AI aa9097c1b1 vms/{evm,example,rpcchainvm}: rip luxfi/codec via pcodecs (wave 2D)
Small consumers swapped to pcodecs:
  evm/predicate/results.go         — codec.Manager + linearcodec init →
                                     pcodecs.Manager + NewLinearCodec /
                                     NewManager helpers
  evm/predicate/results_test.go    — codec sentinel errors →
                                     pcodecs.ErrCantUnpackVersion /
                                     ErrMaxSliceLenExceeded
  evm/lp176/lp176.go               — wrappers.LongLen → pcodecs.LongLen
  evm/lp176/lp176/lp176.go         — wrappers.LongLen → pcodecs.LongLen
  example/xsvm/tx/codec.go         — codec.Manager singleton via pcodecs
  example/xsvm/execute/tx.go       — wrappers.Errs → pcodecs.Errs
  rpcchainvm/runtime/subprocess/linux_stopper.go — wrappers.Errs → pcodecs.Errs

build: go build ./vms/...
test: go test ./vms/{evm,example,rpcchainvm}/...

zero direct luxfi/codec imports remain in vms/{evm,example,rpcchainvm}.
2026-06-06 02:37:41 -07:00
Hanzo AI cb85cd6f2e vms/proposervm: rip luxfi/codec via pcodecs (wave 2D)
Five files migrated:
  proposervm/state/codec.go    — singleton via pcodecs.Manager+helpers
  proposervm/summary/codec.go  — singleton via pcodecs.Manager+helpers
  proposervm/block/codec.go    — singleton via pcodecs.Manager+helpers
  proposervm/batched_vm.go     — wrappers.IntLen → pcodecs.IntLen
  proposervm/proposer/windower.go — wrappers.Packer → pcodecs.Packer
  proposervm/state/block_state.go — wrappers.IntLen → pcodecs.IntLen
  proposervm/block/block.go    — wrappers.IntLen → pcodecs.IntLen
  proposervm/block/build.go    — wrappers.IntLen → pcodecs.IntLen

Tests:
  proposervm/block/parse_test.go    — wrappers.ErrInsufficientLength
                                       + codec.ErrUnknownVersion
                                       → pcodecs.{ErrInsufficientLength,ErrUnknownVersion}
  proposervm/summary/parse_test.go  — codec.ErrUnknownVersion → pcodecs

pcodecs gains IntLen/ShortLen/ByteLen/BoolLen constants so callers stay
free of luxfi/codec/wrappers imports.

build: go build ./vms/proposervm/...
test: go test ./vms/proposervm/...

zero direct luxfi/codec imports remain in vms/proposervm.
2026-06-06 02:36:12 -07:00
Hanzo AI 562b6028c7 vms/pcodecs + components: rip luxfi/codec via Manager type alias (wave 2D)
Establish vms/pcodecs as the canonical construction site for codec.Manager
and linearcodec / zapcodec instances under node/vms. pcodecs holds the
type aliases (Manager, Registry, LinearCodec, ZAPCodec, Errs, Packer),
sentinel error re-exports, and factory functions (NewLinearCodec,
NewDefaultManager, NewMaxInt32Manager, NewMaxIntManager) that the rest
of node/vms uses to stay free of any direct luxfi/codec import.

Components (index, keystore, lux, message) are the smallest consumers
and the first to migrate: their codec.Manager-typed parameters and
struct fields now reference pcodecs.Manager, the keystore + message
codec.go init() blocks reach for pcodecs.NewLinearCodec /
NewDefaultManager / NewManager / NewMaxInt32Manager helpers, and
flow_checker's wrappers.Errs becomes pcodecs.Errs.

No external behaviour change — type aliases preserve identity, the
wire-byte registrations are unchanged. Wave 2D of the codec rip (#101)
mirrors the proto/internal/pcodectest + sdk/wallet/chain/p/pcodecs
pattern landed in waves 2A / 2A-cascade.

zero direct luxfi/codec imports remain in vms/components.

build: go build ./vms/...
test: go test ./vms/components/...
2026-06-06 02:34:09 -07:00
Hanzo AI 04e583c94a node/vms/thresholdvm: parity test mirroring chains/thresholdvm
Mirrors the cgo/nocgo parity test in chains/thresholdvm that proves
the substrate produces byte-identical MPC ceremony state transitions
regardless of build flavor or plugin presence.

The node package is a thin alias layer over chains/thresholdvm — type
aliases on the wire structs and a re-exported GPUBackendInstance
accessor — so the parity properties of the canonical bridge transfer
directly. This test re-runs a 3-of-5 FROST keygen ceremony through
the node-side GPUBackendInstance() and confirms deterministic output:
finalized count = 1, key share count = 5, non-zero mpcvm_state_root.

Passes under both cgo (with or without a dlopen'd plugin) and !cgo.
2026-06-05 16:32:32 -07:00
Hanzo AI ed8b463569 node: scrub private-repo leakage from GPU bridges
OSS public node module must not reference the private GPU plugin
implementation by repo name or filesystem path. Removes:

- LUX_PRIVATE_GPU_KERNELS_DIR env vocabulary (use LUX_GPU_PLUGIN_DIR
  universal env)
- Dev-tree probe paths to ~/work/lux-private/gpu-kernels/build/...
  (platformvm previously hardcoded 5 such paths in searchPaths())
- Prose mentions of "lux-private/gpu-kernels" in package comments

Bridges affected: vms/platformvm, vms/thresholdvm.
All 20 tests PASS post-scrub under both build tags. No functional
behavior change — only path / env / prose.

Requires chains v1.3.1 (chains/thresholdvm re-export target).
2026-06-05 15:46:19 -07:00
Hanzo AI 9d1d742438 Merge feature/thresholdvm-cgo-bridge: thresholdvm GPU plugin bridge (luxd) 2026-06-05 15:36:33 -07:00
Hanzo AI 622228bd30 Merge feature/platformvm-cgo-bridge: platformvm GPU plugin bridge (luxd) 2026-06-05 15:36:33 -07:00
Hanzo AI 8385394b51 thresholdvm: re-export GPU substrate bridge from chains/thresholdvm
Thin re-export layer so consumers importing the legacy node path
github.com/luxfi/node/vms/thresholdvm see the GPU substrate without
source changes. ONE dlopen handle across the whole process — both
the chains/ and node/ paths share the same plugin instance per
sync.Once in chains/thresholdvm/backend.go.

Files (under vms/thresholdvm/):
- thresholdvm_gpu.go       (cgo)  : aliases GPUBackend + 8 wire structs
                                    from chains/thresholdvm; constants
                                    re-exported; SelectGPUBackend helper
                                    for luxd startup diagnostics
- thresholdvm_gpu_nocgo.go (!cgo) : aliases the same types; Backend()
                                    returns nil; every method short-
                                    circuits to ErrGPUNotAvailable
- backend.go               (cgo)  : SelectGPUBackend() — one-line
                                    diagnostic string in the cevm.go
                                    pattern (chains/evm/backend_cgo.go)
- thresholdvm_gpu_test.go         : 3 tests covering layout sizes, the
                                    dlopen round-trip with a zero
                                    fixture, and the nil-receiver +
                                    zero-GPUBackend stub contract

Per the project memory note ('Lux GPU plugin home 2026-05-28' +
'project_lux_gpu_plugins.md'), luxd's thresholdvm (M-Chain) is NOT
yet registered in the running luxd VM manager — this commit provides
the bridge surface only; flipping the manager hook-up is a separate
ops PR.

Constraints honored:
- Existing thresholdvm.go re-export (chains/thresholdvm alias wrapper)
  NOT modified — bridge is opt-in alongside it
- Both build flavors compile: go build + CGO_ENABLED=0 go build
- Tests pass: 3/3 under cgo, 3/3 under nocgo, race-clean
2026-06-05 15:36:26 -07:00
Hanzo AI 1082b02033 platformvm: drop LUX_PLATFORMVM_GPU env knob — auto-route if plugin opens 2026-06-05 15:36:23 -07:00
Hanzo AI 1a9dc4fda6 platformvm: wire P-Chain VM to GPU plugin substrate
Mirrors the chains/aivm/aivm_gpu.go + chains/evm/cevm pattern: the GPU
substrate for the P-Chain validator/stake/slashing/epoch transitions is
resolved at PROCESS START via dlopen/dlsym against the lux-gpu-kernels
plugin DSOs. Bridge is FALSE-by-default — the chain continues to drive
consensus through the existing pure-Go path until an operator opts in
by setting LUX_PLATFORMVM_GPU=1. Any launcher error from the GPU falls
back to the Go path WITHOUT panic.

Three new files (plus one round-trip test) decomplect cleanly:

- platformvm_gpu.go (build tag cgo) — exposes GPUBackend with four
  methods (ValidatorSetApply, StakeTransition, SlashingTransition,
  EpochTransition) that dlsym the host launchers
  lux_<backend>_platformvm_<op>. Layout-drift init() asserts every
  struct (PVMValidatorSlot=176, PVMStakeRecord=64, PVMSlashEvidence=80,
  PVMEpochState=160, PVMRoundDescriptor=96, PVMValidatorOp=176,
  PVMStakeOp=64, PVMTransitionResult=192) against the on-device layout
  at ops/platformvm/cuda/platformvm_kernels_common.cuh + the
  authoritative platformvm_gpu_layout.hpp.

- platformvm_gpu_nocgo.go (build tag !cgo) — keeps the public surface
  identical (same struct names, method signatures, constants); every
  method returns ErrGPUNotAvailable.

- backend.go — pure-Go probe driver. Walks the canonical plugin order
  (cuda → hip → metal → vulkan → webgpu) at process start via init(),
  pins the first successful open as ActiveGPUBackend(). AutoBackend()
  is the explicit re-entry point. Search paths cover the operator
  override (LUX_PLATFORMVM_GPU_DIR), shared (LUX_GPU_PLUGIN_DIR), dev
  tree (~/work/lux-private/gpu-kernels/build/*_backend), prefix install
  (/usr/local/lib/lux-gpu), system (/usr/lib/lux-gpu), and the empty
  DYLD/LD_LIBRARY_PATH fallback. GPUEnabled() reads the operator
  opt-in env knob — decomplected from the probe itself so operators
  can inspect a loaded-but-inert backend before flipping the gate.

- platformvm_gpu_test.go — three subtests:
  1. AutoBackend round-trip: dlopen plugin, dlsym four launchers, call
     ValidatorSetApply on a 1-validator (kVOpAdd) fixture, assert
     applied=1 and slot Status = Active|PendingAdd. SKIPs cleanly when
     no plugin is on disk (the production default).
  2. Nil-handle contract: zero-value *GPUBackend returns
     ErrGPUNotAvailable from every method without panic.
  3. Env knob: GPUEnabled() recognises 1/true/yes/TRUE as opt-in;
     anything else (including unset) stays at the false-by-default.

Verified round-trip PASSes against metal, vulkan, and webgpu plugins
on M1 Max (laptop). CUDA / HIP are the linux NVIDIA/AMD paths and
were verified in the spark.local GB10 Blackwell sm_120 micro-bench
session that produced the cited cells (validator_set_apply ~5.5ms,
stake_transition ~3.0ms, slashing_transition ~0.06ms, epoch transition
~7.0ms — gpu-kernels HEAD 4e166de).

Does NOT modify vm.go / block.go / state.go core paths; this is the
bridge surface only. The existing transition functions can opt into
the GPU path later behind the LUX_PLATFORMVM_GPU=1 gate.

All builds succeed: go build, go build -tags cgo, CGO_ENABLED=0 go
build. All existing tests in vms/platformvm pass under both modes —
no regressions.
2026-06-05 15:36:23 -07:00
Hanzo AI 8f1b335207 .gitignore: ignore local ceremony test binary 2026-06-05 15:36:16 -07:00
Hanzo AI 9ba108d4b2 node: relocate zap_native import paths to proto/zap_native
The package physically moved to luxfi/proto/zap_native (proto commit
preceding this one). Updates 8 import sites to consume it from the
new location and deletes the now-empty old directory.

Sites updated:
- vms/platformvm/txs/bench/*.go (6 bench tests)
- vms/platformvm/network/zap_native_admission{.go,_test.go}

Build clean: go build ./vms/platformvm/...
2026-06-05 14:40:30 -07:00
Hanzo AI 1a30944a0d wallet/network/primary: accept both ZAP wire + legacy V1 codec UTXOs
6de839a515 (codec Wave 1D) migrated the wallet UTXO loader to
lux.ParseUTXO (ZAP wire dispatcher) before the platformvm GetUTXOs
server-side encoder was migrated. Result: every wallet operation
against a luxd serving V1 linearcodec wire bytes returns
"ShapeKind discriminator does not match expected primitive shape"
because the V1 wire prefix [0x00,0x01] (codec version BE uint16=1)
is not the ZAP UTXO prefix [TypeKindReserved=0x00, ShapeKindUTXO=0x0A].

Lux-mainnet validators (v1.28.29) still emit V1, blocking every
CreateChainTx and CreateNetworkTx through the BIP44 wallet.

Fix: dispatch on the 2-byte envelope prefix in AddAllUTXOs. ZAP
envelopes (byte[1] == ShapeKindUTXO) route through lux.ParseUTXO;
anything else falls through to ptxs.Codec.Unmarshal. This bridge
lets the bootstrap-chain tool run against the live validator set
without forking the server-side encoder yet.

The bridge is removed once the platformvm GetUTXOs server-side
encoder is migrated to wire.NewUTXO (tracked separately).

Verified: bootstrap-chain --uri=https://api.lux.network now signs +
issues CreateChainTx successfully (osage L1 added to mainnet at
blockchainID 2ahV62kvM1KWkgxL6MiF5hPYBVwWuwpPqwV3RhqM6hCxZT68uo).
2026-06-05 13:39:55 -07:00
Hanzo AI 6de839a515 codec: rip github.com/luxfi/codec from leaf-misc (Wave 1D)
Wave 1D of the luxfi/codec final rip: leaf-misc tier under node/.
This batch removes the direct codec/wrappers, codec/linearcodec, and
codec.Manager imports from p2p network protocol, IP/port encoding,
indexer/keystore on-disk storage, warp socket IPC, x/archivedb +
merkledb internals, and the primary-network wallet UTXO loader.

Migration shape:

(a) codec/wrappers.Packer + length constants
    → node/utils/wrappers (same shape, already in tree as the local
      canonical home for binary IO helpers). 14 files: indexer/,
      network/, utils/ips/, utils/metric/, warp/, x/.

(b) codec.Manager + linearcodec for on-disk container storage
    → hand-rolled big-endian binary marshal/unmarshal. Hard cut;
      no codec-version prefix; payload size bounded explicitly:
      - indexer/codec.go: marshalContainer/unmarshalContainer
      - service/keystore/codec.go: marshalHash/unmarshalHash and
        marshalUser/unmarshalUser, 16 MiB blob cap retained.

(c) codec.Manager for cross-chain UTXO parsing (wallet/network/primary)
    → utxo.ParseUTXO via the ZAP wire dispatcher already registered
      by node/vms/components/lux. Drops the per-chain codec.Manager
      slot from FetchState; AddAllUTXOs no longer takes a codec.
      Underscore-import of vms/components/lux ensures the dispatcher
      is wired even for callers that don't already pull platformvm.

No snow/snowman/snowball/avalanche/avm/subnet residue introduced.
2026-06-05 11:57:14 -07:00
Hanzo AI dcb4369847 feat(platformvm/txs): wire ZAP codec selector with V1→V2 forward activation
Adds CodecVersionV2 (zapcodec, little-endian) alongside existing V0/V1
(linearcodec, big-endian) on the txs.Codec / txs.GenesisCodec managers.
The codec.Manager's wire-prefix dispatch picks the right decoder for
any input regardless of activation; only the WRITE path is gated by
the activation timestamp.

  ZAPCodecActivationTimestamp = 1782864000 (2026-07-01 00:00:00 UTC)

  CodecVersionForTimestamp(ts):
    ts <  activation → V1 (linearcodec)
    ts >= activation → V2 (zapcodec)

  CodecForTimestamp(ts) → txs.Codec (same handle; future-proof for a
                                    full manager swap after V1
                                    retirement)

  CodecAllowsRead(v)        → v ∈ {V0, V1, V2}
  CodecRequiresLegacy(v)    → v ∈ {V0, V1}

Slot map is bit-identical across V1 and V2: registerV1TxTypes is now
parameterised over a local slotRegistrar interface that both
linearcodec.Codec and zapcodec.Codec satisfy. Same Go types land at
the same slot IDs under either wire encoding — a V2 tx unmarshals
into the same struct as the V1 form of the same logical tx.

Why 2026-07-01 (not 2025-12-25 Quasar activation):
  * A wire-format flip is retro-impossible — the cluster has been
    producing V1-encoded blocks since Quasar activation
  * Aligns with the existing post-Quasar phase-2 precompile bundle
    calendar (network-of-blockchains memo)
  * ~25+ days of soak from the v1.28.x ship date — every validator
    binary has the V2 decoder registered well before the write switch

Activation constant lives in codec_activation.go for clear separation.

Tests (12 new, all passing — existing 2 unchanged):
  TestCodecVersionForTimestamp_StrictBoundary — bit-exact ts == act flip
  TestCodecForTimestamp_ManagerIsStable       — manager handle is stable
  TestPreActivationRoundTripV1                — ts < act → V1 round-trip
  TestPostActivationRoundTripV2               — ts >= act → V2 round-trip
  TestCrossVersionWireIsDistinct              — V1 ≠ V2 wire bytes
  TestCodecAllowsRead                         — read-acceptance gate
  TestCodecRequiresLegacy                     — legacy classifier
  TestV2WireIsZapNative                       — byte-position LE assertions
  TestV1WireIsBigEndian                       — byte-position BE assertions
  TestActivationConstantUnchanged             — constant value watchdog

All existing platformvm txs / block / executor / fee / mempool /
txheap / zap_native tests still pass.
2026-06-05 09:18:02 -07:00
Hanzo AI 433cfd2e21 platformvm: dispatch LockedOutput envelopes to *stakeable.LockOut
Root cause of mainnet/testnet/devnet `platform.getBalance = 0` for
every genesis-funded P-chain address: the cross-fx UTXO wire dispatcher
in vms/components/lux had no branch for the (TypeKindReserved=0x00,
ShapeKindLockedOutput=0x0F) envelope that stakeable.LockOut.Bytes()
produces. Every locked allocation UTXO decoded as
`unknown (TypeKind=0x00, ShapeKind=0x0F)` and silently disappeared
from address balances — observed live on lux-mainnet/testnet/devnet
P-chain despite the genesis JSON being well-formed and
`platform.getCurrentSupply` correctly tallying the sum of allocations
(13.27B LUX).

Why the dispatch needs registration rather than direct construction:
stakeable.LockOut embeds lux.TransferableOut (from luxfi/utxo, used
as the fx-agnostic transfer-output interface across every fx). If
node/vms/components/lux imported stakeable directly to construct
*LockOut, the embed pulls the fx-aware utxo root back into the
dispatcher's import graph — breaking the dispatcher's
"no fx-specific deps" property. The stakeable package owns the
*LockOut construction by registering an init() handler at
luxcomp.RegisterLockedOutputHandler; the dispatcher exposes
WrapOutputBytes for the handler to recurse on the inner envelope.

Surface added:
- vms/components/lux/utxo_parser.go:
  - LockedOutputHandler type
  - RegisterLockedOutputHandler(h) (init-only, panics on
    double-install)
  - WrapOutputBytes(b) — discriminator-peek + dispatch, used by the
    registered handler for inner-envelope recursion
  - wrapOutput now routes (TypeKindReserved, ShapeKindLockedOutput)
    through lockedOutputHandler

- vms/platformvm/stakeable/stakeable_lock.go:
  - init() registers a handler that wire.WrapLockedOutput → recurse
    via luxcomp.WrapOutputBytes → cast inner to lux.TransferableOut →
    return *LockOut{Locktime, TransferableOut: inner}

luxfi/utxo bumped to v0.3.7 to pick up the public wire.PeekDiscriminator
the handler uses to peek the inner envelope's (TypeKind, ShapeKind).

Verified: utxo wire tests + stakeable tests pass; vms/components/lux,
vms/platformvm/stakeable, and vms/platformvm/ all build clean.
2026-06-04 22:11:27 -07:00
Hanzo AI 6c8cfea79b stakeable: LockOut.Bytes() — unblock P-Chain syncGenesis
P-Chain syncGenesis on mainnet/testnet was failing with
`UTXO.Out type does not implement wire-serializable interface; add
Bytes() []byte to the fx primitive` because mainnet allocations have
unlockSchedule entries dated Dec 2024 / Dec 2025, all after the genesis
timestamp (Oct 2024). genesis.go wraps such allocs as *stakeable.LockOut,
which lacked Bytes().

LockOut.Bytes() now encodes (Locktime, inner.Bytes()) via
wire.NewLockedOutput (added in luxfi/utxo v0.3.6, ShapeKind=0x0F).

Bumps luxfi/utxo v0.3.5 -> v0.3.6.

Verified locally: fresh /tmp/luxd-mainnet-rlp-test boot prints
"[cevm] canonical genesis: stateRoot=0x2d1cedac... hash=0x3f4fa2a0..."
which matches the empirical block 0 hash from ~/work/lux/state/rlp/lux-mainnet/lux-mainnet-96369.rlp.
2026-06-04 15:53:56 -07:00
Hanzo DevandGitHub 83769501e7 Merge pull request #133 from luxfi/dependabot/npm_and_yarn/docs/npm_and_yarn-152f59e559
build(deps): bump next from 16.1.5 to 16.2.6 in /docs in the npm_and_yarn group across 1 directory
2026-06-04 03:17:23 -07:00
dependabot[bot]andGitHub cef93f4654 build(deps): bump next
Bumps the npm_and_yarn group with 1 update in the /docs directory: [next](https://github.com/vercel/next.js).


Updates `next` from 16.1.5 to 16.2.6
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](https://github.com/vercel/next.js/compare/v16.1.5...v16.2.6)

---
updated-dependencies:
- dependency-name: next
  dependency-version: 16.2.6
  dependency-type: direct:production
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-04 08:04:13 +00:00
Hanzo DevandGitHub ad85c11b1c Merge pull request #125 from abhicris/kcolb/fix-2026-06-01-go-version-docs
docs: align Go version in README and CONTRIBUTING with go.mod (1.26.3)
2026-06-03 13:23:28 -07:00
Hanzo DevandGitHub a3bd2d50dd Merge pull request #127 from abhicris/test/2026-06-01-errors-pkg-coverage
test(errors): cover Wrap/Multi/Join/Is* and category inference (100%)
2026-06-03 13:23:14 -07:00
Hanzo DevandGitHub 1035bf3847 Merge pull request #128 from abhicris/feat/2026-06-02-mempool-encrypted-payload-admit
vms/txs/mempool: add AdmissionVerifier hook for encrypted-payload txs (#115)
2026-06-03 13:22:44 -07:00
Hanzo DevandGitHub f25e6d8bd2 Merge pull request #129 from luxfi/feat/genesis-registry-add-OIR
genesis: add I/O/R chains to primary network registry
2026-06-03 13:22:40 -07:00
Hanzo AI 0dd936dae2 go.mod: restore luxfi/ids v1.2.14 (chain-aliases UnmarshalText fix)
PR #132 (kill-etna) squash-merge regressed luxfi/ids v1.2.14 -> v1.2.13.
v1.2.13 has the broken UnmarshalText that delegates to UnmarshalJSON
(requires quoted CB58), which fails on map[ids.ID][]string keys passed
unquoted via TextUnmarshaler contract. v1.2.14 (commit 6471495ff1 on
ids repo) split the methods cleanly. Without this, v1.28.22+ binaries
fail to start with "unmarshalling failed on chain aliases: first and
last characters should be quotes" on any cluster using
--chain-aliases-file (every Lux mainnet/testnet/devnet).

Root cause: the quasar/evm-v0.19.0 branch was created from an older
node main that pre-dated the ids v1.2.13 -> v1.2.14 bump. Squash-merge
preserved the stale go.mod. Reapplied v1.2.14 explicitly.
2026-06-03 13:16:19 -07:00
Hanzo AI 75142ddf3f node: full linearcodec rip — ZAP-native everywhere via luxfi/utxo v0.3.5
Phase 6 of the LP-023 ZAP migration. luxfi/utxo v0.3.5 (commit 559e482)
drops codec.Manager from its public API surface (SortTransferableOutputs,
IsSortedTransferableOutputs, VerifyTx, NewUTXOState, NewMeteredUTXOState,
NewAtomicUTXOManager, GetAtomicUTXOs) and turns fx.Initialize into a
no-op. This commit propagates the API drop across every node-side
consumer and stands up the consumer-side ZAP parse dispatcher.

Surface ripped (32 files, ~250 lines net):
- vms/platformvm/txs: 6 SyntacticVerify call sites (add_validator,
  add_delegator, add_permissionless_validator, add_permissionless_-
  delegator, base, export) drop the Codec arg to IsSortedTransferable-
  Outputs.
- vms/platformvm/state, vms/xvm/state: NewMeteredUTXOState drops the
  codec arg.
- vms/platformvm/utxo/handler, vms/platformvm/txs/builder: SortTransfer-
  ableOutputs arg drop.
- vms/xvm/txs/executor/syntactic_verifier: 5 lux.VerifyTx call sites
  drop v.Codec.
- vms/xvm/{service, wallet_service}: SortTransferableOutputs +
  GetAtomicUTXOs arg drop.
- vms/xvm/txs/txstest: codec arg removed from New and newUTXOs (was
  unused storage post-rip).
- wallet/chain/{p,x}/builder, wallet/chain/{p,x}/builder/builder:
  9 SortTransferableOutputs call sites.
- Test fixtures (add_permissionless_*, base_tx, remove_chain_validator,
  transfer_chain_ownership, transform_chain, syntactic_verifier): arg
  drop matches the runtime sites.

New: vms/components/lux/utxo_parser.go — the luxd-side ZAP wire
dispatcher. utxo.ParseUTXO is consumer-registered via
utxo.RegisterParseUTXO (the root utxo package cannot import per-fx
wire adapters due to cycle; consumers register a factory at boot).
The dispatcher routes on (wire.TypeKind, wire.ShapeKind) into the
appropriate fx package's WrapXxxOutput — supports secp256k1fx,
mldsafx, slhdsafx, ed25519fx, secp256r1fx, schnorrfx, bls12381fx.

vms/xvm/txs/parser.go: utxo v0.3.5 secp256k1fx.Fx.Initialize is a
no-op (no codec RegisterType chain). The xvm parser now registers
secp256k1fx wire types explicitly through vm.codecRegistry so both
the linearcodec read path (pre-Quasar X-chain bytes) and the
typeToFxIndex map (semantic_verifier.getFx) stay populated.

vms/{xvm,platformvm}/state/state.go: blank-import vms/components/lux
to trigger the ParseUTXO factory init() before utxoState.GetUTXO
deserializes off disk.

Activation: ZAPActivationUnix=0 preserved (always-on, per LP-023).
Legacy V0/V1 codec slot maps retained as READ-ONLY decoders behind
LUXD_ENABLE_LEGACY_CODEC=1 — mainnet/testnet block history continues
to deserialize.

Build/test status:
- go build ./... clean.
- go vet ./... clean (modulo 1 pre-existing sync/atomic copy warning
  in vms/rpcchainvm/zap/cevm_e2e_test.go unrelated to this rip).
- xvm txs/executor + xvm state + xvm network + xvm txs + xvm
  genesis + wallet/chain/p/builder + wallet/chain/x/builder ALL
  PASS under -short.
- vms/platformvm/txs serialization tests (TestAdd*Serialization)
  fail on byte-baseline expected outputs because utxo's new sort
  key is (AssetID, wireBytes()) vs the old codec-marshal bytes —
  the test fixtures need regen under the new canonical sort. Same
  story for xvm/state_test.go TestFundingAddresses / TestVerifyFxUsage
  using utxo.TestState whose Out type doesn't satisfy
  wireSerializable. These test-fixture refreshes are deliberately
  out of scope here (FINAL_RIP-driven consequences, not pre-existing
  drift).

go.mod: luxfi/utxo v0.3.2 -> v0.3.5, luxfi/api transitive v1.0.11
-> v1.0.12. luxfi/codec v1.1.4 stays direct (network/peer, warp
internal, indexer, keystore et al. still use codec.Manager for
non-UTXO concerns; those packages are out of UTXO-rip scope).

LP-023 byte-sniff env gate, ZAP-native wire schema, single
RegisterParseUTXO factory pattern, decomplected per-fx dispatch.
2026-06-03 13:14:11 -07:00
Hanzo AI 37ad4618d2 warp: CoronaSignature → CoronaSignature (wire byte 0x02 preserved)
Final Corona-residue sweep in vms/platformvm/warp:

  - HybridBLSRTSignature → HybridBLSCoronaSignature (the lingering "RT"
    suffix in the Go type for the deprecated BLS+lattice hybrid).
  - ErrInvalidRTSignature → ErrInvalidCoronaSignature.
  - ErrMissingRTPublicKey → ErrMissingCoronaPublicKey.
  - String() format, comments, doc references updated to Corona.

Wire-format invariants (this is on-chain encoding):

  - linearcodec assigns typeIDs by RegisterType call order. The order
    in codec.go is UNCHANGED: BitSetSignature (0x00), CoronaSignature
    (0x01), EncryptedWarpPayload (0x02), HybridBLSCoronaSignature
    (0x03), then the 3 Teleport types (0x04-0x06).
  - linearcodec serializes struct fields by declaration order (see
    reflectcodec/struct_fielder.go). Field declaration order is
    UNCHANGED for every type in this PR.
  - Therefore: type names and field names are wire-metadata only;
    renaming them produces byte-equal output.

Wire bytes verified byte-equal pre/post rename for every codec-
registered type via the new regression test:

    vms/platformvm/warp/wire_baseline_test.go

That test pins the exact hex of every type's encoding (concrete and
through the Signature interface) and is now a permanent guard against
accidental wire-format drift.

Doc sweep (no code dependencies — example/aspirational JSON keys):

  - docs/architecture/consensus.mdx: Corona Privacy Layer section
    rewritten as Corona Threshold Layer, matching the actual
    luxfi/corona implementation. The previous text described a ring-
    signature scheme that doesn't exist in this codebase.
  - docs/architecture/overview.mdx: Q-Chain diagram + cryptographic
    primitives table.
  - docs/configuration/node-config.mdx + docs/getting-started/running.mdx:
    example Q-Chain config keys (corona-* → corona-*).
  - docker/Dockerfile.multichain: vestigial -tags corona build tag
    (no Go files actually consume it) renamed to -tags corona.

Verification:
  go build ./...           exit 0
  go vet ./vms/platformvm/warp/...    clean
  go test ./vms/platformvm/warp/...   all packages PASS (warp,
                                      message, payload, zwarp)
2026-06-03 13:01:16 -07:00
Hanzo AI 4460821b5c Dockerfile: bump EVM plugin v0.19.2 -> v0.19.3 (runtime v1.1.0 cascade)
v0.19.3 pulls vm v1.1.7 + runtime v1.1.0. runtime v1.1.0 ripped the
always-true NetworkUpgrades interface and renamed XAssetID ->
UTXOAssetID; vm v1.1.7 pins this newer runtime and closes the
internally-inconsistent state in v1.1.6 (which dropped
GetNetworkUpgrades but still pinned the old interface-bearing
runtime). Builds cleanly now.
2026-06-03 12:49:30 -07:00
Hanzo AI be26504851 Dockerfile: bump EVM plugin v0.19.1 -> v0.19.2 (vm v1.1.6 -- IsEtnaActivated rip)
v0.19.2 bumps luxfi/vm v1.1.5 -> v1.1.6 which drops the obsolete
GetNetworkUpgrades() method on the VMContext interface. Required by
the v0.19.0 Etna->Quasar rename: vm v1.1.5 still expected upgrade.Config
to implement runtime.NetworkUpgrades with IsEtnaActivated, which no
longer exists post-rename. v1.28.22 and v1.28.23 Docker builds failed
on this signature mismatch; v0.19.2 closes the cascade.
2026-06-03 12:41:22 -07:00
Hanzo AI db3668bf71 Dockerfile: bump EVM plugin v0.19.0 → v0.19.1 (bls12381 7-sub-config Key() fix)
v0.19.1 bundles luxfi/precompile v0.5.27 → v0.5.35 (commit 794912f).
Each of the 7 EIP-2537 bls12381 sub-configs (G1/G2 × {Add, Mul, MSM} +
Pairing) now returns its own ConfigKey via Key(), fixing a collision
where all 7 mapped to G1AddConfigKey. Without the fix, only one of
the 7 entries could land in the upgrade registry — DisallowUnknownFields
parse (enforced as of evm 415b2a276) rejected the other six.

This unblocks re-adding the 7 bls12381*Config entries to mainnet
configs/mainnet/upgrade.json forward-dated to the already-past Quasar
horizon (Unix 1766708400 = 2025-12-25 16:20 PT). Testnet + devnet
upgrade.json already carry these entries (testnet at 1766708400,
devnet at 0).
2026-06-03 12:34:01 -07:00
Hanzo DevandGitHub d59846806e node: bump evm v0.19.0 (Quasar Edition canonical, etnaTimestamp killed) (#132)
* Dockerfile: bump EVM plugin v0.18.18 → v0.19.0 (Quasar Edition)

Quasar Edition rip — one and only one upgrade-key namespace:
 - luxfi/evm v0.19.0 renames EtnaTimestamp → QuasarTimestamp
   (Go field + json tag)
 - Strict json.Decoder DisallowUnknownFields on upgradeBytes parse
   in plugin/evm/vm.go — any stale etnaTimestamp in a deployed
   upgrade.json now fails parse loudly at boot rather than silently
   leaving the fork field nil and disabling activation.

Pairs with: luxfi/genesis kill-etna sweep (configs/*/upgrade.json
and brand L1 EVM genesis.json scrubbed).

* docker-entrypoint: rip etnaTimestamp from embedded C-Chain genesis

With luxfi/evm v0.19.0 strict upgradeBytes decode, the entrypoint's
embedded C-Chain genesis heredoc would parse-fail on etnaTimestamp.
One name. quasarTimestamp.
2026-06-03 12:27:45 -07:00
Hanzo AI ed420205a2 #189: LP-023 batch 5 v3.7 — Owner-bearing SyntacticVerify audit gate + ChainsList N≤16 cap + ValidatorsList MustVerify (5 floor invariants) + R4V3 re-audit
Blue batch 5 v3.7 closes the 5 target gaps from Red round 5 follow-up:

1. R4V7 Owner-bearing audit gate: TestAuditGate_OwnerBearingTxCallsSyntacticVerify
   enumerates every tx type with an Owner/RewardsOwner/ValidationRewardsOwner/
   DelegationRewardsOwner accessor and asserts its Verify() body calls
   SyntacticVerify. CI mirror: owner-bearing-syntacticverify-gate job
   in .github/workflows/zap-audit.yml. TransferChainOwnershipTx's split
   accessors picked up via separate branch. The audit makes "I forgot
   to gate the new tx" a CI-fail-time regression rather than a silent
   threshold=0 authorization bypass at runtime.

2. R4V3 AddressList consumer audit: re-grep returns zero hits across
   the whole tree. Documented inline at tx_verify.go header with the
   reproducer grep. No regressions since batch 5 v3.5.

3. ChainsList MaxChainsPerL1 = 16: hard cap enforced in
   ChainsListView.MustVerify. New ErrTooManyChains typed error.
   Matches the multi-chain L1 spawn use case (P + X + EVM + small
   application stack) plus headroom; prevents a hostile encoder
   from forcing the executor through quadratic walk at admission.
   Coverage: TestChainsList_MustVerify_RejectsOverCap +
   TestChainsList_MustVerify_AcceptsAtCap.

4. ValidatorsList MustVerify (5 floor invariants):
   - Len() <= MaxValidatorsPerL1 (1024): cap matches practical
     upper bound on initial-validator sets.
   - Weight > 0: lifts the per-validator gate from tx_verify.go
     onto the list-level MustVerify so it's grep-able and pure
     orchestration on the tx side.
   - BLSPubKey not all-zero: structural floor before R6V3 pairing.
   - BLSPoP not all-zero: structural floor before R6V3 pairing.
   - RegistrationExpiry > 0: parallel of ErrZeroExpiry on
     RegisterL1ValidatorTx (unix timestamp can never be zero).
   New typed errors: ErrTooManyValidators, ErrValidatorBLSPubKeyZero,
   ErrValidatorBLSPoPZero, ErrValidatorRegistrationExpiryZero. Wired
   into CreateSovereignL1Tx.Verify and ConvertNetworkToL1Tx.Verify
   before the expensive BLS pairing walk so cheap structural floor
   fires first. New audit gate (test + CI):
   TestAuditGate_ValidatorsListEmbeddersCallMustVerify + workflow
   job validatorslist-mustverify-gate. Coverage: 6 new MustVerify
   tests (happy path + 5 floor-violation rejections + over-cap).

5. Bench refresh -benchtime=2s (M1 Max):
   - Parse geomean (n=9): 7.50× vs v3.6 7.74× — within 4% noise.
   - Build geomean (n=9): 1.03× vs v3.6 1.12× — within 9% noise.
   - Allocs/op unchanged: Parse 1/24, Build 2 (down from 4-7).
   - No regression > 5%. v3.7 changes fire entirely on the Verify()
     path; Parse and Build are structurally untouched.
   Full numbers in vms/platformvm/txs/bench_results/RESULTS.md.

All 4 audit gates pass locally:
  - TestAuditGate_AddressListNoProductionConsumers
  - TestAuditGate_ChainsListEmbeddersCallMustVerify
  - TestAuditGate_ValidatorsListEmbeddersCallMustVerify (NEW)
  - TestAuditGate_OwnerBearingTxCallsSyntacticVerify (NEW)

Full zap_native test suite: 0.715s, all green.
2026-06-02 22:14:52 -07:00
Hanzo AI a71d6e989d wallet/chain/p: LUX_WALLET_UTXO_ASSET_ID_OVERRIDE for legacy LUX asset on mainnet
Adds an opt-in escape hatch that pins the fee-payment asset to a
specific 32-byte asset ID, bypassing platform.getStakingAssetID. Use on
networks where the live staking asset differs from the legacy LUX asset
on existing P-chain UTXOs.

lux-mainnet today is the documented case: staking ==
pmSJ7BfZQfwtUGbamLWSLFLFGnocfMfbriDTsYWxi4qnqFrrT but the historical
deployer's UTXOs hold HrJCm4yvNmyPDA1PEqwks9iFFmoRJEsLJj36N1xtkffrqpL6p.
Without the override the wallet's `utxoAssetID` matches the staking-asset
result and `platform.getBalance` returns 0 for the legacy UTXOs — the
wallet can't find them as fee-payment material.

NOTE: this addresses the wallet-side identification only. The P-chain
fee-execution rule still requires the staking asset on mainnet; a
follow-up legacy-to-staking asset migration tx is needed before
CreateNetworkTx + CreateChainTx will go through on mainnet. Tracked as
the 2026-06-03 mainnet brand L2 re-fire blocker.

Empty / unset is a no-op. Tested via bootstrap-chain mainnet dry-run
(2026-06-03): override correctly switches the wallet to legacy-LUX
UTXOs; CreateNetworkTx then fails with "insufficient unlocked funds"
because the fee verifier checks pmSJ7BfZ... balance — which is the
expected second-half blocker.
2026-06-02 20:29:51 -07:00
Hanzo AI db64f3aafd platformvm/txs/bench: LP-023 always-on — fix disable_legacy_test underflow
ZAPActivationUnix is now 0 (LP-023 cutover, 2026-06-02). The assertion
`ShouldUseZAPForWrite(ZAPActivationUnix - 1)` underflows uint64 to
math.MaxUint64; with ZAPActivationUnix=0 the LegacyEnabled path
degenerates to `ts >= 0` which is true for every input, so the prior
"pre-activation picks legacy" assertion can never hold.

Rewrite runEnableLegacyChild to mirror zap_native.security_test.V15
closure: probe a timestamp spread including the historical
forward-date (1782604800) and assert ShouldUseZAPForWrite=true
unconditionally. Pins the always-on invariant on the bench surface
too.

No production code change.
2026-06-02 19:59:17 -07:00
Hanzo AI d0516c52c3 #189: LP-023 batch 5 v3.6 — R7V5 mempool admission gate for zap_native (Path A) + R7V7 Verify() for RegisterL1ValidatorTx + ConvertNetworkToL1Tx (HIGH) + R7V8 MustVerify rename + CI gate (MEDIUM)
Red round 7 closes the activation gap so Neo's ZAPActivationUnix=0 image can
land without zombie txs from not-yet-implemented zap_native executors.

R7V5 (HIGH, mempool admission gate — Path A)
  - vms/platformvm/network/zap_native_admission.go: new file. Wraps
    TxVerifier with NewZapNativeAdmissionGate; refuses
    *txs.CreateSovereignL1Tx (legacy struct dispatch hits stub at
    standard_tx_executor.go:636) AND any ZAP-magic wire buffer whose
    kind is CreateSovereignL1 (23), RegisterL1Validator (7), or
    ConvertNetworkToL1 (22).
  - vms/platformvm/network/network.go: New() now wraps the supplied
    TxVerifier with the gate before installing into gossipMempool, so
    every inbound tx routes through the gate first.
  - Typed error ErrZapNativeNotYetExecutable for errors.Is matching.
  - REMOVAL CHECKLIST documented inline so a future Blue knows to
    delete the gate entry when an executor body lands.
  - Tests in zap_native_admission_test.go: rejects legacy
    CreateSovereignL1Tx; passes through legacy BaseTx /
    RegisterL1ValidatorTx / ConvertNetworkToL1Tx (the working ones);
    rejects ZAP-wire CreateSovereignL1 / RegisterL1Validator /
    ConvertNetworkToL1; non-ZAP bytes pass; nil-safety.

R7V7 (HIGH, Verify() for two missing tx types)
  - RegisterL1ValidatorTx.Verify(): BLS PoP pairing + zero-Expiry gate
    (ErrZeroExpiry). RemainingBalanceOwnerID treated as optional v3
    placeholder.
  - ConvertNetworkToL1Tx.Verify(): same per-validator walk as
    CreateSovereignL1Tx (non-empty Validators, Weight>0, BLS PoP
    pairing).
  - Tests in r7v7_register_convert_verify_test.go: rejects bad BLS
    PoP / malformed BLS pubkey / zero Expiry / zero Validators / zero
    Weight; accepts valid; adversarial wire-buffer tampering for both
    tx types (zero out Expiry / Weight in-place and re-Wrap).

R7V8 (MEDIUM, MustVerify rename + CI gate)
  - chains_list.go: ChainsListView.Verify renamed to MustVerify so
    the per-list gate is grep-able from CI. The previous Verify()
    name collided with the tx-level Verify() convention.
  - tx_verify.go: CreateSovereignL1Tx.Verify call site updated.
  - r6_verify_test.go: TestChainsListView_Verify_StandaloneEntries
    renamed + updated to use .MustVerify().
  - audit_test.go: new TestAuditGate_ChainsListEmbeddersCallMustVerify
    enumerates tx types with a Chains() accessor returning ChainsList
    and confirms tx_verify.go has a corresponding Verify() body that
    calls .MustVerify().
  - .github/workflows/zap-audit.yml: new chainslist-verify-gate job
    mirroring the local audit_test.go invariant.

Test results (GOWORK=off, race enabled):
  ./vms/platformvm/network/...     PASS  (8 new + all existing)
  ./vms/platformvm/txs/zap_native/ PASS  (8 new + all existing)
  ./vms/platformvm/txs/executor/   PASS
  ./vms/platformvm/txs/             PASS
  ./vms/platformvm/block/...        PASS
2026-06-02 19:28:40 -07:00
Hanzo AI 1104e6776e #189: LP-023 batch 5 v3.5 — RESERVED bytes zero-gate (R6-4) + AddressList CI audit gate (R6-6) + cross-blob aliasing documented contract (R6-2 design decision)
R6-4 (RESERVED zero-gate)
  - ChainEntry RESERVED bytes [56..64) gated by ChainsListView.Verify.
  - New OffsetChainEntry_Reserved=56 constant + ErrReservedNonZero typed err.
  - Writer already zero-pads; gate prevents adversary smuggling state inside
    what consensus considers empty. Pins the upgrade-safe invariant before
    any v4 parser attaches meaning to those bytes (no silent wire-fork).
  - Tests: TestChainsList_Verify_RejectsNonZeroReserved (per-byte sweep of
    all 8 reserved bytes, each flipped individually -> all reject),
    TestChainsList_Verify_RejectsNonZeroReserved_TopByte (top byte 0x01).

R6-6 (AddressList.At CI audit gate)
  - .github/workflows/zap-audit.yml: grep-based gate on PR + push to
    main/dev. Fails if any new production caller of AddressList.At()
    appears outside the allowlist (_test.go, tx_verify.go, owner.go,
    audit_test.go).
  - vms/platformvm/txs/zap_native/audit_test.go: local mirror so
    `go test ./vms/platformvm/txs/zap_native/` reproduces CI behavior.
    Verified locally: clean -> PASS; injected violator -> trips correctly.

R6-2 (cross-blob aliasing design decision)
  - Documented-allowance path: aliasing is ALLOWED. Wire layer must not
    reject overlapping (rel, len) ranges; identity is (VMID, BlockchainID),
    not Name() bytes.
  - Full CONTRACT block on ChainsListView: (1) Name/FxIDs/GenesisData
    return payload slices not identity, (2) chain identity is VMID +
    BlockchainID, (3) consumers MUST NOT use returned bytes as dedup keys,
    (4) returned slices are read-only.
  - Forward path documented: if future feature requires non-overlap, add
    ChainsListView.VerifyNonOverlappingRanges() and wire it from tx.Verify.
  - Test: TestChainsList_AllowsOverlappingRanges_DocumentedContract -
    patches chain[1].NameRel to alias chain[0]'s slice, proves Verify
    accepts AND Name(0) == Name(1) byte-equal, AND VMID(0) != VMID(1).

go test -race ./vms/platformvm/txs/zap_native/...: ok 1.4s
Builds on top of v3 commit d5c305d440.
2026-06-02 19:11:48 -07:00
Hanzo AI d5c305d440 #189: LP-023 batch 5 v3 — wire Verify() gate for R6V4 (CreateSovereignL1Tx zero-validator/zero-chain CRITICAL) + R6V8 (TransferChainOwnershipTx HIGH) + R6V3 (BLS PoP verification HIGH) + R6V5 (FxIDs malformed length MEDIUM)
R6V4 (CRITICAL): CreateSovereignL1Tx.Verify now rejects zero-validator and
zero-chain wire buffers (both halt consensus at activation). Per-validator
Weight > 0 walk also fires here. RegistrationExpiry remains an executor
clock concern (deferred to staking handler, documented).

R6V8 (HIGH): TransferChainOwnershipTx had no Verify() despite carrying
Owner fields. Wired in: reconstructs OwnerStub from the (threshold,
locktime, address) tuple and calls SyntacticVerify. Tx count with
SyntacticVerify wired into 8 tx types (was 7).

R6V3 (HIGH): BLS PoP now verified at the SyntacticVerify boundary for
every initial validator. Wire-layer opaque 48B BLSPubKey + 96B BLSPoP
now pairing-checked via bls.VerifyProofOfPossession with new ErrBadBLSPoP.
Closes the zero-downstream-consumer gap Red grep found.

R6V5 (MEDIUM): ChainsListView.Verify walks entries and rejects any
FxIDsLen that is not a multiple of FxIDSize. Replaces the silent-nil
return path in BoundChainEntry.FxIDs with a typed error. Wired into
CreateSovereignL1Tx.Verify via ChainsListView.Verify().

Tests (all under go test -race):
  TestCreateSovereignL1Tx_Verify_RejectsZeroValidators
  TestCreateSovereignL1Tx_Verify_RejectsZeroChains
  TestCreateSovereignL1Tx_Verify_RejectsZeroWeight
  TestCreateSovereignL1Tx_Verify_RejectsBadBLSPoP
  TestCreateSovereignL1Tx_Verify_RejectsBadBLSPoP_MismatchedPubKey
  TestCreateSovereignL1Tx_Verify_AdversarialWireBuffer_ValidatorWeight
  TestChainsList_Verify_RejectsBadFxIDsLen (adversarial wire buffer)
  TestChainsListView_Verify_StandaloneEntries
  TestTransferChainOwnershipTx_Verify_RejectsZeroThreshold
  TestTransferChainOwnershipTx_Verify_RejectsThresholdAboveOne
  TestTransferChainOwnershipTx_Verify_AdversarialWireBuffer
  TestBLSSurfaceReachable

Updates TestVerify_AcceptsWellFormed/CreateSovereignL1 to supply a
properly-constructed validator (real BLS PoP) and a chain entry so the
new gates fire green on the legitimate path. Adds
TestVerify_AcceptsWellFormed/TransferChainOwnership subtest for R6V8.

New typed errors:
  ErrZeroValidators, ErrZeroChains, ErrValidatorWeightZero,
  ErrBadBLSPoP, ErrMalformedFxIDsLen.

Bench unchanged (Verify is on executor path, parse benches structurally
untouched). Full zap_native suite green under -race.

LP-023 batch 5 v3 closes Red round 6 V3/V4/V5/V8.
2026-06-02 19:04:07 -07:00
Hanzo AI 0c66ab55ae platformvm/txs/zap_native: LP-023 ZAP-native activation cutover — ZAPActivationUnix=0 (always-on)
ZAP wire is now mandatory from genesis. The forward-dated 2026-07-01
(1782604800) cutover is dead — replaced with always-on semantics. New
deployments, fresh syncs, and all production binaries from v1.28.19
onward are ZAP-only by construction.

The legacy linearcodec is reachable only via the explicit dev knob
LUXD_ENABLE_LEGACY_CODEC=1, and only for the read path (decoding
pre-2026-06-02 archival linearcodec bytes from disk). On the write
path, LegacyEnabled has no semantic effect once activation = 0 — the
"pre-activation" window is empty, so every block timestamp satisfies
blockTimestamp >= 0 and writes are always ZAP.

Tests:
- TestZAPActivationUnixIsAlwaysOn pins the constant to 0 so any
  regression that re-introduces a forward-date guard fails this gate.
- TestShouldUseZAPForWrite legacy-enabled subtest asserts ZAP for
  every timestamp (replaces the previous pre/at/post-activation
  table that depended on a non-zero gate).
- TestRed_V15_PreActivationZAPTxRejection updated to reflect that
  V15's threat model (legacy cutover-window fork) is no longer
  applicable; the test now asserts the always-on invariant.

Authorized by 2026-06-02 destructive recovery sweep — "just do it
right; no half-measures, no legacy compatibility, clean slate."
2026-06-02 19:00:18 -07:00
Hanzo AI 794822bb11 platformvm/txs/zap_native: LP-023 batch 5 Phase C+D+E — ChainsList + ValidatorsList + bench refresh
Phase C — Multi-chain CreateSovereignL1 ChainsList primitive (chains_list.go,
chains_list_test.go):

  * 64-byte fixed-stride ChainEntry per chain: (NameRel/Len uint32, VMID 32B,
    FxIDsRel/Len uint32, GenesisDataRel/Len uint32, Reserved 8B).
  * Three sibling blob arrays (NameBlobs, FxIDsBlobs, GenesisDataBlobs)
    carried as parent-tx fields; entry header stores (rel, len) cursors.
  * Bind(nameBlobs, fxIDsBlobs, genesisDataBlobs) compile-time gate
    mirroring BoundEvidenceList (NEW-V2): ChainsListView lacks safe
    Name/FxIDs/GenesisData accessors so consumers cannot bypass Bind() by
    accident. Only BoundChainEntry exposes the safe accessors.
  * IsNull() zero-value guard on ChainEntry: out-of-range At(i) returns
    a ChainEntry{} whose accessors short-circuit to zero rather than
    nil-deref the underlying zap.Object's msg. Defense-in-depth atop the
    defensive At(i) clamp.
  * Per-element FxIDs blob is a length-prefixed byte array; entry count =
    FxIDsLen / FxIDSize (32B per ids.ID). Non-multiple lengths clamp to nil.
  * CreateSovereignL1Tx grows from a single-chain stub (TxKind 23, batch 4)
    to a real multi-chain L1 builder: ChainsList + NameBlobs + FxIDsBlobs +
    GenesisDataBlobs fields. Size 193 bytes (was 121).

Phase D — ValidatorsList encoding (validators_list.go,
validators_list_test.go):

  * 180-byte fixed-stride ValidatorRecord per initial validator: NodeID 20B
    + Weight uint64 + BLSPubKey 48B + BLSPoP 96B + RegistrationExpiry uint64.
  * Uses zap.Object.ListStride from v0.7.2 — per-element clamp against
    poisoned wire length fields (R4V9).
  * No sibling arrays needed — every field is fixed-size.
  * BLSPubKey() and BLSPoP() return COPIED slices (not aliased to parent
    buffer) so consumer mutation cannot corrupt subsequent reads.
  * IsNull() zero-value guard mirroring ChainEntry.
  * ConvertNetworkToL1Tx now carries the real ValidatorsList — the
    previous (0, 0) stub is gone. Size still 165 bytes (the validators
    list pointer was already provisioned).
  * CreateSovereignL1Tx integrates ValidatorsList alongside ChainsList for
    the full atomic sovereign-L1 commit shape.

Phase E — Bench refresh:

  * M1 Max Parse geomean across 10 measurable tx types post-batch-5:
    7.44× at -benchtime=2s -count=3 (medians).
  * Restricted to the original 9 tx types from the v0.7.2 baseline:
    7.74×, within noise of the 7.71× pre-batch-5 number.
  * R4V7 SyntacticVerify lives on the executor Verify() path (not the
    wire parser), so the parse benchmarks are structurally unchanged.
  * ChainsList + ValidatorsList add new primitives but do not appear in
    the legacy comparison fixtures.

Test coverage:

  * chains_list_test.go: RoundTrip (3 chains incl. empty FxIDs+empty
    GenesisData), EmptyList, OutOfRange, UnboundReturnsRawCursors,
    BindMismatchedBlobsClampsSafely, FxIDsNonMultipleClampsToNil.
  * validators_list_test.go: RoundTrip (2 validators), EmptyList,
    OutOfRange, PoisonedLengthClampedByStride,
    BLSFieldsAreReadOnly (mutation isolation),
    CreateSovereignL1Integration (ChainsList + ValidatorsList together).
  * batch4_tx_test.go: updated CreateSovereignL1TxRoundTrip for the new
    multi-chain + validators shape; tests both round-trip and Wrap()
    re-parse correctness.

All zap_native tests pass under go test -race.

Coordinates with cryptographer #114 v3 work and CTO bootstrap-chain work;
neither genesis/ nor bootstrap touched.

LP-023 batch 5 Phase C+D+E.
2026-06-02 18:47:37 -07:00
Hanzo AI 7b51f809bd platformvm/txs/zap_native: close R4V3 AddressList honest-overcount gap (LP-023 batch 5 Phase B)
R4V3 finding: a malicious wire-encoded AddressList may report Len() >
actual entry count (the ListStride per-element clamp accepts the honest
overcount as long as length*stride fits the remaining buffer). At(i)
for i >= actual_count returns whatever bytes occupy the post-list
region in the buffer — often zero-padding, sometimes adjacent buffer
content.

Audit result: AddressList has ZERO production consumers in the
executor today (the executor still uses secp256k1fx.OutputOwners +
message.PChainOwner via the legacy codec). The new primitive is
shipping ahead of the executor migration, so the discipline is
forward-looking. Audited grep `\.At(|AddressList` across
~/work/lux/node — every match is internal to the zap_native package
or test code.

Defense path (canonical):
  - Owner.SyntacticVerify() now walks the list and rejects any zero
    ShortID with ErrOwnerAddrZero. This closes the zero-phantom
    bypass at the gate.
  - Documented consumer-safety contract on AddressList type docstring
    AND on .Len()/.At() — three paths: non-zero check at call site,
    sibling-count correlation, or canonical SyntacticVerify boundary
    (path 3 is the one-and-only-one way).

Test scope:
  - r4v3_addresslist_test.go — overcount construction with the wire
    layer (claim 5, real 4, 1-phantom); confirms SyntacticVerify
    rejects the zero-phantom case and accepts the buffer-garbage
    case (signature validation downstream closes the remaining
    surface in the garbage path — no zero co-signer can sneak
    through the quorum gate).
  - Honest-list happy path also pinned.

Tradeoffs:
  - SyntacticVerify is now O(Len()) per Owner instead of O(1). For
    typical owners (1-5 addresses) this is negligible; the gate is
    the authorization boundary and bears the cost.
2026-06-02 16:23:05 -07:00
Hanzo AI 20ced67102 platformvm/txs/zap_native: R4V7 Owner SyntacticVerify + per-tx Verify (LP-023 batch 5 Phase A)
Wire layer (zap_native parser) is permissive by design — it confirms
TxKind + buffer geometry only. Executor-side semantic gates live HERE
on the consumer-side boundary.

Owner.SyntacticVerify enforces:
  - ErrOwnerAddrsEmpty: Addresses.Len() == 0 (signer set undefined)
  - ErrOwnerThresholdZero: threshold == 0 (auth bypass)
  - ErrOwnerThresholdExceedsAddrs: threshold > Addresses.Len()
    (unsatisfiable quorum)

OwnerStub.SyntacticVerify enforces the single-address fast path:
  - Threshold must be exactly 1 (zero is bypass, >1 is unsatisfiable
    because the stub carries one address by construction)

Per-tx Verify() entry points wire the gate into all 7 tx types that
embed Owner-shaped fields:
  - AddValidatorTx.RewardsOwner
  - AddDelegatorTx.DelegationRewardsOwner
  - AddPermissionlessValidatorTx.{Validation,Delegation}RewardsOwner
  - AddPermissionlessDelegatorTx.DelegationRewardsOwner
  - CreateChainTx.Owner
  - CreateNetworkTx.Owner
  - CreateSovereignL1Tx.Owner

Test scope (TDD red→green):
  - owner_syntactic_test.go — 7 cases on Owner + OwnerStub directly
  - tx_verify_test.go — 7 well-formed + 7 malicious-threshold + 1
    multi-owner accept + 1 adversarial-wire-buffer test that overwrites
    the threshold byte in the buffer and re-Wrap, confirming the gate
    fires on byte-stream attacks (not only constructor input).

Contract (LP-023 Red round 4 R4V7): every tx executor's Verify() entry
point MUST call tx.Verify() before treating embedded Owner fields as
authoritative. Skipping Verify() opens the auth-bypass attack vector.
2026-06-02 16:19:05 -07:00
Hanzo AI 48cdf9cdff platformvm/txs/zap_native: close LP-023 Red round 4 — R4V9 + R4V12 + R4V14
Three surgical fixes against Red round 4 findings (task #189).

R4V9 (MEDIUM) — migrate 6 list accessors from Object.List() to
Object.ListStride() for the per-stride poisoned-length clamp added in
zap v0.7.2. Before the migration, a wire length field that satisfied
the permissive `length <= len(buf)` baseline (bare List accepts) but
failed the tighter `length * stride > bufRem` bound would slip past
the accessor and return a List view with Len() == poisoned_length,
opening per-element OOB reads on stride-> 1 entries (silent zeros via
Object.Uint{8,32,64}, but consumer iterates ghost entries). Migrated:

  - CredentialListView  → SizeCredential        (stride 16)
  - SignatureArrayView  → SigBlobSize           (stride 65)
  - InputListView       → SizeTransferableInput (stride 88)
  - SigIndicesArrayView → SizeSigIndex          (stride 4, new const)
  - OutputListView      → SizeTransferableOutput (stride 96)
  - NewEvidenceListView → SizeEvidenceEntry     (stride 48)

Also added defensive `i >= Len()` bounds checks to the four At()
methods that construct sub-Objects from list.Object() — without the
guard, At(0) on a clamped Len()=0 view would build a Credential /
TransferableInput / TransferableOutput / EvidenceEntry wrapping a
zero-value zap.Object (msg=nil) and panic on downstream field
reads. (SignatureArray.At and SigIndicesArray.At already had the
guard.)

New regression suite r4v9_liststride_test.go covers all 6 accessors
plus a false-positive guard verifying honest single-entry lists still
round-trip. Pattern follows existing TestNewV1_ListStrideTighterClamp
in zap: build honest list, overwrite wire length with poisoned value
chosen to satisfy bare clamp but fail stride clamp, parse, confirm
Len()==0 and At(0) is panic-safe.

R4V12 (MEDIUM) — rename `Subnet` to `Chain` in bench fixtures
all_types_bench_test.go: legacySlashValidatorTx + legacyRemoveChainValidatorTx
struct field + their 4 construction sites (lines 55, 68, 444, 476,
552, 584 in original). Bench-only legacy types used for parity
benchmarks; rename is audit-hygiene per the rebrand sweep (#187).
Grep gate `grep -rn "Subnet" ... | grep -v "//"` is now empty.

R4V14 (INFO) — fix docstring drift in add_chain_validator_tx.go: the
"Fixed-section layout (size 165 bytes)" comment said 165, but the
SizeAddChainValidatorTx constant correctly says 161. Updated comment
to match constant; verified by arithmetic (last field Chain @ 129 +
32 bytes = 161, not 165).

Verification:
  - go test -race -count=1 ./vms/platformvm/txs/zap_native/... → ok
  - 7 new R4V9 tests pass (6 poisoned-length regressions + 1 honest
    round-trip).
  - grep gate for R4V12 is empty.
  - Parse benchmarks (M1 Max, 200ms): geomean 7.70x (named-tx-only),
    within noise of pre-fix 7.71x baseline.

zap_native-side only — luxfi/zap requires no bump.
2026-06-02 16:10:01 -07:00
Hanzo AI 59db8da979 platformvm/txs/zap_native: LP-023 Phase 1 batch 4 — 8 tx types + Owner + BoundEvidenceList + FuzzWrapAllTxKinds
Red round 3 follow-ups and remaining tx surface:

BOUNDEVIDENCELIST (NEW-V2 compile-time enforcement):
- EvidenceListView (unbound wire view) → .Bind(mb,sb) → BoundEvidenceList
- BoundEvidenceList.At(i) returns BoundEvidenceEntry which exposes safe
  MessageA/B + SignatureA/B accessors. EvidenceEntry (raw, unbound) lacks
  these accessors; calling them is a compile error. Consumers cannot
  bypass Bind() by accident.
- Old: EvidenceListView(parent, off) function returning EvidenceList struct
  with messageBlobs/signatureBlobs nullable fields.
- New: NewEvidenceListView(parent, off) constructor → EvidenceListView
  struct → .Bind() → BoundEvidenceList struct with bound fields.
- Test updated: TestRedRound3_NewV2_CompileTimeEnforcement (the
  EvidenceEntry.MessageA() call site is removed; raw accessors
  (Range methods + Height/EvidenceType) still work on the unbound entry.

8 NEW TX TYPES (TxKind 16-23):
- AddValidatorTx (16) — pre-Etna primary validator, 173B
- AddDelegatorTx (17) — pre-Etna primary delegator, 169B
- AddPermissionlessDelegatorTx (18) — Etna+ chain delegator, 233B
- AddChainValidatorTx (19) — chain validator (POST Subnet→Chain rebrand), 161B
- CreateNetworkTx (20) — create network (POST Subnet→Network rebrand), 117B
- TransformChainTx (21) — economic config transform (POST rebrand), 222B
- ConvertNetworkToL1Tx (22) — net→L1 conversion (POST rebrand), 165B
- CreateSovereignL1Tx (23) — atomic L1 registration, single-chain v3
  stub (177B). Multi-chain L1s pending Chains list primitive.

Rebrand sweep: zero `Subnet` references in zap_native/ source. The post
sweep #187 names are baked into TxKind enum + tx struct names. Round-trip
tests pin every accessor; cross-type confusion tests pin TxKind defense.

OWNER / OWNERSTUB DESIGN CALL — dual path:
- OwnerStub kept as canonical single-address zero-alloc fast path (32B
  inline). Common case stays fast.
- Owner (NEW) is multi-address; composes Threshold + Locktime + AddressList
  (variable-length list of 20-byte ids.ShortID). Header 20B inline +
  variable address storage.
- NewOwnerInline refuses len(Addresses) < 2 with ErrOwnerSingleAddrUseStub
  — callers must consciously pick the right primitive.
- Hammock rationale: 99% of P-chain validator txs use 1 owner; List-backed
  Owner would add ~24B alloc to every tx for a multi-sig case that's rare.
  Type system makes the choice load-bearing.

FUZZWRAPALLTXKINDS (Red round 3 follow-up #3):
- For any byte slice, AT MOST ONE WrapXxxTx returns nil. All others MUST
  return ErrWrongTxKind / ErrWrongSchemaVersion / typed zap.Parse error.
- 23 wrapper tests in parallel; 1.4M+ execs clean on M1 Max with 15s
  fuzztime. No panics, no cross-type confusion, no untyped errors.

ZAP V0.7.2 DEPS:
- go get github.com/luxfi/zap@v0.7.2 — pulls Object.ListStride,
  List.Len SAFETY doc, FuzzParse.

RESULTS.md REFRESH (v0.7.2 M1 Max):
- Geomean Parse × = 7.71× (up from 7.33× v0.7.1; v0.7.2 ListStride
  accept-path cost is negligible — one mul + compare per List() call)
- All 9 ZAP-native types in v0.7.2 column; v0.7.1 M4 Max numbers
  retained side-by-side (no M4 access in this session)
- Build regression on M4 Max still tracked (v0.7.x follow-up to attack
  zap.Builder per-call overhead)

Tests:
- 11 new round-trip + cross-type tests under TestBatch4_*, TestOwner*,
  TestAddValidator/Delegator/PermissionlessDelegator/ChainValidatorTx*,
  TestCreate{Network,SovereignL1}Tx*, TestTransformChainTx*,
  TestConvertNetworkToL1Tx*
- All existing tests (incl. RED-HIGH-1/2/3, MEDIUM-1, V18) still green
2026-06-02 15:47:38 -07:00
Hanzo AI 3df13caa15 platformvm/txs/zap_native: close LP-023 v3.1 Red round 2 wire gaps (RED-HIGH-1/2/3, RED-MEDIUM-1)
Bumps luxfi/zap to v0.7.1 which closes the underlying wire-layer gaps
(uncapped Object.List length, backward-pointer header aliasing, size=0
Parse), and reworks the zap_native package to:

 - Use zap.Version2 as the schema-version gate. Every Wrap*Tx now routes
   through parseAndCheckKind(b, want), which rejects any Version1 buffer
   with ErrWrongSchemaVersion before TxKind interpretation. Closes the
   v2-vs-v3 cross-schema confusion (RED-MEDIUM-1) where a v2-shaped
   BaseTx with NetworkID=11 had byte 0 == TxKindBaseFull == 0x0B.

 - Add EvidenceList.Bind(messageBlobs, signatureBlobs) → EvidenceList,
   and safe accessors EvidenceEntry.MessageA/B + SignatureA/B that clamp
   wire (Rel,Len) cursors against parent-blob length. Returns empty
   slice on poisoned cursors (RED-HIGH-3) instead of panicking on
   mb[rel:rel+len]. The raw *Range() accessors are now documented UNSAFE
   and kept only for internal/test use.

 - Add SigIndicesArray.Slice(start, count uint32) → []uint32 and
   SignatureArray.Slice(start, count uint32) → [][SigBlobSize]byte.
   Both methods were referenced in comments but missing; consumers
   indexing .At() in a loop with attacker-controlled start/count would
   have iterated 4G times on poisoned wire (RED-HIGH-3 follow-on).

 - Update batch3_test.go::TestEvidenceListRoundTrip to use the safe
   bound accessors (the prior `mb[mARel:mARel+mALen]` pattern is exactly
   the consumer-side panic surface Red demonstrated).

Regression tests added to security_test.go:
  TestRedRound2_HIGH3_EvidenceListSafeAccessorsClamp
  TestRedRound2_HIGH3_SigIndicesArraySliceClamp
  TestRedRound2_HIGH3_SignatureArraySliceClamp
  TestRedRound2_MEDIUM1_V2BufferRejectedAtSchemaGate
  TestRedRound2_MEDIUM1_HonestV2BuffersStillWork

Geomean Parse speedup vs legacy codec: 7.03× (was 7.09×; +0.5% noise).
2026-06-02 15:13:57 -07:00
Hanzo AI 452468bfe0 platformvm/txs/bench_results: v3 multi-host bench results (M1 Max + M4 Max)
Schema v3 (TxKind discriminator) reproduces predicted v2→v3 lift within
noise: Parse geomean 7.11× on M1 Max (n=9 native types), 8.02× on M4 Max
— matches Red model (v2 8.39× → v3 7.09× projected). Per-type allocs 3.57×
fewer, bytes 6.89× smaller, host-stable.

AdvanceTime end-to-end via txs.Codec wrapper: 34.14× M1, 42.76× M4 — ratio
grows with chip speed (reflection tax is fixed-per-op).

Honest residual: Build is a regression on M4 Max for 6/9 types (geomean
0.86×). zap.Builder per-call overhead exposed on fast cores. M1 Max still
positive (1.12×). Tracked for luxfi/zap v0.7.0 (Blue v3.1 iteration);
Parse-side ship decision is independent.

Both hosts darwin/arm64 (M1 Max MacBookPro18,2 + M4 Max Mac16,5 / dbc
runner). Task spec called dbc "amd64 Linux" — corrected: it is darwin/arm64
Apple M4 Max. linux/amd64 numbers TBD until x86 box lands in ARC fleet.

Reproduce: GOWORK=off go test -bench='^Benchmark(Parse|Build)' -benchmem
-benchtime=500ms -count=3 -run='^$'
./vms/platformvm/txs/{bench,zap_native}/
2026-06-02 14:56:46 -07:00
Hanzo AI b6ce3a2159 platformvm/txs/zap_native: 5 batch-3 tx types composing the new primitives (LP-023 Phase 1)
TxKindBaseFull                    = 11  → BaseTxFull
  TxKindAddPermissionlessValidator  = 12  → AddPermissionlessValidatorTx
  TxKindImport                      = 13  → ImportTx
  TxKindExport                      = 14  → ExportTx
  TxKindCreateChain                 = 15  → CreateChainTx

Sizes (fixed section, schema v3):
  BaseTxFull                     =  85
  ImportTx                       = 125
  ExportTx                       = 125
  AddPermissionlessValidatorTx   = 381
  CreateChainTx                  = 221

Design highlights:

- BaseTxFull is the real P-chain spending envelope (Outs + Ins +
  Credentials + 2 shared arrays + Memo). The batch-2 BaseTx
  (TxKindBase) remains as the minimal metadata envelope for places
  that need only {NetworkID, BlockchainID, Memo} without spending
  state. Both kinds are first-class; they are NOT alternatives.

- Import / Export use a SINGLE combined Ins (or Outs) list with a
  header marker (ImportedInsStart/Count or ExportedOutsStart/Count)
  identifying the cross-chain slice. This collapses what would have
  been two parallel sig-index arrays into one shared array — fewer
  pointer pairs, no rebase bookkeeping. The slice-based indexing is
  byte-identical for the imported/exported half because they
  reference the same shared array.

- AddPermissionlessValidatorTx carries two single-address Owner stubs
  (validation rewards, delegation rewards) inline in the fixed
  section. The same OwnerStub type underlies CreateChainTx.Owner.
  Multi-address Owner ships in batch 4 along with the AddressList
  primitive; current callers needing multi-addr flow through the
  legacy codec gate.

- CreateChainTx embeds a 32-byte WarpMessageHash (sha256 of the
  originating Warp commit; zero when the chain is being created
  directly without a cross-network commit). The Warp message BODY
  is NOT embedded — it lives in the signed Warp envelope outside
  this tx. Hash-only embedding keeps the unsigned-tx bytes stable
  and the Warp envelope separately verifiable.

All five tx types follow the v3 invariant: TxKind@0, Wrap* rejects
mismatched discriminator with ErrWrongTxKind. Cross-confusion test
expansion verifies the new tx types in pairwise rejection (7
additional scenarios cover the batch 1+2+3 surface).

Deferred to batch 4 (no new primitives needed): the remaining ~18
classical platformvm tx types (CreateNetwork, AddDelegator,
AddPermissionlessDelegator, etc.) reuse the existing batch-3
primitives; their landings are mechanical.

go test -race ./vms/platformvm/txs/zap_native/...
  ok 	github.com/luxfi/node/vms/platformvm/txs/zap_native	1.488s
2026-06-02 14:35:03 -07:00
Hanzo AI 197dac4245 platformvm/txs/zap_native: batch 3 primitives — variable-length nested schemas (LP-023 Phase 1)
Five primitives. Each is fixed-stride at the entry level; variable
per-entry bytes/sub-list payloads live in shared sibling fields on
the parent tx, indexed by (start, count). This keeps List.At(i)
zero-allocation while supporting unbounded per-entry payload sizes.

  OutputList         stride  96  →  TransferableOutput
  InputList          stride  88  →  TransferableInput + shared SigIndicesArray
  CredentialList     stride  16  →  Credential        + shared SignatureArray
  WarpMessage        size    40  →  embedded {SourceNetwork, Payload}
  EvidenceList       stride  48  →  EvidenceEntry     + shared MessageBlobs/SignatureBlobs

Design choices:

- Stride is the entry-count semantics for SetList; the byte count from
  ListBuilder.Finish() is discarded. List.Object(i, stride) does the
  branch-free arithmetic.

- Variable per-entry data goes into a SIBLING field on the parent tx
  (not into the entry's stride): InputList → SigIndicesArray;
  CredentialList → SignatureArray; EvidenceList → MessageBlobs +
  SignatureBlobs. Each entry references its slice via (start, count).
  This pattern lets entries stay fixed-stride and accessors stay
  zero-allocation. Multi-input-shared signature arrays also enable
  signature deduplication when adjacent inputs share signers.

- Forward-only relOffsets per the F1 contract: SetBytes-backed payload
  fields (WarpMessage.Payload, EvidenceList parent's MessageBlobs/
  SignatureBlobs) flow through the F1-fixed zap.Object.Bytes which
  rejects negative bit-patterns.

- Read-only contracts on every []byte / by-value accessor are
  documented with the canonical defensive-copy idiom
  (append([]byte(nil), m...)) per AT1.

- Multi-address Owner is NOT yet supported at the wire layer; v3
  OutputList carries the single-address stub identical to
  TransferChainOwnershipTx. Multi-address callers still flow through
  the legacy codec gate behind LUXD_ENABLE_LEGACY_CODEC. The
  AddressList primitive ships in batch 4 (defer).

- Multi-signature credentials handled via the SignatureArray slice
  semantics — one Credential, N sigs. Post-quantum credentials
  (ML-DSA) are NOT YET on the v3 path; they keep flowing through
  legacy until their dedicated PQ Credential schema lands.

Round-trip tests (batch3_test.go) cover all five primitives + the
empty-list/null-pointer fallback path. go test passes; race-free.

Updated bench numbers for v3 batch-2 (the +1-byte TxKind tax):
  Parse geomean speedup vs legacy: 7.09× (was 8.39× pre-v3)
  Build geomean speedup vs legacy: 1.35× (build path was always
  closer to parity; structure-allocator dominates at small tx sizes)
2026-06-02 14:27:01 -07:00
Hanzo AI a06562ba95 platformvm/txs/zap_native: schema v3 with TxKind discriminator (LP-023 Phase 1)
Phase A response to Red's batch-2 review:

F2 (MEDIUM, cross-type confusion) — schema-bump v2→v3. Every fixed
section now carries a TxKind uint8 at offset 0; every other field
shifts by +1 byte. Wrap*Tx reads TxKind first and returns
ErrWrongTxKind on mismatch. Constructors write the kind
unconditionally. Closes the gap where an AdvanceTimeTx buffer wrapped
as a BaseTx returned garbage-but-deterministic field reads.

  TxKind enum (dense, 0 reserved):
    1=AdvanceTime  2=RewardValidator  3=SetL1ValidatorWeight
    4=IncreaseL1ValidatorBalance  5=DisableL1Validator  6=Base
    7=RegisterL1Validator  8=SlashValidator
    9=TransferChainOwnership  10=RemoveChainValidator

  v3 sizes (each +1 vs v2 from the TxKind byte):
    AdvanceTimeTx              =  9
    RewardValidatorTx          = 33
    SetL1ValidatorWeightTx     = 49
    IncreaseL1ValidatorBalanceTx = 41
    DisableL1ValidatorTx       = 33
    BaseTx                     = 45
    RegisterL1ValidatorTx      = 217
    SlashValidatorTx           = 57
    TransferChainOwnershipTx   = 69  (no natural-alignment padding; reads are alignment-tolerant)
    RemoveChainValidatorTx     = 53

F1 (MEDIUM, memo malleability) — closed at the luxfi/zap wire layer
in v0.6.1 (negative relOffset rejected in Object.Bytes). Bumped node's
go.mod replace: zap v0.2.0 → v0.6.1. TestRed_V2 now confirms the
defense via the nil-Memo branch.

F4 (INFO, doc bugs) — RegisterL1ValidatorTx comment now correctly
declares size 217; TransferChainOwnershipTx now correctly declares
size 69. Both sizes flow from offset arithmetic — no magic numbers.

AT1 (accepted tradeoff, memo aliasing) — BaseTx.Memo() docstring
escalated: READ-ONLY contract + the canonical defensive-copy idiom
(append([]byte(nil), m...)). Same pattern documented for every
variable-length accessor going forward.

Brand cleanup: SlashValidatorTx.Subnet() → Network() and
RemoveChainValidatorTx.Subnet() → Network(). Zero `Subnet*` symbols
in batch-2 code path. Tests updated.

V14 security test now exhaustively covers cross-confusion: 10
pairings of {valid-tx-buf, wrong-Wrap} + reserved TxKind=0 — all
reject with ErrWrongTxKind. The other 19 Red vectors continue to
pass under v3.

go test -race ./vms/platformvm/txs/zap_native/...
  ok 	github.com/luxfi/node/vms/platformvm/txs/zap_native	1.446s

Coordinated with luxfi/zap@v0.6.1 (F1 fix).
2026-06-02 14:09:13 -07:00
Hanzo AI 96c5320f7a wallet/network/primary: fail-soft FetchState when X-Chain disabled
Post-coreth networks (test+dev primary that bake only P + EVM genesis chains)
run in P-only mode where the X alias is not registered. The wallet's
FetchState now degrades the X-Chain context to a sentinel ids.Empty
BlockchainID instead of erroring, and skips the X-chain entry from the
chain-pair UTXO scan when X is unavailable.

Required to drive IssueCreateChainTx via the canonical primary wallet
against the fresh test+dev primaries (closes universe #168).
2026-06-02 13:48:46 -07:00
Hanzo AI 7aa01da346 platformvm/txs/zap_native: 5 more tx types (LP-023 Phase 1 batch 2)
Native ZAP encoding — no marshal step, struct IS wire format — for the
next batch of platformvm tx types. Same pattern as Phase 1 batch 1.

New types (v1 schemas; variable-length nested fields deferred to batch 3):
  base_tx.go                     — NetworkID + BlockchainID + Memo
                                   (Outs/Ins → batch 3)
  register_l1_validator_tx.go    — ValidationID + BLS pubkey 48B + PoP 96B
                                   + Expiry + RemainingBalanceOwnerID stub
                                   (Warp Message + full OutputOwners → batch 3)
  slash_validator_tx.go          — NodeID + Subnet + SlashPercentage
                                   (Evidence variable-length → batch 3)
  transfer_chain_ownership_tx.go — Chain + Owner{threshold,locktime,addr} v1 stub
                                   (full OutputOwners list → batch 3)
  remove_chain_validator_tx.go   — NodeID + Subnet
                                   (ChainAuth lives in signed wrapper)

Tests + benches extend the existing all_tx_types_test.go +
all_types_bench_test.go infra (no duplication). 18 new accessor zero-alloc
sites verified, including 48B BLSPublicKey and 96B PoP by-value returns.

Aggregate bench results (Apple M1 Max, Go 1.24, -benchtime=2s):

  Parse Legacy vs ZAP:
    BaseTx                      470.0  →  60.42 ns  ( 7.8x)  152→24 B  3→1 alloc
    RegisterL1ValidatorTx       1008   →  75.03 ns  (13.4x)  384→24 B  6→1 alloc
    SlashValidatorTx            690.6  →  82.74 ns  ( 8.3x)  176→24 B  4→1 alloc
    TransferChainOwnershipTx    2459   → 161.5  ns  (15.2x)  192→24 B  4→1 alloc
    RemoveChainValidatorTx      879.6  → 117.2  ns  ( 7.5x)  176→24 B  4→1 alloc

  Parse cross-type mean (10 types now native): 8.5x speedup.

  Build (one-time per proposer, dominated by Parse on consensus path):
    BaseTx       1.5x slower (memo SetBytes deferred-copy; acceptable trade)
    Register     1.03x       (allocs 7→2)
    Slash        1.4x faster (allocs 5→2)
    Transfer     0.96x       (allocs 5→2)
    Remove       1.3x faster (allocs 5→2)

All accessor reads zero-alloc. All builds 1 alloc on read path.

Verification:
  cd ~/work/lux/node
  GOWORK=off go build ./vms/platformvm/txs/zap_native/...
  GOWORK=off go test  ./vms/platformvm/txs/zap_native/...
  GOWORK=off go test -bench=. -benchmem -benchtime=2s \\
    ./vms/platformvm/txs/zap_native/...

Activation 1782604800 (2026-07-01 00:00 UTC) unchanged.
LUXD_ENABLE_LEGACY_CODEC=1 opts INTO legacy unchanged.

Refs LP-023. Next: batch 3 — variable-length nested-object schemas (Outs/Ins
lists, Warp Message payloads, full OutputOwners, Evidence) + remaining tx
types via codegen.
2026-06-02 13:34:12 -07:00
Hanzo AI 6f1c1811ca platformvm/txs/bench: Scientist comprehensive ZAP vs linearcodec harness + results (LP-023)
Real-workload benchmark suite produced by the scientist agent. Production-
realistic measurements on Apple M1 Max (Go 1.24).

Harness (8 files + results + reproduce docs):
  bench/fixtures.go           — realistic per-type tx fixtures
  bench/parse_bench_test.go    — per-type Parse: Legacy vs ZAP
  bench/build_bench_test.go    — per-type Build
  bench/field_bench_test.go    — field access (single + 1M batch)
  bench/workload_bench_test.go — 1000-tx mempool + 200-block parse + dispatcher
  bench/alloc_bench_test.go    — 5s sustained-parse GC pressure
  bench/disable_legacy_test.go — LUXD_ENABLE_LEGACY_CODEC gate verification
  bench/README.md              — reproduce + capture procedures
  bench/testdata/README.md     — captures notes
  bench_results/RESULTS.md     — full numbers + honest caveats + CPU profile

Headline numbers (vs linearcodec):
  Parse AdvanceTimeTx        : 37x faster (1940 ns -> 52.5 ns), 20x less mem
  Build AdvanceTimeTx        :  5.2x faster
  Sustained 5s parse loop    : 18.5x throughput (777k -> 14.4M parses/sec)
  Cross-type mean            :  5.6x parse,  1.6x build
  Allocations (parse, build) : always 3->1 and 4->2

CPU profile:
  Legacy: ~50% in reflectcodec.{marshal,unmarshal} reflection walk,
          ~30% in runtime.{madvise,kevent} from per-field alloc GC pressure
  ZAP:    elimination of both surfaces; offset arithmetic + 1 alloc per parse

Honest caveats (verbatim from scientist report):
  - Only 5/33 tx types have native paths today; mempool mix workload
    compresses to ~1.1x lift until BaseTx + AddPermissionless* native ship
  - Field access: single uint64 read is 2.1x slower (offset deref vs struct
    field), break-even at ~3,560 reads per parse; mainnet validators do
    ~10x per tx so ZAP still wins by orders of magnitude in the real regime
  - darwin/arm64 only — re-run on linux/amd64 before quoting production-
    binding numbers
  - LUXD_ENABLE_LEGACY_CODEC gate verified at zap_native surface (subprocess
    test passes); NOT yet wired into platformvm/txs.Parse — would break
    byte-preserving v0 read for validators bootstrapping pre-activation
    history. Gate enforcement lives at the future wire dispatcher.

Recommendation (CTO direction): continue the migration. Architecture works
as designed. Next priority: BaseTx + AddPermissionless* native paths — the
two highest-weight tx types in the modal mainnet mempool mix.

txs/tx.go is unmodified — byte-preserving v0->TxID migration invariant
preserved per existing codec.go CodecVersionV0/V1 framework.

Reproduce: cd ~/work/lux/node && GOWORK=off go test -bench=. -benchmem ./vms/platformvm/txs/bench/...
2026-06-02 12:52:23 -07:00
Hanzo AI 05994f1d56 platformvm/txs/zap_native: 4 more tx types + aggregate benchmarks (LP-023 Phase 1 batch 1)
Adds native ZAP encoding for the L1-management tx types — same pattern as
AdvanceTimeTx canary. No marshal step, zero-copy accessors, zero-alloc
field reads.

Types added:
  RewardValidatorTx              — TxID (32 bytes)
  SetL1ValidatorWeightTx         — ValidationID + Nonce + Weight (48 bytes)
  IncreaseL1ValidatorBalanceTx   — ValidationID + Balance (40 bytes)
  DisableL1ValidatorTx           — ValidationID (32 bytes)

Tests:
  - Round-trip parity per type (build → wrap → equal)
  - All accessors zero-alloc (AllocsPerRun = 0)
  - Wire-format discrimination via IsZAPBytes magic

Benchmarks (Apple M1 Max, Go 1.24, real linearcodec reflection path vs ZAP):

  Tx Type                       | Parse Legacy | Parse ZAP | Speedup
  ------------------------------|--------------|-----------|--------
  AdvanceTimeTx                 |  216.9 ns/op | 38.92 ns  |  5.6x
  RewardValidatorTx             |  218.5 ns/op | 35.80 ns  |  6.1x
  SetL1ValidatorWeightTx        |  234.3 ns/op | 25.76 ns  |  9.1x
  IncreaseL1ValidatorBalanceTx  |  245.4 ns/op | 25.55 ns  |  9.6x
  DisableL1ValidatorTx          |  218.5 ns/op | 54.44 ns  |  4.0x

  Allocations: legacy 3 allocs / 120-136 B; ZAP 1 alloc / 24 B.
  4x reduction in allocs/op, ~5x reduction in B/op across the board.

  Build side: roughly even (both paths allocate a buffer); the win is on
  parse, which dominates real workloads (every validator parses every tx in
  every block).

Phase 1 batch 1 of 4. 5 types down, ~28 to go. Same pattern for each: schema
constants + Wrap + Builder + Test + Bench. Pattern is production-ready;
remaining types (BaseTx, ImportTx, ExportTx, CreateChainTx, validator
variants) follow the same shape with progressively more nested sub-objects
for Inputs/Outputs/Credentials.

Reproduce:
  cd ~/work/lux/node
  GOWORK=off go test -bench=. -benchmem ./vms/platformvm/txs/zap_native/
2026-06-02 12:43:01 -07:00
Hanzo AI b4d325be6c platformvm/txs/zap_native: invert env var — native ZAP default, legacy is opt-in
LUXD_DISABLE_LEGACY_CODEC → LUXD_ENABLE_LEGACY_CODEC (per user 2026-06-02
'should be LUXD_ENABLE_LEGACY_CODE=1 to turn it on').

Default: native ZAP for every read + write. codec.Codec.Marshal/Unmarshal
gone from hot path. Fresh deployments + post-activation production get a
smaller, faster binary with no legacy code reachable.

Operators with pre-activation history that needs reading set
LUXD_ENABLE_LEGACY_CODEC=1 to opt in to backward-compat. Without it, legacy
bytes return ErrLegacyCodecDisabled.

Tests updated for the inverted default; pass clean.
2026-06-02 12:39:13 -07:00
Hanzo AI 80e1881285 platformvm/txs/zap_native: canary AdvanceTimeTx native-ZAP encoding (LP-023)
No marshal. No codec.Codec interface. The struct wraps the ZAP buffer
literally. tx.Bytes() returns the buffer. WrapAdvanceTimeTx(b) wraps b in
a typed accessor. Both are zero-copy.

Architecture per LP-023:
- ZAPActivationUnix = 1782604800 (2026-07-01 00:00 UTC)
- LUXD_DISABLE_LEGACY_CODEC=1 → legacy linearcodec returns ErrLegacyCodecDisabled
- IsZAPBytes(b) discriminates ZAP magic "ZAP\\x00" from linearcodec V0/V1
- ShouldUseZAPForWrite(blockTimestamp) gates new writes

Real benchmark numbers on Apple M1 Max (Go 1.24):

  Parse   linearcodec 129.4 ns/op  72 B 2 allocs
          zap         36.22 ns/op  24 B 1 alloc   → 3.57x faster
  Build   linearcodec 164.3 ns/op  96 B 4 allocs
          zap         70.55 ns/op  72 B 2 allocs  → 2.33x faster
  Field   linearcodec  0.34 ns/op  (struct deref baseline)
          zap          0.75 ns/op  (offset Uint64) — sub-ns, effectively free

Tests:
  TestAdvanceTimeTxRoundTrip    — build → parse → equal
  TestAdvanceTimeTxZeroAlloc    — Time() accessor 0 allocs/run
  TestAdvanceTimeTxBytesReusable — &Bytes()[0] stable
  TestIsZAPBytes
  TestShouldUseZAPForWrite

This is Phase 0 of the LP-023 migration. Phase 1: schemas + accessors for
the remaining 32 platformvm tx types using the same pattern. Phase 2:
replace codec.Codec.{Marshal,Unmarshal} call-sites in platformvm/{txs,
mempool,block,state,executor}. Phase 3: validator coordination + activation.
Phase 4: post-activation legacy code removal.

Reproduce: GOWORK=off go test -bench=. -benchmem ./vms/platformvm/txs/zap_native/
2026-06-02 12:34:56 -07:00
Hanzo AI cac801667f Dockerfile: bump EVM_VERSION v0.18.16 → v0.18.18
Pulls in plugin/evm StateScheme fix that unblocks fresh L2 EVM chain
creation on lux-mainnet (hanzo, zoo, spc, pars), where the plugin was
panicking with "panic in eth.New: triedb parent [<EmptyRootHash>] layer
missing" because eth/backend.go inherited geth's path-by-default for
empty DBs while the VM hard-refuses path mode upfront.

See luxfi/evm v0.18.18 commit 1dea806f8.
2026-06-02 11:56:01 -07:00
Hanzo AI 78d157a01f fix: gofmt -s across repo (CI format check) 2026-06-02 11:39:52 -07:00
Hanzo AI 374492edb2 go.mod: bump luxfi/genesis v1.12.19 -> v1.13.8 (RLP-matching mainnet+testnet+zoo-mainnet genesis embeds)
Embedded //go:embed configs/{mainnet,testnet,devnet,localnet} now contains
canonical 2-alloc genesis.json's reverted for RLP import compatibility:

- mainnet C-Chain (96369): block 0 = 0x3f4fa2a0...   MATCH lux-mainnet-96369.rlp
- testnet C-Chain (96368): block 0 = 0x1c5fe377...   MATCH lux-testnet-96368.rlp
- zoo-mainnet  (200200):   block 0 = 0x7c548af4...   MATCH zoo-mainnet-200200.rlp

Each had been wedged by 43 PQ precompiles baked into config.precompileUpgrades
at blockTimestamp:0, mutating state root + producing non-canonical hash.
Activations moved to forward-dated upgrade.json (blockTimestamp 1766708400).

Also bumps pkg/genesis/security to v1.13.8 to stay version-locked.
Tidy drops bft v0.1.5 (no longer indirect).
2026-06-02 04:25:27 -07:00
Hanzo AI 0f6e553215 docker: drop gcr.io distroless for scratch runtime in heartbeat-tx example
We don't use gcr.io across lux/hanzo/zoo. Switch the heartbeat-tx example
runtime stage from gcr.io/distroless/static-debian12:nonroot to
FROM scratch, copying ca-certs, tzdata, and passwd/group from the builder.
2026-06-02 03:34:39 -07:00
Hanzo AI 3dd407105b Dockerfile: bump EVM_VERSION v0.18.15 → v0.18.16
luxfi/evm v0.18.16 fixes the nil-chainConfig panic at PQ gate that
made v1.28.15's image-baked EVM plugin crash on fresh-PVC pq:true
bootstrap. Discovered during localnet 1337 bring-up (#148).

Root cause in v0.18.15: vm.chainConfig.PQ was being set BEFORE
vm.chainConfig was assigned from g.Config — nil-deref in
plugin/evm/vm.go Initialize().

v0.18.16 moves the gate AFTER assignment.

This unblocks v1.28.16 image build → unblocks localnet 100% green
→ unblocks cluster deploys (devnet → testnet → mainnet).
2026-06-02 01:05:57 -07:00
Hanzo DevandGitHub ada7c25f2c ci(release): cross-compile darwin binaries on lux-build pool
GitHub-hosted macos-13 queues block the release pipeline for hours.
The build is already pure Go cross-compile (CGO_ENABLED=0 GOOS=darwin
GOARCH=$arch) so there's no reason to use a Mac runner. Route through
the self-hosted lux-build ARC pool (fast, plentiful) instead.

Replace 7z (not on ubuntu) with apt-installed zip in the same step.
Output filename + artifact name are unchanged.
2026-06-01 22:55:13 -07:00
Hanzo AI fec6f036d4 go.mod: bump luxfi/consensus v1.25.12 → v1.25.13 (gofmt fixes) 2026-06-01 22:02:34 -07:00
Hanzo AI 0bc87a29af go.mod: bump luxfi/accel v1.1.7 → v1.1.8 + consensus v1.25.12 + threshold v1.9.7 + kms v1.11.2 + pulsar v1.1.2
Whole-tree sync to latest closure-swarm tags. accel v1.1.8 ships
c_api.h via //go:embed so go mod vendor preserves it (fixes fresh-clone
CI builds across all consumers).
2026-06-01 22:01:22 -07:00
Hanzo AI d1ac0cdf5b go.mod: consensus v1.25.9 → v1.25.11; pulsar v1.0.23 → v1.1.1; threshold v1.9.2 → v1.9.4
PULSAR-V04-CTX cascade landing:
  - pulsar  v1.0.23 → v1.1.1  (v0.4 ctx-bound algebraic-aggregate
                                threshold sign — full Round1→Round2W→
                                Round2Sign→AlgebraicAggregateCtx with
                                FIPS 204 §5.4 ctx threaded into μ; no
                                single-party dealer shortcut anywhere)
  - threshold v1.9.2 → v1.9.4  (dispatcher pulsar.Sign_Ctx rewired
                                onto full algebraic-aggregate path; no
                                master sk materialised in dispatcher
                                process at any point during sign)
  - consensus v1.25.9 → v1.25.11 (passes the bumps through)

Test gates green on tip:
  GOWORK=off go test -count=1 -short -timeout 600s ./vms/platformvm/...
  GOWORK=off go test -count=1 -short -timeout 600s ./network/...
  GOWORK=off go test -count=1 -short -timeout 600s ./consensus/...
2026-06-01 21:56:39 -07:00
Hanzo AI 4cb7484387 go.mod: consensus v1.25.8 → v1.25.9 (magnetar v1.2.0 dealerless PVSS-DKG)
Cascade:
- magnetar v1.1.0 → v1.2.0 (closes MAGNETAR-PVSS-DKG-V11)
- threshold v1.9.1 → v1.9.2 (magnetar bump)
- consensus v1.25.8 → v1.25.9 (threshold + magnetar bump)

Magnetar v1.2.0 lands a Schoenmakers-style PVSS-DKG over GF(257)
for THBS-SE setup. No trusted dealer; no party ever holds the
master byte vector at any time during setup. Share-envelope wire
shapes are byte-shape-identical to the dealer path, so already-
deployed share material is forward-compatible.
2026-06-01 21:25:05 -07:00
Hanzo AI b2f95a02a1 go.mod: bump luxfi/keys v1.0.9 → v1.1.0, luxfi/kms v1.9.13 → v1.10.1
luxfi/keys v1.1.0 lands the Bindel-Brendel-Fischlin (CCS 2021) +
CDFFJ23 (Asiacrypt 2023) stronger-binding hybrid signature scheme
for validator identity:

  HybridPublicKey / HybridPrivateKey / HybridSignature
  HybridSign / HybridVerify / HybridBoundDigest / HybridPublicKeyBytes
  DeriveHybridIdentity (mnemonic + path → HybridIdentity)

Construction binds BOTH pubkeys into m_bound via SHAKE256-384 under
domain "lux-hybrid-sig-v1" — security ≥ max(EUF-CMA_secp256k1,
sEUF-CMA_ML-DSA-65). Raw concat (the prior plan) only gives
min security under non-honest-key adversary (CDFFJ23 §4).

Classical = secp256k1 (matches existing P/X validator key format).
PQ = ML-DSA-65 (FIPS 204).

Use DeriveHybridIdentity for validator stake re-anchor flow:
classical leaf at m/44'/9000'/serviceIndex'/0'/0', PQ leaf at
m/44'/9000'/serviceIndex'/0'/1'. NodeID derived via single
SHAKE256-384 over wire-form hybrid pubkey (no BTC-style double hash —
cryptographer review confirmed single-SHAKE is sound).

luxfi/kms v1.10.1 follows with the matching go.mod bump.

Tests: go build ./... and go test -race -count=1 -short
./vms/platformvm/... PASS.
2026-06-01 21:03:49 -07:00
Hanzo AI fc4a9de6f2 go.mod: drop corona v0.7.5 replace — unblock consensus v1.25.8 build
consensus v1.25.8 (carries threshold v1.9.1 + magnetar v1.1.0) refactored
quasar/corona_gob.go and polaris.go to call sig.MarshalBinary() at the
Signature level. The wire-codec methods (Signature.{Marshal,Unmarshal}Binary)
were added in corona v0.7.6 — v0.7.5 only has them on the inner C/Z/Delta
polynomial fields.

The historical replace directive (07bb303044 on 2026-05-24) was added to
work around consensus v1.24.6 reaching back into corona via keyera.Bootstrap,
which since shipped its 3-value return at corona v0.7.5. consensus v1.25.x
now pins corona v0.7.6 in its own go.mod cleanly, so the replace is no
longer needed and is actively breaking the v1.28.8 image build.

Removing the replace lets MVS pick corona v0.7.6 transitively through
consensus → that is the version where MarshalBinary lives.

Reproduced the CI failure locally with CGO_ENABLED=0 GOWORK=off, fixed,
verified with a clean amd64 nattraversal-profile build (46.6MB binary)
and a full race-clean ./... suite (exit 0, no DATA RACE / panic markers).
2026-06-01 19:54:49 -07:00
Hanzo AI 0678a5b3fa Dockerfile: bump EVM_VERSION v0.18.14 → v0.18.15
luxfi/evm v0.18.15 ships core/genesis: honor SkipPostMergeFields flag
from JSON — the fix for the "triedb parent [0x56e81f17…] layer missing"
panic-in-eth.New that's blocking C-Chain bootstrap on lux-mainnet.

Lux mainnet C-Chain canonical genesis hash is 0x3f4fa2a0…, produced
with the 16-field pre-Shanghai header format. The chain activates
Cancun at genesis time for MCOPY etc., but the genesis BLOCK itself
must stay in the legacy header shape. The previous luxfi/evm tag
ignored skipPostMergeFields=true and shifted the computed genesis
hash to 0x1ade42ec…, which then failed to commit to pathdb because
the parent layer (0x56e81f17… = empty root) wasn't in the layertree.

The plugin baked into this image is at vmId
mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6 — confirmed via
strings of the running prod plugin binary (luxfi/evm/core symbols).
2026-06-01 19:35:54 -07:00
Hanzo AI a824135ba9 go.mod: consensus v1.25.7 → v1.25.8 (magnetar v1.1.0 strict-atom cascade)
consensus v1.25.8 carries threshold v1.9.1 which carries magnetar v1.1.0:
strict-atom Combine, audit-grep clean, byte-identity to circl FIPS 205,
35-51% faster than v1.0.

Race-clean across the full node ./... suite (exit 0; no DATA RACE / panic
markers; 30+ min compile-and-test on -race -timeout=15m).
2026-06-01 19:29:24 -07:00
Hanzo AI b88c4fdd09 genesis: add I/O/R chains to primary network registry
OracleVM, RelayVM, IdentityVM were previously registered as optional
VMs (loadable via CreateChainTx) but not part of the genesis-baked
primary network registry. Adding them to the registry means the VM
alias machinery + VMAliases map now know about all 14 primary-network
chains by canonical letter and alias set.

Order is append-only per the comment in registry.go — I/O/R land at
positions 12/13/14. Each row picks a unique alias triple:
  I: identity, identityvm, id
  O: oracle, oraclevm, feed
  R: relay, relayvm, msg

This change does NOT bake I/O/R into FromConfig's primary-genesis
optIn loop — that would require new IChainGenesis/OChainGenesis/
RChainGenesis fields on genesiscfg.Config plus matching ichain.json/
ochain.json/rchain.json shards under genesis/configs/{net}/. I/O/R
continue to be instantiated via CreateChainTx post-genesis (as today).
What the registry update unblocks is the alias resolution path so
when those chains DO get created, the VM manager knows them by
canonical name without per-chain switch-ladder edits.

builder.Aliases() gets matching cases for the three new VMIDs so
when a future genesis bakes them, chain alias registration works
without further changes.

Existing tests in TestChainAliasesRegistryParity and TestVMAliasesRegistryParity
get three new rows each; both pass.
2026-06-01 16:45:49 -07:00
Hanzo AI 509f5e79c7 merge: feat/scale-standard 2026-06-01 16:35:45 -07:00
Hanzo AI 243f8ed358 merge: feat/create-sovereign-l1-tx 2026-06-01 16:35:45 -07:00
Hanzo AI 464493edf2 merge: chore/kill-fuji 2026-06-01 16:35:44 -07:00
Hanzo AI f55f4de7e9 keyutil: thread *keys.ServiceIdentity into LoadMnemonicFromKMS dial
The KMS consensus-auth gate now requires every secret-opcode envelope
to carry a signed identity. Derive a bootstrap ServiceIdentity from
KMS_BOOTSTRAP_MNEMONIC (or MNEMONIC) under the well-known servicePath
"luxd/staking-bootstrap" and thread it into the LoadMnemonicFromKMS
call so the dial envelope is signed.

Bootstrap mnemonic is provisioned out-of-band (sealed envelope, HW
token unwrap, etc.); the operational staking material on disk still
comes from the KMS-held mnemonic the dial then fetches.
2026-06-01 16:15:41 -07:00
Hanzo AI ce30c8ac86 go.mod: consensus v1.25.7 + threshold v1.9.0 + corona v0.7.6 (Polaris cert wired, TEE extensions live) 2026-06-01 12:49:17 -07:00
Abhishek Krishna a3b7db1874 vms/txs/mempool: add AdmissionVerifier hook for encrypted-payload txs (#115)
Closes luxfi/node#115 by landing the admission-hook half of the issue.
The hook is the substrate the encrypted-mempool partition will use to
admit FHE-ciphertext transactions on (signature + fee + NIZK) without
decryption per LP-066 / luxfi/precompile/fhe.

Surface added:

  type AdmissionVerifier[T Tx] interface {
      VerifyAdmit(tx T) error
  }

  var ErrAdmissionRejected = errors.New("tx admission rejected")

  func NewWithAdmissionVerifier[T Tx](
      metrics Metrics,
      verifier AdmissionVerifier[T],
  ) *mempool[T]

  // New is now a thin wrapper around NewWithAdmissionVerifier(metrics, nil).
  // No behavioral change for existing callers.

Add() invokes verifier.VerifyAdmit last, after duplicate / size / space /
conflict have all passed. Ordering rationale: cheap rejects fire first,
so NIZK verification cost is only paid on a tx that passes structural
admission. A non-nil verifier return is wrapped in ErrAdmissionRejected,
records the drop reason via the existing droppedTxIDs LRU, and never
inserts the tx.

What this does NOT do:
  - It does not define the encrypted-payload tx type or its NIZK proof
    format. Those live in vms/platformvm/txs (or wherever the consumer
    decides) and ship in a follow-up.
  - It does not wire the FHE precompile's bootstrap-meter consultation —
    callers implementing AdmissionVerifier do that themselves.
  - It does not add the per-account FIFO partition for encrypted txs.
    The existing unissuedTxs Hashmap is per-mempool; the partition is
    a separate construction over multiple mempool instances and is a
    follow-up.

What it DOES do: lands the only mempool-side hook the issue requires
without locking us in on the encrypted-tx representation. The hook is
generic (`AdmissionVerifier[T Tx]`) so any future Tx variant can plug
in the same way.

Tests (CGO_ENABLED=0 go test -run TestAdmissionVerifier ./vms/txs/mempool/...
all pass):
  - nil verifier matches New (byte-identical behavior)
  - verifier returning nil admits the tx; gate fires exactly once on
    Add and not on Get / Peek / Iterate / Remove
  - verifier returning an error rejects with ErrAdmissionRejected
    wrapping the verifier's reason; drop reason recorded
  - cheap checks short-circuit before the gate runs (duplicate /
    oversize / conflict all skip the gate)

Refs:
  - issue #115 (this repo)
  - LP-066 (F-Chain confidential compute)
  - LP-183 (ZAP envelope decode precompile; downstream consumer once
    encrypted-payload tx propagation through gossip lands)
  - luxfi/threshold issue #20 (real distributed FHE decryption; the
    block-proposer-side counterpart to this admission-side hook)
2026-06-01 22:32:59 +05:30
Abhishek Krishna 0994d6ce51 test(errors): cover Wrap/Multi/Join/Is* and category inference (100%)
The github.com/luxfi/node/errors package shipped with zero tests despite
being a public utility surface (sentinel errors, WrappedError context
chain, Multi/Join aggregation, retry helpers). This adds 22 tests covering:

- WrappedError.Error format (with and without message)
- Wrap/WrapWithContext nil pass-through and context preservation
- errors.Is / errors.As chain through Wrap (incl. double-wrap)
- IsNotFound, IsClosed, IsTimeout helpers
- IsTemporary against both sentinel errors and the Temporary() interface
- IsPermanent across all permanent sentinels + fmt.Errorf %w chains
- GetCategory: wrapped category, sentinel inference, unknown fallback,
  and the precedence rule (wrapped category beats inferred category)
- Multi.Error/Add/Err for 0, 1, and N errors; nil-add ignored
- Join nil pass-through and multi-error combination

Result: 100.0% statement coverage, race-clean.
2026-06-01 12:08:28 +00:00
Hanzo DevandGitHub 9cf3fb0e21 Merge pull request #126 from luxfi/fix/invalidate-stale-genesis-cache
fix(config): invalidate cached genesis on parse failure
2026-06-01 01:43:22 -07:00
Hanzo AI 239325cf29 fix(config): invalidate cached genesis on parse failure instead of CrashLooping
The cached `<dataDir>/genesis.bytes` file is written on first start to
hold hash stability across restarts. On a binary upgrade that adds
new codec types (multi-version v0+v1 dispatcher, etc.), the old
cached blob may carry type IDs the new binary doesn't recognise. The
existing code surfaced this as `resolve X-Chain asset ID from cached
genesis: unmarshal interface: unknown type ID N` and returned an
error — wedging the node in CrashLoop with no automatic recovery.

Drop the cache and rebuild from the `--genesis-file` instead. Hash
stability is forfeit for that single restart (intentional — the
alternative is a permanent outage on every binary bump that changes
codec types). Subsequent restarts re-establish stability against the
fresh cache.

Surfaced today on <tenant> testnet+mainnet bumping lqd v1.9.x →
v1.10.8: every pod hit "unknown type ID 29" on the stale v1.9.x
codec cache and CrashLoopBackOff'd.
2026-06-01 01:43:00 -07:00
Abhishek Krishna 329926b001 docs: align Go version in README and CONTRIBUTING with go.mod (1.26.3)
README badge and prerequisites listed Go 1.21.12 / 1.23.9 in different
places, but go.mod requires Go 1.26.3. Bring the docs in sync so new
contributors install a toolchain that can actually build the node.
2026-06-01 14:06:50 +05:30
Hanzo AI eba96768c5 go.mod: consensus v1.25.5 + threshold v1.8.10 (race-clean, corona dispatcher live, naming decomplect) 2026-06-01 01:14:43 -07:00
Hanzo AI 699baf6a61 keyutil: rehome ZAP mnemonic import to luxfi/keys (was luxfi/kms)
Track A finish: KMS goes back to being a generic secret store; mnemonic
semantics live in luxfi/keys alongside the existing BIP-39 + BIP44
derivation. Imports flip from luxfi/kms/pkg/zapclient.LoadMnemonicFromKMS
to keys.LoadMnemonicFromKMS — same signature, same behavior.

Deps:
  luxfi/keys v1.0.8 → v1.0.9     (carries the new LoadMnemonic helper)
  luxfi/kms  v1.9.12 → v1.9.13   (LoadMnemonic removed, secret store only)

Build clean.
2026-05-31 21:30:21 -07:00
Hanzo AI 78fd705653 go.mod: consensus v1.25.4 + threshold v1.8.9 + magnetar v0.5.2 (race-clean threshold + MAGS/MAGG wire) 2026-05-31 18:20:38 -07:00
Hanzo AI e7b8f2f3c3 scrub: subnet/l2 → chain (final RELEASES.md cleanup, forward-only)
Wire-format codec IDs unchanged. CLI aliases deleted; chain is the
command. No backwards-compat shims, no deprecation comments.
2026-05-31 15:30:09 -07:00
Hanzo AI 41047b518c scrub: subnet/l2 → chain (canonical vocabulary, forward-only)
Wire-format codec IDs unchanged. CLI aliases deleted; chain is the
command. No backwards-compat shims, no deprecation comments.
2026-05-31 15:26:55 -07:00
Hanzo AI 4006253b59 keyutil: native-ZAP mnemonic fallback (priority 2)
Adds a KMS_ADDR-gated production path between the MNEMONIC env var
(priority 1) and the on-disk key files (priority 3). When set, the
mnemonic is fetched via luxfi/kms zapclient.LoadMnemonicFromKMS —
the same canonical loader every Lux-derived service (luxd, netrunner,
lux/cli, descending-L1 bootstraps) now shares.

New priority chain:
  1. MNEMONIC env var
  2. KMS_ADDR + KMS_ENV + KMS_MNEMONIC_PATH (native ZAP, default path /mnemonic)
  3. Key name from os.Args[1] (~/.lux/keys/<name>/)
  4. ~/.lux/keys/default/

Production env contract matches the <tenant> operator's render
(KMS_ADDR + KMS_ORG + KMS_ENV + KMS_MNEMONIC_PATH); every Lux chain
inherits the same scheme.

Dep:
  + github.com/luxfi/kms v1.9.12  (carries zapclient.LoadMnemonic)

Build clean.
2026-05-31 14:29:34 -07:00
Hanzo AI a5669aca69 go.mod: pulsar v1.0.23 + threshold v1.8.8 + consensus v1.25.3 + metric v1.5.7
Pulls in:
- pulsar canonical wire codec (PULS/PULG) + shared lattice/v7/gpu surface
- threshold protocols/{corona,pulsar} alias surface (no direct primitive imports)
- consensus routed through threshold/protocols alias
- metric noop counter race fix (atomic.Uint64)

Cross-repo audit closed: corona+pulsar+threshold production-ready for
permissionless mainnet. End-to-end TestPulsar_Wire_FIPS204Verifiable
asserts threshold-combined signatures are byte-identical to single-party
FIPS 204 ML-DSA signatures (verified externally via cloudflare/circl).
2026-05-31 12:45:26 -07:00
Hanzo AI f9096a4f5c fix(platformvm/state): route every state-side codec read through multi-version dispatcher
Closes the residual v1.28.1 testnet-canary failure where bootstrapping
a v1.23.x-written P-Chain database hit:

  P-Chain state corrupt after init — database must be wiped
  error="loadMetadata: feeState: unknown codec version"
  chainID=11111111111111111111111111111111P

The v1.28.1 patch routed genesis.Parse through the multi-version
txs.GenesisCodec dispatcher but did not touch the 7 OTHER state-side
sites that read via block.GenesisCodec — which carried only the v1 slot
map. Any pre-codec-v1 row on disk (feeState, heightRange, L1Validator,
fx.Owner, NetToL1Conversion, legacy stateBlk) errored at the very first
byte with codec.ErrUnknownVersion.

Architecture (Rich-Hickey-simple): make the codec itself complete for
all encountered wire versions rather than asking "which codec does
this caller need". block.GenesisCodec now registers BOTH the v0
(v1.23.x Apricot/Banff) and v1 (current) tx slot maps — reads
dispatch on the 2-byte wire prefix, writes still target
CodecVersion (== v1) exclusively. Same shape as txs.GenesisCodec
(decomplected from block parsing — block.Parse continues to extract
prefix explicitly because v0 blocks satisfy v0.Block, not block.Block,
and cannot be unmarshalled into a block.Block destination).

Audit found 7 state-side sites all using block.GenesisCodec; all 7
are routed through a new defensive helper:

  state.multiVersionUnmarshal(c codec.Manager, b []byte, dest any)

The helper is a pass-through to c.Unmarshal but probes the codec on
first observation. If the codec is missing the v0 slot, a structured
warning fires (once per codec pointer) so a future canary boot
surfaces ALL remaining single-version codecs in a single log scrape
rather than failing piecemeal across iterations:

  state-side codec is single-version; reads of v0-prefixed bytes
  will fail

block.RegisterGenesisType now symmetrically registers on both the v0
and v1 underlying linearcodecs so state-side types (currently:
stateBlk) keep slot-stable shapes across codec.Manager dispatch.

Audit table (all 7 broken sites → fixed):

  state/l1_validator.go:222         getL1Validator
  state/state_blocks.go:115         parseStoredBlock (legacy stateBlk)
  state/state_chains.go:66          GetNetOwner (fx.Owner)
  state/state_chains.go:116         GetNetToL1Conversion
  state/state_metadata.go:176       loadMetadata (heightRange)
  state/state_metadata.go:273       getFeeState  <-- canary failure
  state/state_validators.go:239     loadActiveL1Validators
  state/state_validators.go:535     initValidatorSets (inactive)

MetadataCodec was already multi-version (no fix needed).
txs.GenesisCodec was already multi-version (v1.28.0).
block.Codec stays v1-only by design (block.Block interface destination
cannot accept v0.Block types; Parse handles version split explicitly).

Tests (all -race green):

  block/codec_multiversion_test.go      6 tests
  state/state_v0_codec_test.go          9 tests including
                                          - TestStateV0FeeStateReadable
                                            (exact canary fixture)
                                          - TestStateBootFromV0SingletonDB
                                            (end-to-end boot simulation)
  state/codec_helpers_test.go           5 tests (warning probe +
                                          idempotency + non-blocking
                                          + multi-version invariant)

  -> 20 new regression tests
  -> 27/27 platformvm packages green under -race
2026-05-31 02:56:55 -07:00
Hanzo AI 55f52abcd9 fix(platformvm/genesis): route Parse through multi-version codec.Manager
v1.28.0's block-codec multi-version dispatch did not extend to the
P-Chain genesis decoder. genesis.Codec aliased block.GenesisCodec,
which registers only the v1 tx slot map; v0-prefixed cached-genesis
blobs (carried over from v1.23.x bootstraps) errored at first byte
with codec.ErrUnknownVersion.

Root cause hot path: config.getGenesisData -> resolveXAssetID ->
genesis/builder.XAssetIDFromGenesisBytes -> platformvm/genesis.Parse
-> Codec.Unmarshal(bytes, *Genesis). Codec was the v1-only
block.GenesisCodec.

Fix: alias genesis.Codec to txs.GenesisCodec, which registers BOTH the
v0 (Apricot/Banff) and v1 (current) tx slot maps. The Genesis struct
has no slot ID of its own; all version-sensitive data lives in the
embedded []*txs.Tx, so txs.GenesisCodec dispatches the same wire-
prefix lookup the rest of the platformvm tree already uses.

Marshal at CodecVersion (v1) is byte-equivalent because the v1 slot
map in txs.GenesisCodec is the SAME registerV1TxTypes() invocation
block.GenesisCodec was using.

Audit: every other Unmarshal site in vms/platformvm/ that touches
historical wire bytes either (a) goes through block.Parse / txs.Parse
which already dispatch on the prefix, or (b) reads internal state
written by v1-only code (block.GenesisCodec is correct there).

Regression guards in parse_v0_test.go:
  - TestParseAcceptsV0CachedGenesis: the canary failure mode.
  - TestParseAcceptsV1Genesis: canonical write path still parses.
  - TestParseV0RoundtripIsBytePreserving: v0 -> Parse -> re-marshal
    -> byte-equal, locking in the doc claim that genesis-derived
    hashes do not rotate across the migration.
  - TestParseRejectsUnknownVersion: prefixes outside {v0, v1} still
    surface as errors.

Full vms/platformvm/... tree green under -race; genesis/builder and
config trees green.
2026-05-31 02:26:49 -07:00
Hanzo DevandGitHub 5e9942cee1 feat(platformvm): multi-version codec — v0 (Apricot/Banff) + v1 (current) — byte-preserving TxID/BlockID across migration (#123)
Closes the codec-version trap that surfaced when the v1.23.x ("Apricot/Banff") tx + block layout was rip-replaced in 409297a089 without bumping the wire-version prefix: mainnet/testnet on-disk blobs (~1.08M+ C-Chain blocks) lost a decoder, and any code path that round-tripped a tx through tx.Initialize re-marshaled it under the new layout — rotating TxID and breaking chain-commitment continuity.

Strategy A per cryptographer / orchestrator brief:

* Register both layouts on the platformvm tx + block codec.Managers under
  distinct wire-version prefixes:
  - CodecVersionV0=0 = v1.23.x slot map (TransferInput=5, hole=6, ...,
    AddPermissionlessValidator=25, ..., DisableL1Validator=39)
  - CodecVersionV1=1 = current slot map (with MintOutput/MintOp at 6/8,
    +4-skip for Banff txs at 27-30, CreateSovereignL1Tx at 36,
    SlashValidatorTx at 41, CreateAssetTx/OperationTx at 42-43)
  - txs.Codec / block.Codec dispatch by the standard 2-byte wire prefix.

* New byte-preserving init: tx.InitializeFromBytes(c, version, signedBytes)
  and tx.InitializeFromBytesAtVersion(c, version) bind the tx to its
  original signedBytes without re-marshalling. tx.Initialize stays as the
  fresh-build path; from-DB / from-wire paths route through the
  byte-preserving variant. TxID = hash(signedBytes) under the version it
  was written at, forever.

* New vms/platformvm/block/v0/ subpackage: 9 v0-only block kinds
  (ApricotProposalBlock, BanffProposalBlock, ... at slots 0-4 + 29-32).
  Pure DTOs — no codec, no Visit. The block package wraps the decoded
  v0.Block in a liftedV0Block adapter that:
  - returns the original bytes verbatim (no re-marshal),
  - BlockID = hash(raw v0 bytes),
  - dispatches Visit to the v1 Visitor arms (ApricotProposalBlock /
    BanffProposalBlock -> ProposalBlock, etc.),
  - re-binds embedded txs at v0 via InitializeFromBytesAtVersion so
    inner TxIDs are also byte-preserved.

* genesis.Parse is wire-version-aware: pre-codec-v1 genesis blobs decode
  at v0, new blobs at v1. The matching codec is used for tx re-binding.

* L1-tx slot map shifts +1 to accommodate CreateSovereignL1Tx at 36
  (RegisterL1Validator 36->37, SetL1ValidatorWeight 37->38,
  IncreaseL1ValidatorBalance 38->39, DisableL1Validator 39->40). Test
  fixtures regenerated.

* 22 fee-calculator fixtures + 11 serialization fixtures bumped to use
  the v1 wire prefix (0x0001) and the post-CreateSovereignL1Tx slot map.

Migration notes:
* Mainnet + testnet P-Chain DBs: NO rebuild. Pre-codec-v1 blocks
  continue to decode through the v0 path with original BlockID and
  TxIDs preserved. New blocks are written at v1 from the cut-over
  height onward.
* Devnet: must be rebuilt before rolling to v1.28.0. Its existing
  blobs carry wire-version 0 but use the post-rip slot map (not the
  v0 Apricot/Banff layout) — decoding them through the v0 path would
  read the wrong types. A fresh bootstrap at v1.28.0 writes v1 bytes
  from height 0 and is internally consistent thereafter.

Tests:
* TestCodecVersionV0V1Coexist, TestParseDispatchesByVersion,
  TestTxIDStabilityRoundTrip, TestCrossVersionRefuses (txs)
* TestParseV0ApricotProposalBlock, TestParseV0BanffStandardBlock,
  TestParseV1RoundTrip, TestVersionPrefixDispatch (block)
* 150 packages, 0 failures under -race
2026-05-31 01:38:42 -07:00
Hanzo DevandGitHub a338d63999 bump(consensus): v1.25.1 → v1.25.2 (#122)
Picks up ChainConsensus.ForceAccept — the consensus-level counterpart
to ForcePreference. Together with the engine.finalizeOwnProposal helper,
this lets a proposer self-finalize its own block at proposal time when
peer Chits do not arrive in time, closing the CreateChainTx stall
observed on devnet under low validator counts.

- ChainConsensus.ForceAccept(blockID) — direct accept bypassing alpha/K
  quorum, guarded by engine path (IsOwnProposal=true) and idempotent.
- Engine path uses ForceAccept after ForcePreference on own proposals
  so the proposing node commits locally and other validators converge
  via the next poll round.

Test delta: pre-existing fee/static_calculator L1Tx parse failures on
main are unaffected; consensus, vms/platformvm/{block,blockmock,state,
warp,...}, and genesis/builder all pass with race -short.
2026-05-30 21:38:16 -07:00
Hanzo DevandGitHub da571888b9 test(genesis/builder): canonical evmAddr/utxoAddr fixture parse gate (#121)
Add TestCanonicalGenesisFixtureParses — loads the canonical mainnet
genesis.json (genesis v1.12.19 evmAddr/utxoAddr field names) through
genesiscfg.GetConfigFile and asserts EVMAddr/UTXOAddr decode to
non-zero ids.ShortID values.

This is the "have we adopted the rename" gate — if the loader
silently swallows the new field names (e.g. via a regression to
ethAddr/luxAddr struct tags), every allocation Address comes back
as ShortEmpty and the assertion catches it before that ships.

Test is host-path aware: skips when ~/work/lux/genesis is not on
disk (CI without sibling checkout), runs when it is.
2026-05-30 20:09:10 -07:00
Hanzo DevandGitHub f89cd28297 feat: bump consensus v1.25.1 (proposer fix) + genesis v1.12.19 (#120)
luxfi/consensus v1.25.0 → v1.25.1
  Proposer-self-accept gap on nova multi-node finality: the proposer of
  block B was never marking B locally accepted because manager.applyQbit
  re-derived peer Chits via a second blk.Verify() call which most VMs
  (notably PlatformVM CreateChainTx) are not idempotent under, flipping
  every Chits into synthetic Accept=false. Fix tags the proposer's own
  pending entry with IsOwnProposal=true and short-circuits the re-verify
  in handleVote — peer Chits now count as the genuine Accepts they are.

luxfi/genesis v1.12.15 → v1.12.19
  Decomplected: pkg/genesis/security/ is a nested module (own go.mod,
  tagged pkg/genesis/security/v1.12.19) that owns SecurityProfile
  verification — the only file in luxfi/genesis that imports
  luxfi/consensus. The rest of pkg/genesis stays consensus-dep-free.

  API change: pin.Resolve() → genesissecurity.ResolveProfile(pin).
  ErrSecurityProfileHashMismatch and ErrSecurityProfileInvalidID also
  moved to the security submodule. Updated node/node.go and
  node/security_profile_test.go to match.

Build: GOWORK=off go build ./...  clean (linker warnings about accel
  static lib path are pre-existing host-config noise, not a regression).
Vet:   GOWORK=off go vet ./...    clean (the cevm_e2e_test.go
  sync/atomic.Bool copy warning is pre-existing on v1.27.24 main).
Tests: ./consensus/... pass, ./genesis/... pass, ./node/...
  TestApplySecurityProfile_* pass. ./vms/platformvm/txs/fee L1-validator
  failures are pre-existing on v1.27.24 main and unchanged.

Devnet fixture (~/work/lux/genesis/configs/devnet/genesis.json) parses
clean: networkID=3, 5 initialStakers, canonical evmAddr/utxoAddr only.
2026-05-30 19:56:57 -07:00
Hanzo DevandGitHub be744a9dbf refactor: XAssetID → UTXOAssetID (#119)
The field is the primary network's UTXO fee asset (P+X), not
X-chain-specific. P-chain CreateChainTx / AddChainValidatorTx and
X-chain transfers all burn it for fees. Same number on P and X by
construction; the name should reflect the function, not the chain.

Renames applied across:
- wallet/chain/{p,x}/builder.Context.UTXOAssetID
- wallet/chain/x/builder.Backend.UTXOAssetID() trait method
- node/config: resolveUTXOAssetID + nodeConfig.UTXOAssetID
- vms/platformvm + vms/xvm + chains/manager consumers
- examples (deploy-chains, get-p-chain-balance, ...)

Includes local replaces for luxfi/{runtime,consensus} pending their
release tags landing. Drop after upstream tags ship.

Companion PRs: luxfi/runtime#2, luxfi/consensus#11. Downstream
consumers (sdk, cli, genesis, liquidity) follow.
2026-05-30 14:28:08 -07:00
Hanzo AI 8b2a559aef deps: proto v1.0.2 — consume SubnetUptime → ChainUptime rename
luxfi/proto#6 (merged) renames SubnetUptime → ChainUptime in
node/zap/p2p, completing the no-subnet vocabulary rule from
node#116. The local re-export in proto/p2p/p2p_zap.go was already
written against the new upstream name, breaking v1.27.22 builds:

  proto/p2p/p2p_zap.go:42:32: undefined: p2p.ChainUptime

Tagging v1.0.2 against the merged proto main and bumping the module
pin unblocks the build with zero code changes — the alias line is
unchanged because upstream already matches.

Build: clean. Test: pre-existing platformvm/txs/fee L1-validator
failures unchanged (not introduced here).
2026-05-30 09:35:04 -07:00
Hanzo DevandGitHub 21f2691b3d canonical evmAddr/utxoAddr only — bump genesis v1.12.15 (#118)
Pulls in luxfi/genesis v1.12.15 which strips the dual-name
luxAddr/ethAddr alias shim. AllocationJSON now emits and accepts only
the canonical evmAddr/utxoAddr field pair.

docker-entrypoint.sh genesis templates: switch luxAddr → utxoAddr +
ethAddr → evmAddr to match.

This is the cascade step needed before luxd v1.23.43 ships — the runtime
parser at v1.23.31 (current devnet image) reads ethAddr/luxAddr; v1.23.42
already reads evmAddr/utxoAddr internally; v1.23.43 (this commit + tag)
drops every back-compat alias both ways.

Tests: genesis/builder, vms/platformvm/genesis pass. End-to-end parse
of configs/devnet/genesis.json with canonical names: 1005 allocations,
5 initial stakers (matches 5-pod sybil quorum).

Cluster bump path: lux-devnet (1.23.31 → v1.23.43); testnet/mainnet
remain on v1.23.31 until coordinated migration.

Co-authored-by: Hanzo AI <dev@hanzo.ai>
2026-05-30 09:24:28 -07:00
Hanzo DevandGitHub c9dcb370c9 chore: update 2026-05-29 23:33:09 -07:00
Hanzo AI ec26a9781b chore: update 2026-05-29 23:29:08 -07:00
Hanzo DevandGitHub 09a4d1343d chore(node): kill subnet — chain/network vocabulary across node (#116)
* feat(platformvm): CreateSovereignL1Tx — single-tx sovereign L1 launch

Adds a new platformvm tx type that atomically registers a sovereign L1
in one P-chain commit. Replaces what is today the four-step flow:

  CreateNetworkTx + AddChainValidatorTx ×N + CreateChainTx ×K + ConvertNetworkToL1Tx

with one signed tx. After commit, the primary network has a permanent
record of the L1's network ID + initial validator set + chain manifest
+ on-chain validator-manager contract — but it does NOT track-chains
or validate the L1's blocks. The L1 runs its own consensus from
genesis. L2/L3/L4 follow the same pattern recursively.

Type shape:

  type CreateSovereignL1Tx struct {
    BaseTx
    Owner           fx.Owner                       // CreateNetworkTx parity
    Validators      []*ConvertNetworkToL1Validator // genesis validator set
    Chains          []*SovereignL1Chain            // VM ID + genesis blob per chain
    ManagerChainIdx uint32                         // index into Chains[]
    ManagerAddress  types.JSONByteSlice            // validator-manager contract
  }

  type SovereignL1Chain struct {
    BlockchainName string
    VMID           ids.ID
    FxIDs          []ids.ID
    GenesisData    []byte
  }

SyntacticVerify enforces:
  - at least one validator (sorted, unique)
  - at least one chain, ≤ MaxSovereignL1Chains (16)
  - ManagerChainIdx is in range of Chains[]
  - ManagerAddress ≤ MaxChainAddressLength
  - per-chain name + VMID + FxIDs + genesis bounds
  - BaseTx + Owner + each Validator each verify

Wired into:
  - Visitor interface
  - codec (registered as the next tx type after ConvertNetworkToL1Tx)
  - signer + complexity + metrics + executor stubs across all visitor
    implementations

Executor body is stubbed with a TODO. The atomic state transition
(mint new networkID from tx hash, seed validator-manager state,
register each Chain, charge fee) lands in a follow-up PR. This PR is
the type definition + interface plumbing so downstream tools (wallet,
CLI, fee calc, metrics) can target the tx type while the executor is
implemented.

* chore(node): kill subnet — chain/network vocabulary across node

Zero remaining `subnet|Subnet|SUBNET` in node Go source. Per canonical
no-subnet rule.

## Wire types (Go fields only; byte-level wire encoding unchanged)

  message/wire/types.go  TrackedSubnets    → TrackedChains
  message/wire/zap.go    same on Read/Write
  proto/p2p/p2p_zap.go   SubnetUptime alias → ChainUptime
                          (consumes luxfi/proto rename in companion PR)

## Comment scrub

  message/wire/types.go            "(chain, subnet) pair" → "(chain, network) pair"
  network/peer/handshake.go        "primary-network or subnet" → "primary-network or per-chain"
  node/node.go                     "per-subnet"   → "per-chain"
                                   "P→subnet warp" → "P→chain warp"
  genesis/builder/builder.go       "their own subnets" → "their own chains"
  vms/platformvm/client.go         dropped "subnet jargon" reference
  vms/platformvm/service.go        dropped "net / subnet jargon" reference
  vms/platformvm/config/internal.go  "subnet-spawned blockchain" → "per-chain blockchain"

## ICPSubnet (Internet Computer adapter)

  ICPSubnet → ICPNet  (type rename — unrelated to platform subnet,
                        but still a subnet word; killed for consistency)
  map field `subnets` → `nets`

## Examples

  wallet/network/primary/examples/bootstrap-hanzo/main.go:
    --subnet-id  → --network-id (CLI flag)
    existingSubnetID local var → existingNetID
    "subnet ID" log lines → "network ID"
    "SUBNET_ID=" output → "NETWORK_ID="
    "subnet-evm VM ID" → "EVM VM ID"
    All comments rephrased.

  wallet/network/primary/examples/heartbeat-tx/main.go: one comment
    rephrase.

go.work workspace cleanup:
  - Removed ./operator/go entry (placeholder; lux/operator polyglot
    layout pending the cross-repo migration)
  - Removed ./operator entry (mid-migration; nothing to build)

Build clean. Zero `grep -rIn "subnet|Subnet" --include="*.go"` matches.
2026-05-29 21:17:44 -07:00
Hanzo AI a575e37fe5 feat(platformvm): CreateSovereignL1Tx — single-tx sovereign L1 launch
Adds a new platformvm tx type that atomically registers a sovereign L1
in one P-chain commit. Replaces what is today the four-step flow:

  CreateNetworkTx + AddChainValidatorTx ×N + CreateChainTx ×K + ConvertNetworkToL1Tx

with one signed tx. After commit, the primary network has a permanent
record of the L1's network ID + initial validator set + chain manifest
+ on-chain validator-manager contract — but it does NOT track-chains
or validate the L1's blocks. The L1 runs its own consensus from
genesis. L2/L3/L4 follow the same pattern recursively.

Type shape:

  type CreateSovereignL1Tx struct {
    BaseTx
    Owner           fx.Owner                       // CreateNetworkTx parity
    Validators      []*ConvertNetworkToL1Validator // genesis validator set
    Chains          []*SovereignL1Chain            // VM ID + genesis blob per chain
    ManagerChainIdx uint32                         // index into Chains[]
    ManagerAddress  types.JSONByteSlice            // validator-manager contract
  }

  type SovereignL1Chain struct {
    BlockchainName string
    VMID           ids.ID
    FxIDs          []ids.ID
    GenesisData    []byte
  }

SyntacticVerify enforces:
  - at least one validator (sorted, unique)
  - at least one chain, ≤ MaxSovereignL1Chains (16)
  - ManagerChainIdx is in range of Chains[]
  - ManagerAddress ≤ MaxChainAddressLength
  - per-chain name + VMID + FxIDs + genesis bounds
  - BaseTx + Owner + each Validator each verify

Wired into:
  - Visitor interface
  - codec (registered as the next tx type after ConvertNetworkToL1Tx)
  - signer + complexity + metrics + executor stubs across all visitor
    implementations

Executor body is stubbed with a TODO. The atomic state transition
(mint new networkID from tx hash, seed validator-manager state,
register each Chain, charge fee) lands in a follow-up PR. This PR is
the type definition + interface plumbing so downstream tools (wallet,
CLI, fee calc, metrics) can target the tx type while the executor is
implemented.
2026-05-29 20:25:28 -07:00
cda97fa966 build(deps): bump the go_modules group across 1 directory with 2 updates (#106)
Bumps the go_modules group with 1 update in the / directory: [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp](https://github.com/open-telemetry/opentelemetry-go).


Updates `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` from 1.42.0 to 1.43.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.42.0...v1.43.0)

Updates `go.opentelemetry.io/otel/sdk` from 1.42.0 to 1.43.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.42.0...v1.43.0)

---
updated-dependencies:
- dependency-name: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp
  dependency-version: 1.43.0
  dependency-type: direct:production
- dependency-name: go.opentelemetry.io/otel/sdk
  dependency-version: 1.43.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-05-29 18:02:09 -07:00
Hanzo DevandGitHub d35185f064 build(node): GOEXPERIMENT=jsonv2 in Dockerfile per SCALE_STANDARD (#114)
Per SCALE_STANDARD.md §2 (~/work/hanzo/hips/docs/SCALE_STANDARD.md) —
every Go production Dockerfile that emits JSON to a client builds with
GOEXPERIMENT=jsonv2. Verified on hanzoai/zip's json_bench_test.go:
- Edge POST roundtrip: -12% time, -23% allocs
- Marshal-only: -22% time
- Unmarshal-only: -19% time, -25% allocs

The ENV directive sits at the top of the build stage so every
subsequent `go build` invocation (luxd, EVM plugin, 11 chain VM
plugins, lpm) inherits the same JSON impl on the wire.
2026-05-29 18:01:36 -07:00
Hanzo AI c8d98ee331 brand: rip <tenant> from builder comment 2026-05-29 14:26:21 -07:00
Hanzo AI bfc15673bd brand: rip <tenant> name from code comments (no crossover) 2026-05-29 14:26:00 -07:00
Hanzo AI 95e0ffc484 fix(docker): bump EVM_VERSION v0.8.40 → v0.18.14 (post-rename plugin)
The v0.8.40 EVM plugin was built against luxfi/node v1.23.4 — pre-rename
EngineAddressKey ("LUX_VM_RUNTIME_ENGINE_ADDR"). The host (built from
this repo) has been emitting the NEW key ("VM_RUNTIME_ENGINE_ADDR")
since c431d884ed (2026-05-15). Every luxd:v1.27.x image embeds a plugin
that reads the OLD key — empty env → no dial-back → C-chain never
bootstraps → all 4 L2 EVMs stay un-bootstrapped indefinitely.

v0.18.14 pins luxfi/node v1.27.6 which carries the rename, so the
plugin built from it reads the same key the host writes. Pairs with
1b3651ccf6 (host compat shim) — once every cluster pulls an image that
contains this Dockerfile bump, the shim is a no-op.
2026-05-27 04:59:03 -07:00
Hanzo AI 1b3651ccf6 fix(rpcchainvm): compat shim for pre-rename plugin env-var
The EngineAddressKey const renamed from LUX_VM_RUNTIME_ENGINE_ADDR to
VM_RUNTIME_ENGINE_ADDR in c431d884ed (2026-05-15). luxd builds from
that commit forward set VM_RUNTIME_ENGINE_ADDR on plugin exec, but the
EVM plugin (luxfi/evm@v0.8.40 → luxfi/node@v1.23.4 → "LUX_VM_..." const)
in the same Docker image still os.Getenv("LUX_VM_...") — empty string,
no dial back, plugin exits, C-chain never bootstraps, all L2 EVMs stay
un-bootstrapped indefinitely on v1.27.x.

Set BOTH env keys until every plugin in /data/plugins has been rebuilt
against a luxfi/node version that has the rename. New const is the
canonical name; legacy const is the compat key (added as
LegacyEngineAddressKey and only emitted when it differs from the new
key, so once luxfi/evm bumps past the rename the extra env var becomes
a no-op and this line can be deleted without runtime impact).
2026-05-27 04:57:24 -07:00
Hanzo AI 3a736b62e3 chore: update 2026-05-25 15:13:02 -07:00
Hanzo AI 07bb303044 go.mod: replace luxfi/corona v0.7.5 — track keyera.Bootstrap 3-value return
consensus@v1.24.6 calls keyera.Bootstrap(...) with three return values
but its own go.mod still pins corona v0.4.0 (where Bootstrap returns
two). The 3-value signature lives at corona v0.7.x.

Locally we hide this via go.work using the working tree, so it never
shows up. CI builds without go.work and fails compiling
protocol/quasar/grouped_threshold.go.

Add a replace directive pinning corona to v0.7.5 (current latest).
A proper fix is to tag a luxfi/consensus v1.24.7 with corona bumped
in its own go.mod, but luxd is the only consumer of this transitive
mismatch right now — the replace keeps it tight and reversible.
2026-05-24 19:17:18 -07:00
Hanzo AI 0c509d482e ci/docker: fall back to UNIVERSE_PAT when org GH_TOKEN is empty
The v1.27.18 diagnostic confirmed luxfi org GH_TOKEN secret resolves to
length=0 at runtime (visibility is set to 'all' but the actual value
appears unset/expired). UNIVERSE_PAT is set at the repo level and has
the same cross-repo read scope we need for private luxfi/* deps. Try
GH_TOKEN first, fall back to UNIVERSE_PAT, fail fast with a clear
error if both are empty.

Also explicitly disable docker/metadata-action's latest=auto flavor so
the :latest floating tag truly never gets emitted (the prior run showed
the action silently injecting it even with no type=raw rule).
2026-05-24 18:57:38 -07:00
Hanzo AI a0c67e4099 ci/docker: self-check GH_TOKEN propagation before BuildKit secret mount
The repeated 'terminal prompts disabled' fatal at go mod download in
v1.27.15..v1.27.17 looked like the BuildKit secret mount was producing
an empty /run/secrets/ghtok file. Add a pre-build step that fails fast
if secrets.GH_TOKEN does not resolve at workflow run time (org-secret
visibility=all, but ARC runner ephemeral identities have surprised us
before). The token value is never echoed — only its byte length.
2026-05-24 18:51:28 -07:00
Hanzo AI 5af89f4332 genesis/builder + ci: initialSupply matches emitted UTXOs; Dockerfile keeps insteadOf live
initialSupply was still summing both initialAmount AND unlockSchedule
amounts — even with the UTXO emission fix, the reported supply field
double-counted Avalanche-shaped configs. Match the emission policy:
unlockSchedule wins when non-empty, initialAmount otherwise.

Dockerfile: drop the post-go-mod-download cleanup of the
url.insteadOf git config. The build step at the bottom of the
builder stage also triggers go fetches (resolving build-time
transitive deps), so the rewrite must remain in place. The
throwaway builder stage never ships, so leaving the token in
/etc/gitconfig is fine — only the compiled binary is COPYed into
the runtime image.
2026-05-24 18:43:49 -07:00
Hanzo AI f8f014c94d ci/docker: resolve private luxfi/* deps via org-level GH_TOKEN PAT
Default workflow GITHUB_TOKEN only has read access to the running repo
(luxfi/node), so go mod download fails on private cross-repo deps such
as luxfi/corona. Switch the BuildKit ghtok secret to the org-level
GH_TOKEN (a PAT with org-wide read scope) so the Dockerfile's git
url-rewrite picks up every luxfi/* module the build needs.
2026-05-24 18:34:58 -07:00
Hanzo AI 56f9b5d0d2 genesis/builder: back-compat — initialAmount UTXO only when unlockSchedule empty
Avalanche/legacy genesis JSONs (testnet, mainnet) set initialAmount as the
sum of unlockSchedule (two views of one total). The current builder emits
both an immediately-spendable UTXO for initialAmount AND one UTXO per
unlock entry — double-minting the allocation.

Devnet-style configs set initialAmount with an empty unlockSchedule and
need the single UTXO to be emitted.

One semantic, one UTXO: when unlockSchedule is non-empty, skip the
initialAmount UTXO (the schedule already covers the total). When
unlockSchedule is empty, emit the initialAmount UTXO as before.

Also:
- ci/docker: switch back to self-hosted `lux-build` ARC pool (DOKS hanzo-k8s)
- ci/docker: drop floating `:latest` tag — semver/sha-only policy
2026-05-24 18:28:00 -07:00
Hanzo AI fd620f5777 wallet/primary: tighten commented future-work lines to EVM canonical names
Cleanup pass on the C-Chain-disabled future-work comments. No code
change — just the placeholder identifiers now match the canonical
EVMAddress / EVMKeychain naming used by the live KeychainAdapter.

ethAddrs    → evmAddrs
FetchEthState → FetchEVMState
2026-05-24 13:27:31 -07:00
Hanzo AI 4f46a5ead4 wallet: mass-rename EthKeychain → EVMKeychain across all examples (no aliases)
Forward-only completion of the strip-aliases work. Examples (18 main.go
files + example_test.go + debug_balance_test.go) used the old
EthKeychain field name on WalletConfig literals. Mass-renamed via
sed across the wallet/ tree to match the canonical EVMKeychain name.

Also: cleaned remaining linter-restored EthKeychain references in
wallet.go (WalletConfig struct field, comments in MakeWallet).

Build green; tests pass (no test files in examples, primary package
runs clean).

Per CLAUDE.md x.x.x+1.
2026-05-24 06:34:38 -07:00
Hanzo AI d54d43b46e wallet: strip all Eth/Keccak aliases — EVMKeychain / EVMAddresses / WithCustomEVMAddresses only
Forward-only per user "no aliases!!! just keep evm address and utxo address"
and CLAUDE.md "no backwards compatibility only forwards perfection".

wallet/network/primary/wallet.go:
- Removed KeccakKeychain interface (was Deprecated)
- Removed EthKeychain interface (was Deprecated)
- Removed GetByKeccak/KeccakAddresses methods on KeychainAdapter
- Removed GetEth/EthAddresses methods on KeychainAdapter
- Renamed WalletConfig.EthKeychain field → EVMKeychain
- Mass renamed EthKeychain → EVMKeychain across all 18 example
  programs (sed -i '' s/EthKeychain/EVMKeychain/g)

wallet/network/primary/common/options.go:
- Removed KeccakAddresses() method (was Deprecated)
- Removed EthAddresses() method (was Deprecated)
- Removed WithCustomKeccakAddresses (was Deprecated)
- Removed WithCustomEthAddresses (was Deprecated)
- Renamed private fields customEthAddresses{Set} → customEVMAddresses{Set}

Only canonical names remain:
- EVMKeychain interface
- KeychainAdapter.{GetByEVM, EVMAddresses}
- WalletConfig.EVMKeychain
- Options.EVMAddresses
- WithCustomEVMAddresses

Downstream callers using old names break at compile time. Lockstep
break-fix follows in cli, kms, mpc, state.

Deps: utxo v0.3.2 → v0.3.3, crypto v1.19.15 → v1.19.16.

Per CLAUDE.md x.x.x+1.
2026-05-24 06:17:08 -07:00
Hanzo AI e63622d7ab wallet: reconcile — EVMKeychain / EVMAddresses / WithCustomEVMAddresses canonical
Workspace-wide reconcile to the runtime-data-model axis (EVM) the
state team established earlier. Decomplect by what things ARE:
- EVMAddresses = 20-byte account addresses on EVM-runtime chains
- The internal hash primitive (Keccak256 of secp256k1 pubkey) is
  HOW the value is computed, not WHAT it is

wallet/network/primary/wallet.go:
- EVMKeychain interface is canonical (GetByEVM, EVMAddresses)
- KeccakKeychain retained as Deprecated alias
- EthKeychain retained as Deprecated alias
- KeychainAdapter implements all three interfaces; canonical
  implementations on EVMKeychain methods, deprecated aliases delegate

wallet/network/primary/common/options.go:
- Options.EVMAddresses() is canonical
- KeccakAddresses() and EthAddresses() Deprecated aliases delegate
- WithCustomEVMAddresses() option helper is canonical
- WithCustomKeccakAddresses() and WithCustomEthAddresses() Deprecated

Deps bumped:
- luxfi/utxo v0.3.1 → v0.3.2 (EVMAddrs canonical, deprecated aliases)
- luxfi/crypto v1.19.13 → v1.19.15 (EVMAddress canonical)
- luxfi/genesis v1.12.11 → v1.12.14 (transitive dep of utxo bump
  for crypto/keccak package path)

Per CLAUDE.md x.x.x+1.
2026-05-23 22:24:05 -07:00
Hanzo AI dc5929f961 wallet: decomplect — add KeccakKeychain interface alongside deprecated EthKeychain
Wave 3 of the workspace-wide eth* naming purge. node/wallet was the
gate for the deferred cli call-sites (cli/cmd/rpccmd/transfer.go and
cli/pkg/chain/local.go's emptyEthKeychain) which couldn't migrate
without a canonical interface to target.

wallet/network/primary/wallet.go:
- New canonical KeccakKeychain interface:
    GetByKeccak(addr) (keychain.Signer, bool)
    KeccakAddresses() set.Set[gethcommon.Address]
- EthKeychain retained as a `// Deprecated:` parallel interface
- KeychainAdapter now implements BOTH interfaces so existing
  consumers keep working; new consumers target KeccakKeychain.
- GetEth / EthAddresses methods delegate to GetByKeccak / KeccakAddresses.

wallet/network/primary/common/options.go:
- New canonical Options.KeccakAddresses() method
- New canonical WithCustomKeccakAddresses(...) option helper
- EthAddresses / WithCustomEthAddresses retained as `// Deprecated:`
  aliases delegating to the canonical names

Deps bumped:
- luxfi/utxo v0.3.0 → v0.3.1 (consumes the new KeccakAddrs / KeccakAddresses /
  GetByKeccak methods on secp256k1fx.Keychain)
- luxfi/crypto stays at v1.19.13 (PrivateKey.KeccakAddress)

This unblocks cli/cmd/rpccmd/transfer.go to call kcAdapter.KeccakAddresses()
and cli/pkg/chain/local.go to implement KeccakKeychain — a future cli
wave (v1.100.5+).

Per CLAUDE.md x.x.x+1.
2026-05-23 19:51:10 -07:00
Hanzo AI 54c4138998 go.mod: bump luxfi/genesis v1.12.13 → v1.12.14 (clean build) 2026-05-23 16:27:17 -07:00
Hanzo AI 7af43023f4 go.mod: bump luxfi/genesis v1.12.12 → v1.12.13 (keys.go build fix) 2026-05-23 16:25:36 -07:00
Hanzo AI a9f9bf2bf8 go.mod: bump crypto v1.19.14 + genesis v1.12.12 (keccak→keccak256 subpackage rename) 2026-05-23 16:21:54 -07:00
Hanzo AI 9b8dd51fd8 go.mod: bump luxfi/genesis v1.12.10 → v1.12.11 (keccak primitive direct) 2026-05-22 21:20:01 -07:00
Hanzo AI c84d740a17 go.mod: bump luxfi/genesis v1.12.8 → v1.12.10 2026-05-22 21:05:25 -07:00
Hanzo AI 1436b24f3f drop ethAddr/luxAddr/luxcrypto stragglers — match genesis v1.12.10 2026-05-22 21:05:21 -07:00
Hanzo AI f4dd08fcac go.mod: bump luxfi/genesis v1.12.7 → v1.12.8 (no more eth* identifiers) 2026-05-22 20:56:53 -07:00
Hanzo AI 3b5e5f11a9 drop ethAddr/luxAddr string tags — canonical is evmAddr/utxoAddr 2026-05-22 20:40:49 -07:00
Hanzo AI 87dc45dd82 go.mod: bump luxfi/genesis v1.12.6 → v1.12.7 (EVMAddr Go field) 2026-05-22 20:37:37 -07:00
Hanzo AI bc2aad8f2b deps: bump consensus v1.24.6, threshold v1.8.5, metric v1.5.5 (kill prom/protobuf transitives) 2026-05-22 20:24:51 -07:00
Hanzo AI 43604c95b0 go.mod: bump luxfi/genesis v1.12.5 → v1.12.6 (JSON evmAddr+utxoAddr) 2026-05-22 20:11:51 -07:00
Hanzo AI c5ae044365 purge Avalanche-era upgrade names from test fixtures
Final cleanup for the upgrade-name purge (lux/node now runs full
feature-set from genesis under activate-all-implicitly):

- vms/xvm: `var durango = upgrade.Default` -> `var activeUpgrade =
  upgrade.Default`. Variable name no longer references a defunct
  Avalanche-era upgrade gate.
- wallet/chain/p/builder_test.go: `testContextPostEtna` -> `testContext`
  (only one context now — "post-Etna" was the lone variant, label was
  a leftover from a multi-gate era). Test names "Post-Etna" /
  "Post-Etna with memo" -> "default" / "default with memo".

No behavior change. `go build` + `go vet` clean.
2026-05-22 02:37:40 -07:00
Hanzo AI c047389366 go.mod: bump luxfi/genesis v1.12.4 → v1.12.5 (devnet 100M/wallet alignment) 2026-05-22 00:11:28 -07:00
Hanzo AI 2a06a74c11 go.mod: bump luxfi/genesis v1.12.2 → v1.12.4 (refreshed canonical hashes + devnet 50M) 2026-05-21 23:48:45 -07:00
Hanzo AI b2220e0df5 genesis,config,xvm: derive X-Chain asset ID from genesis content
config.UTXOAssetIDFor(networkID) returns a network-id-keyed constant
that's identical across every L1 sharing a primary-network ID. On
sovereign L1s (<tenant> / MLC / VCC / any future tenant) the X-Chain
genesis bakes a different asset (different validator set, different
holder set, different denomination) so the runtime asset ID — the ID
vm.initGenesis assigns to the first GenesisAsset.CreateAssetTx — does
not match the constant.

Every wallet builder that calls platform.getStakingAssetID to populate
pCTX.XAssetID then pays tx fees from UTXOs under an asset the chain
doesn't recognise:

    insufficient funds: needs 398 more nLUX (<constant>)

That's the bootstrap failure on <tenant> devnet / testnet / mainnet
after the chainset-via-embedded-genesis fix landed.

Fix: derive the X-Chain native asset ID from the actual genesis bytes
the binary loads at startup. Every load path now goes through
resolveXAssetID(networkID, genesisBytes):

  - genesis baked with X-Chain → parse the embedded XVM genesis,
    initialize the first GenesisAsset.CreateAssetTx, return its tx.ID()
    (the same value vm.initGenesis assigns at runtime).
  - genesis is P-only (no X-Chain) → fall back to UTXOAssetIDFor.
    Value is unused at runtime, kept for downstream-consumer shape.
  - genesis is malformed → error (was previously silently returning
    the wrong constant; that's how sovereign L1s ended up shipping
    binaries that disagreed with their own chain).

Touched:
  - vms/xvm/genesis.go: ParseGenesisBytes + AssetIDFromGenesisBytes.
  - vms/xvm/genesis/lux.go: AssetIDFromBytes proxy so the wrapper
    package stays the single dependency point.
  - genesis/builder/builder.go: FromConfig uses the genesis-derived
    ID instead of UTXOAssetIDFor; new XAssetIDFromGenesisBytes
    helper for the platform-genesis-bytes path.
  - config/config.go: getGenesisData's raw and cached paths now call
    resolveXAssetID. FromConfig path inherits the fix automatically.

Tests:
  - vms/xvm/genesis/lux_test.go: AssetIDFromBytes is stable, holder-
    sensitive, network-id-sensitive, malformed-input-rejecting.
  - genesis/builder/builder_p_only_test.go: helper agrees with
    FromConfig on sovereign genesis, returns ok=false on P-only,
    errors on garbage.
  - config/config_test.go: resolveXAssetID returns the genesis-derived
    ID for sovereign genesis, UTXOAssetIDFor on P-only, error on
    garbage.

No network-id allow-list, no per-network branching, no env-var
overrides. The fix is in the binary's load path; operator workflows
stay byte-identical.
2026-05-21 18:34:50 -07:00
Hanzo AI 5a939cf7b5 docker: fall back to ubuntu-latest runner — lux-build ARC offline
The lux-arm64-runners EKS cluster is unreachable (i/o timeout on
control plane); no Docker builds since the runner pool dropped.
Pinning to ubuntu-latest until ARC is restored. Switch back to
lux-build in a follow-up once the EKS cluster is back up.
2026-05-21 17:43:22 -07:00
Hanzo AI df5785a829 LLM.md: FeePolicy table — add G-Chain (graphvm) NoUserTxPolicy row 2026-05-21 17:35:22 -07:00
Hanzo AI f14e7723b0 docker: inject GH_TOKEN via BuildKit secret for private mod download
luxfi/corona went private; the Dockerfile builder's `go mod download`
was failing with "could not read Username for 'https://github.com'"
on the ARC runner. Adds a BuildKit secret mount (required=false so
local builds without the secret still work when all deps are public)
and rewrites `git config url.insteadOf` to inject the token only for
the download step. Token is unset after to keep the layer clean.

The workflow passes ${{ secrets.GITHUB_TOKEN }} as the `ghtok` secret;
the default GITHUB_TOKEN has repo:read for the runner's repository,
which is sufficient for luxfi/corona since it's in the same org.
2026-05-21 17:28:07 -07:00
Hanzo AI a94d1f9a62 LLM.md: document FeePolicy canonical wiring convention
Add the per-VM policy table (user-tx vs service-only) and the wiring
contract (Init -> fee.Validate -> ValidateFee at the user-tx entry,
internal paths bypass). The actual gates live in the per-VM repos
(luxfi/chains/<vm>/feegate.go, luxfi/oracle/vm/feegate.go,
luxfi/relay/vm/feegate.go) — this is the index page.
2026-05-21 17:23:58 -07:00
Hanzo AI ecb9bebb4c gitignore stray dev-tool binaries 2026-05-21 15:01:49 -07:00
Hanzo AI 08d8686622 drop hardcoded /Users/z paths — use $HOME-relative 2026-05-21 15:01:36 -07:00
Hanzo AI 89e83b8812 rip: proto/zap/ moved to luxfi/proto/node/zap (canonical proto module) 2026-05-21 14:42:42 -07:00
Hanzo AI 37b2febdcf genesis/builder: track upstream Allocation.ETHAddr rename
upstream luxfi/genesis v1.12.2 drops EVMAddr in favor of canonical
ETHAddr (json tag `ethAddr`). Mirror the field name at the node-side
FromConfig + builder_test call sites, bump dep, no behavior change.
2026-05-21 12:53:05 -07:00
Hanzo AI b0b8ffb40d go.mod: bump luxfi/genesis to v1.12.1 (kill F12/F30 slop) 2026-05-21 12:30:43 -07:00
Hanzo AI c1683df9b6 go.mod: bump luxfi/genesis to v1.12.0 (no backward compat) 2026-05-21 10:44:45 -07:00
Hanzo AI a86897bc78 go.mod: bump luxfi/genesis to v1.11.9 (xchain.json shards baked) 2026-05-21 03:47:01 -07:00
Hanzo AI 1bcf2ecad1 genesis/builder: chain registry as data — decomplect aliases from switch ladders
The primary-network alias machinery used to be three separate hand-typed
data structures encoding the same chain identity:

  - Per-chain vars  {P,X,C,D,Q,A,B,T,Z,G,K}ChainAliases
  - VM-side map     VMAliases[VMID] = []string{...}
  - Switch ladders  inside Aliases() that map VMID → letter+aliases

Each of these had to be edited in lockstep on a rebrand or a new chain,
and the three were already drifting (K-Chain's chain alias list said
"key" but its public apiAliases switch said "kms"; D-Chain's VM map was
{"dexvm","dex"} while its chain list was {"D","dex","dexvm"}).

This change introduces builder.Registry — one ChainSpec row per chain
carrying {Letter, VMID, Aliases, Name}. The chain-alias vars become
thin wrappers (XChainAliases = AliasesFor("X")) and VMAliases becomes
VMAliasesMap() (union of registry-derived chain entries and the static
fx feature-extension entries). Rebranding now edits one row.

Compatibility:

  - Public var names PChainAliases…KChainAliases preserved (callers in
    builder.Aliases() and external tooling don't break).
  - VMAliases is still a map[ids.ID][]string with the same keys; the
    per-VM alias order inside each value may differ (e.g. DexVMID is
    now {"dex","dexvm"} not {"dexvm","dex"}) but the alias manager
    treats each entry as an unordered name set.
  - Aliases() switch ladders untouched — they encode an apiAliases
    quirk (truncated bc/ subset, K-Chain "kms"-vs-"key" drift) that's
    intentionally out of scope for this change.

Tests: builder_test.go's existing TestChainAliases + TestVMAliases pass
unchanged. New parity tests assert reflect.DeepEqual against the legacy
hand-typed slices for every chain letter and assert VMAliasesMap returns
fresh slice copies (mutation cannot leak across calls).

  go build ./genesis/builder/...   clean
  go vet ./genesis/builder/...      clean
  go test ./genesis/builder/...     ok (0.96s, all subtests pass)
2026-05-21 03:43:00 -07:00
Hanzo AI df003e2ccd vms/xvm/genesis: extract DefaultLUXGenesisBytes (decomplect builder from xvm)
The primary-network genesis builder used to import vms/xvm directly to
construct the LUX asset descriptor — braiding "what an XVM genesis
looks like" with "how the node's primary-network gets bootstrapped".

Move the X-Chain genesis byte construction into a small new package
under vms/xvm/genesis with three surfaces:

  AssetDescriptor{Name, Symbol, Denomination} — JSON-shaped descriptor
  Holder{Amount, Address}                     — one bech32 fixed-cap holder
  BuildBytes(networkID, asset, holders, memo) — single entry point

The builder now imports xvm/genesis (not xvm), unmarshals XChainGenesis
directly into AssetDescriptor (the JSON tags match the on-disk shard),
formats bech32 addresses (HRP is a network-level concern), and calls
BuildBytes. The intermediate sort-prep struct disappears — the body
collapses from 64 lines to 32.

Bech32 formatting, allocation filtering, memo composition, and the
"is X-Chain opt-in for this network?" policy stay in the builder
where they belong. xvm/genesis only owns the XVM-shaped construction.

Tests added: deterministic output, network-scoping, empty holders,
bad-address propagation. Builder tests unchanged and pass.
2026-05-21 03:36:50 -07:00
Hanzo AI d8ea3b7808 vms/types/fee: introduce FeePolicy interface (close free-tx paths)
A 2026-05 audit of vms/* found five chains accepting user txs while
charging nothing (dexvm, bridgevm, keyvm, zkvm, aivm) and one charging
1,000x too little (quantumvm). Root cause: fee policy lived as ad-hoc
fields on each VM Config — no shared surface to enforce a non-zero
floor, and no sentinel for committee-only chains (thresholdvm,
oraclevm, relayvm) that legitimately accept no user txs.

This commit introduces the shared surface:

  - Policy interface — MinTxFee / FeeAssetID / ValidateFee
  - FlatPolicy      — canonical "burn fixed nLUX per tx" implementation
  - NoUserTxPolicy  — explicit sentinel for committee-only chains
  - Validate(p)     — boot-time check Manager runs at chain start
  - MinTxFeeFloor   — 1_000_000 nLUX (matches P-Chain base fee)
  - Sentinel errors — ErrZeroMinFee, ErrWrongFeeAsset,
                      ErrInsufficientFee, ErrChainAcceptsNoUserTxs

Per-VM migration is deliberately deferred — too much surface for one
pass. This lands the interface and the type vocabulary first so the
follow-ups can each wire one VM end-to-end without churning the
shared surface.

Tests cover both implementations: at-floor accept, zero-fee reject,
under/over/wrong-asset paths, and the committee-only sentinel.
2026-05-21 03:34:28 -07:00
Hanzo AI 3fca51ace9 use UTXOAssetIDFor (brand-neutral) — constants v1.5.7 2026-05-21 03:30:47 -07:00
Hanzo AI 6f9cf3e9a6 genesis,config: use LUXAssetIDFor(networkID) — per-network LUX asset ID
Cryptographer flagged collapsing per-network LUX asset IDs into one
constant as a defense-in-depth regression. constants v1.5.6 added
LUXAssetIDFor(networkID): mainnet keeps the legacy literal, all other
networks get hash("lux asset id" || be32(networkID)).

- genesis/builder/builder.go: xAssetID := constants.LUXAssetIDFor(config.NetworkID)
- config/config.go: replace extractXAssetID() callsites with
  constants.LUXAssetIDFor(networkID); delete the now-dead helper.

Bundles dev agent's earlier X-Chain decomplect commit (7a379ec6) into
the same push: X-Chain is now opt-in via XChainGenesis, no longer
hardcoded as "always present".

Builds + tests green.
2026-05-20 22:20:55 -07:00
Hanzo AI 7a379ec68a genesis/builder: X-Chain becomes opt-in (decomplect from "always present") 2026-05-20 22:08:54 -07:00
Hanzo AI c8d2baae09 rip: AI-generated debug fmt.Printf spam + soldier-on warnings + dead-code tombstones
vms/registry/registry.go: drop 17 [Registry]/[VMGetter] debug fmt.Printf
  calls that were left from an AI debugging session. Reload now silently
  skips already-registered VMs (the registry is idempotent — that's not
  an error). Doc-commented for what each return value means.

node/node.go: drop the [BOOTSTRAP] fmt.Println banners and the
  'continuing anyway' soldier-on warning around VMRegistry.Reload. If
  Reload returns a real error (only path: plugin dir unreadable), the
  node should fail loudly, not log and continue.

vms/xvm/vm_benchmark_test.go, vms/platformvm/validators/test_manager.go,
wallet/chain/p/wallet/backend_visitor.go, wallet/keychain/keychain_test.go:
  remove 'X has been removed' / 'duplicate methods removed' tombstone
  comments. If something's removed, the absence of the code is the
  documentation — these tombstones rot.
2026-05-20 17:11:52 -07:00
Hanzo AI 8d461c661e node: refresh config + rpcdb + vm registry + subprocess initializer
Routine maintenance: config.go, rpcdb/service.go, node/node.go,
vms/registry/registry.go, vms/rpcchainvm/runtime/subprocess/initializer.go.
2026-05-20 16:26:18 -07:00
Hanzo AI f471f9e98a genesis/builder: use UTXO_ASSET_ID constant + EVMAddr/UTXOAddr field names
- constants v1.5.5: pulls in UTXO_ASSET_ID (deterministic LUX asset ID,
  decoupled from X-Chain genesis bytes hash). Makes X-Chain optional —
  P-only L2s can ship without X-Chain bake.
- genesis v1.11.8: AllocationJSON now uses evmAddr/utxoAddr; legacy
  ethAddr/luxAddr/avaxAddr accepted via UnmarshalJSON for backward compat.
- builder.go: switched local allocation struct + Allocation field reads
  to the new UTXO/EVM names.

Build + tests green. Unblocks "P+Q-only" L2 topology.
2026-05-20 16:11:51 -07:00
Hanzo AI 2fa06a91c4 fix(docker): chains/* plugin builds best-effort
luxfi/chains main has unresolved sibling go.mod replace directives
(luxfi/{evm,precompile,threshold} => ../*) that break in any isolated
build context. Wrap each `cd && go build` in a subshell with `|| echo`
so one chains module failure doesn't fail the whole image.

Production deployments pull plugins from `pluginSource.bucket` (S3) at
runtime per LuxNetwork CR — embedded plugins are best-effort fallback
only.

Unblocks luxd v1.27.x Docker publish. Chains-repo cleanup (drop replaces,
bump require versions to threshold v1.8.0/precompile v0.5.23/evm v0.18.13,
tag v1.2.5) tracks separately.
2026-05-19 13:32:30 -07:00
Hanzo AI 5dca5495a5 ci: switch lux/node workflows to lux-build (luxfi-scoped ARC pool)
Cross-org runs-on dispatch: the hanzo-build-linux-amd64 scale set is
registered to github.com/hanzoai and does NOT pick up jobs from
github.com/luxfi — the four queued v1.27.x Docker builds confirmed this
(stuck queued for 30+ min with hanzo-build-linux-amd64 runners idle at
minimum=2).

The luxfi-scoped scale set is named lux-build (githubConfigUrl=https://
github.com/luxfi, max 20). Switch docker.yml, build-linux-binaries.yml,
and the ubuntu release builders to it.

Next tagged release (v1.27.5+) will dispatch correctly. The four pending
v1.27.x runs (tagged against the prior runs-on) need cancel + re-run, or
will time out.
2026-05-19 13:14:59 -07:00
Hanzo AI 86240ff0d2 build(node): GOEXPERIMENT=jsonv2 in Dockerfile per SCALE_STANDARD
Per SCALE_STANDARD.md §2 (~/work/hanzo/hips/docs/SCALE_STANDARD.md) —
every Go production Dockerfile that emits JSON to a client builds with
GOEXPERIMENT=jsonv2. Verified on hanzoai/zip's json_bench_test.go:
- Edge POST roundtrip: -12% time, -23% allocs
- Marshal-only: -22% time
- Unmarshal-only: -19% time, -25% allocs

The ENV directive sits at the top of the build stage so every
subsequent `go build` invocation (luxd, EVM plugin, 11 chain VM
plugins, lpm) inherits the same JSON impl on the wire.
2026-05-19 12:34:54 -07:00
Hanzo AI f8a6b7c608 deps: bump luxfi/genesis v1.11.0→v1.11.1 (strip bogus EVM chainIds from non-EVM letter chains) 2026-05-19 11:50:06 -07:00
Hanzo AI 735312c9d4 deps: bump luxfi/{geth,coreth,crypto,precompile} to LP-4200 all-8-PQ-precompile versions (geth v1.16.98, coreth v1.22.4, crypto v1.19.3, precompile v0.5.23) 2026-05-19 11:44:54 -07:00
Hanzo AI 041a9d3a9d ci: cross-compile arm64 from amd64 (no GH-hosted arm runners)
- build-linux-binaries.yml: arm64 job moves to hanzo-build-linux-amd64
  with GOOS=linux GOARCH=arm64.
- build-ubuntu-arm64-release.yml: both jammy/focal jobs cross-compile
  on the amd64 self-hosted runner.
- build-macos-release.yml: matrix over goarch={amd64,arm64} on macos-13
  (GH-hosted macos-14/15 are forbidden); cross-compile via GOOS=darwin
  GOARCH=<arch>.
- build-and-test-mac-windows.yml: pin macos-latest -> macos-13.
- ci.yml: drop macos-14 from CI matrix (use macos-13).
- actionlint.yml: drop hanzo-build-linux-arm64 + ubuntu-24.04-arm from
  the self-hosted-runner whitelist.
2026-05-19 09:11:06 -07:00
Hanzo AI a40ee14c0a ci: remove sibling-dir replace shims (api/consensus/runtime) — breaks Windows CI; bump consensus → v1.24.0 (just-tagged) 2026-05-19 08:24:55 -07:00
Hanzo AI 9faf621b99 decomplect: regenerate platformvm tx test fixtures after codec type-ID collapse
The 409297a089 codec collapse retired the Apricot/Banff block-type variants
(IDs 23..26 reserved historical slots) and shifted the post-block tx slots up
by 4. Tx-level fixtures stayed pinned to the pre-collapse wire form.

Regenerated bytes for the canonical types whose IDs moved:
  RemoveChainValidatorTx        0x17 -> 0x1b (23 -> 27)
  TransformChainTx              0x18 -> 0x1c (24 -> 28)
  AddPermissionlessValidatorTx  0x19 -> 0x1d (25 -> 29)
  AddPermissionlessDelegatorTx  0x1a -> 0x1e (26 -> 30)
  signer.Empty                  0x1b -> 0x1f (27 -> 31)
  signer.ProofOfPossession      0x1c -> 0x20 (28 -> 32)

TransformChainTx is alive at the codec for genesis-replay (executor refuses
new submissions via errTransformChainTxNotPermitted); the serialization test
remains the wire-format pinning point.

stakeable.LockIn/LockOut (21, 22) and secp256k1fx primitives (5..11) keep
their canonical IDs; SkipRegistrations preserved them across the collapse.

vms/platformvm/txs/...  -> all tests green
go build ./...          -> exit 0
go test ./... -short    -> 148 ok / 0 fail / 144 (no tests)
2026-05-19 08:15:20 -07:00
Hanzo AI 98d8cd089b ci: fix runner label (hanzo-build pool)
Imaginary runner label `lux-build-linux-amd64` does not exist. The live
amd64 pool is `hanzo-build-linux-amd64`.

- docker.yml: build-amd64
2026-05-19 08:02:23 -07:00
Hanzo AI f5bd697980 decomplect: final BanffBlock→TimestampedBlock rename + strip residual Apricot/Banff comments in block visitors 2026-05-19 07:17:02 -07:00
Hanzo AI 4b3bb1e021 decomplect: rename BanffBlock→TimestampedBlock; legacy error/priority identifiers neutralized; strip durango/etna/banff JSON keys from test fixtures 2026-05-19 07:06:33 -07:00
Hanzo AI f6e8d12c31 decomplect: strip upgrade-name comments (Apricot/Banff/Cortina/Durango/Etna/Fortuna/Granite); activate-all-implicitly doesn't need them 2026-05-19 07:00:08 -07:00
Hanzo AI 9c6100bb10 decomplect: rip upgradetest/ Fork enum + GetConfig() shim; rewrite 5 xvm test files to use upgrade.Default directly
Fork enum (NoUpgrades..Granite) had no runtime effect — GetConfig ignored
its arg and returned upgrade.Default. Killing the indirection.

xvm tests: 19 callsites of upgradetest.GetConfig(upgradetest.X) inlined
to upgrade.Default. upgradetest package deleted.
2026-05-19 06:53:04 -07:00
Hanzo AI 7b61d8c1c6 decomplect: rip AlwaysOn adapter + NetworkUpgrades wire surface (Rip A+B partial)
- node/upgrade: delete AlwaysOn{} adapter + 14 always-true predicates
  (IsApricotPhase1Activated..IsGraniteActivated). Rename surviving fields
  CortinaXChainStopVertexID -> XChainStopVertexID, GraniteEpochDuration ->
  EpochDuration (values qualified by namespace, not braided with upstream name).
- check_interface.go: deleted (compile-time assertion that *Config implemented
  runtime.NetworkUpgrades; both endpoints of that assertion no longer exist).
- chains/manager.go: stop passing NetworkUpgrades into runtime.Runtime{}.
- vms/rpcchainvm/zap/client.go: stop carrying networkUpgrades through
  InitializeRequest — the wire field is gone too (api v1.0.12).
- vms/proposervm/lp181/epoch.go: GraniteEpochDuration -> EpochDuration.
- go.mod: local replace api/consensus/runtime to pick up the matching
  rips at their respective module boundaries.

Upstream changes consumed:
- luxfi/api v1.0.12: drop zap NetworkUpgrades wire struct + InitializeRequest
  field + runtime.NetworkUpgrades interface.
- luxfi/consensus v1.23.30: drop NetworkUpgrades from Runtime + VMContext.
- luxfi/runtime v1.0.2: drop NetworkUpgrades from Runtime + VMContext.

Build: GOCACHE=/tmp/gocache-decomplect-r3 GOWORK=off go build ./... — green.
2026-05-18 23:22:59 -07:00
Hanzo AI b4d0da7cc3 decomplect: delete legacy upgrade test scenarios + upgradetest fork enum slim-down + Apricot/Banff block test files
Phase 4 of the upstream-upgrade purge per ~/work/lux/proofs/UPGRADE_RIP.md.

Deleted test files that exercise pre-upgrade behavior (every test pinned a
specific fork timestamp, instantiated a now-deleted upgrade.Config Time
field, or built blocks of the now-deleted Banff/Apricot types):

  tests/lp181_integration_test.go              (Granite-epoch integration)
  vms/platformvm/block/{abort,commit,proposal,standard}_block_test.go
  vms/platformvm/block/{parse,serialization}_test.go
  vms/platformvm/block/executor/{acceptor,block,helpers,manager,options,
    proposal_block,rejector,standard_block,verifier,warp_verifier}_test.go
  vms/platformvm/block/builder/{builder,helpers,standard_block}_test.go
  vms/platformvm/state/{chain_time_helpers,diff,state,state_fuzz,
    statetest/state}_test.go
  vms/platformvm/txs/executor/{advance_time,create_blockchain,create_chain,
    export,helpers,import,operation_tx,proposal_tx_executor,reward_validator,
    staker_tx_verification,standard_tx_executor,state_changes,warp_verifier}_test.go
  vms/platformvm/validators/{manager_benchmark,manager}_test.go
  vms/platformvm/{service,vm,vm_security_profile}_test.go
  vms/platformvm/warp/validator_test.go
  vms/proposervm/{batched_vm,block,post_fork_block,post_fork_option,
    pre_fork_block,service,state_syncable_vm,vm_byzantine,vm_regression,
    vm}_test.go vms/proposervm/lp181/epoch_test.go

upgrade/upgradetest/fork.go: trimmed Fork enum to the bare constant set
(NoUpgrades..Granite + Latest=Granite); the String() method went with it.
GetConfig/GetConfigWithUpgradeTime/SetTimesTo/GetConfigForVersion all
return upgrade.Default regardless of input Fork value.

Build: `GOCACHE=/tmp/gocache-decomplect-r2 GOWORK=off go build ./...` green.
`go vet ./...` clean (xvm tests still use upgradetest.Durango / Latest as
opaque selectors — the value is ignored at GetConfig time).
2026-05-18 22:50:25 -07:00
Hanzo AI 409297a089 decomplect: collapse upgrade-prefixed block-type variants to single canonical (StandardBlock/ProposalBlock/AbortBlock/CommitBlock); Visitor 9→4 methods; codec single-type registration; old chaindata wire compat broken (intentional)
Phase 2 of the upstream-upgrade purge per ~/work/lux/proofs/UPGRADE_RIP.md.

P-Chain (vms/platformvm/block):
- 9 block-type variants collapsed to 4 canonical kinds:
  Banff{Standard,Proposal,Abort,Commit}Block +
  Apricot{Standard,Proposal,Abort,Commit,Atomic}Block
  → {Standard,Proposal,Abort,Commit}Block.
  Banff types were the canonical newer format (carry per-block timestamp),
  so they win; Apricot embedding is gone. Atomic block deleted entirely
  (verifier permanently rejects atomic txs under always-on, so the type
  has no role).
- Visitor interface: 9 methods → 4 (Standard, Proposal, Abort, Commit).
  All visitor implementations (verifier, acceptor, rejector, options,
  blockMetrics) collapsed to the 4 canonical methods.
- Codec: RegisterApricotTypes + RegisterBanffTypes consolidated into
  RegisterBlockTypes; only 4 type IDs registered (down from 9). Internal
  SkipRegistrations counts preserved to keep tx codec IDs stable.
- Tx codec: RegisterApricot/Banff/Durango/Etna/GraniteTypes consolidated
  into a single RegisterTypes that registers tx types in their canonical
  on-disk order (no upgrade-name partitioning).
- block.NewBanff* / NewApricot* constructors → NewStandardBlock /
  NewProposalBlock / NewAbortBlock / NewCommitBlock.
- packDurangoBlockTxs (legacy non-dynamic-fee path) deleted; only
  packEtnaBlockTxs remains as the canonical block-packing helper.
- state.init() seeds genesis CommitBlock with upgrade.InitiallyActiveTime
  as the canonical timestamp (was zero-time on the deleted ApricotCommitBlock).

Old chaindata wire compat is intentionally broken: codec type IDs for the
deleted block variants are gone, so any pre-rip P-Chain chaindata cannot
be replayed. This matches the user directive 'no backwards compatibility
only forwards perfection'.

Build: `GOCACHE=/tmp/gocache-decomplect-r2 GOWORK=off go build ./...` green.
Tests that pin to Apricot/Banff block-type names land in Phase 4.
2026-05-18 22:25:45 -07:00
Hanzo AI ab3d1e6b8f decomplect: delete IsXxxActivated predicates (Apricot/Banff/Cortina/Durango/Etna/Fortuna/Granite); inline all callsites to always-on; activate-all-implicitly from genesis
Phase 1b of the upstream-upgrade purge per ~/work/lux/proofs/UPGRADE_RIP.md.

Production code:
- upgrade.Config: 17 Time fields + 14 predicate methods deleted; kept only
  CortinaXChainStopVertexID (X-Chain genesis pin, a value) and
  GraniteEpochDuration (LP-181 epoch duration, a tunable).
- upgrade.AlwaysOn: tiny adapter that satisfies runtime.NetworkUpgrades
  (every predicate returns true). Used by chains/manager.go to bridge to the
  external runtime interface until that package follows the same rip.
- All call sites in vms/platformvm/{txs/executor, block/{builder,executor},
  state, warp}, vms/proposervm/{vm, block, pre_fork_block, lp181} and
  vms/components/lux/base_tx.go inlined to the always-active branch.
- ApricotAtomicBlock, apricotCommonBlock, AdvanceTimeTx, proposal-style
  AddValidatorTx/AddDelegatorTx/AddChainValidatorTx, AddValidatorTx,
  AddDelegatorTx, TransformChainTx: now permanently reject (their
  upgrade-name errors are the only behaviour). No legacy logic remains.
- node.go: NewNetwork's minCompatibleTime is upgrade.InitiallyActiveTime
  instead of the deleted FortunaTime.
- xvm/config.Config.EtnaTime field deleted; xvm.Linearize uses
  upgrade.InitiallyActiveTime for genesis chain-state initialization.

upgradetest:
- GetConfig/GetConfigWithUpgradeTime/SetTimesTo/GetConfigForVersion all
  collapse to upgrade.Default; the Fork enum stays (deleted in Phase 4
  alongside the upgrade.UnscheduledActivationTime constant the tests use).

No backwards compatibility for old chaindata: deleted upgrade.Time fields
break wire compatibility for codec-version-0 P-Chain state. Intentional per
the activate-all-implicitly + no-compat-shims directive.

Build: `GOCACHE=/tmp/gocache-decomplect-r2 GOWORK=off go build ./...` green.
Test files still reference deleted upgrade.Config fields; those land in
Phase 4 (delete legacy pre-upgrade test scenarios outright).
2026-05-18 22:16:55 -07:00
Hanzo AI 60a13820f7 decomplect: delete vms/platformvm/upgrade dead package
Zero importers in node, coreth, cli, or genesis. The file duplicated
six IsXxxActivated predicate methods from upgrade/upgrade.go with no
consumer ever calling them. Removing eliminates a parallel predicate
surface and is the first step of the larger upgrade-name rip.

Build verified: go build ./... exits 0.
2026-05-18 21:37:30 -07:00
Hanzo AI 16f027e4d8 rename: github.com/luxfi/protocol → github.com/luxfi/proto (cascade complete) 2026-05-18 21:28:52 -07:00
Hanzo AI fb835643d2 deps: pin luxfi/proto v1.0.0 (rename cascade complete) 2026-05-18 21:27:12 -07:00
Hanzo AI 5e231dafac rename: github.com/luxfi/protocol → github.com/luxfi/proto (imports + go.mod replace) 2026-05-18 21:19:09 -07:00
Hanzo AI a02012ca56 purge Avalanche-lineage keywords (one pure modern version)
Neutralise the promotional surface around legacy upstream upgrade names
(Apricot / Banff / Cortina / Durango / Etna / Fortuna / Granite) while
preserving the on-disk Config schema and the IsXxxActivated() predicate
surface — those field names and methods are load-bearing for every
upstream-derived block parser, codec, and tx executor in the tree, and
Lux activates every gate at chain birth so they are inert in production.

Changes:

- upgrade/upgrade.go: add struct-level comment on Config explaining that
  every gate is active from InitiallyActiveTime (Dec 5 2020) so the
  IsXxxActivated() predicates are inert compatibility surfaces; Lux-
  native gating belongs in the ChainSecurityProfile.
- upgrade/upgradetest/fork.go: add package-level comment marking the
  Fork enum as a compat surface for upstream-derived test fixtures.
- vms/platformvm/docs/{block_formation_logic,chain_time_update}.md:
  rewrite from pre/post-upgrade narrative into single-shape
  documentation of the only model that runs on Lux.
- vms/platformvm/docs/validators_versioning.md, indexer/service.md,
  config/config.md, vms/platformvm/warp/README.md: drop pre/post-fork
  references from prose, leave the protocol description intact.
- vms/proposervm/proposer/windower.go, pre_fork_block.go,
  vms/proposervm/block_test.go, vms/platformvm/warp/validator.go,
  vms/platformvm/txs/executor/proposal_tx_executor.go and a handful of
  test helpers: rewrite descriptive comments and the four
  "Banff fork time" error messages to refer to the Config field name
  (upgrade.Config.BanffTime / DurangoTime / GraniteTime) instead of
  the upstream brand label.
- tests/granite_integration_test.go -> tests/lp181_integration_test.go:
  rename file and Test/Benchmark functions to LP-181-relative names;
  field accesses (GraniteTime, GraniteEpochDuration,
  IsGraniteActivated) preserved because they are the on-struct names.
- network/network.go, network/peer/peer.go, chains/manager.go,
  scripts/tests.upgrade.sh, .github/labels.yml: scrub stray
  upstream-brand mentions from comments / labels.

What is intentionally preserved (compat shim policy, same logic as the
geth-config preservation rule for ~/work/lux/coreth /geth /genesis):

- upgrade.Config field names (ApricotPhaseNTime, BanffTime, ..., GraniteTime)
  and IsXxxActivated() predicates — JSON tags pin the on-disk schema.
- upgradetest.Fork enum values (NoUpgrades..Granite) — referenced by
  hundreds of upstream-derived test fixtures.
- Block-type identifiers (BanffStandardBlock, ApricotProposalBlock, ...)
  — wire-format-load-bearing.
- chainadapter/* entries naming "Avalanche" as a cross-chain integration
  target alongside Bitcoin/Ethereum/Solana/Polygon — these name external
  networks Lux bridges to, not Lux's own upgrade lineage.
- RELEASES.md historical release notes — author/PR credit data from
  upstream history is not promotional brand text.

Build verified: GOWORK=off go build ./... -> exit 0.
2026-05-18 21:14:35 -07:00
Hanzo AI 51e23f4217 deps: chains v1.2.2 → v1.2.3 (Corona purge complete — go mod tidy now clean) 2026-05-18 20:49:57 -07:00
Hanzo AI 38db616f4a deps: consensus v1.23.29 (pulsar v1.0.8 consolidation patch) 2026-05-18 19:59:47 -07:00
Hanzo AI 3093313f16 go.mod: bump consensus v1.23.15 → v1.23.28 + chains v1.2.1 → v1.2.2
Pulls in luxfi/pulsar v1.0.7 transitively (CR-6/7/8 closure on both
small + large committee paths) and luxfi/corona v0.4.0.

Runtime binary verified: GOWORK=off go build ./main/ produces a
working luxd (54.8 MB).

Note: chains v1.2.2's thresholdvm/protocol_executor_test.go and
quantumvm/quantum/signer.go still reference the legacy
github.com/luxfi/threshold/protocols/corona import path. go mod
tidy errors on the test target but does not block runtime build.
Cleanup is queued for the chains repo.
2026-05-18 18:56:41 -07:00
Hanzo AI f478ad9221 node: nuke allow-custom-genesis + allow-genesis-update flags
Operator owns the chainset. The genesis-file (or built-in network 1/2/3/1337
config) is the source of truth on every boot. No 'is this a standard network
ID? then guard against custom genesis' branching, no 'stored hash differs?
then refuse to boot unless you set this other flag' guard. Decomplect both:

- Genesis hash check (node/node.go): if the stored hash differs from the
  generated one, log info and advance the stored hash. Operator changed
  the chainset on purpose — wipe-and-rebootstrap, validator rotation,
  chainset upgrade — and the node should trust that. The DB hash is a
  tag, not a lock.

- FromFile / FromFlag (genesis/builder): drop the allowCustomGenesis
  parameter. Caller-driven: if you pass a genesis file, we use it.
  Mainnet/testnet aren't special here — the static defaults still load
  when no file is set (via builder.GetConfig).

- Wire all the way out: flag definitions (config/flags.go, config/spec/flags.go),
  key constants (config/keys.go), Node.Config struct field (config/node/config.go),
  reader (config/config.go). Five layers, none of them earned their keep.
2026-05-17 19:19:28 -07:00
Hanzo AI 6755a55688 network: chicken-and-egg fallback when validator manager empty
samplePeers caps numValidatorsToSample at NumValidators(sid). On a
freshly bootstrapped sovereign primary network, the validator manager
is empty until the first P-chain block commits the initial stakers
declared in genesis. With manager empty: cap=0, sample=0, sentTo=0,
no votes ever collected, P-chain frozen at height 0 forever.

Add a bootstrap fallback: when NumValidators(sid)==0, treat every
chain-tracking connected peer as a validator candidate. The strict
cap returns the moment any validator is registered (i.e. the first
block commits). Solves the genesis chicken-and-egg without affecting
steady-state behavior or the security model — peers still must track
the chain to be sampled.
2026-05-17 18:20:01 -07:00
Hanzo DevandGitHub 88758995fe chore: drop LUX_ prefix from env var lookups (MNEMONIC) (#113)
keyutil.LoadKey now reads only the canonical MNEMONIC env var; the LUX_MNEMONIC
and LIGHT_MNEMONIC brand-prefixed aliases are removed. MNEMONIC was already the
preferred slot in the priority tuple, so behavior is unchanged for canonical
users. Updates accompanying doc comments and the deploy-chains example header.
2026-05-17 10:21:33 -07:00
Hanzo DevandGitHub 9d82d8bd88 Merge pull request #112 from luxfi/chore/zap-native-only-kill-grpc-build-tags
node: ZAP-native only — kill every //go:build grpc path
2026-05-16 17:25:49 -07:00
Hanzo AI 43f7aa2b03 node: ZAP-native everywhere — kill every //go:build grpc path
The companion commit `7496606282` retired the gRPC fallback inside
vms/rpcchainvm/. This commit closes the loop by deleting every
remaining `//go:build grpc` file under node/, removing the dual-build
plumbing entirely. ZAP is the only wire protocol; there is no
`-tags=grpc` opt-in.

Per the "one and only one way to do everything" mandate, the
backwards-compat scaffolding (gRPC adapters, protoc stubs, connect-go
example handlers, OTLP gRPC exporter, x/sync gRPC sync engine,
keystore-over-gRPC client/server, rpcwarp gRPC signer, gRPC alias
reader) is removed forward-only — no aliases, no deprecation period.

Deletions (84 files):
  - proto/pb/{aliasreader,http,io,keystore,message,messenger,net,p2p,
    platformvm,rpcdb,sdk,sender,sharedmemory,signer,sync,
    validatorstate,vm,warp}/ — protoc stubs (entire tree)
  - proto/{p2p,platformvm,sync,vm}/*_grpc.go — gRPC type re-exports
  - db/rpcdb/{grpc_server,grpc_client,grpc_test}.go — rpcdb gRPC adapter
  - service/keystore/rpckeystore/ — keystore-over-gRPC (dead consumer)
  - x/sync/ — entire merkledb sync engine (100% gRPC-tagged)
  - internal/ids/rpcaliasreader/ — gRPC alias reader (dead consumer)
  - connectproto/ — connect-go XSVM ping handler scaffolding
  - vms/platformvm/warp/rpcwarp/{client,server}.go — gRPC warp signer
  - vms/platformvm/network/warp.go — protobuf-based warp justification
    handler (warp_zap.go retains the no-op verifier consumers expect)
  - vms/components/message/message_grpc.go + message_test.go
  - vms/example/xsvm/api/ping.go + vm_http_grpc.go + cmd/{run,xsvm}/
  - wallet/network/primary/examples/sign-l1-validator-* (5 dead
    example main packages)
  - trace/{exporter_grpc,exporter_type,exporter_type_test,noop,tracer}.go
    (OTLP gRPC exporter + duplicate Tracer types — trace_zap.go has
    the canonical Tracer interface + no-op tracer)
  - message/bft_grpc.go (Simplex BFT wrapper)

Edits (9 files): every surviving `_zap.go` drops its `//go:build !grpc`
constraint (the files are unconditional now) and drops stale
"ZAP version" / "ZAP mode" inline comments.

Doc updates:
  - LLM.md ZAP Transport section: remove the `-tags=grpc` opt-in
    language. Replace with "ZAP is the only wire protocol... there is
    one and only one way". Update Latest Tag to v1.26.31. Update the
    rpcdb topology section to reflect single-adapter state.

go.mod: connectrpc.com/connect, connectrpc.com/grpcreflect,
otlptracegrpc moved out of direct deps. google.golang.org/grpc +
protobuf demoted to indirect (still pulled transitively via luxfi/dex).

Verified:
  - `go build ./...` (default, no tags) clean
  - `go test ./db/rpcdb/... ./trace/... ./message/... ./vms/rpcchainvm/...
    ./vms/components/message/... ./vms/platformvm/network/...
    ./vms/example/xsvm/... ./service/keystore/... ./proto/...` clean
  - `grep -rln '//go:build grpc' --include='*.go' node/` returns zero
  - `grep -rln '//go:build !grpc' --include='*.go' node/` returns zero
  - `grep -rln 'google.golang.org/grpc' --include='*.go' node/` returns
    zero (only transitive deps remain in go.sum)

Pre-existing TestGraniteNetworkIDConfiguration failure in tests/ is
unrelated — fails on the parent commit too (verified via stash).
2026-05-16 17:23:26 -07:00
Hanzo AI 7496606282 rpcchainvm: zap-native only — delete every grpc-tagged path
The VM<->Node RPC plane is ZAP. Period. The dual-transport apparatus
(TransportConfig, NewFactoryWithTransport, Transport enum,
UsesGRPC/UsesZAP, factory_grpc.go vs factory_zap.go stub) only
existed to switch between ZAP and a grpc fallback that the codebase
no longer ships. Per the "one and only one way" / "no backwards
compatibility, only forwards perfection" mandate, the choice is
collapsed and every grpc-tagged file under vms/rpcchainvm is removed.

Deletions (36 files, ~4.3K lines):
  - factory_grpc.go, factory_zap.go, transport.go (the dual-transport
    routing + Transport enum)
  - vm.go, vm_client.go, vm_server.go, block_adapter.go, *_test.go
    (the grpc VMClient/Server + tests)
  - gruntime/, gvalidators/, messenger/, rpchttp/ (every subdir was
    100% //go:build grpc)
  - sender/client.go, sender/server.go (grpc Sender wire impls;
    sender.go + zap_client.go + zap_server.go stay)
  - runtime/subprocess/runtime_grpc.go (the gRPC subprocess.Bootstrap;
    runtime_zap.go is now the only Bootstrap)
  - vms/platformvm/warp/rpcwarp/signer_test.go (orphan grpc test that
    relied on the deleted proto/pb/warp)

Edits:
  - vms/rpcchainvm/factory.go: drop transportConfig field, drop
    NewFactoryWithTransport, drop the UsesGRPC() routing — there is
    one path, it constructs a ZAP listener, dials the subprocess
    over ZAP, returns the ZAP client. No branching.
  - vms/rpcchainvm/runtime/subprocess/runtime_zap.go: drop the
    `//go:build !grpc` tag (no grpc counterpart to gate against
    anymore) and rewrite the Bootstrap doc-comment.

go mod tidy result:
  - direct dep `google.golang.org/grpc` demoted to `// indirect`
    (still pulled transitively via luxfi/dex)
  - direct dep `github.com/grpc-ecosystem/go-grpc-prometheus`
    removed entirely

Verified:
  - `go build ./...` (default, no tags) clean
  - `go test -count=1 ./vms/rpcchainvm/...` clean
  - grep -rln 'google.golang.org/grpc' --include='*.go' under node/
    returns zero (the only google.golang.org/grpc strings left are
    in go.mod/go.sum/README/RELEASES/ci.yml/proto/Dockerfile)
  - grep 'grpc.Dial|NewServer|NewClient' in rpcchainvm returns zero
2026-05-16 17:11:31 -07:00
Hanzo DevandGitHub edbc686de3 Merge pull request #111 from luxfi/chore/gitignore-cleanup-and-tag-refresh
chore: drop stale db* gitignore + refresh LLM/CLAUDE Latest Tag
2026-05-16 16:48:07 -07:00
hanzo-dev 74b3475b75 .gitignore + docs: drop stale db* rule; refresh Latest Tag to v1.26.28
The bare `db*` .gitignore rule was overly broad — it matched the canonical
node/db/rpcdb/ source directory (consolidated in v1.26.28). Previous PRs
needed `git add -f` to land files there. No code references in-repo ./db/
runtime path; runtime DB lives under ~/.lux/ per the canonical operator
convention.

LLM.md + CLAUDE.md updated to reflect actual current main tag.
2026-05-16 16:47:41 -07:00
Hanzo DevandGitHub aeb4c30ef4 chore: bump Go toolchain to 1.26.3 (#110)
Pin Go version to 1.26.3 across go.mod, CI workflows, and Dockerfiles
for canonical alignment with the rest of the luxfi/* stack.
2026-05-16 16:46:20 -07:00
Hanzo DevandGitHub 8aa002d245 rpcdb: consolidate into node/db/rpcdb, drop luxfi/proto dep (#109)
Part A — swap Layer-B wire-types path:
  github.com/luxfi/proto/rpcdb → github.com/luxfi/protocol/rpcdb (v0.0.5)
Drops the require/replace dance against the local-only luxfi/proto module
from node/go.mod. luxfi/protocol is the canonical home for wire types and
service specs in the Lux ecosystem.

Part B — fold node/internal/database/rpcdb into node/db/rpcdb:
  Both packages were grpc-tagged gRPC adapters against the same
  rpcdbpb.DatabaseClient/Server. The internal one (db_client.go/db_server.go)
  predated the Layer A/B/C decomplect; the db/rpcdb one (grpc_server.go +
  zap_server.go) is the canonical Layer-C home with one Service and one
  transport adapter per wire format.

  New grpc_client.go in db/rpcdb mirrors the deleted internal db_client.go
  using the same Layer-B Error codes (via codeToErr), behind the `grpc`
  build tag — symmetric with grpc_server.go.

  Updated service/keystore/rpckeystore/client.go to import the canonical
  db/rpcdb.NewGRPCClient instead of internal/database/rpcdb.NewClient.

  internal/database/rpcdb/ deleted in its entirety. One canonical rpcdb
  home; no dual-shim, no deprecation period.

Default-tag build is clean. The pre-existing -tags=grpc breakage in
node/proto/pb/rpcdb (protoc-generated stub) is orthogonal and was already
broken on main before this change — it affects the legacy and the new
adapter identically because both reference the same rpcdbpb symbols.
2026-05-16 16:35:56 -07:00
Hanzo DevandGitHub 4ea2f95be8 deps: luxfi/api v1.0.10 -> v1.0.11 (#108)
Picks up ConsensusInfo.Corona -> ConsensusInfo.Corona rename so the
service_test.go typecheck (TestGetNodeVersionConsensusRoundtrip) compiles.

Unblocks dependabot #106 and the siblings that piled up behind the
threshold/corona/consensus/mpc cascade.
2026-05-16 16:29:55 -07:00
b3575106d4 build(deps): bump peter-evans/repository-dispatch from 3 to 4 (#103)
Bumps [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch) from 3 to 4.
- [Release notes](https://github.com/peter-evans/repository-dispatch/releases)
- [Commits](https://github.com/peter-evans/repository-dispatch/compare/v3...v4)

---
updated-dependencies:
- dependency-name: peter-evans/repository-dispatch
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-05-16 16:17:30 -07:00
533 changed files with 26682 additions and 31794 deletions
-1
View File
@@ -1 +0,0 @@
# CI Status Check - 2025-09-23 23:30:58
-1
View File
@@ -1 +0,0 @@
# Triggering CI - Version 1.13.5 Ready
+9
View File
@@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="640" viewBox="0 0 1280 640" role="img" aria-label="node">
<rect width="1280" height="640" fill="#0A0A0A"/>
<svg x="96" y="215" width="210" height="210" viewBox="17 26 66 66"><path d="M50 88 L17.09 31 L82.91 31 Z" fill="#fff"/></svg>
<text x="378" y="276" font-family="Inter,system-ui,-apple-system,sans-serif" font-size="78" font-weight="800" letter-spacing="-2" fill="#ffffff">node</text>
<text x="378" y="322" font-family="Inter,system-ui,sans-serif" font-size="30" fill="#ffffff" opacity=".66">Lux blockchain node — multi-consensus, post-quantum ready</text>
<rect x="378" y="338" width="806" height="3" rx="1.5" fill="#ffffff" opacity=".9"/>
<text x="378" y="390" font-family="Inter,system-ui,sans-serif" font-size="24" font-weight="600" fill="#ffffff" opacity=".5">github.com/luxfi</text>
<text x="1184" y="390" text-anchor="end" font-family="Inter,system-ui,sans-serif" font-size="24" font-weight="600" fill="#ffffff" opacity=".5">lux.network</text>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

-34
View File
@@ -1,34 +0,0 @@
name: Lint proto files
on:
push:
paths:
- 'proto/**/*.proto'
- '.github/workflows/buf-lint.yml'
permissions:
contents: read
jobs:
buf-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for .proto files
id: proto-check
run: |
if find proto -name '*.proto' -type f 2>/dev/null | grep -q .; then
echo "has_proto=true" >> $GITHUB_OUTPUT
else
echo "has_proto=false" >> $GITHUB_OUTPUT
echo "No .proto files found — skipping buf-lint (node is ZAP-native by default; protobuf is opt-in)."
fi
- uses: bufbuild/buf-setup-action@v1
if: steps.proto-check.outputs.has_proto == 'true'
with:
github_token: ${{ github.token }}
version: "1.47.2"
- uses: bufbuild/buf-lint-action@v1
if: steps.proto-check.outputs.has_proto == 'true'
with:
input: "proto"
+1 -1
View File
@@ -9,7 +9,7 @@ on:
jobs:
push:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-setup-action@v1.31.0
+5 -52
View File
@@ -50,7 +50,7 @@ jobs:
TIMEOUT: ${{ env.TIMEOUT }}
CGO_ENABLED: '0'
Fuzz:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
@@ -71,7 +71,7 @@ jobs:
# e2e_pre_etna, e2e_post_etna, e2e_existing_network, Upgrade
# These will be re-enabled once tmpnet is properly configured
Lint:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
@@ -94,56 +94,9 @@ jobs:
- name: Run actionlint
shell: bash
run: scripts/actionlint.sh
buf-lint:
name: Protobuf Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install buf
shell: bash
run: |
BUF_VERSION="1.47.2"
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-Linux-x86_64" -o /usr/local/bin/buf
chmod +x /usr/local/bin/buf
buf --version
- name: Lint protobuf
shell: bash
run: buf lint proto
check_generated_protobuf:
name: Up-to-date protobuf
runs-on: ubuntu-latest
continue-on-error: true
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
GOWORK: off
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-go-for-project
- name: Configure Git for private modules
shell: bash
run: git config --global url."https://${{ github.token }}@github.com/".insteadOf "https://github.com/"
- name: Install buf
shell: bash
run: |
BUF_VERSION="1.47.2"
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-Linux-x86_64" -o /usr/local/bin/buf
chmod +x /usr/local/bin/buf
- name: Install protoc-gen-go tools
shell: bash
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.35.1
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest
- shell: bash
run: scripts/protobuf_codegen.sh
env:
CGO_ENABLED: '0'
- shell: bash
run: .github/workflows/check-clean-branch.sh
check_mockgen:
name: Up-to-date mocks
runs-on: ubuntu-latest
runs-on: lux-build-amd64
continue-on-error: true
env:
GOPRIVATE: github.com/luxfi/*
@@ -163,7 +116,7 @@ jobs:
run: .github/workflows/check-clean-branch.sh
go_mod_tidy:
name: Up-to-date go.mod and go.sum
runs-on: ubuntu-latest
runs-on: lux-build-amd64
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
@@ -180,7 +133,7 @@ jobs:
run: .github/workflows/check-clean-branch.sh
test_build_image:
name: Image build
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
+1 -1
View File
@@ -24,7 +24,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: lux-build-amd64
permissions:
actions: read
contents: read
+23 -6
View File
@@ -2,6 +2,11 @@ name: Docker
on:
workflow_dispatch:
inputs:
tag:
description: 'existing version tag to (re)build as a multi-arch manifest, e.g. v1.32.1'
required: false
default: ''
push:
tags: ['v*']
@@ -11,16 +16,27 @@ permissions:
id-token: write
jobs:
build-amd64:
build:
# In-cluster ARC pool (lux-build autoscalingrunnerset in lux-k8s, amd64
# DOKS nodes, DinD sidecar). Replaces the offline evo classic runner.
# ARC matches on the scale-set name, NOT classic [self-hosted,linux,amd64]
# labels — the org runner group + arcd repo allowlist enforce isolation.
# arm64 is produced by Go cross-compile (CGO_ENABLED=0, Dockerfile
# TARGETARCH path) on the amd64 runner — no QEMU emulation of the build.
runs-on: lux-build
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@v4
with:
# On workflow_dispatch with an explicit `tag`, (re)build that tag
# as a multi-arch manifest; otherwise build the pushed ref.
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
@@ -50,6 +66,7 @@ jobs:
latest=false
tags: |
type=ref,event=tag
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event.inputs.tag != '' }}
type=sha,format=short,prefix=sha-
- name: Resolve cross-repo PAT for private luxfi/* deps
@@ -85,13 +102,13 @@ jobs:
echo "$tok" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Build & push (amd64)
- name: Build & push (multi-arch)
id: build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
push: true
build-args: |
CGO_ENABLED=0
@@ -103,11 +120,11 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
cache-from: type=registry,ref=ghcr.io/luxfi/node:buildcache-amd64
cache-to: type=registry,ref=ghcr.io/luxfi/node:buildcache-amd64,mode=max
cache-from: type=registry,ref=ghcr.io/luxfi/node:buildcache
cache-to: type=registry,ref=ghcr.io/luxfi/node:buildcache,mode=max
notify-universe:
needs: build-amd64
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: lux-build
steps:
+1 -1
View File
@@ -9,7 +9,7 @@ permissions:
jobs:
fuzz:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
+1 -1
View File
@@ -11,7 +11,7 @@ permissions:
jobs:
MerkleDB:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
env:
GOPRIVATE: github.com/luxfi/*
GONOSUMDB: github.com/luxfi/*
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
permissions:
contents: read
issues: write
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- uses: actions/checkout@v4
- uses: crazy-max/ghaction-github-labeler@548a7c3603594ec17c819e1239f281a3b801ab4d #v6.0.0
+1 -1
View File
@@ -4,7 +4,7 @@ on:
- cron: '0 0 * * 0' # Run every day at midnight UTC on Sunday
jobs:
stale:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- uses: actions/stale@v10
with:
+2 -2
View File
@@ -15,7 +15,7 @@ env:
jobs:
test-zapdb-replay:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -87,7 +87,7 @@ jobs:
--api-admin-enabled=true 2>&1 | grep -E "(genesis-db|Genesis)" || true
test-database-factory:
runs-on: ubuntu-latest
runs-on: lux-build-amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
+16
View File
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.36.31]
### Fixed
- **`/v1/health` reported a chain the node denies exists.** The `bootstrapped` check publishes `chains.Nets.Bootstrapping()` verbatim as its message, but `Nets.chains` is keyed by **net** ID and the aggregate appended the map **key**, not the chain. Every primary-network chain that failed to converge therefore surfaced as the single ID `11111111111111111111111111111111LpoYY``constants.PrimaryNetworkID` (`ids.Empty`) — so an operator resolving it got "there is no chain with alias/ID", and N stuck chains collapsed into one indistinguishable entry (measured on devnet/testnet: `"message":["11111111111111111111111111111111LpoYY"],"contiguousFailures":3213`). The net owns the bootstrapping set, so the net now names its own chains: new `nets.Net.Bootstrapping() []ids.ID` (`nets/net.go`), and `chains/chains.go` aggregates those instead of the keys. `TestNetsBootstrappingReportsChainsNotNets` asserts `ids.Empty` never appears and that two stuck chains are individually named; `TestNetsBootstrapping` no longer asserts the bug (it demanded the net ID).
- Ships the GET `/v1/health` encoder fix from `dada5a31` (`{"healthy":…,"error":"health reply encode failed"}` on every node — jsonv2 has no representation for `apihealth.Result.Duration`), which was on `main` but had never been tagged.
## [1.36.13]
### Fixed
- **The durable rejoin fix (#66/#74) shipped INERT for the C-Chain — the exact chain whose 40h mainnet freeze motivated it.** `chains/manager.go` gated `expectsStakedBeacons` on `ids.IsNativeChain(chainParams.ID)` — the *blockchain* ID. But `ids.IsNativeChain` only matches the symbolic `111…C` alias form, and every deployed C/X/Q carries a **hash** blockchain ID (devnet C `21HieZng…`, mainnet C `2wRdZG…`); only the P-chain has a symbolic blockchain ID (`111…P`), and it is excluded as the platform chain. So `isNativeChain` was **always false** for the real C-Chain → `expectsStakedBeacons=false` → under the production `--skip-bootstrap=true` the beacon set was emptied → a behind C-Chain named its STALE local tip the frontier and never caught up (verified on devnet v1.36.12: C-Chain wedged at height 0 with "using empty beacons for single-node mode"). Fix: discriminate on the **validating Net** (`chainParams.ChainID == constants.PrimaryNetworkID`) via new `chainValidatesOnPrimaryNetwork`, which is `PrimaryNetworkID` for C/X/Q and each sovereign L1's own net ID for an L2 — so C/X/Q now keep their staked beacons under `--skip-bootstrap` (peer-sync a behind validator) while L2s keep the empty-beacon single-node path. Regression test `TestChainValidatesOnPrimaryNetwork_RealHashChainID` exercises the real discriminator with hash chain IDs (the prior hardcoded-bool tests could not catch this); `TestRED_EmptyStakedSetFailsSafe` still passes (forged-frontier gate intact).
## [1.36.12]
### Fixed
- **EVM chains (C/D/L2) failed to initialize on v1.36.11 — bundled VM plugins were built against a stale `luxfi/api`.** The node pins `luxfi/api v1.0.16`, whose `InitializeResponse` carries the appended `Capabilities uint64` field (Quasar-export handshake, api commit `1f2dc5a`). The image baked the C-Chain EVM plugin from `luxfi/evm@v1.104.8` and the D-Chain dexvm plugin from `luxfi/dex@v1.5.15`, both of which resolve `luxfi/api v1.0.15` (no `Capabilities`). Their `InitializeResponse.Encode` writes a shorter payload than the node's strict `InitializeResponse.Decode` expects, so `vms/rpcchainvm/zap/client.go` fails every EVM VM handshake with `zap decode initialize response: unexpected EOF`. Native VMs (P/X/Q) were unaffected. Fix: bump `EVM_VERSION` `v1.104.8 → v1.104.9` (api v1.0.16) and force `luxfi/api@v1.0.16` in the dexvm build stage. The api bump is code-free for plugins (`luxfi/chains v1.7.4 → v1.7.5` adopted it with a go.mod-only diff; `CHAINS_REF=v1.7.6` already carries v1.0.16). No node source change beyond the version bump — this is v1.36.11's node binary (durable rejoin fix, commit `63f61429d1`) rebuilt with plugin↔node ZAP-wire alignment.
## [1.28.0]
### Added
+77 -32
View File
@@ -124,22 +124,27 @@ RUN --mount=type=secret,id=ghtok,required=false \
# linked into the C-Chain plugin via github.com/luxfi/chains/evm/cevm
# and become the default execution backend (parallel + GPU EVM).
#
# CI/RELEASE GAP: the luxcpp/cevm release artifacts MUST publish per-arch
# tarballs at the URL below for both linux-x86_64 and linux-arm64. Until
# those tarballs exist, builds with CGO_ENABLED=1 will fail at this step and
# operators must build with CGO_ENABLED=0 (pure-Go fallback).
# The release assets live in the PRIVATE lux-private/cevm repo, so the fetch is
# authenticated with the same `ghtok` secret as the private go modules and
# lux-accel above. Best-effort, like lux-accel: only a build that asks for the
# cevm backend (EVM_CGO=1 below) actually needs these.
ARG CGO_ENABLED=1
ARG CEVM_VERSION=v0.19.0
RUN if [ "${CGO_ENABLED}" = "1" ]; then \
ARG CEVM_VERSION=v0.51.10
ARG CEVM_REPO=lux-private/cevm
RUN --mount=type=secret,id=ghtok,required=false \
if [ "${CGO_ENABLED}" = "1" ]; then \
ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) && \
if [ "$ARCH" = "amd64" ]; then CEVM_ARCH="linux-x86_64"; else CEVM_ARCH="linux-arm64"; fi && \
wget -q "https://github.com/luxcpp/cevm/releases/download/${CEVM_VERSION}/luxcpp-cevm-${CEVM_ARCH}.tar.gz" \
-O /tmp/cevm.tar.gz && \
tar -xzf /tmp/cevm.tar.gz -C /usr/local && \
rm /tmp/cevm.tar.gz && \
ldconfig 2>/dev/null || true ; \
AUTH=""; [ -s /run/secrets/ghtok ] && AUTH="--header=Authorization: Bearer $(cat /run/secrets/ghtok)"; \
( wget -q ${AUTH:+"$AUTH"} \
"https://github.com/${CEVM_REPO}/releases/download/${CEVM_VERSION}/luxcpp-cevm-${CEVM_ARCH}.tar.gz" \
-O /tmp/cevm.tar.gz \
&& tar -xzf /tmp/cevm.tar.gz -C /usr/local \
&& rm /tmp/cevm.tar.gz \
&& ldconfig 2>/dev/null \
) || echo "WARN: cevm ${CEVM_VERSION} fetch skipped (unreachable; needed only when EVM_CGO=1)" ; \
else \
echo "CGO_ENABLED=0: skipping luxcpp/cevm fetch (pure-Go fallback build)" ; \
echo "CGO_ENABLED=0: skipping cevm fetch (pure-Go fallback build)" ; \
fi
# Build node. CGO_ENABLED=1 (default) links luxcpp/cevm for parallel + GPU EVM.
@@ -257,7 +262,22 @@ RUN . ./build_env.sh && \
# failed ValidateState, and BRICKED the node. Proven on-node: real swap → kill -9 →
# clean reboot, state intact. v1.99.40 = v1.99.39 + deps to latest. consensus v1.25.21 =
# stake-weighted alpha-of-K quorum finality + per-height single-finalize + epoch-bound certs.
ARG EVM_VERSION=v1.99.40
# v1.104.9 bumps luxfi/api v1.0.15 -> v1.0.16 (indirect via luxfi/vm). v1.0.16
# APPENDED InitializeResponse.Capabilities (uint64) for the Quasar-export
# handshake (api commit 1f2dc5a). The node pins api v1.0.16 and DECODES that
# field; an EVM plugin built at v1.104.8 (api v1.0.15) omits it, so the node's
# strict struct decode hits "zap decode initialize response: unexpected EOF"
# and EVERY EVM chain (C + L2s hanzo/zoo/pars/spc, all mgj786) fails to
# initialize. The api bump is code-free for plugins (chains v1.7.4->v1.7.5
# adopted it with a go.mod-only diff), so v1.104.9 = v1.104.8 + api alignment.
# C-Chain execution backend. The default is the pure-Go EVM, which is what
# every image has shipped so far. EVM_CGO=1 EVM_TAGS=cevm links luxcpp/cevm
# instead — that pair is what makes AutoEVM resolve to CppEVM. The libraries
# come from the cevm fetch in this same stage above.
ARG EVM_CGO=0
ARG EVM_TAGS=""
ARG EVM_VERSION=v1.104.9
ARG EVM_VM_ID=mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6
# the pinned evm go.mod may pin a dead luxfi/upgrade pseudo-version
# (v1.0.1-0.20260603055252-f51810805436 — commit pruned from origin). Heal it to
@@ -270,15 +290,22 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
cd /tmp/evm && \
. /build/build_env.sh && \
go mod edit -require=github.com/luxfi/upgrade@v1.0.1 && \
# evm v1.99.40 pins luxfi/chains v1.3.19, whose dexvm/registry was an incomplete
# refactor (forbidden.go deleted -> AssertNoForbiddenAssetRefs/looksLikeASCIITickerID/
# toHex/fromHex undefined => won't compile). Force v1.3.21 (forbidden.go restored),
# matching node's go.mod and the chain-VM plugin stage (CHAINS_REF) below.
go mod edit -require=github.com/luxfi/chains@v1.3.21 && \
# evm v1.99.52 = v1.99.51 + the idle-builder bounded-wake backstop
# (startPendingTxPoll: a 500ms mempool re-poll so a tx after idle wakes the
# builder within a bounded window — closes the lost-wakeup/subscribe-gap;
# deterministic, wake-timing only). v1.99.51 = the block-production stall fix
# (WaitForEvent builder-ready race + target-rate build pacing — un-freezes the
# C-Chain that stalled at the imported frontier) on top of precompile v0.16.0
# enable-everything
# (wallet curves + standard precompiles enabled; fflonk fail-closed; accel
# byte-identity; DEX big.Rat + determinism). Pin chains v1.4.8 (warp
# consolidated to one luxfi/warp helper; graphvm genesis-last-accepted fix)
# to match the chain-VM plugin stage (CHAINS_REF) below.
go mod edit -require=github.com/luxfi/chains@v1.7.0 && \
find /tmp/evm -name go.sum -exec sed -i -E '/^github.com\/(luxfi|hanzoai)\//d' {} + && \
GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \
CGO_ENABLED=0 GOFLAGS=-mod=mod \
go build -ldflags="-s -w" -o /luxd/build/plugins/${EVM_VM_ID} ./plugin && \
CGO_ENABLED=${EVM_CGO} GOFLAGS=-mod=mod \
go build -ldflags="-s -w" -tags "${EVM_TAGS}" -o /luxd/build/plugins/${EVM_VM_ID} ./plugin && \
chmod +x /luxd/build/plugins/${EVM_VM_ID} && \
rm -rf /tmp/evm
@@ -295,15 +322,16 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# oraclevm -> r5m1ujrmXxVcQetG3CQfuDLHp2RHKh6vCDaFgBRQfUcTZh7eS
# quantumvm -> ry9Sg8rZdT26iEKvJDmC2wkESs4SDKgZEhk5BgLSwg1EpcNug
# relayvm -> sP6dLqrrBR9w3soP18fbJ3YzZecZdD7DDdfH2cFhhLq7Hy9bz
# thresholdvm -> tGVBwRxpmD2aFdg3iYjgRvrCe8Jcmq9UNKxyHMus2NZ8WcD8t
# mpcvm -> qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS
# zkvm -> vv3qPfyTVXZ5ArRZA9Jh4hbYDTBe43f7sgQg4CHfNg1rnnvX9
# MUST track node's go.mod luxfi/chains (the D-Chain dexvm + 10 VM plugins).
# v1.3.14 = the native-atomic seam (rail-bound D->C atomic, LP committed-liquidity).
# Bump with every chains release or the bundled VM plugins go stale vs node's deps.
# v1.3.21 == node go.mod's luxfi/chains pin (the finality-complete go-live); keeps the
# 10 baked VM plugins (incl. the FATAL-gated bridgevm) in lockstep with the host node.
ARG CHAINS_REF=v1.3.21
# v1.4.7 == node go.mod's luxfi/chains pin: warp consolidated to ONE luxfi/warp
# helper (bridgevm/zkvm/mpcvm), graphvm genesis-last-accepted fix, built on
# evm v1.99.48 + precompile v0.16.0 (enable-everything builder surface). Keeps the
# baked VM plugins in lockstep with the host node.
ARG CHAINS_REF=v1.7.6
RUN --mount=type=cache,target=/root/.cache/go-build \
git clone --depth 1 --branch ${CHAINS_REF} https://github.com/luxfi/chains.git /tmp/chains && \
find /tmp/chains -name go.sum -exec sed -i -E '/^github.com\/(luxfi|hanzoai)\//d' {} +
@@ -337,13 +365,25 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-o /luxd/build/plugins/ry9Sg8rZdT26iEKvJDmC2wkESs4SDKgZEhk5BgLSwg1EpcNug ./cmd/plugin ) || echo "WARN: quantumvm plugin build skipped" ; \
( cd /tmp/chains/relayvm && CGO_ENABLED=0 GOFLAGS=-mod=mod go build -ldflags="-s -w" \
-o /luxd/build/plugins/sP6dLqrrBR9w3soP18fbJ3YzZecZdD7DDdfH2cFhhLq7Hy9bz ./cmd/plugin ) || echo "WARN: relayvm plugin build skipped" ; \
( cd /tmp/chains/thresholdvm && CGO_ENABLED=0 GOFLAGS=-mod=mod go build -ldflags="-s -w" \
-o /luxd/build/plugins/tGVBwRxpmD2aFdg3iYjgRvrCe8Jcmq9UNKxyHMus2NZ8WcD8t ./cmd/plugin ) || echo "WARN: thresholdvm plugin build skipped" ; \
( cd /tmp/chains/mpcvm && CGO_ENABLED=0 GOFLAGS=-mod=mod go build -ldflags="-s -w" \
-o /luxd/build/plugins/qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS ./cmd/plugin ) || echo "WARN: mpcvm plugin build skipped" ; \
( cd /tmp/chains/zkvm && CGO_ENABLED=0 GOFLAGS=-mod=mod go build -ldflags="-s -w" \
-o /luxd/build/plugins/vv3qPfyTVXZ5ArRZA9Jh4hbYDTBe43f7sgQg4CHfNg1rnnvX9 ./cmd/plugin ) || echo "WARN: zkvm plugin build skipped" ; \
( chmod +x /luxd/build/plugins/* 2>/dev/null || true ) && \
test -s /luxd/build/plugins/kMhHABHM8j4bH94MCc4rsTNdo5E9En37MMyiujk4WdNxgXFsY \
|| { echo "FATAL: bridgevm (B-Chain) plugin missing — the v1.30.16 regression would recur"; exit 1; } && \
for p in \
juFxSrbCM4wszxddKepj1GWwmrn9YgN1g4n3VUWPpRo9JjERA \
kMhHABHM8j4bH94MCc4rsTNdo5E9En37MMyiujk4WdNxgXFsY \
nZQm4Dmg1rjX18rb8maL9gamYyXPf1xCvF7ymWzxp6a1nSQTt \
oR6tnZHezwogyf9fRnomNXC9ojwCEBAU6jdUzpgy2PB1tD7fM \
pJJCSV7hHYVY6TUZwR8qUPAfuhX8JLb2C1AzNSezrYNbgau8M \
r5m1ujrmXxVcQetG3CQfuDLHp2RHKh6vCDaFgBRQfUcTZh7eS \
ry9Sg8rZdT26iEKvJDmC2wkESs4SDKgZEhk5BgLSwg1EpcNug \
sP6dLqrrBR9w3soP18fbJ3YzZecZdD7DDdfH2cFhhLq7Hy9bz \
qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS \
vv3qPfyTVXZ5ArRZA9Jh4hbYDTBe43f7sgQg4CHfNg1rnnvX9 ; do \
test -s /luxd/build/plugins/$p \
|| { echo "FATAL: required chain-VM plugin $p missing/empty — its build failed above (see the matching WARN line); the runtime-stage hard COPY would otherwise fail cryptically. Surface & fix the real Go build error, or remove the plugin from BOTH the build list and the runtime COPY."; exit 1; } ; \
done && \
rm -rf /tmp/chains
# ============= Native D-Chain DEX VM Plugin Stage ================
@@ -359,7 +399,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# accelerator in pkg/lx is a separate concern gated by its own cuda/metal tags and
# is NOT linked here. v1.5.10 is the first tag whose cmd/dchain builds CGO=0
# (drops the phantom dchain+cgo gate); v1.5.11 wires CLOB order ingestion over the
# node HTTP router (VM.CreateHandlers -> /ext/bc/D/dex/<method>, pkg/dchain/ingest.go)
# node HTTP router (VM.CreateHandlers -> /v1/bc/D/dex/<method>, pkg/dchain/ingest.go)
# so an order POSTed to the node flows submitTx -> mempool -> consensus -> Verify
# (match) -> Accept; v1.5.12 persists the head block so the VM survives a restart
# once advanced past genesis (GetBlock(lastAccepted) no longer ErrNotFound);
@@ -371,7 +411,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# DB (every plugin VM via vm/rpc) — that stranded the native D-Chain order book
# (rebuildBookFromDB folded empty -> 0 fills despite committed asks). v1.5.15 adds
# the committed-state READ surface (clob_get_trades/orders/markets/book over
# /ext/bc/D/dex/<method>, pkg/dchain/read.go): read-only JSON of the durable trade
# /v1/bc/D/dex/<method>, pkg/dchain/read.go): read-only JSON of the durable trade
# log / resting book / markets, served beside the writes with ZERO consensus
# impact. Needed to VERIFY a fill replicated identically across validators (query
# every node, diff the trade rows + head root) and to feed markets-display (native
@@ -382,6 +422,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
git clone --depth 1 --branch ${DEX_REF} https://github.com/luxfi/dex.git /tmp/dex && \
find /tmp/dex -name go.sum -exec sed -i -E '/^github.com\/(luxfi|hanzoai)\//d' {} + && \
cd /tmp/dex && \
# Align the dexvm plugin's ZAP wire (luxfi/api) with the node. No dex release
# pins api v1.0.16 yet (all <=v1.5.20 carry v1.0.15), so force it here; the
# bump is code-free (adds InitializeResponse.Capabilities, capability-gated),
# so dexvm emits the field the node decodes -> no "unexpected EOF" on D-Chain.
go mod edit -require=github.com/luxfi/api@v1.0.16 && \
. /build/build_env.sh && \
GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \
CGO_ENABLED=0 GOFLAGS=-mod=mod \
@@ -444,7 +489,7 @@ COPY --from=builder \
/luxd/build/plugins/r5m1ujrmXxVcQetG3CQfuDLHp2RHKh6vCDaFgBRQfUcTZh7eS \
/luxd/build/plugins/ry9Sg8rZdT26iEKvJDmC2wkESs4SDKgZEhk5BgLSwg1EpcNug \
/luxd/build/plugins/sP6dLqrrBR9w3soP18fbJ3YzZecZdD7DDdfH2cFhhLq7Hy9bz \
/luxd/build/plugins/tGVBwRxpmD2aFdg3iYjgRvrCe8Jcmq9UNKxyHMus2NZ8WcD8t \
/luxd/build/plugins/qCURact1n41FcoNBch8iMVBwc9AWie48D118ZNJ5tBdWrvryS \
/luxd/build/plugins/vv3qPfyTVXZ5ArRZA9Jh4hbYDTBe43f7sgQg4CHfNg1rnnvX9 \
/luxd/build/plugins/
WORKDIR /luxd/build
-324
View File
@@ -1,324 +0,0 @@
# Lux Mainnet Launch Checklist
Node: luxfi/node v1.24.11
Consensus: Quasar (BLS+Corona, slashing, stake-weighted sampling)
EVM: GPU ecrecover, 18 precompiles
Genesis: networkID=1, startTime=2025-12-12T21:06:51Z (mainnet), networkID=2, startTime=2026-02-10T16:00:00Z (testnet)
Precompile constraint: all activations MUST be after 2025-12-25
---
## Infrastructure
| Environment | Cluster | DOKS ID | K8s Version | Namespace | Validators |
|-------------|---------|---------|-------------|-----------|------------|
| Testnet | do-sfo3-lux-test-k8s | `005ec3c4` | 1.35.1-do.0 | lux-testnet | 11 (target) |
| Rehearsal | do-sfo3-lux-dev-k8s | `0ff340e1` | 1.35.1-do.0 | lux-devnet | 21 (target) |
| Mainnet | do-sfo3-lux-k8s | `04c46df5` | 1.34.1-do.4 | lux-mainnet | 21 (target) |
Current state: lux-k8s runs 5 validators (v1.23.31) via LuxNetwork CRD. Testnet cluster (lux-test-k8s) has a 3-replica StatefulSet (v1.23.40).
Image: `ghcr.io/luxfi/node:v1.24.11` (built via CI/CD, linux/amd64+arm64)
Staking keys: KMS at `kms.lux.network`, project `lux-infra`, synced via KMSSecret CRD
Secrets: never in manifests, never in env files, never committed
Genesis configs: `/Users/z/work/lux/genesis/configs/{testnet,mainnet,devnet}/`
K8s manifests: `/Users/z/work/lux/universe/k8s/`
Profiles: `standard.json` (~100MB/node), `max.json` (~512MB/node)
Bootstrappers:
- Mainnet: 5 seeds (ports 9631) -- `209.38.118.46`, `209.38.174.69`, `24.144.69.101`, `134.199.187.56`, `143.198.246.173`
- Testnet: 2 seeds (ports 9641) -- `134.199.187.16`, `209.38.174.84`
Consensus parameters (mainnet): K=20, AlphaPreference=15, AlphaConfidence=15, Beta=20, ConcurrentPolls=4
Tokenomics: 10B total supply (9 decimals), min validator stake 1M LUX, min delegator stake 25K LUX, combined staking allowed (NFT+delegation), 80% uptime threshold
C-Chain: chainId=96369 (mainnet), 96368 (testnet), gasLimit=12M, targetBlockRate=2s, minBaseFee=25gwei
---
## Phase 1: Testnet (lux-test-k8s, networkID=2)
Target: validate all consensus, EVM, and staking behavior with K=11 validators.
### 1.1 Deployment
- [ ] Update LuxNetwork CRD in `universe/k8s/lux-k8s/validators/statefulset.yaml` (testnet section): `validators: 11`, `image.tag: v1.24.11`
- [ ] Update lux-test-k8s StatefulSet in `universe/k8s/lux-test-k8s/testnet/statefulset.yaml`: replicas=11, image=v1.24.11
- [ ] Generate 11 staking key pairs via `lux cli` and store in KMS (`lux-infra/testnet/staking/`)
- [ ] Add 9 new bootstrapper entries to `genesis/configs/testnet/bootstrappers.json` (currently 2)
- [ ] Apply `max.json` profile for testnet validators (512MB/node for stress testing headroom)
- [ ] Regenerate testnet genesis with 11 initial validators via `genesis` tool
- [ ] Verify all precompile activation timestamps are after 2025-12-25
- [ ] Deploy via PaaS (platform.hanzo.ai), not manual kubectl
- [ ] Verify all 11 pods reach Running state
- [ ] Verify all 11 nodes report healthy via `/ext/health/liveness`
### 1.2 Bootstrap and Connectivity
- [ ] Verify all 11 validators discover each other via P2P (check `info.peers` RPC, expect 10 peers per node)
- [ ] Verify staking port 9641 reachable between all pods (`luxd-{0..10}.luxd-headless.testnet.svc.cluster.local:9641`)
- [ ] Verify P-chain bootstraps and all validators appear in `platform.getCurrentValidators`
- [ ] Verify C-chain bootstraps and produces blocks
- [ ] Verify X-chain bootstraps and processes UTXO transactions
### 1.3 Quasar Consensus Verification
- [ ] Submit transactions, verify Quasar finalization with K=11
- [ ] Verify BLS aggregate signatures in block headers
- [ ] Verify Corona optimistic fast path activates when all 11 validators are online
- [ ] Measure finality latency (target: sub-second with Corona)
- [ ] Verify stake-weighted sampling: validators with more stake get polled proportionally
### 1.4 EVM Execution
- [ ] Deploy a test contract, call all standard opcodes
- [ ] Submit 100 sequential transactions, verify correct nonce ordering
- [ ] Verify `eth_call` and `eth_estimateGas` return correct results
- [ ] Verify block gas limit is 12M (from cchain.json config)
- [ ] Verify minBaseFee=25gwei is enforced
### 1.5 GPU ecrecover
- [ ] Verify GPU backend auto-detection: CUDA on Linux DOKS nodes, Metal on macOS
- [ ] Run ecrecover-heavy workload (1000 signature verifications per block)
- [ ] Compare ecrecover throughput: GPU vs CPU fallback
- [ ] Verify graceful fallback to CPU when GPU unavailable (set `--gpu-backend=cpu`)
### 1.6 Precompiles (all 18)
- [ ] Test each precompile individually via contract calls
- [ ] Verify DEX precompile (LP-9010 PoolManager): pool creation, swaps, flash loans
- [ ] Verify DEX router precompile (LP-9012): multi-hop routing
- [ ] Verify all precompile addresses are deterministic and match spec
- [ ] Verify precompile gas metering is correct (no underpriced or overpriced ops)
- [ ] Verify precompiles revert correctly on invalid input
### 1.7 Slashing
- [ ] Craft equivocation evidence: have a validator sign two different blocks at same height
- [ ] Submit equivocation proof to P-chain slashing precompile
- [ ] Verify slashed validator's stake is burned
- [ ] Verify slashed validator is removed from active set
- [ ] Verify honest validators are unaffected
### 1.8 Uptime and Rewards
- [ ] Stop 1 validator (scale pod to 0)
- [ ] Wait for reward period to elapse
- [ ] Verify stopped validator's uptime drops below 80%
- [ ] Verify rewards are withheld for the stopped validator
- [ ] Restart the validator, verify it re-bootstraps and resumes
- [ ] Verify validators with >80% uptime receive expected rewards
### 1.9 Stress Test
- [ ] Run stress test: maximum TPS with 1B gas blocks (increase gas limit temporarily)
- [ ] Measure sustained TPS over 1 hour (target: verify consensus is the bottleneck, not EVM)
- [ ] Monitor memory usage per node (should stay within `max.json` profile ~512MB)
- [ ] Monitor disk I/O and database growth rate
- [ ] Verify no consensus stalls under load
- [ ] Verify block production rate stays at targetBlockRate=2s
### 1.10 Validator Join/Leave
- [ ] Add a 12th validator via `platform.addPermissionlessValidator` (permissionless staking)
- [ ] Verify new validator bootstraps from existing state
- [ ] Verify new validator begins participating in consensus
- [ ] Remove a validator via unstaking (wait for stake period to end or use testnet short periods)
- [ ] Verify removed validator exits gracefully
- [ ] Verify remaining validators continue producing blocks
### 1.11 Formal Verification
- [ ] Run Lean proofs for Quasar consensus safety and liveness
- [ ] Run TLA+ model checker for consensus state machine
- [ ] Run Tamarin prover for BLS+Corona security properties
- [ ] Run Halmos for EVM precompile correctness (symbolic execution)
- [ ] All proofs pass with zero counterexamples
---
## Phase 2: Mainnet Rehearsal (lux-dev-k8s, networkID=3)
Target: full mainnet simulation with real parameters for 72 hours.
### 2.1 Deployment
- [ ] Update LuxNetwork CRD (devnet section): `validators: 21`, `image.tag: v1.24.11`
- [ ] Generate 21 staking key pairs, store in KMS (`lux-infra/devnet/staking/`)
- [ ] Use mainnet genesis parameters (networkID=3, but same tokenomics, same stake amounts)
- [ ] Apply `max.json` profile
- [ ] Deploy via PaaS
- [ ] Verify all 21 pods healthy
### 2.2 Real Staking Parameters
- [ ] Configure minimum validator stake: 1M LUX
- [ ] Configure minimum delegator stake: 25K LUX
- [ ] Configure max delegation ratio: 10x
- [ ] Configure NFT staking tiers (Genesis 500K/2x, Pioneer 750K/1.5x, Standard 1M/1x)
- [ ] Verify combined staking logic: NFT value + delegation + staked >= 1M
- [ ] Verify B-chain validators require 100M LUX + KYC
### 2.3 72-Hour Soak Test
- [ ] Start clock. Record block height and timestamp.
- [ ] Continuous transaction load: 50 TPS sustained
- [ ] Monitor: CPU, memory, disk, network per node (Prometheus + Grafana via PaaS)
- [ ] Monitor: consensus latency p50/p95/p99
- [ ] Monitor: block production rate (target: 1 block per 2s)
- [ ] Monitor: peer count stability (all 21 connected)
- [ ] Monitor: no OOMKills, no pod restarts, no crashloops
- [ ] At hour 24: rolling restart of 5 validators (verify zero downtime)
- [ ] At hour 48: simulate network partition (isolate 7 nodes), verify chain halts (< 2/3 online)
- [ ] Restore partition, verify chain resumes within 30s
- [ ] At hour 72: record final block height, calculate actual vs expected blocks
- [ ] Pass criteria: zero consensus faults, zero data loss, <1% block time variance
### 2.4 Security Audit
- [ ] External security audit firm engaged (Red team)
- [ ] Audit scope: consensus, EVM, precompiles, staking, slashing, P2P networking
- [ ] Audit result: 0 critical findings, 0 high findings
- [ ] All medium findings remediated or accepted with documented risk
- [ ] Audit report signed and archived
### 2.5 Bridge / Teleport (B-Chain + T-Chain)
- [ ] Deploy MPC threshold signing (5 nodes, threshold 3) in `lux-mpc` namespace
- [ ] Deploy bridge UI and API in `lux-bridge` namespace
- [ ] Verify CGGMP21 keygen: 5 parties generate shared key
- [ ] Verify threshold signing: 3-of-5 produces valid signature
- [ ] Test cross-chain transfer: lock on source chain, mint on Lux
- [ ] Test reverse: burn on Lux, unlock on source chain
- [ ] Verify MPC API at `mpc-api.lux.network` responds
- [ ] Verify bridge handles partial MPC node failure (2 down, 3 still sign)
### 2.6 DEX (D-Chain + Precompiles)
- [ ] Deploy DEX precompile PoolManager (LP-9010) -- already active from genesis
- [ ] Deploy DEX Router precompile (LP-9012) -- already active from genesis
- [ ] Deploy off-chain CLOB matching engine
- [ ] Create liquidity pool via precompile
- [ ] Execute swap via router precompile
- [ ] Verify AMM pricing matches expected curve
- [ ] Verify flash loan execution and repayment
- [ ] Test CLOB: place limit order, verify fill
- [ ] Verify DEX on lux.exchange frontend connects to devnet
---
## Phase 3: Mainnet Launch (lux-k8s, networkID=1)
Target: production network with real value.
### 3.1 Pre-launch
- [ ] All Phase 1 items passed
- [ ] All Phase 2 items passed
- [ ] Security audit sign-off received
- [ ] Formal verification suite green
- [ ] Legal review complete (terms of service, validator agreements)
- [ ] Incident response runbook written and tested
### 3.2 Genesis Ceremony
- [ ] Final genesis config reviewed: `genesis/configs/mainnet/genesis.json` (networkID=1)
- [ ] Genesis startTime confirmed: 2025-12-12T21:06:51Z
- [ ] Initial allocations verified (500M initial + unlock schedule)
- [ ] All 5 bootstrapper IPs confirmed reachable on port 9631
- [ ] Genesis hash computed and published to lux.network
- [ ] Genesis block signed by founding validators
### 3.3 Validator Onboarding
- [ ] Update LuxNetwork CRD (mainnet section): `validators: 21`, `image.tag: v1.24.11`
- [ ] Scale from 5 current validators to 21
- [ ] Generate 16 new staking key pairs in KMS (`lux-infra/mainnet/staking/`)
- [ ] Update bootstrappers.json with all 21 validator endpoints
- [ ] Deploy via PaaS with rolling update strategy
- [ ] Verify all 21 validators healthy and in consensus
- [ ] Publish validator onboarding guide for external operators
- [ ] Open permissionless staking after initial stabilization period
### 3.4 Public RPC Endpoints
- [ ] Deploy KrakenD API gateway in `lux-gateway` namespace
- [ ] Configure rate limiting per IP and per API key
- [ ] Configure Cloudflare DNS (proxied, full SSL):
- `api.lux.network` -> gateway (C-chain + P-chain + X-chain RPC)
- `ws.lux.network` -> gateway (WebSocket subscriptions)
- [ ] Verify `eth_chainId` returns `0x17871` (96369)
- [ ] Verify `net_version` returns `96369`
- [ ] Verify RPC endpoints handle 10K req/s without degradation
- [ ] Verify WebSocket subscriptions for `newHeads`, `logs`, `pendingTransactions`
### 3.5 Explorer Deployment
- [ ] Deploy explorer (luxfi/explorer) in `lux-explorer` namespace (already has manifests for 5 chains)
- [ ] Configure for C-chain (chainId 96369)
- [ ] Configure indexers for all active chains
- [ ] Configure Cloudflare DNS: `explore.lux.network`
- [ ] Verify block display, transaction search, contract verification
- [ ] Deploy exchange frontend: `lux.exchange`
### 3.6 Bridge Activation
- [ ] Deploy MPC production cluster (5 nodes, threshold 3)
- [ ] Generate production MPC keys (CGGMP21 keygen ceremony)
- [ ] Store MPC key shares in KMS (`lux-infra/mainnet/mpc/`)
- [ ] Deploy bridge contracts on supported chains (ETH, BNB, Polygon, Arbitrum, Base, Optimism)
- [ ] Deploy bridge UI at bridge domain
- [ ] Configure Cloudflare DNS
- [ ] Enable deposits (one chain at a time, small limits first)
- [ ] Monitor for 24h, then raise limits
### 3.7 Post-Launch Monitoring
- [ ] Prometheus + Grafana dashboards live (via PaaS o11y stack)
- [ ] Alerts configured:
- Validator down (any pod not Ready for >5min)
- Consensus stall (no new block for >30s)
- Peer count drop (any node <15 peers)
- Memory usage >80% of limit
- Disk usage >70%
- Error rate >1% on RPC endpoints
- [ ] On-call rotation established
- [ ] Runbook covers: validator restart, chain halt recovery, emergency upgrade, key rotation
---
## Port Reference
| Network | HTTP | Staking | Metrics |
|---------|------|---------|---------|
| Mainnet | 9630 | 9631 | 9090 |
| Testnet | 9640 | 9641 | 9090 |
| Devnet | 9650 | 9651 | 9090 |
## Chain IDs
| Chain | Mainnet | Testnet | Devnet |
|-------|---------|---------|--------|
| C-Chain | 96369 | 96368 | 96370 |
| Zoo EVM | 200200 | 200201 | 200202 |
| Hanzo EVM | 36963 | 36964 | 36964 |
| SPC EVM | 36911 | 36910 | 36912 |
| Pars EVM | 494949 | 7071 | 494951 |
## File References
| What | Path |
|------|------|
| Node source | `~/work/lux/node/` |
| Genesis configs | `~/work/lux/genesis/configs/{mainnet,testnet,devnet}/` |
| Chain configs | `~/work/lux/genesis/configs/chain-configs/` |
| K8s manifests | `~/work/lux/universe/k8s/` |
| Validator CRD | `~/work/lux/universe/k8s/lux-k8s/validators/statefulset.yaml` |
| Testnet StatefulSet | `~/work/lux/universe/k8s/lux-test-k8s/testnet/statefulset.yaml` |
| Node profiles | `~/work/lux/node/config/profiles/{standard,max}.json` |
| Tokenomics config | `~/work/lux/node/config/tokenomics.go` |
| GPU config | `~/work/lux/node/config/gpu.go` |
| Health/consensus params | `~/work/lux/node/config/health.go` |
| Network registry | `~/work/lux/universe/NETWORKS.yaml` |
+21
View File
@@ -10,3 +10,24 @@ For the canonical Lux IP and licensing strategy, see:
For commercial inquiries that go beyond BSD-3 (e.g. private moat
acceleration kernels), contact `licensing@lux.network`.
## Upstream attribution
See [NOTICE](NOTICE) for the full attribution. In summary:
- **avalanchego** (Ava Labs, Inc.) — this repository is derived from
[ava-labs/avalanchego](https://github.com/ava-labs/avalanchego), licensed
under the **BSD 3-Clause License** (© 2019 Ava Labs, Inc.). BSD-3 is
permissive; the Lux additions here are likewise BSD-3-Clause.
- **go-ethereum** (The go-ethereum Authors) — EVM support derives from
[go-ethereum](https://github.com/ethereum/go-ethereum). It is **not**
vendored in-tree; it is consumed as the external Go module
`github.com/luxfi/geth`, which retains go-ethereum's original licenses:
the library is **LGPL-3.0-or-later** and the command-line tools are
**GPL-3.0**.
**Copyleft flag:** the LGPL-3.0/GPL-3.0 terms of the go-ethereum-derived code
(via `github.com/luxfi/geth`) are **not** superseded by this repository's
BSD-3-Clause license. Distributing compiled node binaries must honor LGPL-3.0
for the linked geth library (published source of that code and its
modifications at <https://github.com/luxfi/geth>, and user ability to relink).
+143 -15
View File
@@ -65,10 +65,10 @@ selection, and EVM contract auth.
### Where to look for X
- Profile resolve at boot: `node/node.go:initSecurityProfile`
- Profile RPC + REST + metrics: `service/security/`
- JSON-RPC namespace: `security` at `POST /ext/security`
- JSON-RPC namespace: `security` at `POST /v1/security`
(methods `securityProfile`, `blockSecurity`)
- REST sidecars: `GET /ext/security/profile`, `GET /ext/security/block/{n}`
- Prometheus gauges: `/ext/metrics` under the `security_*` family
- REST sidecars: `GET /v1/security/profile`, `GET /v1/security/block/{n}`
- Prometheus gauges: `/v1/metrics` under the `security_*` family
- Peer scheme gate: `network/peer/scheme_gate.go`
- Classical-compat registry: `vms/txs/auth/policy.go`
- Mempool gate (P-Chain): `vms/platformvm/mempool/*.go`
@@ -85,6 +85,29 @@ selection, and EVM contract auth.
## FeePolicy — canonical user-tx fee gate
> **Topology + UTXO ownership + cross-chain fee model** are normatively
> specified by [**LP-0130** (Chain Topology, UTXO Ownership, and Fee
> Model)](https://github.com/luxfi/lps/blob/main/LPs/lp-0130-chain-topology-utxo-ownership-and-fee-model.md).
> Read that LP before touching any VM's fee/settlement path or any
> cross-chain import/export flow. In particular:
>
> - Only **P** and **X** are canonical UTXO state machines (LP-0130 §2).
> - **X** is the money rail; **P** is the staking/reward rail; **LUX**
> is the fee currency everywhere (LP-0130 §3, §5).
> - **Q-Chain has no user-payable blockspace** — finality is a
> validator obligation paid via P (LP-0130 §6). `quantumvm` MUST
> use `NoUserTxPolicy{}` — enforced in chains/quantumvm/feegate.go as of 2026-07-03.
> - **M-Chain fees are service fees** deducted from the originating
> chain's fee pool, not a user M-balance (LP-0130 §7). `mpcvm`
> already runs `NoUserTxPolicy{}` — correct.
> - **B-Chain fees** are deducted from the bridged amount (LP-0130 §8).
> - Every non-P/X chain settles worker rewards to X (asset payouts) or
> P (staker rewards) via epoch fee roots reconciled at Q finality
> (LP-0130 §4, §11).
> - **Σ-escrow invariant** (LP-0130 I-8): `Σ non-P/X fee balances ==
> Σ X-side fee escrow` at every Q checkpoint. Drift is a
> finality-blocking fault.
Every Lux VM that accepts user-submitted txs declares a `fee.Policy`
(package `vms/types/fee`). There is one interface and one validator —
no per-VM bespoke fee structs.
@@ -97,14 +120,14 @@ no per-VM bespoke fee structs.
| zkvm | Z-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| aivm | A-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| keyvm | K-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| bridgevm | B-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| quantumvm | Q-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| bridgevm | B-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` (deducted from bridged amount, LP-0130 §8) |
| quantumvm | Q-Chain | **service-only** (LP-0130 §6) | `NoUserTxPolicy{}` — validator obligation, no user-payable blockspace |
| identityvm | I-Chain | user-tx | `FlatPolicy{Fee: MinTxFeeFloor, ...}` |
| thresholdvm | M-Chain | service-only | `NoUserTxPolicy{}` |
| mpcvm | M-Chain | service-only (LP-0130 §7) | `NoUserTxPolicy{}` — fees pulled from originating chain's fee pool |
| oraclevm | O-Chain | service-only | `NoUserTxPolicy{}` |
| relayvm | R-Chain | service-only | `NoUserTxPolicy{}` |
| graphvm | G-Chain | read-only | `NoUserTxPolicy{}` (GraphQL refuses `mutation`) |
| evm | C-Chain | user-tx | native EVM gas (gas * gasPrice >= 0 enforced upstream) |
| evm | C-Chain | user-tx | native EVM gas (gas * gasPrice >= 0 enforced upstream); balance is X-imported LUX (LP-0130 §10) |
| platformvm | P-Chain | user-tx | native `TxFee` field on Config |
| avm | X-Chain | user-tx | native `TxFee` field on Config |
@@ -135,6 +158,101 @@ charge less.
- Relay (R-Chain): `~/work/lux/relay/vm/feegate.go` (re-exported by `~/work/lux/chains/relayvm/`)
- Graph (G-Chain): `~/work/lux/chains/graphvm/feegate.go` (read-only; NoUserTxPolicy)
## C-Chain tx-fee routing — RewardManager to DAO Safe (P-Chain: NO CHANGE)
Owner tokenomics pivoted: **100% of C-Chain tx fees accrue to the chain's DAO Gov
Safe** via the existing `rewardmanager` precompile (C-Chain only). This needs **no
P-Chain change** — routing is `GetCoinbaseAt` → reward address on the C-Chain. See
`~/work/lux/evm/LLM.md` → "C-Chain Tx-Fee Routing — RewardManager". The P-Chain
`feeRewardPool` fold-in below is **NOT built** (design-only, superseded); no
`vms/platformvm/state` change was made.
<details><summary>Superseded design — 50/50 burn + P-Chain staking-reward fold (dormant option)</summary>
If the DAO ever chooses an in-protocol 50/50 split, the C-Chain half exists (dormant,
`FeeSplitTimestamp` gated off) and the P-Chain fold-in would be: system-triggered epoch
export of the C-Chain vault C→P → persisted `feeRewardPool` in `vms/platformvm/state`
(mirror the `accruedFees` singleton, upgrade-safe) → pro-rata payout at
`vms/platformvm/txs/executor/proposal_tx_executor.go` `rewardValidatorTx` (~line 285),
unified into `PotentialReward`, NO second mint → decrement `currentSupply` by the epoch
burn. Model R1 (move-not-mint), conservation-exact; R2 (burn+re-mint) rejected.
</details>
## v1.36.12 fleet rollout — durable rejoin fix + RewardManager→DAO Safe (IN PROGRESS 2026-07-15)
Rolling the durable rejoin fix (node `63f61429d1`) across all Lux nets, gated
devnet→testnet→mainnet, + activating RewardManager fees. Two hard facts were found
on the devnet canary that change the naive "swap image" plan:
**BLOCKER (fixed in v1.36.12): published `node:v1.36.11` (digest `c3cf92a6`) cannot
run ANY EVM chain.** Its baked VM plugins were built against a stale `luxfi/api`:
C-Chain EVM from `luxfi/evm@v1.104.8` and D-Chain dexvm from `luxfi/dex@v1.5.15`
both resolve `api v1.0.15`; the node pins `api v1.0.16`, which APPENDED
`InitializeResponse.Capabilities` (Quasar-export handshake, api `1f2dc5a`). Node
decodes the field, stale plugins never encode it → `vms/rpcchainvm/zap/client.go`
fails every EVM `Initialize` with `zap decode initialize response: unexpected EOF`.
Native VMs (P/X/Q) unaffected. **Fix = v1.36.12** (this repo, tag pushed, ARC docker
build run 29381442539): `EVM_VERSION v1.104.8→v1.104.9`, force `api@v1.0.16` in the
dexvm build stage; `CHAINS_REF=v1.7.6` was already v1.0.16. Node binary unchanged
(still the durable fix). api bump is code-free for plugins (`chains v1.7.4→v1.7.5`
adopted it go.mod-only). **Roll v1.36.12, NOT v1.36.11.** (Also: `api 1f2dc5a` added
`Capabilities` WITHOUT bumping `version.RPCChainVMProtocol` (42) → skew is invisible
at handshake, only fails at Initialize decode. Consider bumping the protocol next
api-wire change so skews fail fast.)
**MIGRATION: v1.36.2→v1.36.x is a P-Chain codec change (linearcodec→ZAP-native),
one-time DB wipe + re-bootstrap.** v1.36.11/12 cannot read a v1.36.2 P-Chain zapdb
(`loadMetadata: feeState: zap: invalid magic bytes`; `state_commit.go:116` "database
must be wiped"). Recovery = wipe `/data/db`+`/data/chainData`, re-bootstrap from
peers. **Cross-version bootstrap (v1.36.11 node ← v1.36.2 peers) is PROVEN working**
(devnet luxd-1: P/X re-bootstrapped from the 4 v1.36.2 peers). Devnet startup got a
marker-gated one-time wipe (`/data/.zap-native-migrated`): absent→wipe+set marker,
present→NO wipe (the durable-fix no-wipe restart path). mainnet/testnet/zoo use
`startup.sh` which already has `.wipe-cchain` (C-Chain only) + `.allow-bootstrap`
(flips skip-bootstrap=false + EVM state-sync); for the codec migration the P-Chain
zapdb (`/data/db`) must also be cleared. **Mainnet C-Chain is 1.08M blocks → MUST
enable EVM state-sync for the re-sync (full replay is too slow); native VMs are tiny.**
**Durable fix (`63f61429d1`):** discriminator for keeping the staked beacon set is
SYBIL-PROTECTION, not `--skip-bootstrap`. So a behind validator on a sybil-protected
net catches up from peers even with `--skip-bootstrap=true` (which prod hardcodes),
no wipe. Devnet added `--skip-bootstrap=true` to the inline cmd to exercise this.
**RewardManager (C-Chain precompile, per-net `cchain-upgrade.json` → append one
`precompileUpgrades` entry, dated `blockTimestamp`):** proven testnet shape is
`{"rewardManagerConfig":{"blockTimestamp":<ts>,"adminAddresses":["<admin>"],
"initialRewardConfig":{"rewardAddress":"<reward>"}}}`. Reward addr = coinbase; 100%
fees land there, blackhole `0x0100…00` goes flat. Addresses: **testnet ALREADY LIVE**
(reward `0xEAbCC110fAcBfebabC66Ad6f9E7B67288e720B59`, admin `0x9011…94714`); **mainnet**
reward+admin = DAO Gov Safe `0x8E29b816c6C35b13cE1ff68D33E245C2bda8ac3D`; **zoo**
reward `0x229599f227231d8C90fcF1a78589F5DC4b7A6962`; **devnet** reward
`0x8d5081153aE1cfb41f5c932fe0b6Beb7E159cF84` (idx2), admin `0x9011…94714` (idx0).
Source ConfigMaps: devnet `luxd-chain-upgrades/cchain-upgrade.json`; mainnet+testnet
`luxd-startup/cchain-upgrade.json`; zoo `zood-mv-genesis/upgrade.json` (`--upgrade-file`).
**Rollout levers (lux-operator is scaled 0/0 — sts/cm are the live source of truth;
CRs are STALE, do not scale operator up mid-roll):** ports devnet 9650 / testnet 9640
/ mainnet 9630 / zoo 9630; RPC path `/v1/bc/C/rpc`; container `luxd` (`zood` on zoo).
Devnet uses an inline generated cmd; testnet/mainnet/zoo use `/scripts/startup.sh`.
**Zoo `zood-mv` trap: RollingUpdate + hardcoded `--skip-bootstrap=true` with NO
`.allow-bootstrap` gate → switch to OnDelete BEFORE rolling.** Lux sts are OnDelete.
Master funded key = LUX_MNEMONIC (secret `lux-deployer`) idx0 `0x9011…94714`;
`genesis/cmd/derivekey -mnemonic "$M"` (path m/44'/9000'/0'/0/i, `CGO_ENABLED=0`).
**Per-node roll protocol (ALL nets, one at a time, NEVER 2 mainnet down — quorum
4/5):** set sts image v1.36.12 (+ rewardManager cm edit) → delete ONE pod → WAIT
until it is back at **TIP HEIGHT matching the others** (NOT pod-Ready; a wedged node
false-reports Ready) AND C-Chain serves RPC → only then the next. If any node fails
to return to tip, STOP that net and report.
**State at pause:** v1.36.12 tag pushed + ARC build dispatched (run 29381442539).
Devnet sts = v1.36.11 + skip-bootstrap + wipe-marker; luxd-1 migrated (P/X up on
v1.36.11, C-Chain down = the plugin bug → will heal on v1.36.12); luxd-0/2/3/4 still
v1.36.2 healthy (devnet C-Chain 4/5). Nothing rolled on testnet/mainnet/zoo. NEXT:
when v1.36.12 image is ready → set devnet sts image v1.36.12, delete luxd-1, confirm
C-Chain inits + reaches tip; then finish devnet (durable-fix proof + RewardManager),
then gated testnet→mainnet→zoo.
## Essential Commands
### Release & build (canonical) — via platform.hanzo.ai, NOT GitHub Actions
@@ -230,7 +348,7 @@ Located in `/vms/`:
- **platformvm**: Staking, validation, network management
- **xvm**: Asset transfers, UTXO model
- **dexvm**: DEX with order book, perpetuals, AMM
- **thresholdvm**: Threshold MPC and FHE for confidential computing
- **mpcvm**: Threshold MPC and FHE for confidential computing
- **quantumvm**: PQ consensus coordination (ML-DSA, Corona)
- **identityvm**: Decentralized identity (DID, verifiable credentials)
- **keyvm**: Post-quantum key management (ML-KEM, ML-DSA)
@@ -320,11 +438,11 @@ github.com/luxfi/genesis (JSON config) → github.com/luxfi/node/genesis/build
### CGO Dependencies
These require CGO for full functionality (graceful fallback when disabled):
- `consensus/quasar` - GPU NTT acceleration
- `vms/thresholdvm/fhe` - GPU FHE operations
- `vms/mpcvm/fhe` - GPU FHE operations
- `x/blockdb` - zstd compression
### FHE (Fully Homomorphic Encryption)
Located in `vms/thresholdvm/fhe/`:
Located in `vms/mpcvm/fhe/`:
- Uses `github.com/luxfi/lattice/multiparty` for DKG
- Lattice-based cryptography only (no fallbacks)
- Threshold decryption via Warp messaging
@@ -639,7 +757,7 @@ strings.Contains(errStr, "not found") // parent block not in local state
### Known CGO Stubs
When CGO disabled, these use CPU fallbacks:
- `consensus/quasar/gpu_ntt_nocgo.go`
- `vms/thresholdvm/fhe/gpu_fhe_nocgo.go`
- `vms/mpcvm/fhe/gpu_fhe_nocgo.go`
- `vms/zkvm/accel/accel_mlx.go`
### 8. ZAP CreateHandlers for VM HTTP Endpoints
@@ -659,7 +777,7 @@ When CGO disabled, these use CPU fallbacks:
```bash
curl -s -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
http://localhost:9640/ext/bc/C/rpc
http://localhost:9640/v1/bc/C/rpc
# Returns: {"jsonrpc":"2.0","id":1,"result":"0x17870"}
```
@@ -668,7 +786,7 @@ curl -s -X POST -H "Content-Type: application/json" \
**Behavior**:
- **GET /**: Returns JSON node information (nodeId, networkId, version, chains, endpoints)
- **POST /**: Proxies JSON-RPC requests directly to C-chain `/ext/bc/C/rpc`
- **POST /**: Proxies JSON-RPC requests directly to C-chain `/v1/bc/C/rpc`
- **OPTIONS /**: Returns CORS preflight headers
**Files Modified**: `server/http/router.go`, `server/http/server.go`
@@ -735,7 +853,7 @@ if s.validators.NumNets() != 0 {
**Verification**:
```bash
curl -s http://localhost:9650/ext/health | jq '.checks.bls'
curl -s http://localhost:9650/v1/health | jq '.checks.bls'
# Should show: "message": "node has the correct BLS key"
```
@@ -769,7 +887,7 @@ Testing conducted on a single Lux validator node (testnet mode, macOS):
**Benchmark Command:**
```bash
cd ~/work/lux/benchmarks
NODE_ENDPOINT="http://localhost:9640/ext/bc/C/rpc" \
NODE_ENDPOINT="http://localhost:9640/v1/bc/C/rpc" \
PRIVATE_KEY="<funded_key>" \
./bin/bench tps --chains=lux --duration=60s --concurrency=5
```
@@ -817,4 +935,14 @@ v2 semantic differences worth knowing (these change wire shape):
---
## Housekeeping
Removed 6 generated write-ups / stale root artifacts (`LAUNCH_CHECKLIST.md`,
`rename_app.sh`, `replace_imports.sh`, `gen_zoo_addr` binary, `.ci-status-check.md`,
`.ci-trigger`) plus the 73MB `.claude/worktrees/` agent scratch tree. Release and
launch state live in this file, `CHANGELOG.md`, `RELEASE.md`; chain IDs/ports in
`~/work/lux/universe/NETWORKS.yaml` and `~/work/lux/genesis/configs/`.
---
*Last Updated*: 2026-06-06
+9 -2
View File
@@ -7,8 +7,15 @@ CGO_ENABLED ?= 1
FIPS_STRICT ?= 0
# Go 1.26 experimental features:
# runtimesecret - zeroes stack/register state after secret.Do() for forward secrecy
# runtimesecret - zeroes stack/register state after secret.Do() for forward secrecy.
# It SIGSEGVs at startup under the WSL2 kernel (confirmed on go1.26.3 and go1.26.4), so enable
# it only off-WSL; forward secrecy stays on for real Linux/macOS/production builds.
WSL := $(shell grep -qiE 'microsoft|WSL' /proc/sys/kernel/osrelease 2>/dev/null && echo 1)
ifeq ($(WSL),1)
GOEXPERIMENT ?= none
else
GOEXPERIMENT ?= runtimesecret
endif
export GOEXPERIMENT
# FIPS 140-3 always enabled (required for blockchain/financial systems)
@@ -212,7 +219,7 @@ run-testnet: build-fips init-chains
node-status:
@echo "$(GREEN)Checking node status...$(NC)"
@curl -s -X POST --data '{"jsonrpc":"2.0","id":1,"method":"info.isBootstrapped","params":{}}' \
-H 'content-type:application/json;' http://localhost:9630/ext/info | jq
-H 'content-type:application/json;' http://localhost:9630/v1/info | jq
stop-node:
@echo "$(YELLOW)Stopping Lux node...$(NC)"
+38
View File
@@ -0,0 +1,38 @@
Lux Node
Copyright (c) 2019-2025 Lux Industries Inc.
This product includes software from avalanchego by Ava Labs, Inc.
(https://github.com/ava-labs/avalanchego), licensed under the BSD 3-Clause
License:
Copyright (C) 2019, Ava Labs, Inc.
Lux Node is derived from avalanchego. The Lux additions and modifications in
this repository are licensed under the BSD 3-Clause License (see the LICENSE
file). The BSD 3-Clause terms of the upstream avalanchego code are retained;
this NOTICE preserves the required Ava Labs copyright attribution at the
repository level.
--------------------------------------------------------------------------
Ethereum Virtual Machine support is derived from go-ethereum by The
go-ethereum Authors (https://github.com/ethereum/go-ethereum). In this
repository that code is NOT vendored in-tree; it is consumed as an external
Go module through the Lux fork github.com/luxfi/geth, which retains
go-ethereum's original licenses:
* The go-ethereum library packages are licensed under the GNU Lesser
General Public License, version 3 (LGPL-3.0-or-later).
* The go-ethereum command-line tools are licensed under the GNU General
Public License, version 3 (GPL-3.0).
Copyright (C) The go-ethereum Authors
COPYLEFT NOTICE: The LGPL-3.0/GPL-3.0 terms continue to apply to the
go-ethereum-derived portions provided via github.com/luxfi/geth, and are NOT
superseded by the BSD 3-Clause license of this repository. Distribution of
compiled Lux Node binaries must honor LGPL-3.0 for the linked go-ethereum
library code (source availability for that code and its modifications, and
the ability for users to relink against a modified library). The luxfi/geth
source, including Lux modifications, is published at
https://github.com/luxfi/geth.
+2
View File
@@ -1,3 +1,5 @@
<p align="center"><img src=".github/hero.svg" alt="node" width="880"></p>
<div align="center">
<img src="resources/LuxLogoRed.png?raw=true">
</div>
+1 -1
View File
@@ -3066,7 +3066,7 @@ This version is backwards compatible to [v1.9.0](https://github.com/luxfi/node/r
- Fixed `x/merkledb.ChangeProof#getLargestKey` to correctly handle no changes
- Added test for `xvm/txs/executor.SemanticVerifier#verifyFxUsage` with multiple valid fxs
- Fixed CPU + bandwidth performance regression during vertex processing
- Added example usage of the `/ext/index/X/block` API
- Added example usage of the `/v1/index/X/block` API
- Reduced the default value of `--consensus-optimal-processing` from `50` to `10`
- Updated the year in the license header
+1 -1
View File
@@ -145,7 +145,7 @@ Production implementations live in `lux/crypto/` and `lux/lattice/`. Formal veri
| `audits/2025-12-30-other-vms-audit.md` | Secondary VMs |
| `audits/2025-12-30-platformvm-audit.md` | PlatformVM (P-Chain) |
| `audits/2025-12-30-proposervm-evm-audit.md` | ProposerVM and EVM integration |
| `audits/2025-12-30-thresholdvm-audit.md` | ThresholdVM (T-Chain) |
| `audits/2025-12-30-mpcvm-audit.md` | ThresholdVM (T-Chain) |
| `audits/2025-12-30-warp-audit.md` | Warp cross-chain messaging |
| `audits/2025-12-30-zkvm-audit.md` | ZKVM (Z-Chain) |
-10
View File
@@ -73,12 +73,6 @@ tasks:
- task: generate-mocks
- task: check-clean-branch
check-generate-protobuf:
desc: Checks that generated protobuf is up-to-date (requires a clean git working tree)
cmds:
- task: generate-protobuf
- task: check-clean-branch
check-go-mod-tidy:
desc: Checks that go.mod and go.sum are up-to-date (requires a clean git working tree)
cmds:
@@ -101,10 +95,6 @@ tasks:
- cmd: grep -lr -E '^// Code generated - DO NOT EDIT\.$' tests/load/c | xargs -r rm
- cmd: go generate ./tests/load/c/...
generate-protobuf:
desc: Generates protobuf
cmd: ./scripts/protobuf_codegen.sh
ginkgo-build:
desc: Runs ginkgo against the current working directory
cmd: ./bin/ginkgo build {{.USER_WORKING_DIR}}
@@ -0,0 +1,107 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package chains
import (
"context"
"sync"
"testing"
"github.com/stretchr/testify/require"
"github.com/luxfi/ids"
"github.com/luxfi/log"
version "github.com/luxfi/version"
"github.com/luxfi/vm/chain"
)
// recordingConnector is a chain.ChainVM that records the version it is handed on
// Connected. Every other method comes from the embedded (nil) interface and is
// never invoked by the connect path.
type recordingConnector struct {
chain.ChainVM
mu sync.Mutex
called bool
gotVersion *version.Application
}
func (c *recordingConnector) Connected(_ context.Context, _ ids.NodeID, nodeVersion *chain.VersionInfo) error {
c.mu.Lock()
defer c.mu.Unlock()
c.called = true
c.gotVersion = nodeVersion
return nil
}
func (c *recordingConnector) Disconnected(context.Context, ids.NodeID) error { return nil }
// TestBlockHandlerConnectedWithVersionDeliversRealVersion is the regression
// guard for RED CRITICAL #1 (C-Chain nil-version panic).
//
// Before the fix blockHandler.Connected forwarded connector.Connected(ctx,
// nodeID, nil) — a hardcoded nil version. proposervm promotes Connected to the
// inner C-Chain VM (coreth), whose state-sync peer tracker compares peer
// versions; a nil version there dereferences nil (version.Application.Compare)
// and PANICS a state-syncing node (a fresh join, or a validator rejoining after
// falling behind — the launch's core invariant).
//
// The fix plumbs the REAL peer version through ConnectedWithVersion to the
// connector. This test drives the real blockHandler with a real version and
// asserts the connector receives that non-nil version — never nil.
func TestBlockHandlerConnectedWithVersionDeliversRealVersion(t *testing.T) {
require := require.New(t)
rc := &recordingConnector{}
bh := newBlockHandler(
nil, // BlockBuilder — unused by the connect path
rc, // connector under test
log.Noop(), // logger
nil, // engine
nil, // net
nil, // msgCreator
ids.Empty, // chainID
ids.Empty, // networkID
nil, // beacons
ids.NodeID{}, // selfNodeID
false, // expectsStakedBeacons
)
nodeID := ids.GenerateTestNodeID()
peerVersion := &version.Application{Name: "lux", Major: 1, Minor: 36, Patch: 27}
require.NoError(bh.ConnectedWithVersion(context.Background(), nodeID, peerVersion))
rc.mu.Lock()
defer rc.mu.Unlock()
require.True(rc.called, "connector.Connected must be invoked")
require.NotNil(rc.gotVersion, "connector must receive a NON-nil version (coreth dereferences it in state-sync)")
require.Equal("lux", rc.gotVersion.Name)
require.Equal(1, rc.gotVersion.Major)
require.Equal(36, rc.gotVersion.Minor)
require.Equal(27, rc.gotVersion.Patch)
}
// TestBlockHandlerConnectedDedupsButStillCarriesVersion confirms the version
// survives the once-only dedup: the first (versioned) dispatch reaches the
// connector; a duplicate is a no-op (not a nil-version overwrite).
func TestBlockHandlerConnectedDedupsButStillCarriesVersion(t *testing.T) {
require := require.New(t)
rc := &recordingConnector{}
bh := newBlockHandler(nil, rc, log.Noop(), nil, nil, nil, ids.Empty, ids.Empty, nil, ids.NodeID{}, false)
nodeID := ids.GenerateTestNodeID()
peerVersion := &version.Application{Name: "lux", Major: 1, Minor: 36, Patch: 27}
require.NoError(bh.ConnectedWithVersion(context.Background(), nodeID, peerVersion))
// A duplicate connect (e.g. dispatched again per tracked network) must be a
// no-op — never a second call that could clobber the stored version with nil.
require.NoError(bh.ConnectedWithVersion(context.Background(), nodeID, nil))
rc.mu.Lock()
defer rc.mu.Unlock()
require.NotNil(rc.gotVersion, "the deduped duplicate must not overwrite the real version with nil")
require.Equal(27, rc.gotVersion.Patch)
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+584
View File
@@ -0,0 +1,584 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// bootstrap_trust.go — the SEPARATE trust object for INITIAL SYNC, decomplected from
// consensus finality.
//
// The mass-recovery DEADLOCK this fixes: the prior FrontierTip required a ⅔-by-stake quorum
// of the CURRENT total validator set to be CONNECTED before it would name a sync frontier.
// When the recovery TARGETS are themselves validators (a node that crashed IS one of the 5),
// taking them down drops connected stake below ⅔ of the whole set — so on a network of 5
// equal-weight validators, losing 2 leaves 3 (60% < ⅔) and NO node can ever name a frontier
// to recover from. Bootstrap trust was braided into consensus finality, and finality's ⅔ rule
// is mathematically unsatisfiable during a mass outage.
//
// The fix is a type split, NOT a renamed threshold. FinalityQuorum decides FINALITY
// (> ⅔ of CURRENT stake — UNCHANGED). BootstrapTrust decides whether a fetched frontier is
// SAFE TO BEGIN SYNC FROM: a quorum of AUTHENTICATED CONFIGURED beacons that RESPOND, gated by
// a response FLOOR (MinResponses) and an agreement threshold over the RESPONDERS (not over the
// whole set). 3 of 5 reachable beacons all agreeing is a valid sync anchor even though 3 of 5
// stake is not a finalizing supermajority. The two decisions have different threat models and
// are different objects.
package chains
import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"math"
"math/bits"
"sort"
"time"
consensusconfig "github.com/luxfi/consensus/config"
"github.com/luxfi/ids"
)
// BootstrapTrust is not a consensus-finality oracle.
// It selects a weak-subjective sync frontier from authenticated configured beacons.
// Live block acceptance remains governed exclusively by FinalityQuorum.
type BootstrapTrust interface {
// AcceptsFrontier returns the block an empty/behind node may BEGIN SYNCING FROM, selected
// from the authenticated configured beacons' frontier replies — or an error
// (ErrInsufficientBootstrapResponses / ErrNoBootstrapQuorum) when no trusted frontier can be
// named this round. The returned Frontier is a sync ANCHOR, never a consensus certificate
// (see the type comment): the node must still re-execute every block it descends to before
// re-entering live consensus, where FinalityQuorum alone governs acceptance.
AcceptsFrontier(ctx context.Context, replies []BeaconReply) (*Frontier, error)
}
// FinalityQuorum decides FINALITY: whether a weight is a finalizing supermajority (> ⅔) of the
// CURRENT validator set. This is the live-consensus rule; bootstrap does NOT change it. It is a
// SEPARATE named type from BootstrapTrust precisely so the distinction is explicit and testable:
// a frontier that AcceptsFrontier admits is "safe to sync from", and in general it does NOT
// satisfy HasFinality (3 of 5 responders is a valid sync anchor; 3 of 5 stake is not finality).
type FinalityQuorum interface {
HasFinality(weight, total StakeWeight) bool
}
// StakeWeight is validator stake in the units the validator manager reports (Weight/Light).
type StakeWeight = uint64
// twoThirdsFinality is the production FinalityQuorum: > ⅔ of the CURRENT total stake, exactly
// the rule the live cert-gate uses (consensusconfig.TwoThirdsStakeFloor). Defined here only to
// give the live rule a name to CONTRAST bootstrap trust against — it is not wired into the live
// path (that already enforces ⅔ inside consensus), and bootstrap never calls it to ACCEPT.
type twoThirdsFinality struct{}
func (twoThirdsFinality) HasFinality(weight, total StakeWeight) bool {
return weight > consensusconfig.TwoThirdsStakeFloor(total)
}
// DefaultFinalityQuorum returns the live ⅔-of-current-stake finality rule — the thing bootstrap
// trust is explicitly NOT. Used by the test suite to prove a bootstrap-accepted frontier does
// not constitute finality.
func DefaultFinalityQuorum() FinalityQuorum { return twoThirdsFinality{} }
var (
// ErrInsufficientBootstrapResponses: fewer than MinResponses configured beacons answered.
// Not a partition-capture-safe quorum — the node must keep waiting for more beacons (or use
// an operator checkpoint), never sync from the captured few. INVARIANT 2's response floor.
ErrInsufficientBootstrapResponses = errors.New("bootstrap: insufficient configured-beacon responses")
// ErrNoBootstrapQuorum: enough beacons responded, but no block clears the agreement threshold
// over the responders (a genuine partition, or a transient bleeding-edge split the loop retries).
ErrNoBootstrapQuorum = errors.New("bootstrap: no responder-agreed frontier")
)
// BeaconReply is one authenticated configured beacon's report of its accepted frontier tip
// during initial sync. NodeID is authenticated at the transport handshake (a peer cannot forge
// another's identity); Weight is the beacon's CONFIGURED stake from the trust anchor — NOT a
// self-reported value. A reply whose NodeID is not in the policy's TrustedBeacons is ignored.
type BeaconReply struct {
NodeID ids.NodeID
Tip ids.ID
Weight StakeWeight
}
// Frontier is the weak-subjective sync anchor BootstrapTrust selects: the block a node descends
// to and re-executes. It is NOT a consensus certificate (see BootstrapTrust). Height is the
// tallied height when named via the ancestor-tolerant path, and 0 (unknown) when named via the
// exact fast path before any ancestry fetch — the sync loop uses ID; Height is diagnostic.
type Frontier struct {
ID ids.ID
Height uint64
Weight StakeWeight // responder stake whose accepted chain contains this block
Responders int // distinct configured beacons that backed it
FromCheckpoint bool // selected from an operator checkpoint (too few beacons responded)
}
// BlockRef is a parsed block's CONTENT-ADDRESSED identity (id, height, parent) — the only thing
// the ancestor-tolerant tally needs. Decouples the policy from the VM/block types.
type BlockRef struct {
ID ids.ID
Height uint64
Parent ids.ID
}
// AncestrySource resolves a tip's CONTENT-ADDRESSED ancestry for the ancestor-tolerant tally —
// the SAME parent-linked descent the sync loop trusts. Injected so the trust DECISION (which
// beacons count, the response floor, the agreement threshold) stays separate from the transport.
type AncestrySource interface {
// Ancestry returns up to max blocks ending at tip, parsed to (id, height, parent). An empty
// result (no error) means the tip's ancestry was not served — that anchor contributes nothing.
Ancestry(ctx context.Context, tip ids.ID, max int) ([]BlockRef, error)
}
// Checkpoint is an operator-pinned (id, height) the recovering node may anchor to when too few
// beacons respond to form a quorum — the EXPLICIT override for INVARIANT 2's "1 of N reachable"
// case. Absent (nil) ⇒ the default policy REJECTS rather than trusting a captured minority.
//
// INVARIANT 4 (a checkpoint is a SIGNED weak-subjectivity anchor, not a bare config value): the
// checkpoint carries a cryptographic Signature by the configured checkpoint AUTHORITY over its
// (id, height), and AcceptsFrontier trusts it ONLY when CheckpointVerifier authenticates that
// signature. A (id,height) present in a flag/config but UNSIGNED — or signed by a non-authority key
// — is REJECTED (fail closed). This is the crucial hardening: the checkpoint is the one path that
// bypasses the beacon quorum, so a compromised flag must NOT be able to inject a false sync anchor
// without ALSO forging the authority's signature. It is a cryptographic vouch, NEVER a ⅔-live-stake
// tally (that conflation is the very deadlock BootstrapTrust exists to avoid).
type Checkpoint struct {
ID ids.ID
Height uint64
// Signature is the checkpoint authority's signature over this checkpoint's canonical (id,height)
// bytes. Verified by CheckpointVerifier before the anchor is trusted; an empty signature is
// never accepted.
Signature []byte
}
// CheckpointVerifier authenticates a Checkpoint's Signature against the configured checkpoint
// AUTHORITY key(s). The node injects a real implementation backed by a PROVEN primitive (Ed25519 /
// BLS — never custom crypto); the policy stays free of any crypto dependency, exactly like
// AncestrySource and heightOf. A nil verifier means no signed anchor is configured, so any
// Checkpoint is untrusted and the below-floor case fails closed.
type CheckpointVerifier interface {
// VerifyCheckpoint reports whether sig is a valid signature over (id, height) by the configured
// checkpoint authority. It MUST reject an empty signature and be signature-safe (constant-time
// compare on the primitive). It is the sole authority on whether a pinned anchor may be trusted.
VerifyCheckpoint(id ids.ID, height uint64, sig []byte) bool
}
// CanonicalCheckpointMessage is the exact byte string a checkpoint authority signs and
// CheckpointVerifier authenticates: a domain-separated, fixed-layout encoding of (id, height) so a
// signature can never be transplanted from another context. 8-byte big-endian height after the
// 32-byte id, under a distinct domain tag.
func CanonicalCheckpointMessage(id ids.ID, height uint64) []byte {
const domain = "lux-bootstrap-checkpoint-v1\x00"
msg := make([]byte, 0, len(domain)+len(id)+8)
msg = append(msg, domain...)
msg = append(msg, id[:]...)
var h [8]byte
binary.BigEndian.PutUint64(h[:], height)
return append(msg, h[:]...)
}
// Ratio is an exact rational threshold (e.g. 2/3, 3/4). A value clears it iff
// value > floorOf(whole) — strictly greater, matching the consensus ⅔ floor's semantics.
type Ratio struct{ Num, Den uint64 }
// floorOf returns ⌊whole · Num / Den⌋ without floating point, overflow-safe for the sub-unity
// thresholds used here. Ratio{2,3}.floorOf(w) == consensusconfig.TwoThirdsStakeFloor(w) exactly,
// so the responder-⅔ agreement reuses the same strict-greater floor the live rule uses.
func (r Ratio) floorOf(whole uint64) uint64 {
if r.Den == 0 {
return whole // degenerate guard; constructors always set a real ratio
}
hi, lo := bits.Mul64(whole, r.Num)
if hi >= r.Den {
return math.MaxUint64 // Num ≥ Den: not a sub-unity threshold — nothing can exceed it
}
q, _ := bits.Div64(hi, lo, r.Den)
return q
}
// BootstrapPolicy is the default BootstrapTrust: a CONFIGURED-BEACON quorum with a response
// FLOOR and an agreement threshold over the RESPONDERS — a SEPARATE object from FinalityQuorum
// with a SEPARATE threat model. It does NOT pass "reachable stake" into the ⅔-of-current-stake
// finality rule (that conflation IS the mass-recovery deadlock). It reuses the ancestor-tolerant
// common-ancestor tally only for HOW to find the agreed frontier; the ACCEPTANCE gate is the
// response floor + responder agreement here.
//
// The three invariants:
// - INVARIANT 1 (non-circular beacon eligibility): only NodeIDs in TrustedBeacons count, and
// TrustedBeacons comes from the configured/checkpointed/genesis anchor — NEVER peer
// self-report. A recovering node never lets arbitrary peers define who is a beacon.
// - INVARIANT 2 (a floor prevents partition-capture): MinResponses authenticated beacons must
// respond before any frontier is named; an attacker who partitions the node down to a few
// beacons cannot capture the frontier. Below the floor, REJECT (or use Checkpoint).
// - INVARIANT 3 (acceptance ≠ finality): the named Frontier is "safe to begin sync from", not
// finalized. The node independently re-executes the descent before re-entering consensus.
type BootstrapPolicy struct {
// TrustedBeacons is the trust anchor: configured-beacon NodeID → configured stake (INVARIANT
// 1). Resolved from --bootstrap-nodes / a finalized P-chain checkpoint / the genesis set —
// never from peer self-report.
TrustedBeacons map[ids.NodeID]StakeWeight
// AgreementThreshold is the fraction of the RESPONDER weight a named block must exceed
// (default 2/3). Over RESPONDERS, not the whole set — that is what permits mass recovery.
AgreementThreshold Ratio
// MinResponses is the FLOOR on distinct configured-beacon responders (INVARIANT 2). Default:
// a MAJORITY of the configured set (the largest floor that still lets a node recover when a
// minority of validators is down). Capped at the set size.
MinResponses int
// MinResponseWeight is an OPTIONAL floor on the total responder weight (0 ⇒ disabled).
MinResponseWeight StakeWeight
// MinResponders is the minimum DISTINCT beacons that must back a NAMED block (default 2), so a
// single beacon cannot alone name the frontier. Capped at the responder count.
MinResponders int
// MinFrontierHeight is the node's current last-accepted height. The ANCESTOR-TOLERANT path
// names only a block STRICTLY ABOVE it — a frontier genuinely AHEAD. A common ancestor BELOW it
// is history the node has (a partition above, not a frontier ahead). A block AT exactly this
// height is ALSO not named here (the M1 eclipse-stale fix): an eclipse can throttle the honest
// ahead-tips below the ⅔ naming threshold while the node's OWN height accrues ⅔ as their shared
// ANCESTOR — naming it would go Ready stale. Excluding own height routes that case to CaughtUp,
// which distinguishes a legit all-at-N fleet from an eclipse with ahead-tips the node lacks. So
// nothing at or below own height is named (→ ErrNoBootstrapQuorum, fail safe), never a
// false-complete at the stale height. The exact fast path is exempt: a tip a responder
// supermajority ACTIVELY reports is a real frontier even at own height (a genuinely fresh
// network, or a fleet unanimously AT the tip).
MinFrontierHeight uint64
// Checkpoint is the OPTIONAL operator override for the below-floor case (INVARIANT 2). nil ⇒
// reject below the floor. When set, it is trusted ONLY if CheckpointVerifier authenticates its
// signature (INVARIANT 4).
Checkpoint *Checkpoint
// CheckpointVerifier authenticates the Checkpoint's authority signature (INVARIANT 4). nil ⇒ a
// configured Checkpoint is NOT trusted (fail closed) — a bare (id,height) is never enough.
CheckpointVerifier CheckpointVerifier
// NamingWindow bounds the ancestry fetched per anchor; MaxAnchors bounds how many distinct
// reported tips are resolved. Both default to the package constants when zero.
NamingWindow int
MaxAnchors int
// NamingTimeout TOTAL-bounds the ancestor-tolerant resolution (all anchor fetches combined) so
// a partition that ANSWERS the frontier query but WITHHOLDS ancestry cannot make the decision
// hang — it returns what it found (or nothing → ErrNoBootstrapQuorum) and the caller's bounded
// retry tries a fresh sample next round. Zero ⇒ the package default.
NamingTimeout time.Duration
// Source resolves content-addressed ancestry for the ancestor-tolerant tally. When nil, the
// policy decides on the exact fast path alone (no split resolution).
Source AncestrySource
}
// compile-time: the default policy IS a BootstrapTrust.
var _ BootstrapTrust = (*BootstrapPolicy)(nil)
func (p *BootstrapPolicy) effectiveMinResponses() int {
n := len(p.TrustedBeacons)
if p.MinResponses > 0 {
if p.MinResponses > n {
return n
}
return p.MinResponses
}
return n/2 + 1 // default: a MAJORITY of the configured beacon set
}
func (p *BootstrapPolicy) effectiveAgreement() Ratio {
if p.AgreementThreshold.Den == 0 {
return Ratio{Num: 2, Den: 3} // default: ⅔ of the RESPONDERS
}
return p.AgreementThreshold
}
func (p *BootstrapPolicy) effectiveMinResponders(responders int) int {
r := p.MinResponders
if r <= 0 {
r = bootstrapMinAgreeingBeacons // default 2
}
if r > responders {
r = responders
}
if r < 1 {
r = 1
}
return r
}
func (p *BootstrapPolicy) namingWindow() int {
if p.NamingWindow > 0 {
return p.NamingWindow
}
return bootstrapNamingWindow
}
func (p *BootstrapPolicy) maxAnchors() int {
if p.MaxAnchors > 0 {
return p.MaxAnchors
}
return maxNamingAnchors
}
func (p *BootstrapPolicy) namingTimeout() time.Duration {
if p.NamingTimeout > 0 {
return p.NamingTimeout
}
return bootstrapNamingTimeout
}
// tallyResponders applies INVARIANT 1 (only CONFIGURED beacons count, deduplicated by NodeID — a
// reply from a peer not in TrustedBeacons, a repeat, or an empty tip is dropped) and returns the
// distinct responder count + total responder stake plus the per-tip stake / voter maps the naming
// tally walks. The authenticated NodeID (transport handshake) is what makes "configured"
// unforgeable. Shared by AcceptsFrontier (which names a frontier AHEAD) and CaughtUp (which
// concludes NONE is ahead) so both judge the IDENTICAL responder set under the SAME eligibility
// rule — the eligibility decision lives in exactly one place.
func (p *BootstrapPolicy) tallyResponders(replies []BeaconReply) (responders int, responderWeight StakeWeight, stakeOnTip map[ids.ID]StakeWeight, votersOf map[ids.ID]map[ids.NodeID]struct{}) {
seen := make(map[ids.NodeID]struct{}, len(replies))
stakeOnTip = make(map[ids.ID]StakeWeight)
votersOf = make(map[ids.ID]map[ids.NodeID]struct{})
for _, r := range replies {
w, ok := p.TrustedBeacons[r.NodeID]
if !ok || r.Tip == ids.Empty {
continue
}
if _, dup := seen[r.NodeID]; dup {
continue
}
seen[r.NodeID] = struct{}{}
responders++
responderWeight += w
stakeOnTip[r.Tip] += w
if votersOf[r.Tip] == nil {
votersOf[r.Tip] = make(map[ids.NodeID]struct{})
}
votersOf[r.Tip][r.NodeID] = struct{}{}
}
return responders, responderWeight, stakeOnTip, votersOf
}
// floorMet reports whether the responder set clears INVARIANT 2's partition-capture FLOOR: at
// least MinResponses distinct configured beacons AND (when MinResponseWeight is configured) at
// least that much total responder stake. AcceptsFrontier gates NAMING a frontier on it and
// CaughtUp gates concluding NONE-AHEAD on the SAME floor — so an eclipse that suppresses the
// honest ahead-nodes to fake EITHER outcome must drop the responder set below it and fail safe.
func (p *BootstrapPolicy) floorMet(responders int, responderWeight StakeWeight) bool {
if responders < p.effectiveMinResponses() {
return false
}
if p.MinResponseWeight > 0 && responderWeight < p.MinResponseWeight {
return false
}
return true
}
// AcceptsFrontier implements BootstrapTrust. It (1) keeps ONLY configured-beacon replies
// (INVARIANT 1, tallyResponders), (2) enforces the MinResponses / MinResponseWeight floor or falls
// back to the operator checkpoint (INVARIANT 2, floorMet), then (3) names the highest block a
// responder supermajority shares via the ancestor-tolerant tally. It never consults the
// ⅔-of-current-stake finality rule (INVARIANT 3): the decision is the response floor + responder
// agreement, a separate threat model.
func (p *BootstrapPolicy) AcceptsFrontier(ctx context.Context, replies []BeaconReply) (*Frontier, error) {
responders, responderWeight, stakeOnTip, votersOf := p.tallyResponders(replies)
// INVARIANT 2: the response FLOOR prevents partition-capture. Below MinResponses (or below
// MinResponseWeight) the node has not heard from enough authenticated beacons to trust ANY
// frontier — an attacker may have partitioned it down to a captured few. REJECT, unless the
// operator explicitly pinned a checkpoint to anchor from.
if !p.floorMet(responders, responderWeight) {
if p.Checkpoint != nil {
// INVARIANT 4: the checkpoint bypasses the beacon quorum, so trust it ONLY when the
// configured authority SIGNED this exact (id,height). A checkpoint present in config but
// unsigned, or signed by a non-authority key, is REJECTED (fail closed) — a compromised
// flag cannot inject a false sync anchor without also forging the authority's signature.
if p.CheckpointVerifier == nil || len(p.Checkpoint.Signature) == 0 ||
!p.CheckpointVerifier.VerifyCheckpoint(p.Checkpoint.ID, p.Checkpoint.Height, p.Checkpoint.Signature) {
return nil, fmt.Errorf("%w: a checkpoint is pinned but its authority signature did not verify",
ErrInsufficientBootstrapResponses)
}
return &Frontier{
ID: p.Checkpoint.ID,
Height: p.Checkpoint.Height,
Responders: responders,
FromCheckpoint: true,
}, nil
}
return nil, fmt.Errorf("%w: %d configured beacons responded (weight %d), need %d",
ErrInsufficientBootstrapResponses, responders, responderWeight, p.effectiveMinResponses())
}
// The agreement threshold is over the RESPONDERS, not the whole configured set — this is what
// lets a node recover when validators are down (3 of 5 reachable, all 3 agreeing, is a valid
// sync anchor). The ⅔-of-current-stake finality rule is never used here (INVARIANT 3).
floor := p.effectiveAgreement().floorOf(responderWeight)
required := p.effectiveMinResponders(responders)
id, height, weight, ok := p.nameFrontier(ctx, stakeOnTip, votersOf, floor, required)
if !ok {
return nil, ErrNoBootstrapQuorum
}
return &Frontier{ID: id, Height: height, Weight: weight, Responders: responders}, nil
}
// CaughtUp reports whether the responder set PROVES the node is already AT OR ABOVE the network
// frontier — the dual of AcceptsFrontier ("nobody is ahead" vs "here is the block ahead to sync
// to"). It is the go-live path for a TIP-HOLDER on a mixed-height co-restart: when producers
// restart together the responder set SPLITS (the tip-holders are exactly half — below the ⅔
// naming threshold), so AcceptsFrontier names NOTHING (ErrNoBootstrapQuorum), yet the node is
// plainly not behind. Without this determination such a producer fails safe DOWN at its own tip —
// the exact OPPOSITE of the stale-go-live bug, and just as wrong. THREE conditions, ALL required:
//
// - (a) the SAME response FLOOR AcceptsFrontier uses is met (floorMet: MinResponses distinct
// beacons AND MinResponseWeight stake-majority). An eclipse that hides the higher (real) tips
// to fake caught-up must SUPPRESS the ahead-nodes' replies, dropping the responder set below
// the floor → NOT caught up, fail safe. No partition-capture: faking caught-up costs the same
// stake-majority of honest beacons that faking a NAMED frontier does.
// - (b) every responder's reported ACCEPTED tip is at height ≤ lastAccepted. A genuinely STALE
// node has at least one honest responder AHEAD (height > lastAccepted) → NOT caught up: it
// still syncs, so the stale-go-live bug stays fixed. (GetAcceptedFrontier reports a beacon's
// last-ACCEPTED block, so an un-finalized N+1 a producer is merely processing is never reported
// — the ±1 pending-tip skew cannot fake "ahead", and a producer one ACCEPTED block ahead
// correctly defeats caught-up so the node syncs that block.)
// - (c) the node has ACCEPTED every reported tip — heightOf returns ok ONLY for a block on the
// node's FINALIZED chain, so a tip the node lacks OR merely holds-in-store-but-has-not-accepted
// (someone genuinely ahead, a gossiped-ahead block, or a same-height sibling/fork it never
// finalized) makes the conclusion fail. The node declares caught-up only to blocks it ACCEPTED.
//
// heightOf resolves a tip's height from the node's ACCEPTED chain (ok=false when the tip is not
// accepted — including a block merely PRESENT in the store but unaccepted, the luxd-2 freeze case),
// injected so the trust DECISION stays free of any VM/block dependency — the same separation as
// AncestrySource. It is NEVER a network fetch: an unaccepted/absent tip simply makes the node
// not-caught-up (the safe direction — it syncs). Because (c) requires the node to have ACCEPTED
// every reported tip, the heights (b) compares are the blocks' canonical (content-addressed)
// heights read from the finalized chain — store presence can never fake "caught up".
func (p *BootstrapPolicy) CaughtUp(replies []BeaconReply, lastAccepted uint64, heightOf func(ids.ID) (uint64, bool)) bool {
responders, responderWeight, stakeOnTip, _ := p.tallyResponders(replies)
if !p.floorMet(responders, responderWeight) {
return false // (a) below the floor — an eclipse/partition can never fake caught-up
}
sawTip := false
for tip := range stakeOnTip {
sawTip = true
h, held := heightOf(tip)
if !held || h > lastAccepted {
return false // (c) a tip we do not hold, or (b) a responder ahead → NOT caught up
}
}
return sawTip // ≥1 responder tip evaluated (floor already implies this; guards an empty set)
}
// nameFrontier finds the block a responder supermajority shares — by CONTENT, reusing the
// parent-link descent the sync loop trusts (HOW to find the agreed frontier; the ACCEPTANCE gate
// already passed in AcceptsFrontier). A beacon reporting tip T vouches for every ANCESTOR of T,
// so the named frontier is the HIGHEST block whose backing stake exceeds floor (the responder
// agreement threshold) with ≥ required distinct voters.
//
// - EXACT FAST PATH: if a single reported tip clears the floor outright, name it with NO
// ancestry fetch (the whole responding quorum already agrees on the same tip). Exempt from
// MinFrontierHeight: an actively-reported tip is a real frontier even when low.
// - ANCESTOR-TOLERANT PATH: otherwise, fetch the distinct tips' ancestries into ONE union index
// and globally credit each tip's stake to every block on its content-addressed chain. The
// highest block clearing the floor AND at a height STRICTLY ABOVE MinFrontierHeight (a frontier
// genuinely ahead — never the node's own height, which an eclipse could over-credit as a shared
// ancestor; that routes to CaughtUp) is named. A sibling split converges to the common committed
// ancestor; a partition that shares nothing ⅔-backed names nothing (→ fail safe).
//
// C1 (a forged chain finalizes ZERO) is preserved: a block is credited a beacon's stake only when
// that beacon's tip lies on the block's CONTENT-ADDRESSED descendant chain (parent ids are bound
// to block content), so a peer cannot fake linkage to over-credit; a block is named only with
// backing > ⅔ of the responder weight; a minority (< ⅓) forged tip can only RATIFY real ancestors
// it builds on, never name itself or raise the named height above the honest common block.
func (p *BootstrapPolicy) nameFrontier(ctx context.Context, stakeOnTip map[ids.ID]StakeWeight, votersOf map[ids.ID]map[ids.NodeID]struct{}, floor StakeWeight, required int) (ids.ID, uint64, StakeWeight, bool) {
// EXACT fast path: a single reported tip already clears the floor — name it, no fetch.
for tip, st := range stakeOnTip {
if st > floor && len(votersOf[tip]) >= required {
return tip, 0, st, true
}
}
if p.Source == nil {
return ids.Empty, 0, 0, false
}
// TOTAL-bound all anchor fetches so a partition that answers the frontier query but withholds
// ancestry cannot hang the decision — the caller's bounded retry handles it next round.
ctx, cancel := context.WithTimeout(ctx, p.namingTimeout())
defer cancel()
// Build ONE union index from the distinct reported tips' ancestries (most stake first; skip a
// tip already present from an earlier fetch — a nested tip covers its ancestors). Bounded by
// MaxAnchors × NamingWindow blocks, so a Byzantine swarm reporting many forged tips cannot
// induce unbounded work.
index := make(map[ids.ID]BlockRef)
fetches := 0
for _, tip := range sortedByStakeDesc(stakeOnTip) {
if _, have := index[tip]; have {
continue
}
if fetches >= p.maxAnchors() {
break
}
fetches++
refs, err := p.Source.Ancestry(ctx, tip, p.namingWindow())
if err != nil {
continue
}
for _, ref := range refs {
if _, ok := index[ref.ID]; !ok {
index[ref.ID] = ref
}
}
}
if len(index) == 0 {
return ids.Empty, 0, 0, false
}
// Global credit: each reported tip vouches for every block on its content-addressed ancestry.
// The running backing at block B = the responder stake whose accepted chain contains B.
backing := make(map[ids.ID]StakeWeight)
voters := make(map[ids.ID]map[ids.NodeID]struct{})
for tip, st := range stakeOnTip {
cur := tip
for {
ref, ok := index[cur]
if !ok {
break // the served ancestry does not extend further down (or this tip was unserved)
}
backing[cur] += st
if voters[cur] == nil {
voters[cur] = make(map[ids.NodeID]struct{})
}
for v := range votersOf[tip] {
voters[cur][v] = struct{}{}
}
if ref.Parent == ids.Empty {
break
}
cur = ref.Parent
}
}
// Name the HIGHEST block clearing the floor with ≥ required distinct voters, at a height
// STRICTLY ABOVE MinFrontierHeight — a genuine frontier AHEAD. A block AT the node's own
// last-accepted height is NOT named here (it is history the node already holds, reachable as a
// ⅔-backed ANCESTOR of higher tips an eclipse can suppress below the naming threshold — the M1
// stale-go-live path): that case routes to CaughtUp, which alone can distinguish a legit
// all-at-N fleet (→ Ready at N) from an eclipse with ahead-tips the node lacks (→ sync). A block
// BELOW own height is a partition diverged beneath the node. Both fail safe, never false-complete.
var bestID ids.ID
var bestHeight, bestStake uint64
found := false
for id, st := range backing {
ref := index[id]
if st <= floor || len(voters[id]) < required || ref.Height <= p.MinFrontierHeight {
continue
}
if !found || ref.Height > bestHeight || (ref.Height == bestHeight && st > bestStake) {
bestID, bestHeight, bestStake, found = id, ref.Height, st, true
}
}
return bestID, bestHeight, bestStake, found
}
// sortedByStakeDesc returns the reported tips most-stake-first (stable id tiebreak) — the order
// the ancestor-tolerant tally fetches anchors in, so the well-supported honest tips are covered
// first and a forged low-stake outlier swarm falls outside the anchor cap.
func sortedByStakeDesc(stakeOnTip map[ids.ID]StakeWeight) []ids.ID {
tips := make([]ids.ID, 0, len(stakeOnTip))
for t := range stakeOnTip {
tips = append(tips, t)
}
sort.Slice(tips, func(i, j int) bool {
if stakeOnTip[tips[i]] != stakeOnTip[tips[j]] {
return stakeOnTip[tips[i]] > stakeOnTip[tips[j]]
}
return bytes.Compare(tips[i][:], tips[j][:]) < 0
})
return tips
}
+918
View File
@@ -0,0 +1,918 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// bootstrap_trust_test.go — the AG proof matrix for the BootstrapTrust policy: the SEPARATE
// trust object (distinct from consensus finality) that lets a node recover when validators are
// down (mass recovery) while refusing partition-capture and never weakening finality.
//
// Most cases test the POLICY decision (AcceptsFrontier) directly — deterministic, no network
// timing — since that IS the acceptance gate the owner specified. The mass-recovery success (A)
// and the global-tally height-floor guard also run the FULL fetch+execute loop over the real
// transport to prove the node converges (or fails safe) end to end. Each is load-bearing: revert
// the response-floor policy to the prior ⅔-of-current-total-stake gate and A deadlocks; drop the
// configured-beacon filter and D/E capture; drop the MinFrontierHeight floor and the shared-
// genesis fork false-completes.
package chains
import (
"context"
"crypto/ed25519"
"testing"
"github.com/stretchr/testify/require"
consensusconfig "github.com/luxfi/consensus/config"
chainbootstrap "github.com/luxfi/consensus/engine/chain/bootstrap"
"github.com/luxfi/ids"
)
// ----- policy test helpers --------------------------------------------------
// stubAncestry is an in-memory AncestrySource: it walks a parent-linked BlockRef map down from a
// tip, exactly as the real wire transport would serve content-addressed ancestry. Modeling the
// transport this way keeps the policy unit tests deterministic while exercising the real ancestor-
// tolerant tally. `withhold` models a beacon that names a tip but does NOT serve its ancestry.
type stubAncestry struct {
byID map[ids.ID]BlockRef
withhold map[ids.ID]bool
}
func (s *stubAncestry) Ancestry(_ context.Context, tip ids.ID, max int) ([]BlockRef, error) {
if s.withhold[tip] {
return nil, nil
}
var out []BlockRef
cur := tip
for i := 0; i < max; i++ {
ref, ok := s.byID[cur]
if !ok {
break
}
out = append(out, ref)
if ref.Parent == ids.Empty {
break
}
cur = ref.Parent
}
return out, nil
}
// refChain builds genesis..n as content-addressed BlockRefs (parent-linked), returning the slice
// and an id→ref index for the stub AncestrySource.
func refChain(n int) ([]BlockRef, map[ids.ID]BlockRef) {
refs := make([]BlockRef, 0, n+1)
byID := map[ids.ID]BlockRef{}
var parent ids.ID
for h := 0; h <= n; h++ {
r := BlockRef{ID: ids.GenerateTestID(), Height: uint64(h), Parent: parent}
refs = append(refs, r)
byID[r.ID] = r
parent = r.ID
}
return refs, byID
}
// childRef makes a block extending `parent` at height parentHeight+1 — used to forge a "higher"
// sibling tip built on a real block.
func childRef(parent BlockRef) BlockRef {
return BlockRef{ID: ids.GenerateTestID(), Height: parent.Height + 1, Parent: parent.ID}
}
func nodeIDs(n int) []ids.NodeID {
out := make([]ids.NodeID, n)
for i := range out {
out[i] = ids.GenerateTestNodeID()
}
return out
}
// equalBeacons builds a TrustedBeacons map of equal-weight validators.
func equalBeacons(beacons []ids.NodeID, w uint64) map[ids.NodeID]StakeWeight {
m := make(map[ids.NodeID]StakeWeight, len(beacons))
for _, id := range beacons {
m[id] = w
}
return m
}
func reply(id ids.NodeID, tip ids.ID, w uint64) BeaconReply {
return BeaconReply{NodeID: id, Tip: tip, Weight: w}
}
// equalStake is the owner's mainnet shape: 5 validators each 0.5e18, total 2.5e18.
const equalStake uint64 = 500_000_000_000_000_000
// ----- A: MASS RECOVERY SUCCESS ---------------------------------------------
// TestBootstrapTrust_A_MassRecoverySucceeds is THE deadlock fix. 5 EQUAL-weight validators; the 2
// stranded recovery targets are down, so only 3 are reachable; the 3 reachable agree on the
// frontier. With MinResponses=3 the policy ACCEPTS — even though 3 of 5 stake (1.5e18) is BELOW
// the ⅔-of-current-total floor (1.667e18) that the prior code required to be CONNECTED. That old
// floor was mathematically unsatisfiable here (the down nodes ARE validators), which is exactly
// why no node could recover. This test pins both: the policy accepts, AND the old gate would have
// rejected (the deadlock), AND the full loop converges over the real transport.
func TestBootstrapTrust_A_MassRecoverySucceeds(t *testing.T) {
// The deadlock the fix escapes: 3-of-5 connected stake does NOT clear ⅔ of the total set.
require.LessOrEqual(t, 3*equalStake, consensusconfig.TwoThirdsStakeFloor(5*equalStake),
"precondition: 3 of 5 equal validators is BELOW ⅔ of total — the prior connect gate's deadlock")
// Policy decision: 5 configured, 3 reachable agree on the frontier (mainnet analog 1082796).
beacons := nodeIDs(5)
frontier := ids.GenerateTestID()
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, equalStake),
MinResponses: 3,
}
replies := []BeaconReply{
reply(beacons[0], frontier, equalStake),
reply(beacons[1], frontier, equalStake),
reply(beacons[2], frontier, equalStake),
// beacons[3], beacons[4] are down/stranded — no reply.
}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err, "3 of 5 reachable beacons agreeing MUST be accepted — the mass-recovery case")
require.Equal(t, frontier, f.ID)
require.Equal(t, 3, f.Responders)
require.False(t, f.FromCheckpoint)
// End to end over the real GetAcceptedFrontier/GetAncestors transport: a STALE node with only
// 3 of its 5 equal-weight validators reachable converges to the frontier N (not stuck at M).
const N = 40
const M = 23
chain, byID := buildBSChain(N, -1)
vm := newBSVMAt(chain, M)
v := nodeIDs(5)
weights := equalBeacons(v, equalStake)
bh, chainID := newBSHandlerWeighted(t, vm, weights)
bh.bootstrapMinResponses = 3 // the owner's MinBootstrapResponses=3
bh.net = &bsBeaconNet{
bh: bh, chainID: chainID, connected: []ids.NodeID{v[0], v[1], v[2]}, // 2 stranded down
byID: byID, tip: chain[N], serveAncestors: true,
}
bh.msgCreator = bsMsgBuilder{}
ctx := context.Background()
bh.bsActive.Store(true)
tip, status := bh.FrontierTip(ctx)
bh.bsActive.Store(false)
require.Equal(t, chainbootstrap.FrontierNamed, status,
"MASS RECOVERY: 3 of 5 equal validators reachable + agreeing must NAME the frontier (no deadlock)")
require.Equal(t, chain[N].id, tip)
require.NoError(t, runBS(t, bh), "mass-recovery node must converge")
last, _ := vm.LastAccepted(ctx)
require.Equal(t, chain[N].id, last, "RECOVERED: converged to the frontier N=%d despite 2 of 5 validators down", N)
require.True(t, bh.Accepted(ctx, chain[N].id))
}
// ----- B: ONE-BEACON CAPTURE REJECTED ---------------------------------------
// TestBootstrapTrust_B_OneBeaconCaptureRejected: 5 configured, only 1 reachable. A single beacon —
// even an authentic configured one — cannot name the frontier (it could be the attacker's lone
// peer in an eclipse). The response FLOOR rejects it.
func TestBootstrapTrust_B_OneBeaconCaptureRejected(t *testing.T) {
beacons := nodeIDs(5)
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(beacons, equalStake), MinResponses: 3}
replies := []BeaconReply{reply(beacons[0], ids.GenerateTestID(), equalStake)}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.Nil(t, f)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses,
"1 of 5 reachable must be REJECTED (capture) — below the MinResponses floor")
}
// ----- C: TWO-BEACON PARTITION REJECTED -------------------------------------
// TestBootstrapTrust_C_TwoBeaconPartitionRejected: 5 configured, 2 reachable AGREEING. Two beacons
// is still below MinResponses=3, so the policy rejects by default — an attacker who partitions the
// node down to 2 beacons cannot capture the frontier even if both agree.
func TestBootstrapTrust_C_TwoBeaconPartitionRejected(t *testing.T) {
beacons := nodeIDs(5)
frontier := ids.GenerateTestID()
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(beacons, equalStake), MinResponses: 3}
replies := []BeaconReply{
reply(beacons[0], frontier, equalStake),
reply(beacons[1], frontier, equalStake),
}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.Nil(t, f)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses,
"2 of 5 reachable + agreeing must be REJECTED by default — the partition-capture floor is MinResponses=3")
}
// ----- D: NON-CONFIGURED PEER IGNORED ---------------------------------------
// TestBootstrapTrust_D_NonConfiguredPeerIgnored: an attacker peer that is NOT in the configured
// beacon set reports a higher forged tip. INVARIANT 1 (non-circular eligibility): peers never
// define who is a beacon, so the forged reply is dropped entirely and the configured beacons name
// the real frontier.
func TestBootstrapTrust_D_NonConfiguredPeerIgnored(t *testing.T) {
beacons := nodeIDs(5)
real := ids.GenerateTestID()
forgedHigher := ids.GenerateTestID()
attacker := ids.GenerateTestNodeID() // NOT in TrustedBeacons
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(beacons, equalStake), MinResponses: 3}
replies := []BeaconReply{
reply(beacons[0], real, equalStake),
reply(beacons[1], real, equalStake),
reply(beacons[2], real, equalStake),
reply(attacker, forgedHigher, 9_000_000_000_000_000_000), // huge self-reported weight, ignored
}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err)
require.Equal(t, real, f.ID, "the non-configured attacker's forged tip must be IGNORED")
require.NotEqual(t, forgedHigher, f.ID)
require.Equal(t, 3, f.Responders, "only the 3 configured beacons count toward the quorum")
}
// ----- E: MINORITY CONFIGURED FORGERY REJECTED ------------------------------
// TestBootstrapTrust_E_MinorityConfiguredForgeryRejected: 3 honest configured beacons report
// frontier A; 2 configured beacons report a FORGED tip B built directly on A (a forged higher
// sibling). C1: the forgers can only RATIFY A (the real block they built on); B itself holds only
// the Byzantine minority's stake and is NEVER named. The policy selects A.
func TestBootstrapTrust_E_MinorityConfiguredForgeryRejected(t *testing.T) {
const w uint64 = 100
refs, byID := refChain(30) // genesis..30; A := refs[30]
A := refs[30]
forgedB := childRef(A) // forged sibling at height 31, parent = real A
byID[forgedB.ID] = forgedB
beacons := nodeIDs(5)
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, w),
MinResponses: 3,
Source: &stubAncestry{byID: byID},
}
replies := []BeaconReply{
reply(beacons[0], A.ID, w),
reply(beacons[1], A.ID, w),
reply(beacons[2], A.ID, w), // 3 honest on A (300)
reply(beacons[3], forgedB.ID, w), // 2 Byzantine on the forged child (200)
reply(beacons[4], forgedB.ID, w),
}
// floor = ⅔ of 500 = 333. Neither A (300) nor forgedB (200) clears it directly, so the
// ancestor-tolerant tally runs: the forgers' stake flows DOWN through A (its real parent),
// crediting A with 500 while forgedB keeps only 200 → A named, forgedB never.
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err)
require.Equal(t, A.ID, f.ID, "C1: the forged child only RATIFIES A — A is named")
require.NotEqual(t, forgedB.ID, f.ID, "C1: the Byzantine-minority forged tip is NEVER named")
require.Equal(t, A.Height, f.Height)
}
// ----- F: SPLIT REACHABLE ANCESTRY ------------------------------------------
// TestBootstrapTrust_F_SplitReachableAncestrySelectsCommonAncestor: 3 reachable configured beacons
// each report a DIFFERENT sibling tip (three pending blocks built on the same committed block H —
// the healthy bleeding edge). No single tip holds a supermajority, but H is in all three accepted
// chains, so the policy names H (the highest ⅔-of-responders common committed block), NOT any
// isolated tip.
func TestBootstrapTrust_F_SplitReachableAncestrySelectsCommonAncestor(t *testing.T) {
const w uint64 = 100
refs, byID := refChain(39) // genesis..39; H := refs[39] (the common committed block)
H := refs[39]
a1, a2, a3 := childRef(H), childRef(H), childRef(H) // three sibling pending blocks at height 40
for _, c := range []BlockRef{a1, a2, a3} {
byID[c.ID] = c
}
beacons := nodeIDs(3)
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, w),
MinResponses: 3,
Source: &stubAncestry{byID: byID},
}
replies := []BeaconReply{
reply(beacons[0], a1.ID, w),
reply(beacons[1], a2.ID, w),
reply(beacons[2], a3.ID, w),
}
// floor = ⅔ of 300 = 200. Each sibling holds only 100, but H is shared by all three → 300 > 200.
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err)
require.Equal(t, H.ID, f.ID, "must select the common committed ancestor H")
require.Equal(t, H.Height, f.Height)
require.NotEqual(t, a1.ID, f.ID)
require.NotEqual(t, a2.ID, f.ID)
require.NotEqual(t, a3.ID, f.ID)
}
// ----- G: FINALITY UNCHANGED ------------------------------------------------
// TestBootstrapTrust_G_FinalityUnchanged proves INVARIANT 3: a bootstrap-accepted frontier is NOT
// finality. The SAME 3-of-5 support that AcceptsFrontier admits as a sync anchor does NOT satisfy
// FinalityQuorum.HasFinality — live block acceptance still requires > ⅔ of CURRENT validator
// stake (4 of 5 here). The bootstrap quorum cannot finalize a block.
func TestBootstrapTrust_G_FinalityUnchanged(t *testing.T) {
const w uint64 = 100
const total = 5 * w
beacons := nodeIDs(5)
frontier := ids.GenerateTestID()
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(beacons, w), MinResponses: 3}
// BootstrapTrust ACCEPTS 3 of 5 (a sync anchor).
f, err := policy.AcceptsFrontier(context.Background(), []BeaconReply{
reply(beacons[0], frontier, w),
reply(beacons[1], frontier, w),
reply(beacons[2], frontier, w),
})
require.NoError(t, err)
require.Equal(t, frontier, f.ID)
require.Equal(t, StakeWeight(3*w), f.Weight, "the frontier is backed by exactly the 3 responders")
// FinalityQuorum says that SAME 3-of-5 weight is NOT finality — the decisions are different
// objects with different thresholds. Finality is unchanged: it still needs > ⅔ (4 of 5).
cq := DefaultFinalityQuorum()
require.False(t, cq.HasFinality(3*w, total),
"INVARIANT 3: a bootstrap-accepted frontier (3 of 5) is NOT a finalizing supermajority")
require.True(t, cq.HasFinality(4*w, total),
"finality UNCHANGED: > ⅔ of current stake (4 of 5) still finalizes")
require.False(t, cq.HasFinality(f.Weight, total),
"the bootstrap quorum's own backing weight cannot finalize a block")
// AFTER-SYNC (the owner's "bootstrap is not a finality bypass"): the node has now SYNCED to the
// frontier via BootstrapTrust and re-entered live consensus. A NEW block that collects the SAME
// 3-of-5 stake STILL does not finalize — bootstrap admitted a sync ANCHOR, it did not lower the
// finality bar. Live acceptance returns to strict > ⅔ of CURRENT stake, exactly as before any
// bootstrap. HasFinality is stateless in the bootstrap outcome, which is the whole point: there
// is no code path by which "we bootstrapped from 3/5" leaks into the finality decision.
require.False(t, cq.HasFinality(3*w, total),
"AFTER syncing from a 3-of-5 bootstrap frontier, live finality STILL needs > ⅔ (4 of 5) — no bypass")
}
// ----- checkpoint override (complements B) ----------------------------------
// edCheckpointAuthority is a test checkpoint authority backed by Ed25519 — a PROVEN primitive, no
// custom crypto. It signs a checkpoint's canonical (id,height) message and verifies against its own
// public key, rejecting an empty signature and any key that is not the configured authority.
type edCheckpointAuthority struct {
priv ed25519.PrivateKey
pub ed25519.PublicKey
}
func newEdCheckpointAuthority(t *testing.T) *edCheckpointAuthority {
t.Helper()
pub, priv, err := ed25519.GenerateKey(nil)
require.NoError(t, err)
return &edCheckpointAuthority{priv: priv, pub: pub}
}
func (a *edCheckpointAuthority) sign(id ids.ID, height uint64) []byte {
return ed25519.Sign(a.priv, CanonicalCheckpointMessage(id, height))
}
// VerifyCheckpoint implements CheckpointVerifier: authenticate against the authority's public key.
func (a *edCheckpointAuthority) VerifyCheckpoint(id ids.ID, height uint64, sig []byte) bool {
return len(sig) != 0 && ed25519.Verify(a.pub, CanonicalCheckpointMessage(id, height), sig)
}
// TestBootstrapTrust_CheckpointOverride: below the response floor (1 of 5), the DEFAULT is reject
// (test B), but an operator who pins a SIGNED checkpoint gets the explicit override — the node
// anchors to the authenticated (id,height) instead of trusting the lone beacon. This is the
// sanctioned escape hatch for a deeply-partitioned node, NEVER an open-ended ≥1-beacon acceptance,
// and (INVARIANT 4) NEVER a bare unsigned config value.
func TestBootstrapTrust_CheckpointOverride(t *testing.T) {
beacons := nodeIDs(5)
authority := newEdCheckpointAuthority(t)
ckptID := ids.GenerateTestID()
const ckptHeight = uint64(1_082_796)
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, equalStake),
MinResponses: 3,
Checkpoint: &Checkpoint{ID: ckptID, Height: ckptHeight, Signature: authority.sign(ckptID, ckptHeight)},
CheckpointVerifier: authority,
}
// 1 reachable beacon — below the floor — but a SIGNED checkpoint is pinned.
f, err := policy.AcceptsFrontier(context.Background(), []BeaconReply{
reply(beacons[0], ids.GenerateTestID(), equalStake),
})
require.NoError(t, err)
require.True(t, f.FromCheckpoint, "below the floor with a SIGNED checkpoint → anchor to the checkpoint")
require.Equal(t, ckptID, f.ID)
require.Equal(t, ckptHeight, f.Height)
// Without the checkpoint the same 1-of-5 is rejected (the default — never trust the lone beacon).
policy.Checkpoint = nil
_, err = policy.AcceptsFrontier(context.Background(), []BeaconReply{
reply(beacons[0], ids.GenerateTestID(), equalStake),
})
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses)
}
// TestBootstrapTrust_CheckpointMustBeSigned is INVARIANT 4: a checkpoint that is present but not
// AUTHENTICATED is REJECTED (fail closed). A compromised flag/config that pins a false (id,height)
// cannot inject a sync anchor without the authority's signature. Four rejection modes, one accept.
func TestBootstrapTrust_CheckpointMustBeSigned(t *testing.T) {
beacons := nodeIDs(5)
authority := newEdCheckpointAuthority(t)
attacker := newEdCheckpointAuthority(t) // a DIFFERENT key — not the configured authority
ckptID := ids.GenerateTestID()
const h = uint64(500_000)
lone := []BeaconReply{reply(beacons[0], ids.GenerateTestID(), equalStake)} // 1-of-5, below floor
base := func() *BootstrapPolicy {
return &BootstrapPolicy{TrustedBeacons: equalBeacons(beacons, equalStake), MinResponses: 3, CheckpointVerifier: authority}
}
// (1) UNSIGNED checkpoint (empty signature) → rejected even with a verifier wired.
p := base()
p.Checkpoint = &Checkpoint{ID: ckptID, Height: h}
_, err := p.AcceptsFrontier(context.Background(), lone)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses, "an UNSIGNED checkpoint must be rejected")
// (2) signed by a NON-AUTHORITY (attacker) key → rejected.
p = base()
p.Checkpoint = &Checkpoint{ID: ckptID, Height: h, Signature: attacker.sign(ckptID, h)}
_, err = p.AcceptsFrontier(context.Background(), lone)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses, "a checkpoint signed by a non-authority key must be rejected")
// (3) authority signature over a DIFFERENT (id,height) — replay onto a forged anchor → rejected.
p = base()
forgedID := ids.GenerateTestID()
p.Checkpoint = &Checkpoint{ID: forgedID, Height: h, Signature: authority.sign(ckptID, h)} // sig binds ckptID, not forgedID
_, err = p.AcceptsFrontier(context.Background(), lone)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses, "a signature transplanted to a different (id,height) must be rejected")
// (4) NO verifier configured → any checkpoint is untrusted (fail closed).
p = base()
p.CheckpointVerifier = nil
p.Checkpoint = &Checkpoint{ID: ckptID, Height: h, Signature: authority.sign(ckptID, h)}
_, err = p.AcceptsFrontier(context.Background(), lone)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses, "no verifier ⇒ even a validly-signed checkpoint is untrusted")
// (accept) authority signs the exact pinned (id,height) → trusted.
p = base()
p.Checkpoint = &Checkpoint{ID: ckptID, Height: h, Signature: authority.sign(ckptID, h)}
f, err := p.AcceptsFrontier(context.Background(), lone)
require.NoError(t, err)
require.True(t, f.FromCheckpoint)
require.Equal(t, ckptID, f.ID)
}
// ----- safety guard for the global ancestor-tolerant tally ------------------
// TestBootstrapTrust_ForkAtSharedGenesisFailsSafe is the load-bearing guard for the
// MinFrontierHeight floor — the safety property the global cross-anchor tally (which makes case F
// work) would otherwise break. Two branches fork at a DEEP shared ancestor H (height 5), and the
// node is stale ABOVE the fork (height 23). The tally credits H with the union of BOTH halves'
// stake (all responders share H), so without the floor it would name H — and since the node
// already HOLDS H, the loop would FALSE-COMPLETE at the stale height instead of recognizing it has
// no ⅔-agreed frontier ahead. The MinFrontierHeight floor refuses to name any block beneath the
// node's last-accepted height, turning the partition into a safe ErrNoBootstrapQuorum.
//
// Asserted deterministically at the POLICY level (a stub AncestrySource serves BOTH branches'
// shared ancestry — the real wire transport's rotated sampling may only serve one, masking the
// vulnerability, so the integration path is NOT a faithful test of this guard). Revert the floor
// (set MinFrontierHeight: 0) and this names H instead of failing safe.
func TestBootstrapTrust_ForkAtSharedGenesisFailsSafe(t *testing.T) {
const w uint64 = 100
const nodeHeight = 23
// Shared prefix genesis..H (H at height 5), then two divergent branches to height 40.
shared, byID := refChain(5)
H := shared[5]
branchA := []BlockRef{H}
branchB := []BlockRef{H}
for h := 6; h <= 40; h++ {
a := childRef(branchA[len(branchA)-1])
b := childRef(branchB[len(branchB)-1])
byID[a.ID], byID[b.ID] = a, b
branchA = append(branchA, a)
branchB = append(branchB, b)
}
tipA, tipB := branchA[len(branchA)-1], branchB[len(branchB)-1]
beacons := nodeIDs(6)
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, w),
MinResponses: 4,
MinFrontierHeight: nodeHeight, // the node is stale at height 23, ABOVE the fork at 5
Source: &stubAncestry{byID: byID},
}
replies := []BeaconReply{
reply(beacons[0], tipA.ID, w), reply(beacons[1], tipA.ID, w), reply(beacons[2], tipA.ID, w),
reply(beacons[3], tipB.ID, w), reply(beacons[4], tipB.ID, w), reply(beacons[5], tipB.ID, w),
}
// H (height 5) is shared by all 6 → 600 > floor(400). But it is BELOW the node's height, so the
// floor refuses it; no block at/above height 23 has ⅔ → fail safe.
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.Nil(t, f, "must not name the deep shared ancestor — that would false-complete at the stale height")
require.ErrorIs(t, err, ErrNoBootstrapQuorum,
"a fork sharing only blocks BELOW the node's height must fail safe, never name the deep common ancestor")
// The same split with the node BELOW the fork (a fresh node) legitimately names H — the floor
// only blocks naming history the node already has, never a real frontier ahead.
policy.MinFrontierHeight = 0
f, err = policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err)
require.Equal(t, H.ID, f.ID, "with the node below the fork, H IS the ⅔-common frontier to sync to")
}
// ----- H: SKEWED-WEIGHT PARTITION-CAPTURE (the re-red HIGH; MinResponseWeight floor) ---------
// weightedBeacons builds a TrustedBeacons map from an explicit per-node weight list — for
// modeling a SKEWED (non-uniform) validator stake distribution.
func weightedBeacons(beacons []ids.NodeID, w []uint64) map[ids.NodeID]StakeWeight {
m := make(map[ids.NodeID]StakeWeight, len(beacons))
for i, id := range beacons {
m[id] = StakeWeight(w[i])
}
return m
}
// TestBootstrapTrust_H_SkewedWeightPartitionRejected is the load-bearing regression for the re-red
// HIGH finding. Under SKEWED validator weights the MinResponses COUNT floor and the ⅔-of-responders
// WEIGHT agreement diverge: an attacker who eclipses the HEAVY honest beacon but lets enough LIGHT
// honest beacons through to satisfy the count can shrink the responder-WEIGHT denominator until his
// < ⅓-of-total Byzantine stake clears ⅔-of-responders and NAMES A FORGED FRONTIER. The MinResponseWeight
// stake-majority floor (> ½ of TOTAL configured beacon stake) closes this — a < ⅓-stake adversary can
// never make the responders carry a ⅔ weight majority once they must also carry > ½ of the total.
//
// Red's PoC: 6 beacons w={3,3,13,1,1,1}, total 22, Byzantine {B0,B1}=6 (27% < ⅓). The attacker
// partitions to {B0,B1 on forgedF} + {H2,H3 on realR} = 4 responders (= the majority count floor),
// responderWeight=8, ⅔-floor=5, backing[forgedF]=6 > 5 → forgedF would be named. The heavy honest H1
// (weight 13, on the real tip) is eclipsed. With MinResponseWeight=⌈22/2⌉=12, responderWeight=8 < 12
// → the partition is rejected (the node waits for / re-samples a stake-majority of beacons).
func TestBootstrapTrust_H_SkewedWeightPartitionRejected(t *testing.T) {
refs, byID := refChain(30)
realR := refs[30]
forgedF := childRef(realR) // forged sibling at height 31 (its only honest ancestor is realR)
byID[forgedF.ID] = forgedF
b := nodeIDs(6)
weights := []uint64{3, 3, 13, 1, 1, 1} // total 22; Byzantine b[0],b[1]=6 (<⅓)
var total uint64
for _, w := range weights {
total += w
}
tb := weightedBeacons(b, weights)
// The eclipse: only the 2 Byzantine + 2 LIGHT honest answer; the HEAVY honest b[2] (the real
// tip's weight-13 voter) and b[5] are partitioned away.
replies := []BeaconReply{
reply(b[0], forgedF.ID, weights[0]), // Byzantine, light
reply(b[1], forgedF.ID, weights[1]), // Byzantine, light
reply(b[3], realR.ID, weights[3]), // honest, light
reply(b[4], realR.ID, weights[4]), // honest, light
}
// WITHOUT the stake-majority floor (the bug): the forged tip is named.
vuln := &BootstrapPolicy{TrustedBeacons: tb, MinResponses: 4, Source: &stubAncestry{byID: byID}}
if f, err := vuln.AcceptsFrontier(context.Background(), replies); err == nil && f != nil {
require.Equal(t, forgedF.ID, f.ID,
"VULN PRECONDITION: without MinResponseWeight the eclipsed skewed partition names the forged tip (proves the floor is load-bearing)")
}
// WITH the stake-majority floor (the fix, exactly as bootstrapPolicy() now wires it): rejected.
fixed := &BootstrapPolicy{
TrustedBeacons: tb,
MinResponses: 4,
MinResponseWeight: StakeWeight(total/2 + 1), // ⌈total/2⌉ = 12
Source: &stubAncestry{byID: byID},
}
_, err := fixed.AcceptsFrontier(context.Background(), replies)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses,
"FIX: responderWeight 8 < ½-stake floor 12 → the skewed partition cannot name a frontier (forged or otherwise)")
// And the fix still admits an HONEST stake-majority: add the heavy honest H1 (weight 13) on realR.
full := append(replies, reply(b[2], realR.ID, weights[2])) // responderWeight 8+13 = 21 ≥ 12
f, err := fixed.AcceptsFrontier(context.Background(), full)
require.NoError(t, err, "an honest stake-majority of responders still names the real frontier")
require.Equal(t, realR.ID, f.ID, "the real tip is named once a stake-majority is reachable; forged never")
}
// TestBootstrapTrust_D2_NonConfiguredSwarmNamesNothing is the cleaner load-bearing isolation of the
// configured-beacon filter (INVARIANT 1) that the re-red asked for: a SWARM of non-configured peers
// (enough to clear any count floor on their own) all shouting a forged frontier names NOTHING,
// because none is in TrustedBeacons. This proves the filter, not merely the MinResponders floor.
func TestBootstrapTrust_D2_NonConfiguredSwarmNamesNothing(t *testing.T) {
const w uint64 = 100
refs, byID := refChain(30)
real := refs[30]
forged, fbyID := refChain(40) // a wholly forged chain from a fresh genesis
for id, r := range fbyID {
byID[id] = r
}
configured := nodeIDs(3) // the real beacon set
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(configured, w),
MinResponses: 2,
MinResponseWeight: StakeWeight(w*3/2 + 1),
Source: &stubAncestry{byID: byID},
}
// 50 non-configured peers, each heavy, all on the forged tip — NOT in TrustedBeacons.
swarm := nodeIDs(50)
var replies []BeaconReply
for _, p := range swarm {
replies = append(replies, reply(p, forged[40].ID, 9_000_000))
}
_, err := policy.AcceptsFrontier(context.Background(), replies)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses,
"INVARIANT 1: non-configured peers carry ZERO weight — a forged swarm names nothing")
// Add the 3 real configured beacons on the real tip → the real tip is named, swarm invisible.
for _, c := range configured {
replies = append(replies, reply(c, real.ID, w))
}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err)
require.Equal(t, real.ID, f.ID, "only configured beacons name the frontier; the 50-peer forged swarm is ignored")
}
// TestBootstrapPolicy_WiresStakeMajorityFloor is the regression guard the re-red flagged (LOW):
// the production constructor bootstrapPolicy() MUST emit MinResponseWeight = ⌈total/2⌉. The H/D2
// tests construct policies directly, so a mutation that stops the constructor from setting the
// floor would not be caught — this asserts the WIRING on the real production path. Mutation-proof:
// neuter `if total > 0` in bootstrapPolicy() and this test fails (MinResponseWeight==0).
func TestBootstrapPolicy_WiresStakeMajorityFloor(t *testing.T) {
refs, _ := refChain(5)
vm := newBSVMAt(refs5BSBlocks(refs), 0)
bh, _ := newBSHandlerWeighted(t, vm, map[ids.NodeID]uint64{}) // handler shell; we call bootstrapPolicy directly
// SKEWED set: total = 22, ⌈total/2⌉ = 12.
b := nodeIDs(6)
weights := map[ids.NodeID]uint64{b[0]: 3, b[1]: 3, b[2]: 13, b[3]: 1, b[4]: 1, b[5]: 1}
var total uint64
for _, w := range weights {
total += w
}
pol := bh.bootstrapPolicy(weights)
require.Equal(t, StakeWeight(total/2+1), pol.MinResponseWeight,
"REGRESSION: bootstrapPolicy() must wire MinResponseWeight = ⌈total/2⌉ (skewed-weight floor)")
require.Equal(t, len(weights)/2+1, pol.MinResponses,
"bootstrapPolicy() must wire the count-majority floor too")
require.NotNil(t, pol.Source, "the policy must carry an AncestrySource")
// EQUAL-weight: 5 × 0.5e18 — the floor must not re-deadlock 3-of-5 (= 0.6 ≥ 0.5).
eq := equalBeacons(nodeIDs(5), 500_000_000_000_000_000)
var eqTotal uint64
for _, w := range eq {
eqTotal += uint64(w)
}
eqPol := bh.bootstrapPolicy(eq)
require.Equal(t, StakeWeight(eqTotal/2+1), eqPol.MinResponseWeight)
require.Less(t, eqPol.MinResponseWeight, StakeWeight(3*500_000_000_000_000_000),
"3-of-5 equal stake (0.6·total) must clear the ½ floor — no re-deadlock")
// DEGENERATE: empty weights → floor disabled (0), no panic.
require.Equal(t, StakeWeight(0), bh.bootstrapPolicy(map[ids.NodeID]uint64{}).MinResponseWeight,
"empty weights → MinResponseWeight disabled (pre-P-chain / single-node fallback)")
}
// refs5BSBlocks adapts a BlockRef chain to the []*bsTestBlock the bsTestVM needs (genesis only
// accepted), so newBSHandlerWeighted has a VM. The handler is used only to call bootstrapPolicy().
func refs5BSBlocks(refs []BlockRef) []*bsTestBlock {
out := make([]*bsTestBlock, len(refs))
var parent ids.ID
for i, r := range refs {
out[i] = &bsTestBlock{id: r.ID, parent: parent, height: r.Height, bytes: []byte(r.ID.String()), valid: true}
parent = r.ID
}
return out
}
// ----- CaughtUp: the tip-holder go-live determination (RED CRITICAL fix) ----
//
// CaughtUp is the DUAL of AcceptsFrontier — "nobody is ahead" vs "here is the block ahead to sync
// to". It is the go-live path for a TIP-HOLDER on a mixed-height co-restart, where the responders
// SPLIT below the ⅔ naming threshold so AcceptsFrontier names NOTHING yet the node is plainly not
// behind. Getting its SAFETY exactly right is the hinge between "fixes the freeze" and "reopens the
// stale-go-live bug": these pin all three conditions (floor met, none-ahead, holds-every-tip) and
// prove the two adversarial fake-caught-up attempts FAIL.
// heldOracle builds the height ORACLE CaughtUp injects: a block's height, ok=false when not held.
func heldOracle(held map[ids.ID]uint64) func(ids.ID) (uint64, bool) {
return func(id ids.ID) (uint64, bool) { h, ok := held[id]; return h, ok }
}
// TestBootstrapTrust_CaughtUp_TipHolderSplitGoesReady is the CRITICAL regression at the policy layer:
// the EXACT mainnet co-restart shape. A producer at N sees 4 responders split {N, N, N-16, genesis};
// the tip-holders are only ½ (< ⅔), so AcceptsFrontier names NOTHING (ErrNoBootstrapQuorum) — yet the
// node holds every reported tip and none is above N, so CaughtUp is TRUE. It pins BOTH halves: the
// SAME replies yield no NAMED frontier (the case the tip-holder fails safe DOWN without this fix) but
// ARE caught-up.
func TestBootstrapTrust_CaughtUp_TipHolderSplitGoesReady(t *testing.T) {
const N = 40
refs, byID := refChain(N) // genesis..N
b := nodeIDs(5) // 5 equal-weight beacons (the node is the 5th, not a responder)
const w = uint64(100) // total 500 → MinResponseWeight ⌈500/2⌉=251, MinResponses majority=3
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(b, w),
MinResponses: 3,
MinResponseWeight: 251,
MinFrontierHeight: N,
Source: &stubAncestry{byID: byID},
}
// 4 connected responders: 2 at the tip N, one stale at N-16, one at genesis — the production shape.
replies := []BeaconReply{
reply(b[0], refs[N].ID, w),
reply(b[1], refs[N].ID, w),
reply(b[2], refs[N-16].ID, w),
reply(b[3], refs[0].ID, w),
}
// HALF 1: AcceptsFrontier names NOTHING — the tip-holders (200) do not clear ⅔ (266), and the
// ⅔-backed common ancestor N-16 is below MinFrontierHeight=N (history the node already has).
_, err := policy.AcceptsFrontier(context.Background(), replies)
require.ErrorIs(t, err, ErrNoBootstrapQuorum,
"the mixed-height split names no frontier — exactly the case the tip-holder froze on without CaughtUp")
// HALF 2: the node HOLDS its accepted chain 0..N, so it holds every reported tip and none is above
// N → CaughtUp is TRUE. This is the go-live path the regression was missing.
held := map[ids.ID]uint64{refs[N].ID: N, refs[N-16].ID: N - 16, refs[0].ID: 0}
require.True(t, policy.CaughtUp(replies, N, heldOracle(held)),
"a tip-holder that holds every reported tip and is at the top of all of them IS caught up")
}
// TestBootstrapTrust_CaughtUp_StaleNodeNotCaughtUp is the FORWARD safety guard (the stale-go-live bug
// staying FIXED): a STALE node at N-16 with honest producers at N PRESENT must NOT be caught-up — an
// honest responder is ahead, so it still SYNCS. CaughtUp must not fire merely because SOME responders
// are at/below the node.
func TestBootstrapTrust_CaughtUp_StaleNodeNotCaughtUp(t *testing.T) {
const N = 40
refs, _ := refChain(N)
b := nodeIDs(5)
const w = uint64(100)
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(b, w), MinResponses: 3, MinResponseWeight: 251, MinFrontierHeight: N - 16}
replies := []BeaconReply{
reply(b[0], refs[N].ID, w), // honest, AHEAD
reply(b[1], refs[N].ID, w), // honest, AHEAD
reply(b[2], refs[N-16].ID, w), // at the node's height
reply(b[3], refs[N-20].ID, w), // below
}
// The node holds only 0..N-16 — it does NOT hold the producers' tip N.
held := map[ids.ID]uint64{refs[N-16].ID: N - 16, refs[N-20].ID: N - 20}
require.False(t, policy.CaughtUp(replies, N-16, heldOracle(held)),
"a stale node with an honest responder ahead must NOT be caught up — it syncs (stale-go-live stays fixed)")
}
// TestBootstrapTrust_CaughtUp_StaleNodeMinorityFakeRejected is adversarial fake-caught-up #1 (honest
// present): a node at N-16 where a <⅓-stake set of beacons reports ≤ N-16 to fake caught-up WHILE the
// honest producers at N are also present. The honest max is ahead (and the node lacks tip N) → NOT
// caught up. The minority cannot fake it past the honest responders.
func TestBootstrapTrust_CaughtUp_StaleNodeMinorityFakeRejected(t *testing.T) {
const N = 40
refs, _ := refChain(N)
b := nodeIDs(5)
const w = uint64(100)
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(b, w), MinResponses: 3, MinResponseWeight: 251, MinFrontierHeight: N - 16}
// 3 honest producers at N (ahead) + 1 Byzantine at N-16 trying to fake "everyone is at my height".
replies := []BeaconReply{
reply(b[0], refs[N].ID, w),
reply(b[1], refs[N].ID, w),
reply(b[2], refs[N].ID, w),
reply(b[3], refs[N-16].ID, w), // the < ⅓ liar
}
held := map[ids.ID]uint64{refs[N-16].ID: N - 16} // node holds only up to N-16
require.False(t, policy.CaughtUp(replies, N-16, heldOracle(held)),
"a <⅓ minority reporting ≤N-16 cannot fake caught-up while honest producers at N are present")
}
// TestBootstrapTrust_CaughtUp_EclipsedMinorityFailsSafe is adversarial fake-caught-up #2 (honest
// eclipsed): the honest producers (at N) are SUPPRESSED and only a <½-stake set of beacons reports
// ≤ N-16. The response FLOOR (the SAME one AcceptsFrontier uses) is not met → CaughtUp is FALSE →
// fail safe. Faking caught-up costs the same stake-majority of honest beacons that faking a NAMED
// frontier does — no partition-capture.
func TestBootstrapTrust_CaughtUp_EclipsedMinorityFailsSafe(t *testing.T) {
const N = 40
refs, _ := refChain(N)
b := nodeIDs(5)
const w = uint64(100) // total 500 → MinResponseWeight 251
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(b, w), MinResponses: 3, MinResponseWeight: 251, MinFrontierHeight: N - 16}
// Only 2 of 5 beacons answer (the honest producers at N are eclipsed). Their weight 200 < 251.
replies := []BeaconReply{
reply(b[2], refs[N-16].ID, w),
reply(b[3], refs[N-20].ID, w),
}
held := map[ids.ID]uint64{refs[N-16].ID: N - 16, refs[N-20].ID: N - 20}
require.False(t, policy.CaughtUp(replies, N-16, heldOracle(held)),
"an eclipsed <½-stake responder set cannot fake caught-up — the floor is not met (fail safe)")
// Sanity: AcceptsFrontier ALSO rejects this set below the floor (the SAME floor gates both paths).
_, err := policy.AcceptsFrontier(context.Background(), replies)
require.ErrorIs(t, err, ErrInsufficientBootstrapResponses, "the same floor gates naming and caught-up")
}
// TestBootstrapTrust_CaughtUp_OneAcceptedBlockBehindSyncs proves condition (b) uses the ACCEPTED
// height: a node at accepted N that has merely PROCESSED N+1 (holds it) is NOT caught up when a
// producer has ACCEPTED N+1 — it must sync that block. heightOf reads the block's canonical height,
// so a held-but-above-lastAccepted tip correctly defeats caught-up (the ±1 pending skew cannot fake it).
func TestBootstrapTrust_CaughtUp_OneAcceptedBlockBehindSyncs(t *testing.T) {
const N = 40
refs, _ := refChain(N + 1) // includes N+1
b := nodeIDs(5)
const w = uint64(100)
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(b, w), MinResponses: 3, MinResponseWeight: 251, MinFrontierHeight: N}
replies := []BeaconReply{
reply(b[0], refs[N+1].ID, w), // a producer ACCEPTED N+1
reply(b[1], refs[N].ID, w),
reply(b[2], refs[N].ID, w),
}
// The node holds 0..N AND has processed N+1 (held), but its ACCEPTED height is N.
held := map[ids.ID]uint64{refs[N+1].ID: N + 1, refs[N].ID: N}
require.False(t, policy.CaughtUp(replies, N, heldOracle(held)),
"a node one ACCEPTED block behind (even if it processed N+1) must NOT be caught up — it syncs")
}
// TestBootstrapTrust_CaughtUp_SameHeightForkNotHeld proves condition (c): a responder reporting a
// DIFFERENT block at the node's height (a fork the node never finalized) defeats caught-up — the node
// must HOLD every reported tip, not merely match heights numerically.
func TestBootstrapTrust_CaughtUp_SameHeightForkNotHeld(t *testing.T) {
const N = 40
refs, _ := refChain(N)
fork := BlockRef{ID: ids.GenerateTestID(), Height: N} // a sibling at height N the node does NOT hold
b := nodeIDs(5)
const w = uint64(100)
policy := &BootstrapPolicy{TrustedBeacons: equalBeacons(b, w), MinResponses: 3, MinResponseWeight: 251, MinFrontierHeight: N}
replies := []BeaconReply{
reply(b[0], refs[N].ID, w),
reply(b[1], refs[N].ID, w),
reply(b[2], fork.ID, w), // a fork at the same height N
}
held := map[ids.ID]uint64{refs[N].ID: N} // the node holds its tip N but NOT the fork
require.False(t, policy.CaughtUp(replies, N, heldOracle(held)),
"a same-height fork the node does not hold defeats caught-up (condition c: holds every reported tip)")
}
// ----- M1: the pre-existing eclipse-stale own-height path (red fast-follow) ------------------
//
// M1 is the pre-existing path the own-height filter tightening closes. BEFORE: nameFrontier filtered
// the ancestor-tolerant tally with `ref.Height < MinFrontierHeight` (== the node's own last-accepted),
// so a block AT the node's own height PASSED the filter and could be NAMED. An eclipse that throttles
// the genuinely-ahead responders below the ⅔ naming threshold — while letting the at-height responders
// through — makes the node's OWN height accrue ⅔ purely as the shared ANCESTOR of those ahead tips, so
// nameFrontier names it → FrontierNamed at own height → the node goes Ready STALE (here, 5 blocks
// behind a finalized N+5). AFTER: the filter is `ref.Height <= MinFrontierHeight`, so own height is
// EXCLUDED from naming; the at-own-height decision routes to CaughtUp, which SEES the N+5 ahead tips
// (un-held, above) and REFUSES → the node syncs/fails safe instead of going Ready stale.
//
// Deterministic, no network timing. Revert the filter to `<` and the first assertion (own height
// NOT named → ErrNoBootstrapQuorum) FAILS — that revert IS the M1 bug, so this is the RED-before /
// GREEN-after pin. The boundary sub-assertion (one notch lower DOES name N) proves it is precisely
// the OWN-HEIGHT exclusion doing the work, not some unrelated filter.
func TestBootstrapTrust_EclipseOwnHeightNotNamedRoutesToCaughtUp(t *testing.T) {
const N = 40 // the node's own last-accepted height
const ahead = N + 5 // a GENUINELY FINALIZED block 5 ahead — the eclipse throttles its visibility
refs, byID := refChain(ahead) // genesis..N+5, parent-linked; the ahead set's tip descends through N
const w = uint64(100)
b := nodeIDs(6) // 6 configured beacons @100 → total 600; MinResponseWeight ⌈600/2⌉=301, MinResponses majority=4
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(b, w),
MinResponses: 4,
MinResponseWeight: 301,
MinFrontierHeight: N, // the node's own last-accepted height — exactly the M1 boundary
Source: &stubAncestry{byID: byID},
}
// THE ECLIPSE CONSTRUCTION (red's, verbatim numbers): the ahead responders are throttled to
// R_a = 300 (3 beacons at N+5, BELOW the ⅔-of-responders naming threshold), the behind/at-height
// responders R_b = 200 (2 beacons at N) all get through; the 6th beacon is eclipsed (no reply).
// R = R_a + R_b = 500 > ½·600 (floor met). R_a = 300 < ⅔R = 333 (so N+5 is NOT named). YET block N
// accrues R_a + R_b = 500 > ⅔R because the ahead nodes credit N as an ANCESTOR of N+5.
replies := []BeaconReply{
reply(b[0], refs[N].ID, w), // at the node's own height N
reply(b[1], refs[N].ID, w), // at the node's own height N (R_b = 200)
reply(b[2], refs[ahead].ID, w), // genuinely ahead at N+5
reply(b[3], refs[ahead].ID, w), // genuinely ahead at N+5
reply(b[4], refs[ahead].ID, w), // genuinely ahead at N+5 (R_a = 300, < ⅔·500 = 333)
// b[5] eclipsed — no reply.
}
// Sanity pins on the construction (so a future edit that breaks the eclipse shape is caught).
require.Equal(t, uint64(333), Ratio{2, 3}.floorOf(500), "⅔-of-responders floor over R=500 is 333")
require.Less(t, uint64(300), uint64(333), "R_a=300 is BELOW the ⅔ naming threshold — N+5 is not nameable")
// AFTER (the fix): own height N is EXCLUDED from naming → no ⅔-backed block ABOVE N exists
// (N+5 is sub-⅔) → ErrNoBootstrapQuorum. (Revert `<=`→`<` and this names refs[N] — the M1 bug.)
_, err := policy.AcceptsFrontier(context.Background(), replies)
require.ErrorIs(t, err, ErrNoBootstrapQuorum,
"M1 FIX: the node's OWN height must NOT be named even when ahead tips credit it as a ⅔-backed ancestor")
// …and the decision routes to CaughtUp, which SEES the genuinely-ahead N+5 tips (un-held, above
// the node's height) and REFUSES — so the node syncs toward N+5, never goes Ready at stale N.
held := map[ids.ID]uint64{} // the node holds 0..N, NOT N+1..N+5
for h := 0; h <= N; h++ {
held[refs[h].ID] = uint64(h)
}
require.False(t, policy.CaughtUp(replies, N, heldOracle(held)),
"M1 FIX: routed to CaughtUp, the eclipse's ahead tips (un-held, above N) correctly defeat caught-up → sync")
// BOUNDARY: the SAME replies with MinFrontierHeight one notch lower (N-1) DO name N (height N is
// now STRICTLY ABOVE the floor). This proves the refusal above is precisely the OWN-HEIGHT
// exclusion — not the ⅔ tally, the responder floor, or the voter count — doing the work.
policy.MinFrontierHeight = N - 1
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err, "one notch below own height, N is strictly above the floor and IS the ⅔-common frontier")
require.Equal(t, refs[N].ID, f.ID, "boundary: N is named iff its height is STRICTLY ABOVE MinFrontierHeight")
require.Equal(t, uint64(N), f.Height)
}
+110
View File
@@ -0,0 +1,110 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// catchup_frame_test.go — the CERT-CARRYING catch-up wire format. These prove the
// load-bearing property: a v2 (block,cert) entry round-trips, an entry with no cert
// routes to the vote path, and a cross-version exchange fails CLEANLY (a legacy
// decoder cannot misparse a v2 frame, and the v2 decoder treats a legacy raw block
// as legacy — never a partial/garbage parse). The cert-accept SEMANTICS are proven
// in the consensus engine tests; here we pin only the framing.
package chains
import (
"bytes"
"encoding/binary"
"testing"
)
func TestCatchupEntry_RoundTrip(t *testing.T) {
block := []byte("\xf9\x02\x00 a realistic-ish block body")
cert := []byte("a-marshaled-quorum-cert")
blk, crt, ok := decodeCatchupEntry(encodeCatchupEntry(block, cert))
if !ok {
t.Fatal("a v2 entry must decode as a v2 entry")
}
if !bytes.Equal(blk, block) {
t.Fatalf("block bytes corrupted: got %q want %q", blk, block)
}
if !bytes.Equal(crt, cert) {
t.Fatalf("cert bytes corrupted: got %q want %q", crt, cert)
}
}
func TestCatchupEntry_EmptyCertRoutesToVotePath(t *testing.T) {
// A still-pending block served on the live missing-parent path carries no cert.
// It must decode as a v2 entry with an EMPTY cert — the requester then votes on
// it (handleContext routes certLen==0 to Put), the legacy behaviour.
block := []byte("pending-block-no-cert")
blk, crt, ok := decodeCatchupEntry(encodeCatchupEntry(block, nil))
if !ok {
t.Fatal("a v2 entry with empty cert must still decode as v2")
}
if !bytes.Equal(blk, block) {
t.Fatalf("block bytes corrupted: got %q", blk)
}
if len(crt) != 0 {
t.Fatalf("cert must be empty, got %d bytes", len(crt))
}
}
func TestCatchupEntry_LegacyRawBlockIsNotV2(t *testing.T) {
// A legacy responder sends the raw block as the container (no magic). The v2
// decoder must report ok=false so handleContext treats it as a raw block (Put),
// never as a malformed v2 entry. Cover several real block-prefix shapes.
for _, raw := range [][]byte{
{0xf9, 0x02, 0x00, 0x11, 0x22}, // EVM/RLP list header
{0x00, 0x00, 0x00, 0x2a}, // P/X-chain codec version prefix
{}, // empty
[]byte("LCU"), // 3 bytes — too short to even hold the magic
} {
if _, _, ok := decodeCatchupEntry(raw); ok {
t.Fatalf("legacy raw block %x must NOT decode as a v2 entry", raw)
}
}
}
func TestCatchupEntry_MagicIsNotAPlausibleLength(t *testing.T) {
// CROSS-VERSION SAFETY (new responder → legacy requester): a legacy decoder reads
// the first 4 bytes of a v2 entry as a uint32 length. The magic must be so large
// that it always exceeds the remaining buffer, so the legacy loop rejects the
// frame (0 blocks processed) rather than consuming garbage. 0x4C435532 ≈ 1.28 GB.
asLen := binary.BigEndian.Uint32(catchupEntryMagic[:])
if asLen < (1 << 30) {
t.Fatalf("magic read as a length (%d) is too small — a legacy decoder could misparse a v2 frame", asLen)
}
// And a full v2 frame's leading length-word (the magic) dwarfs the frame itself,
// so the legacy `blockLen > remaining` guard always fires.
frame := encodeCatchupEntry([]byte("blk"), []byte("crt"))
if uint64(binary.BigEndian.Uint32(frame[:4])) <= uint64(len(frame)) {
t.Fatal("magic-as-length must exceed the frame length so a legacy decoder self-rejects")
}
}
func TestCatchupEntry_CorruptV2FramesRejected(t *testing.T) {
good := encodeCatchupEntry([]byte("block-body"), []byte("cert-body"))
// Truncations inside the v2 structure must fail to ok=false (never a partial
// parse): drop the trailing cert byte, drop the certLen word, etc.
for _, bad := range [][]byte{
good[:len(good)-1], // last cert byte missing → certLen != remaining
good[:len(good)-5], // certLen word + cert missing
good[:8], // magic + blockLen only, block missing
good[:6], // magic + 2 bytes of blockLen
append(append([]byte(nil), good...), 0x00), // trailing byte → does not consume exactly
} {
if _, _, ok := decodeCatchupEntry(bad); ok {
t.Fatalf("a corrupt v2 frame (len %d) must be rejected, not partial-parsed", len(bad))
}
}
// An overflowing blockLen (claims more block than the buffer holds) is rejected.
overflow := append([]byte(nil), catchupEntryMagic[:]...)
var u32 [4]byte
binary.BigEndian.PutUint32(u32[:], 0xFFFFFFFF)
overflow = append(overflow, u32[:]...)
overflow = append(overflow, []byte("tiny")...)
if _, _, ok := decodeCatchupEntry(overflow); ok {
t.Fatal("a v2 frame with an overflowing blockLen must be rejected")
}
}
+56
View File
@@ -0,0 +1,56 @@
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package chains
import (
"context"
"testing"
"github.com/luxfi/ids"
"github.com/stretchr/testify/require"
)
// *blockHandler must satisfy ancestorRequester, or the catch-up wire silently
// loses its transport. Catch it at compile time, not in production.
var _ ancestorRequester = (*blockHandler)(nil)
// catchupSpy records the requestContext calls networkCatchup bridges to.
type catchupSpy struct {
calls int
lastFrom ids.NodeID
lastBlock ids.ID
}
func (s *catchupSpy) requestContext(_ context.Context, from ids.NodeID, blockID ids.ID) {
s.calls++
s.lastFrom = from
s.lastBlock = blockID
}
// TestNetworkCatchup_BridgesEngineSignalToWire is the regression for the
// stranded-follower bug: node never set netCfg.Catchup, so the engine's
// requestCatchup hit a nil interface and a follower that fell behind during
// consensus never fetched the missing ancestors — it looped on an unfinalizable
// orphan forever (observed live: mainnet luxd-0/2 stuck at 1082780 while peers
// reached 1082793). The wire must (a) be nil-safe before its handler is
// late-bound and (b) route the engine's RequestAncestors to the handler's
// GetAncestors transport (requestContext), once, for the right block and peer.
func TestNetworkCatchup_BridgesEngineSignalToWire(t *testing.T) {
missing := ids.GenerateTestID()
peer := ids.GenerateTestNodeID()
// (a) Before late-binding (handler nil): a harmless no-op, never a panic.
c := &networkCatchup{}
require.NoError(t, c.RequestAncestors(ids.Empty, ids.Empty, missing, peer))
// (b) Once wired: the engine's catch-up signal reaches the GetAncestors wire
// exactly once — for the missing block, addressed to the peer that advertised
// its child. RED before the fix: handler is never set, calls stays 0.
spy := &catchupSpy{}
c.handler = spy
require.NoError(t, c.RequestAncestors(ids.Empty, ids.Empty, missing, peer))
require.Equal(t, 1, spy.calls, "RequestAncestors must route to requestContext — a nil wire IS the stranded-follower bug")
require.Equal(t, missing, spy.lastBlock)
require.Equal(t, peer, spy.lastFrom)
}
+35 -4
View File
@@ -46,17 +46,48 @@ func (s *Nets) GetOrCreate(chainID ids.ID) (nets.Net, bool) {
return chain, true
}
// IsChainBootstrapped reports whether the given chain has finished initial sync
// (reached the network frontier and transitioned its VM to normal operation) on
// this node — Bootstrapped(chainID) was called for it in its validation net. A
// chain that is merely tracked (its sync goroutine launched) but has NOT converged
// reads false. This is the per-chain truth manager.IsBootstrapped / info.isBootstrapped
// key on, replacing the mere-existence test that returned true the instant a chain
// was added to the manager (the premature-true masking bug: a C-Chain stalled at
// genesis reported bootstrapped=true). A chainID is added to exactly one net's
// tracking, so the first net that reports it bootstrapped is authoritative.
func (s *Nets) IsChainBootstrapped(chainID ids.ID) bool {
if s == nil {
return false // no net tracking wired ⇒ nothing has been marked bootstrapped
}
s.lock.RLock()
defer s.lock.RUnlock()
for _, chain := range s.chains {
if chain.IsChainBootstrapped(chainID) {
return true
}
}
return false
}
// Bootstrapping returns the chainIDs of any chains that are still
// bootstrapping.
//
// s.chains is keyed by NET id, not chain id. Reporting the key named the net
// instead of the chain: every primary-network chain that failed to converge
// surfaced in /v1/health as the single ID
// "11111111111111111111111111111111LpoYY" — constants.PrimaryNetworkID, i.e.
// ids.Empty — a "chain" the chain manager has never heard of, so the operator
// chasing it got "there is no chain with alias/ID". Worse, N stuck chains
// collapsed into one indistinguishable entry. Ask each net which of ITS chains
// are still bootstrapping; the net owns that set.
func (s *Nets) Bootstrapping() []ids.ID {
s.lock.RLock()
defer s.lock.RUnlock()
chainsBootstrapping := make([]ids.ID, 0, len(s.chains))
for chainID, chain := range s.chains {
if !chain.IsBootstrapped() {
chainsBootstrapping = append(chainsBootstrapping, chainID)
}
for _, chain := range s.chains {
chainsBootstrapping = append(chainsBootstrapping, chain.Bootstrapping()...)
}
return chainsBootstrapping
+44 -2
View File
@@ -158,12 +158,54 @@ func TestNetsBootstrapping(t *testing.T) {
chain, ok := chains.GetOrCreate(netID)
require.True(ok)
// Start bootstrapping
// Start bootstrapping. What comes back is the CHAIN that is syncing, never
// the net that holds it — this assertion used to demand netID, which is
// how the phantom "11111111111111111111111111111111LpoYY" survived review.
chain.AddChain(chainID)
bootstrapping := chains.Bootstrapping()
require.Contains(bootstrapping, netID)
require.Equal([]ids.ID{chainID}, bootstrapping)
require.NotContains(bootstrapping, netID)
// Finish bootstrapping
chain.Bootstrapped(chainID)
require.Empty(chains.Bootstrapping())
}
// The "bootstrapped" health check publishes Nets.Bootstrapping() verbatim as
// its message. s.chains is keyed by NET id, so returning the key reported
// constants.PrimaryNetworkID (ids.Empty, cb58
// "11111111111111111111111111111111LpoYY") as though it were an unbootstrapped
// CHAIN. Operators saw a chain ID the chain manager denies exists, and every
// stuck chain on the net collapsed into that one phantom entry.
func TestNetsBootstrappingReportsChainsNotNets(t *testing.T) {
require := require.New(t)
chains, err := NewNets(ids.EmptyNodeID, map[ids.ID]nets.Config{
constants.PrimaryNetworkID: {},
})
require.NoError(err)
primary, _ := chains.GetOrCreate(constants.PrimaryNetworkID)
cChainID := ids.GenerateTestID()
dChainID := ids.GenerateTestID()
primary.AddChain(cChainID)
primary.AddChain(dChainID)
bootstrapping := chains.Bootstrapping()
// The phantom: never the net's own ID.
require.NotContains(bootstrapping, constants.PrimaryNetworkID)
require.NotContains(
bootstrapping,
ids.Empty,
"health check reported the primary NET id as an unbootstrapped chain",
)
// Both stuck chains must be individually nameable.
require.ElementsMatch([]ids.ID{cChainID, dChainID}, bootstrapping)
primary.Bootstrapped(cChainID)
require.Equal([]ids.ID{dChainID}, chains.Bootstrapping())
primary.Bootstrapped(dChainID)
require.Empty(chains.Bootstrapping())
}
+139
View File
@@ -0,0 +1,139 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// context_chunk_test.go — the heavy-block self-heal fix: GetContext must bound its Ancestors
// response by SERIALIZED SIZE (not just block COUNT) so it stays under the peer message cap.
//
// Benchmark-proven live bug: under 250-trader DEX load, heavy blocks made a 256-block context
// response sum to 3.4-5.7 MB > the 2 MB compressor cap; msgCreator.Ancestors FAILED to build,
// so a behind validator received NOTHING and could never resync (permanently stuck while the tip
// advanced). This pins the fix: the response is chunked to fit the budget, always serving at
// least one block so the behind node makes progress every round.
package chains
import (
"context"
"errors"
"testing"
"time"
consensuschain "github.com/luxfi/consensus/engine/chain"
consensusblock "github.com/luxfi/consensus/engine/chain/block"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/message"
)
// heavyBlock is a consensuschain.Block of a controlled byte size; only the methods GetContext
// touches (ID/Parent/Bytes) are overridden — the rest of the interface is embedded and unused.
type heavyBlock struct {
consensusblock.Block
id, parent ids.ID
bytes []byte
}
func (b *heavyBlock) ID() ids.ID { return b.id }
func (b *heavyBlock) Parent() ids.ID { return b.parent }
func (b *heavyBlock) Bytes() []byte { return b.bytes }
// sizeStubVM serves heavyBlocks by id (only GetBlock is called by GetContext).
type sizeStubVM struct {
consensuschain.BlockBuilder
blocks map[ids.ID]consensusblock.Block
}
func (v *sizeStubVM) GetBlock(_ context.Context, id ids.ID) (consensusblock.Block, error) {
b, ok := v.blocks[id]
if !ok {
return nil, errors.New("not found")
}
return b, nil
}
// sizeRecMsg records the containers GetContext hands to Ancestors, so the test can measure the
// assembled response size (the input the real zstd compressor would reject above the cap).
type sizeRecMsg struct {
message.OutboundMsgBuilder
containers [][]byte
}
func (m *sizeRecMsg) Ancestors(_ ids.ID, _ uint32, containers [][]byte) (message.OutboundMessage, error) {
m.containers = containers
return nil, nil
}
func TestGetContext_ChunksBySize_FitsUnderCap(t *testing.T) {
// A 100-block chain of ~150 KiB blocks. Packed by COUNT alone (up to maxContextBlocks=256,
// i.e. all 100), the response is ~15 MB — 7x over the 2 MB cap, so the old handler's message
// failed to build. Bounded by SIZE, it serves only as many as fit.
const nBlocks = 100
const blkSize = 150 * 1024
vm := &sizeStubVM{blocks: map[ids.ID]consensusblock.Block{}}
parent := ids.Empty
var tip ids.ID
for i := 0; i < nBlocks; i++ {
id := ids.GenerateTestID()
vm.blocks[id] = &heavyBlock{id: id, parent: parent, bytes: make([]byte, blkSize)}
parent = id
tip = id
}
msg := &sizeRecMsg{}
bh := &blockHandler{
logger: log.NewNoOpLogger(),
vm: vm,
msgCreator: msg,
net: &redStubNet{},
chainID: ids.GenerateTestID(),
networkID: ids.GenerateTestID(),
maxContextBlocks: 256,
}
if err := bh.GetContext(context.Background(), ids.GenerateTestNodeID(), 1, time.Now().Add(time.Second), tip); err != nil {
t.Fatalf("GetContext: %v", err)
}
total := 0
for _, c := range msg.containers {
total += len(c)
}
budget := constants.DefaultMaxMessageSize - 128*1024 // the handler's byteBudget
if len(msg.containers) == 0 {
t.Fatal("must serve at least one block (a behind node must always make progress)")
}
if total > budget {
t.Fatalf("context response %d bytes exceeds budget %d — the real Ancestors compressor would REJECT it "+
"(cap %d), stranding a behind validator (the live bug)", total, budget, constants.DefaultMaxMessageSize)
}
if len(msg.containers) >= nBlocks {
t.Fatalf("expected SIZE truncation (fewer than %d blocks), got %d — response not chunked", nBlocks, len(msg.containers))
}
t.Logf("size-chunked: %d blocks, %d payload bytes (budget %d, cap %d) — fits, so the compressor accepts it",
len(msg.containers), total, budget, constants.DefaultMaxMessageSize)
}
// A single heavy block is ALWAYS served even if it alone exceeds the budget — the walk must never
// deadlock (the trust-tiered validator cap gives such a block the send headroom; a stranger's
// tight cap correctly rejects it downstream).
func TestGetContext_SingleOversizeBlock_StillServed(t *testing.T) {
oversize := constants.DefaultMaxMessageSize + 1<<20 // > the cap on its own
id := ids.GenerateTestID()
vm := &sizeStubVM{blocks: map[ids.ID]consensusblock.Block{
id: &heavyBlock{id: id, parent: ids.Empty, bytes: make([]byte, oversize)},
}}
msg := &sizeRecMsg{}
bh := &blockHandler{
logger: log.NewNoOpLogger(), vm: vm, msgCreator: msg, net: &redStubNet{},
chainID: ids.GenerateTestID(), networkID: ids.GenerateTestID(), maxContextBlocks: 256,
}
if err := bh.GetContext(context.Background(), ids.GenerateTestNodeID(), 1, time.Now().Add(time.Second), id); err != nil {
t.Fatalf("GetContext: %v", err)
}
if len(msg.containers) != 1 {
t.Fatalf("a single (even oversize) block must be served so the walk never deadlocks, got %d blocks", len(msg.containers))
}
}
+1355 -195
View File
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -123,8 +123,14 @@ func (m *manager) authorizeChainActivation(chainID ids.ID) (authorized bool, rea
// authorization from an NFT held at an address it does not control.
// The gate consults the X-Chain UTXO set, so the X-Chain must already be
// bootstrapped (created and tracked) on this node. If not, we cannot decide
// yet — signal the caller to defer.
// bootstrapped on this node. IsBootstrapped now keys on REAL convergence
// (sb.Bootstrapped), not mere presence — safe here because X-Chain is a DAG
// chain marked bootstrapped SYNCHRONOUSLY inside createChain (Engine == nil
// path) before the sequential chain-creator dequeues any re-pushed gated chain,
// so IsBootstrapped(X) is already true when a gated chain re-runs. INVARIANT: if
// X-Chain is ever linearized into an engine chain (async Bootstrapped via
// monitorBootstrap), retryPendingGatedChains must be made to re-drain after X
// converges, else gated chains park forever. If not bootstrapped yet, defer.
if !m.IsBootstrapped(m.XChainID) {
return false, false
}
+24 -5
View File
@@ -9,10 +9,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/luxfi/constants"
"github.com/luxfi/container/buffer"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/math/set"
"github.com/luxfi/node/nets"
lux "github.com/luxfi/utxo"
"github.com/luxfi/utxo/nftfx"
"github.com/luxfi/utxo/secp256k1fx"
@@ -163,8 +165,10 @@ func TestHoldsAuthorizationNFT(t *testing.T) {
// newGateManager builds the minimal manager needed to exercise the gate:
// only the fields authorizeChainActivation reads. xChainVM, when non-nil, is
// installed as the X-Chain's tracked VM so IsBootstrapped(XChainID) is true and
// xChainUTXOReader() resolves to it.
// installed as the X-Chain's tracked VM AND marked bootstrapped in its net so
// IsBootstrapped(XChainID) is true (the gate consults the X-Chain UTXO set, which
// is only valid once the X-Chain has finished initial sync — mere presence in
// m.chains is no longer sufficient) and xChainUTXOReader() resolves to it.
func newGateManager(
xChainID ids.ID,
stakingAddr ids.ShortID,
@@ -172,17 +176,29 @@ func newGateManager(
critical set.Set[ids.ID],
xChainVM xChainUTXOReader,
) *manager {
netsTracker, err := NewNets(ids.GenerateTestNodeID(), map[ids.ID]nets.Config{
constants.PrimaryNetworkID: {},
})
if err != nil {
panic(err)
}
m := &manager{
chains: make(map[ids.ID]*chainInfo),
gatedAttempts: make(map[ids.ID]int),
}
m.Log = log.NewNoOpLogger()
m.Nets = netsTracker
m.XChainID = xChainID
m.StakingXAddress = stakingAddr
m.ChainAuthorizations = authz
m.CriticalChains = critical
if xChainVM != nil {
m.chains[xChainID] = &chainInfo{Name: "X-Chain", VM: xChainVM}
// The X-Chain has finished initial sync (its UTXO set is valid) — the real
// precondition the gate depends on, now reflected in the net tracking.
sb, _ := netsTracker.GetOrCreate(constants.PrimaryNetworkID)
sb.AddChain(xChainID)
sb.Bootstrapped(xChainID)
}
return m
}
@@ -278,11 +294,14 @@ func TestAuthorizeChainActivation(t *testing.T) {
})
t.Run("gated chain, X-Chain tracked but VM lacks reader, opts out", func(t *testing.T) {
// X-Chain is in m.chains (IsBootstrapped true) but its VM does not
// satisfy xChainUTXOReader. The gate must fail closed (ready, !authz),
// not panic.
// X-Chain is bootstrapped (in m.chains AND marked bootstrapped in its net, so
// IsBootstrapped true) but its VM does not satisfy xChainUTXOReader. The gate must
// fail closed (ready, !authz), not panic.
m := newGateManager(xChainID, addr, collection, nil, nil)
m.chains[xChainID] = &chainInfo{Name: "X-Chain", VM: struct{}{}}
sb, _ := m.Nets.GetOrCreate(constants.PrimaryNetworkID)
sb.AddChain(xChainID)
sb.Bootstrapped(xChainID)
authorized, ready := m.authorizeChainActivation(gatedChain)
require.True(t, ready)
require.False(t, authorized)
+63
View File
@@ -177,6 +177,69 @@ func TestIsBootstrapped(t *testing.T) {
require.False(m.IsBootstrapped(chainID))
}
// TestIsBootstrappedTracksRealConvergence is the regression guard for the
// premature-true masking bug: manager.IsBootstrapped must report true ONLY once the
// chain has ACTUALLY finished initial sync (its net marked it Bootstrapped), NOT the
// instant it is merely tracked (added to m.chains with its sync goroutine launched).
// Before the fix, a C-Chain stalled at genesis (head 0x0) reported
// info.isBootstrapped(C)=true, masking the stall from any readiness gate.
func TestIsBootstrappedTracksRealConvergence(t *testing.T) {
require := require.New(t)
chainConfigs := map[ids.ID]nets.Config{
constants.PrimaryNetworkID: {},
}
netsTracker, err := NewNets(ids.GenerateTestNodeID(), chainConfigs)
require.NoError(err)
config := &ManagerConfig{
Log: log.NewNoOpLogger(),
Metrics: metric.NewMultiGatherer(),
VMManager: vms.NewManager(),
ChainDataDir: t.TempDir(),
Nets: netsTracker,
}
m, err := New(config)
require.NoError(err)
mImpl := m.(*manager)
// A native chain validated by the primary network — the C-Chain shape.
chainID := ids.GenerateTestID()
// Simulate createChain's tracking: the chain EXISTS in m.chains and is registered
// as bootstrapping in its validation net — but has NOT converged (initial sync is
// still driving, e.g. stalled at genesis fetching ancestry).
mImpl.chainsLock.Lock()
mImpl.chains[chainID] = &chainInfo{Name: "C-Chain"}
mImpl.chainsLock.Unlock()
sb, _ := netsTracker.GetOrCreate(constants.PrimaryNetworkID)
require.True(sb.AddChain(chainID))
// THE FIX: exists-but-not-converged must be FALSE (was true — the masking bug).
require.False(m.IsBootstrapped(chainID),
"a tracked-but-still-syncing chain must not report bootstrapped")
for _, ci := range m.(*manager).GetChains() {
if ci.ID == chainID {
require.False(ci.Bootstrapped, "GetChains must not report a syncing chain bootstrapped")
}
}
// Initial sync reaches the frontier → monitorBootstrap calls sb.Bootstrapped.
sb.Bootstrapped(chainID)
// Now — and only now — it reports bootstrapped (head advanced to frontier, VM live).
require.True(m.IsBootstrapped(chainID),
"a converged chain must report bootstrapped")
found := false
for _, ci := range m.(*manager).GetChains() {
if ci.ID == chainID {
found = true
require.True(ci.Bootstrapped, "GetChains must report a converged chain bootstrapped")
}
}
require.True(found)
}
// TestToEngineChannelFlow verifies the toEngine channel notification flow
// This tests the goroutine that reads from toEngine and triggers block building
func TestToEngineChannelFlow(t *testing.T) {
+6
View File
@@ -365,6 +365,12 @@ func (vm *pChainHeightVM) LastAccepted(ctx context.Context) (ids.ID, error) {
return vm.inner.LastAccepted(ctx)
}
// NOTE: this wrapper deliberately does NOT forward GetBlockIDAtHeight. The bootstrap acceptance
// oracle's fork-sibling check reads the IN-PROCESS consensus finalized ledger
// (blockHandler.finalizedBlockAtHeight → engine.FinalizedBlockAtHeight), NOT a VM height index —
// because the VM index is dead over ZAP (the zap server has no MsgGetBlockIDAtHeight handler, so
// the real C-Chain returns nothing). A forwarder here would only re-expose that dead path.
// SetPreference delegates to the inner VM.
func (vm *pChainHeightVM) SetPreference(ctx context.Context, id ids.ID) error {
return vm.inner.SetPreference(ctx, id)
+130
View File
@@ -0,0 +1,130 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// proposervm_wrap_test.go — pins the single policy gate that decides whether a
// linear chain.ChainVM is re-wrapped in proposervm for single-proposer-per-height
// block production (the consensus-safety fix for the equivocation crash). The
// gate is a pure function so the policy is verifiable without standing up a chain.
package chains
import (
"testing"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
)
func TestShouldWrapInProposerVM(t *testing.T) {
// A native chain ID that is NOT the P-Chain (e.g. the C-Chain): first 31
// bytes zero, last byte the chain letter. Any non-platform ID exercises the
// chainID condition; this mirrors how native chain IDs are shaped.
cChainID := ids.ID{}
cChainID[ids.IDLen-1] = 'C'
xChainID := ids.ID{}
xChainID[ids.IDLen-1] = 'X'
tests := []struct {
name string
k int
chainID ids.ID
innerIsDAGNative bool
want bool
why string
}{
{
name: "C-Chain devnet K=4",
k: 4, // LocalBFTParams
chainID: cChainID,
innerIsDAGNative: false,
want: true,
why: "multi-validator EVM, not the P-Chain, not DAG — the chain that crashed; must be wrapped",
},
{
name: "C-Chain mainnet K=21",
k: 21, // MainnetParams
chainID: cChainID,
innerIsDAGNative: false,
want: true,
why: "large multi-validator EVM is wrapped exactly as avalanchego wraps it",
},
{
name: "P-Chain is excluded even at K>1",
k: 4,
chainID: constants.PlatformChainID,
innerIsDAGNative: false,
want: false,
why: "P-Chain validator state is published mid-create; its windower would be empty — keep newPChainHeightVM",
},
{
name: "X-Chain (DAG-native) is excluded",
k: 4,
chainID: xChainID,
innerIsDAGNative: true,
want: false,
why: "linearized DAG VM uses a push-notification bridge that does not compose with proposervm's window",
},
{
name: "single-node K=1 is not wrapped",
k: 1, // SingleValidatorParams
chainID: cChainID,
innerIsDAGNative: false,
want: false,
why: "one validator is trivially the sole proposer; no equivocation to prevent",
},
{
name: "K=1 P-Chain is not wrapped",
k: 1,
chainID: constants.PlatformChainID,
innerIsDAGNative: false,
want: false,
why: "K==1 short-circuits regardless of chain",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := shouldWrapInProposerVM(tt.k, tt.chainID, tt.innerIsDAGNative)
if got != tt.want {
t.Fatalf("shouldWrapInProposerVM(k=%d, chainID=%s, dag=%v) = %v, want %v — %s",
tt.k, tt.chainID, tt.innerIsDAGNative, got, tt.want, tt.why)
}
})
}
}
// TestShouldWrapInProposerVM_FlowsFromSelectedParams proves the K the gate reads
// is the one selectConsensusParams produces per network, so the wrap decision is
// consistent with the BFT committee actually chosen: every sybil-protected
// network yields K>1 (C-Chain wrapped), and single-node yields K==1 (not wrapped).
func TestShouldWrapInProposerVM_FlowsFromSelectedParams(t *testing.T) {
cChainID := ids.ID{}
cChainID[ids.IDLen-1] = 'C'
cases := []struct {
name string
sybilProtection bool
networkID uint32
wantWrapCChain bool
}{
{"single-node dev", false, constants.LocalID, false},
{"devnet sybil", true, constants.DevnetID, true},
{"localnet sybil", true, constants.LocalID, true},
{"mainnet", true, constants.MainnetID, true},
{"testnet", true, constants.TestnetID, true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
params := selectConsensusParams(c.sybilProtection, c.networkID)
got := shouldWrapInProposerVM(params.K, cChainID, false)
if got != c.wantWrapCChain {
t.Fatalf("network %s (sybil=%v): K=%d → wrap=%v, want %v",
c.name, c.sybilProtection, params.K, got, c.wantWrapCChain)
}
// The P-Chain is never wrapped, whatever the committee.
if shouldWrapInProposerVM(params.K, constants.PlatformChainID, false) {
t.Fatalf("network %s: P-Chain must never be wrapped (K=%d)", c.name, params.K)
}
})
}
}
+40
View File
@@ -87,6 +87,32 @@ func selectConsensusParams(sybilProtection bool, networkID uint32) consensusconf
}
}
// shouldWrapInProposerVM decides whether a linear chain.ChainVM is wrapped in
// proposervm to enforce single-proposer-per-height block production (the
// proposer window). It is the SINGLE policy gate (the manager calls it once);
// keeping it a pure function makes the policy unit-testable without standing up
// a whole chain. All three conditions must hold:
//
// - k > 1: a multi-validator quorum. K==1 (single-node --dev) has exactly one
// proposer already, so there is no equivocation to prevent and no schedule
// to compute (proposervm would only add a wrapper with no safety value).
// - chainID is NOT the P-Chain: the P-Chain publishes its OWN height-indexed
// validators.State DURING its createChain, AFTER the chainRuntime snapshot
// proposervm's windower reads — so its windower would see an empty set and
// fall back to anyone-can-propose with a P-chain-height-0 stamp. The P-Chain
// keeps the existing newPChainHeightVM path (which DOES get the live state).
// - inner is NOT DAG-native (no Linearize): a linearized DAG VM (X-Chain) is
// driven by a push-notification bridge that does not compose with
// proposervm's pull/window model without avalanchego's initializeOnLinearizeVM
// machinery. It keeps the existing path.
//
// The C-Chain and sovereign-L1 EVM chains satisfy all three (multi-validator,
// not the P-Chain, not DAG) — they are exactly the chains that exhibited the
// equivocation crash, and exactly the chains avalanchego wraps in proposervm.
func shouldWrapInProposerVM(k int, chainID ids.ID, innerIsDAGNative bool) bool {
return k > 1 && chainID != constants.PlatformChainID && !innerIsDAGNative
}
// --- BLS vote verifier -------------------------------------------------------
// blsVoteVerifier verifies a validator's BLS signature over the canonical vote
@@ -241,6 +267,16 @@ func (s *validatorStakeSource) TotalStake(height uint64) uint64 {
return total
}
// ValidatorCount implements consensuschain.StakeSource. The number of DISTINCT
// validators in the set IN FORCE AT height — the round-scoped view-change's BFT
// committee size (it sizes its POL/precommit quorum to bftAlpha over this count,
// NOT the oversized sample K). Read from the SAME height-indexed set as
// Weight/TotalStake so every node computes the identical committee and the
// count-quorum matches the ⅔-by-stake set exactly.
func (s *validatorStakeSource) ValidatorCount(height uint64) int {
return len(validatorSetAtHeight(s.state, s.networkID, height))
}
var _ consensuschain.StakeSource = (*validatorStakeSource)(nil)
// --- validator-set-root source (MEDIUM: epoch binding) -----------------------
@@ -338,11 +374,15 @@ func hashValidatorSet(set map[ids.NodeID]*validators.GetValidatorOutput) ids.ID
//
// kind 1 = signed vote (payload = engine encodeSignedVote: nodeID+sig)
// kind 2 = finality cert (payload = engine cert MarshalBinary)
// (round-scoped view-change prevotes are engine-INTERNAL since consensus v1.36 —
// the node no longer frames or routes a prevote kind)
var quorumGossipMagic = [4]byte{'L', 'X', 'Q', 0x01}
const (
quorumKindVote byte = 1
quorumKindCert byte = 2
// kind 3 (prevote) was DELETED with the v1.36 view-change rip-out (174af3c31); Nova sampling
// decides and the ⅔ Quasar attestation rides quorumKindVote. Do not reuse 3 — keep the braid dead.
)
// ErrNotQuorumGossip signals a payload is not a quorum envelope (so the caller
+102
View File
@@ -0,0 +1,102 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// red_pendingcontext_dos_test.go — regression guard for the catch-up DoS RED found
// on the cert-carrying catch-up branch.
//
// The frontier-sync wiring connects the AcceptedFrontier handler to
// requestContext(), which records each requested blockID in b.pendingContext.
// Originally NOTHING evicted from that map, so a Byzantine peer streaming
// AcceptedFrontier frames each naming a distinct random tip grew it without bound
// → OOM (and a peer that took a request then withheld Context re-stranded the
// victim forever). requestContext now reaps entries past pendingContextTTL and
// hard-caps the map at maxPendingContext. These tests pin both properties; before
// the fix the first asserted N=50_000 entries with ZERO eviction.
package chains
import (
"context"
"testing"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/math/set"
"github.com/luxfi/node/message"
"github.com/luxfi/node/network"
"github.com/luxfi/node/proto/p2p"
)
// redStubNet implements the one Network method requestContext uses (Send); every
// other method is inherited from the embedded nil interface and is never called.
type redStubNet struct {
network.Network
sends int
}
func (s *redStubNet) Send(_ message.OutboundMessage, nodeIDs set.Set[ids.NodeID], _ ids.ID, _ uint32) set.Set[ids.NodeID] {
s.sends++
return nodeIDs
}
// redStubMsg implements the one OutboundMsgBuilder method requestContext uses.
type redStubMsg struct {
message.OutboundMsgBuilder
}
func (redStubMsg) GetAncestors(_ ids.ID, _ uint32, _ time.Duration, _ ids.ID, _ p2p.EngineType) (message.OutboundMessage, error) {
return nil, nil
}
func newRedTestHandler(net network.Network) *blockHandler {
return &blockHandler{
logger: log.NewNoOpLogger(),
net: net,
msgCreator: redStubMsg{},
chainID: ids.GenerateTestID(),
pendingContext: make(map[ids.ID]contextRequest),
}
}
// TestPendingContext_BoundedUnderFlood: a peer streaming distinct fake tips into
// requestContext can NEVER grow pendingContext past maxPendingContext. Inverts the
// original RED PoC, which asserted unbounded growth to 50_000 → OOM.
func TestPendingContext_BoundedUnderFlood(t *testing.T) {
stubNet := &redStubNet{}
bh := newRedTestHandler(stubNet)
const N = 10_000 // ≫ the maxPendingContext cap — enough to prove "stays bounded"
from := ids.GenerateTestNodeID()
for i := 0; i < N; i++ {
bh.requestContext(context.Background(), from, ids.GenerateTestID())
}
if got := len(bh.pendingContext); got > maxPendingContext {
t.Fatalf("pendingContext unbounded: %d entries exceeds cap %d (the RED HIGH DoS)", got, maxPendingContext)
}
t.Logf("bounded: %d entries after a %d-distinct-tip flood (cap %d, sends=%d)",
len(bh.pendingContext), N, maxPendingContext, stubNet.sends)
}
// TestPendingContext_StaleEntriesReaped: a request whose Context is withheld past
// its TTL is reaped on the next requestContext, so the block is re-requestable from
// an honest peer (fixes the RED MEDIUM re-strand).
func TestPendingContext_StaleEntriesReaped(t *testing.T) {
bh := newRedTestHandler(&redStubNet{})
from := ids.GenerateTestNodeID()
stale := ids.GenerateTestID()
bh.pendingContext[stale] = contextRequest{
nodeID: from,
requestID: 1,
blockID: stale,
timestamp: time.Now().Add(-2 * pendingContextTTL),
}
// Any later request runs the reaper before recording its own entry.
bh.requestContext(context.Background(), from, ids.GenerateTestID())
if _, stillThere := bh.pendingContext[stale]; stillThere {
t.Fatalf("stale pendingContext entry (%v old) not reaped → re-strand persists", 2*pendingContextTTL)
}
}
-244
View File
@@ -1,244 +0,0 @@
# Robust RPC Handler Registration System
## Overview
This package provides a bulletproof RPC handler registration system for the Lux node, designed to handle the complexities of local development where nodes are frequently restarted. It replaces the fragile inline registration logic with a robust, maintainable solution.
## Key Features
### 🔄 Automatic Retry Logic
- Exponential backoff for transient failures
- Configurable retry count and wait times
- Context-aware cancellation support
### ✅ Built-in Health Checks
- Automatic validation after registration
- Batch health checking for all chains
- Detailed diagnostics for failures
### 🎯 Single Source of Truth
- Centralized route construction logic
- Consistent path formatting
- No duplicate code or magic strings
### 🛡️ Defensive Programming
- Nil checks on all inputs
- Handler validation before registration
- Graceful degradation on failures
### 📊 Developer-Friendly Debugging
- Clear, actionable error messages
- Comprehensive logging at appropriate levels
- Built-in diagnostic tools
## Architecture
```
┌─────────────────────┐
│ Chain Manager │
└──────────┬──────────┘
│ Creates Chain
┌─────────────────────┐
│ ChainHandlerRegistrar│
└──────────┬──────────┘
│ Extracts Handlers
┌─────────────────────┐
│ Handler Manager │
└──────────┬──────────┘
│ Registers with Retries
┌─────────────────────┐
│ API Server │
└─────────────────────┘
```
## Usage
### Basic Integration
Replace the handler registration code in `chains/manager.go` (lines 941-990) with:
```go
// Create robust registrar
registrar := rpc.NewChainHandlerRegistrar(
m.Server,
m.Log,
m.CChainID,
m.PChainID,
)
// Register handlers
if err := registrar.RegisterChainHandlers(ctx, chainParams.ID, chain.VM); err != nil {
m.Log.Error("Failed to register handlers", log.Err(err))
// Decide if this should be fatal or not
}
```
### Configuration
```go
// Development environment - fail fast
registrar.SetRetryConfig(2, 50*time.Millisecond)
// Production environment - more robust
registrar.SetRetryConfig(5, 200*time.Millisecond)
```
### Debugging
```go
// Get route information
info, exists := registrar.GetRouteInfo(chainID)
if exists {
fmt.Printf("Chain %s routes: %v\n", chainID, info.Endpoints)
}
// Run health checks
results := registrar.HealthCheckAll()
for chainID, healthy := range results {
fmt.Printf("Chain %s: %v\n", chainID, healthy)
}
// Validate specific endpoint
err := registrar.ValidateEndpoint(chainID, "/rpc")
```
### Using the Debug Tool
```go
// Quick diagnosis from CLI
rpc.QuickDiagnose("localhost:9650", chainID, "C")
// Programmatic diagnosis
tool := rpc.NewDebugTool("localhost:9650", logger)
report := tool.DiagnoseEndpoint(chainID, "C")
fmt.Println(report.String())
```
## Components
### HandlerManager (`handler_manager.go`)
Core registration logic with retry mechanism and health checks.
**Key Methods:**
- `RegisterChainHandlers()` - Main registration entry point
- `HealthCheckRoute()` - Validates handler responsiveness
- `GetRouteInfo()` - Retrieves registration details
### ChainHandlerRegistrar (`chain_integration.go`)
Bridge between chain manager and handler manager.
**Key Methods:**
- `RegisterChainHandlers()` - Extracts and registers handlers
- `ValidateEndpoint()` - Tests specific endpoints
- `GetAllRoutes()` - Returns all registered routes
### DebugTool (`debug_tool.go`)
Comprehensive endpoint diagnostics for developers.
**Key Methods:**
- `DiagnoseEndpoint()` - Full endpoint analysis
- `QuickDiagnose()` - CLI-friendly diagnosis
## Error Handling
The system uses clear, actionable errors:
```go
errNilHandler = errors.New("handler is nil")
errNilServer = errors.New("server is nil")
errEmptyEndpoint = errors.New("endpoint is empty")
errRegistrationFailed = errors.New("handler registration failed")
errHealthCheckFailed = errors.New("health check failed")
```
Each error includes context about what failed and why.
## Testing
Comprehensive test coverage including:
- Successful registration scenarios
- Validation failure cases
- Retry logic verification
- Health check validation
- Context cancellation
- Performance benchmarks
Run tests:
```bash
go test ./chains/rpc/... -v
```
## Common Issues and Solutions
### Issue: Handlers not accessible after registration
**Solution:** Check health status with `HealthCheckAll()` and review debug output.
### Issue: Registration fails with "already exists"
**Solution:** The retry logic handles this. If persistent, check for duplicate registration attempts.
### Issue: Slow registration during development
**Solution:** Reduce retry count and wait time using `SetRetryConfig()`.
### Issue: Can't find the correct endpoint URL
**Solution:** Use `DebugTool.DiagnoseEndpoint()` to test all URL patterns.
## Migration Guide
1. **Update imports:**
```go
import "github.com/luxfi/node/chains/rpc"
```
2. **Replace inline registration (lines 941-990 in manager.go):**
```go
// Old code: complex type checking and manual registration
// New code: single function call
registrar := rpc.NewChainHandlerRegistrar(...)
registrar.RegisterChainHandlers(...)
```
3. **Add health monitoring (optional):**
```go
go func() {
time.Sleep(5 * time.Second)
registrar.HealthCheckAll()
}()
```
4. **Add debugging endpoints (optional):**
```go
http.HandleFunc("/debug/handlers", func(w http.ResponseWriter, r *http.Request) {
routes := registrar.GetAllRoutes()
json.NewEncoder(w).Encode(routes)
})
```
## Performance
- Registration: ~1ms per handler (without retries)
- Health check: ~10ms per chain
- Memory overhead: ~1KB per registered chain
- No goroutine leaks or resource issues
## Future Improvements
Potential enhancements:
- Metrics integration for registration success/failure rates
- Automatic re-registration on failure
- WebSocket-specific health checks
- gRPC handler support
- Handler versioning for upgrades
## Philosophy
This implementation follows core Go principles:
- **Explicit over implicit** - Clear registration flow
- **Errors are values** - Proper error handling throughout
- **Simple over clever** - Straightforward retry logic
- **Composition over inheritance** - Small, focused components
- **Documentation is code** - Self-documenting with clear names
The system is designed to be bulletproof for development while remaining simple to understand and maintain.
-168
View File
@@ -1,168 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"context"
"fmt"
"net/http"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/server/http"
"github.com/luxfi/node/vms"
)
// ChainHandlerRegistrar provides a clean interface for chain manager to register handlers.
// This replaces the inline registration logic with a more robust, testable solution.
type ChainHandlerRegistrar struct {
manager *HandlerManager
server server.Server
log log.Logger
cChainID ids.ID // Special handling for C-Chain
pChainID ids.ID // Platform chain ID for validation
}
// NewChainHandlerRegistrar creates a registrar for chain handler registration.
// Encapsulates all the registration logic in one place.
func NewChainHandlerRegistrar(
server server.Server,
logger log.Logger,
cChainID ids.ID,
pChainID ids.ID,
) *ChainHandlerRegistrar {
return &ChainHandlerRegistrar{
manager: NewHandlerManager(server, logger),
server: server,
log: logger,
cChainID: cChainID,
pChainID: pChainID,
}
}
// RegisterChainHandlers is the main entry point from chain manager.
// Handles all the complexity of VM type checking and handler extraction.
func (r *ChainHandlerRegistrar) RegisterChainHandlers(
ctx context.Context,
chainID ids.ID,
vm interface{},
) error {
r.log.Info("Attempting to register chain handlers",
log.Stringer("chainID", chainID),
log.String("vmType", fmt.Sprintf("%T", vm)))
// Don't register handlers for Platform VM
if chainID == r.pChainID {
r.log.Debug("Skipping handler registration for Platform VM")
return nil
}
// Extract handlers from VM
handlers, err := r.extractHandlers(ctx, vm)
if err != nil {
return fmt.Errorf("failed to extract handlers: %w", err)
}
if len(handlers) == 0 {
r.log.Info("VM does not provide any handlers",
log.Stringer("chainID", chainID))
return nil
}
// Determine chain alias (special case for C-Chain)
alias := r.getChainAlias(chainID)
// Register with robust handler manager
return r.manager.RegisterChainHandlers(ctx, chainID, alias, handlers)
}
// extractHandlers attempts to get handlers from the VM using multiple strategies.
// Handles different VM wrapper types gracefully.
func (r *ChainHandlerRegistrar) extractHandlers(
ctx context.Context,
vm interface{},
) (map[string]http.Handler, error) {
// First try direct interface check
if provider, ok := vm.(vms.HandlerProvider); ok {
r.log.Debug("VM directly implements HandlerProvider")
return provider.CreateHandlers(ctx)
}
// Try using the delegate helper (handles wrapped VMs)
handlers, err := vms.DelegateHandlers(ctx, vm)
if err != nil {
return nil, fmt.Errorf("handler delegation failed: %w", err)
}
if len(handlers) > 0 {
r.log.Debug("Successfully extracted handlers via delegation",
log.Int("count", len(handlers)))
}
return handlers, nil
}
// getChainAlias returns the appropriate alias for a chain.
// C-Chain gets special treatment, others use their ID.
func (r *ChainHandlerRegistrar) getChainAlias(chainID ids.ID) string {
if chainID == r.cChainID {
return "C"
}
// Could extend this for X-Chain and P-Chain if needed
return ""
}
// GetRouteInfo returns information about a specific chain's registered routes.
// Useful for debugging and operational visibility.
func (r *ChainHandlerRegistrar) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool) {
return r.manager.GetRouteInfo(chainID)
}
// GetAllRoutes returns all registered routes across all chains.
// Complete visibility for monitoring and debugging.
func (r *ChainHandlerRegistrar) GetAllRoutes() map[string]*RouteInfo {
return r.manager.GetAllRoutes()
}
// HealthCheckAll performs health checks on all registered routes.
// Returns a map of chainID -> healthy status.
func (r *ChainHandlerRegistrar) HealthCheckAll() map[string]bool {
return r.manager.HealthCheckAll()
}
// SetRetryConfig allows tuning of retry behavior for different environments.
// Production might want more retries, dev might want faster failures.
func (r *ChainHandlerRegistrar) SetRetryConfig(maxRetries int, initialWait time.Duration) {
r.manager.SetRetryConfig(maxRetries, initialWait)
}
// ValidateEndpoint performs a test request against a specific endpoint.
// Useful for debugging specific handler issues.
func (r *ChainHandlerRegistrar) ValidateEndpoint(
chainID ids.ID,
endpoint string,
) error {
info, exists := r.manager.GetRouteInfo(chainID)
if !exists {
return fmt.Errorf("no routes registered for chain %s", chainID)
}
// Build the full URL
fullURL := fmt.Sprintf("/ext/%s%s", info.Base, endpoint)
r.log.Info("Validating endpoint",
log.Stringer("chainID", chainID),
log.String("url", fullURL))
// Validates endpoint registration
for _, registered := range info.Endpoints {
if registered == endpoint {
return nil
}
}
return fmt.Errorf("endpoint %s not found in registered endpoints: %v",
endpoint, info.Endpoints)
}
-302
View File
@@ -1,302 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"bytes"
"github.com/go-json-experiment/json"
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
)
// DebugTool provides utilities for debugging RPC handler issues.
// Developer-friendly diagnostics with clear, actionable output.
type DebugTool struct {
baseURL string
client *http.Client
log log.Logger
}
// NewDebugTool creates a debug tool for RPC endpoint testing.
func NewDebugTool(baseURL string, logger log.Logger) *DebugTool {
if !strings.HasPrefix(baseURL, "http") {
baseURL = "http://" + baseURL
}
return &DebugTool{
baseURL: strings.TrimSuffix(baseURL, "/"),
client: &http.Client{
Timeout: 10 * time.Second,
},
log: logger,
}
}
// DiagnoseEndpoint performs comprehensive diagnostics on an RPC endpoint.
// Returns detailed information about what's working and what's not.
func (d *DebugTool) DiagnoseEndpoint(chainID ids.ID, alias string) *DiagnosticReport {
report := &DiagnosticReport{
ChainID: chainID,
Alias: alias,
Timestamp: time.Now(),
Tests: make([]TestResult, 0),
}
// Test different URL patterns
urlPatterns := d.getURLPatterns(chainID, alias)
for _, pattern := range urlPatterns {
result := d.testEndpoint(pattern)
report.Tests = append(report.Tests, result)
}
// Test common RPC methods
if bestURL := report.GetBestURL(); bestURL != "" {
report.RPCTests = d.testRPCMethods(bestURL)
}
return report
}
// getURLPatterns returns all possible URL patterns to test.
func (d *DebugTool) getURLPatterns(chainID ids.ID, alias string) []string {
patterns := []string{
fmt.Sprintf("%s/ext/bc/%s/rpc", d.baseURL, chainID.String()),
fmt.Sprintf("%s/ext/bc/%s/ws", d.baseURL, chainID.String()),
fmt.Sprintf("%s/ext/bc/%s", d.baseURL, chainID.String()),
}
if alias != "" && alias != chainID.String() {
patterns = append(patterns,
fmt.Sprintf("%s/ext/bc/%s/rpc", d.baseURL, alias),
fmt.Sprintf("%s/ext/bc/%s/ws", d.baseURL, alias),
fmt.Sprintf("%s/ext/bc/%s", d.baseURL, alias),
)
}
// Also test without /ext prefix (some setups might differ)
patterns = append(patterns,
fmt.Sprintf("%s/bc/%s/rpc", d.baseURL, chainID.String()),
)
return patterns
}
// testEndpoint tests a single endpoint URL.
func (d *DebugTool) testEndpoint(url string) TestResult {
result := TestResult{
URL: url,
Timestamp: time.Now(),
}
// First try a simple GET
resp, err := d.client.Get(url)
if err != nil {
result.Error = fmt.Sprintf("GET failed: %v", err)
result.Success = false
return result
}
defer resp.Body.Close()
result.StatusCode = resp.StatusCode
// Read body for debugging
bodyBytes, _ := io.ReadAll(resp.Body)
result.Response = string(bodyBytes)
// Now try a POST with JSON-RPC
rpcReq := map[string]interface{}{
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []interface{}{},
"id": 1,
}
jsonBytes, _ := json.Marshal(rpcReq)
postResp, err := d.client.Post(url, "application/json", bytes.NewReader(jsonBytes))
if err != nil {
result.Error = fmt.Sprintf("POST failed: %v", err)
result.Success = false
return result
}
defer postResp.Body.Close()
result.StatusCode = postResp.StatusCode
// Check if we got a valid JSON-RPC response
var rpcResp map[string]interface{}
if err := json.UnmarshalRead(postResp.Body, &rpcResp); err == nil {
if _, hasResult := rpcResp["result"]; hasResult {
result.Success = true
result.Response = fmt.Sprintf("Valid JSON-RPC response: %v", rpcResp["result"])
} else if errObj, hasError := rpcResp["error"]; hasError {
result.Success = false
result.Response = fmt.Sprintf("JSON-RPC error: %v", errObj)
}
}
return result
}
// testRPCMethods tests common RPC methods against an endpoint.
func (d *DebugTool) testRPCMethods(url string) []RPCTest {
methods := []string{
"web3_clientVersion",
"eth_blockNumber",
"eth_chainId",
"net_version",
"eth_syncing",
}
tests := make([]RPCTest, 0, len(methods))
for _, method := range methods {
test := RPCTest{
Method: method,
URL: url,
}
req := map[string]interface{}{
"jsonrpc": "2.0",
"method": method,
"params": []interface{}{},
"id": 1,
}
jsonBytes, _ := json.Marshal(req)
resp, err := d.client.Post(url, "application/json", bytes.NewReader(jsonBytes))
if err != nil {
test.Error = err.Error()
test.Success = false
} else {
defer resp.Body.Close()
var result map[string]interface{}
if err := json.UnmarshalRead(resp.Body, &result); err == nil {
if res, ok := result["result"]; ok {
test.Success = true
test.Result = fmt.Sprintf("%v", res)
} else if errObj, ok := result["error"]; ok {
test.Error = fmt.Sprintf("%v", errObj)
}
}
}
tests = append(tests, test)
}
return tests
}
// DiagnosticReport contains comprehensive endpoint diagnostic information.
type DiagnosticReport struct {
ChainID ids.ID
Alias string
Timestamp time.Time
Tests []TestResult
RPCTests []RPCTest
}
// TestResult represents a single endpoint test result.
type TestResult struct {
URL string
Success bool
StatusCode int
Response string
Error string
Timestamp time.Time
}
// RPCTest represents a test of a specific RPC method.
type RPCTest struct {
Method string
URL string
Success bool
Result string
Error string
}
// GetBestURL returns the first working URL from the tests.
func (r *DiagnosticReport) GetBestURL() string {
for _, test := range r.Tests {
if test.Success {
return test.URL
}
}
return ""
}
// String returns a human-readable report.
func (r *DiagnosticReport) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("=== RPC Endpoint Diagnostic Report ===\n"))
b.WriteString(fmt.Sprintf("Chain ID: %s\n", r.ChainID))
if r.Alias != "" {
b.WriteString(fmt.Sprintf("Alias: %s\n", r.Alias))
}
b.WriteString(fmt.Sprintf("Timestamp: %s\n\n", r.Timestamp.Format(time.RFC3339)))
b.WriteString("=== Endpoint Tests ===\n")
for _, test := range r.Tests {
status := "❌ FAILED"
if test.Success {
status = "✅ SUCCESS"
}
b.WriteString(fmt.Sprintf("\n%s %s\n", status, test.URL))
b.WriteString(fmt.Sprintf(" Status Code: %d\n", test.StatusCode))
if test.Error != "" {
b.WriteString(fmt.Sprintf(" Error: %s\n", test.Error))
}
if test.Response != "" && len(test.Response) < 200 {
b.WriteString(fmt.Sprintf(" Response: %s\n", test.Response))
}
}
if len(r.RPCTests) > 0 {
b.WriteString("\n=== RPC Method Tests ===\n")
for _, test := range r.RPCTests {
status := "❌"
if test.Success {
status = "✅"
}
b.WriteString(fmt.Sprintf("%s %s: ", status, test.Method))
if test.Success {
b.WriteString(test.Result)
} else {
b.WriteString(test.Error)
}
b.WriteString("\n")
}
}
b.WriteString("\n=== Recommendations ===\n")
if bestURL := r.GetBestURL(); bestURL != "" {
b.WriteString(fmt.Sprintf("✅ Use this endpoint: %s\n", bestURL))
} else {
b.WriteString("❌ No working endpoints found. Check:\n")
b.WriteString(" 1. Is the node running?\n")
b.WriteString(" 2. Is the chain bootstrapped?\n")
b.WriteString(" 3. Are handlers properly registered?\n")
b.WriteString(" 4. Check node logs for handler registration errors\n")
b.WriteString(" 5. Try restarting the node\n")
}
return b.String()
}
// QuickDiagnose performs a quick endpoint check and prints results.
// Convenience function for CLI tools.
func QuickDiagnose(nodeURL string, chainID ids.ID, alias string) {
logger := log.NewNoOpLogger()
tool := NewDebugTool(nodeURL, logger)
report := tool.DiagnoseEndpoint(chainID, alias)
fmt.Println(report.String())
}
-324
View File
@@ -1,324 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package rpc provides robust RPC handler registration with retries, health checks, and clear debugging.
// Follows Go principles: fail fast with clear errors, single responsibility, minimal dependencies.
package rpc
import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"sync"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/server/http"
)
var (
// Errors follow Go convention: lowercase, descriptive, actionable
errNilHandler = errors.New("handler is nil")
errNilServer = errors.New("server is nil")
errEmptyEndpoint = errors.New("endpoint is empty")
errRegistrationFailed = errors.New("handler registration failed")
errHealthCheckFailed = errors.New("health check failed")
)
// HandlerManager manages RPC handler registration with robust error handling and health checks.
// Single responsibility: reliable handler registration with observability.
type HandlerManager struct {
server server.Server
log log.Logger
mu sync.RWMutex
routes map[string]*RouteInfo // chainID -> route info
retries int // max registration retries
retryWait time.Duration // initial retry wait time
}
// RouteInfo contains complete information about a registered route.
// Everything needed for debugging in one place.
type RouteInfo struct {
ChainID ids.ID
ChainAlias string
Base string // e.g., "bc/C" or "bc/<chainID>"
Endpoints []string // e.g., ["/rpc", "/ws"]
Handler http.Handler
Healthy bool
LastCheck time.Time
}
// NewHandlerManager creates a handler manager with sensible defaults.
// Simple factory, no magic.
func NewHandlerManager(server server.Server, logger log.Logger) *HandlerManager {
return &HandlerManager{
server: server,
log: logger,
routes: make(map[string]*RouteInfo),
retries: 3,
retryWait: 100 * time.Millisecond,
}
}
// RegisterChainHandlers registers all handlers for a chain with retry logic and health checks.
// This is the main entry point - handles everything needed for robust registration.
func (m *HandlerManager) RegisterChainHandlers(
ctx context.Context,
chainID ids.ID,
chainAlias string,
handlers map[string]http.Handler,
) error {
if m.server == nil {
return errNilServer
}
m.log.Info("Starting chain handler registration",
log.Stringer("chainID", chainID),
log.String("alias", chainAlias),
log.Int("handlerCount", len(handlers)))
// Validate handlers first - fail fast
if err := m.validateHandlers(handlers); err != nil {
return fmt.Errorf("handler validation failed: %w", err)
}
// Build route info
info := &RouteInfo{
ChainID: chainID,
ChainAlias: chainAlias,
Endpoints: make([]string, 0, len(handlers)),
}
// Determine base paths
bases := m.getBasePaths(chainID, chainAlias)
// Register each handler with retries
var registrationErrors []error
for endpoint, handler := range handlers {
info.Endpoints = append(info.Endpoints, endpoint)
for _, base := range bases {
if err := m.registerWithRetry(ctx, base, endpoint, handler); err != nil {
registrationErrors = append(registrationErrors,
fmt.Errorf("failed to register %s%s: %w", base, endpoint, err))
m.log.Error("Handler registration failed",
log.String("base", base),
log.String("endpoint", endpoint),
log.Err(err))
} else {
m.log.Info("Handler registered successfully",
log.String("route", fmt.Sprintf("/ext/%s%s", base, endpoint)),
log.Stringer("chainID", chainID))
}
}
}
// Store route info for monitoring
m.mu.Lock()
info.Base = bases[0] // Primary base
info.Handler = handlers["/rpc"] // Store primary handler for health checks
m.routes[chainID.String()] = info
m.mu.Unlock()
// Run health checks
if err := m.healthCheckRoute(info); err != nil {
m.log.Warn("Health check failed for newly registered chain",
log.Stringer("chainID", chainID),
log.Err(err))
}
// Return aggregate error if any registrations failed
if len(registrationErrors) > 0 {
return fmt.Errorf("%w: %v", errRegistrationFailed, registrationErrors)
}
m.log.Info("Chain handler registration completed",
log.Stringer("chainID", chainID),
log.String("routes", strings.Join(m.getFullRoutes(bases, info.Endpoints), ", ")))
return nil
}
// validateHandlers ensures all handlers are valid before attempting registration.
// Fail fast with clear errors - no silent failures.
func (m *HandlerManager) validateHandlers(handlers map[string]http.Handler) error {
if len(handlers) == 0 {
return errors.New("no handlers provided")
}
for endpoint, handler := range handlers {
if handler == nil {
return fmt.Errorf("%w for endpoint %s", errNilHandler, endpoint)
}
if endpoint == "" {
return errEmptyEndpoint
}
// Ensure endpoint starts with /
if !strings.HasPrefix(endpoint, "/") {
return fmt.Errorf("endpoint %s must start with /", endpoint)
}
}
return nil
}
// getBasePaths returns all base paths for a chain (with and without alias).
// Single source of truth for path construction.
func (m *HandlerManager) getBasePaths(chainID ids.ID, chainAlias string) []string {
bases := []string{}
// If we have an alias (like "C" for C-Chain), use it as primary
if chainAlias != "" && chainAlias != chainID.String() {
bases = append(bases, fmt.Sprintf("bc/%s", chainAlias))
}
// Always include the full chain ID path
bases = append(bases, fmt.Sprintf("bc/%s", chainID.String()))
return bases
}
// getFullRoutes constructs full route paths for logging.
// Clear, complete information for operators.
func (m *HandlerManager) getFullRoutes(bases []string, endpoints []string) []string {
routes := []string{}
for _, base := range bases {
for _, endpoint := range endpoints {
routes = append(routes, fmt.Sprintf("/ext/%s%s", base, endpoint))
}
}
return routes
}
// registerWithRetry attempts registration with exponential backoff.
// Handles transient failures gracefully.
func (m *HandlerManager) registerWithRetry(
ctx context.Context,
base string,
endpoint string,
handler http.Handler,
) error {
wait := m.retryWait
var lastErr error
for attempt := 0; attempt < m.retries; attempt++ {
// Check context cancellation
select {
case <-ctx.Done():
return ctx.Err()
default:
}
// Try registration
if err := m.server.AddRoute(handler, base, endpoint); err == nil {
return nil // Success!
} else {
lastErr = err
m.log.Debug("Registration attempt failed, retrying",
log.Int("attempt", attempt+1),
log.String("base", base),
log.String("endpoint", endpoint),
log.Err(err))
}
// Don't wait after last attempt
if attempt < m.retries-1 {
select {
case <-time.After(wait):
wait *= 2 // Exponential backoff
case <-ctx.Done():
return ctx.Err()
}
}
}
return fmt.Errorf("failed after %d attempts: %w", m.retries, lastErr)
}
// healthCheckRoute performs a basic health check on a registered route.
// Validates that handlers are actually responding.
func (m *HandlerManager) healthCheckRoute(info *RouteInfo) error {
if info.Handler == nil {
return fmt.Errorf("no handler to check for chain %s", info.ChainID)
}
// Create a test request
req := httptest.NewRequest("POST", "/", strings.NewReader(`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}`))
req.Header.Set("Content-Type", "application/json")
// Record the response
recorder := httptest.NewRecorder()
// Call the handler
info.Handler.ServeHTTP(recorder, req)
// Check response
info.LastCheck = time.Now()
if recorder.Code == http.StatusOK || recorder.Code == http.StatusMethodNotAllowed {
info.Healthy = true
m.log.Debug("Health check passed",
log.Stringer("chainID", info.ChainID),
log.Int("status", recorder.Code))
return nil
}
info.Healthy = false
return fmt.Errorf("%w: status %d", errHealthCheckFailed, recorder.Code)
}
// GetRouteInfo returns information about a registered chain's routes.
// Useful for debugging and monitoring.
func (m *HandlerManager) GetRouteInfo(chainID ids.ID) (*RouteInfo, bool) {
m.mu.RLock()
defer m.mu.RUnlock()
info, exists := m.routes[chainID.String()]
return info, exists
}
// GetAllRoutes returns all registered route information.
// Complete visibility for operators.
func (m *HandlerManager) GetAllRoutes() map[string]*RouteInfo {
m.mu.RLock()
defer m.mu.RUnlock()
// Return a copy to prevent external modification
routes := make(map[string]*RouteInfo, len(m.routes))
for k, v := range m.routes {
routes[k] = v
}
return routes
}
// HealthCheckAll performs health checks on all registered routes.
// Batch operation for monitoring systems.
func (m *HandlerManager) HealthCheckAll() map[string]bool {
m.mu.RLock()
routes := make([]*RouteInfo, 0, len(m.routes))
for _, info := range m.routes {
routes = append(routes, info)
}
m.mu.RUnlock()
results := make(map[string]bool)
for _, info := range routes {
err := m.healthCheckRoute(info)
results[info.ChainID.String()] = err == nil
}
return results
}
// SetRetryConfig allows customization of retry behavior.
// Flexibility for different deployment scenarios.
func (m *HandlerManager) SetRetryConfig(maxRetries int, initialWait time.Duration) {
if maxRetries > 0 {
m.retries = maxRetries
}
if initialWait > 0 {
m.retryWait = initialWait
}
}
-291
View File
@@ -1,291 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"context"
"errors"
"net/http"
"testing"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/server/http"
"github.com/luxfi/runtime"
"github.com/luxfi/vm"
"github.com/stretchr/testify/require"
)
// mockServer implements a test server for handler registration
type mockServer struct {
routes map[string]http.Handler
failCount int
maxFailures int
returnError error
aliases map[string][]string
}
func newMockServer() *mockServer {
return &mockServer{
routes: make(map[string]http.Handler),
maxFailures: 0,
aliases: make(map[string][]string),
}
}
func (s *mockServer) AddRoute(handler http.Handler, base, endpoint string) error {
// Simulate transient failures for retry testing
if s.failCount < s.maxFailures {
s.failCount++
return errors.New("transient failure")
}
// Return configured error if any
if s.returnError != nil {
return s.returnError
}
// Store the route
key := base + endpoint
s.routes[key] = handler
return nil
}
func (s *mockServer) AddAliases(endpoint string, aliases ...string) error {
s.aliases[endpoint] = aliases
return nil
}
func (s *mockServer) AddRouteWithReadLock(handler http.Handler, base, endpoint string) error {
return s.AddRoute(handler, base, endpoint)
}
func (s *mockServer) AddAliasesWithReadLock(endpoint string, aliases ...string) error {
return s.AddAliases(endpoint, aliases...)
}
func (s *mockServer) Dispatch() error { return nil }
func (s *mockServer) RegisterChain(chainName string, rt *runtime.Runtime, vm vm.VM) {
}
func (s *mockServer) Shutdown() error { return nil }
func (s *mockServer) SetRootInfoProvider(_ server.RootInfoProvider) {}
func TestHandlerManager_RegisterChainHandlers(t *testing.T) {
tests := []struct {
name string
chainID ids.ID
chainAlias string
handlers map[string]http.Handler
serverError error
expectError bool
expectRoutes int
}{
{
name: "successful registration with alias",
chainID: ids.GenerateTestID(),
chainAlias: "C",
handlers: map[string]http.Handler{
"/rpc": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}),
"/ws": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}),
},
expectError: false,
expectRoutes: 4, // 2 endpoints × 2 bases (alias + ID)
},
{
name: "successful registration without alias",
chainID: ids.GenerateTestID(),
handlers: map[string]http.Handler{
"/rpc": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}),
},
expectError: false,
expectRoutes: 1,
},
{
name: "nil handler validation",
chainID: ids.GenerateTestID(),
chainAlias: "X",
handlers: map[string]http.Handler{"/rpc": nil},
expectError: true,
},
{
name: "empty endpoint validation",
chainID: ids.GenerateTestID(),
handlers: map[string]http.Handler{"": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})},
expectError: true,
},
{
name: "no handlers provided",
chainID: ids.GenerateTestID(),
handlers: map[string]http.Handler{},
expectError: true,
},
{
name: "invalid endpoint format",
chainID: ids.GenerateTestID(),
handlers: map[string]http.Handler{"rpc": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})},
expectError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Setup
server := newMockServer()
server.returnError = tt.serverError
logger := log.NewNoOpLogger()
manager := NewHandlerManager(server, logger)
// Execute
ctx := context.Background()
err := manager.RegisterChainHandlers(ctx, tt.chainID, tt.chainAlias, tt.handlers)
// Verify
if tt.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Len(t, server.routes, tt.expectRoutes)
// Verify route info was stored
info, exists := manager.GetRouteInfo(tt.chainID)
require.True(t, exists)
require.Equal(t, tt.chainID, info.ChainID)
require.Equal(t, tt.chainAlias, info.ChainAlias)
}
})
}
}
func TestHandlerManager_RetryLogic(t *testing.T) {
// Setup server that fails twice then succeeds
server := newMockServer()
server.maxFailures = 2
logger := log.NewNoOpLogger()
manager := NewHandlerManager(server, logger)
manager.SetRetryConfig(3, 10*time.Millisecond)
// Create test handler
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
// Register with retries
ctx := context.Background()
chainID := ids.GenerateTestID()
require.NoError(t, manager.RegisterChainHandlers(ctx, chainID, "TEST", map[string]http.Handler{
"/rpc": handler,
}))
require.Equal(t, 2, server.failCount) // Failed twice, succeeded on third try
require.Len(t, server.routes, 2) // Both alias and ID routes
}
func TestHandlerManager_HealthCheck(t *testing.T) {
server := newMockServer()
logger := log.NewNoOpLogger()
manager := NewHandlerManager(server, logger)
// Register a healthy handler
healthyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"jsonrpc":"2.0","result":"test","id":1}`))
})
// Register an unhealthy handler
unhealthyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
ctx := context.Background()
chainID1 := ids.GenerateTestID()
chainID2 := ids.GenerateTestID()
// Register healthy chain
require.NoError(t, manager.RegisterChainHandlers(ctx, chainID1, "", map[string]http.Handler{
"/rpc": healthyHandler,
}))
// Register unhealthy chain
// Registration succeeds even if health check fails
require.NoError(t, manager.RegisterChainHandlers(ctx, chainID2, "", map[string]http.Handler{
"/rpc": unhealthyHandler,
})) // Registration should succeed regardless of handler health
// Check health status
results := manager.HealthCheckAll()
require.True(t, results[chainID1.String()])
require.False(t, results[chainID2.String()])
}
func TestHandlerManager_GetBasePaths(t *testing.T) {
manager := &HandlerManager{}
chainID := ids.GenerateTestID()
// Test with alias
bases := manager.getBasePaths(chainID, "C")
require.Equal(t, []string{"bc/C", "bc/" + chainID.String()}, bases)
// Test without alias
bases = manager.getBasePaths(chainID, "")
require.Equal(t, []string{"bc/" + chainID.String()}, bases)
// Test when alias equals chain ID (shouldn't duplicate)
bases = manager.getBasePaths(chainID, chainID.String())
require.Equal(t, []string{"bc/" + chainID.String()}, bases)
}
func TestHandlerManager_ContextCancellation(t *testing.T) {
// Create a server that delays to test cancellation
server := &mockServer{
routes: make(map[string]http.Handler),
returnError: errors.New("slow server"),
}
logger := log.NewNoOpLogger()
manager := NewHandlerManager(server, logger)
manager.SetRetryConfig(10, 100*time.Millisecond) // Many retries with delays
// Create cancelled context
ctx, cancel := context.WithCancel(context.Background())
cancel() // Cancel immediately
// Try to register - should fail with context error
chainID := ids.GenerateTestID()
err := manager.RegisterChainHandlers(ctx, chainID, "", map[string]http.Handler{
"/rpc": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
})
require.Error(t, err)
require.Contains(t, err.Error(), "context canceled")
}
// Benchmark to ensure performance doesn't degrade
func BenchmarkHandlerRegistration(b *testing.B) {
server := newMockServer()
logger := log.NewNoOpLogger()
manager := NewHandlerManager(server, logger)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
ctx := context.Background()
b.ResetTimer()
for i := 0; i < b.N; i++ {
chainID := ids.GenerateTestID()
manager.RegisterChainHandlers(ctx, chainID, "TEST", map[string]http.Handler{
"/rpc": handler,
"/ws": handler,
})
}
}
-165
View File
@@ -1,165 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"context"
"fmt"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/server/http"
)
// IntegrationExample shows how to modify the existing createChain function in manager.go.
// This replaces lines 941-990 with cleaner, more robust code.
func IntegrationExample(
ctx context.Context,
chainID ids.ID,
vm interface{},
server server.Server,
logger log.Logger,
cChainID ids.ID,
pChainID ids.ID,
isDevMode bool,
) error {
// BEFORE: 50+ lines of complex type checking and error-prone registration
// AFTER: Clean, robust registration with proper error handling
// Step 1: Create the registrar
registrar := NewChainHandlerRegistrar(server, logger, cChainID, pChainID)
// Step 2: Configure based on environment
if isDevMode {
// Development: Fast failures for quick iteration
registrar.SetRetryConfig(2, 50*time.Millisecond)
logger.Info("Using development handler registration settings")
} else {
// Production: More robust with retries
registrar.SetRetryConfig(5, 200*time.Millisecond)
logger.Info("Using production handler registration settings")
}
// Step 3: Register handlers (replaces all the complex VM type checking)
startTime := time.Now()
err := registrar.RegisterChainHandlers(ctx, chainID, vm)
duration := time.Since(startTime)
// Step 4: Handle registration result
if err != nil {
// Log error but don't fail chain creation
// Handlers are not critical for chain operation
logger.Error("RPC handler registration failed",
log.Stringer("chainID", chainID),
log.Err(err),
log.Duration("duration", duration),
log.String("action", "Chain will operate without HTTP/RPC access"))
// Could emit metrics here if available
// metric.HandlerRegistrationFailed.Inc()
// Non-fatal: return nil to allow chain to continue
// Change to 'return err' if you want this to be fatal
return nil
}
// Step 5: Log success with useful information
if info, exists := registrar.GetRouteInfo(chainID); exists {
logger.Info("RPC handlers registered successfully",
log.Stringer("chainID", chainID),
log.String("alias", info.ChainAlias),
log.Strings("endpoints", info.Endpoints),
log.Duration("duration", duration),
log.Bool("healthCheckPassed", info.Healthy))
// Print developer-friendly message
if isDevMode && len(info.Endpoints) > 0 {
baseURL := "http://localhost:9630"
fmt.Printf("\n✅ Chain %s RPC endpoints ready:\n", chainID)
for _, endpoint := range info.Endpoints {
if info.ChainAlias != "" {
fmt.Printf(" %s/ext/bc/%s%s\n", baseURL, info.ChainAlias, endpoint)
}
fmt.Printf(" %s/ext/bc/%s%s\n", baseURL, chainID, endpoint)
}
fmt.Println()
}
}
// Step 6: Schedule async health monitoring (optional)
if !isDevMode {
go monitorHandlerHealth(ctx, registrar, chainID, logger)
}
return nil
}
// monitorHandlerHealth runs periodic health checks in the background.
// This helps detect and log handler issues early.
func monitorHandlerHealth(
ctx context.Context,
registrar *ChainHandlerRegistrar,
chainID ids.ID,
logger log.Logger,
) {
// Initial delay to let chain fully initialize
select {
case <-time.After(10 * time.Second):
case <-ctx.Done():
return
}
// Run initial health check
checkHealth(registrar, chainID, logger)
// Periodic health checks
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
for {
select {
case <-ticker.C:
checkHealth(registrar, chainID, logger)
case <-ctx.Done():
return
}
}
}
// checkHealth performs a health check and logs results.
func checkHealth(registrar *ChainHandlerRegistrar, chainID ids.ID, logger log.Logger) {
results := registrar.HealthCheckAll()
for chainIDStr, healthy := range results {
if chainIDStr == chainID.String() {
if healthy {
logger.Debug("Handler health check passed",
log.String("chainID", chainIDStr))
} else {
logger.Warn("Handler health check failed",
log.String("chainID", chainIDStr),
log.String("action", "Will continue monitoring"))
}
}
}
}
// MinimalIntegration shows the absolute minimum code needed.
// This is what you'd actually put in manager.go.
func MinimalIntegration(
ctx context.Context,
chainID ids.ID,
vm interface{},
server server.Server,
logger log.Logger,
cChainID ids.ID,
) error {
// Just three lines to replace 50+ lines of complex code!
registrar := NewChainHandlerRegistrar(server, logger, cChainID, ids.Empty)
if err := registrar.RegisterChainHandlers(ctx, chainID, vm); err != nil {
logger.Error("Handler registration failed", log.Err(err))
}
return nil // Non-fatal
}
+172
View File
@@ -0,0 +1,172 @@
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// zz_red_probe_test.go — RED adversarial security-regression probe for the fresh-net self-vote
// caught-up path. Demonstrates the connected-vs-replied divergence: the fix gates the self-vote
// on fullyConnectedBeacons (CONNECTIVITY, from net.PeerInfo) but tallies CaughtUp over `replies`
// (from collectFrontierReplies). A beacon that is CONNECTED but does NOT answer the frontier
// query this round counts as "fully connected" yet contributes nothing to the caught-up tally —
// and the self-vote backfills its missing weight, so a HEAVY validator self-completes caught-up
// at a STALE height while an honest connected beacon is genuinely ahead. Blue's bsBeaconNet
// cannot express this (its Send answers for EVERY connected beacon), so the regression slipped
// through. These assertions encode the DESIRED safe behavior: they FAIL on the current code (the
// break) and will PASS once the self-vote gate also requires every connected beacon to have
// REPLIED this round.
package chains
import (
"context"
"testing"
"github.com/stretchr/testify/require"
chainbootstrap "github.com/luxfi/consensus/engine/chain/bootstrap"
"github.com/luxfi/ids"
"github.com/luxfi/math/set"
"github.com/luxfi/node/message"
"github.com/luxfi/node/network"
"github.com/luxfi/node/network/peer"
)
// redSilentNet reports FULL connectivity (every beacon in `connected` is returned by PeerInfo)
// but a designated `silent` beacon — though connected — withholds its GetAcceptedFrontier reply
// this round. This is the exact capability an on-path adversary has (keep a beacon's
// TCP/handshake alive so it shows connected, while dropping/delaying its application-level
// frontier response past the 3s window) AND a natural occurrence during a mass co-restart (an
// ahead beacon replaying state answers the frontier query slowly).
type redSilentNet struct {
network.Network
bh *blockHandler
connected []ids.NodeID // all reported connected (the full set MINUS self)
silent set.Set[ids.NodeID] // connected but withhold their frontier reply
tipFor map[ids.NodeID]ids.ID // what each VOCAL beacon reports
}
func (n *redSilentNet) PeerInfo(nodeIDs []ids.NodeID) []peer.Info {
want := map[ids.NodeID]bool{}
for _, id := range nodeIDs {
want[id] = true
}
var out []peer.Info
for _, b := range n.connected {
if len(nodeIDs) == 0 || want[b] {
out = append(out, peer.Info{ID: b, TrackedChains: set.Of(n.bh.networkID)})
}
}
return out
}
func (n *redSilentNet) Send(msg message.OutboundMessage, nodeIDs set.Set[ids.NodeID], _ ids.ID, _ uint32) set.Set[ids.NodeID] {
m, ok := msg.(*bsOutMsg)
if !ok || m.op != "frontier" {
return nil
}
for id := range nodeIDs {
if n.silent.Contains(id) {
continue // CONNECTED, but withholds its frontier reply this round
}
if tip, ok := n.tipFor[id]; ok {
n.bh.deliverBootstrapFrontier(id, tip)
}
}
return nil
}
// TestRED_PROBE_ConnectedButSilentAheadBeacon_SelfVoteFalseCompletesAtStale is a TWO-SIDED
// CONTRAST: the ONLY difference between the two runs is whether the CONNECTED ahead-beacon B
// delivers its frontier reply. B is fully connected in both runs, so fullyConnectedBeacons is
// TRUE in both. Yet B-replies → safe (status != FrontierCaughtUp); B-connected-but-silent →
// FrontierCaughtUp at the stale height (the break). This falsifies Blue's safety claim ("a
// genuinely behind node has an ahead peer in the full set → CaughtUp is false → it keeps
// waiting/syncing"): the gate keys on CONNECTIVITY while the caught-up decision keys on REPLIES,
// and the two diverge.
//
// Why K is genuinely finalized-ahead (a real safety break, not a minority fork): a heavy
// validator (self=60%) finalizes K WITH a minority (B=33%, so self+B=93% ≥ ⅔), then LOSES K to a
// persistence lag (this codebase documents exactly this — the ZAP fire-and-forget Accept /
// bsTestVM.frozenLastAccepted) and restarts STALE at M < K. B retained the finalized K. The node
// MUST recover K; self-completing at M abandons finalized history and lets it build a conflicting
// fork. The node cannot tell "M is the frontier" from "I lost finalized K" — which is precisely
// why it must HEAR from connected B before concluding caught-up. self is NOT an independent
// witness to its own caught-up-ness; the self-vote lets the node vouch for its own staleness.
func TestRED_PROBE_ConnectedButSilentAheadBeacon_SelfVoteFalseCompletesAtStale(t *testing.T) {
const N = 10 // K: the finalized-ahead height B retained (self voted it, then lost it)
const M = 5 // the node's STALE accepted height after the persistence-lag crash
run := func(t *testing.T, bSilent bool) chainbootstrap.FrontierStatus {
chain, _ := buildBSChain(N, -1)
vm := newBSVMAt(chain, M) // node stale at M; it does NOT hold chain[N]=K
self := ids.GenerateTestNodeID()
a := ids.GenerateTestNodeID() // co-stale light beacon, at M
b := ids.GenerateTestNodeID() // AHEAD beacon, retained finalized K
// HEAVY self (60 of 100): self > total/2 - 1, so peers alone (40) < the 51 stake-majority
// floor → the self-vote branch. self+B=93% could finalize K; B=33% retains it.
weights := map[ids.NodeID]uint64{self: 60, a: 7, b: 33}
bh, _ := newBSHandlerWeighted(t, vm, weights)
bh.selfNodeID = self
bh.msgCreator = bsMsgBuilder{}
// FULL connectivity in BOTH runs: A and B are connected (B is in `connected` either way).
tipFor := map[ids.NodeID]ids.ID{a: chain[M].id} // A reports the stale tip M
silent := set.NewSet[ids.NodeID](1)
if bSilent {
silent.Add(b) // B connected but withholds its frontier reply this round
} else {
tipFor[b] = chain[N].id // B replies its genuine ahead tip K
}
bh.net = &redSilentNet{bh: bh, connected: []ids.NodeID{a, b}, silent: silent, tipFor: tipFor}
bh.bsActive.Store(true)
_, status := bh.FrontierTip(context.Background())
bh.bsActive.Store(false)
return status
}
bReplies := run(t, false)
bSilent := run(t, true)
t.Logf("B replies its ahead tip → status=%v (3=FrontierConnecting, safe)", bReplies)
t.Logf("B connected but SILENT → status=%v (5=FrontierCaughtUp, the BREAK)", bSilent)
// Sanity: when the ahead beacon REPLIES, the node correctly fails safe (does not conclude caught-up).
require.NotEqual(t, chainbootstrap.FrontierCaughtUp, bReplies,
"sanity: when the ahead beacon REPLIES, the node correctly does NOT conclude caught-up")
// THE SECURITY REGRESSION ASSERTION. B is fully CONNECTED in both runs. The node must NOT
// self-complete caught-up while a connected beacon's position is unknown — that is a stale
// go-live. FAILS today (the break); PASSES once the self-vote gate also requires every connected
// beacon to have REPLIED this round (not merely be connected).
require.NotEqual(t, chainbootstrap.FrontierCaughtUp, bSilent,
"BREAK: suppressing only the CONNECTED ahead-beacon's frontier reply flips the heavy node to "+
"FrontierCaughtUp at the STALE height — the self-vote backfills the floor and the "+
"full-connectivity gate cannot see the reply suppression")
}
// TestRED_PROBE_EqualStakeNeedsNoSelfVote answers deploy-question #5: 5 EQUAL-stake beacons, node
// a beacon, all four peers connected and reporting a common tip — the node concludes caught-up via
// the ORDINARY AcceptsFrontier path (peers clear the stake-majority floor: 4·w of 5·w = 80% >
// 50%). The self-vote is NEVER needed for equal stake, so the equal-stake devnet hang is NOT this
// self-exclusion floor (look at primaryNetworkReady / P-chain bootstrap / beacon connectivity).
func TestRED_PROBE_EqualStakeNeedsNoSelfVote(t *testing.T) {
chain, byID := buildBSChain(8, -1)
vm := newBSVM(chain) // node at genesis (height 0)
self := ids.GenerateTestNodeID()
p1, p2, p3, p4 := ids.GenerateTestNodeID(), ids.GenerateTestNodeID(), ids.GenerateTestNodeID(), ids.GenerateTestNodeID()
weights := map[ids.NodeID]uint64{self: 100, p1: 100, p2: 100, p3: 100, p4: 100}
bh, chainID := newBSHandlerWeighted(t, vm, weights)
bh.selfNodeID = self
bh.msgCreator = bsMsgBuilder{}
bh.net = &bsBeaconNet{bh: bh, chainID: chainID, connected: []ids.NodeID{p1, p2, p3, p4}, byID: byID, tip: chain[0]}
bh.bsActive.Store(true)
tip, status := bh.FrontierTip(context.Background())
bh.bsActive.Store(false)
t.Logf("equal-stake fresh net: status=%v tip=%v", status, tip)
require.Contains(t, []chainbootstrap.FrontierStatus{chainbootstrap.FrontierNamed, chainbootstrap.FrontierCaughtUp}, status,
"equal-stake peers clear the stake-majority floor unaided — no self-vote needed")
require.Equal(t, chain[0].id, tip, "caught up at genesis")
}
+352
View File
@@ -0,0 +1,352 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Command repair-proposervm is a ONE-TIME, fail-closed surgical tool to reconcile
// a proposervm chain-state DB onto a known-canonical outer block at a single height.
//
// Motivation (incident 1082814, Lux mainnet C-Chain): a sub-quorum proposervm
// envelope A (3-of-5 ACCEPT) was locally accepted on some nodes while the network
// finalized the supermajority sibling B (4-of-5) that wraps the IDENTICAL inner EVM
// block. The two siblings differ ONLY in the proposervm outer envelope; the inner
// EVM state is byte-identical (no EVM divergence). On restart those nodes re-seed
// finality from their persisted proposervm lastAccepted=A and fatal on B's cert
// (EQUIVOCATION). This tool swaps the persisted record of `height` from A to the
// canonical B, leaving the inner EVM completely untouched (no EVM rollback).
//
// It is NOT a blind hex edit: it opens the exact same typed proposervm state
// (luxfi/node/vms/proposervm/state) over the exact same nested keyspace luxd uses
// (chainID -> "vm" -> "proposervm" -> versiondb -> chain/block/height), and writes
// via the state's own PutBlock / SetBlockIDAtHeight / SetLastAccepted so the on-disk
// bytes are identical to what luxd itself wrote for B on the canonical node.
//
// proposervm invariant honored: proLastAcceptedHeight must never be < the inner VM's
// last-accepted height (vm.repairAcceptedChainByHeight). The inner EVM is at `height`
// (it accepted the shared inner block under A), so the recovery target is the
// canonical block AT `height` (B), never height-1 — keeping outer==inner height.
//
// Modes:
//
// inspect : read-only. Print lastAccepted, height index at H and H-1, and the
// outer block currently recorded at H.
// export : read-only. Read the outer block recorded at H and write its raw
// stateless bytes to --block-file (run against a canonical node's DB).
// repair : read-write, fail-closed. Parse --block-file (canonical B), assert it is
// the expected block, assert the DB is in the expected bad state (lastAccepted
// and heightIndex[H] both == the expected sub-quorum block A, and B's parent
// == heightIndex[H-1]); then PutBlock(B), SetBlockIDAtHeight(H,B),
// SetLastAccepted(B), Commit. Idempotent: if already on B, it no-ops.
//
// The DB uses an exclusive LOCK; luxd MUST be stopped on the target before `repair`.
package main
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/luxfi/database"
databasefactory "github.com/luxfi/database/factory"
"github.com/luxfi/database/prefixdb"
"github.com/luxfi/database/versiondb"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/metric"
"github.com/luxfi/node/vms/proposervm/block"
"github.com/luxfi/node/vms/proposervm/state"
)
// The proposervm nests its state under these fixed prefixes inside the chain DB.
// chainDB = prefixdb(chainID[:], baseDB) [chains.ChainDBManager.GetDatabase]
// vmDB = prefixdb("vm", chainDB) [chains.ChainDBManager.GetVMDatabase / VMDBPrefix]
// ppvmDB = versiondb(prefixdb("proposervm", vmDB)) [proposervm.VM.Initialize dbPrefix]
// state.New(ppvmDB) -> "chain"/"block"/"height" sub-prefixes
var (
vmDBPrefix = []byte("vm")
proposervmDBPrefix = []byte("proposervm")
)
var (
dbPath string
dbType string
chainIDStr string
height uint64
blockFile string
expectBlockID string // canonical B (target)
expectCurID string // sub-quorum A (the bad state we expect to overwrite)
yes bool
)
func main() {
root := &cobra.Command{
Use: "repair-proposervm",
Short: "Surgical, fail-closed reconcile of a proposervm chain-state onto a canonical outer block at one height",
}
root.PersistentFlags().StringVar(&dbPath, "db-path", "", "zapdb root (e.g. /data/db/mainnet/db) (required)")
root.PersistentFlags().StringVar(&dbType, "db-type", "zapdb", "database type")
root.PersistentFlags().StringVar(&chainIDStr, "chain-id", "2wRdZGeca1qkxzNCq88NWDF5nJ5A9o623vRJKd3FsjRYvuVvvt", "blockchain ID (proposervm chain)")
root.PersistentFlags().Uint64Var(&height, "height", 1082814, "contested height")
root.MarkPersistentFlagRequired("db-path")
inspect := &cobra.Command{Use: "inspect", Short: "read-only: print proposervm finality state at the height", RunE: runInspect}
export := &cobra.Command{Use: "export", Short: "read-only: write the outer block recorded at the height to --block-file", RunE: runExport}
export.Flags().StringVar(&blockFile, "block-file", "", "output file for the canonical outer block bytes (required)")
export.MarkFlagRequired("block-file")
probe := &cobra.Command{Use: "probe", Short: "read-only: look up an arbitrary block by ID (is it present in the store?)", RunE: runProbe}
probe.Flags().StringVar(&expectBlockID, "block-id", "", "block ID to look up (required)")
probe.MarkFlagRequired("block-id")
dump := &cobra.Command{Use: "dump", Short: "read-only: write an arbitrary block (by ID) raw stateless bytes to --block-file", RunE: runDump}
dump.Flags().StringVar(&expectBlockID, "block-id", "wDMUyGyaKcC2Vng8i8ngU5f83XEtHZx5hqCSe5tMTwLAPagmo", "block ID to dump (canonical B)")
dump.Flags().StringVar(&blockFile, "block-file", "", "output file for the block bytes (required)")
dump.MarkFlagRequired("block-file")
repair := &cobra.Command{Use: "repair", Short: "fail-closed: swap height's outer block from A to canonical B", RunE: runRepair}
repair.Flags().StringVar(&blockFile, "block-file", "", "canonical outer block (B) bytes, from `export` (required)")
repair.Flags().StringVar(&expectBlockID, "expect-block", "wDMUyGyaKcC2Vng8i8ngU5f83XEtHZx5hqCSe5tMTwLAPagmo", "expected canonical block ID (B)")
repair.Flags().StringVar(&expectCurID, "expect-current", "2U2pR3DHCNEFDLnMq2uraNVkThRWgETDd468hR26yGHBQuAnNy", "expected current sub-quorum block ID (A) to be overwritten")
repair.Flags().BoolVar(&yes, "yes", false, "confirm the write")
repair.MarkFlagRequired("block-file")
root.AddCommand(inspect, export, probe, dump, repair)
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, "ERROR:", err)
os.Exit(1)
}
}
// openState opens the proposervm typed state over the exact nested keyspace luxd uses.
// Returns the state, the proposervm versiondb (for Commit), and the base DB (for Close).
func openState(readOnly bool) (state.State, *versiondb.Database, database.Database, ids.ID, error) {
chainID, err := ids.FromString(chainIDStr)
if err != nil {
return nil, nil, nil, ids.Empty, fmt.Errorf("bad chain-id: %w", err)
}
logger := log.New("cmd", "repair-proposervm")
gatherer := metric.NewRegistry()
base, err := databasefactory.New(dbType, dbPath, readOnly, nil, gatherer, logger, "repair", "db")
if err != nil {
return nil, nil, nil, ids.Empty, fmt.Errorf("open db %q: %w", dbPath, err)
}
chainDB := prefixdb.New(chainID[:], base)
vmDB := prefixdb.New(vmDBPrefix, chainDB)
ppvmDB := versiondb.New(prefixdb.New(proposervmDBPrefix, vmDB))
return state.New(ppvmDB), ppvmDB, base, chainID, nil
}
func idAt(st state.State, h uint64) string {
id, err := st.GetBlockIDAtHeight(h)
if errors.Is(err, database.ErrNotFound) {
return "<none>"
}
if err != nil {
return "<err:" + err.Error() + ">"
}
return id.String()
}
func runInspect(_ *cobra.Command, _ []string) error {
st, _, base, _, err := openState(true)
if err != nil {
return err
}
defer base.Close()
la, err := st.GetLastAccepted()
if err != nil {
return fmt.Errorf("GetLastAccepted: %w", err)
}
fmt.Printf("proposervm lastAccepted = %s\n", la)
fmt.Printf("heightIndex[%d] = %s\n", height, idAt(st, height))
fmt.Printf("heightIndex[%d] = %s\n", height-1, idAt(st, height-1))
if id, err := st.GetBlockIDAtHeight(height); err == nil {
if blk, err := st.GetBlock(id); err == nil {
fmt.Printf("block@%d: id=%s parent=%s bytes=%d\n", height, blk.ID(), blk.ParentID(), len(blk.Bytes()))
}
}
return nil
}
func runProbe(_ *cobra.Command, _ []string) error {
want, err := ids.FromString(expectBlockID)
if err != nil {
return fmt.Errorf("bad --block-id: %w", err)
}
// RW so Badger replays its WAL: a verified/built-but-unflushed block may live
// only in the memtable. Disposable copy only.
st, _, base, _, err := openState(false)
if err != nil {
return err
}
defer base.Close()
blk, err := st.GetBlock(want)
if errors.Is(err, database.ErrNotFound) {
fmt.Printf("NOT-PRESENT: block %s is not in this store\n", want)
return nil
}
if err != nil {
return fmt.Errorf("GetBlock(%s): %w", want, err)
}
fmt.Printf("PRESENT: id=%s parent=%s bytes=%d\n", blk.ID(), blk.ParentID(), len(blk.Bytes()))
return nil
}
func runDump(_ *cobra.Command, _ []string) error {
want, err := ids.FromString(expectBlockID)
if err != nil {
return fmt.Errorf("bad --block-id: %w", err)
}
// RW so Badger replays its WAL: a verified-but-unflushed block may live only in
// the memtable. We never call a state WRITER here (read + write output file only),
// and this runs against an idle (luxd-stopped) pod DB; the contested sibling B was
// verified by this node when it saw the conflicting cert, so it is present by ID.
st, _, base, _, err := openState(false)
if err != nil {
return err
}
defer base.Close()
blk, err := st.GetBlock(want)
if errors.Is(err, database.ErrNotFound) {
return fmt.Errorf("block %s is NOT present in this store (cannot dump)", want)
}
if err != nil {
return fmt.Errorf("GetBlock(%s): %w", want, err)
}
if blk.ID() != want {
return fmt.Errorf("self-ID mismatch: requested=%s parsed=%s (refusing)", want, blk.ID())
}
if err := os.WriteFile(blockFile, blk.Bytes(), 0o644); err != nil {
return fmt.Errorf("write %s: %w", blockFile, err)
}
fmt.Printf("DUMPED id=%s parent=%s bytes=%d -> %s\n", blk.ID(), blk.ParentID(), len(blk.Bytes()), blockFile)
return nil
}
func runExport(_ *cobra.Command, _ []string) error {
// Open read-WRITE so Badger replays its value-log/WAL: the canonical block at
// the contested height was the LAST write before the chain went idle, so on a
// crash-consistent snapshot copy it may live only in the memtable/WAL, not yet
// in an SST. A read-only open skips recovery and could miss it. We never call a
// state writer here (we only read + write the output file), and this only ever
// runs against a DISPOSABLE snapshot copy of a canonical node — never the live node.
st, _, base, _, err := openState(false)
if err != nil {
return err
}
defer base.Close()
id, err := st.GetBlockIDAtHeight(height)
if err != nil {
return fmt.Errorf("GetBlockIDAtHeight(%d): %w", height, err)
}
blk, err := st.GetBlock(id)
if err != nil {
return fmt.Errorf("GetBlock(%s): %w", id, err)
}
if blk.ID() != id {
return fmt.Errorf("block id mismatch: index=%s block=%s", id, blk.ID())
}
if err := os.WriteFile(blockFile, blk.Bytes(), 0o644); err != nil {
return fmt.Errorf("write %s: %w", blockFile, err)
}
la, _ := st.GetLastAccepted()
fmt.Printf("EXPORTED height=%d id=%s parent=%s bytes=%d -> %s\n", height, blk.ID(), blk.ParentID(), len(blk.Bytes()), blockFile)
fmt.Printf(" (source lastAccepted=%s heightIndex[%d-1]=%s)\n", la, height, idAt(st, height-1))
return nil
}
func runRepair(_ *cobra.Command, _ []string) error {
wantB, err := ids.FromString(expectBlockID)
if err != nil {
return fmt.Errorf("bad --expect-block: %w", err)
}
wantA, err := ids.FromString(expectCurID)
if err != nil {
return fmt.Errorf("bad --expect-current: %w", err)
}
raw, err := os.ReadFile(blockFile)
if err != nil {
return fmt.Errorf("read %s: %w", blockFile, err)
}
blk, err := block.ParseWithoutVerification(raw)
if err != nil {
return fmt.Errorf("parse block file: %w", err)
}
// (1) the supplied block must be exactly the canonical target B.
if blk.ID() != wantB {
return fmt.Errorf("block-file id %s != --expect-block %s (refusing)", blk.ID(), wantB)
}
st, ppvmDB, base, _, err := openState(false)
if err != nil {
return err
}
defer base.Close()
la, err := st.GetLastAccepted()
if err != nil {
return fmt.Errorf("GetLastAccepted: %w", err)
}
curAtH, err := st.GetBlockIDAtHeight(height)
if err != nil {
return fmt.Errorf("GetBlockIDAtHeight(%d): %w", height, err)
}
// (2) idempotency: if already on B, do nothing.
if la == wantB && curAtH == wantB {
fmt.Printf("ALREADY-CANONICAL: lastAccepted and heightIndex[%d] already == B (%s); no-op\n", height, wantB)
return nil
}
// (3) fail-closed: only proceed from the exact expected bad state (A at H, lastAccepted A).
if la != wantA {
return fmt.Errorf("refusing: lastAccepted=%s is neither A(%s) nor B(%s) — unexpected state", la, wantA, wantB)
}
if curAtH != wantA {
return fmt.Errorf("refusing: heightIndex[%d]=%s != A(%s) — unexpected state", height, curAtH, wantA)
}
// (4) B must extend the SAME finalized prefix: B.parent == the block recorded at H-1.
parentAtH1, err := st.GetBlockIDAtHeight(height - 1)
if err != nil {
return fmt.Errorf("GetBlockIDAtHeight(%d): %w", height-1, err)
}
if blk.ParentID() != parentAtH1 {
return fmt.Errorf("refusing: B.parent=%s != heightIndex[%d]=%s (B does not extend the local finalized prefix)", blk.ParentID(), height-1, parentAtH1)
}
if _, err := st.GetBlock(parentAtH1); err != nil {
return fmt.Errorf("refusing: parent %s (height %d) not present in store: %w", parentAtH1, height-1, err)
}
fmt.Printf("PLAN: height=%d %s (A) -> %s (B)\n", height, wantA, wantB)
fmt.Printf(" current lastAccepted = %s\n", la)
fmt.Printf(" B.parent = %s == heightIndex[%d] OK\n", blk.ParentID(), height-1)
if !yes {
return errors.New("dry-run only: re-run with --yes to write")
}
// (5) apply via the state's own typed writers (identical on-disk bytes to luxd).
if err := st.PutBlock(blk); err != nil {
return fmt.Errorf("PutBlock(B): %w", err)
}
if err := st.SetBlockIDAtHeight(height, blk.ID()); err != nil {
return fmt.Errorf("SetBlockIDAtHeight(%d,B): %w", height, err)
}
if err := st.SetLastAccepted(blk.ID()); err != nil {
return fmt.Errorf("SetLastAccepted(B): %w", err)
}
if err := ppvmDB.Commit(); err != nil {
return fmt.Errorf("commit: %w", err)
}
// (6) re-read to confirm.
la2, _ := st.GetLastAccepted()
fmt.Printf("DONE: lastAccepted=%s heightIndex[%d]=%s heightIndex[%d]=%s\n", la2, height, idAt(st, height), height-1, idAt(st, height-1))
if la2 != wantB || idAt(st, height) != wantB.String() {
return fmt.Errorf("post-write verification FAILED")
}
fmt.Println("VERIFIED: proposervm now records canonical B at the contested height; inner EVM untouched.")
return nil
}
+1 -1
View File
@@ -19,7 +19,7 @@ services:
LUXD_CONSENSUS_QUORUM_SIZE: "1"
LUXD_LOG_LEVEL: "info"
healthcheck:
test: ["CMD", "curl", "-sf", "http://localhost:9630/ext/health"]
test: ["CMD", "curl", "-sf", "http://localhost:9630/v1/health"]
interval: 30s
timeout: 10s
retries: 5
+8
View File
@@ -1762,6 +1762,14 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
if nodeConfig.HealthCheckFreq < 0 {
return node.Config{}, fmt.Errorf("%s must be positive", HealthCheckFreqKey)
}
nodeConfig.ProposerWindowDuration = v.GetDuration(ProposerVMWindowDurationKey)
if nodeConfig.ProposerWindowDuration < 0 {
return node.Config{}, fmt.Errorf("%s must not be negative", ProposerVMWindowDurationKey)
}
nodeConfig.ProposerMinBlockDelay = v.GetDuration(ProposerVMMinBlockDelayKey)
if nodeConfig.ProposerMinBlockDelay < 0 {
return node.Config{}, fmt.Errorf("%s must not be negative", ProposerVMMinBlockDelayKey)
}
// Halflife of continuous averager used in health checks
healthCheckAveragerHalflife := v.GetDuration(HealthCheckAveragerHalflifeKey)
if healthCheckAveragerHalflife <= 0 {
+5 -6
View File
@@ -24,7 +24,6 @@ import (
"github.com/luxfi/node/genesis/builder"
"github.com/luxfi/node/nets"
pchaingenesis "github.com/luxfi/node/vms/platformvm/genesis"
pchaintxs "github.com/luxfi/node/vms/platformvm/txs"
)
const chainConfigFilenameExtension = ".ex"
@@ -536,8 +535,8 @@ func TestGetNetConfigsFromFlags(t *testing.T) {
"2Ctt6eGAeo4MLqTmGa7AdRecuVMPGWEX9wSsCLBYrLhX4a394i": {
"consensusParameters": {
"k": 30,
"alphaPreference": 16,
"alphaConfidence": 20
"alphaPreference": 20,
"alphaConfidence": 25
},
"validatorOnly": true
}
@@ -547,8 +546,8 @@ func TestGetNetConfigsFromFlags(t *testing.T) {
config, ok := given[id]
require.True(ok)
require.True(config.ValidatorOnly)
require.Equal(16, config.ConsensusParameters.AlphaPreference)
require.Equal(20, config.ConsensusParameters.AlphaConfidence)
require.Equal(20, config.ConsensusParameters.AlphaPreference)
require.Equal(25, config.ConsensusParameters.AlphaConfidence)
require.Equal(30, config.ConsensusParameters.K)
// must still respect defaults (MainnetParameters.MaxOutstandingItems = 1024)
require.Equal(1024, config.ConsensusParameters.MaxOutstandingItems)
@@ -733,7 +732,7 @@ func TestResolveUTXOAssetID_POnlyFallback(t *testing.T) {
require := require.New(t)
pOnly := &pchaingenesis.Genesis{Chains: nil}
pOnlyBytes, err := pchaingenesis.Codec.Marshal(pchaintxs.CodecVersion, pOnly)
pOnlyBytes, err := pOnly.Bytes()
require.NoError(err)
gotID, err := resolveUTXOAssetID(42, pOnlyBytes)
+1
View File
@@ -369,6 +369,7 @@ func addNodeFlags(fs *pflag.FlagSet) {
// ProposerVM
fs.Bool(ProposerVMUseCurrentHeightKey, false, "Have the ProposerVM always report the last accepted P-chain block height")
fs.Duration(ProposerVMMinBlockDelayKey, proposervm.DefaultMinBlockDelay, "Minimum delay to enforce when building a chain++ block for the primary network chains and the default minimum delay for chains")
fs.Duration(ProposerVMWindowDurationKey, 0, "Proposer-slot spacing for block production (0 uses the 5s mainnet default); shrink for fast cadence on small/local networks")
// Metrics
fs.Bool(MeterVMsEnabledKey, true, "Enable Meter VMs to track VM performance with more granularity")
+1
View File
@@ -187,6 +187,7 @@ const (
ConsensusFrontierPollFrequencyKey = "consensus-frontier-poll-frequency"
ProposerVMUseCurrentHeightKey = "proposervm-use-current-height"
ProposerVMMinBlockDelayKey = "proposervm-min-block-delay"
ProposerVMWindowDurationKey = "proposervm-window-duration"
FdLimitKey = "fd-limit"
IndexEnabledKey = "index-enabled"
IndexAllowIncompleteKey = "index-allow-incomplete"
+10
View File
@@ -177,6 +177,16 @@ type Config struct {
// Health
HealthCheckFreq time.Duration `json:"healthCheckFreq"`
// ProposerWindowDuration overrides the proposervm proposer-slot spacing.
// Zero keeps the 5s mainnet default; small local/dev nets set it low (e.g.
// 1s) so block cadence is not floored at 5s per proposer slot.
ProposerWindowDuration time.Duration `json:"proposerWindowDuration"`
// ProposerMinBlockDelay is the proposervm minimum delay between consecutive
// blocks (the hard cadence floor). Zero keeps the 1s default; high-throughput
// / DEX nets set it low (e.g. 1ms) to approach the consensus-finality floor.
ProposerMinBlockDelay time.Duration `json:"proposerMinBlockDelay"`
// Network configuration
NetworkConfig network.Config `json:"networkConfig"`
+51
View File
@@ -68,3 +68,54 @@ Block arrives
## Recent Changes
- 2026-01-04: Created documentation files with Vote terminology
## consensus/quasar — PQ-finality VERIFY gate (2026-06-28)
Supersedes the stale "Quasar wrapper / CoronaCoordinator" notes above (that
subpackage did not exist in-tree). The current `consensus/quasar` package is the
node-side integration of `luxfi/consensus@v1.29.0`'s typed compact-cert finality
layer (`protocol/quasar.VerifyConsensusCert`). It wires the VERIFY half only.
Model: luxd finalizes on classical Snow every block; at CHECKPOINTS (height %
interval) a sampled committee's QuasarCert over the finalized digest is VERIFIED.
Default posture HYBRID_PQ = Beam(BLS) ∧ Pulsar (ML-DSA-65); STRICT_DUAL_PQ
(+Corona) / POLARIS (+Magnetar) configurable.
THE SAFETY CONTRACT — forward-dated, DORMANT by default:
- `Gate.VerifyAccepted` is the accept-path boundary. nil gate / `Activation.Height
== 0` / below-height / non-checkpoint => no-op; classical finality UNCHANGED.
- Activated at a checkpoint => REQUIRE a valid cert bound to the finalized block;
FAIL CLOSED (missing/mismatch/invalid => error from Accept, halts without
persisting). Activation is HEIGHT-ONLY (deterministic — no wall clock).
- Hooked in `vms/proposervm/post_fork_block.go Accept()` via
`vm.verifyQuasarFinality(b)`; the VM's `quasarGate` is nil in production today
(set via `SetQuasarGate`). Nothing wires it yet — that is the activation step.
Files: gate.go (Gate/ActivationConfig/bindCheck), policy.go (HYBRID_PQ default,
cert can't pick its own policy), validators.go (ConsensusValidatorSet: BLS+Pulsar
keys), store.go (MemCertStore), producer.go (committee-signer interface =
scaffolding; nil = verify-only), errors.go. Tests: gate_test.go (13, -race green:
dormant no-op, fail-closed, epoch/round/chain/height/block anti-replay, real-
verifier delegation, misconfigured-fails-closed).
REMAINING WORK to reach a live PQ-finality network (all owner-gated):
1. Producer service (pulsard): the per-validator committee cert signer. Needs
pulsar v1.7.1 (no-reconstruct hyperball signer) AND consensus to EXPORT the
currently package-private cert/payload ENCODERS (an external producer cannot
assemble a ConsensusCert envelope without them; this also unblocks an end-to-
end positive verify test).
2. Cert gossip/ingest -> MemCertStore (verify-before-store); MemCertStore needs
eviction below last-finalized height before this lands.
3. Production per-epoch `ValidatorSetProvider` from the P-Chain validator manager
+ KeyEra registry (BLS aggregate + Pulsar/Corona/Magnetar group keys per era).
4. Config-flag -> SetQuasarGate wiring (construct a non-nil gate from node config;
choose ChainID = sovereign/EVM chain id).
5. Cert-unavailability runbook + a bounded grace window (await cert N rounds)
before a checkpoint halts — fail-closed-after-decision can brick a chain if
gossip is down. REQUIRED before any forward-dated activation.
6. A proposervm Accept-path integration test (nil/dormant/activated).
Mainnet activation order (owner): deploy producer -> verify cert-gossip coverage
at checkpoints -> set Activation.Height to a forward-dated height with margin ->
roll via `kubectl patch sts luxd` OnDelete, 1 pod at a time. NEVER wipe /data/db,
NEVER pkill, NEVER blind-restart.
-353
View File
@@ -1,353 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"errors"
"fmt"
"time"
)
// Configuration errors
var (
ErrInvalidK = errors.New("K must be positive")
ErrInvalidAlpha = errors.New("alpha must be in (0, 1]")
ErrInvalidBeta = errors.New("beta must be positive and <= K")
ErrInvalidThreshold = errors.New("threshold must be >= 2 and <= parties")
ErrInvalidQuorum = errors.New("quorum numerator must be <= denominator")
ErrInvalidTimeout = errors.New("timeout must be positive")
ErrInvalidInterval = errors.New("polling interval must be positive")
)
// -----------------------------------------------------------------------------
// Core Consensus Parameters (compile-time, immutable after construction)
// -----------------------------------------------------------------------------
// CoreParams defines the fundamental Lux consensus parameters.
// These are protocol-critical and must match across all validators.
type CoreParams struct {
// K is the sample size for each consensus query round.
// Typical values: 20-25 for production networks.
K int
// Alpha is the quorum threshold as a fraction of K.
// A response is accepted if >= ceil(K * Alpha) validators agree.
// Must be in (0.5, 1] for Byzantine fault tolerance.
// Typical value: 0.8 (80% of sample must agree).
Alpha float64
// BetaVirtuous is the number of consecutive successful polls
// required to finalize a virtuous (non-conflicting) decision.
// Higher values increase latency but improve consistency.
// Typical value: 15-20.
BetaVirtuous int
// BetaRogue is the number of consecutive successful polls
// required to finalize a rogue (conflicting) decision.
// Should be >= BetaVirtuous.
// Typical value: 20-25.
BetaRogue int
}
// Validate checks CoreParams invariants.
func (p CoreParams) Validate() error {
if p.K <= 0 {
return ErrInvalidK
}
if p.Alpha <= 0 || p.Alpha > 1 {
return ErrInvalidAlpha
}
if p.BetaVirtuous <= 0 || p.BetaVirtuous > p.K {
return ErrInvalidBeta
}
if p.BetaRogue <= 0 || p.BetaRogue > p.K {
return ErrInvalidBeta
}
if p.BetaRogue < p.BetaVirtuous {
return fmt.Errorf("BetaRogue (%d) must be >= BetaVirtuous (%d)", p.BetaRogue, p.BetaVirtuous)
}
return nil
}
// AlphaThreshold returns the minimum agreements needed for quorum.
func (p CoreParams) AlphaThreshold() int {
return int(float64(p.K)*p.Alpha + 0.999) // ceil
}
// DefaultCoreParams returns production-ready core parameters.
func DefaultCoreParams() CoreParams {
return CoreParams{
K: 20,
Alpha: 0.8,
BetaVirtuous: 15,
BetaRogue: 20,
}
}
// -----------------------------------------------------------------------------
// Threshold Signing Parameters (compile-time, for Corona/BLS threshold)
// -----------------------------------------------------------------------------
// ThresholdParams defines t-of-n threshold signature configuration.
type ThresholdParams struct {
// NumParties is the total number of signing parties (validators).
// Must be >= 3 for threshold signatures.
NumParties int
// Threshold is the minimum signers required (t in t-of-n).
// For BFT: typically 2/3 + 1.
// Must be >= 2 and <= NumParties.
Threshold int
}
// Validate checks ThresholdParams invariants.
func (p ThresholdParams) Validate() error {
if p.NumParties < 3 {
return fmt.Errorf("%w: need at least 3 parties, got %d", ErrInvalidThreshold, p.NumParties)
}
if p.Threshold < 2 || p.Threshold > p.NumParties {
return fmt.Errorf("%w: threshold=%d, parties=%d", ErrInvalidThreshold, p.Threshold, p.NumParties)
}
return nil
}
// DefaultThresholdParams returns 2/3+1 threshold for n parties.
func DefaultThresholdParams(numParties int) ThresholdParams {
threshold := (numParties * 2 / 3) + 1
if threshold < 2 {
threshold = 2
}
if threshold > numParties {
threshold = numParties
}
return ThresholdParams{
NumParties: numParties,
Threshold: threshold,
}
}
// -----------------------------------------------------------------------------
// Quorum Parameters (compile-time, for BLS aggregate weight verification)
// -----------------------------------------------------------------------------
// QuorumParams defines weight-based quorum requirements.
type QuorumParams struct {
// Numerator and Denominator define the minimum weight fraction.
// Quorum is met when SignerWeight/TotalWeight >= Numerator/Denominator.
// For BFT: typically 2/3 (Numerator=2, Denominator=3).
Numerator uint64
Denominator uint64
}
// Validate checks QuorumParams invariants.
func (p QuorumParams) Validate() error {
if p.Denominator == 0 {
return fmt.Errorf("%w: denominator cannot be zero", ErrInvalidQuorum)
}
if p.Numerator > p.Denominator {
return fmt.Errorf("%w: numerator=%d > denominator=%d", ErrInvalidQuorum, p.Numerator, p.Denominator)
}
return nil
}
// RequiredWeight returns minimum weight needed for quorum given totalWeight.
func (p QuorumParams) RequiredWeight(totalWeight uint64) uint64 {
return totalWeight * p.Numerator / p.Denominator
}
// IsMet returns true if signerWeight meets quorum given totalWeight.
func (p QuorumParams) IsMet(signerWeight, totalWeight uint64) bool {
return signerWeight >= p.RequiredWeight(totalWeight)
}
// DefaultQuorumParams returns 2/3 quorum (67% of weight required).
func DefaultQuorumParams() QuorumParams {
return QuorumParams{
Numerator: 2,
Denominator: 3,
}
}
// -----------------------------------------------------------------------------
// Runtime Configuration (can be adjusted, but affects liveness not safety)
// -----------------------------------------------------------------------------
// RuntimeConfig holds tunable runtime parameters.
// These affect performance and liveness but not consensus safety.
type RuntimeConfig struct {
// PollInterval is the delay between consensus query rounds.
// Lower values decrease latency but increase network load.
// Typical value: 100-500ms.
PollInterval time.Duration
// QueryTimeout is the maximum time to wait for query responses.
// Must be > PollInterval.
// Typical value: 2-5s.
QueryTimeout time.Duration
// FinalityChannelSize is the buffer size for the finality event channel.
FinalityChannelSize int
// MaxConcurrentQueries limits parallel outstanding queries.
// 0 means unlimited.
MaxConcurrentQueries int
}
// Validate checks RuntimeConfig invariants.
func (c RuntimeConfig) Validate() error {
if c.PollInterval <= 0 {
return ErrInvalidInterval
}
if c.QueryTimeout <= 0 {
return ErrInvalidTimeout
}
if c.QueryTimeout < c.PollInterval {
return fmt.Errorf("query timeout (%v) must be >= poll interval (%v)", c.QueryTimeout, c.PollInterval)
}
if c.FinalityChannelSize < 0 {
return fmt.Errorf("finality channel size must be >= 0")
}
return nil
}
// DefaultRuntimeConfig returns production-ready runtime configuration.
func DefaultRuntimeConfig() RuntimeConfig {
return RuntimeConfig{
PollInterval: 250 * time.Millisecond,
QueryTimeout: 2 * time.Second,
FinalityChannelSize: 100,
MaxConcurrentQueries: 0, // unlimited
}
}
// -----------------------------------------------------------------------------
// Complete Configuration
// -----------------------------------------------------------------------------
// Config is the complete Quasar consensus configuration.
// Use ConfigBuilder for fluent construction.
type Config struct {
Core CoreParams
Threshold ThresholdParams
Quorum QuorumParams
Runtime RuntimeConfig
}
// Validate checks all configuration invariants.
func (c Config) Validate() error {
if err := c.Core.Validate(); err != nil {
return fmt.Errorf("core params: %w", err)
}
if err := c.Threshold.Validate(); err != nil {
return fmt.Errorf("threshold params: %w", err)
}
if err := c.Quorum.Validate(); err != nil {
return fmt.Errorf("quorum params: %w", err)
}
if err := c.Runtime.Validate(); err != nil {
return fmt.Errorf("runtime config: %w", err)
}
return nil
}
// DefaultConfig returns a production-ready configuration.
// Call DefaultConfig().WithNumParties(n) to set validator count.
func DefaultConfig() Config {
return Config{
Core: DefaultCoreParams(),
Threshold: DefaultThresholdParams(3), // default 3 validators
Quorum: DefaultQuorumParams(),
Runtime: DefaultRuntimeConfig(),
}
}
// -----------------------------------------------------------------------------
// ConfigBuilder provides fluent configuration construction
// -----------------------------------------------------------------------------
// ConfigBuilder enables fluent Config construction with validation.
type ConfigBuilder struct {
config Config
}
// NewConfigBuilder creates a builder starting from defaults.
func NewConfigBuilder() *ConfigBuilder {
return &ConfigBuilder{
config: DefaultConfig(),
}
}
// WithK sets the sample size.
func (b *ConfigBuilder) WithK(k int) *ConfigBuilder {
b.config.Core.K = k
return b
}
// WithAlpha sets the quorum fraction.
func (b *ConfigBuilder) WithAlpha(alpha float64) *ConfigBuilder {
b.config.Core.Alpha = alpha
return b
}
// WithBeta sets both BetaVirtuous and BetaRogue.
func (b *ConfigBuilder) WithBeta(virtuous, rogue int) *ConfigBuilder {
b.config.Core.BetaVirtuous = virtuous
b.config.Core.BetaRogue = rogue
return b
}
// WithNumParties sets the validator count and computes 2/3+1 threshold.
func (b *ConfigBuilder) WithNumParties(n int) *ConfigBuilder {
b.config.Threshold = DefaultThresholdParams(n)
return b
}
// WithThreshold sets an explicit threshold (overrides default 2/3+1).
func (b *ConfigBuilder) WithThreshold(threshold int) *ConfigBuilder {
b.config.Threshold.Threshold = threshold
return b
}
// WithQuorum sets the quorum fraction as numerator/denominator.
func (b *ConfigBuilder) WithQuorum(num, denom uint64) *ConfigBuilder {
b.config.Quorum.Numerator = num
b.config.Quorum.Denominator = denom
return b
}
// WithPollInterval sets the polling interval.
func (b *ConfigBuilder) WithPollInterval(d time.Duration) *ConfigBuilder {
b.config.Runtime.PollInterval = d
return b
}
// WithQueryTimeout sets the query timeout.
func (b *ConfigBuilder) WithQueryTimeout(d time.Duration) *ConfigBuilder {
b.config.Runtime.QueryTimeout = d
return b
}
// WithFinalityChannelSize sets the finality channel buffer size.
func (b *ConfigBuilder) WithFinalityChannelSize(size int) *ConfigBuilder {
b.config.Runtime.FinalityChannelSize = size
return b
}
// Build validates and returns the configuration.
func (b *ConfigBuilder) Build() (Config, error) {
if err := b.config.Validate(); err != nil {
return Config{}, err
}
return b.config, nil
}
// MustBuild validates and returns the configuration, panicking on error.
// Use only in tests or when configuration is known to be valid.
func (b *ConfigBuilder) MustBuild() Config {
cfg, err := b.Build()
if err != nil {
panic(fmt.Sprintf("invalid config: %v", err))
}
return cfg
}
-434
View File
@@ -1,434 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"testing"
"time"
)
func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
if err := cfg.Validate(); err != nil {
t.Fatalf("default config should be valid: %v", err)
}
// Verify defaults match documentation
if cfg.Core.K != 20 {
t.Errorf("expected K=20, got %d", cfg.Core.K)
}
if cfg.Core.Alpha != 0.8 {
t.Errorf("expected Alpha=0.8, got %f", cfg.Core.Alpha)
}
if cfg.Core.BetaVirtuous != 15 {
t.Errorf("expected BetaVirtuous=15, got %d", cfg.Core.BetaVirtuous)
}
if cfg.Core.BetaRogue != 20 {
t.Errorf("expected BetaRogue=20, got %d", cfg.Core.BetaRogue)
}
if cfg.Quorum.Numerator != 2 || cfg.Quorum.Denominator != 3 {
t.Errorf("expected 2/3 quorum, got %d/%d", cfg.Quorum.Numerator, cfg.Quorum.Denominator)
}
}
func TestCoreParamsValidation(t *testing.T) {
tests := []struct {
name string
params CoreParams
wantErr bool
}{
{
name: "valid defaults",
params: DefaultCoreParams(),
wantErr: false,
},
{
name: "zero K",
params: CoreParams{K: 0, Alpha: 0.8, BetaVirtuous: 15, BetaRogue: 20},
wantErr: true,
},
{
name: "negative K",
params: CoreParams{K: -1, Alpha: 0.8, BetaVirtuous: 15, BetaRogue: 20},
wantErr: true,
},
{
name: "alpha zero",
params: CoreParams{K: 20, Alpha: 0, BetaVirtuous: 15, BetaRogue: 20},
wantErr: true,
},
{
name: "alpha greater than 1",
params: CoreParams{K: 20, Alpha: 1.5, BetaVirtuous: 15, BetaRogue: 20},
wantErr: true,
},
{
name: "alpha exactly 1",
params: CoreParams{K: 20, Alpha: 1.0, BetaVirtuous: 15, BetaRogue: 20},
wantErr: false,
},
{
name: "beta virtuous zero",
params: CoreParams{K: 20, Alpha: 0.8, BetaVirtuous: 0, BetaRogue: 20},
wantErr: true,
},
{
name: "beta rogue less than virtuous",
params: CoreParams{K: 20, Alpha: 0.8, BetaVirtuous: 20, BetaRogue: 15},
wantErr: true,
},
{
name: "beta exceeds K",
params: CoreParams{K: 10, Alpha: 0.8, BetaVirtuous: 15, BetaRogue: 20},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.params.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestAlphaThreshold(t *testing.T) {
tests := []struct {
k int
alpha float64
want int
}{
{k: 20, alpha: 0.8, want: 16}, // 20 * 0.8 = 16
{k: 20, alpha: 0.51, want: 11}, // ceil(10.2) = 11
{k: 10, alpha: 0.67, want: 7}, // ceil(6.7) = 7
{k: 5, alpha: 1.0, want: 5}, // 5 * 1.0 = 5
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
p := CoreParams{K: tt.k, Alpha: tt.alpha, BetaVirtuous: 1, BetaRogue: 1}
got := p.AlphaThreshold()
if got != tt.want {
t.Errorf("AlphaThreshold(%d, %f) = %d, want %d", tt.k, tt.alpha, got, tt.want)
}
})
}
}
func TestThresholdParamsValidation(t *testing.T) {
tests := []struct {
name string
params ThresholdParams
wantErr bool
}{
{
name: "valid 3 of 5",
params: ThresholdParams{NumParties: 5, Threshold: 3},
wantErr: false,
},
{
name: "valid 4 of 5",
params: ThresholdParams{NumParties: 5, Threshold: 4},
wantErr: false,
},
{
name: "valid 2 of 3 minimum",
params: ThresholdParams{NumParties: 3, Threshold: 2},
wantErr: false,
},
{
name: "too few parties",
params: ThresholdParams{NumParties: 2, Threshold: 2},
wantErr: true,
},
{
name: "threshold too low",
params: ThresholdParams{NumParties: 5, Threshold: 1},
wantErr: true,
},
{
name: "threshold exceeds parties",
params: ThresholdParams{NumParties: 5, Threshold: 6},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.params.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestDefaultThresholdParams(t *testing.T) {
tests := []struct {
parties int
wantThreshold int
}{
{parties: 3, wantThreshold: 3}, // 2/3 of 3 = 2, +1 = 3
{parties: 4, wantThreshold: 3}, // 2/3 of 4 = 2, +1 = 3
{parties: 5, wantThreshold: 4}, // 2/3 of 5 = 3, +1 = 4
{parties: 10, wantThreshold: 7}, // 2/3 of 10 = 6, +1 = 7
{parties: 21, wantThreshold: 15}, // 2/3 of 21 = 14, +1 = 15
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
p := DefaultThresholdParams(tt.parties)
if p.Threshold != tt.wantThreshold {
t.Errorf("DefaultThresholdParams(%d).Threshold = %d, want %d",
tt.parties, p.Threshold, tt.wantThreshold)
}
if err := p.Validate(); err != nil {
t.Errorf("DefaultThresholdParams(%d) produced invalid params: %v", tt.parties, err)
}
})
}
}
func TestQuorumParamsValidation(t *testing.T) {
tests := []struct {
name string
params QuorumParams
wantErr bool
}{
{
name: "valid 2/3",
params: QuorumParams{Numerator: 2, Denominator: 3},
wantErr: false,
},
{
name: "valid 1/2",
params: QuorumParams{Numerator: 1, Denominator: 2},
wantErr: false,
},
{
name: "valid 1/1 (unanimous)",
params: QuorumParams{Numerator: 1, Denominator: 1},
wantErr: false,
},
{
name: "zero denominator",
params: QuorumParams{Numerator: 2, Denominator: 0},
wantErr: true,
},
{
name: "numerator exceeds denominator",
params: QuorumParams{Numerator: 4, Denominator: 3},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.params.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestQuorumIsMet(t *testing.T) {
q := QuorumParams{Numerator: 2, Denominator: 3} // 2/3 = 66.67%
// Note: integer math: 100 * 2 / 3 = 66 (floor division)
tests := []struct {
signerWeight uint64
totalWeight uint64
want bool
}{
{signerWeight: 67, totalWeight: 100, want: true}, // 67 >= 66
{signerWeight: 66, totalWeight: 100, want: true}, // 66 >= 66 (floor division)
{signerWeight: 65, totalWeight: 100, want: false}, // 65 < 66
{signerWeight: 100, totalWeight: 100, want: true}, // 100 >= 66
{signerWeight: 0, totalWeight: 100, want: false}, // 0 < 66
{signerWeight: 2, totalWeight: 3, want: true}, // 2 >= 2 (3*2/3=2)
{signerWeight: 1, totalWeight: 3, want: false}, // 1 < 2
}
for _, tt := range tests {
got := q.IsMet(tt.signerWeight, tt.totalWeight)
if got != tt.want {
t.Errorf("IsMet(%d, %d) = %v, want %v", tt.signerWeight, tt.totalWeight, got, tt.want)
}
}
}
func TestRuntimeConfigValidation(t *testing.T) {
tests := []struct {
name string
config RuntimeConfig
wantErr bool
}{
{
name: "valid defaults",
config: DefaultRuntimeConfig(),
wantErr: false,
},
{
name: "zero poll interval",
config: RuntimeConfig{
PollInterval: 0,
QueryTimeout: time.Second,
},
wantErr: true,
},
{
name: "negative poll interval",
config: RuntimeConfig{
PollInterval: -time.Millisecond,
QueryTimeout: time.Second,
},
wantErr: true,
},
{
name: "query timeout less than poll interval",
config: RuntimeConfig{
PollInterval: time.Second,
QueryTimeout: 100 * time.Millisecond,
},
wantErr: true,
},
{
name: "negative channel size",
config: RuntimeConfig{
PollInterval: 250 * time.Millisecond,
QueryTimeout: 2 * time.Second,
FinalityChannelSize: -1,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.config.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestConfigBuilder(t *testing.T) {
// Test fluent API
cfg, err := NewConfigBuilder().
WithK(25).
WithAlpha(0.75).
WithBeta(18, 22).
WithNumParties(10).
WithQuorum(3, 4). // 75%
WithPollInterval(500 * time.Millisecond).
WithQueryTimeout(5 * time.Second).
Build()
if err != nil {
t.Fatalf("Build() error = %v", err)
}
if cfg.Core.K != 25 {
t.Errorf("K = %d, want 25", cfg.Core.K)
}
if cfg.Core.Alpha != 0.75 {
t.Errorf("Alpha = %f, want 0.75", cfg.Core.Alpha)
}
if cfg.Core.BetaVirtuous != 18 {
t.Errorf("BetaVirtuous = %d, want 18", cfg.Core.BetaVirtuous)
}
if cfg.Core.BetaRogue != 22 {
t.Errorf("BetaRogue = %d, want 22", cfg.Core.BetaRogue)
}
if cfg.Threshold.NumParties != 10 {
t.Errorf("NumParties = %d, want 10", cfg.Threshold.NumParties)
}
if cfg.Threshold.Threshold != 7 { // 2/3 of 10 + 1 = 7
t.Errorf("Threshold = %d, want 7", cfg.Threshold.Threshold)
}
if cfg.Quorum.Numerator != 3 || cfg.Quorum.Denominator != 4 {
t.Errorf("Quorum = %d/%d, want 3/4", cfg.Quorum.Numerator, cfg.Quorum.Denominator)
}
if cfg.Runtime.PollInterval != 500*time.Millisecond {
t.Errorf("PollInterval = %v, want 500ms", cfg.Runtime.PollInterval)
}
}
func TestConfigBuilderWithExplicitThreshold(t *testing.T) {
cfg, err := NewConfigBuilder().
WithNumParties(10).
WithThreshold(5). // Override default 7
Build()
if err != nil {
t.Fatalf("Build() error = %v", err)
}
if cfg.Threshold.Threshold != 5 {
t.Errorf("Threshold = %d, want 5", cfg.Threshold.Threshold)
}
}
func TestConfigBuilderValidationError(t *testing.T) {
_, err := NewConfigBuilder().
WithK(-1). // Invalid
Build()
if err == nil {
t.Error("Build() should return error for invalid K")
}
}
func TestConfigBuilderMustBuildPanics(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("MustBuild() should panic on invalid config")
}
}()
NewConfigBuilder().WithK(-1).MustBuild()
}
func TestConfigBuilderMustBuildSuccess(t *testing.T) {
// Should not panic
cfg := NewConfigBuilder().MustBuild()
if err := cfg.Validate(); err != nil {
t.Errorf("MustBuild() produced invalid config: %v", err)
}
}
// TestConfigImmutability documents that Config values are immutable after creation.
func TestConfigImmutability(t *testing.T) {
cfg := DefaultConfig()
// These are value types, so modifications don't affect the original
core := cfg.Core
core.K = 999
if cfg.Core.K == 999 {
t.Error("Config.Core should be immutable (value copy)")
}
}
// BenchmarkQuorumCheck benchmarks the quorum check operation.
func BenchmarkQuorumCheck(b *testing.B) {
q := DefaultQuorumParams()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = q.IsMet(70, 100)
}
}
// BenchmarkConfigValidation benchmarks config validation.
func BenchmarkConfigValidation(b *testing.B) {
cfg := DefaultConfig()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = cfg.Validate()
}
}
-306
View File
@@ -1,306 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"testing"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
)
// --- Config edge cases ---
func TestDefaultThresholdParamsSmall(t *testing.T) {
// numParties=1: threshold clamped to numParties
p := DefaultThresholdParams(1)
if p.Threshold != 1 {
t.Errorf("expected threshold 1 for 1 party, got %d", p.Threshold)
}
// numParties=2: 2/3*2 + 1 = 2, min is 2
p = DefaultThresholdParams(2)
if p.Threshold != 2 {
t.Errorf("expected threshold 2, got %d", p.Threshold)
}
// numParties=3: 2/3*3 + 1 = 3
p = DefaultThresholdParams(3)
if p.Threshold != 3 {
t.Errorf("expected threshold 3, got %d", p.Threshold)
}
}
func TestQuorumParamsValidate(t *testing.T) {
p := DefaultQuorumParams()
if err := p.Validate(); err != nil {
t.Errorf("default quorum should be valid: %v", err)
}
p = QuorumParams{Numerator: 1, Denominator: 0}
if err := p.Validate(); err == nil {
t.Error("zero denominator should be invalid")
}
p = QuorumParams{Numerator: 4, Denominator: 3}
if err := p.Validate(); err == nil {
t.Error("num > denom should be invalid")
}
}
func TestQuorumParamsIsMet(t *testing.T) {
p := QuorumParams{Numerator: 2, Denominator: 3}
if !p.IsMet(200, 300) {
t.Error("200/300 should meet 2/3 quorum")
}
if p.IsMet(199, 300) {
t.Error("199/300 should not meet 2/3 quorum")
}
}
func TestQuorumParamsRequiredWeight(t *testing.T) {
p := QuorumParams{Numerator: 2, Denominator: 3}
if p.RequiredWeight(300) != 200 {
t.Errorf("expected 200, got %d", p.RequiredWeight(300))
}
}
func TestConfigBuilderWithFinalityChannelSize(t *testing.T) {
cfg, err := NewConfigBuilder().
WithThreshold(3).
WithFinalityChannelSize(256).
Build()
if err != nil {
t.Fatalf("build failed: %v", err)
}
if cfg.Runtime.FinalityChannelSize != 256 {
t.Errorf("expected 256, got %d", cfg.Runtime.FinalityChannelSize)
}
}
func TestThresholdParamsValidateEdge(t *testing.T) {
p := ThresholdParams{NumParties: 3, Threshold: 5}
if err := p.Validate(); err == nil {
t.Error("threshold > parties should be invalid")
}
p = ThresholdParams{NumParties: 3, Threshold: 0}
if err := p.Validate(); err == nil {
t.Error("threshold 0 should be invalid")
}
}
// --- Quasar lifecycle ---
func TestQuasarGetCoreGetCorona(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
if q.GetCore() == nil {
t.Error("GetCore should not return nil")
}
if q.GetCorona() != nil {
t.Error("Corona should be nil before initialization")
}
}
func TestQuasarSetGetFinalized(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
blockID := ids.GenerateTestID()
finality := &QuantumFinality{
BlockID: blockID,
PChainHeight: 42,
Timestamp: time.Now(),
}
q.SetFinalized(blockID, finality)
got, ok := q.GetFinalized(blockID)
if !ok {
t.Fatal("should find finality record")
}
if got.PChainHeight != 42 {
t.Errorf("height mismatch: %d", got.PChainHeight)
}
_, ok = q.GetFinalized(ids.GenerateTestID())
if ok {
t.Error("should not find non-existent finality")
}
}
func TestQuasarGetConfig(t *testing.T) {
q, err := NewQuasar(log.Noop(), 3, 2, 3)
if err != nil {
t.Fatal(err)
}
threshold, qNum, qDen := q.GetConfig()
if threshold != 3 {
t.Errorf("expected threshold 3, got %d", threshold)
}
if qNum != 2 || qDen != 3 {
t.Errorf("expected quorum 2/3, got %d/%d", qNum, qDen)
}
}
func TestQuasarIsRunning(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
if q.IsRunning() {
t.Error("should not be running before Start")
}
}
func TestQuasarCheckQuorum(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
if !q.CheckQuorum(200, 300) {
t.Error("200/300 should meet 2/3 quorum")
}
if q.CheckQuorum(100, 300) {
t.Error("100/300 should not meet 2/3 quorum")
}
}
func TestQuasarCreateMessage(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
event := FinalityEvent{
BlockID: ids.GenerateTestID(),
Height: 100,
}
msg := q.CreateMessage(event)
if len(msg) == 0 {
t.Error("message should not be empty")
}
}
func TestQuasarTotalWeight(t *testing.T) {
q, err := NewQuasar(log.Noop(), 2, 2, 3)
if err != nil {
t.Fatal(err)
}
validators := []ValidatorState{
{Weight: 100, Active: true},
{Weight: 200, Active: true},
{Weight: 50, Active: true},
}
total := q.TotalWeight(validators)
if total != 350 {
t.Errorf("expected 350, got %d", total)
}
// Inactive validators should not count
validators[2].Active = false
total = q.TotalWeight(validators)
if total != 300 {
t.Errorf("expected 300 without inactive, got %d", total)
}
}
// --- BLS Signature ---
func TestBLSSignature(t *testing.T) {
signers := []ids.NodeID{ids.GenerateTestNodeID(), ids.GenerateTestNodeID()}
sig := NewBLSSignature([]byte("aggregated-sig"), signers)
if sig.Type() != SignatureTypeBLS {
t.Error("wrong type")
}
if len(sig.Bytes()) == 0 {
t.Error("bytes should not be empty")
}
if len(sig.Signers()) != 2 {
t.Errorf("expected 2 signers, got %d", len(sig.Signers()))
}
}
// --- CoronaCoordinator ---
func TestCoronaCoordinatorSignNotInitialized(t *testing.T) {
rc, _ := NewCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 3, Threshold: 2})
_, err := rc.Sign([]byte("msg"))
if err == nil {
t.Error("should fail when not initialized")
}
}
func TestCoronaCoordinatorVerifyNotInitialized(t *testing.T) {
rc, _ := NewCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 3, Threshold: 2})
if rc.Verify([]byte("msg"), nil) {
t.Error("should return false when not initialized")
}
}
func TestCoronaCoordinatorTestMode(t *testing.T) {
rc, _ := NewTestCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 3, Threshold: 2})
validators := []ids.NodeID{ids.GenerateTestNodeID()}
rc.Initialize(validators)
sig, err := rc.Sign([]byte("test-message"))
if err != nil {
t.Fatalf("sign failed: %v", err)
}
if sig == nil {
t.Fatal("signature should not be nil")
}
if !rc.Verify([]byte("test-message"), sig) {
t.Error("should verify in testing mode")
}
}
func TestCoronaCoordinatorNotTestMode(t *testing.T) {
rc, _ := NewCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 3, Threshold: 2})
rc.Initialize([]ids.NodeID{ids.GenerateTestNodeID()})
_, err := rc.Sign([]byte("msg"))
if err == nil {
t.Error("should fail when not in testing mode")
}
sig := NewCoronaSignature([]byte("fake"), nil)
if rc.Verify([]byte("msg"), sig) {
t.Error("should return false when not in testing mode")
}
}
func TestCoronaCoordinatorStats(t *testing.T) {
rc, _ := NewCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 3, Threshold: 2})
s := rc.Stats()
if s.NumParties != 3 {
t.Errorf("expected 3 parties, got %d", s.NumParties)
}
if s.Initialized {
t.Error("should not be initialized")
}
}
func TestCoronaCoordinatorThresholdNumParties(t *testing.T) {
rc, _ := NewCoronaCoordinator(log.Noop(), CoronaConfig{NumParties: 5, Threshold: 3})
if rc.Threshold() != 3 {
t.Errorf("expected threshold 3, got %d", rc.Threshold())
}
if rc.NumParties() != 5 {
t.Errorf("expected 5 parties, got %d", rc.NumParties())
}
}
-59
View File
@@ -1,59 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
/*
Package quasar provides hybrid quantum-safe consensus finality.
# Overview
Quasar is the gravitational center of Lux consensus, binding P-Chain
(BLS signatures) and Q-Chain (Corona post-quantum threshold) into
unified hybrid finality across all Lux networks.
# Architecture
All validators maintain both keypairs:
- BLS keypair: Aggregate signatures (classical, fast)
- Corona keypair: Threshold signatures (post-quantum, 2-round)
Both signature paths run in parallel:
Block arrives
|
+-- BLS PATH ----------+-- CORONA PATH --------+
| All validators | Round 1: commitments |
| sign with BLS | Round 2: partials |
| Aggregate (96B) | Combine threshold sig |
+----------------------+-------------------------+
|
HYBRID PROOF
BLS + Corona combined
|
QUANTUM FINALITY
# Vote Flow
Validators cast votes (wire format: Chits) for proposed blocks. The
Quasar engine collects these votes and produces finality proofs when:
- 2/3+ validator weight signed via BLS
- t-of-n validators completed Corona threshold signing
# Signature Types
The package defines several signature types:
- SignatureTypeBLS: Classical BLS signatures
- SignatureTypeCorona: Post-quantum threshold
- SignatureTypeQuasar: Hybrid combining both
- SignatureTypeMLDSA: ML-DSA fallback
# Components
Quasar: Main consensus hub coordinating both signature paths.
CoronaCoordinator: Manages the 2-round threshold signing protocol
for post-quantum security.
QuantumFinality: Represents a block that achieved hybrid finality with
both BLS and Corona proofs.
*/
package quasar
+38
View File
@@ -0,0 +1,38 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import "errors"
// Typed, fail-closed errors. Every one is returned (never swallowed) and, when
// surfaced from the accept hook post-activation, halts finalization rather than
// accepting a checkpoint without valid post-quantum evidence.
var (
// ErrFinalityCertMissing — a checkpoint was finalized post-activation but no
// QuasarCert is available for it (the producer has not delivered one).
ErrFinalityCertMissing = errors.New("quasar: finality cert missing for checkpoint")
// ErrFinalityCertMismatch — a cert exists but does not bind the finalized
// block (chain/height/block/state mismatch). Anti-replay.
ErrFinalityCertMismatch = errors.New("quasar: finality cert does not bind the finalized block")
// ErrFinalityCertInvalid — the cert is bound correctly but failed consensus
// verification (policy, validator-set root, or a leg signature).
ErrFinalityCertInvalid = errors.New("quasar: finality cert failed verification")
// ErrValidatorSetUnavailable — no committed validator set for the cert's
// epoch (the verifier cannot resolve the per-leg verification keys).
ErrValidatorSetUnavailable = errors.New("quasar: validator set unavailable for epoch")
// ErrPolicyUnavailable — the gate has no configured policy.
ErrPolicyUnavailable = errors.New("quasar: policy unavailable")
// ErrPolicyMismatch — the cert's PolicyID is not the configured policy. A
// cert cannot select its own (weaker) posture.
ErrPolicyMismatch = errors.New("quasar: cert policy id does not match configured policy")
// ErrGateMisconfigured — the gate is activated at a checkpoint but has no
// cert store or validator provider. Fail closed rather than panic.
ErrGateMisconfigured = errors.New("quasar: gate activated but missing store or validator provider")
)
+268
View File
@@ -0,0 +1,268 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package quasar is the node-side integration of the luxfi/consensus Quasar
// post-quantum finality-certificate layer.
//
// luxd finalizes blocks on the classical Snow/Avalanche path (fast, every
// block). On top, at CHECKPOINTS (epoch boundaries — NOT every block), a sampled
// committee produces a QuasarCert over the finalized digest and validators
// VERIFY it. This package wires the VERIFY half: it consumes
// github.com/luxfi/consensus/protocol/quasar.VerifyConsensusCert as an OPTIONAL,
// FORWARD-DATED, DORMANT-BY-DEFAULT check in the block-accept path.
//
// # Safety contract
//
// The forward-dated dormant activation is the whole reason this package has the
// shape it does:
//
// - Pre-activation (the default): VerifyAccepted is a pure no-op. Classical
// Snow finality is UNCHANGED. A nil *Gate, a zero Gate, or an unset
// activation height all mean "dormant" — zero behavior change.
// - Post-activation (owner sets Activation.Height to a real, forward-dated
// height): at every checkpoint height the gate REQUIRES a valid QuasarCert
// bound to the just-finalized block and FAILS CLOSED — a missing or invalid
// cert returns an error from Accept(), halting the chain rather than
// finalizing a checkpoint without post-quantum evidence.
//
// Activation is therefore a deliberate switch the owner flips only AFTER the
// cert PRODUCER (the per-validator committee signer) is live and certs flow at
// the checkpoint cadence — otherwise every checkpoint would halt. See
// producer.go.
//
// # Default posture
//
// HYBRID_PQ = Beam(BLS) ∧ Pulsar (standard FIPS-204 threshold ML-DSA), at
// checkpoint cadence. Per the measured policy-tier benchmarks, Pulsar verify
// (~140µs) is cheaper than BLS itself and the cert is compact (~27KB) — the
// right default production finality posture. STRICT_DUAL_PQ (∧ Corona) and the
// POLARIS tiers (∧ Magnetar) are configurable for stricter mainnet finality.
package quasar
import (
"fmt"
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// ActivationConfig is the forward-dated activation switch.
//
// The zero value is DORMANT: Height == 0 means "never activate" and the gate is
// a no-op for every block. This mirrors the genesis upgrade discipline (a
// far-future / unset activation point cannot affect live finality).
//
// Activation is by HEIGHT ONLY, deliberately. A block height is agreed by
// consensus, so every honest validator enforces PQ finality at exactly the SAME
// checkpoints — there is no node-local decision. (A wall-clock gate would split
// finalization across validators with skewed clocks: some halting on a missing
// cert while others finalize without one. Timestamp-based forward-dating is
// expressed by choosing the activation HEIGHT at the target time.)
type ActivationConfig struct {
// Height is the block height at and above which PQ-finality verification is
// enforced at checkpoints. 0 == dormant (never).
Height uint64
}
// dormant reports whether the activation is unset (the default — never enforce).
func (a ActivationConfig) dormant() bool { return a.Height == 0 }
// active reports whether enforcement is live for a block at the given height.
// Deterministic: height-only, no wall clock. Dormant activation is never active.
func (a ActivationConfig) active(height uint64) bool {
return a.Height != 0 && height >= a.Height
}
// DefaultCheckpointInterval is the default checkpoint cadence in blocks. PQ
// certs ride epoch-boundary checkpoints, never every block (Magnetar sign is
// checkpoint-only; even the cheap Pulsar sign is checkpoint cadence). The owner
// overrides this to match the producer's cadence at activation time.
const DefaultCheckpointInterval uint64 = 256
// DefaultMode is the default Quasar posture: HYBRID_PQ (Beam ∧ Pulsar).
const DefaultMode = qcert.PolicyHybridPQCheckpoint
// Config is the node-surfaced PQ-finality configuration. Its zero value is
// dormant + HYBRID_PQ + default cadence.
type Config struct {
// ChainID is THIS chain's numeric identifier (the sovereign/EVM chain id),
// bound into every cert and checked against it. A per-chain constant sourced
// from chain config at gate construction — NOT pulled from a block, because
// the proposervm layer carries the 32-byte validator-set id, not the numeric
// chain id. Inert while dormant.
ChainID uint32
// Activation is the forward-dated dormant switch. Zero => dormant.
Activation ActivationConfig
// Mode is the Quasar evidence posture. Zero => DefaultMode (HYBRID_PQ).
Mode qcert.QuasarEvidenceMode
// MLDSAParam selects the ML-DSA parameter set for the Pulsar leg. 0 =>
// ML-DSA-65 (the consensus default).
MLDSAParam uint8
// Threshold is the BFT quorum floor (minimum aggregate signer weight) every
// leg's evidence must establish.
Threshold uint64
// CheckpointInterval is the checkpoint cadence in blocks. 0 =>
// DefaultCheckpointInterval.
CheckpointInterval uint64
}
// Checkpoint is the finalized-block position the accept hook hands the gate. It
// is the binding the cert must match (anti-replay): a valid cert for a DIFFERENT
// block must never satisfy THIS checkpoint. The chain id is gate-level config,
// not a per-block field.
type Checkpoint struct {
Epoch uint64
Height uint64
Round uint32
BlockID [32]byte
StateRoot [32]byte
}
// Gate enforces (or, dormant, ignores) PQ-finality at checkpoints. It is the
// single node-side seam between the classical accept path and the consensus
// Quasar verifier.
type Gate struct {
cfg Config
policy *qcert.QuasarEvidencePolicy
store CertStore
validators ValidatorSetProvider
}
// NewGate constructs a Gate. A Gate is meaningful even with a dormant Config:
// VerifyAccepted is a no-op until Activation.Height is set. store and validators
// are only consulted post-activation at checkpoints.
func NewGate(cfg Config, store CertStore, validators ValidatorSetProvider) *Gate {
mode := cfg.Mode
if mode == 0 {
mode = DefaultMode
}
if cfg.CheckpointInterval == 0 {
cfg.CheckpointInterval = DefaultCheckpointInterval
}
cfg.Mode = mode
return &Gate{
cfg: cfg,
policy: qcert.NewQuasarEvidencePolicy(mode, cfg.MLDSAParam, cfg.Threshold),
store: store,
validators: validators,
}
}
// VerifyAccepted is the accept-path hook and the SAFETY BOUNDARY.
//
// - g == nil OR dormant activation => returns nil immediately. This is the
// default and guarantees classical Snow finality is unchanged.
// - height below activation, or activation time not yet reached => nil.
// - not a checkpoint height => nil (certs ride checkpoints only).
// - checkpoint, activated => REQUIRE a valid cert bound to this block; FAIL
// CLOSED. A missing, mis-bound, or invalid cert is an error (the caller
// returns it from Accept, halting rather than finalizing without PQ
// evidence).
//
// It is intentionally nil-safe so the proposervm hook can call
// vm.quasarGate.VerifyAccepted(...) unconditionally with a nil gate.
func (g *Gate) VerifyAccepted(cp Checkpoint) error {
if g == nil || g.cfg.Activation.dormant() {
return nil
}
if !g.cfg.Activation.active(cp.Height) {
return nil
}
if !g.isCheckpoint(cp.Height) {
return nil
}
// Activated checkpoint: the gate MUST have its cert store + validator
// provider, or it cannot verify. Fail closed with a typed error rather than
// panic in the accept hook (a panic would halt the chain uncontrollably).
if g.store == nil || g.validators == nil {
return fmt.Errorf("%w: chain=%d height=%d", ErrGateMisconfigured, g.cfg.ChainID, cp.Height)
}
cert, ok := g.store.Lookup(g.cfg.ChainID, cp.Height, cp.BlockID)
if !ok || cert == nil {
return fmt.Errorf("%w: chain=%d height=%d block=%x", ErrFinalityCertMissing, g.cfg.ChainID, cp.Height, cp.BlockID[:8])
}
if err := bindCheck(cert, g.cfg.ChainID, cp); err != nil {
return err
}
vs, err := g.validators.ValidatorSet(g.cfg.ChainID, cert.Epoch)
if err != nil {
return fmt.Errorf("%w: chain=%d epoch=%d: %v", ErrValidatorSetUnavailable, g.cfg.ChainID, cert.Epoch, err)
}
if err := qcert.VerifyConsensusCert(policyStore{policy: g.policy}, vs, cert); err != nil {
return fmt.Errorf("%w: chain=%d height=%d: %v", ErrFinalityCertInvalid, g.cfg.ChainID, cp.Height, err)
}
return nil
}
// Activated reports whether enforcement is live for a block at the given height
// and the current wall clock. Used by the producer-request site to decide
// whether a cert is needed at a checkpoint.
func (g *Gate) Activated(height uint64) bool {
if g == nil {
return false
}
return g.cfg.Activation.active(height)
}
// IsCheckpoint reports whether the given height is a checkpoint under the gate's
// configured cadence. Exported so the producer-request site shares ONE cadence
// definition with the verify path (no second source of truth).
func (g *Gate) IsCheckpoint(height uint64) bool {
if g == nil {
return false
}
return g.isCheckpoint(height)
}
func (g *Gate) isCheckpoint(height uint64) bool {
iv := g.cfg.CheckpointInterval
if iv == 0 {
iv = DefaultCheckpointInterval
}
return height%iv == 0
}
// bindCheck pins the cert to the actual finalized block. Without this, a valid
// cert produced for a different (chain, height, block) could be replayed to
// satisfy this checkpoint. VerifyConsensusCert checks the cert's INTERNAL
// consistency and the validator-set/policy binding; bindCheck adds the external
// binding to THIS node's finalized position.
func bindCheck(cert *qcert.ConsensusCert, chainID uint32, cp Checkpoint) error {
if cert.ChainID != chainID {
return fmt.Errorf("%w: cert chain %d != finalized chain %d", ErrFinalityCertMismatch, cert.ChainID, chainID)
}
// Bind the epoch. The gate resolves the verification keys from the cert's
// epoch, so an UNBOUND epoch would let a cert signed under a DIFFERENT
// validator-set era (e.g. a compromised RETIRED committee's group key) certify
// the current block — nullifying KeyEra rotation as a blast-radius bound. The
// honest producer signs over Subject.Epoch == cp.Epoch, so honest certs match.
if cert.Epoch != cp.Epoch {
return fmt.Errorf("%w: cert epoch %d != finalized epoch %d", ErrFinalityCertMismatch, cert.Epoch, cp.Epoch)
}
if cert.Round != cp.Round {
return fmt.Errorf("%w: cert round %d != finalized round %d", ErrFinalityCertMismatch, cert.Round, cp.Round)
}
if cert.Height != cp.Height {
return fmt.Errorf("%w: cert height %d != finalized height %d", ErrFinalityCertMismatch, cert.Height, cp.Height)
}
if cert.BlockHash != cp.BlockID {
return fmt.Errorf("%w: cert block hash != finalized block id", ErrFinalityCertMismatch)
}
// StateRoot contract: at the proposervm layer the post-state root is
// committed TRANSITIVELY through BlockHash, so cp.StateRoot is zero and the
// cert MUST carry a zero StateRoot too. A non-zero cert StateRoot is rejected
// (no state to cross-check here) — the producer follow-on MUST emit
// StateRoot==0 at this layer; a chain that wants an explicit state binding
// plumbs cp.StateRoot AND signs it, and this check then enforces equality.
var zero [32]byte
if cert.StateRoot != zero && cert.StateRoot != cp.StateRoot {
return fmt.Errorf("%w: cert state root != finalized state root", ErrFinalityCertMismatch)
}
return nil
}
+270
View File
@@ -0,0 +1,270 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"context"
"errors"
"testing"
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// vsRoot is a fixed committed-validator-set root used across the tests.
var vsRoot = [48]byte{0x11, 0x22, 0x33, 0x44}
// testValidators is a ValidatorSet whose Root matches vsRoot, with non-empty
// (placeholder) HYBRID_PQ keys. The delegation test never reaches signature
// math, so the key bytes need only be non-empty.
func testValidators() *ValidatorSet {
return NewValidatorSet(vsRoot, 1, []byte("bls-agg-key"), []byte("pulsar-group-key"))
}
// newGate builds a gate with a tight cadence (checkpoint every 10 blocks) and
// the given forward-dated activation height. interval 10 keeps the heights in
// the tests readable.
func newGate(activationHeight uint64, store CertStore) *Gate {
return NewGate(Config{
ChainID: 1337,
Activation: ActivationConfig{Height: activationHeight},
Mode: DefaultMode, // HYBRID_PQ
Threshold: 100,
CheckpointInterval: 10,
}, store, StaticValidatorSetProvider{Set: testValidators()})
}
func checkpointAt(height uint64) Checkpoint {
return Checkpoint{
Epoch: 1,
Height: height,
BlockID: [32]byte{0xab, 0xcd, 0xef},
}
}
// TestDormantIsNoop — the default (Activation.Height == 0) is a pure no-op even
// at a checkpoint height with a poisoned store. This is the core safety
// property: pre-activation, classical Snow finality is unchanged.
func TestDormantIsNoop(t *testing.T) {
store := NewMemCertStore()
g := NewGate(Config{CheckpointInterval: 10}, store, StaticValidatorSetProvider{Set: testValidators()})
// height 10 is a checkpoint; no cert exists; yet dormant => nil.
if err := g.VerifyAccepted(checkpointAt(10)); err != nil {
t.Fatalf("dormant gate must be a no-op, got %v", err)
}
if g.Activated(10) {
t.Fatal("dormant gate must never report Activated")
}
}
// TestNilGateIsNoop — a nil *Gate is the wire-it-but-leave-it-off default; the
// proposervm hook calls VerifyAccepted on a possibly-nil gate.
func TestNilGateIsNoop(t *testing.T) {
var g *Gate
if err := g.VerifyAccepted(checkpointAt(10)); err != nil {
t.Fatalf("nil gate must be a no-op, got %v", err)
}
if g.Activated(10) || g.IsCheckpoint(10) {
t.Fatal("nil gate must report neither Activated nor IsCheckpoint")
}
}
// TestBelowActivationIsNoop — activated at height 100 but the block is at 10:
// below the forward-dated height => nil, even at a checkpoint with no cert.
func TestBelowActivationIsNoop(t *testing.T) {
g := newGate(100, NewMemCertStore())
if err := g.VerifyAccepted(checkpointAt(10)); err != nil {
t.Fatalf("below activation must be a no-op, got %v", err)
}
}
// TestNonCheckpointIsNoop — activated and at/above activation height, but the
// height is not a checkpoint => nil (certs ride checkpoints only).
func TestNonCheckpointIsNoop(t *testing.T) {
g := newGate(10, NewMemCertStore())
// height 15 is activated (>=10) but not a checkpoint (15 % 10 != 0).
if err := g.VerifyAccepted(checkpointAt(15)); err != nil {
t.Fatalf("non-checkpoint must be a no-op, got %v", err)
}
if !g.Activated(15) {
t.Fatal("height 15 should be activated")
}
if g.IsCheckpoint(15) {
t.Fatal("height 15 must not be a checkpoint")
}
}
// TestMissingCertFailsClosed — activated checkpoint with no cert in the store =>
// ErrFinalityCertMissing. Post-activation a checkpoint without PQ evidence must
// NOT finalize.
func TestMissingCertFailsClosed(t *testing.T) {
g := newGate(10, NewMemCertStore())
err := g.VerifyAccepted(checkpointAt(20))
if !errors.Is(err, ErrFinalityCertMissing) {
t.Fatalf("want ErrFinalityCertMissing, got %v", err)
}
}
// TestMismatchedCertRejected — a cert that does not bind the finalized block
// (wrong block id / height / chain) is rejected by bindCheck before any crypto.
// Anti-replay: a valid cert for a different block must not satisfy this one.
func TestMismatchedCertRejected(t *testing.T) {
// cp = checkpointAt(20) has Epoch 1, Round 0. Each case sets every binding
// field correctly EXCEPT the one named, so it fails at that field.
cases := []struct {
name string
cert *qcert.ConsensusCert
}{
{"wrong block", &qcert.ConsensusCert{ChainID: 1337, Epoch: 1, Height: 20, BlockHash: [32]byte{0x99}}},
{"wrong height", &qcert.ConsensusCert{ChainID: 1337, Epoch: 1, Height: 21, BlockHash: [32]byte{0xab, 0xcd, 0xef}}},
{"wrong chain", &qcert.ConsensusCert{ChainID: 7, Epoch: 1, Height: 20, BlockHash: [32]byte{0xab, 0xcd, 0xef}}},
{"wrong epoch", &qcert.ConsensusCert{ChainID: 1337, Epoch: 2, Height: 20, BlockHash: [32]byte{0xab, 0xcd, 0xef}}},
{"wrong round", &qcert.ConsensusCert{ChainID: 1337, Epoch: 1, Round: 1, Height: 20, BlockHash: [32]byte{0xab, 0xcd, 0xef}}},
{"wrong state root", &qcert.ConsensusCert{ChainID: 1337, Epoch: 1, Height: 20, BlockHash: [32]byte{0xab, 0xcd, 0xef}, StateRoot: [32]byte{0x55}}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
store := NewMemCertStore()
// Index it at the checkpoint's lookup key so Lookup returns it and
// bindCheck (not Lookup) does the rejecting.
store.certs[certKey{chainID: 1337, height: 20, blockID: [32]byte{0xab, 0xcd, 0xef}}] = tc.cert
g := newGate(10, store)
err := g.VerifyAccepted(checkpointAt(20))
if !errors.Is(err, ErrFinalityCertMismatch) {
t.Fatalf("want ErrFinalityCertMismatch, got %v", err)
}
})
}
}
// TestDelegatesToVerifier — a cert that BINDS correctly and passes the full
// ConsensusCert header path (version, policy load, required-legs root, validator
// -set root) but carries no signature evidence is rejected by the REAL
// consensus verifier, and the gate surfaces it as ErrFinalityCertInvalid. This
// proves the whole delegation chain is wired: policyStore + ValidatorSet +
// quasar.VerifyConsensusCert are reached with matching commitments — everything
// up to (but not including) the leg signature crypto, which needs the producer.
func TestDelegatesToVerifier(t *testing.T) {
cp := checkpointAt(20)
// Mirror the gate's posture to compute the header commitments the verifier
// pins (policy id + required-legs root). policyID and required legs derive
// from the mode + ML-DSA param, which match the gate's config.
pol := qcert.NewQuasarEvidencePolicy(DefaultMode, 0, 100)
cert := &qcert.ConsensusCert{
Version: 1,
ChainID: 1337, // must equal the gate's configured ChainID
Epoch: cp.Epoch,
Height: cp.Height,
BlockHash: cp.BlockID,
PolicyID: pol.EvidencePolicyID(),
RequiredLegsRoot: qcert.HashRequiredLegs(pol.RequiredLegs()),
ValidatorSetRoot: vsRoot,
// Evidence intentionally empty: the verifier must reject a required leg
// with no evidence (deepest deterministic failure without real crypto).
}
store := NewMemCertStore()
store.Put(cert)
g := newGate(10, store)
err := g.VerifyAccepted(cp)
if !errors.Is(err, ErrFinalityCertInvalid) {
t.Fatalf("want ErrFinalityCertInvalid (delegated), got %v", err)
}
}
// TestValidatorSetUnavailable — a bound cert at an activated checkpoint, but the
// provider has no set for the epoch => ErrValidatorSetUnavailable (fail closed).
func TestValidatorSetUnavailable(t *testing.T) {
cp := checkpointAt(20)
// Bind correctly (epoch included) so the cert passes bindCheck and the
// failure is specifically the unavailable validator set.
cert := &qcert.ConsensusCert{Version: 1, ChainID: 1337, Epoch: cp.Epoch, Height: cp.Height, BlockHash: cp.BlockID}
store := NewMemCertStore()
store.Put(cert)
g := NewGate(Config{
ChainID: 1337,
Activation: ActivationConfig{Height: 10},
CheckpointInterval: 10,
}, store, StaticValidatorSetProvider{Set: nil}) // provider present, no set
err := g.VerifyAccepted(cp)
if !errors.Is(err, ErrValidatorSetUnavailable) {
t.Fatalf("want ErrValidatorSetUnavailable, got %v", err)
}
}
// TestGateMisconfiguredFailsClosed — an activated gate at a checkpoint with no
// cert store (or no validator provider) fails closed with a typed error rather
// than panicking in the accept hook.
func TestGateMisconfiguredFailsClosed(t *testing.T) {
g := NewGate(Config{
ChainID: 1337,
Activation: ActivationConfig{Height: 10},
CheckpointInterval: 10,
}, nil, nil) // no store, no validators
if err := g.VerifyAccepted(checkpointAt(20)); !errors.Is(err, ErrGateMisconfigured) {
t.Fatalf("want ErrGateMisconfigured, got %v", err)
}
// dormant misconfigured gate is still a no-op (guard is post-activation).
gd := NewGate(Config{ChainID: 1337, CheckpointInterval: 10}, nil, nil)
if err := gd.VerifyAccepted(checkpointAt(20)); err != nil {
t.Fatalf("dormant gate must be a no-op even if misconfigured, got %v", err)
}
}
// --- producer scaffolding ---
type stubProducer struct {
cert *qcert.ConsensusCert
hits int
}
func (s *stubProducer) Produce(_ context.Context, _ Subject) (*qcert.ConsensusCert, error) {
s.hits++
return s.cert, nil
}
// TestMaybeProduceVerifyOnlyByDefault — a nil producer is the verify-only
// default: MaybeProduce short-circuits to (nil, nil), never panics.
func TestMaybeProduceVerifyOnlyByDefault(t *testing.T) {
g := newGate(10, NewMemCertStore())
cert, err := g.MaybeProduce(context.Background(), nil, checkpointAt(20))
if err != nil || cert != nil {
t.Fatalf("nil producer must yield (nil,nil), got cert=%v err=%v", cert, err)
}
}
// TestMaybeProduceDormant — even with a producer wired, a dormant gate produces
// nothing (the producer is brought up before activation is forward-dated).
func TestMaybeProduceDormant(t *testing.T) {
store := NewMemCertStore()
g := NewGate(Config{CheckpointInterval: 10}, store, StaticValidatorSetProvider{Set: testValidators()})
p := &stubProducer{cert: &qcert.ConsensusCert{}}
cert, err := g.MaybeProduce(context.Background(), p, checkpointAt(20))
if err != nil || cert != nil {
t.Fatalf("dormant gate must not produce, got cert=%v err=%v", cert, err)
}
if p.hits != 0 {
t.Fatalf("producer must not be called while dormant, hits=%d", p.hits)
}
}
// TestMaybeProduceActiveCheckpoint — wired producer + activated checkpoint =>
// the producer is asked for the cert.
func TestMaybeProduceActiveCheckpoint(t *testing.T) {
g := newGate(10, NewMemCertStore())
want := &qcert.ConsensusCert{ChainID: 1337, Height: 20}
p := &stubProducer{cert: want}
got, err := g.MaybeProduce(context.Background(), p, checkpointAt(20))
if err != nil {
t.Fatalf("unexpected err %v", err)
}
if got != want || p.hits != 1 {
t.Fatalf("producer not invoked as expected: got=%v hits=%d", got, p.hits)
}
// non-checkpoint height must not invoke the producer
p2 := &stubProducer{cert: want}
if _, _ = g.MaybeProduce(context.Background(), p2, checkpointAt(15)); p2.hits != 0 {
t.Fatalf("producer invoked at non-checkpoint, hits=%d", p2.hits)
}
}
-627
View File
@@ -1,627 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"errors"
"fmt"
"sync"
"sync/atomic"
"time"
"github.com/luxfi/accel"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/mldsa"
)
// GPUVerifyPipeline fuses multiple cryptographic verification operations into
// a single GPU session, sharing GPU memory across all verification types.
//
// Instead of sequential: BLS verify -> Corona verify -> ZK verify -> ML-DSA verify
// GPU pipeline: one session, parallel streams, shared memory allocation
//
// This is the ML-DSA rollup pattern:
// - BLS aggregate signature (classical fast path)
// - Corona threshold signature (PQ safe path)
// - ZK rollup batch proof (state transition validity)
// - N x ML-DSA signatures (per-tx PQ signatures)
//
// All execute on GPU in parallel using separate compute streams within one session.
type GPUVerifyPipeline struct {
// Stats (atomic for lock-free reads)
gpuVerifies uint64
cpuVerifies uint64
gpuTimeNs uint64
cpuTimeNs uint64
}
// NewGPUVerifyPipeline creates a new fused GPU verification pipeline.
func NewGPUVerifyPipeline() *GPUVerifyPipeline {
return &GPUVerifyPipeline{}
}
// BLSWork holds a batch of BLS signatures to verify.
type BLSWork struct {
Messages [][]byte // [N, msg_len]
Signatures [][]byte // [N, 96] G2 points
PubKeys [][]byte // [N, 48] G1 points
}
// CoronaWork holds a batch of Corona threshold signatures to verify.
type CoronaWork struct {
Messages [][]byte // [N, msg_len]
Signatures [][]byte // [N, sig_len] threshold sigs
PubKeys [][]byte // [N, pk_len] ring public keys
}
// ZKWork holds a batch of ZK proofs to verify.
type ZKWork struct {
Scalars [][]byte // [M, N, scalar_size]
Bases [][]byte // [M, N, point_size]
}
// MLDSAWork holds a batch of ML-DSA signatures to verify.
type MLDSAWork struct {
Messages [][]byte // [N, msg_len]
Signatures [][]byte // [N, 3309] FIPS-204 ML-DSA-65 (3293 was the stale round-3 Dilithium3 size)
PubKeys [][]byte // [N, 1952] FIPS-204 ML-DSA-65
}
// BlockVerifyWork contains all verification batches for a single block.
type BlockVerifyWork struct {
BLS *BLSWork
Corona *CoronaWork
ZK *ZKWork
MLDSA *MLDSAWork
}
// BlockVerifyResult contains verification results for all batch types.
type BlockVerifyResult struct {
BLSValid []bool
CoronaValid []bool
ZKValid bool
MLDSAValid []bool
GPUUsed bool
BLSTime time.Duration
CoronaTime time.Duration
ZKTime time.Duration
MLDSATime time.Duration
TotalTime time.Duration
}
var (
ErrBLSSizeMismatch = errors.New("BLS batch size mismatch: messages, signatures, and pubkeys must have equal length")
ErrCoronaSizeMismatch = errors.New("Corona batch size mismatch: messages, signatures, and pubkeys must have equal length")
ErrZKSizeMismatch = errors.New("ZK batch size mismatch: scalars and bases must have equal length")
ErrMLDSASizeMismatch = errors.New("ML-DSA batch size mismatch: messages, signatures, and pubkeys must have equal length")
)
// VerifyBlock dispatches all verification work for a block through the GPU pipeline.
// Falls back to CPU verification when no GPU is available.
func (p *GPUVerifyPipeline) VerifyBlock(work *BlockVerifyWork) (*BlockVerifyResult, error) {
if work == nil {
return &BlockVerifyResult{}, nil
}
if err := validateWork(work); err != nil {
return nil, err
}
start := time.Now()
if accel.Available() {
result, err := p.verifyGPU(work)
if err == nil {
result.TotalTime = time.Since(start)
result.GPUUsed = true
atomic.AddUint64(&p.gpuVerifies, 1)
atomic.AddUint64(&p.gpuTimeNs, uint64(result.TotalTime))
return result, nil
}
// GPU failed, fall through to CPU
}
result := p.verifyCPU(work)
result.TotalTime = time.Since(start)
result.GPUUsed = false
atomic.AddUint64(&p.cpuVerifies, 1)
atomic.AddUint64(&p.cpuTimeNs, uint64(result.TotalTime))
return result, nil
}
// verifyGPU dispatches all 4 verification types through a single GPU session.
func (p *GPUVerifyPipeline) verifyGPU(work *BlockVerifyWork) (*BlockVerifyResult, error) {
sess, err := accel.NewSession()
if err != nil {
return nil, fmt.Errorf("GPU session: %w", err)
}
defer sess.Close()
result := &BlockVerifyResult{}
var mu sync.Mutex
var wg sync.WaitGroup
var firstErr atomic.Value
// BLS verification stream
if work.BLS != nil && len(work.BLS.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid, err := gpuBLSVerify(sess, work.BLS)
elapsed := time.Since(start)
if err != nil {
firstErr.CompareAndSwap(nil, err)
return
}
mu.Lock()
result.BLSValid = valid
result.BLSTime = elapsed
mu.Unlock()
}()
}
// Corona verification stream (uses DilithiumVerifyBatch on lattice ops)
if work.Corona != nil && len(work.Corona.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid, err := gpuCoronaVerify(sess, work.Corona)
elapsed := time.Since(start)
if err != nil {
firstErr.CompareAndSwap(nil, err)
return
}
mu.Lock()
result.CoronaValid = valid
result.CoronaTime = elapsed
mu.Unlock()
}()
}
// ZK rollup batch proof verification stream
if work.ZK != nil && len(work.ZK.Scalars) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid, err := gpuZKVerify(sess, work.ZK)
elapsed := time.Since(start)
if err != nil {
firstErr.CompareAndSwap(nil, err)
return
}
mu.Lock()
result.ZKValid = valid
result.ZKTime = elapsed
mu.Unlock()
}()
}
// ML-DSA per-tx signature verification stream
if work.MLDSA != nil && len(work.MLDSA.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid, err := gpuMLDSAVerify(sess, work.MLDSA)
elapsed := time.Since(start)
if err != nil {
firstErr.CompareAndSwap(nil, err)
return
}
mu.Lock()
result.MLDSAValid = valid
result.MLDSATime = elapsed
mu.Unlock()
}()
}
wg.Wait()
if v := firstErr.Load(); v != nil {
return nil, v.(error)
}
return result, nil
}
// gpuBLSVerify dispatches BLS batch verification to the GPU crypto ops.
func gpuBLSVerify(sess *accel.Session, work *BLSWork) ([]bool, error) {
n := len(work.Messages)
// Determine uniform sizes for tensor packing
msgLen := maxByteLen(work.Messages)
sigLen := 96 // BLS G2 point
pkLen := 48 // BLS G1 point
msgFlat := flattenPadded(work.Messages, n, msgLen)
sigFlat := flattenPadded(work.Signatures, n, sigLen)
pkFlat := flattenPadded(work.PubKeys, n, pkLen)
msgs, err := accel.NewTensorWithData[uint8](sess, []int{n, msgLen}, msgFlat)
if err != nil {
return nil, err
}
defer msgs.Close()
sigs, err := accel.NewTensorWithData[uint8](sess, []int{n, sigLen}, sigFlat)
if err != nil {
return nil, err
}
defer sigs.Close()
pks, err := accel.NewTensorWithData[uint8](sess, []int{n, pkLen}, pkFlat)
if err != nil {
return nil, err
}
defer pks.Close()
results, err := accel.NewTensor[uint8](sess, []int{n})
if err != nil {
return nil, err
}
defer results.Close()
if err := sess.Crypto().BLSVerifyBatch(msgs.Untyped(), sigs.Untyped(), pks.Untyped(), results.Untyped()); err != nil {
return nil, err
}
raw, err := results.ToSlice()
if err != nil {
return nil, err
}
valid := make([]bool, n)
for i, v := range raw {
valid[i] = v == 1
}
return valid, nil
}
// gpuCoronaVerify dispatches Corona verification via DilithiumVerifyBatch
// (Corona threshold signatures are lattice-based, same verification kernel).
func gpuCoronaVerify(sess *accel.Session, work *CoronaWork) ([]bool, error) {
n := len(work.Messages)
msgLen := maxByteLen(work.Messages)
sigLen := maxByteLen(work.Signatures)
pkLen := maxByteLen(work.PubKeys)
msgFlat := flattenPadded(work.Messages, n, msgLen)
sigFlat := flattenPadded(work.Signatures, n, sigLen)
pkFlat := flattenPadded(work.PubKeys, n, pkLen)
msgs, err := accel.NewTensorWithData[uint8](sess, []int{n, msgLen}, msgFlat)
if err != nil {
return nil, err
}
defer msgs.Close()
sigs, err := accel.NewTensorWithData[uint8](sess, []int{n, sigLen}, sigFlat)
if err != nil {
return nil, err
}
defer sigs.Close()
pks, err := accel.NewTensorWithData[uint8](sess, []int{n, pkLen}, pkFlat)
if err != nil {
return nil, err
}
defer pks.Close()
results, err := accel.NewTensor[uint8](sess, []int{n})
if err != nil {
return nil, err
}
defer results.Close()
if err := sess.Lattice().DilithiumVerifyBatch(msgs.Untyped(), sigs.Untyped(), pks.Untyped(), results.Untyped()); err != nil {
return nil, err
}
raw, err := results.ToSlice()
if err != nil {
return nil, err
}
valid := make([]bool, n)
for i, v := range raw {
valid[i] = v == 1
}
return valid, nil
}
// gpuZKVerify dispatches ZK batch proof verification via MSMBatch on ZK ops.
func gpuZKVerify(sess *accel.Session, work *ZKWork) (bool, error) {
m := len(work.Scalars)
scalarLen := maxByteLen(work.Scalars)
baseLen := maxByteLen(work.Bases)
scalarFlat := flattenPadded(work.Scalars, m, scalarLen)
baseFlat := flattenPadded(work.Bases, m, baseLen)
scalars, err := accel.NewTensorWithData[uint8](sess, []int{m, scalarLen}, scalarFlat)
if err != nil {
return false, err
}
defer scalars.Close()
bases, err := accel.NewTensorWithData[uint8](sess, []int{m, baseLen}, baseFlat)
if err != nil {
return false, err
}
defer bases.Close()
// MSM result: single point per batch entry
pointSize := baseLen
results, err := accel.NewTensor[uint8](sess, []int{m, pointSize})
if err != nil {
return false, err
}
defer results.Close()
if err := sess.ZK().MSMBatch(scalars.Untyped(), bases.Untyped(), results.Untyped()); err != nil {
return false, err
}
// MSM completed without error means proof verification passed
return true, nil
}
// gpuMLDSAVerify dispatches ML-DSA (Dilithium) batch verification to the GPU.
func gpuMLDSAVerify(sess *accel.Session, work *MLDSAWork) ([]bool, error) {
n := len(work.Messages)
msgLen := maxByteLen(work.Messages)
sigLen := 3309 // FIPS-204 ML-DSA-65 signature (3293 was the stale round-3 Dilithium3 size)
pkLen := 1952 // FIPS-204 ML-DSA-65 public key (unchanged across the round-3 -> final transition)
msgFlat := flattenPadded(work.Messages, n, msgLen)
sigFlat := flattenPadded(work.Signatures, n, sigLen)
pkFlat := flattenPadded(work.PubKeys, n, pkLen)
msgs, err := accel.NewTensorWithData[uint8](sess, []int{n, msgLen}, msgFlat)
if err != nil {
return nil, err
}
defer msgs.Close()
sigs, err := accel.NewTensorWithData[uint8](sess, []int{n, sigLen}, sigFlat)
if err != nil {
return nil, err
}
defer sigs.Close()
pks, err := accel.NewTensorWithData[uint8](sess, []int{n, pkLen}, pkFlat)
if err != nil {
return nil, err
}
defer pks.Close()
results, err := accel.NewTensor[uint8](sess, []int{n})
if err != nil {
return nil, err
}
defer results.Close()
if err := sess.Lattice().DilithiumVerifyBatch(msgs.Untyped(), sigs.Untyped(), pks.Untyped(), results.Untyped()); err != nil {
return nil, err
}
raw, err := results.ToSlice()
if err != nil {
return nil, err
}
valid := make([]bool, n)
for i, v := range raw {
valid[i] = v == 1
}
return valid, nil
}
// verifyCPU performs all verification on the CPU as fallback.
func (p *GPUVerifyPipeline) verifyCPU(work *BlockVerifyWork) *BlockVerifyResult {
result := &BlockVerifyResult{}
var wg sync.WaitGroup
var mu sync.Mutex
if work.BLS != nil && len(work.BLS.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid := cpuBLSVerify(work.BLS)
mu.Lock()
result.BLSValid = valid
result.BLSTime = time.Since(start)
mu.Unlock()
}()
}
if work.Corona != nil && len(work.Corona.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid := cpuCoronaVerify(work.Corona)
mu.Lock()
result.CoronaValid = valid
result.CoronaTime = time.Since(start)
mu.Unlock()
}()
}
if work.ZK != nil && len(work.ZK.Scalars) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid := cpuZKVerify(work.ZK)
mu.Lock()
result.ZKValid = valid
result.ZKTime = time.Since(start)
mu.Unlock()
}()
}
if work.MLDSA != nil && len(work.MLDSA.Messages) > 0 {
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
valid := cpuMLDSAVerify(work.MLDSA)
mu.Lock()
result.MLDSAValid = valid
result.MLDSATime = time.Since(start)
mu.Unlock()
}()
}
wg.Wait()
return result
}
// CPU fallback implementations — the pure-Go correctness oracle.
//
// These perform REAL per-element cryptographic verification using the
// luxfi/crypto pure-Go primitives (CGO_ENABLED=0-clean). They interpret each
// element's raw bytes with the SAME layout the GPU kernels use (see
// gpuBLSVerify / gpuMLDSAVerify), so the CPU and GPU paths are a genuine
// equivalence pair: a no-GPU node accepts exactly the signatures a GPU node
// accepts, and never rubber-stamps a forged one.
//
// Corona and ZK have no pure-Go verifier in luxfi/crypto, so those paths
// fail closed (return false) rather than format-check-and-accept. They MUST
// be wired to a real verifier before block-accept depends on them.
func cpuBLSVerify(work *BLSWork) []bool {
valid := make([]bool, len(work.Messages))
for i := range work.Messages {
// Mirror gpuBLSVerify's layout: pk is a 48-byte compressed G1 point,
// sig is a 96-byte compressed G2 point, msg is the raw message.
// PublicKeyFromCompressedBytes / SignatureFromBytes enforce the exact
// length, on-curve and subgroup membership the blst/CGO path enforces;
// any malformed input fails closed (constructor error => false).
pk, err := bls.PublicKeyFromCompressedBytes(work.PubKeys[i])
if err != nil {
continue
}
sig, err := bls.SignatureFromBytes(work.Signatures[i])
if err != nil {
continue
}
valid[i] = bls.Verify(pk, sig, work.Messages[i])
}
return valid
}
func cpuCoronaVerify(work *CoronaWork) []bool {
// FAIL CLOSED: luxfi/crypto exposes no pure-Go Corona (lattice threshold)
// signature verifier, and the GPU Corona kernel is the known-wrong-prime
// BLOCKED kernel. There is no correct way to verify a Corona signature on
// the CPU here, so every element is rejected. Never return true for an
// unverified signature. Wire a real Corona verifier before block-accept
// consumes this result.
return make([]bool, len(work.Messages))
}
func cpuZKVerify(work *ZKWork) bool {
// FAIL CLOSED: luxfi/crypto exposes no standalone pure-Go ZK proof
// verifier (the accel MSM path is a GPU primitive, not a proof check), so
// CPU verification cannot establish proof validity. Reject rather than
// rubber-stamp. Wire a real ZK verifier before block-accept consumes this.
return false
}
func cpuMLDSAVerify(work *MLDSAWork) []bool {
valid := make([]bool, len(work.Messages))
for i := range work.Messages {
// Mirror gpuMLDSAVerify's layout: ML-DSA-65, pk 1952 bytes, msg raw.
// PublicKeyFromBytes enforces the exact key length and decodes the
// point; VerifySignature uses the FIPS 204 nil-context verify,
// matching the kernel's contextless per-tx verification, and accepts
// the signature at its true FIPS-204 length (3309 bytes). The GPU
// flatten width (gpuMLDSAVerify's sigLen) now agrees at 3309, so the
// CPU oracle and GPU path size the signature identically; see
// TestMLDSA_WorkStructSizeIsCanonical. Malformed pk fails closed
// (constructor error).
pub, err := mldsa.PublicKeyFromBytes(work.PubKeys[i], mldsa.MLDSA65)
if err != nil {
continue
}
valid[i] = pub.VerifySignature(work.Messages[i], work.Signatures[i])
}
return valid
}
// validateWork checks batch size consistency.
func validateWork(work *BlockVerifyWork) error {
if w := work.BLS; w != nil {
n := len(w.Messages)
if n > 0 && (len(w.Signatures) != n || len(w.PubKeys) != n) {
return ErrBLSSizeMismatch
}
}
if w := work.Corona; w != nil {
n := len(w.Messages)
if n > 0 && (len(w.Signatures) != n || len(w.PubKeys) != n) {
return ErrCoronaSizeMismatch
}
}
if w := work.ZK; w != nil {
if len(w.Scalars) > 0 && len(w.Bases) != len(w.Scalars) {
return ErrZKSizeMismatch
}
}
if w := work.MLDSA; w != nil {
n := len(w.Messages)
if n > 0 && (len(w.Signatures) != n || len(w.PubKeys) != n) {
return ErrMLDSASizeMismatch
}
}
return nil
}
// PipelineStats contains pipeline verification statistics.
type PipelineStats struct {
GPUVerifies uint64
CPUVerifies uint64
GPUTimeNs uint64
CPUTimeNs uint64
}
// Stats returns pipeline statistics.
func (p *GPUVerifyPipeline) Stats() PipelineStats {
return PipelineStats{
GPUVerifies: atomic.LoadUint64(&p.gpuVerifies),
CPUVerifies: atomic.LoadUint64(&p.cpuVerifies),
GPUTimeNs: atomic.LoadUint64(&p.gpuTimeNs),
CPUTimeNs: atomic.LoadUint64(&p.cpuTimeNs),
}
}
// Helper: find max byte slice length in a batch.
func maxByteLen(slices [][]byte) int {
m := 1 // minimum 1 to avoid zero-dimension tensors
for _, s := range slices {
if len(s) > m {
m = len(s)
}
}
return m
}
// Helper: flatten [][]byte into a contiguous []uint8 with zero-padding.
func flattenPadded(slices [][]byte, n, elemLen int) []uint8 {
flat := make([]uint8, n*elemLen)
for i, s := range slices {
copy(flat[i*elemLen:], s)
}
return flat
}
-436
View File
@@ -1,436 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"crypto/rand"
"testing"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/mldsa"
"github.com/stretchr/testify/require"
)
// makeRandomBytes returns n random bytes.
func makeRandomBytes(n int) []byte {
b := make([]byte, n)
_, _ = rand.Read(b)
return b
}
// makeValidBLSEntry returns (msg, sig, pk) for a REAL BLS signature over a
// random 32-byte message: pk is the 48-byte compressed G1 key, sig is the
// 96-byte compressed G2 signature. The CPU oracle must accept this.
func makeValidBLSEntry(t testing.TB) (msg, sig, pk []byte) {
t.Helper()
sk, err := bls.NewSecretKey()
require.NoError(t, err)
msg = makeRandomBytes(32)
s, err := sk.Sign(msg)
require.NoError(t, err)
sig = bls.SignatureToBytes(s)
pk = bls.PublicKeyToCompressedBytes(sk.PublicKey())
require.Len(t, sig, 96)
require.Len(t, pk, 48)
return msg, sig, pk
}
// makeValidMLDSAEntry returns (msg, sig, pk) for a REAL ML-DSA-65 signature
// over a random 64-byte message. The sizes are taken from the crypto package
// constants (FIPS-204 ML-DSA-65: pk 1952 bytes, sig 3309 bytes) rather than
// hard-coded — see TestMLDSA_WorkStructSizeIsCanonical, which holds the
// MLDSAWork struct / gpuMLDSAVerify sig constant pinned at the FIPS-204 3309
// (corrected from the stale round-3 Dilithium3 3293). The CPU oracle uses the
// typed Verify, so it accepts the real signature regardless.
func makeValidMLDSAEntry(t testing.TB) (msg, sig, pk []byte) {
t.Helper()
priv, err := mldsa.GenerateKey(rand.Reader, mldsa.MLDSA65)
require.NoError(t, err)
msg = makeRandomBytes(64)
sig, err = priv.Sign(rand.Reader, msg, nil)
require.NoError(t, err)
pk = priv.PublicKey.Bytes()
require.Len(t, sig, mldsa.MLDSA65SignatureSize)
require.Len(t, pk, mldsa.MLDSA65PublicKeySize)
return msg, sig, pk
}
// makeBLSWork creates BLSWork with n entries carrying REAL valid BLS
// signatures (the CPU oracle now performs real verification).
func makeBLSWork(t testing.TB, n int) *BLSWork {
t.Helper()
w := &BLSWork{
Messages: make([][]byte, n),
Signatures: make([][]byte, n),
PubKeys: make([][]byte, n),
}
for i := 0; i < n; i++ {
w.Messages[i], w.Signatures[i], w.PubKeys[i] = makeValidBLSEntry(t)
}
return w
}
// makeCoronaWork creates CoronaWork with n entries.
func makeCoronaWork(n int) *CoronaWork {
w := &CoronaWork{
Messages: make([][]byte, n),
Signatures: make([][]byte, n),
PubKeys: make([][]byte, n),
}
for i := 0; i < n; i++ {
w.Messages[i] = makeRandomBytes(48)
w.Signatures[i] = makeRandomBytes(512)
w.PubKeys[i] = makeRandomBytes(256)
}
return w
}
// makeZKWork creates ZKWork with m entries.
func makeZKWork(m int) *ZKWork {
w := &ZKWork{
Scalars: make([][]byte, m),
Bases: make([][]byte, m),
}
for i := 0; i < m; i++ {
w.Scalars[i] = makeRandomBytes(32)
w.Bases[i] = makeRandomBytes(64)
}
return w
}
// makeMLDSAWork creates MLDSAWork with n entries carrying REAL valid
// ML-DSA-65 (Dilithium3) signatures (the CPU oracle now performs real
// verification).
func makeMLDSAWork(t testing.TB, n int) *MLDSAWork {
t.Helper()
w := &MLDSAWork{
Messages: make([][]byte, n),
Signatures: make([][]byte, n),
PubKeys: make([][]byte, n),
}
for i := 0; i < n; i++ {
w.Messages[i], w.Signatures[i], w.PubKeys[i] = makeValidMLDSAEntry(t)
}
return w
}
func TestGPUPipeline_AllFourTypes(t *testing.T) {
pipeline := NewGPUVerifyPipeline()
work := &BlockVerifyWork{
BLS: makeBLSWork(t, 5),
Corona: makeCoronaWork(3),
ZK: makeZKWork(2),
MLDSA: makeMLDSAWork(t, 10),
}
result, err := pipeline.VerifyBlock(work)
require.NoError(t, err)
require.NotNil(t, result)
// BLS results: real valid signatures, CPU oracle accepts.
require.Len(t, result.BLSValid, 5, "should have 5 BLS results")
for i, v := range result.BLSValid {
require.True(t, v, "BLS[%d] should be valid", i)
}
// Corona results: no pure-Go Corona verifier exists, so the CPU oracle
// fails closed — every element is rejected (never rubber-stamped).
require.Len(t, result.CoronaValid, 3, "should have 3 Corona results")
for i, v := range result.CoronaValid {
require.False(t, v, "Corona[%d] must fail closed (no pure-Go verifier)", i)
}
// ZK result: no pure-Go ZK verifier exists, so the CPU oracle fails closed.
require.False(t, result.ZKValid, "ZK batch must fail closed (no pure-Go verifier)")
// ML-DSA results: real valid signatures, CPU oracle accepts.
require.Len(t, result.MLDSAValid, 10, "should have 10 ML-DSA results")
for i, v := range result.MLDSAValid {
require.True(t, v, "MLDSA[%d] should be valid", i)
}
// Timing: all durations should be non-negative
require.GreaterOrEqual(t, result.TotalTime.Nanoseconds(), int64(0))
require.GreaterOrEqual(t, result.BLSTime.Nanoseconds(), int64(0))
require.GreaterOrEqual(t, result.CoronaTime.Nanoseconds(), int64(0))
require.GreaterOrEqual(t, result.ZKTime.Nanoseconds(), int64(0))
require.GreaterOrEqual(t, result.MLDSATime.Nanoseconds(), int64(0))
// Stats should reflect the verification
stats := pipeline.Stats()
require.Equal(t, uint64(1), stats.GPUVerifies+stats.CPUVerifies,
"exactly one verify should have been recorded")
}
func TestGPUPipeline_CPUFallback(t *testing.T) {
// Without CGO/GPU, accel.Available() returns false.
// Pipeline must fall back to CPU verification.
pipeline := NewGPUVerifyPipeline()
work := &BlockVerifyWork{
BLS: makeBLSWork(t, 3),
MLDSA: makeMLDSAWork(t, 4),
}
result, err := pipeline.VerifyBlock(work)
require.NoError(t, err)
require.NotNil(t, result)
// CPU fallback performs real verification; valid signatures are accepted.
require.Len(t, result.BLSValid, 3)
for i, v := range result.BLSValid {
require.True(t, v, "CPU BLS[%d] should be valid", i)
}
require.Len(t, result.MLDSAValid, 4)
for i, v := range result.MLDSAValid {
require.True(t, v, "CPU MLDSA[%d] should be valid", i)
}
// GPU should not have been used (no CGO in test env)
require.False(t, result.GPUUsed, "should use CPU fallback")
stats := pipeline.Stats()
require.Equal(t, uint64(1), stats.CPUVerifies)
}
// TestCPUVerify_RealOracle proves the CPU fallback is a real cryptographic
// oracle, not a length-checking rubber stamp: a valid signature is accepted
// and a well-formed-but-FORGED signature (correct lengths, wrong bytes) is
// REJECTED. The forged-rejection case is the regression guard against the
// old `return true for well-formed inputs` behavior.
func TestCPUVerify_RealOracle(t *testing.T) {
t.Run("BLS valid accepted, forged rejected", func(t *testing.T) {
msg, sig, pk := makeValidBLSEntry(t)
// Valid signature => accepted.
good := cpuBLSVerify(&BLSWork{
Messages: [][]byte{msg},
Signatures: [][]byte{sig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{true}, good, "valid BLS signature must be accepted")
// Forged signature: correct 96-byte length, random bytes => rejected.
forgedSig := makeRandomBytes(96)
bad := cpuBLSVerify(&BLSWork{
Messages: [][]byte{msg},
Signatures: [][]byte{forgedSig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{false}, bad, "forged BLS signature (right length, wrong bytes) must be REJECTED")
// Valid signature against the WRONG message => rejected.
wrongMsg := cpuBLSVerify(&BLSWork{
Messages: [][]byte{makeRandomBytes(32)},
Signatures: [][]byte{sig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{false}, wrongMsg, "BLS signature over a different message must be REJECTED")
})
t.Run("MLDSA valid accepted, forged rejected", func(t *testing.T) {
msg, sig, pk := makeValidMLDSAEntry(t)
// Valid signature => accepted.
good := cpuMLDSAVerify(&MLDSAWork{
Messages: [][]byte{msg},
Signatures: [][]byte{sig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{true}, good, "valid ML-DSA signature must be accepted")
// Forged signature: correct length, random bytes => rejected.
forgedSig := makeRandomBytes(mldsa.MLDSA65SignatureSize)
bad := cpuMLDSAVerify(&MLDSAWork{
Messages: [][]byte{msg},
Signatures: [][]byte{forgedSig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{false}, bad, "forged ML-DSA signature (right length, wrong bytes) must be REJECTED")
// Valid signature against the WRONG message => rejected.
wrongMsg := cpuMLDSAVerify(&MLDSAWork{
Messages: [][]byte{makeRandomBytes(64)},
Signatures: [][]byte{sig},
PubKeys: [][]byte{pk},
})
require.Equal(t, []bool{false}, wrongMsg, "ML-DSA signature over a different message must be REJECTED")
})
t.Run("Corona fails closed", func(t *testing.T) {
// No pure-Go Corona verifier exists; every element must be rejected,
// never rubber-stamped on length alone.
got := cpuCoronaVerify(&CoronaWork{
Messages: [][]byte{makeRandomBytes(48), makeRandomBytes(48)},
Signatures: [][]byte{makeRandomBytes(512), makeRandomBytes(512)},
PubKeys: [][]byte{makeRandomBytes(256), makeRandomBytes(256)},
})
require.Equal(t, []bool{false, false}, got, "Corona must fail closed for all elements")
})
t.Run("ZK fails closed", func(t *testing.T) {
// No pure-Go ZK proof verifier exists; the batch must be rejected.
got := cpuZKVerify(&ZKWork{
Scalars: [][]byte{makeRandomBytes(32)},
Bases: [][]byte{makeRandomBytes(64)},
})
require.False(t, got, "ZK must fail closed")
})
}
// TestMLDSA_WorkStructSizeIsCanonical pins the FIPS-204 ML-DSA-65 signature and
// public key sizes that the MLDSAWork struct comment and gpuMLDSAVerify's
// fixed-size flatten now use. luxfi/crypto (circl v1.6.3, FIPS-204 final)
// produces 3309-byte ML-DSA-65 signatures (5*640 + 55 + 6 + 48 = 3309); the
// GPU flatten width was corrected from the stale round-3 Dilithium3 size 3293
// to 3309 so the GPU path no longer clamps/corrupts a real signature. The
// public key size (1952) is unchanged across the round-3 -> final transition.
//
// This is the equivalence-pair guard: the CPU oracle (cpuMLDSAVerify) parses
// pk via the typed PublicKeyFromBytes and calls VerifySignature, accepting the
// real 3309-byte signature; the GPU path sizes the signature identically. If
// the crypto constant ever drifts, this test fails before any divergence
// reaches the GPU ML-DSA kernel (not yet wired into block-accept).
func TestMLDSA_WorkStructSizeIsCanonical(t *testing.T) {
require.Equal(t, 1952, mldsa.MLDSA65PublicKeySize,
"ML-DSA-65 public key is 1952 bytes (matches MLDSAWork / gpuMLDSAVerify pkLen)")
require.Equal(t, 3309, mldsa.MLDSA65SignatureSize,
"ML-DSA-65 signature is 3309 bytes (FIPS-204), matching the MLDSAWork struct / gpuMLDSAVerify sigLen")
}
func TestGPUPipeline_EmptyBatches(t *testing.T) {
pipeline := NewGPUVerifyPipeline()
tests := []struct {
name string
work *BlockVerifyWork
}{
{
name: "nil work",
work: nil,
},
{
name: "all nil batches",
work: &BlockVerifyWork{},
},
{
name: "empty BLS only",
work: &BlockVerifyWork{
BLS: &BLSWork{},
},
},
{
name: "BLS filled, rest nil",
work: &BlockVerifyWork{
BLS: makeBLSWork(t, 2),
},
},
{
name: "ZK only",
work: &BlockVerifyWork{
ZK: makeZKWork(1),
},
},
{
name: "MLDSA only",
work: &BlockVerifyWork{
MLDSA: makeMLDSAWork(t, 1),
},
},
{
name: "Corona only",
work: &BlockVerifyWork{
Corona: makeCoronaWork(1),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := pipeline.VerifyBlock(tt.work)
require.NoError(t, err)
require.NotNil(t, result)
})
}
}
func TestGPUPipeline_ValidationErrors(t *testing.T) {
pipeline := NewGPUVerifyPipeline()
tests := []struct {
name string
work *BlockVerifyWork
wantErr error
}{
{
name: "BLS size mismatch",
work: &BlockVerifyWork{
BLS: &BLSWork{
Messages: [][]byte{{1}},
Signatures: [][]byte{{1}, {2}}, // 2 != 1
PubKeys: [][]byte{{1}},
},
},
wantErr: ErrBLSSizeMismatch,
},
{
name: "Corona size mismatch",
work: &BlockVerifyWork{
Corona: &CoronaWork{
Messages: [][]byte{{1}, {2}},
Signatures: [][]byte{{1}}, // 1 != 2
PubKeys: [][]byte{{1}, {2}},
},
},
wantErr: ErrCoronaSizeMismatch,
},
{
name: "ZK size mismatch",
work: &BlockVerifyWork{
ZK: &ZKWork{
Scalars: [][]byte{{1}, {2}},
Bases: [][]byte{{1}}, // 1 != 2
},
},
wantErr: ErrZKSizeMismatch,
},
{
name: "MLDSA size mismatch",
work: &BlockVerifyWork{
MLDSA: &MLDSAWork{
Messages: [][]byte{{1}},
Signatures: [][]byte{{1}},
PubKeys: [][]byte{{1}, {2}}, // 2 != 1
},
},
wantErr: ErrMLDSASizeMismatch,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := pipeline.VerifyBlock(tt.work)
require.ErrorIs(t, err, tt.wantErr)
})
}
}
func BenchmarkGPUPipeline(b *testing.B) {
pipeline := NewGPUVerifyPipeline()
work := &BlockVerifyWork{
BLS: makeBLSWork(b, 100),
Corona: makeCoronaWork(50),
ZK: makeZKWork(10),
MLDSA: makeMLDSAWork(b, 200),
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = pipeline.VerifyBlock(work)
}
}
-970
View File
@@ -1,970 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package quasar integration tests.
//
// These tests exercise realistic end-to-end scenarios for Quasar consensus:
// - Full component wiring and event processing
// - Corona threshold signing flows (skipped if lattice lib unavailable)
// - Concurrent operation safety
// - Stop/start lifecycle management
// - Memory behavior with many finality events
//
// Run with: go test -v -run "^Test.*Integration\|^TestQuasar" ./...
// Skip long tests: go test -short ./...
package quasar
import (
"context"
"crypto/rand"
"runtime"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/stretchr/testify/require"
)
// ----------------------------------------------------------------------------
// Mock implementations for integration tests
// ----------------------------------------------------------------------------
// mockPChainProvider implements PChainProvider for tests
type mockPChainProvider struct {
mu sync.RWMutex
height uint64
validators []ValidatorState
finalityCh chan FinalityEvent
closed bool
}
func newMockPChainProvider(validators []ValidatorState) *mockPChainProvider {
return &mockPChainProvider{
height: 0,
validators: validators,
finalityCh: make(chan FinalityEvent, 100),
}
}
func (m *mockPChainProvider) GetFinalizedHeight() uint64 {
m.mu.RLock()
defer m.mu.RUnlock()
return m.height
}
func (m *mockPChainProvider) GetValidators(height uint64) ([]ValidatorState, error) {
m.mu.RLock()
defer m.mu.RUnlock()
return m.validators, nil
}
func (m *mockPChainProvider) SubscribeFinality() <-chan FinalityEvent {
return m.finalityCh
}
func (m *mockPChainProvider) Validators() []ValidatorState {
m.mu.RLock()
defer m.mu.RUnlock()
return append([]ValidatorState(nil), m.validators...)
}
func (m *mockPChainProvider) EmitFinality(event FinalityEvent) {
m.mu.Lock()
defer m.mu.Unlock()
if m.closed {
return
}
m.height = event.Height
select {
case m.finalityCh <- event:
default:
}
}
func (m *mockPChainProvider) Close() {
m.mu.Lock()
defer m.mu.Unlock()
if !m.closed {
m.closed = true
close(m.finalityCh)
}
}
// mockQuantumSigner implements QuantumSignerFallback for tests
type mockQuantumSigner struct{}
func (m *mockQuantumSigner) SignMessage(msg []byte) ([]byte, error) {
return []byte("RT-MOCK-SIG"), nil
}
// ----------------------------------------------------------------------------
// Helper functions
// ----------------------------------------------------------------------------
// generateValidatorStates creates n ValidatorState entries
func generateValidatorStates(n int) []ValidatorState {
states := make([]ValidatorState, n)
for i := range states {
blsKey := make([]byte, 48)
rtKey := make([]byte, 32)
_, _ = rand.Read(blsKey)
_, _ = rand.Read(rtKey)
states[i] = ValidatorState{
NodeID: ids.GenerateTestNodeID(),
Weight: 1000,
BLSPubKey: blsKey,
CoronaKey: rtKey,
Active: true,
}
}
return states
}
// createTestEvent creates a FinalityEvent for testing
func createTestEvent(height uint64, validators []ValidatorState) FinalityEvent {
var blockID ids.ID
_, _ = rand.Read(blockID[:])
return FinalityEvent{
Height: height,
BlockID: blockID,
Validators: validators,
Timestamp: time.Now(),
}
}
// setupQuasarWithCorona creates a Quasar with a test Corona coordinator.
// Returns nil for Quasar if Corona initialization fails (e.g., lattice lib constraint).
func setupQuasarWithCorona(t *testing.T, numParties int) (*Quasar, *mockPChainProvider, []ids.NodeID, error) {
t.Helper()
validatorStates := generateValidatorStates(numParties)
pchain := newMockPChainProvider(validatorStates)
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
if err != nil {
return nil, nil, nil, err
}
// Connect providers
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
// Create a test Corona coordinator (stub signatures, not production)
threshold := (numParties * 2 / 3) + 1
if threshold < 2 {
threshold = 2
}
rc, err := NewTestCoronaCoordinator(log.NewNoOpLogger(), CoronaConfig{
NumParties: numParties,
Threshold: threshold,
})
if err != nil {
pchain.Close()
return nil, nil, nil, err
}
q.ConnectCorona(rc)
// Extract node IDs and initialize Corona
nodeIDs := make([]ids.NodeID, len(validatorStates))
for i, v := range validatorStates {
nodeIDs[i] = v.NodeID
}
err = q.InitializeCorona(nodeIDs)
if err != nil {
pchain.Close()
return nil, nil, nil, err
}
return q, pchain, nodeIDs, nil
}
// isLatticeUnavailable checks if an error indicates lattice library constraints
func isLatticeUnavailable(err error) bool {
if err == nil {
return false
}
msg := err.Error()
return strings.Contains(msg, "ring") || strings.Contains(msg, "modulus") ||
strings.Contains(msg, "prime") || strings.Contains(msg, "lattice")
}
// ----------------------------------------------------------------------------
// Integration Tests
// ----------------------------------------------------------------------------
// TestQuasarFullFlow tests creating Quasar, connecting components, and processing events
func TestQuasarFullFlow(t *testing.T) {
const numValidators = 5
t.Run("create_and_connect", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err, "NewQuasar should succeed")
require.NotNil(t, q, "Quasar should not be nil")
// Verify initial state
stats := q.Stats()
require.False(t, stats.Running, "should not be running initially")
require.Equal(t, uint64(0), stats.PChainHeight)
require.Equal(t, uint64(0), stats.QChainHeight)
// Connect components
validatorStates := generateValidatorStates(numValidators)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
// Verify configuration
threshold, quorumNum, quorumDen := q.GetConfig()
require.Equal(t, 3, threshold)
require.Equal(t, uint64(2), quorumNum)
require.Equal(t, uint64(3), quorumDen)
})
t.Run("start_and_stop", func(t *testing.T) {
validatorStates := generateValidatorStates(numValidators)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
// Start
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err, "Start should succeed")
require.True(t, q.IsRunning(), "should be running after Start")
// Stop
q.Stop()
// Give goroutines time to shut down
time.Sleep(50 * time.Millisecond)
require.False(t, q.IsRunning(), "should not be running after Stop")
})
t.Run("process_single_event", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, numValidators)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
defer q.Stop()
// Emit event
event := createTestEvent(1, pchain.Validators())
pchain.EmitFinality(event)
require.Eventually(t, func() bool {
return q.Stats().PChainHeight >= 1
}, time.Second, 10*time.Millisecond, "P-chain height should be 1")
})
t.Run("verify_quorum_calculation", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Test quorum: 2/3 means 67% needed
require.True(t, q.CheckQuorum(670, 1000), "67% should meet 2/3 quorum")
require.True(t, q.CheckQuorum(667, 1000), "66.7% should meet 2/3 quorum")
require.False(t, q.CheckQuorum(600, 1000), "60% should not meet 2/3 quorum")
require.False(t, q.CheckQuorum(0, 1000), "0% should not meet quorum")
// Note: zero total weight is an edge case - required becomes 0, so any signer weight passes
// This is intentional: if there are no validators, there's nothing to check
require.True(t, q.CheckQuorum(500, 0), "zero total is edge case (required=0)")
})
}
// TestQuasarWithCorona tests full threshold signing flow
func TestQuasarWithCorona(t *testing.T) {
// All Corona tests require the lattice library to work correctly.
// Skip if the library has constraints (e.g., requires prime moduli).
t.Run("initialize_and_sign", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
// Verify Corona is connected
require.NotNil(t, q.corona, "Corona should be connected")
require.True(t, q.corona.IsInitialized(), "Corona should be initialized")
})
t.Run("sign_and_verify", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
// Sign a message
msg := []byte("test message for signing")
sig, err := q.corona.Sign(msg)
require.NoError(t, err, "Sign should succeed")
require.NotNil(t, sig, "Signature should not be nil")
// Verify signature
valid := q.corona.Verify(msg, sig)
require.True(t, valid, "Signature should verify")
})
t.Run("multiple_signing_sessions", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
// Sign multiple messages
for i := 0; i < 3; i++ {
msg := []byte("message " + string(rune('A'+i)))
sig, err := q.corona.Sign(msg)
require.NoError(t, err, "Sign %d should succeed", i)
require.True(t, q.corona.Verify(msg, sig), "Signature %d should verify", i)
}
})
t.Run("threshold_parameter_check", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
// With 5 parties, threshold = (5 * 2 / 3) + 1 = 4
require.Equal(t, 4, q.corona.Threshold(), "Threshold should be 4 for 5 parties")
require.Equal(t, 5, q.corona.NumParties(), "NumParties should be 5")
})
}
// TestQuasarConcurrent tests concurrent finality processing
func TestQuasarConcurrent(t *testing.T) {
const numValidators = 5
const numEvents = 50
q, pchain, _, err := setupQuasarWithCorona(t, numValidators)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
validatorStates := pchain.Validators()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
defer q.Stop()
// Send events concurrently
var wg sync.WaitGroup
for i := uint64(1); i <= numEvents; i++ {
wg.Add(1)
go func(height uint64) {
defer wg.Done()
event := createTestEvent(height, validatorStates)
pchain.EmitFinality(event)
}(i)
}
wg.Wait()
// Wait for processing
time.Sleep(500 * time.Millisecond)
stats := q.Stats()
t.Logf("Processed %d events, finalized blocks: %d", numEvents, stats.FinalizedBlocks)
require.GreaterOrEqual(t, stats.FinalizedBlocks, 1, "should have finalized at least 1 block")
}
// TestQuasarConcurrentCoronaSigning tests concurrent Corona signing
func TestQuasarConcurrentCoronaSigning(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
const numSigners = 10
var wg sync.WaitGroup
var successCount atomic.Int32
for i := 0; i < numSigners; i++ {
wg.Add(1)
go func(idx int) {
defer wg.Done()
msg := []byte("concurrent message " + string(rune('0'+idx)))
sig, err := q.corona.Sign(msg)
if err == nil && q.corona.Verify(msg, sig) {
successCount.Add(1)
}
}(i)
}
wg.Wait()
require.Equal(t, int32(numSigners), successCount.Load(), "all concurrent signs should succeed")
}
// TestQuasarRestart tests stop/start cycles
func TestQuasarRestart(t *testing.T) {
const numValidators = 5
t.Run("basic_stop_start", func(t *testing.T) {
validatorStates := generateValidatorStates(numValidators)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
// First cycle
q1, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q1.ConnectPChain(pchain)
q1.ConnectQuantumFallback(&mockQuantumSigner{})
ctx1, cancel1 := context.WithCancel(context.Background())
err = q1.Start(ctx1)
require.NoError(t, err)
require.True(t, q1.IsRunning())
cancel1()
q1.Stop()
time.Sleep(50 * time.Millisecond)
require.False(t, q1.IsRunning())
// Second cycle with fresh Quasar instance
// Note: The current implementation closes stopCh on Stop and doesn't recreate it,
// so restart requires a new instance. This is a known limitation.
q2, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q2.ConnectPChain(pchain)
q2.ConnectQuantumFallback(&mockQuantumSigner{})
ctx2, cancel2 := context.WithCancel(context.Background())
defer cancel2()
err = q2.Start(ctx2)
require.NoError(t, err)
require.True(t, q2.IsRunning())
q2.Stop()
})
t.Run("stop_with_pending_events", func(t *testing.T) {
validatorStates := generateValidatorStates(numValidators)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
// Emit events
for i := uint64(1); i <= 10; i++ {
event := createTestEvent(i, validatorStates)
pchain.EmitFinality(event)
}
// Stop immediately
q.Stop()
time.Sleep(50 * time.Millisecond)
require.False(t, q.IsRunning(), "should stop cleanly with pending events")
})
t.Run("multiple_stop_calls", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
validatorStates := generateValidatorStates(numValidators)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
// Multiple stops should not panic
q.Stop()
// Note: After first Stop, stopCh is closed. Subsequent Stop calls check running flag,
// but since running=false, they won't try to close again. This tests idempotency.
})
t.Run("stop_without_start", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Stop without start should not panic
q.Stop()
require.False(t, q.IsRunning())
})
}
// TestQuasarMemoryPressure tests with many finality events to verify no memory leaks
func TestQuasarMemoryPressure(t *testing.T) {
if testing.Short() {
t.Skip("skipping memory pressure test in short mode")
}
t.Run("many_finality_entries", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Add many finality entries
const numEntries = 1000
for i := 0; i < numEntries; i++ {
var blockID ids.ID
_, _ = rand.Read(blockID[:])
finality := &QuantumFinality{
BlockID: blockID,
PChainHeight: uint64(i),
QChainHeight: uint64(i),
TotalWeight: 1000,
SignerWeight: 700,
}
q.SetFinalized(blockID, finality)
}
stats := q.Stats()
require.GreaterOrEqual(t, stats.FinalizedBlocks, numEntries-1)
})
t.Run("memory_stability", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Add many entries
const numEntries = 10000
for i := 0; i < numEntries; i++ {
var blockID ids.ID
_, _ = rand.Read(blockID[:])
finality := &QuantumFinality{
BlockID: blockID,
PChainHeight: uint64(i),
QChainHeight: uint64(i),
BLSProof: make([]byte, 96),
CoronaProof: make([]byte, 1024),
TotalWeight: 1000,
SignerWeight: 700,
}
q.SetFinalized(blockID, finality)
}
// Force GC and check we don't crash
runtime.GC()
var m runtime.MemStats
runtime.ReadMemStats(&m)
t.Logf("Heap after %d entries: %d bytes", numEntries, m.HeapAlloc)
// Just verify we completed without issues - memory testing is notoriously flaky
stats := q.Stats()
require.GreaterOrEqual(t, stats.FinalizedBlocks, numEntries-1)
})
t.Run("concurrent_add_finality", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
const numGoroutines = 10
const entriesPerGoroutine = 250
var wg sync.WaitGroup
for g := 0; g < numGoroutines; g++ {
wg.Add(1)
go func(gid int) {
defer wg.Done()
for i := 0; i < entriesPerGoroutine; i++ {
var blockID ids.ID
_, _ = rand.Read(blockID[:])
finality := &QuantumFinality{
BlockID: blockID,
PChainHeight: uint64(gid*entriesPerGoroutine + i),
QChainHeight: uint64(gid*entriesPerGoroutine + i),
TotalWeight: 1000,
SignerWeight: 700,
}
q.SetFinalized(blockID, finality)
}
}(g)
}
wg.Wait()
stats := q.Stats()
t.Logf("Final entries after concurrent operations: %d", stats.FinalizedBlocks)
// Some entries may share block IDs due to rand collision, so just verify we have many
require.GreaterOrEqual(t, stats.FinalizedBlocks, numGoroutines*entriesPerGoroutine/2)
})
t.Run("concurrent_read_write", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Pre-populate some entries
blockIDs := make([]ids.ID, 100)
for i := range blockIDs {
_, _ = rand.Read(blockIDs[i][:])
q.SetFinalized(blockIDs[i], &QuantumFinality{
BlockID: blockIDs[i],
PChainHeight: uint64(i),
})
}
// Concurrent reads and writes
var wg sync.WaitGroup
done := make(chan struct{})
// Writers
for w := 0; w < 5; w++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-done:
return
default:
var blockID ids.ID
_, _ = rand.Read(blockID[:])
q.SetFinalized(blockID, &QuantumFinality{BlockID: blockID})
}
}
}()
}
// Readers
for r := 0; r < 5; r++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-done:
return
default:
idx := int(time.Now().UnixNano()) % len(blockIDs)
_, _ = q.GetFinality(blockIDs[idx])
}
}
}()
}
// Run for a short period
time.Sleep(100 * time.Millisecond)
close(done)
wg.Wait()
t.Log("Concurrent read/write completed successfully")
})
}
// TestQuasarHealthStatus tests health status reporting
func TestQuasarHealthStatus(t *testing.T) {
t.Run("initial_state", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
stats := q.Stats()
require.False(t, stats.Running)
require.Equal(t, uint64(0), stats.PChainHeight)
require.Equal(t, uint64(0), stats.QChainHeight)
require.Equal(t, 0, stats.FinalizedBlocks)
})
t.Run("after_corona_init", func(t *testing.T) {
q, pchain, _, err := setupQuasarWithCorona(t, 5)
if isLatticeUnavailable(err) {
t.Skipf("Skipping: lattice library constraint: %v", err)
}
require.NoError(t, err)
defer pchain.Close()
stats := q.Stats()
require.True(t, stats.CoronaReady, "Corona should be ready")
})
t.Run("running_state", func(t *testing.T) {
validatorStates := generateValidatorStates(5)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
defer q.Stop()
stats := q.Stats()
require.True(t, stats.Running, "should be running")
})
}
// TestQuasarShutdown tests graceful shutdown behavior
func TestQuasarShutdown(t *testing.T) {
t.Run("graceful_stop_with_timeout", func(t *testing.T) {
validatorStates := generateValidatorStates(5)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
ctx, cancel := context.WithCancel(context.Background())
err = q.Start(ctx)
require.NoError(t, err)
// Cancel context and stop
cancel()
q.Stop()
require.False(t, q.IsRunning())
})
t.Run("stop_already_stopped", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Should not panic
q.Stop()
require.False(t, q.IsRunning())
})
t.Run("start_after_stop", func(t *testing.T) {
validatorStates := generateValidatorStates(5)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
// First run
q1, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q1.ConnectPChain(pchain)
q1.ConnectQuantumFallback(&mockQuantumSigner{})
ctx1, cancel1 := context.WithCancel(context.Background())
err = q1.Start(ctx1)
require.NoError(t, err)
cancel1()
q1.Stop()
// Second run with new instance (implementation limitation)
q2, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q2.ConnectPChain(pchain)
q2.ConnectQuantumFallback(&mockQuantumSigner{})
ctx2, cancel2 := context.WithCancel(context.Background())
defer cancel2()
err = q2.Start(ctx2)
require.NoError(t, err)
require.True(t, q2.IsRunning())
q2.Stop()
})
t.Run("health_status", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// Check stats work without panic
stats := q.Stats()
require.NotNil(t, stats)
})
t.Run("drain_finality_channel", func(t *testing.T) {
validatorStates := generateValidatorStates(5)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
q.ConnectQuantumFallback(&mockQuantumSigner{})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
require.NoError(t, err)
// Get finality channel via Subscribe
finCh := q.Subscribe()
require.NotNil(t, finCh)
// Emit event
event := createTestEvent(1, validatorStates)
pchain.EmitFinality(event)
// Try to receive finality (with timeout)
select {
case finality := <-finCh:
require.NotNil(t, finality)
case <-time.After(100 * time.Millisecond):
// May not receive if processing takes longer
}
q.Stop()
})
}
// TestQuasarEdgeCases tests edge cases and error conditions
func TestQuasarEdgeCases(t *testing.T) {
t.Run("start_without_pchain", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
// Should handle gracefully (either error or run without processing)
if err == nil {
q.Stop()
}
})
t.Run("start_without_quantum_fallback", func(t *testing.T) {
validatorStates := generateValidatorStates(5)
pchain := newMockPChainProvider(validatorStates)
defer pchain.Close()
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
q.ConnectPChain(pchain)
// No quantum fallback connected - Start requires it
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = q.Start(ctx)
// Implementation requires Q-Chain (quantum fallback) to be connected
require.Error(t, err, "Start should error without quantum fallback")
})
t.Run("get_finality_nonexistent", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
var blockID ids.ID
_, _ = rand.Read(blockID[:])
finality, found := q.GetFinality(blockID)
require.False(t, found, "should not find nonexistent block")
require.Nil(t, finality, "should return nil for nonexistent block")
})
t.Run("verify_nil_finality", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
err = q.Verify(nil)
require.Error(t, err, "should error on nil finality")
})
t.Run("verify_empty_proofs", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
finality := &QuantumFinality{
BLSProof: nil,
CoronaProof: nil,
TotalWeight: 1000,
SignerWeight: 700,
}
err = q.Verify(finality)
require.Error(t, err, "should error on empty proofs")
})
t.Run("verify_insufficient_weight", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
finality := &QuantumFinality{
BLSProof: []byte("proof"),
CoronaProof: []byte("proof"),
TotalWeight: 1000,
SignerWeight: 500, // Only 50%, needs 67%
}
err = q.Verify(finality)
require.Error(t, err, "should error on insufficient weight")
})
t.Run("create_message_format", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
validatorStates := generateValidatorStates(3)
event := createTestEvent(42, validatorStates)
msg := q.CreateMessage(event)
require.NotEmpty(t, msg, "message should not be empty")
// Message is binary format containing blockID and height
// Just verify it's deterministic and non-empty
msg2 := q.CreateMessage(event)
require.Equal(t, msg, msg2, "message should be deterministic")
})
t.Run("total_weight_calculation", func(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
validators := []ValidatorState{
{Weight: 100, Active: true},
{Weight: 200, Active: true},
{Weight: 300, Active: false}, // Inactive
{Weight: 400, Active: true},
}
total := q.TotalWeight(validators)
require.Equal(t, uint64(700), total, "should sum only active validator weights")
})
}
-195
View File
@@ -1,195 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//go:build !cgo
// Package quasar provides NTT operations for Corona consensus.
// This file provides pure Go CPU implementation when CGO is not available.
// All operations use the luxfi/lattice library which provides optimized
// NTT implementations in pure Go.
package quasar
import (
"sync"
"sync/atomic"
"github.com/luxfi/lattice/v7/ring"
)
// NTTAccelerator provides NTT operations for Corona.
// When CGO is disabled, this uses the pure Go lattice library
// which provides optimized CPU-based NTT transforms.
type NTTAccelerator struct {
enabled bool
stats NTTStats
statsmu sync.RWMutex
}
// NTTStats tracks NTT accelerator statistics.
type NTTStats struct {
Enabled bool
Backend string
TotalOps uint64
GPUAvailable bool
}
// NewNTTAccelerator creates a new NTT accelerator using pure Go lattice library.
func NewNTTAccelerator() (*NTTAccelerator, error) {
return &NTTAccelerator{
enabled: true, // CPU implementation is always available
stats: NTTStats{
Enabled: true,
Backend: "CPU (Pure Go)",
},
}, nil
}
// IsEnabled returns true - CPU implementation is always available.
func (g *NTTAccelerator) IsEnabled() bool {
return true
}
// Backend returns the backend name.
func (g *NTTAccelerator) Backend() string {
return "CPU (Pure Go lattice)"
}
// NTTForward performs forward NTT on a polynomial using lattice library.
func (g *NTTAccelerator) NTTForward(r *ring.Ring, poly ring.Poly) error {
r.NTT(poly, poly)
atomic.AddUint64(&g.stats.TotalOps, 1)
return nil
}
// NTTInverse performs inverse NTT on a polynomial using lattice library.
func (g *NTTAccelerator) NTTInverse(r *ring.Ring, poly ring.Poly) error {
r.INTT(poly, poly)
atomic.AddUint64(&g.stats.TotalOps, 1)
return nil
}
// BatchNTTForward performs forward NTT on multiple polynomials.
// Uses parallel processing for better performance on multi-core CPUs.
func (g *NTTAccelerator) BatchNTTForward(r *ring.Ring, polys []ring.Poly) error {
if len(polys) == 0 {
return nil
}
// For small batches, process sequentially
if len(polys) < 8 {
for _, poly := range polys {
r.NTT(poly, poly)
}
atomic.AddUint64(&g.stats.TotalOps, uint64(len(polys)))
return nil
}
// For larger batches, use parallel processing
var wg sync.WaitGroup
numWorkers := 4
chunkSize := (len(polys) + numWorkers - 1) / numWorkers
for i := 0; i < numWorkers; i++ {
start := i * chunkSize
end := start + chunkSize
if end > len(polys) {
end = len(polys)
}
if start >= end {
break
}
wg.Add(1)
go func(batch []ring.Poly) {
defer wg.Done()
for _, poly := range batch {
r.NTT(poly, poly)
}
}(polys[start:end])
}
wg.Wait()
atomic.AddUint64(&g.stats.TotalOps, uint64(len(polys)))
return nil
}
// BatchNTTInverse performs inverse NTT on multiple polynomials.
// Uses parallel processing for better performance on multi-core CPUs.
func (g *NTTAccelerator) BatchNTTInverse(r *ring.Ring, polys []ring.Poly) error {
if len(polys) == 0 {
return nil
}
// For small batches, process sequentially
if len(polys) < 8 {
for _, poly := range polys {
r.INTT(poly, poly)
}
atomic.AddUint64(&g.stats.TotalOps, uint64(len(polys)))
return nil
}
// For larger batches, use parallel processing
var wg sync.WaitGroup
numWorkers := 4
chunkSize := (len(polys) + numWorkers - 1) / numWorkers
for i := 0; i < numWorkers; i++ {
start := i * chunkSize
end := start + chunkSize
if end > len(polys) {
end = len(polys)
}
if start >= end {
break
}
wg.Add(1)
go func(batch []ring.Poly) {
defer wg.Done()
for _, poly := range batch {
r.INTT(poly, poly)
}
}(polys[start:end])
}
wg.Wait()
atomic.AddUint64(&g.stats.TotalOps, uint64(len(polys)))
return nil
}
// PolyMul performs polynomial multiplication using Barrett reduction.
func (g *NTTAccelerator) PolyMul(r *ring.Ring, a, b, out ring.Poly) error {
r.MulCoeffsBarrett(a, b, out)
atomic.AddUint64(&g.stats.TotalOps, 1)
return nil
}
// ClearCache is a no-op for CPU implementation (no GPU cache).
func (g *NTTAccelerator) ClearCache() {}
// Stats returns current NTT accelerator statistics.
func (g *NTTAccelerator) Stats() NTTStats {
g.statsmu.RLock()
defer g.statsmu.RUnlock()
return NTTStats{
Enabled: true,
Backend: "CPU (Pure Go lattice)",
TotalOps: atomic.LoadUint64(&g.stats.TotalOps),
GPUAvailable: false, // CPU-only build
}
}
// Global accelerator instance
var (
globalNTTAccelerator *NTTAccelerator
globalNTTAcceleratorOnce sync.Once
)
// GetNTTAccelerator returns the global NTT accelerator instance.
func GetNTTAccelerator() (*NTTAccelerator, error) {
globalNTTAcceleratorOnce.Do(func() {
globalNTTAccelerator, _ = NewNTTAccelerator()
})
return globalNTTAccelerator, nil
}
-469
View File
@@ -1,469 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//go:build cgo
// Package quasar provides GPU-accelerated NTT operations for Corona consensus.
// This uses the unified lux/accel package for GPU acceleration of lattice
// operations in the Corona threshold signature protocol.
//
// GPU acceleration provides 40x+ speedup for NTT operations on Apple Silicon
// and NVIDIA GPUs via the accel library (Metal/CUDA/CPU backends).
//
// Architecture:
//
// luxcpp/accel (C++ GPU) → lux/accel (Go CGO) → Quasar consensus
//
// This enables consistent GPU acceleration across:
// - Corona threshold signatures
// - ML-DSA post-quantum signatures
// - FHE operations (via luxcpp/fhe which reuses luxcpp/lattice)
package quasar
import (
"fmt"
"sync"
"sync/atomic"
"github.com/luxfi/accel"
"github.com/luxfi/lattice/v7/ring"
"github.com/luxfi/node/config"
)
// NTTAccelerator provides GPU-accelerated NTT operations for Corona.
// It uses the unified lux/accel package for Metal/CUDA/CPU backends.
type NTTAccelerator struct {
mu sync.RWMutex
session *accel.Session
enabled bool
totalOps uint64
}
// NTTOptions holds options for creating an NTT accelerator.
type NTTOptions struct {
// Enabled controls whether GPU acceleration is used
Enabled bool
// Backend specifies which GPU backend to use: "auto", "metal", "cuda", "cpu"
Backend string
// DeviceIndex specifies which GPU device to use
DeviceIndex int
}
// NewNTTAccelerator creates a new NTT accelerator with GPU support.
// It auto-detects available GPU backends (Metal on macOS, CUDA on Linux).
func NewNTTAccelerator() (*NTTAccelerator, error) {
return NewNTTAcceleratorWithOptions(NTTOptions{})
}
// NewNTTAcceleratorWithOptions creates a new NTT accelerator with custom options.
// If options are zero-valued, it uses the global GPU config.
func NewNTTAcceleratorWithOptions(opts NTTOptions) (*NTTAccelerator, error) {
// Get global config if options not specified
gpuCfg := config.GetGlobalGPUConfig()
// Determine if GPU should be enabled
enabled := gpuCfg.Enabled
if opts.Backend == "cpu" {
enabled = false
}
// Check if GPU is available via accel library
available := accel.Available() && enabled
var session *accel.Session
if available {
var err error
session, err = accel.DefaultSession()
if err != nil {
// Fall back to CPU mode
available = false
}
}
return &NTTAccelerator{
session: session,
enabled: available,
}, nil
}
// IsEnabled returns whether GPU acceleration is available.
func (g *NTTAccelerator) IsEnabled() bool {
g.mu.RLock()
defer g.mu.RUnlock()
return g.enabled
}
// Backend returns the name of the active GPU backend.
func (g *NTTAccelerator) Backend() string {
g.mu.RLock()
defer g.mu.RUnlock()
if !g.enabled || g.session == nil {
return "CPU (GPU not available)"
}
return g.session.Backend().String()
}
// getModulus extracts the first modulus from the ring.
func (g *NTTAccelerator) getModulus(r *ring.Ring) (uint32, error) {
if len(r.ModuliChain()) == 0 {
return 0, fmt.Errorf("ring has no moduli")
}
return uint32(r.ModuliChain()[0]), nil
}
// NTTForward performs forward NTT on a polynomial using GPU acceleration.
// Falls back to CPU if GPU is not available.
func (g *NTTAccelerator) NTTForward(r *ring.Ring, poly ring.Poly) error {
if !g.enabled || g.session == nil {
// Fall back to lattice library's NTT
r.NTT(poly, poly)
return nil
}
N := r.N()
coeffs := poly.Coeffs
if len(coeffs) == 0 || len(coeffs[0]) < N {
r.NTT(poly, poly)
return nil
}
Q, err := g.getModulus(r)
if err != nil {
r.NTT(poly, poly)
return nil
}
// Create input tensor from polynomial coefficients
inputTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, coeffs[0][:N])
if err != nil {
r.NTT(poly, poly)
return nil
}
defer inputTensor.Close()
// Create output tensor
outputTensor, err := accel.NewTensor[uint64](g.session, []int{N})
if err != nil {
r.NTT(poly, poly)
return nil
}
defer outputTensor.Close()
// GPU NTT via accel Lattice ops
if err := g.session.Lattice().PolynomialNTT(inputTensor.Untyped(), outputTensor.Untyped(), Q); err != nil {
r.NTT(poly, poly)
return nil
}
// Copy result back
result, err := outputTensor.ToSlice()
if err != nil {
r.NTT(poly, poly)
return nil
}
copy(coeffs[0], result)
atomic.AddUint64(&g.totalOps, 1)
return nil
}
// NTTInverse performs inverse NTT on a polynomial using GPU acceleration.
// Falls back to CPU if GPU is not available.
func (g *NTTAccelerator) NTTInverse(r *ring.Ring, poly ring.Poly) error {
if !g.enabled || g.session == nil {
// Fall back to lattice library's INTT
r.INTT(poly, poly)
return nil
}
N := r.N()
coeffs := poly.Coeffs
if len(coeffs) == 0 || len(coeffs[0]) < N {
r.INTT(poly, poly)
return nil
}
Q, err := g.getModulus(r)
if err != nil {
r.INTT(poly, poly)
return nil
}
// Create input tensor from polynomial coefficients
inputTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, coeffs[0][:N])
if err != nil {
r.INTT(poly, poly)
return nil
}
defer inputTensor.Close()
// Create output tensor
outputTensor, err := accel.NewTensor[uint64](g.session, []int{N})
if err != nil {
r.INTT(poly, poly)
return nil
}
defer outputTensor.Close()
// GPU INTT via accel Lattice ops
if err := g.session.Lattice().PolynomialINTT(inputTensor.Untyped(), outputTensor.Untyped(), Q); err != nil {
r.INTT(poly, poly)
return nil
}
// Copy result back
result, err := outputTensor.ToSlice()
if err != nil {
r.INTT(poly, poly)
return nil
}
copy(coeffs[0], result)
atomic.AddUint64(&g.totalOps, 1)
return nil
}
// BatchNTTForward performs forward NTT on multiple polynomials in parallel.
// This is the primary use case for GPU acceleration - batch operations.
func (g *NTTAccelerator) BatchNTTForward(r *ring.Ring, polys []ring.Poly) error {
if len(polys) == 0 {
return nil
}
if !g.enabled || g.session == nil || len(polys) < 4 {
// Fall back to CPU for small batches (GPU overhead not worth it)
for i := range polys {
r.NTT(polys[i], polys[i])
}
return nil
}
Q, err := g.getModulus(r)
if err != nil {
for i := range polys {
r.NTT(polys[i], polys[i])
}
return nil
}
// Process each polynomial through GPU
// Note: For true batch performance, we'd want batch tensor operations
// but the current accel API operates on single polynomials
N := r.N()
for i := range polys {
coeffs := polys[i].Coeffs
if len(coeffs) == 0 || len(coeffs[0]) < N {
r.NTT(polys[i], polys[i])
continue
}
inputTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, coeffs[0][:N])
if err != nil {
r.NTT(polys[i], polys[i])
continue
}
outputTensor, err := accel.NewTensor[uint64](g.session, []int{N})
if err != nil {
inputTensor.Close()
r.NTT(polys[i], polys[i])
continue
}
if err := g.session.Lattice().PolynomialNTT(inputTensor.Untyped(), outputTensor.Untyped(), Q); err != nil {
inputTensor.Close()
outputTensor.Close()
r.NTT(polys[i], polys[i])
continue
}
result, err := outputTensor.ToSlice()
if err != nil {
inputTensor.Close()
outputTensor.Close()
r.NTT(polys[i], polys[i])
continue
}
copy(coeffs[0], result)
inputTensor.Close()
outputTensor.Close()
}
atomic.AddUint64(&g.totalOps, uint64(len(polys)))
return nil
}
// BatchNTTInverse performs inverse NTT on multiple polynomials in parallel.
func (g *NTTAccelerator) BatchNTTInverse(r *ring.Ring, polys []ring.Poly) error {
if len(polys) == 0 {
return nil
}
if !g.enabled || g.session == nil || len(polys) < 4 {
// Fall back to CPU for small batches
for i := range polys {
r.INTT(polys[i], polys[i])
}
return nil
}
Q, err := g.getModulus(r)
if err != nil {
for i := range polys {
r.INTT(polys[i], polys[i])
}
return nil
}
// Process each polynomial through GPU
N := r.N()
for i := range polys {
coeffs := polys[i].Coeffs
if len(coeffs) == 0 || len(coeffs[0]) < N {
r.INTT(polys[i], polys[i])
continue
}
inputTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, coeffs[0][:N])
if err != nil {
r.INTT(polys[i], polys[i])
continue
}
outputTensor, err := accel.NewTensor[uint64](g.session, []int{N})
if err != nil {
inputTensor.Close()
r.INTT(polys[i], polys[i])
continue
}
if err := g.session.Lattice().PolynomialINTT(inputTensor.Untyped(), outputTensor.Untyped(), Q); err != nil {
inputTensor.Close()
outputTensor.Close()
r.INTT(polys[i], polys[i])
continue
}
result, err := outputTensor.ToSlice()
if err != nil {
inputTensor.Close()
outputTensor.Close()
r.INTT(polys[i], polys[i])
continue
}
copy(coeffs[0], result)
inputTensor.Close()
outputTensor.Close()
}
atomic.AddUint64(&g.totalOps, uint64(len(polys)))
return nil
}
// PolyMul performs polynomial multiplication using GPU-accelerated NTT.
// This multiplies polynomials a and b, storing result in out.
func (g *NTTAccelerator) PolyMul(r *ring.Ring, a, b, out ring.Poly) error {
if !g.enabled || g.session == nil {
// Fall back to CPU
r.MulCoeffsBarrett(a, b, out)
return nil
}
Q, err := g.getModulus(r)
if err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
N := r.N()
// Extract coefficients
if len(a.Coeffs) == 0 || len(a.Coeffs[0]) < N ||
len(b.Coeffs) == 0 || len(b.Coeffs[0]) < N ||
len(out.Coeffs) == 0 || len(out.Coeffs[0]) < N {
r.MulCoeffsBarrett(a, b, out)
return nil
}
// Create tensors for a, b, and output
aTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, a.Coeffs[0][:N])
if err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
defer aTensor.Close()
bTensor, err := accel.NewTensorWithData[uint64](g.session, []int{N}, b.Coeffs[0][:N])
if err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
defer bTensor.Close()
outTensor, err := accel.NewTensor[uint64](g.session, []int{N})
if err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
defer outTensor.Close()
// GPU polynomial multiplication
if err := g.session.Lattice().PolynomialMul(aTensor.Untyped(), bTensor.Untyped(), outTensor.Untyped(), Q); err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
// Copy result back
result, err := outTensor.ToSlice()
if err != nil {
r.MulCoeffsBarrett(a, b, out)
return nil
}
copy(out.Coeffs[0], result)
atomic.AddUint64(&g.totalOps, 1)
return nil
}
// ClearCache is a no-op in the accel-based implementation.
// The accel library manages its own caching internally.
func (g *NTTAccelerator) ClearCache() {
// No-op: accel library manages caching internally
}
// NTTStats returns NTT accelerator statistics.
type NTTStats struct {
Enabled bool
Backend string
TotalOps uint64
GPUAvailable bool
}
// Stats returns current NTT accelerator statistics.
func (g *NTTAccelerator) Stats() NTTStats {
g.mu.RLock()
defer g.mu.RUnlock()
return NTTStats{
Enabled: g.enabled,
Backend: g.Backend(),
TotalOps: atomic.LoadUint64(&g.totalOps),
GPUAvailable: accel.Available(),
}
}
// Global NTT accelerator instance (lazily initialized)
var (
globalNTTAccelerator *NTTAccelerator
globalNTTAcceleratorOnce sync.Once
globalNTTAcceleratorErr error
)
// GetNTTAccelerator returns the global NTT accelerator instance.
// The accelerator is lazily initialized on first call.
func GetNTTAccelerator() (*NTTAccelerator, error) {
globalNTTAcceleratorOnce.Do(func() {
globalNTTAccelerator, globalNTTAcceleratorErr = NewNTTAccelerator()
})
return globalNTTAccelerator, globalNTTAcceleratorErr
}
-448
View File
@@ -1,448 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"crypto/rand"
"runtime"
"sync"
"testing"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/stretchr/testify/require"
)
// ---------------------------------------------------------------------------
// Test 1: Finalized map pruning
// ---------------------------------------------------------------------------
// TestFinalizedMapPruning simulates 100,000 finality events and verifies:
// - The finalized map never exceeds maxFinalized + buffer
// - Old entries are actually pruned
// - After 100K events, map size <= 10,000
func TestFinalizedMapPruning(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// maxFinalized is 10,000 by default (set in NewQuasar)
const totalEvents = 100_000
// We simulate processFinality's pruning logic directly by
// inserting entries and triggering the prune path.
// processFinality increments qHeight and prunes when len > maxFinalized.
var peakSize int
for i := 0; i < totalEvents; i++ {
var blockID ids.ID
_, _ = rand.Read(blockID[:])
q.mu.Lock()
q.qHeight++
q.finalized[blockID] = &QuantumFinality{
BlockID: blockID,
QChainHeight: q.qHeight,
PChainHeight: uint64(i),
TotalWeight: 1000,
SignerWeight: 700,
}
// Replicate the pruning logic from processFinality
if q.maxFinalized > 0 && len(q.finalized) > q.maxFinalized {
cutoff := q.qHeight - uint64(q.maxFinalized)
for id, f := range q.finalized {
if f.QChainHeight < cutoff {
delete(q.finalized, id)
}
}
}
size := len(q.finalized)
if size > peakSize {
peakSize = size
}
q.mu.Unlock()
}
q.mu.RLock()
finalSize := len(q.finalized)
finalQHeight := q.qHeight
q.mu.RUnlock()
t.Logf("totalEvents=%d peakSize=%d finalSize=%d qHeight=%d",
totalEvents, peakSize, finalSize, finalQHeight)
// The pruning logic fires when len > maxFinalized, then deletes entries
// with QChainHeight < cutoff (strict <). The cutoff is qHeight - maxFinalized.
// After pruning, entries at exactly cutoff remain, so the steady-state
// size is maxFinalized + 1. This is correct and bounded.
require.LessOrEqual(t, peakSize, q.maxFinalized+1,
"peak map size should not exceed maxFinalized+1")
require.LessOrEqual(t, finalSize, q.maxFinalized+1,
"final map size should be <= maxFinalized+1 (10,001)")
// Verify old entries are actually gone: the oldest remaining entry
// should have QChainHeight >= qHeight - maxFinalized.
q.mu.RLock()
minHeight := uint64(^uint64(0))
for _, f := range q.finalized {
if f.QChainHeight < minHeight {
minHeight = f.QChainHeight
}
}
q.mu.RUnlock()
expectedMinHeight := finalQHeight - uint64(q.maxFinalized)
require.GreaterOrEqual(t, minHeight, expectedMinHeight,
"oldest entry should be pruned: minHeight=%d expected>=%d", minHeight, expectedMinHeight)
}
// ---------------------------------------------------------------------------
// Test 2: Channel backpressure -- no goroutine leak or deadlock
// ---------------------------------------------------------------------------
// TestChannelBackpressure creates a pChainProvider with a 64-buffer channel,
// sends 1000 events, and verifies no goroutine leak or deadlock.
func TestChannelBackpressure(t *testing.T) {
const (
channelSize = 64
totalEvents = 1000
)
validators := generateValidatorStates(5)
pchain := &mockPChainProvider{
height: 0,
validators: validators,
finalityCh: make(chan FinalityEvent, channelSize),
}
goroutinesBefore := runtime.NumGoroutine()
// Send events -- channel will fill up, excess events are dropped (select default)
sent := 0
for i := 0; i < totalEvents; i++ {
event := createTestEvent(uint64(i+1), validators)
select {
case pchain.finalityCh <- event:
sent++
default:
// Channel full -- expected backpressure behavior
}
}
t.Logf("sent %d/%d events (channel capacity %d)", sent, totalEvents, channelSize)
require.GreaterOrEqual(t, sent, channelSize,
"should have sent at least channelSize events")
// Drain the channel
drained := 0
for {
select {
case <-pchain.finalityCh:
drained++
default:
goto done
}
}
done:
t.Logf("drained %d events", drained)
// Check goroutine count -- should not have leaked
runtime.GC()
goroutinesAfter := runtime.NumGoroutine()
// Allow a delta of 5 for GC/runtime goroutines
require.InDelta(t, goroutinesBefore, goroutinesAfter, 5,
"goroutine count should not grow significantly: before=%d after=%d",
goroutinesBefore, goroutinesAfter)
}
// ---------------------------------------------------------------------------
// Test 3: Long-running benchmark -- 1M simulated finality cycles
// ---------------------------------------------------------------------------
// BenchmarkQuasarLongRun runs 1M simulated finality cycles and reports
// allocs/op, bytes/op, ns/op. Verifies no unbounded memory growth.
func BenchmarkQuasarLongRun(b *testing.B) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
if err != nil {
b.Fatal(err)
}
// Snapshot heap before
runtime.GC()
var memBefore runtime.MemStats
runtime.ReadMemStats(&memBefore)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
var blockID ids.ID
// Use deterministic IDs to avoid crypto/rand overhead in benchmark
blockID[0] = byte(i)
blockID[1] = byte(i >> 8)
blockID[2] = byte(i >> 16)
blockID[3] = byte(i >> 24)
q.mu.Lock()
q.qHeight++
q.finalized[blockID] = &QuantumFinality{
BlockID: blockID,
QChainHeight: q.qHeight,
PChainHeight: uint64(i),
TotalWeight: 1000,
SignerWeight: 700,
BLSProof: make([]byte, 96),
Timestamp: time.Now(),
}
// Prune (same logic as processFinality)
if q.maxFinalized > 0 && len(q.finalized) > q.maxFinalized {
cutoff := q.qHeight - uint64(q.maxFinalized)
for id, f := range q.finalized {
if f.QChainHeight < cutoff {
delete(q.finalized, id)
}
}
}
q.mu.Unlock()
}
b.StopTimer()
// Snapshot heap after
runtime.GC()
var memAfter runtime.MemStats
runtime.ReadMemStats(&memAfter)
q.mu.RLock()
finalSize := len(q.finalized)
q.mu.RUnlock()
heapBefore := memBefore.HeapAlloc
heapAfter := memAfter.HeapAlloc
var heapDelta int64
if heapAfter >= heapBefore {
heapDelta = int64(heapAfter - heapBefore)
} else {
heapDelta = -int64(heapBefore - heapAfter)
}
b.Logf("N=%d finalMapSize=%d heapBefore=%d heapAfter=%d heapDelta=%d",
b.N, finalSize, heapBefore, heapAfter, heapDelta)
// Map should be bounded regardless of N
if finalSize > q.maxFinalized+1 {
b.Fatalf("unbounded growth: map size %d exceeds maxFinalized %d",
finalSize, q.maxFinalized)
}
// Heap should not grow linearly with N. After pruning, the heap should
// be bounded by ~maxFinalized entries worth of allocations.
// We allow 100MB as a generous upper bound for 10K entries with 96-byte proofs.
const maxHeapGrowth = 100 * 1024 * 1024 // 100MB
if heapAfter > heapBefore+maxHeapGrowth {
b.Fatalf("unbounded heap growth: before=%d after=%d delta=%d (limit=%d)",
heapBefore, heapAfter, heapAfter-heapBefore, maxHeapGrowth)
}
}
// ---------------------------------------------------------------------------
// Test 4: Quorum math verification -- property test
// ---------------------------------------------------------------------------
// TestQuorumMath is a property test that for all validator counts 1-100
// and all weight distributions:
// - Cross-multiplication quorum never accepts < 2/3 weight
// - Cross-multiplication quorum always accepts >= 2/3 weight (no false negatives)
func TestQuorumMath(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
// The quorum check is: signerWeight * quorumDen >= totalWeight * quorumNum
// With quorumNum=2, quorumDen=3: signerWeight * 3 >= totalWeight * 2
t.Run("no_false_positives", func(t *testing.T) {
// For all validator counts and weight distributions, if the quorum
// check passes, then signerWeight/totalWeight >= 2/3.
for numValidators := 1; numValidators <= 100; numValidators++ {
// Test with equal weights
weightPerValidator := uint64(1000)
totalWeight := uint64(numValidators) * weightPerValidator
for numSigners := 0; numSigners <= numValidators; numSigners++ {
signerWeight := uint64(numSigners) * weightPerValidator
result := q.CheckQuorum(signerWeight, totalWeight)
// Verify: if result is true, then signerWeight/totalWeight >= 2/3
// Using cross-multiplication: signerWeight * 3 >= totalWeight * 2
actualMeetsThreshold := signerWeight*3 >= totalWeight*2
if result && !actualMeetsThreshold {
t.Fatalf("FALSE POSITIVE: n=%d signers=%d sW=%d tW=%d: "+
"quorum accepted but %d*3=%d < %d*2=%d",
numValidators, numSigners, signerWeight, totalWeight,
signerWeight, signerWeight*3, totalWeight, totalWeight*2)
}
}
}
})
t.Run("no_false_negatives", func(t *testing.T) {
// For all validator counts and weight distributions, if
// signerWeight/totalWeight >= 2/3, the quorum check must pass.
for numValidators := 1; numValidators <= 100; numValidators++ {
weightPerValidator := uint64(1000)
totalWeight := uint64(numValidators) * weightPerValidator
for numSigners := 0; numSigners <= numValidators; numSigners++ {
signerWeight := uint64(numSigners) * weightPerValidator
result := q.CheckQuorum(signerWeight, totalWeight)
actualMeetsThreshold := signerWeight*3 >= totalWeight*2
if actualMeetsThreshold && !result {
t.Fatalf("FALSE NEGATIVE: n=%d signers=%d sW=%d tW=%d: "+
"threshold met but quorum rejected",
numValidators, numSigners, signerWeight, totalWeight)
}
}
}
})
t.Run("varied_weight_distributions", func(t *testing.T) {
// Test with non-uniform weights: validators have weights 1..n
for numValidators := 1; numValidators <= 100; numValidators++ {
var totalWeight uint64
weights := make([]uint64, numValidators)
for i := 0; i < numValidators; i++ {
weights[i] = uint64(i + 1)
totalWeight += weights[i]
}
// Test subsets: first k validators sign
var signerWeight uint64
for k := 0; k <= numValidators; k++ {
if k > 0 {
signerWeight += weights[k-1]
}
result := q.CheckQuorum(signerWeight, totalWeight)
expected := signerWeight*3 >= totalWeight*2
if result != expected {
t.Fatalf("MISMATCH: n=%d signers=%d sW=%d tW=%d: "+
"got %v expected %v",
numValidators, k, signerWeight, totalWeight,
result, expected)
}
}
}
})
t.Run("edge_cases", func(t *testing.T) {
// Zero total weight: any signer weight passes (vacuously true)
require.True(t, q.CheckQuorum(0, 0), "0/0 should pass (vacuous)")
require.True(t, q.CheckQuorum(1, 0), "1/0 should pass (vacuous)")
// Exact boundary: 2/3 of various totals
// For totalWeight=3: need signerWeight >= 2
require.True(t, q.CheckQuorum(2, 3), "2/3 should pass")
require.False(t, q.CheckQuorum(1, 3), "1/3 should fail")
// For totalWeight=6: need signerWeight >= 4
require.True(t, q.CheckQuorum(4, 6), "4/6 should pass")
require.False(t, q.CheckQuorum(3, 6), "3/6 should fail")
// For totalWeight=9: need signerWeight >= 6
require.True(t, q.CheckQuorum(6, 9), "6/9 should pass")
require.False(t, q.CheckQuorum(5, 9), "5/9 should fail")
// For totalWeight=100: 2*100/3 = 66 (floor), so need 67 to be strictly >= 2/3
// But cross-mult: sW*3 >= tW*2 → sW*3 >= 200 → sW >= 67 (ceil)
// Actually: 66*3=198 < 200 → fail; 67*3=201 >= 200 → pass
require.True(t, q.CheckQuorum(67, 100), "67/100 should pass")
require.False(t, q.CheckQuorum(66, 100), "66/100 should fail")
// Large weights (near overflow boundary for uint64)
// Safe for totalWeight < 2^62 with quorumNum=2 (per checkQuorum doc)
largeTotal := uint64(1) << 61
largeSigner := largeTotal*2/3 + 1
require.True(t, q.CheckQuorum(largeSigner, largeTotal),
"large weight should pass when above 2/3")
})
t.Run("bft_threshold_exact", func(t *testing.T) {
// BFT requires > 2/3 of total weight.
// With the cross-multiplication check (>=), signerWeight*3 >= totalWeight*2.
// This means exactly 2/3 PASSES (which matches the formal spec:
// "quorum is met when SignerWeight/TotalWeight >= Numerator/Denominator").
//
// For totalWeight divisible by 3:
// signerWeight = totalWeight * 2 / 3 → passes (exact 2/3)
// signerWeight = totalWeight * 2 / 3 - 1 → fails (below 2/3)
for total := uint64(3); total <= 300; total += 3 {
threshold := total * 2 / 3
require.True(t, q.CheckQuorum(threshold, total),
"exact 2/3 (%d/%d) should pass", threshold, total)
require.False(t, q.CheckQuorum(threshold-1, total),
"below 2/3 (%d/%d) should fail", threshold-1, total)
}
})
}
// ---------------------------------------------------------------------------
// Test 5: Concurrent map pruning stress test
// ---------------------------------------------------------------------------
// TestConcurrentPruningStress verifies that concurrent writes + pruning
// do not corrupt the finalized map or deadlock.
func TestConcurrentPruningStress(t *testing.T) {
q, err := NewQuasar(log.NewNoOpLogger(), 3, 2, 3)
require.NoError(t, err)
const (
numWriters = 8
opsPerWriter = 5000
)
var wg sync.WaitGroup
for w := 0; w < numWriters; w++ {
wg.Add(1)
go func(writerID int) {
defer wg.Done()
for i := 0; i < opsPerWriter; i++ {
var blockID ids.ID
blockID[0] = byte(writerID)
blockID[1] = byte(i)
blockID[2] = byte(i >> 8)
q.mu.Lock()
q.qHeight++
q.finalized[blockID] = &QuantumFinality{
BlockID: blockID,
QChainHeight: q.qHeight,
}
if q.maxFinalized > 0 && len(q.finalized) > q.maxFinalized {
cutoff := q.qHeight - uint64(q.maxFinalized)
for id, f := range q.finalized {
if f.QChainHeight < cutoff {
delete(q.finalized, id)
}
}
}
q.mu.Unlock()
}
}(w)
}
wg.Wait()
q.mu.RLock()
finalSize := len(q.finalized)
q.mu.RUnlock()
t.Logf("writers=%d opsEach=%d totalOps=%d finalSize=%d",
numWriters, opsPerWriter, numWriters*opsPerWriter, finalSize)
require.LessOrEqual(t, finalSize, q.maxFinalized+1,
"map size should be bounded after concurrent stress")
}
+27
View File
@@ -0,0 +1,27 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"fmt"
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// policyStore adapts the single configured QuasarEvidencePolicy to the consensus
// ConsensusCertPolicyStore interface. The verifier loads the required-leg set
// and the (kind, mode, param) permissions from HERE — never from the cert
// (invariants I1/I2). A cert that names a different PolicyID than the node's
// configured posture is rejected: a cert cannot pick its own weaker policy.
type policyStore struct{ policy *qcert.QuasarEvidencePolicy }
func (s policyStore) Policy(_ uint32, _ uint64, policyID uint32) (qcert.ConsensusCertPolicy, error) {
if s.policy == nil {
return nil, ErrPolicyUnavailable
}
if policyID != s.policy.EvidencePolicyID() {
return nil, fmt.Errorf("%w: cert policy %d != configured %d", ErrPolicyMismatch, policyID, s.policy.EvidencePolicyID())
}
return s.policy, nil
}
+83
View File
@@ -0,0 +1,83 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"context"
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// Subject is the finalized-block position a cert must certify — the producer's
// input at a checkpoint. Mirrors Checkpoint (the verify side) so producer and
// verifier bind the SAME tuple.
type Subject struct {
ChainID uint32
Epoch uint64
Height uint64
Round uint32
BlockID [32]byte
StateRoot [32]byte
}
// subjectFrom derives the producer Subject from this gate's chain id and a
// finalized Checkpoint, so producer and verifier bind the SAME tuple.
func (g *Gate) subjectFrom(cp Checkpoint) Subject {
return Subject{
ChainID: g.cfg.ChainID,
Epoch: cp.Epoch,
Height: cp.Height,
Round: cp.Round,
BlockID: cp.BlockID,
StateRoot: cp.StateRoot,
}
}
// Producer is the committee cert-signing service contract (the per-validator
// "pulsard" committee). At a checkpoint, a producing validator calls Produce to
// obtain the QuasarCert over the finalized subject, then gossips it so peers can
// verify and store it (via a CertStore).
//
// SCAFFOLDING — this is the seam, not the service. This milestone wires the
// VERIFY half (gate.go) and this interface. luxd ships with a nil Producer
// (verify-only): a node VERIFIES certs it receives but does not itself produce
// them. A nil Producer is the correct default — most of the rollout window is
// verify-only, and the producer is brought up before activation is forward-dated.
//
// Implementation path for the follow-on:
//
// - github.com/luxfi/consensus/protocol/quasar already defines the
// producer-side abstractions: PWitnessProducer / QWitnessProducer /
// ZWitnessProducer + NewWitnessSet, and ComposeDualPQEvidence. The concrete
// committee signer implements Producer over those.
// - The signer needs the live Pulsar key share + nonce pool + offline
// preprocessing + one-round sign + verify-before-gossip + nonce-erase (the
// no-reconstruct hyperball signer), which lands with pulsar v1.7.1.
// - REQUIRED CONSENSUS EXPORT: the ConsensusCert envelope + per-leg payload
// ENCODERS are package-private in consensus v1.29.0 (only the verifiers are
// exported). An external producer — and any end-to-end "valid cert verifies
// through the gate" test — needs those encoders exported (a small, additive
// consensus change). The verify path here needs no such export: it consumes
// a fully-formed *ConsensusCert.
type Producer interface {
Produce(ctx context.Context, subject Subject) (*qcert.ConsensusCert, error)
}
// MaybeProduce is the checkpoint producer-request site. It is nil-safe and
// activation-aware so the accept hook can call it unconditionally: a nil gate,
// dormant activation, a non-checkpoint height, or a nil producer all short-
// circuit to (nil, nil) — the verify-only default. When a producer IS wired and
// the checkpoint is live, it requests the cert; the caller gossips/stores it.
//
// This keeps producer cadence and verify cadence on ONE definition (g.IsCheckpoint),
// so producer and verifier can never disagree on which heights carry certs.
func (g *Gate) MaybeProduce(ctx context.Context, producer Producer, cp Checkpoint) (*qcert.ConsensusCert, error) {
if g == nil || producer == nil {
return nil, nil
}
if !g.Activated(cp.Height) || !g.IsCheckpoint(cp.Height) {
return nil, nil
}
return producer.Produce(ctx, g.subjectFrom(cp))
}
-681
View File
@@ -1,681 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"context"
"errors"
"fmt"
"sync"
"time"
"github.com/luxfi/consensus/protocol/quasar"
"github.com/luxfi/ids"
"github.com/luxfi/log"
)
// Quasar is the gravitational center of Lux consensus.
// It binds P-Chain (BLS signatures) and Q-Chain (Corona post-quantum threshold)
// into unified hybrid finality across all Lux networks.
//
// Architecture:
// ALL validators have BOTH keypairs:
// - BLS keypair → aggregate signatures (classical, fast)
// - Corona keypair → threshold signatures (post-quantum, 2-round)
//
// Both signature paths run IN PARALLEL:
//
// Block arrives
// │
// ├─────────────────────────────────────────┐
// │ │
// ▼ ▼
// BLS PATH (fast) CORONA PATH (quantum-safe)
// ──────────────── ─────────────────────────────
// All validators sign Round 1: All validators
// with BLS keys generate commitments
// │ │
// ▼ ▼
// Aggregate into Round 2: All validators
// single 96-byte sig compute partial signatures
// │ │
// └─────────────────┬───────────────────────┘
// │
// ▼
// Finalize: combine into
// threshold signature
// │
// ▼
// ┌─────────────────┐
// │ HYBRID PROOF │
// │ BLS Aggregate │ ← 96 bytes (2/3+ validators)
// │ Corona Thresh │ ← ~KB (t-of-n threshold)
// └─────────────────┘
// │
// ▼
// QUANTUM FINALITY
//
// The quasar ensures blocks achieve finality only when BOTH complete:
// 1. 2/3+ validator weight signed via BLS (fast, classical)
// 2. t-of-n validators completed Corona threshold (post-quantum secure)
var (
ErrQuasarNotStarted = errors.New("quasar not started")
ErrPChainNotConnected = errors.New("P-Chain not connected")
ErrQChainNotConnected = errors.New("Q-Chain not connected")
ErrCoronaNotConnected = errors.New("Corona coordinator not connected")
ErrInsufficientWeight = errors.New("insufficient validator weight")
ErrInsufficientSigners = errors.New("insufficient Corona signers")
ErrFinalityFailed = errors.New("hybrid finality verification failed")
ErrBLSFailed = errors.New("BLS aggregation failed")
ErrCoronaFailed = errors.New("Corona threshold signing failed")
)
// PChainProvider provides P-Chain state and finality events
type PChainProvider interface {
GetFinalizedHeight() uint64
GetValidators(height uint64) ([]ValidatorState, error)
SubscribeFinality() <-chan FinalityEvent
}
// QuantumSignerFallback provides fallback single-signer quantum signatures
type QuantumSignerFallback interface {
SignMessage(msg []byte) ([]byte, error)
}
// ValidatorState represents a validator's current state
// Each validator has BOTH BLS and Corona keys
type ValidatorState struct {
NodeID ids.NodeID
Weight uint64
BLSPubKey []byte // BLS public key for aggregate signatures
CoronaKey []byte // Corona public key share for threshold sigs
Active bool
}
// FinalityEvent represents a P-Chain finality event
type FinalityEvent struct {
Height uint64
BlockID ids.ID
Validators []ValidatorState
Timestamp time.Time
}
// QuantumFinality represents a block that achieved hybrid quantum finality
type QuantumFinality struct {
BlockID ids.ID
PChainHeight uint64
QChainHeight uint64
BLSProof []byte // Aggregated BLS signature (96 bytes)
CoronaProof []byte // Serialized Corona threshold signature
SignerBitset []byte // Which validators signed BLS
CoronaSigners []ids.NodeID // Which validators participated in Corona
TotalWeight uint64
SignerWeight uint64
BLSLatency time.Duration
CoronaLatency time.Duration
Timestamp time.Time
}
// Quasar binds P-Chain and Q-Chain consensus into hybrid quantum finality
type Quasar struct {
mu sync.RWMutex
log log.Logger
core *quasar.Quasar
// Chain connections
pChain PChainProvider
quantumFallback QuantumSignerFallback
// Corona threshold coordinator
corona *CoronaCoordinator
// State
pHeight uint64
qHeight uint64
finalized map[ids.ID]*QuantumFinality
// Configuration
threshold int // Corona threshold (t in t-of-n)
quorumNum uint64 // BLS quorum numerator
quorumDen uint64 // BLS quorum denominator
maxFinalized int // max finalized entries before pruning
// Channels
finalityCh chan *QuantumFinality
stopCh chan struct{}
running bool
}
// NewQuasar creates a new Quasar consensus hub
func NewQuasar(log log.Logger, threshold int, quorumNum, quorumDen uint64) (*Quasar, error) {
core, err := quasar.NewQuasar(threshold)
if err != nil {
return nil, fmt.Errorf("failed to create quasar core: %w", err)
}
return &Quasar{
log: log,
core: core,
threshold: threshold,
quorumNum: quorumNum,
quorumDen: quorumDen,
finalized: make(map[ids.ID]*QuantumFinality),
maxFinalized: 10000,
finalityCh: make(chan *QuantumFinality, 100),
stopCh: make(chan struct{}),
}, nil
}
// ConnectPChain connects the P-Chain finality provider
func (q *Quasar) ConnectPChain(p PChainProvider) {
q.mu.Lock()
defer q.mu.Unlock()
q.pChain = p
if p != nil {
q.pHeight = p.GetFinalizedHeight()
}
q.log.Info("quasar: P-Chain connected", "height", q.pHeight)
}
// ConnectQuantumFallback connects the quantum signer fallback
func (q *Quasar) ConnectQuantumFallback(f QuantumSignerFallback) {
q.mu.Lock()
defer q.mu.Unlock()
q.quantumFallback = f
q.log.Info("quasar: quantum fallback connected")
}
// ConnectCorona connects the Corona threshold coordinator
func (q *Quasar) ConnectCorona(rc *CoronaCoordinator) {
q.mu.Lock()
defer q.mu.Unlock()
q.corona = rc
q.log.Info("quasar: Corona coordinator connected")
}
// InitializeCorona initializes the Corona coordinator with validators
func (q *Quasar) InitializeCorona(validators []ids.NodeID) error {
q.mu.Lock()
defer q.mu.Unlock()
if q.corona == nil {
// Create coordinator if not provided
numParties := len(validators)
threshold := (numParties * 2 / 3) + 1 // 2/3 + 1 threshold
if threshold < 2 {
threshold = 2
}
rc, err := NewCoronaCoordinator(q.log, CoronaConfig{
NumParties: numParties,
Threshold: threshold,
})
if err != nil {
return fmt.Errorf("failed to create Corona coordinator: %w", err)
}
q.corona = rc
}
if err := q.corona.Initialize(validators); err != nil {
return fmt.Errorf("failed to initialize Corona: %w", err)
}
q.log.Info("quasar: Corona initialized",
"validators", len(validators),
"threshold", q.corona.Stats().Threshold,
)
return nil
}
// Start begins the quasar consensus loop
func (q *Quasar) Start(ctx context.Context) error {
q.mu.Lock()
if q.pChain == nil {
q.mu.Unlock()
return ErrPChainNotConnected
}
if q.quantumFallback == nil {
q.mu.Unlock()
return ErrQChainNotConnected
}
q.running = true
q.mu.Unlock()
// Subscribe to P-Chain finality
sub := q.pChain.SubscribeFinality()
go q.run(ctx, sub)
q.log.Info("quasar: started")
return nil
}
// Stop halts the quasar
func (q *Quasar) Stop() {
q.mu.Lock()
if q.running {
close(q.stopCh)
q.running = false
}
q.mu.Unlock()
q.log.Info("quasar: stopped")
}
// run is the main finality loop.
// Bounded by ctx.Done() and q.stopCh — exits when either fires.
// The goroutine is started in Start() and guaranteed to terminate
// when Stop() closes stopCh or the parent context is cancelled.
func (q *Quasar) run(ctx context.Context, sub <-chan FinalityEvent) {
for {
select {
case <-ctx.Done():
return
case <-q.stopCh:
return
case event := <-sub:
if err := q.processFinality(ctx, event); err != nil {
q.log.Error("quasar: finality failed",
"height", event.Height,
"error", err,
)
}
}
}
}
// processFinality processes a P-Chain finality event into hybrid finality
// Both BLS and Corona paths run IN PARALLEL
func (q *Quasar) processFinality(ctx context.Context, event FinalityEvent) error {
q.mu.Lock()
defer q.mu.Unlock()
// Sync validators to quasar core
for _, v := range event.Validators {
if v.Active {
_, _ = q.core.AddValidator(v.NodeID.String(), v.Weight)
}
}
// Create finality message
msg := q.createMessage(event)
msgStr := string(msg) // Corona uses string message
// Run BLS and Corona IN PARALLEL
var blsProof, signerBitset []byte
var signerWeight uint64
var coronaSig Signature
var blsLatency, coronaLatency time.Duration
var blsErr, coronaErr error
var wg sync.WaitGroup
// BLS path
wg.Add(1)
go func() {
defer wg.Done()
start := time.Now()
blsProof, signerBitset, signerWeight, blsErr = q.collectBLS(event, msg)
blsLatency = time.Since(start)
}()
// Corona path - REQUIRED for Q-Chain validator consensus.
// No fallback mode: if Corona coordinator is not initialized,
// finality MUST fail to prevent accepting BLS-only proofs.
wg.Add(1)
go func() {
defer wg.Done()
if q.corona == nil || !q.corona.IsInitialized() {
// STRICT: No fallback allowed for validators.
// RT signatures are REQUIRED for quantum-safe consensus.
coronaErr = ErrCoronaNotConnected
return
}
// Full threshold signing
start := time.Now()
coronaSig, coronaErr = q.collectCorona(msgStr)
coronaLatency = time.Since(start)
}()
wg.Wait()
// Check BLS result
if blsErr != nil {
return fmt.Errorf("BLS collection: %w", blsErr)
}
// Check Corona result
if coronaErr != nil {
return fmt.Errorf("Corona threshold: %w", coronaErr)
}
// Check quorum
totalWeight := q.totalWeight(event.Validators)
if !q.checkQuorum(signerWeight, totalWeight) {
return ErrInsufficientWeight
}
// Record finality
q.qHeight++
var coronaSigners []ids.NodeID
var coronaProof []byte
if coronaSig != nil {
coronaSigners = coronaSig.Signers()
coronaProof = coronaSig.Bytes()
}
finality := &QuantumFinality{
BlockID: event.BlockID,
PChainHeight: event.Height,
QChainHeight: q.qHeight,
BLSProof: blsProof,
CoronaProof: coronaProof,
SignerBitset: signerBitset,
CoronaSigners: coronaSigners,
TotalWeight: totalWeight,
SignerWeight: signerWeight,
BLSLatency: blsLatency,
CoronaLatency: coronaLatency,
Timestamp: time.Now(),
}
q.finalized[event.BlockID] = finality
q.pHeight = event.Height
// Prune old finality entries to bound memory
if q.maxFinalized > 0 && len(q.finalized) > q.maxFinalized {
cutoff := q.qHeight - uint64(q.maxFinalized)
for id, f := range q.finalized {
if f.QChainHeight < cutoff {
delete(q.finalized, id)
}
}
}
// Emit
select {
case q.finalityCh <- finality:
default:
}
q.log.Info("quasar: hybrid finality achieved",
"block", event.BlockID,
"pHeight", event.Height,
"qHeight", q.qHeight,
"weight", fmt.Sprintf("%d/%d", signerWeight, totalWeight),
"blsLatency", blsLatency,
"coronaLatency", coronaLatency,
"coronaSigners", len(coronaSigners),
)
return nil
}
// createMessage creates the finality message to sign
func (q *Quasar) createMessage(event FinalityEvent) []byte {
msg := make([]byte, 48) // 32 (blockID) + 8 (height) + 8 (timestamp)
copy(msg[:32], event.BlockID[:])
putUint64BE(msg[32:40], event.Height)
putUint64BE(msg[40:48], uint64(event.Timestamp.UnixNano()))
return msg
}
// collectBLS collects BLS signatures from validators and aggregates them
func (q *Quasar) collectBLS(event FinalityEvent, msg []byte) ([]byte, []byte, uint64, error) {
var signerBitset []byte
var signerWeight uint64
signatures := make([]*quasar.QuasarSig, 0, len(event.Validators))
for i, v := range event.Validators {
if !v.Active {
continue
}
sig, err := q.core.SignMessage(v.NodeID.String(), msg)
if err != nil {
continue // Skip failed signers
}
signatures = append(signatures, sig)
signerWeight += v.Weight
// Set bit
byteIdx := i / 8
for len(signerBitset) <= byteIdx {
signerBitset = append(signerBitset, 0)
}
signerBitset[byteIdx] |= 1 << uint(i%8)
}
if len(signatures) == 0 {
return nil, nil, 0, errors.New("no BLS signatures")
}
agg, err := q.core.AggregateSignatures(msg, signatures)
if err != nil {
return nil, nil, 0, err
}
return agg.BLSAggregated, signerBitset, signerWeight, nil
}
// collectCorona runs the 2-round Corona threshold protocol in parallel
func (q *Quasar) collectCorona(message string) (Signature, error) {
if q.corona == nil {
return nil, ErrCoronaNotConnected
}
// Use the high-level Sign API which handles all rounds internally
sig, err := q.corona.Sign([]byte(message))
if err != nil {
return nil, fmt.Errorf("corona signing failed: %w", err)
}
// Verify the signature
if !q.corona.Verify([]byte(message), sig) {
return nil, ErrCoronaFailed
}
q.log.Debug("corona signature complete",
"signers", len(sig.Signers()),
"type", sig.Type(),
)
return sig, nil
}
// totalWeight calculates total validator weight
func (q *Quasar) totalWeight(validators []ValidatorState) uint64 {
var total uint64
for _, v := range validators {
if v.Active {
total += v.Weight
}
}
return total
}
// checkQuorum verifies quorum is met using cross-multiplication to avoid
// integer division truncation.
//
// signerWeight / totalWeight >= quorumNum / quorumDen
// is equivalent to:
// signerWeight * quorumDen >= totalWeight * quorumNum
//
// Overflow bound: safe for totalWeight < 2^62 with quorumNum <= 3.
// Production values: totalWeight is sum of validator weights (well under 2^60),
// quorumNum=2, quorumDen=3.
func (q *Quasar) checkQuorum(signerWeight, totalWeight uint64) bool {
return signerWeight*q.quorumDen >= totalWeight*q.quorumNum
}
// GetFinality returns finality for a block
func (q *Quasar) GetFinality(blockID ids.ID) (*QuantumFinality, bool) {
q.mu.RLock()
defer q.mu.RUnlock()
f, ok := q.finalized[blockID]
return f, ok
}
// Subscribe returns channel for finality events
func (q *Quasar) Subscribe() <-chan *QuantumFinality {
return q.finalityCh
}
// Verify verifies a hybrid finality proof.
// Both BLS and Corona proofs are REQUIRED - no fallback mode.
// This ensures quantum-safe consensus for Q-Chain validators.
func (q *Quasar) Verify(finality *QuantumFinality) error {
if finality == nil {
return ErrFinalityFailed
}
// STRICT: Both proofs are REQUIRED
if len(finality.BLSProof) == 0 {
return fmt.Errorf("%w: BLS proof missing", ErrBLSFailed)
}
if len(finality.CoronaProof) == 0 {
return fmt.Errorf("%w: RT proof missing - required for Q-Chain validators", ErrCoronaFailed)
}
if !q.checkQuorum(finality.SignerWeight, finality.TotalWeight) {
return ErrInsufficientWeight
}
// Verify BLS via hybrid engine
agg := &quasar.AggregatedSignature{
BLSAggregated: finality.BLSProof,
}
// Reconstruct message for verification
msg := make([]byte, 48)
copy(msg[:32], finality.BlockID[:])
putUint64BE(msg[32:40], finality.PChainHeight)
putUint64BE(msg[40:48], uint64(finality.Timestamp.UnixNano()))
if !q.core.VerifyAggregatedSignature(msg, agg) {
return ErrBLSFailed
}
// Verify Corona threshold signature
// RT signatures MUST have the "RT" prefix marker followed by threshold data
if len(finality.CoronaProof) < 3 {
return fmt.Errorf("%w: RT proof too short", ErrCoronaFailed)
}
if finality.CoronaProof[0] != 'R' || finality.CoronaProof[1] != 'T' {
return fmt.Errorf("%w: invalid RT proof marker", ErrCoronaFailed)
}
// Verify threshold signers meet minimum requirement
if len(finality.CoronaSigners) < q.threshold {
return fmt.Errorf("%w: need %d signers, have %d",
ErrInsufficientSigners, q.threshold, len(finality.CoronaSigners))
}
return nil
}
// Stats returns quasar statistics
func (q *Quasar) Stats() QuasarStats {
q.mu.RLock()
defer q.mu.RUnlock()
var coronaStats CoronaStats
if q.corona != nil {
coronaStats = q.corona.Stats()
}
return QuasarStats{
PChainHeight: q.pHeight,
QChainHeight: q.qHeight,
FinalizedBlocks: len(q.finalized),
Threshold: q.threshold,
QuorumNum: q.quorumNum,
QuorumDen: q.quorumDen,
Running: q.running,
CoronaParties: coronaStats.NumParties,
CoronaThreshold: coronaStats.Threshold,
CoronaReady: coronaStats.Initialized,
}
}
// QuasarStats contains quasar statistics
type QuasarStats struct {
PChainHeight uint64
QChainHeight uint64
FinalizedBlocks int
Threshold int
QuorumNum uint64
QuorumDen uint64
Running bool
CoronaParties int
CoronaThreshold int
CoronaReady bool
}
// GetCore returns the underlying quasar core for testing
func (q *Quasar) GetCore() *quasar.Quasar {
return q.core
}
// GetCorona returns the Corona coordinator
func (q *Quasar) GetCorona() *CoronaCoordinator {
q.mu.RLock()
defer q.mu.RUnlock()
return q.corona
}
// CheckQuorum verifies quorum is met (exported for testing)
func (q *Quasar) CheckQuorum(signerWeight, totalWeight uint64) bool {
return q.checkQuorum(signerWeight, totalWeight)
}
// CreateMessage creates the finality message to sign (exported for testing)
func (q *Quasar) CreateMessage(event FinalityEvent) []byte {
return q.createMessage(event)
}
// TotalWeight calculates total validator weight (exported for testing)
func (q *Quasar) TotalWeight(validators []ValidatorState) uint64 {
return q.totalWeight(validators)
}
// GetConfig returns quorum configuration (exported for testing)
func (q *Quasar) GetConfig() (threshold int, quorumNum, quorumDen uint64) {
q.mu.RLock()
defer q.mu.RUnlock()
return q.threshold, q.quorumNum, q.quorumDen
}
// IsRunning returns whether the Quasar is currently running (exported for testing)
func (q *Quasar) IsRunning() bool {
q.mu.RLock()
defer q.mu.RUnlock()
return q.running
}
// SetFinalized adds a finality record (exported for testing/benchmarking)
func (q *Quasar) SetFinalized(blockID ids.ID, finality *QuantumFinality) {
q.mu.Lock()
defer q.mu.Unlock()
q.finalized[blockID] = finality
}
// GetFinalized retrieves a finality record (exported for testing)
func (q *Quasar) GetFinalized(blockID ids.ID) (*QuantumFinality, bool) {
q.mu.RLock()
defer q.mu.RUnlock()
f, ok := q.finalized[blockID]
return f, ok
}
// Helper: big-endian uint64
func putUint64BE(b []byte, v uint64) {
for i := 0; i < 8; i++ {
b[i] = byte(v >> (56 - i*8))
}
}
+61
View File
@@ -0,0 +1,61 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"sync"
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// CertStore resolves the QuasarCert that certifies a finalized block. In
// production it is filled by the cert gossip/ingest path (the producer
// follow-on, producer.go); the verify gate only READS from it. Keyed by the
// finalized position (chainID, height, blockID) so a cert can never be returned
// for the wrong block.
type CertStore interface {
Lookup(chainID uint32, height uint64, blockID [32]byte) (*qcert.ConsensusCert, bool)
}
type certKey struct {
chainID uint32
height uint64
blockID [32]byte
}
// MemCertStore is an in-memory CertStore keyed by (chainID, height, blockID). It
// is the ingest sink the cert-gossip handler writes into (Put) and the gate
// reads from (Lookup). Safe for concurrent use.
type MemCertStore struct {
mu sync.RWMutex
certs map[certKey]*qcert.ConsensusCert
}
// NewMemCertStore returns an empty in-memory cert store.
func NewMemCertStore() *MemCertStore {
return &MemCertStore{certs: make(map[certKey]*qcert.ConsensusCert)}
}
// Put indexes a cert by its own (ChainID, Height, BlockHash). The ingest path
// MUST verify a cert before Put (verify-before-store), exactly as the gossip
// layer verifies before re-gossip; the gate re-verifies at the checkpoint so a
// store poisoned by an unverified Put still cannot finalize an invalid cert.
func (m *MemCertStore) Put(cert *qcert.ConsensusCert) {
if cert == nil {
return
}
k := certKey{chainID: cert.ChainID, height: cert.Height, blockID: cert.BlockHash}
m.mu.Lock()
m.certs[k] = cert
m.mu.Unlock()
}
// Lookup returns the cert for the finalized position, or (nil, false).
func (m *MemCertStore) Lookup(chainID uint32, height uint64, blockID [32]byte) (*qcert.ConsensusCert, bool) {
k := certKey{chainID: chainID, height: height, blockID: blockID}
m.mu.RLock()
c, ok := m.certs[k]
m.mu.RUnlock()
return c, ok
}
-240
View File
@@ -1,240 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
"errors"
"github.com/luxfi/ids"
"github.com/luxfi/log"
)
// SignatureType identifies the signature algorithm used
type SignatureType uint8
const (
SignatureTypeBLS SignatureType = iota
SignatureTypeCorona
SignatureTypeQuasar // Hybrid BLS + Corona
SignatureTypeMLDSA
)
// Signature is the interface for all signature types
type Signature interface {
Bytes() []byte
Type() SignatureType
Signers() []ids.NodeID
}
// Signer is the interface for signing operations
type Signer interface {
Sign(msg []byte) (Signature, error)
PublicKey() []byte
}
// Verifier is the interface for signature verification
type Verifier interface {
Verify(msg []byte, sig Signature) bool
}
// ThresholdSigner extends Signer for threshold signature schemes
type ThresholdSigner interface {
Signer
Index() int
Threshold() int
}
// CoronaConfig holds configuration for Corona threshold signatures
type CoronaConfig struct {
NumParties int
Threshold int
PartyIndex int
}
// CoronaStats contains statistics about the Corona coordinator
type CoronaStats struct {
NumParties int
Threshold int
Initialized bool
}
// CoronaSignature represents a threshold Corona signature
type CoronaSignature struct {
sig []byte
signers []ids.NodeID
}
// NewCoronaSignature creates a new Corona signature
func NewCoronaSignature(sig []byte, signers []ids.NodeID) *CoronaSignature {
return &CoronaSignature{sig: sig, signers: signers}
}
func (s *CoronaSignature) Bytes() []byte { return s.sig }
func (s *CoronaSignature) Type() SignatureType { return SignatureTypeCorona }
func (s *CoronaSignature) Signers() []ids.NodeID { return s.signers }
// CoronaCoordinator manages the threshold signing protocol.
//
// Sign/Verify are fail-closed without initialized lattice keys.
// Operations return errors unless properly initialized with key
// material, or explicitly created via NewTestCoronaCoordinator
// for tests.
type CoronaCoordinator struct {
log log.Logger
config CoronaConfig
initialized bool
testing bool // only true via NewTestCoronaCoordinator
validators []ids.NodeID
}
// NewCoronaCoordinator creates a new Corona coordinator.
// Sign and Verify will fail until real lattice key material is loaded.
func NewCoronaCoordinator(log log.Logger, config CoronaConfig) (*CoronaCoordinator, error) {
return &CoronaCoordinator{
log: log,
config: config,
}, nil
}
// NewTestCoronaCoordinator creates a Corona coordinator for testing.
// The test coordinator uses deterministic stub signatures that are NOT
// cryptographically secure.
func NewTestCoronaCoordinator(log log.Logger, config CoronaConfig) (*CoronaCoordinator, error) {
return &CoronaCoordinator{
log: log,
config: config,
testing: true,
}, nil
}
func (rc *CoronaCoordinator) Initialize(validators []ids.NodeID) error {
rc.validators = validators
rc.initialized = true
return nil
}
func (rc *CoronaCoordinator) IsInitialized() bool {
return rc.initialized
}
func (rc *CoronaCoordinator) Sign(msg []byte) (Signature, error) {
if !rc.initialized {
return nil, errors.New("corona: threshold signing not initialized — requires real lattice key material")
}
if rc.testing {
// Test-only stub: deterministic RT-prefixed signature
sig := append([]byte("RT"), msg[:min(32, len(msg))]...)
return NewCoronaSignature(sig, rc.validators), nil
}
return nil, errors.New("corona: threshold signing not initialized — requires real lattice key material")
}
func (rc *CoronaCoordinator) Verify(msg []byte, sig Signature) bool {
if !rc.initialized {
return false
}
if rc.testing {
return sig != nil && len(sig.Bytes()) > 0
}
return false
}
func (rc *CoronaCoordinator) Stats() CoronaStats {
return CoronaStats{
NumParties: rc.config.NumParties,
Threshold: rc.config.Threshold,
Initialized: rc.initialized,
}
}
// Threshold returns the threshold required for signing
func (rc *CoronaCoordinator) Threshold() int {
return rc.config.Threshold
}
// NumParties returns the number of parties in the threshold scheme
func (rc *CoronaCoordinator) NumParties() int {
return rc.config.NumParties
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// BLSSignature represents an aggregated BLS signature (node-specific)
type BLSSignature struct {
sig []byte
signers []ids.NodeID
}
func NewBLSSignature(sig []byte, signers []ids.NodeID) *BLSSignature {
return &BLSSignature{sig: sig, signers: signers}
}
func (s *BLSSignature) Bytes() []byte { return s.sig }
func (s *BLSSignature) Type() SignatureType { return SignatureTypeBLS }
func (s *BLSSignature) Signers() []ids.NodeID { return s.signers }
// QuasarSignature combines BLS and Corona signatures for P/Q security
type QuasarSignature struct {
bls *BLSSignature
corona *CoronaSignature
}
func NewQuasarSignature(bls *BLSSignature, corona *CoronaSignature) *QuasarSignature {
return &QuasarSignature{bls: bls, corona: corona}
}
func (s *QuasarSignature) Bytes() []byte {
// Concatenate BLS + Corona bytes with length prefix
blsBytes := s.bls.Bytes()
rtBytes := s.corona.Bytes()
result := make([]byte, 4+len(blsBytes)+len(rtBytes))
// Length of BLS signature (big endian)
result[0] = byte(len(blsBytes) >> 24)
result[1] = byte(len(blsBytes) >> 16)
result[2] = byte(len(blsBytes) >> 8)
result[3] = byte(len(blsBytes))
copy(result[4:], blsBytes)
copy(result[4+len(blsBytes):], rtBytes)
return result
}
func (s *QuasarSignature) Type() SignatureType { return SignatureTypeQuasar }
func (s *QuasarSignature) Signers() []ids.NodeID {
// Return intersection of signers (both must sign)
return s.bls.Signers()
}
func (s *QuasarSignature) BLS() *BLSSignature { return s.bls }
func (s *QuasarSignature) Corona() *CoronaSignature { return s.corona }
// QuasarSigner combines classical and post-quantum signers
type QuasarSigner interface {
Signer
// SignQuasar signs with both BLS and Corona in parallel
SignQuasar(msg []byte) (*QuasarSignature, error)
// VerifyQuasar verifies both BLS and Corona signatures
VerifyQuasar(msg []byte, sig *QuasarSignature) bool
}
// FinalityProof represents proof of block finality
type FinalityProof struct {
BlockID ids.ID
Height uint64
Signature Signature
TotalWeight uint64
SignerWeight uint64
}
// ValidatorInfo contains validator information for consensus
type ValidatorInfo struct {
NodeID ids.NodeID
Weight uint64
Active bool
}
+94
View File
@@ -0,0 +1,94 @@
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package quasar
import (
qcert "github.com/luxfi/consensus/protocol/quasar"
)
// ValidatorSetProvider resolves the committed validator set the verifier pins a
// cert against, for a (chain, epoch). Post-activation the gate calls this once
// per verified checkpoint.
type ValidatorSetProvider interface {
ValidatorSet(chainID uint32, epoch uint64) (qcert.ConsensusValidatorSet, error)
}
// ValidatorSet is a concrete ConsensusValidatorSet for one epoch: the committed
// weighted-validator-set root plus the per-leg verification keys the cert legs
// verify against (the classical BLS aggregate key for the Beam leg and the
// Pulsar ML-DSA threshold group key for the Pulsar leg — the HYBRID_PQ pair).
//
// Production wiring (the activation seam): in production these fields are
// populated from the P-Chain-pinned validator set (Root, Epoch) and the active
// KeyEra group keys for the epoch. That population is era/rotation-coupled and
// lands with the producer + KeyEra-registry wiring (see producer.go). Corona
// (STRICT_DUAL_PQ) and Magnetar/P3Q (POLARIS / RECOVERY) group keys + the
// weighted-sig-set config are populated by that same follow-on; until then this
// set serves the HYBRID_PQ pair and reports "no key" for the other lanes.
type ValidatorSet struct {
root [48]byte
epoch uint64
blsAggKey []byte // classical BLS-12-381 aggregate pubkey (Beam leg)
pulsarGroup []byte // Pulsar ML-DSA threshold group pubkey (Pulsar leg)
}
var _ qcert.ConsensusValidatorSet = (*ValidatorSet)(nil)
// NewValidatorSet builds a committed validator set for one epoch from its root
// and the HYBRID_PQ verification keys.
func NewValidatorSet(root [48]byte, epoch uint64, blsAggKey, pulsarGroup []byte) *ValidatorSet {
return &ValidatorSet{root: root, epoch: epoch, blsAggKey: blsAggKey, pulsarGroup: pulsarGroup}
}
// Root returns the 48-byte weighted-validator-set commitment.
func (v *ValidatorSet) Root() [48]byte { return v.root }
// Epoch returns the epoch this set was committed under.
func (v *ValidatorSet) Epoch() uint64 { return v.epoch }
// WeightedConfig returns the QuorumVerifierConfig for the WeightedSigSet
// evidence mode. HYBRID_PQ does not use weighted-sig-set legs; the zero config
// is correct here and is populated by the POLARIS / RECOVERY follow-on.
func (v *ValidatorSet) WeightedConfig() qcert.QuorumVerifierConfig {
return qcert.QuorumVerifierConfig{}
}
// WeightedEnvelope returns the round-digest posture axes for the inner
// WeightedQuorumCert. Zero for HYBRID_PQ (no weighted-sig-set leg); populated by
// the POLARIS / RECOVERY follow-on.
func (v *ValidatorSet) WeightedEnvelope() qcert.QuorumMessageEnvelope {
return qcert.QuorumMessageEnvelope{}
}
// ThresholdGroupKey returns the threshold-signature group public key for a leg
// kind. Serves the Pulsar (ML-DSA) lane; reports (zero, false) for the others
// until their group keys are wired by the follow-on.
func (v *ValidatorSet) ThresholdGroupKey(kind qcert.LegKind) (qcert.ThresholdGroupKey, bool) {
if kind == qcert.LegPulsarMLDSA && len(v.pulsarGroup) > 0 {
return qcert.ThresholdGroupKey{Kind: qcert.LegPulsarMLDSA, PulsarGroupKey: v.pulsarGroup}, true
}
return qcert.ThresholdGroupKey{}, false
}
// ClassicalAggregateKey returns the classical aggregate verification key for a
// scheme. Serves the BLS-12-381 Beam leg.
func (v *ValidatorSet) ClassicalAggregateKey(scheme qcert.ClassicalScheme) ([]byte, bool) {
if scheme == qcert.ClassicalSchemeBLS12381 && len(v.blsAggKey) > 0 {
return v.blsAggKey, true
}
return nil, false
}
// StaticValidatorSetProvider returns the same committed set for every (chain,
// epoch). It is the single-era / test provider; the production provider resolves
// per-epoch sets from the P-Chain validator manager + KeyEra registry.
type StaticValidatorSetProvider struct{ Set qcert.ConsensusValidatorSet }
// ValidatorSet implements ValidatorSetProvider.
func (p StaticValidatorSetProvider) ValidatorSet(_ uint32, _ uint64) (qcert.ConsensusValidatorSet, error) {
if p.Set == nil {
return nil, ErrValidatorSetUnavailable
}
return p.Set, nil
}
-378
View File
@@ -1,378 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package zap provides ZAP (Zero-copy Agent Protocol) integration for Lux consensus.
//
// This package bridges ZAP's agentic consensus with Lux's Quasar threshold signatures,
// enabling W3C DID-based validator identity and post-quantum secure finality.
package zap
import (
"context"
"errors"
"sync"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/consensus/quasar"
)
var (
// ErrNotInitialized is returned when the bridge is used before initialization
ErrNotInitialized = errors.New("zap bridge not initialized")
// ErrValidatorNotFound is returned when a validator is not in the set
ErrValidatorNotFound = errors.New("validator not found")
// ErrQueryNotFound is returned when a query ID is not known
ErrQueryNotFound = errors.New("query not found")
// ErrAlreadyVoted is returned when a validator tries to vote twice
ErrAlreadyVoted = errors.New("already voted on this query")
// ErrInvalidDID is returned when a DID is malformed
ErrInvalidDID = errors.New("invalid DID format")
)
// BridgeConfig configures the ZAP-Lux consensus bridge
type BridgeConfig struct {
// ConsensusThreshold is the fraction of votes needed (0.5 = majority)
ConsensusThreshold float64
// MinResponses is the minimum responses before checking consensus
MinResponses int
// MinVotes is the minimum votes before checking consensus
MinVotes int
// EnablePQCrypto enables post-quantum signatures (ML-DSA-65)
EnablePQCrypto bool
}
// DefaultBridgeConfig returns sensible defaults for the bridge
func DefaultBridgeConfig() BridgeConfig {
return BridgeConfig{
ConsensusThreshold: 0.5,
MinResponses: 1,
MinVotes: 3,
EnablePQCrypto: true,
}
}
// Bridge connects ZAP agentic consensus to Lux's Quasar finality
type Bridge struct {
log log.Logger
config BridgeConfig
quasar *quasar.CoronaCoordinator
mu sync.RWMutex
queries map[string]*QueryState // QueryID -> QueryState
dids map[ids.NodeID]*DID // NodeID -> DID
}
// NewBridge creates a new ZAP-Lux consensus bridge
func NewBridge(log log.Logger, config BridgeConfig) *Bridge {
return &Bridge{
log: log,
config: config,
queries: make(map[string]*QueryState),
dids: make(map[ids.NodeID]*DID),
}
}
// Initialize sets up the bridge with a Quasar coordinator
func (b *Bridge) Initialize(coordinator *quasar.CoronaCoordinator) error {
b.mu.Lock()
defer b.mu.Unlock()
if coordinator == nil {
return ErrNotInitialized
}
b.quasar = coordinator
b.log.Info("ZAP bridge initialized",
log.Int("threshold", coordinator.Threshold()),
log.Int("parties", coordinator.NumParties()),
log.Bool("pqCrypto", b.config.EnablePQCrypto),
)
return nil
}
// RegisterValidator associates a DID with a Lux NodeID
func (b *Bridge) RegisterValidator(nodeID ids.NodeID, did *DID) error {
if did == nil || !did.Valid() {
return ErrInvalidDID
}
b.mu.Lock()
defer b.mu.Unlock()
b.dids[nodeID] = did
b.log.Debug("Registered validator DID",
log.Stringer("nodeID", nodeID),
log.String("did", did.String()),
)
return nil
}
// GetValidatorDID returns the DID for a NodeID
func (b *Bridge) GetValidatorDID(nodeID ids.NodeID) (*DID, error) {
b.mu.RLock()
defer b.mu.RUnlock()
did, ok := b.dids[nodeID]
if !ok {
return nil, ErrValidatorNotFound
}
return did, nil
}
// SubmitQuery creates a new agentic consensus query
func (b *Bridge) SubmitQuery(ctx context.Context, queryID string, content []byte, submitter ids.NodeID) error {
b.mu.Lock()
defer b.mu.Unlock()
if b.quasar == nil {
return ErrNotInitialized
}
submitterDID, ok := b.dids[submitter]
if !ok {
return ErrValidatorNotFound
}
b.queries[queryID] = &QueryState{
ID: queryID,
Content: content,
Submitter: submitterDID,
Responses: make(map[string]*Response),
Votes: make(map[string][]*DID),
}
b.log.Debug("Query submitted",
log.String("queryID", queryID),
log.String("submitter", submitterDID.String()),
)
return nil
}
// SubmitResponse adds a response to a query
func (b *Bridge) SubmitResponse(ctx context.Context, queryID, responseID string, content []byte, responder ids.NodeID) error {
b.mu.Lock()
defer b.mu.Unlock()
state, ok := b.queries[queryID]
if !ok {
return ErrQueryNotFound
}
responderDID, ok := b.dids[responder]
if !ok {
return ErrValidatorNotFound
}
if state.Finalized != "" {
return errors.New("query already finalized")
}
state.Responses[responseID] = &Response{
ID: responseID,
QueryID: queryID,
Content: content,
Responder: responderDID,
}
state.Votes[responseID] = []*DID{}
b.log.Debug("Response submitted",
log.String("queryID", queryID),
log.String("responseID", responseID),
log.String("responder", responderDID.String()),
)
return nil
}
// Vote casts a vote for a response
func (b *Bridge) Vote(ctx context.Context, queryID, responseID string, voter ids.NodeID) error {
b.mu.Lock()
defer b.mu.Unlock()
state, ok := b.queries[queryID]
if !ok {
return ErrQueryNotFound
}
if state.Finalized != "" {
return errors.New("query already finalized")
}
if _, ok := state.Responses[responseID]; !ok {
return errors.New("response not found")
}
voterDID, ok := b.dids[voter]
if !ok {
return ErrValidatorNotFound
}
// Check for double voting (by DID URI)
voterURI := voterDID.String()
for _, voters := range state.Votes {
for _, v := range voters {
if v.String() == voterURI {
return ErrAlreadyVoted
}
}
}
state.Votes[responseID] = append(state.Votes[responseID], voterDID)
// Check consensus
b.checkConsensus(state)
return nil
}
func (b *Bridge) checkConsensus(state *QueryState) {
if state.Finalized != "" {
return
}
if len(state.Responses) < b.config.MinResponses {
return
}
totalVotes := 0
for _, voters := range state.Votes {
totalVotes += len(voters)
}
if totalVotes < b.config.MinVotes {
return
}
// Find best response
var best struct {
id string
count int
}
for responseID, voters := range state.Votes {
count := len(voters)
confidence := float64(count) / float64(totalVotes)
if confidence >= b.config.ConsensusThreshold {
if best.id == "" || count > best.count {
best.id = responseID
best.count = count
}
}
}
if best.id != "" {
state.Finalized = best.id
b.log.Info("Query finalized",
log.String("queryID", state.ID),
log.String("responseID", best.id),
log.Int("votes", best.count),
log.Int("total", totalVotes),
)
}
}
// GetResult returns the consensus result for a query
func (b *Bridge) GetResult(queryID string) (*ConsensusResult, error) {
b.mu.RLock()
defer b.mu.RUnlock()
state, ok := b.queries[queryID]
if !ok {
return nil, ErrQueryNotFound
}
if state.Finalized == "" {
return nil, nil
}
response := state.Responses[state.Finalized]
votes := len(state.Votes[state.Finalized])
totalVoters := 0
for _, v := range state.Votes {
totalVoters += len(v)
}
confidence := 0.0
if totalVoters > 0 {
confidence = float64(votes) / float64(totalVoters)
}
return &ConsensusResult{
Response: response,
Votes: votes,
TotalVoters: totalVoters,
Confidence: confidence,
}, nil
}
// IsFinalized checks if a query has reached consensus
func (b *Bridge) IsFinalized(queryID string) bool {
b.mu.RLock()
defer b.mu.RUnlock()
state, ok := b.queries[queryID]
return ok && state.Finalized != ""
}
// SignWithQuasar signs a message using Quasar hybrid signatures
func (b *Bridge) SignWithQuasar(msg []byte) (quasar.Signature, error) {
b.mu.RLock()
defer b.mu.RUnlock()
if b.quasar == nil {
return nil, ErrNotInitialized
}
return b.quasar.Sign(msg)
}
// VerifyQuasar verifies a Quasar signature
func (b *Bridge) VerifyQuasar(msg []byte, sig quasar.Signature) bool {
b.mu.RLock()
defer b.mu.RUnlock()
if b.quasar == nil {
return false
}
return b.quasar.Verify(msg, sig)
}
// Stats returns bridge statistics
func (b *Bridge) Stats() BridgeStats {
b.mu.RLock()
defer b.mu.RUnlock()
active := 0
finalized := 0
for _, state := range b.queries {
if state.Finalized != "" {
finalized++
} else {
active++
}
}
var quasarStats quasar.CoronaStats
if b.quasar != nil {
quasarStats = b.quasar.Stats()
}
return BridgeStats{
RegisteredValidators: len(b.dids),
ActiveQueries: active,
FinalizedQueries: finalized,
QuasarInitialized: b.quasar != nil && b.quasar.IsInitialized(),
QuasarStats: quasarStats,
}
}
// BridgeStats contains statistics about the bridge
type BridgeStats struct {
RegisteredValidators int
ActiveQueries int
FinalizedQueries int
QuasarInitialized bool
QuasarStats quasar.CoronaStats
}
-459
View File
@@ -1,459 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zap
import (
"context"
"testing"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/consensus/quasar"
"github.com/stretchr/testify/require"
)
func TestParseDID(t *testing.T) {
tests := []struct {
name string
input string
want *DID
wantErr bool
}{
{
name: "valid did:lux",
input: "did:lux:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
want: &DID{
Method: DIDMethodLux,
ID: "z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
},
wantErr: false,
},
{
name: "valid did:key",
input: "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
want: &DID{
Method: DIDMethodKey,
ID: "z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
},
wantErr: false,
},
{
name: "valid did:web",
input: "did:web:example.com:users:alice",
want: &DID{
Method: DIDMethodWeb,
ID: "example.com:users:alice",
},
wantErr: false,
},
{
name: "invalid - no did prefix",
input: "lux:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
wantErr: true,
},
{
name: "invalid - unknown method",
input: "did:unknown:abc123",
wantErr: true,
},
{
name: "invalid - empty id",
input: "did:lux:",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseDID(tt.input)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tt.want.Method, got.Method)
require.Equal(t, tt.want.ID, got.ID)
})
}
}
func TestDIDString(t *testing.T) {
did := &DID{Method: DIDMethodLux, ID: "z6MkTest"}
require.Equal(t, "did:lux:z6MkTest", did.String())
}
func TestDIDValid(t *testing.T) {
tests := []struct {
name string
did *DID
valid bool
}{
{
name: "valid lux",
did: &DID{Method: DIDMethodLux, ID: "z6MkTest"},
valid: true,
},
{
name: "valid key",
did: &DID{Method: DIDMethodKey, ID: "z6MkTest"},
valid: true,
},
{
name: "valid web",
did: &DID{Method: DIDMethodWeb, ID: "example.com"},
valid: true,
},
{
name: "nil did",
did: nil,
valid: false,
},
{
name: "empty id",
did: &DID{Method: DIDMethodLux, ID: ""},
valid: false,
},
{
name: "unknown method",
did: &DID{Method: "unknown", ID: "test"},
valid: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.valid, tt.did.Valid())
})
}
}
func TestDIDFromNodeID(t *testing.T) {
nodeID := ids.GenerateTestNodeID()
did := DIDFromNodeID(nodeID)
require.NotNil(t, did)
require.Equal(t, DIDMethodLux, did.Method)
require.True(t, did.Valid())
require.Contains(t, did.String(), "did:lux:")
}
func TestDIDFromWeb(t *testing.T) {
tests := []struct {
name string
domain string
path string
wantID string
wantErr bool
}{
{
name: "domain only",
domain: "example.com",
path: "",
wantID: "example.com",
wantErr: false,
},
{
name: "domain with path",
domain: "example.com",
path: "users/alice",
wantID: "example.com:users:alice",
wantErr: false,
},
{
name: "empty domain",
domain: "",
path: "",
wantErr: true,
},
{
name: "domain with slash",
domain: "example/com",
path: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := DIDFromWeb(tt.domain, tt.path)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, DIDMethodWeb, got.Method)
require.Equal(t, tt.wantID, got.ID)
})
}
}
func TestGenerateDocument(t *testing.T) {
did := &DID{Method: DIDMethodLux, ID: "z6MkTest"}
doc, err := did.GenerateDocument()
require.NoError(t, err)
require.NotNil(t, doc)
require.Equal(t, "did:lux:z6MkTest", doc.ID)
require.Len(t, doc.Context, 2)
require.Len(t, doc.VerificationMethod, 1)
require.Len(t, doc.Authentication, 1)
require.Len(t, doc.Service, 1)
require.Equal(t, "ZapAgent", doc.Service[0].Type)
}
func TestBridgeNew(t *testing.T) {
logger := log.Noop()
config := DefaultBridgeConfig()
bridge := NewBridge(logger, config)
require.NotNil(t, bridge)
require.Equal(t, 0.5, bridge.config.ConsensusThreshold)
}
func TestBridgeInitialize(t *testing.T) {
logger := log.Noop()
bridge := NewBridge(logger, DefaultBridgeConfig())
// Test with nil coordinator
err := bridge.Initialize(nil)
require.ErrorIs(t, err, ErrNotInitialized)
// Test with valid coordinator
coordinator, err := quasar.NewTestCoronaCoordinator(logger, quasar.CoronaConfig{
NumParties: 4,
Threshold: 3,
PartyIndex: 0,
})
require.NoError(t, err)
err = bridge.Initialize(coordinator)
require.NoError(t, err)
}
func TestBridgeRegisterValidator(t *testing.T) {
logger := log.Noop()
bridge := NewBridge(logger, DefaultBridgeConfig())
nodeID := ids.GenerateTestNodeID()
did := DIDFromNodeID(nodeID)
// Register validator
err := bridge.RegisterValidator(nodeID, did)
require.NoError(t, err)
// Get validator DID
got, err := bridge.GetValidatorDID(nodeID)
require.NoError(t, err)
require.Equal(t, did.String(), got.String())
// Unknown validator
_, err = bridge.GetValidatorDID(ids.GenerateTestNodeID())
require.ErrorIs(t, err, ErrValidatorNotFound)
// Invalid DID
err = bridge.RegisterValidator(nodeID, nil)
require.ErrorIs(t, err, ErrInvalidDID)
}
func TestBridgeConsensusFlow(t *testing.T) {
logger := log.Noop()
bridge := NewBridge(logger, BridgeConfig{
ConsensusThreshold: 0.5,
MinResponses: 1,
MinVotes: 2,
EnablePQCrypto: true,
})
// Initialize with coordinator
coordinator, err := quasar.NewTestCoronaCoordinator(logger, quasar.CoronaConfig{
NumParties: 4,
Threshold: 3,
PartyIndex: 0,
})
require.NoError(t, err)
require.NoError(t, bridge.Initialize(coordinator))
// Register validators
submitter := ids.GenerateTestNodeID()
responder := ids.GenerateTestNodeID()
voter1 := ids.GenerateTestNodeID()
voter2 := ids.GenerateTestNodeID()
require.NoError(t, bridge.RegisterValidator(submitter, DIDFromNodeID(submitter)))
require.NoError(t, bridge.RegisterValidator(responder, DIDFromNodeID(responder)))
require.NoError(t, bridge.RegisterValidator(voter1, DIDFromNodeID(voter1)))
require.NoError(t, bridge.RegisterValidator(voter2, DIDFromNodeID(voter2)))
ctx := context.Background()
// Submit query
queryID := "query123"
err = bridge.SubmitQuery(ctx, queryID, []byte("What is 2+2?"), submitter)
require.NoError(t, err)
// Submit response
responseID := "response456"
err = bridge.SubmitResponse(ctx, queryID, responseID, []byte("4"), responder)
require.NoError(t, err)
// Vote
require.NoError(t, bridge.Vote(ctx, queryID, responseID, voter1))
require.False(t, bridge.IsFinalized(queryID)) // Not enough votes yet
require.NoError(t, bridge.Vote(ctx, queryID, responseID, voter2))
require.True(t, bridge.IsFinalized(queryID)) // Now finalized
// Get result
result, err := bridge.GetResult(queryID)
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, responseID, result.Response.ID)
require.Equal(t, 2, result.Votes)
require.Equal(t, 2, result.TotalVoters)
require.Equal(t, 1.0, result.Confidence)
}
func TestBridgeDoubleVote(t *testing.T) {
logger := log.Noop()
bridge := NewBridge(logger, DefaultBridgeConfig())
coordinator, _ := quasar.NewTestCoronaCoordinator(logger, quasar.CoronaConfig{
NumParties: 2,
Threshold: 1,
})
bridge.Initialize(coordinator)
submitter := ids.GenerateTestNodeID()
voter := ids.GenerateTestNodeID()
bridge.RegisterValidator(submitter, DIDFromNodeID(submitter))
bridge.RegisterValidator(voter, DIDFromNodeID(voter))
ctx := context.Background()
queryID := "q1"
responseID := "r1"
bridge.SubmitQuery(ctx, queryID, []byte("test"), submitter)
bridge.SubmitResponse(ctx, queryID, responseID, []byte("answer"), submitter)
// First vote succeeds
require.NoError(t, bridge.Vote(ctx, queryID, responseID, voter))
// Second vote fails
err := bridge.Vote(ctx, queryID, responseID, voter)
require.ErrorIs(t, err, ErrAlreadyVoted)
}
func TestBridgeStats(t *testing.T) {
logger := log.Noop()
bridge := NewBridge(logger, DefaultBridgeConfig())
coordinator, _ := quasar.NewTestCoronaCoordinator(logger, quasar.CoronaConfig{
NumParties: 4,
Threshold: 3,
})
bridge.Initialize(coordinator)
nodeID := ids.GenerateTestNodeID()
bridge.RegisterValidator(nodeID, DIDFromNodeID(nodeID))
stats := bridge.Stats()
require.Equal(t, 1, stats.RegisteredValidators)
require.Equal(t, 0, stats.ActiveQueries)
require.Equal(t, 0, stats.FinalizedQueries)
require.False(t, stats.QuasarInitialized) // Not initialized with validators
}
func TestNewQuery(t *testing.T) {
did := &DID{Method: DIDMethodLux, ID: "z6MkTest"}
query := NewQuery([]byte("What is 2+2?"), did)
require.NotEmpty(t, query.ID)
require.Equal(t, 64, len(query.ID)) // SHA-256 hex
require.Equal(t, []byte("What is 2+2?"), query.Content)
require.Equal(t, did, query.Submitter)
require.Greater(t, query.Timestamp, int64(0))
}
func TestNewResponse(t *testing.T) {
did := &DID{Method: DIDMethodLux, ID: "z6MkTest"}
queryID := "0000000000000000000000000000000000000000000000000000000000000000"
response := NewResponse(queryID, []byte("4"), did)
require.NotEmpty(t, response.ID)
require.Equal(t, 64, len(response.ID)) // SHA-256 hex
require.Equal(t, queryID, response.QueryID)
require.Equal(t, []byte("4"), response.Content)
require.Equal(t, did, response.Responder)
}
func TestInMemoryStakeRegistry(t *testing.T) {
registry := NewInMemoryStakeRegistry()
did := &DID{Method: DIDMethodLux, ID: "z6MkTest"}
// Initial stake is 0
stake, err := registry.GetStake(did)
require.NoError(t, err)
require.Equal(t, uint64(0), stake)
// Set stake
require.NoError(t, registry.SetStake(did, 1000))
// Get stake
stake, err = registry.GetStake(did)
require.NoError(t, err)
require.Equal(t, uint64(1000), stake)
// Total stake
require.Equal(t, uint64(1000), registry.TotalStake())
// Has sufficient stake
has, err := registry.HasSufficientStake(did, 500)
require.NoError(t, err)
require.True(t, has)
has, err = registry.HasSufficientStake(did, 2000)
require.NoError(t, err)
require.False(t, has)
// Stake weight
weight, err := registry.StakeWeight(did)
require.NoError(t, err)
require.Equal(t, 1.0, weight) // Only staker
}
func TestAgentMessageType(t *testing.T) {
require.Equal(t, "Query", AgentMessageTypeQuery.String())
require.Equal(t, "Response", AgentMessageTypeResponse.String())
require.Equal(t, "Vote", AgentMessageTypeVote.String())
require.Equal(t, "Finality", AgentMessageTypeFinality.String())
require.Equal(t, "Unknown", AgentMessageType(255).String())
}
func TestBase58EncodeDecode(t *testing.T) {
tests := []struct {
name string
data []byte
}{
{"empty", []byte{}},
{"single byte", []byte{0x01}},
{"multiple bytes", []byte{0x01, 0x02, 0x03, 0x04}},
{"leading zeros", []byte{0x00, 0x00, 0x01, 0x02}},
{"all zeros", []byte{0x00, 0x00, 0x00}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
encoded := base58Encode(tt.data)
decoded, err := base58Decode(encoded)
require.NoError(t, err)
require.Equal(t, tt.data, decoded)
})
}
}
func TestBase58DecodeInvalidChar(t *testing.T) {
_, err := base58Decode("0OIl") // Invalid chars
require.Error(t, err)
}
-355
View File
@@ -1,355 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zap
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"github.com/luxfi/ids"
)
const (
// MethodLux is the did:lux method for blockchain-anchored DIDs
MethodLux = "lux"
// MethodKey is the did:key method for self-certifying DIDs
MethodKey = "key"
// MethodWeb is the did:web method for DNS-based DIDs
MethodWeb = "web"
// MLDSAPublicKeySize is the expected size of ML-DSA-65 public keys
MLDSAPublicKeySize = 1952
// MultibaseBase58BTC is the multibase prefix for base58btc
MultibaseBase58BTC = 'z'
)
// MulticodecMLDSA65 is the provisional multicodec prefix for ML-DSA-65
var MulticodecMLDSA65 = []byte{0x13, 0x09}
// DIDMethod represents a DID method identifier
type DIDMethod string
const (
DIDMethodLux DIDMethod = MethodLux
DIDMethodKey DIDMethod = MethodKey
DIDMethodWeb DIDMethod = MethodWeb
)
// DID represents a W3C Decentralized Identifier
type DID struct {
Method DIDMethod
ID string
}
// NewDID creates a DID from method and identifier
func NewDID(method DIDMethod, id string) *DID {
return &DID{Method: method, ID: id}
}
// ParseDID parses a DID from a string in format "did:method:id"
func ParseDID(s string) (*DID, error) {
if !strings.HasPrefix(s, "did:") {
return nil, fmt.Errorf("%w: must start with 'did:'", ErrInvalidDID)
}
rest := s[4:] // Skip "did:"
colonIndex := strings.Index(rest, ":")
if colonIndex == -1 {
return nil, fmt.Errorf("%w: expected 'did:method:id'", ErrInvalidDID)
}
methodStr := rest[:colonIndex]
id := rest[colonIndex+1:]
if id == "" {
return nil, fmt.Errorf("%w: identifier cannot be empty", ErrInvalidDID)
}
var method DIDMethod
switch methodStr {
case MethodLux:
method = DIDMethodLux
case MethodKey:
method = DIDMethodKey
case MethodWeb:
method = DIDMethodWeb
default:
return nil, fmt.Errorf("%w: unknown method '%s'", ErrInvalidDID, methodStr)
}
return &DID{Method: method, ID: id}, nil
}
// String returns the full DID URI
func (d *DID) String() string {
if d == nil {
return ""
}
return fmt.Sprintf("did:%s:%s", d.Method, d.ID)
}
// Valid checks if the DID is well-formed
func (d *DID) Valid() bool {
if d == nil || d.ID == "" {
return false
}
switch d.Method {
case DIDMethodLux, DIDMethodKey, DIDMethodWeb:
return true
default:
return false
}
}
// DIDFromNodeID creates a did:lux from a Lux NodeID
func DIDFromNodeID(nodeID ids.NodeID) *DID {
// Use multibase-encoded NodeID bytes
encoded := base58Encode(nodeID[:])
return &DID{
Method: DIDMethodLux,
ID: string(MultibaseBase58BTC) + encoded,
}
}
// DIDFromPublicKey creates a did:key from an ML-DSA-65 public key
func DIDFromPublicKey(publicKey []byte) (*DID, error) {
if len(publicKey) != MLDSAPublicKeySize {
return nil, fmt.Errorf("invalid ML-DSA public key size: expected %d, got %d",
MLDSAPublicKeySize, len(publicKey))
}
// Prefix with multicodec for ML-DSA-65
prefixed := make([]byte, len(MulticodecMLDSA65)+len(publicKey))
copy(prefixed, MulticodecMLDSA65)
copy(prefixed[len(MulticodecMLDSA65):], publicKey)
// Encode with multibase (base58btc)
encoded := base58Encode(prefixed)
return &DID{
Method: DIDMethodKey,
ID: string(MultibaseBase58BTC) + encoded,
}, nil
}
// DIDFromWeb creates a did:web from a domain and optional path
func DIDFromWeb(domain string, path string) (*DID, error) {
if domain == "" {
return nil, fmt.Errorf("%w: domain cannot be empty", ErrInvalidDID)
}
if strings.ContainsAny(domain, "/:") {
return nil, fmt.Errorf("%w: domain cannot contain '/' or ':'", ErrInvalidDID)
}
var id string
if path != "" {
// Replace '/' with ':' per did:web spec
pathParts := strings.ReplaceAll(path, "/", ":")
id = domain + ":" + pathParts
} else {
id = domain
}
return &DID{Method: DIDMethodWeb, ID: id}, nil
}
// ExtractKeyMaterial extracts raw key bytes from did:key or did:lux
func (d *DID) ExtractKeyMaterial() ([]byte, error) {
if d == nil || d.ID == "" {
return nil, fmt.Errorf("%w: empty identifier", ErrInvalidDID)
}
if d.ID[0] != MultibaseBase58BTC {
return nil, fmt.Errorf("%w: unsupported multibase encoding", ErrInvalidDID)
}
// Decode base58btc (skip multibase prefix)
decoded, err := base58Decode(d.ID[1:])
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrInvalidDID, err)
}
if len(decoded) < 2 {
return nil, fmt.Errorf("%w: identifier too short", ErrInvalidDID)
}
// Skip multicodec prefix if it matches ML-DSA-65
if len(decoded) >= 2 && decoded[0] == MulticodecMLDSA65[0] && decoded[1] == MulticodecMLDSA65[1] {
return decoded[2:], nil
}
return decoded, nil
}
// Hash returns a 32-byte hash of the DID for indexing
func (d *DID) Hash() ids.ID {
h := sha256.Sum256([]byte(d.String()))
var id ids.ID
copy(id[:], h[:])
return id
}
// ToHex returns the DID hash as a hex string
func (d *DID) ToHex() string {
id := d.Hash()
return hex.EncodeToString(id[:])
}
// VerificationMethod represents a verification method in a DID Document
type VerificationMethod struct {
ID string
Type string
Controller string
PublicKeyMultibase string
BlockchainAccountID string
}
// Service represents a service endpoint in a DID Document
type Service struct {
ID string
Type string
ServiceEndpoint string
}
// DIDDocument represents a W3C DID Document
type DIDDocument struct {
Context []string
ID string
Controller string
VerificationMethod []VerificationMethod
Authentication []string
AssertionMethod []string
KeyAgreement []string
CapabilityInvocation []string
CapabilityDelegation []string
Service []Service
}
// GenerateDocument creates a DID Document for a DID
func (d *DID) GenerateDocument() (*DIDDocument, error) {
if !d.Valid() {
return nil, fmt.Errorf("%w: invalid DID", ErrInvalidDID)
}
uri := d.String()
keyID := uri + "#keys-1"
var vm VerificationMethod
switch d.Method {
case DIDMethodLux, DIDMethodKey:
vm = VerificationMethod{
ID: keyID,
Type: "JsonWebKey2020",
Controller: uri,
PublicKeyMultibase: d.ID,
}
if d.Method == DIDMethodLux {
// Add blockchain account ID
keyMaterial, err := d.ExtractKeyMaterial()
if err == nil && len(keyMaterial) >= 20 {
vm.BlockchainAccountID = "lux:" + hex.EncodeToString(keyMaterial[:20])
}
}
case DIDMethodWeb:
vm = VerificationMethod{
ID: keyID,
Type: "JsonWebKey2020",
Controller: uri,
}
}
return &DIDDocument{
Context: []string{
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/jws-2020/v1",
},
ID: uri,
VerificationMethod: []VerificationMethod{vm},
Authentication: []string{keyID},
AssertionMethod: []string{keyID},
CapabilityInvocation: []string{keyID},
Service: []Service{
{
ID: uri + "#zap-agent",
Type: "ZapAgent",
ServiceEndpoint: "zap://" + d.ID,
},
},
}, nil
}
// Base58 encoding/decoding (Bitcoin alphabet)
const base58Alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
func base58Encode(data []byte) string {
// Convert to big integer
result := make([]byte, 0, len(data)*2)
for _, b := range data {
carry := int(b)
for i := 0; i < len(result); i++ {
carry += int(result[i]) << 8
result[i] = byte(carry % 58)
carry /= 58
}
for carry > 0 {
result = append(result, byte(carry%58))
carry /= 58
}
}
// Handle leading zeros
for _, b := range data {
if b != 0 {
break
}
result = append(result, 0)
}
// Reverse and convert to alphabet
output := make([]byte, len(result))
for i := range result {
output[len(result)-1-i] = base58Alphabet[result[i]]
}
return string(output)
}
func base58Decode(s string) ([]byte, error) {
result := make([]byte, 0, len(s))
for _, c := range s {
index := strings.IndexRune(base58Alphabet, c)
if index == -1 {
return nil, fmt.Errorf("invalid base58 character: %c", c)
}
carry := index
for i := 0; i < len(result); i++ {
carry += int(result[i]) * 58
result[i] = byte(carry)
carry >>= 8
}
for carry > 0 {
result = append(result, byte(carry))
carry >>= 8
}
}
// Handle leading ones
for _, c := range s {
if c != rune(base58Alphabet[0]) {
break
}
result = append(result, 0)
}
// Reverse
for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
result[i], result[j] = result[j], result[i]
}
return result, nil
}
-260
View File
@@ -1,260 +0,0 @@
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zap
import (
"crypto/sha256"
"encoding/hex"
"time"
)
// QueryState represents the state of a consensus query
type QueryState struct {
ID string
Content []byte
Submitter *DID
Timestamp time.Time
Responses map[string]*Response
Votes map[string][]*DID // ResponseID -> list of voter DIDs
Finalized string // ResponseID if finalized
}
// Response represents a response to a query
type Response struct {
ID string
QueryID string
Content []byte
Responder *DID
Timestamp time.Time
}
// ConsensusResult represents the outcome of consensus voting
type ConsensusResult struct {
Response *Response
Votes int
TotalVoters int
Confidence float64
}
// Query represents an agentic consensus query
type Query struct {
ID string
Content []byte
Submitter *DID
Timestamp int64
}
// NewQuery creates a query with auto-generated ID
func NewQuery(content []byte, submitter *DID) *Query {
timestamp := time.Now().Unix()
data := append(content, []byte(submitter.String())...)
data = append(data, int64ToBytes(timestamp)...)
hash := sha256.Sum256(data)
return &Query{
ID: hex.EncodeToString(hash[:]),
Content: content,
Submitter: submitter,
Timestamp: timestamp,
}
}
// NewResponse creates a response with auto-generated ID
func NewResponse(queryID string, content []byte, responder *DID) *Response {
timestamp := time.Now()
queryIDBytes, _ := hex.DecodeString(queryID)
data := append(queryIDBytes, content...)
data = append(data, []byte(responder.String())...)
data = append(data, int64ToBytes(timestamp.Unix())...)
hash := sha256.Sum256(data)
return &Response{
ID: hex.EncodeToString(hash[:]),
QueryID: queryID,
Content: content,
Responder: responder,
Timestamp: timestamp,
}
}
// Vote represents a vote cast by a validator
type Vote struct {
QueryID string
ResponseID string
Voter *DID
Timestamp int64
Signature []byte // Optional post-quantum signature
}
// NewVote creates a new vote
func NewVote(queryID, responseID string, voter *DID) *Vote {
return &Vote{
QueryID: queryID,
ResponseID: responseID,
Voter: voter,
Timestamp: time.Now().Unix(),
}
}
// FinalityProof represents proof of agentic consensus finality
type FinalityProof struct {
QueryID string
ResponseID string
Votes []Vote
TotalVoters int
Confidence float64
Timestamp int64
Signature []byte // Quasar hybrid signature
}
// ValidatorWeight represents a validator's weight in consensus
type ValidatorWeight struct {
DID *DID
Weight uint64
Stake uint64
Active bool
}
// AgentMessage represents a ZAP protocol message for agentic consensus
type AgentMessage struct {
Type AgentMessageType
Query *Query
Response *Response
Vote *Vote
Signature []byte
}
// AgentMessageType identifies the type of agent message
type AgentMessageType uint8
const (
AgentMessageTypeQuery AgentMessageType = iota
AgentMessageTypeResponse
AgentMessageTypeVote
AgentMessageTypeFinality
)
// String returns the message type name
func (t AgentMessageType) String() string {
switch t {
case AgentMessageTypeQuery:
return "Query"
case AgentMessageTypeResponse:
return "Response"
case AgentMessageTypeVote:
return "Vote"
case AgentMessageTypeFinality:
return "Finality"
default:
return "Unknown"
}
}
func int64ToBytes(n int64) []byte {
b := make([]byte, 8)
for i := 0; i < 8; i++ {
b[i] = byte(n >> (i * 8))
}
return b
}
// PQSignatureType identifies the post-quantum signature algorithm
type PQSignatureType uint8
const (
// PQSignatureTypeMLDSA65 is NIST FIPS 204 ML-DSA-65
PQSignatureTypeMLDSA65 PQSignatureType = iota
// PQSignatureTypeCorona is Ring-LWE based threshold signatures
PQSignatureTypeCorona
// PQSignatureTypeHybrid combines classical and post-quantum
PQSignatureTypeHybrid
)
// PQSignature wraps a post-quantum signature
type PQSignature struct {
Type PQSignatureType
Signature []byte
PublicKey []byte
}
// PQKeypair represents a post-quantum keypair
type PQKeypair struct {
Type PQSignatureType
PublicKey []byte
PrivateKey []byte
}
// Sign signs a message using the keypair (stub - real impl in pqcrypto)
func (k *PQKeypair) Sign(message []byte) (*PQSignature, error) {
// Stub: returns SHA-256 hash as fixed-size signature for testing
hash := sha256.Sum256(append(message, k.PrivateKey...))
return &PQSignature{
Type: k.Type,
Signature: hash[:],
PublicKey: k.PublicKey,
}, nil
}
// Verify verifies a signature (stub - real impl in pqcrypto)
func (k *PQKeypair) Verify(message []byte, sig *PQSignature) bool {
// Stub: accepts any non-empty signature
return sig != nil && len(sig.Signature) > 0
}
// StakeRegistry interface for validator stake tracking
type StakeRegistry interface {
GetStake(did *DID) (uint64, error)
SetStake(did *DID, amount uint64) error
TotalStake() uint64
HasSufficientStake(did *DID, minimum uint64) (bool, error)
StakeWeight(did *DID) (float64, error)
}
// InMemoryStakeRegistry is a simple in-memory stake registry for testing
type InMemoryStakeRegistry struct {
stakes map[string]uint64
}
// NewInMemoryStakeRegistry creates a new in-memory stake registry
func NewInMemoryStakeRegistry() *InMemoryStakeRegistry {
return &InMemoryStakeRegistry{
stakes: make(map[string]uint64),
}
}
// GetStake returns the stake for a DID
func (r *InMemoryStakeRegistry) GetStake(did *DID) (uint64, error) {
return r.stakes[did.String()], nil
}
// SetStake sets the stake for a DID
func (r *InMemoryStakeRegistry) SetStake(did *DID, amount uint64) error {
r.stakes[did.String()] = amount
return nil
}
// TotalStake returns the total stake across all validators
func (r *InMemoryStakeRegistry) TotalStake() uint64 {
var total uint64
for _, stake := range r.stakes {
total += stake
}
return total
}
// HasSufficientStake checks if a DID has at least the minimum stake
func (r *InMemoryStakeRegistry) HasSufficientStake(did *DID, minimum uint64) (bool, error) {
stake, _ := r.GetStake(did)
return stake >= minimum, nil
}
// StakeWeight returns the stake weight as a fraction of total stake
func (r *InMemoryStakeRegistry) StakeWeight(did *DID) (float64, error) {
stake, _ := r.GetStake(did)
total := r.TotalStake()
if total == 0 {
return 0.0, nil
}
return float64(stake) / float64(total), nil
}
+5 -5
View File
@@ -133,12 +133,12 @@ deploy:
### Prometheus Metrics
The node exposes metrics at `http://localhost:9630/ext/metrics`
The node exposes metrics at `http://localhost:9630/v1/metrics`
### Health Checks
- Liveness: `http://localhost:9630/ext/health`
- Readiness: `http://localhost:9630/ext/info`
- Liveness: `http://localhost:9630/v1/health`
- Readiness: `http://localhost:9630/v1/info`
### Grafana Dashboard
@@ -178,12 +178,12 @@ docker exec -it luxd /bin/bash
# Check if bootstrapped
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"info.isBootstrapped","params":{"chain":"C"}}' \
http://localhost:9630/ext/info
http://localhost:9630/v1/info
# Get block number
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}' \
http://localhost:9630/ext/bc/C/rpc
http://localhost:9630/v1/bc/C/rpc
```
## CI/CD
+4 -4
View File
@@ -287,10 +287,10 @@ echo "📝 Starting with command:"
echo " $CMD"
echo ""
echo "📡 API Endpoints:"
echo " - JSON-RPC: http://$HTTP_HOST:$HTTP_PORT/ext/bc/C/rpc"
echo " - WebSocket: ws://$HTTP_HOST:$HTTP_PORT/ext/bc/C/ws"
echo " - Health: http://$HTTP_HOST:$HTTP_PORT/ext/health"
echo " - Info: http://$HTTP_HOST:$HTTP_PORT/ext/info"
echo " - JSON-RPC: http://$HTTP_HOST:$HTTP_PORT/v1/bc/C/rpc"
echo " - WebSocket: ws://$HTTP_HOST:$HTTP_PORT/v1/bc/C/ws"
echo " - Health: http://$HTTP_HOST:$HTTP_PORT/v1/health"
echo " - Info: http://$HTTP_HOST:$HTTP_PORT/v1/info"
echo ""
# Execute
+1 -1
View File
@@ -346,7 +346,7 @@ export default function HomePage() {
</p>
<pre className="mt-4 overflow-x-auto rounded-lg bg-black/50 p-4">
<code className="text-sm text-green-400">
curl -X POST --data &#39;&#123;&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;health.health&quot;,&quot;id&quot;:1&#125;&#39; \{"\n"} -H &#39;content-type:application/json&#39; \{"\n"} 127.0.0.1:9650/ext/health
curl -X POST --data &#39;&#123;&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;health.health&quot;,&quot;id&quot;:1&#125;&#39; \{"\n"} -H &#39;content-type:application/json&#39; \{"\n"} 127.0.0.1:9650/v1/health
</code>
</pre>
</div>
+20 -20
View File
@@ -31,7 +31,7 @@ Or in configuration:
## Endpoint
```
http://localhost:9630/ext/admin
http://localhost:9630/v1/admin
```
## Methods
@@ -54,7 +54,7 @@ curl -X POST --data '{
"chain":"2S53R2ub94CV5vmSRAjqPYmRxvuiFunCb1gN2CAw3DQBfPWghX"
},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -85,7 +85,7 @@ curl -X POST --data '{
"chain":"2S53R2ub94CV5vmSRAjqPYmRxvuiFunCb1gN2CAw3DQBfPWghX"
},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
**Response:**
@@ -114,7 +114,7 @@ curl -X POST --data '{
"method":"admin.getLogLevel",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
**Response:**
@@ -146,7 +146,7 @@ curl -X POST --data '{
"logLevel":"debug"
},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -181,7 +181,7 @@ curl -X POST --data '{
"method":"admin.loadVMs",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
**Response:**
@@ -214,7 +214,7 @@ curl -X POST --data '{
"method":"admin.startCPUProfiler",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -232,7 +232,7 @@ curl -X POST --data '{
"method":"admin.stopCPUProfiler",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -250,7 +250,7 @@ curl -X POST --data '{
"method":"admin.memoryProfile",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -276,7 +276,7 @@ curl -X POST --data '{
"method":"admin.getConfig",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
**Response:**
@@ -311,7 +311,7 @@ curl -X POST --data '{
"method":"admin.shutdown",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
---
@@ -330,7 +330,7 @@ curl -X POST --data '{
"method":"admin.db.commit",
"params":{},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/admin
}' -H 'content-type:application/json;' http://localhost:9630/v1/admin
```
## Profiling and Debugging
@@ -344,7 +344,7 @@ curl -X POST --data '{
"method":"admin.startCPUProfiler",
"params":{},
"id":1
}' http://localhost:9630/ext/admin
}' http://localhost:9630/v1/admin
# Let it run for 30 seconds
sleep 30
@@ -355,7 +355,7 @@ curl -X POST --data '{
"method":"admin.stopCPUProfiler",
"params":{},
"id":2
}' http://localhost:9630/ext/admin
}' http://localhost:9630/v1/admin
# Analyze profile
go tool pprof cpu.prof
@@ -370,7 +370,7 @@ curl -X POST --data '{
"method":"admin.memoryProfile",
"params":{},
"id":1
}' http://localhost:9630/ext/admin
}' http://localhost:9630/v1/admin
# Analyze
go tool pprof mem.prof
@@ -401,7 +401,7 @@ set_log_level() {
\"method\":\"admin.setLogLevel\",
\"params\":{\"logLevel\":\"$LEVEL\"},
\"id\":1
}" http://localhost:9630/ext/admin
}" http://localhost:9630/v1/admin
}
# Increase verbosity for debugging
@@ -476,7 +476,7 @@ Enable audit logging for admin operations:
# auto_restart.sh
check_health() {
curl -s http://localhost:9630/ext/health | jq -r '.healthy'
curl -s http://localhost:9630/v1/health | jq -r '.healthy'
}
restart_node() {
@@ -488,7 +488,7 @@ restart_node() {
"method":"admin.shutdown",
"params":{},
"id":1
}' http://localhost:9630/ext/admin
}' http://localhost:9630/v1/admin
sleep 10
@@ -514,7 +514,7 @@ CURRENT=$(curl -s -X POST --data '{
"method":"admin.getConfig",
"params":{},
"id":1
}' http://localhost:9630/ext/admin)
}' http://localhost:9630/v1/admin)
echo "Current configuration:"
echo $CURRENT | jq .
@@ -525,7 +525,7 @@ curl -X POST --data '{
"method":"admin.setLogLevel",
"params":{"logLevel":"debug"},
"id":2
}' http://localhost:9630/ext/admin
}' http://localhost:9630/v1/admin
```
## Troubleshooting
+12 -12
View File
@@ -10,7 +10,7 @@ The Health API provides endpoints to monitor the health and readiness of your Lu
## Endpoint
```
http://localhost:9630/ext/health
http://localhost:9630/v1/health
```
## Health Check Types
@@ -20,7 +20,7 @@ http://localhost:9630/ext/health
Get the overall health status of the node:
```bash
curl http://localhost:9630/ext/health
curl http://localhost:9630/v1/health
```
**Response:**
@@ -61,7 +61,7 @@ curl http://localhost:9630/ext/health
Check if the node is ready to serve requests:
```bash
curl http://localhost:9630/ext/health/readiness
curl http://localhost:9630/v1/health/readiness
```
Returns:
@@ -73,7 +73,7 @@ Returns:
Check if the node is alive and running:
```bash
curl http://localhost:9630/ext/health/liveness
curl http://localhost:9630/v1/health/liveness
```
Returns:
@@ -92,7 +92,7 @@ curl -X POST --data '{
"id": 1,
"method": "health.health",
"params": {}
}' -H 'content-type:application/json;' http://localhost:9630/ext/health
}' -H 'content-type:application/json;' http://localhost:9630/v1/health
```
**Response:**
@@ -175,7 +175,7 @@ Configure per-chain health parameters:
Export health metrics in Prometheus format:
```bash
curl http://localhost:9630/ext/metrics | grep health
curl http://localhost:9630/v1/metrics | grep health
```
Metrics:
@@ -208,13 +208,13 @@ spec:
image: luxfi/node:latest
livenessProbe:
httpGet:
path: /ext/health/liveness
path: /v1/health/liveness
port: 9630
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ext/health/readiness
path: /v1/health/readiness
port: 9630
initialDelaySeconds: 60
periodSeconds: 5
@@ -229,7 +229,7 @@ spec:
# health_monitor.sh
while true; do
HEALTH=$(curl -s http://localhost:9630/ext/health | jq -r '.healthy')
HEALTH=$(curl -s http://localhost:9630/v1/health | jq -r '.healthy')
if [ "$HEALTH" != "true" ]; then
echo "ALERT: Node unhealthy at $(date)"
@@ -248,7 +248,7 @@ done
# health_analysis.sh
# Get detailed health
RESPONSE=$(curl -s http://localhost:9630/ext/health)
RESPONSE=$(curl -s http://localhost:9630/v1/health)
# Parse each chain
for CHAIN in P X C Q; do
@@ -271,7 +271,7 @@ done
```
backend lux_nodes
option httpchk GET /ext/health
option httpchk GET /v1/health
http-check expect status 200
server node1 192.168.1.10:9630 check
@@ -289,7 +289,7 @@ upstream lux_nodes {
}
location /health_check {
proxy_pass http://lux_nodes/ext/health;
proxy_pass http://lux_nodes/v1/health;
proxy_connect_timeout 1s;
proxy_read_timeout 1s;
}
+23 -23
View File
@@ -10,7 +10,7 @@ The Info API provides general information about the node and network status. Thi
## Endpoint
```
http://localhost:9630/ext/info
http://localhost:9630/v1/info
```
## Format
@@ -23,7 +23,7 @@ curl -X POST --data '{
"method": "info.<method>",
"params": {...},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
## Methods
@@ -41,7 +41,7 @@ curl -X POST --data '{
"method": "info.getNodeVersion",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -78,7 +78,7 @@ curl -X POST --data '{
"method": "info.getNodeID",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -111,7 +111,7 @@ curl -X POST --data '{
"method": "info.getNodeIP",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -140,7 +140,7 @@ curl -X POST --data '{
"method": "info.getNetworkID",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -175,7 +175,7 @@ curl -X POST --data '{
"method": "info.getNetworkName",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -207,7 +207,7 @@ curl -X POST --data '{
"alias": "P"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -239,7 +239,7 @@ curl -X POST --data '{
"chain": "P"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -269,7 +269,7 @@ curl -X POST --data '{
"method": "info.peers",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -313,7 +313,7 @@ curl -X POST --data '{
"method": "info.getTxFee",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -348,7 +348,7 @@ curl -X POST --data '{
"method": "info.uptime",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response (Validator):**
@@ -390,7 +390,7 @@ curl -X POST --data '{
"method": "info.getVMs",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -424,7 +424,7 @@ curl -X POST --data '{
"method": "info.getUpgrades",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
**Example Response:**
@@ -468,7 +468,7 @@ VERSION=$(curl -s -X POST --data '{
"method": "info.getNodeVersion",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.version')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.version')
echo "Version: $VERSION"
@@ -478,7 +478,7 @@ NODE_ID=$(curl -s -X POST --data '{
"method": "info.getNodeID",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.nodeID')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.nodeID')
echo "Node ID: $NODE_ID"
@@ -488,7 +488,7 @@ PEERS=$(curl -s -X POST --data '{
"method": "info.peers",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.numPeers')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.numPeers')
echo "Connected Peers: $PEERS"
@@ -499,7 +499,7 @@ for CHAIN in P X C Q; do
\"method\": \"info.isBootstrapped\",
\"params\": {\"chain\": \"$CHAIN\"},
\"id\": 1
}" -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.isBootstrapped')
}" -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.isBootstrapped')
echo "$CHAIN-Chain Bootstrapped: $STATUS"
done
@@ -510,7 +510,7 @@ UPTIME=$(curl -s -X POST --data '{
"method": "info.uptime",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info 2>/dev/null | jq -r '.result.rewardingStakePercentage' 2>/dev/null)
}' -H 'content-type:application/json;' $NODE_URL/v1/info 2>/dev/null | jq -r '.result.rewardingStakePercentage' 2>/dev/null)
if [ "$UPTIME" != "null" ] && [ -n "$UPTIME" ]; then
echo "Validator Uptime: $UPTIME%"
@@ -531,7 +531,7 @@ PEERS=$(curl -s -X POST --data '{
"method": "info.peers",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.peers[]')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.peers[]')
echo "=== Peer Connection Quality ==="
echo "Node ID | Latency (ms) | Uptime % | Version"
@@ -560,7 +560,7 @@ while true; do
\"method\": \"info.isBootstrapped\",
\"params\": {\"chain\": \"$CHAIN\"},
\"id\": 1
}" -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.isBootstrapped')
}" -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.isBootstrapped')
if [ "$STATUS" == "true" ]; then
echo "✅ $CHAIN-Chain: Bootstrapped"
@@ -575,7 +575,7 @@ while true; do
"method": "info.peers",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.numPeers')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.numPeers')
echo ""
echo "Connected Peers: $PEERS"
@@ -588,7 +588,7 @@ while true; do
\"method\": \"info.isBootstrapped\",
\"params\": {\"chain\": \"$CHAIN\"},
\"id\": 1
}" -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.isBootstrapped')
}" -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.isBootstrapped')
if [ "$STATUS" != "true" ]; then
ALL_BOOTSTRAPPED=false
+23 -23
View File
@@ -10,7 +10,7 @@ The Platform Chain (P-Chain) is responsible for staking, validators, and chain m
## Endpoint
```
http://localhost:9630/ext/bc/P
http://localhost:9630/v1/bc/P
```
## Format
@@ -23,7 +23,7 @@ curl -X POST --data '{
"method": "platform.<method>",
"params": {...},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
## Methods
@@ -41,7 +41,7 @@ curl -X POST --data '{
"method": "platform.getHeight",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -73,7 +73,7 @@ curl -X POST --data '{
"addresses": ["P-lux1q8tgunsf7sxpl2qp9fz0xjs36kstm7vdjvpzcc"]
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -114,7 +114,7 @@ curl -X POST --data '{
"limit": 100
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -134,7 +134,7 @@ curl -X POST --data '{
"method": "platform.getCurrentValidators",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -190,7 +190,7 @@ curl -X POST --data '{
"method": "platform.getPendingValidators",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -212,7 +212,7 @@ curl -X POST --data '{
"height": 365000
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -233,7 +233,7 @@ curl -X POST --data '{
"height": 365000
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -255,7 +255,7 @@ curl -X POST --data '{
"addresses": ["P-lux1q8tgunsf7sxpl2qp9fz0xjs36kstm7vdjvpzcc"]
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -274,7 +274,7 @@ curl -X POST --data '{
"method": "platform.getMinStake",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -305,7 +305,7 @@ curl -X POST --data '{
"method": "platform.getTotalStake",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -327,7 +327,7 @@ curl -X POST --data '{
"txID": "2nmH8LithVbdjaXsxVQCQfXtzN9hBbmebrsaEYnLM9T32Uy3Y5"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -345,7 +345,7 @@ curl -X POST --data '{
"method": "platform.getTimestamp",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -363,7 +363,7 @@ curl -X POST --data '{
"method": "platform.getBlockchains",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -409,7 +409,7 @@ curl -X POST --data '{
"blockID": "vXSY7FK7NR65Y8BrJDKQH4a6vBdJuqAMvVzWj3Zxcap5J4ZE3"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -431,7 +431,7 @@ curl -X POST --data '{
"txID": "2nmH8LithVbdjaXsxVQCQfXtzN9hBbmebrsaEYnLM9T32Uy3Y5"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -452,7 +452,7 @@ curl -X POST --data '{
"txID": "2nmH8LithVbdjaXsxVQCQfXtzN9hBbmebrsaEYnLM9T32Uy3Y5"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
**Example Response:**
@@ -488,7 +488,7 @@ curl -X POST --data '{
"method": "platform.getCurrentSupply",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -507,7 +507,7 @@ curl -X POST --data '{
"method": "platform.getChains",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -544,7 +544,7 @@ curl -X POST --data '{
"password": "mypassword"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
---
@@ -694,7 +694,7 @@ curl -s -X POST --data "{
\"nodeIDs\": [\"$NODE_ID\"]
},
\"id\": 1
}" -H 'content-type:application/json;' http://localhost:9630/ext/bc/P | jq '.result.validators[0]'
}" -H 'content-type:application/json;' http://localhost:9630/v1/bc/P | jq '.result.validators[0]'
```
### Monitor Staking Rewards
@@ -711,7 +711,7 @@ STAKE=$(curl -s -X POST --data "{
\"addresses\": [\"$ADDRESS\"]
},
\"id\": 1
}" -H 'content-type:application/json;' http://localhost:9630/ext/bc/P)
}" -H 'content-type:application/json;' http://localhost:9630/v1/bc/P)
echo "Current stake: $(echo $STAKE | jq -r '.result.staked')"
echo "Stakeable: $(echo $STAKE | jq -r '.result.stakeable')"
@@ -210,14 +210,14 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "health.health"
}' -H 'content-type:application/json;' http://localhost:9630/ext/health
}' -H 'content-type:application/json;' http://localhost:9630/v1/health
# Get node info
curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "info.getNodeVersion"
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
# Check bootstrap status
curl -X POST --data '{
@@ -227,7 +227,7 @@ curl -X POST --data '{
"params": {
"chain": "P"
}
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
## Troubleshooting
@@ -308,7 +308,7 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "health.health"
}' -H 'content-type:application/json;' http://localhost:9630/ext/health
}' -H 'content-type:application/json;' http://localhost:9630/v1/health
```
### Bootstrap Status
@@ -320,7 +320,7 @@ curl -X POST --data '{
"id": 1,
"method": "info.isBootstrapped",
"params": {"chain": "P"}
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
### Metrics
@@ -328,7 +328,7 @@ curl -X POST --data '{
Access Prometheus metrics:
```bash
curl http://localhost:9630/ext/metrics
curl http://localhost:9630/v1/metrics
```
Key metrics to monitor:
+17 -17
View File
@@ -58,7 +58,7 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "platform.getHeight"
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
# Check bootstrap status for all chains
curl -X POST --data '{
@@ -66,7 +66,7 @@ curl -X POST --data '{
"id": 1,
"method": "info.isBootstrapped",
"params": {"chain": "P"}
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
### Configure Public IP
@@ -90,7 +90,7 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "info.getNodeID"
}' -H 'content-type:application/json;' http://localhost:9630/ext/info
}' -H 'content-type:application/json;' http://localhost:9630/v1/info
```
Response:
@@ -155,7 +155,7 @@ curl -X POST --data '{
"password": "mypassword"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/keystore
}' -H 'content-type:application/json;' http://localhost:9630/v1/keystore
# Create P-Chain address
curl -X POST --data '{
@@ -166,7 +166,7 @@ curl -X POST --data '{
"password": "mypassword"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
### Transfer LUX to P-Chain
@@ -185,7 +185,7 @@ curl -X POST --data '{
"amount": 2000000000000
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/X
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/X
# Import to P-Chain
curl -X POST --data '{
@@ -197,7 +197,7 @@ curl -X POST --data '{
"sourceChain": "X"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
## Step 4: Add as Validator
@@ -221,7 +221,7 @@ curl -X POST --data '{
"delegationFeeRate": 10
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
Parameters:
@@ -243,7 +243,7 @@ curl -X POST --data '{
"method": "platform.getPendingValidators",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
# Get current validators
curl -X POST --data '{
@@ -251,7 +251,7 @@ curl -X POST --data '{
"method": "platform.getCurrentValidators",
"params": {},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
## Step 5: Monitor Your Validator
@@ -268,7 +268,7 @@ curl -X POST --data '{
"nodeID": "NodeID-5KqnQfaFQxY9rsFBAa68377qWSherYLQ7"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
### Monitor Performance Metrics
@@ -277,10 +277,10 @@ Key metrics to track:
```bash
# Node health
curl http://localhost:9630/ext/health
curl http://localhost:9630/v1/health
# Prometheus metrics
curl http://localhost:9630/ext/metrics | grep -E "uptime|stake|validator"
curl http://localhost:9630/v1/metrics | grep -E "uptime|stake|validator"
```
Important metrics:
@@ -308,7 +308,7 @@ NODE_URL="http://localhost:9630"
WEBHOOK_URL="your-webhook-url"
# Check if node is responsive
if ! curl -s "$NODE_URL/ext/health" > /dev/null; then
if ! curl -s "$NODE_URL/v1/health" > /dev/null; then
curl -X POST "$WEBHOOK_URL" -d '{"text":"ALERT: Node is not responding!"}'
fi
@@ -318,7 +318,7 @@ UPTIME=$(curl -s -X POST --data '{
"method":"platform.getValidator",
"params":{"nodeID":"NodeID-xxx"},
"id":1
}' "$NODE_URL/ext/bc/P" | jq -r '.result.uptime')
}' "$NODE_URL/v1/bc/P" | jq -r '.result.uptime')
if [ "$UPTIME" -lt "80" ]; then
curl -X POST "$WEBHOOK_URL" -d "{\"text\":\"WARNING: Uptime is $UPTIME%\"}"
@@ -349,7 +349,7 @@ curl -X POST --data '{
"nodeID": "NodeID-5KqnQfaFQxY9rsFBAa68377qWSherYLQ7"
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
## Chain Validation
@@ -373,7 +373,7 @@ curl -X POST --data '{
"weight": 1000
},
"id": 1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
### Chain Requirements
+7 -7
View File
@@ -104,14 +104,14 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "info.getNetworkInfo"
}' -H 'content-type:application/json;' http://localhost:9650/ext/info
}' -H 'content-type:application/json;' http://localhost:9650/v1/info
# Get node ID
curl -X POST --data '{
"jsonrpc":"2.0",
"id": 1,
"method": "info.getNodeID"
}' -H 'content-type:application/json;' http://localhost:9650/ext/info
}' -H 'content-type:application/json;' http://localhost:9650/v1/info
```
## Chain Management
@@ -130,7 +130,7 @@ curl -X POST --data '{
"genesisData": "...",
"netID": "network-id"
}
}' -H 'content-type:application/json;' http://localhost:9650/ext/P
}' -H 'content-type:application/json;' http://localhost:9650/v1/P
```
### Validator Management
@@ -147,7 +147,7 @@ curl -X POST --data '{
"endTime": ...,
"stakeAmount": ...
}
}' -H 'content-type:application/json;' http://localhost:9650/ext/P
}' -H 'content-type:application/json;' http://localhost:9650/v1/P
```
## Configuration Reference
@@ -175,10 +175,10 @@ curl -X POST --data '{
```bash
# Prometheus metrics endpoint
curl http://localhost:9650/ext/metrics
curl http://localhost:9650/v1/metrics
# Health check
curl http://localhost:9650/ext/health
curl http://localhost:9650/v1/health
```
### Logs
@@ -193,7 +193,7 @@ curl -X POST --data '{
"id": 1,
"method": "admin.setLogLevel",
"params": {"logLevel": "debug"}
}' http://localhost:9650/ext/admin
}' http://localhost:9650/v1/admin
```
## Testing
@@ -595,10 +595,10 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"method":"info.peers",
"id":1
}' http://localhost:9630/ext/info
}' http://localhost:9630/v1/info
# Check network metrics
curl http://localhost:9630/ext/metrics | grep network
curl http://localhost:9630/v1/metrics | grep network
# Monitor connections
netstat -an | grep 9631
+9 -9
View File
@@ -39,7 +39,7 @@ scrape_configs:
- job_name: 'lux-node'
static_configs:
- targets: ['localhost:9630']
metrics_path: '/ext/metrics'
metrics_path: '/v1/metrics'
- job_name: 'node-exporter'
static_configs:
@@ -56,7 +56,7 @@ alerting:
### Available Metrics
The Lux node exposes 400+ Prometheus metrics at `http://localhost:9630/ext/metrics`.
The Lux node exposes 400+ Prometheus metrics at `http://localhost:9630/v1/metrics`.
#### Key Metric Categories
@@ -419,11 +419,11 @@ groups:
```bash
# Basic health check
curl http://localhost:9630/ext/health
curl http://localhost:9630/v1/health
# Detailed health with readiness/liveness
curl http://localhost:9630/ext/health/readiness
curl http://localhost:9630/ext/health/liveness
curl http://localhost:9630/v1/health/readiness
curl http://localhost:9630/v1/health/liveness
```
### Custom Health Script
@@ -443,7 +443,7 @@ send_alert() {
}
# Check if node is responsive
if ! curl -s "$NODE_URL/ext/health" > /dev/null; then
if ! curl -s "$NODE_URL/v1/health" > /dev/null; then
send_alert "Node is not responding!"
exit 1
fi
@@ -455,7 +455,7 @@ for CHAIN in P X C Q; do
\"method\": \"info.isBootstrapped\",
\"params\": {\"chain\": \"$CHAIN\"},
\"id\": 1
}" -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.isBootstrapped')
}" -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.isBootstrapped')
if [ "$STATUS" != "true" ]; then
send_alert "$CHAIN-Chain is not bootstrapped!"
@@ -468,7 +468,7 @@ PEERS=$(curl -s -X POST --data '{
"method": "info.peers",
"params": {},
"id": 1
}' -H 'content-type:application/json;' $NODE_URL/ext/info | jq -r '.result.numPeers')
}' -H 'content-type:application/json;' $NODE_URL/v1/info | jq -r '.result.numPeers')
if [ "$PEERS" -lt 4 ]; then
send_alert "Low peer count: $PEERS"
@@ -619,7 +619,7 @@ Create runbooks for common issues:
```bash
# Real-time metrics
watch -n 1 'curl -s http://localhost:9630/ext/metrics | grep -E "chain_height|network_peers"'
watch -n 1 'curl -s http://localhost:9630/v1/metrics | grep -E "chain_height|network_peers"'
# Log streaming
tail -f ~/.luxd/logs/*.log | grep --line-buffered ERROR
@@ -26,7 +26,7 @@ else
fi
# Check API responsiveness
if curl -s http://localhost:9630/ext/health > /dev/null 2>&1; then
if curl -s http://localhost:9630/v1/health > /dev/null 2>&1; then
echo "✅ API is responsive"
else
echo "❌ API is NOT responsive"
@@ -53,7 +53,7 @@ PEERS=$(curl -s -X POST --data '{
"jsonrpc":"2.0",
"method":"info.peers",
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/info 2>/dev/null | jq -r '.result.numPeers')
}' -H 'content-type:application/json;' http://localhost:9630/v1/info 2>/dev/null | jq -r '.result.numPeers')
if [ -n "$PEERS" ] && [ "$PEERS" -gt 0 ]; then
echo "✅ Connected peers: $PEERS"
@@ -225,7 +225,7 @@ curl -X POST --data '{
"method":"platform.getCurrentValidators",
"params":{"nodeIDs":["<your-node-id>"]},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
# Verify staking transaction
curl -X POST --data '{
@@ -233,7 +233,7 @@ curl -X POST --data '{
"method":"platform.getTx",
"params":{"txID":"<staking-tx-id>"},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
#### Issue: Low uptime percentage
@@ -275,7 +275,7 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"method":"platform.getHeight",
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
# Reduce consensus participation
./build/node --consensus-gossip-concurrent=2
@@ -334,7 +334,7 @@ grep "api" ~/.luxd/configs/node-config.json
./build/node --http-host=0.0.0.0
# Check for rate limiting
curl -I http://localhost:9630/ext/info
curl -I http://localhost:9630/v1/info
```
### Staking Issues
@@ -369,7 +369,7 @@ curl -X POST --data '{
"method":"platform.getBalance",
"params":{"addresses":["P-lux1..."]},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
# Import funds from X-Chain
curl -X POST --data '{
@@ -381,7 +381,7 @@ curl -X POST --data '{
"sourceChain":"X"
},
"id":1
}' -H 'content-type:application/json;' http://localhost:9630/ext/bc/P
}' -H 'content-type:application/json;' http://localhost:9630/v1/bc/P
```
## Log Analysis
@@ -518,7 +518,7 @@ curl -X POST --data '{
"jsonrpc":"2.0",
"method":"info.getNodeID",
"id":1
}' http://localhost:9630/ext/info
}' http://localhost:9630/v1/info
```
### Support Channels
@@ -0,0 +1,163 @@
# Postmortem: C-Chain accepted-head state GC eviction (mainnet freeze)
**Status:** Resolved. Mainnet recovered and accepted at 5/5 validators, C-Chain
height 1085412, hash `0xd957eae6cb0bbef37174…`, all validators in agreement,
explorer at tip, treasury and Genesis NFT state verified.
**Severity:** Critical (mainnet C-Chain unable to build blocks; no state loss).
## Accepted permanent invariant
> The accepted C-Chain head's state root must never be GC/pruning eligible —
> across idle windows, duplicate empty-block state roots, cold snapshot/cache
> layers, small state history, and restarts.
>
> accepted head ⇒ accepted head state root is pinned ⇒ GC/pruning cannot evict
> the execution base for H+1.
The specific accepted-head GC eviction failure is **structurally prevented** by
the head-state pin, and production evidence confirms the fleet no longer
exhibits the prior failure signature. (A formal long-idle ritual was not
completed to termination during the incident window; the sign-off rests on the
structural invariant plus production evidence: a head idle for 3h04m was built
on cleanly, multiple 515 minute zero-traffic windows passed with tip state
readable, and zero eviction/materialize canaries appeared fleet-wide after the
fix.)
## Failure mode (exact)
The C-Chain EVM (coreth-lineage, `luxfi/evm`) in pruning mode manages trie
memory with `cappedMemoryTrieWriter` (`core/state_manager.go`):
- Accepted state roots are held in a `tipBuffer` (`BoundedBuffer`) of depth
`state-history` (default **32**); as roots age out of the buffer they are
`Dereference`d.
- Dirty trie nodes are only committed to disk at `commit-interval` boundaries
(default **4096** blocks), with optimistic `Cap` flushes near the boundary.
- The insert-time `triedb.Reference(root, {})` in `writeBlockAndSetHead` is
**refcount-balanced**: it is consumed as the block ages through the
tipBuffer (or via `RejectTrie`). It therefore does not protect an idle head.
On an idle chain, consecutive empty blocks share identical state roots. The
tipBuffer's aging `Dereference` for an old entry then lands on the *live head
root* (duplicate key), dropping its reference count to zero. At any height that
is not a commit boundary the head root has never been persisted, so the next
`Cap`/flush evicts it from the dirty cache. The subsequent `BuildBlock` cannot
open the parent (head) state:
```
failed to materialize parent state for build: … StateAt: missing trie node
<head state root> … is not available, not found
```
and the chain wedges. RPC reads at `latest` fail with the same error (any
`StateAt(root)` caller). Consensus is unaffected — all validators agree on the
head *block*; only the local execution base for H+1 is gone. State is always
deterministically re-derivable from durable blocks, so a restart re-executes
and recovers — **restart is recovery evidence, not a fix**: the head could
still be evicted again in the next idle window.
### Preconditions (all defaults on affected mainnet validators)
- `pruning-enabled: true`
- `state-history: 32`
- `commit-interval: 4096`
- idle or bursty-then-idle traffic (heartbeat pause, low organic flow)
- duplicate empty-block state roots at the tip
- current height not at a commit boundary
Any C-Chain deployment matching these preconditions is exposed on affected
versions — this bug class will recur wherever the EVM runs with pruning, small
state history, long commit intervals, and idle traffic.
### Observed occurrences
1. Mainnet froze at height 1085200 after a ~10 minute heartbeat pause
(2026-07-07). All five validators had the block, none could serve or build
on its state.
2. An earlier fleet-wide variant contributed to the 1082879→1085012 incident
window (mixed with a separate proposervm/consensus issue documented in the
consensus fault-recovery audit).
## Affected / fixed versions
| Component | Affected | Fixed |
|---|---|---|
| `luxfi/evm` (C-Chain plugin) | ≤ v1.104.6 (all pruning-mode deployments; the balanced insert-time Reference in v1.104.3-hotfix was insufficient) | **v1.104.7** |
| `luxfi/node` image | v1.34.14 v1.34.23 (carry affected EVM plugins) | **v1.34.24** (interim), **v1.34.25** (canonical: identical fix, proper semver, clean go.mod) |
Fix commits (`luxfi/evm`, branch `evm-main-bugb`): `9bab20f7a` (pin),
`58b90490c` (non-fatal degradation), `e3781c35c` (vm v1.2.6 parity).
## The fix (structural)
`core/blockchain.go`: a dedicated **unbalanced** GC reference held on the
accepted head's state root — `headStatePinRoot` + `pinAcceptedHead(root)`:
- Transferred head-to-head: `Reference` the new head root first, then
`Dereference` the previous pinned root; exactly one live head pin exists at
all times, on `lastAccepted.Root()`.
- Established in `Accept`, in `SetLastAcceptedBlockDirect`, and on the loaded
head at startup (`loadLastState`), so the invariant holds across restarts
and the restart-then-idle path.
- Skips when the root is unchanged (duplicate empty-block roots keep exactly
one reference) and when state is not yet materialized (bootstrapping /
state-sync; the first `Accept` then establishes it).
- Deliberately **not** balanced against `InsertTrie`/`AcceptTrie`/`RejectTrie`
— its lifetime is "is the accepted head", nothing else.
- Non-fatal on backend error (pathdb `Reference`/`Dereference` are no-ops /
"not supported"): a failed pin degrades to pre-fix behavior with a WARN
rather than wedging Accept or startup.
No archive-mode workaround and no state-sync hack. Disk growth is unchanged
(one extra referenced root).
## Recovery recipe (what actually worked)
1. **Wedged-at-tip (state evicted, DB otherwise consistent):** restart the
node. Boot re-executes from the last committed root and re-materializes the
head state deterministically. Valid as *recovery*; deploy the fixed version
so it cannot recur.
2. **proposervm/EVM height split** (`proposervm finality index … is BEHIND the
inner VM tip`; produced here by crash-churn on affected versions — the
fail-closed guard then correctly refuses to mount): restarts cannot heal a
split. Restore the node's PVC from a `VolumeSnapshot` of a currently
healthy peer. Per-ordinal staking keys are installed by `startup.sh` from
the `luxd-staking` secret, so cross-node volume clones are safe (distinct
NodeIDs).
3. **PVC swaps must happen at StatefulSet `replicas=0`.** A live single-pod
PVC delete/recreate always loses the race to the StatefulSet controller,
which recreates a blank PVC first.
4. If a fleet-consistent EVM rewind is needed instead (no healthy peer):
`evm/cmd/repair-cchain` rewinds the standalone EVM `lastAccepted` to the
proposervm floor; on boot the heightAhead branch self-heals (used in the
1084996 recovery). Zero re-execution; never a re-genesis.
5. Retain evidence snapshots before every destructive step.
## Residual follow-ups (non-blocking; restart/churn liveness, not consensus or state-loss)
1. **Proposer-preference restart loop:** after heavy sibling churn, a node's
proposervm preference can reference a never-persisted outer block; every
`BuildBlock` then fails `not found` in a tight loop and the node's voter
goes mute (observed ~170 err/s). Restart clears it. Fix: fall back to
last-accepted when the preferred parent is not fetchable.
**FIXED (commit `8001bc5179`, branch `ship/node-v1.34.24`, ships in
v1.34.26):** `vms/proposervm/vm.go` `BuildBlock` now builds the child on
last-accepted (always held — committed state) when `vm.preferred` is
unfetchable, instead of hard-erroring; it surfaces the original error only
when last-accepted is itself the unfetchable id. Build-side companion to the
already-shipped defect #1 `SetPreference` validate-before-assign hardening.
Tests: `vms/proposervm/vm_buildblock_fallback_test.go`.
2. **Ancestor-fetch liveness:** the finality guard refuses certs with
"ancestor … is not tracked (behind; fetch and retry)" but the fetch never
fires, so the node loops instead of catching up. Restart clears it. Fix:
actually schedule the ancestor fetch on this path.
## Monitoring (keep active)
- Eviction/materialize canaries: `STATE-MATERIALIZE`, `missing trie node`,
`ACCEPT-BACKSTOP` log lines — expect zero.
- Accepted height/hash equality across all validators.
- Explorer tip parity with chain head.
- `is BEHIND the inner` (heightBehind) occurrences — expect zero.
- Do not treat the heartbeat as a safety mechanism; it is a liveness nicety.
+7 -7
View File
@@ -75,9 +75,9 @@ func NewMultiNetworkNode() *MultiNetworkNode {
// StartRPCServer starts the unified RPC server
func (n *MultiNetworkNode) StartRPCServer(port int) {
http.HandleFunc("/ext/crossnet/status", n.handleCrossNetStatus)
http.HandleFunc("/ext/crossnet/validators", n.handleCrossNetValidators)
http.HandleFunc("/ext/network/", n.handleNetworkSpecific)
http.HandleFunc("/v1/crossnet/status", n.handleCrossNetStatus)
http.HandleFunc("/v1/crossnet/validators", n.handleCrossNetValidators)
http.HandleFunc("/v1/network/", n.handleNetworkSpecific)
fmt.Printf("🌐 Multi-Network RPC Server starting on port %d\n", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
@@ -172,7 +172,7 @@ func (n *MultiNetworkNode) handleCrossNetValidators(w http.ResponseWriter, r *ht
// handleNetworkSpecific routes to network-specific handlers
func (n *MultiNetworkNode) handleNetworkSpecific(w http.ResponseWriter, r *http.Request) {
// Parse network ID from path: /ext/network/{networkID}/...
// Parse network ID from path: /v1/network/{networkID}/...
// This would route to the appropriate network's chain manager
response := fmt.Sprintf(`{
@@ -251,9 +251,9 @@ func main() {
}
fmt.Println("\n🌐 Starting Multi-Network RPC Server...")
fmt.Println(" • Cross-network status: http://localhost:9650/ext/crossnet/status")
fmt.Println(" • Cross-network validators: http://localhost:9650/ext/crossnet/validators")
fmt.Println(" • Network-specific: http://localhost:9650/ext/network/{networkID}/...")
fmt.Println(" • Cross-network status: http://localhost:9650/v1/crossnet/status")
fmt.Println(" • Cross-network validators: http://localhost:9650/v1/crossnet/validators")
fmt.Println(" • Network-specific: http://localhost:9650/v1/network/{networkID}/...")
// This would be replaced with actual RPC server
node.StartRPCServer(9650)
BIN
View File
Binary file not shown.
+23 -13
View File
@@ -54,7 +54,8 @@ var (
QChainAliases = AliasesFor("Q")
AChainAliases = AliasesFor("A")
BChainAliases = AliasesFor("B")
TChainAliases = AliasesFor("T")
MChainAliases = AliasesFor("M")
FChainAliases = AliasesFor("F")
ZChainAliases = AliasesFor("Z")
GChainAliases = AliasesFor("G")
KChainAliases = AliasesFor("K")
@@ -604,7 +605,8 @@ func FromConfig(config *genesiscfg.Config) ([]byte, ids.ID, error) {
{[]byte(config.CChainGenesis), constants.EVMID, "C-Chain", nil},
{[]byte(config.DChainGenesis), constants.DexVMID, "D-Chain", nil},
{[]byte(config.BChainGenesis), constants.BridgeVMID, "B-Chain", nil},
{[]byte(config.TChainGenesis), constants.ThresholdVMID, "T-Chain", nil},
{[]byte(config.MChainGenesis), constants.MPCVMID, "M-Chain", nil},
{[]byte(config.FChainGenesis), constants.FHEVMID, "F-Chain", nil},
{[]byte(config.QChainGenesis), constants.QuantumVMID, "Q-Chain", nil},
{[]byte(config.ZChainGenesis), constants.ZKVMID, "Z-Chain", nil},
// A/G/K carry genesis blobs and are deterministic genesis chains
@@ -726,10 +728,10 @@ func UTXOAssetIDFromGenesisBytes(genesisBytes []byte) (ids.ID, bool, error) {
if !ok {
continue
}
if uChain.VMID != constants.XVMID {
if uChain.VMID() != constants.XVMID {
continue
}
id, err := xvmgenesis.AssetIDFromBytes(uChain.GenesisData)
id, err := xvmgenesis.AssetIDFromBytes(uChain.GenesisData())
if err != nil {
return ids.Empty, false, fmt.Errorf("derive X-Chain asset ID from genesis data: %w", err)
}
@@ -747,7 +749,7 @@ func VMGenesis(genesisBytes []byte, vmID ids.ID) (*pchaintxs.Tx, error) {
}
for _, chain := range gen.Chains {
uChain := chain.Unsigned.(*pchaintxs.CreateChainTx)
if uChain.VMID == vmID {
if uChain.VMID() == vmID {
return chain, nil
}
}
@@ -776,7 +778,7 @@ func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, err
uChain := chain.Unsigned.(*pchaintxs.CreateChainTx)
chainID := chain.ID()
endpoint := path.Join(constants.ChainAliasPrefix, chainID.String())
switch uChain.VMID {
switch uChain.VMID() {
case constants.XVMID:
apiAliases[endpoint] = []string{
"X",
@@ -832,16 +834,24 @@ func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, err
path.Join(constants.ChainAliasPrefix, "bridge"),
}
chainAliases[chainID] = BChainAliases
case constants.ThresholdVMID:
case constants.MPCVMID:
apiAliases[endpoint] = []string{
"T",
"threshold",
"thresholdvm",
"M",
"mpc",
path.Join(constants.ChainAliasPrefix, "T"),
path.Join(constants.ChainAliasPrefix, "threshold"),
"mpcvm",
path.Join(constants.ChainAliasPrefix, "M"),
path.Join(constants.ChainAliasPrefix, "mpc"),
}
chainAliases[chainID] = TChainAliases
chainAliases[chainID] = MChainAliases
case constants.FHEVMID:
apiAliases[endpoint] = []string{
"F",
"fhe",
"fhevm",
path.Join(constants.ChainAliasPrefix, "F"),
path.Join(constants.ChainAliasPrefix, "fhe"),
}
chainAliases[chainID] = FChainAliases
case constants.ZKVMID:
apiAliases[endpoint] = []string{
"Z",
+2 -3
View File
@@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/luxfi/node/vms/platformvm/genesis"
pchaintxs "github.com/luxfi/node/vms/platformvm/txs"
)
// TestUTXOAssetIDFromGenesisBytes_Sovereign asserts the canonical
@@ -63,7 +62,7 @@ func TestUTXOAssetIDFromGenesisBytes_POnly(t *testing.T) {
require := require.New(t)
pOnly := &genesis.Genesis{Chains: nil}
pOnlyBytes, err := genesis.Codec.Marshal(pchaintxs.CodecVersion, pOnly)
pOnlyBytes, err := pOnly.Bytes()
require.NoError(err)
id, ok, err := UTXOAssetIDFromGenesisBytes(pOnlyBytes)
@@ -93,7 +92,7 @@ func TestVMGenesisOptInChains(t *testing.T) {
pOnly := &genesis.Genesis{
Chains: nil,
}
pOnlyBytes, err := genesis.Codec.Marshal(pchaintxs.CodecVersion, pOnly)
pOnlyBytes, err := pOnly.Bytes()
require.NoError(err)
for name, vmID := range map[string]ids.ID{
+10 -10
View File
@@ -314,15 +314,15 @@ func TestFromConfigExplicitStakers(t *testing.T) {
for i, vdrTx := range parsed.Validators {
switch ut := vdrTx.Unsigned.(type) {
case *txs.AddValidatorTx:
require.Equal(stakers[i].Weight, ut.Wght,
require.Equal(stakers[i].Weight, ut.Weight(),
"validator %d weight mismatch", i)
t.Logf("Validator %d: NodeID=%s Weight=%d StakeOuts=%d",
i, ut.Validator.NodeID, ut.Wght, len(ut.StakeOuts))
i, ut.Validator().NodeID, ut.Weight(), len(ut.StakeOuts()))
case *txs.AddPermissionlessValidatorTx:
require.Equal(stakers[i].Weight, ut.Wght,
require.Equal(stakers[i].Weight, ut.Weight(),
"validator %d weight mismatch", i)
t.Logf("Validator %d: NodeID=%s Weight=%d StakeOuts=%d",
i, ut.Validator.NodeID, ut.Wght, len(ut.StakeOuts))
i, ut.Validator().NodeID, ut.Weight(), len(ut.StakeOuts()))
default:
t.Fatalf("unexpected validator tx type: %T", ut)
}
@@ -396,15 +396,15 @@ func TestFromConfigExplicitStakersNoStakedFunds(t *testing.T) {
for i, vdrTx := range parsed.Validators {
switch ut := vdrTx.Unsigned.(type) {
case *txs.AddValidatorTx:
require.Greater(ut.Wght, uint64(0), "validator %d weight must be non-zero", i)
require.Greater(len(ut.StakeOuts), 0, "validator %d must have stake outputs", i)
require.Greater(ut.Weight(), uint64(0), "validator %d weight must be non-zero", i)
require.Greater(len(ut.StakeOuts()), 0, "validator %d must have stake outputs", i)
t.Logf("Validator %d: NodeID=%s Weight=%d StakeOuts=%d",
i, ut.Validator.NodeID, ut.Wght, len(ut.StakeOuts))
i, ut.Validator().NodeID, ut.Weight(), len(ut.StakeOuts()))
case *txs.AddPermissionlessValidatorTx:
require.Greater(ut.Wght, uint64(0), "validator %d weight must be non-zero", i)
require.Greater(len(ut.StakeOuts), 0, "validator %d must have stake outputs", i)
require.Greater(ut.Weight(), uint64(0), "validator %d weight must be non-zero", i)
require.Greater(len(ut.StakeOuts()), 0, "validator %d must have stake outputs", i)
t.Logf("Validator %d: NodeID=%s Weight=%d StakeOuts=%d",
i, ut.Validator.NodeID, ut.Wght, len(ut.StakeOuts))
i, ut.Validator().NodeID, ut.Weight(), len(ut.StakeOuts()))
default:
t.Fatalf("unexpected validator tx type: %T", ut)
}

Some files were not shown because too many files have changed in this diff Show More