mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
The matching engine (pkg/lx, 45.5K LOC incl. tests) and the deterministic core layered on it (pkg/dex) are one matcher spread across two packages (dex imported lx in 12 files; lx imported neither). Fold lx into dex and drop the "lx" name entirely — pkg/dex is now the single matcher package. Pure rename/fold, ZERO logic change. Behavior proven identical: the merged pkg/dex runs 457 top-level tests (431 former-lx + 26 former-dex) and 489 test funcs (468 + 21), all green — matching, batch (BatchMatchEqualsSequential, run-to-run determinism, tile boundary), GPU/CPU parity, truncation, and CL swap math all pass unchanged. What moved: - git mv all 101 pkg/lx/*.go + 1 .c into pkg/dex/ (package lx -> package dex). - lx's swap_test.go -> swap_math_test.go (only filename collision with dex's existing swap_test.go). - Rewrote imports repo-wide: 54 pkg/lx import lines removed; 42 external importers (api, client, consensus, dchain, dpdk, lxgpu, marketdata, test/, tests/) repointed to pkg/dex with lx.X -> dex.X; the 12 in-package dex files had lx.X -> bare X. 717 selector lines rewritten. Stale pkg/lx comment refs updated (pkg/lxgpu left intact). Collisions resolved (2, both package-level vars): - ErrNoLiquidity: lx's pool-level error (dexError, used only in swap.go, never referenced via qualifier) renamed ErrPoolNoLiquidity to match the existing ErrPool* convention; dex's router-level ErrNoLiquidity (public, has errors.Is tests) kept. - priceMultiplierBig: identical after fold (both big.NewInt(PriceMultiplier)); deduped by deleting dex's copy. Not folded — pkg/orderbook: it is NOT the GPU seam (that is orderbook_gpu.go, which lives in the engine and folded in here). pkg/orderbook is a zero-importer, placeholder-cgo island whose 13 core domain identifiers (Order, OrderBook, Trade, OrderType, OrderStatus, PriceLevel, Buy, Sell, Market, Limit, Filled, PartiallyFilled, NewOrderBook) collide incompatibly with the engine's. Folding it verbatim breaks the build; folding via rename reintroduces the exact parallel duplication this fold removes. Left for owner decision (recommend deletion as dead code) — see refactor notes. Follow-on (separate repos, not touched): 19 files under luxfi/dex import pkg/lx externally — lux/precompile/dex, lux/precompile-dex/dex, lux/consensus/examples/01-simple-bridge, lux/_consensus-v12537/examples, lux/cex/pkg/engine — repoint to pkg/dex after this lands. Verified: CGO_ENABLED=0 GOWORK=off go build ./... clean; go vet ./... clean; go test ./... -count=1 all green (22 ok / 0 fail). Co-authored-by: Hanzo Dev <[email protected]>
50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Command dexd is the ONE D-Chain DEX binary. It runs the DEX two ways:
|
|
//
|
|
// dexd run as a luxd VM plugin (rpcchainvm). luxd execs the plugin
|
|
// dexd plugin from its PluginDir with NO args and drives
|
|
// BuildBlock/Verify/Accept inside multi-validator consensus.
|
|
// NO-args == plugin is REQUIRED, not a convenience: it is
|
|
// exactly how luxd launches a plugin (the engine address
|
|
// arrives via the runtime.EngineAddressKey env var, never argv),
|
|
// and `dexd version` is the node's version probe.
|
|
//
|
|
// dexd run run the standalone D-Chain venue: open the on-disk zapdb,
|
|
// dexd standalone serve the frozen dex_* surface over ZAP, and drive the
|
|
// consensus sealer loop itself (WaitForEvent -> BuildBlock ->
|
|
// Verify -> Accept).
|
|
//
|
|
// The matcher, VM, and engine all live in pkg/dchain + pkg/dex; this binary only
|
|
// selects a run mode and wires it — it duplicates no engine code. CGO_ENABLED
|
|
// picks the matcher in pkg/dex (GPU under cgo, pure-Go CPU without); the default
|
|
// build is CPU (CGO=0) and links no native code.
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/luxfi/dex/internal/plugin"
|
|
"github.com/luxfi/dex/internal/standalone"
|
|
)
|
|
|
|
func main() {
|
|
// The first arg selects the run mode. Anything that is NOT an explicit
|
|
// standalone/plugin subcommand falls through to the plugin entrypoint —
|
|
// this preserves the luxd plugin contract byte-for-byte: luxd execs the
|
|
// binary with NO args (serve the handshake) or with "version" (probe the
|
|
// version), and both must reach plugin.Run.
|
|
if len(os.Args) > 1 {
|
|
switch os.Args[1] {
|
|
case "run", "standalone":
|
|
standalone.Run(os.Args[2:])
|
|
return
|
|
case "plugin":
|
|
plugin.Run()
|
|
return
|
|
}
|
|
}
|
|
plugin.Run()
|
|
}
|