refactor(cmd): consolidate cmd/* into one binary — dexd

dexd is now the ONLY command in the repo. One binary, two run modes:

  dexd            run as a luxd rpcchainvm PLUGIN. luxd execs the plugin from
  dexd plugin     its PluginDir with NO positional args (engine address arrives
                  via the runtime.EngineAddressKey env var) and probes the
                  version with `dexd version`. No-subcommand == plugin is
                  REQUIRED to preserve that contract — byte-for-byte the old
                  cmd/dchain behavior (rpc.Serve over the plugin transport).
  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 (WaitForEvent->BuildBlock->Verify->
                  Accept). -addr/-db flags preserved from the old cmd/dvenue.

Relocated logic (engine code NOT duplicated — pkg/dchain + pkg/lx untouched):
  cmd/dchain/{main,runner}   -> internal/plugin     (plugin.Run)
  cmd/dvenue/{main,engine_*} -> internal/standalone (standalone.Run + engineName)
  cmd/dexd/main.go            = thin run-mode dispatcher

Removed cmd dirs (12): dchain, dvenue, demo, dex-api-server, dex-server,
dexfillproof, dexseed, fix-gateway, gateway, monitor, persistent-server,
price-feed. Removed committed build artifacts: gateway, dex-server-linux.

Build/ship ONLY dexd:
  - Dockerfile: canonical CPU image (CGO=0, ghcr.io/luxfi/dex) running
    `dexd run`; no GPU/MLX required.
  - Dockerfile.dvenue: GPU operator bundle repointed cmd/dvenue -> cmd/dexd.
  - Deleted Dockerfile.{gateway,devnet,minimal,dvenue-cpu} and
    docker/{Dockerfile,Dockerfile.cuda,backend/Dockerfile,compose-simple.yml}.
  - Makefile rewritten to build/run/ship dexd only.
  - docker.yml: dropped the dex-gateway image; dex-venue-image.yml: dvenue->dexd.
  - Deleted legacy scripts that built removed/long-gone cmds; fixed deploy.sh +
    dev-setup.sh; .gitignore ignores root build binaries.

Also included (coupled, environment-applied, settled): the in-progress
clob -> dex/orderbook terminology refactor across pkg/* + sdk/* + tests/*
(identifier + file renames, e.g. RegisterCLOB->RegisterDEX,
source_clob.go->source_orderbook.go). The relocated standalone venue calls the
renamed API, so it lands in the same consistent snapshot.

Verified (GOWORK=off CGO_ENABLED=0): `go build ./cmd/dexd`, `go build ./...`,
`go vet ./...` all exit 0; `go test ./pkg/dchain` (renamed RegisterDEX socket
path) green. GPU/cgo path not compiled locally (no CUDA); its rename mirrors
the verified nocgo twins and preserves the C ABI symbol names.
This commit is contained in:
2026-06-26 12:24:34 -07:00
parent afcc765854
commit 21301212f9
113 changed files with 876 additions and 5665 deletions
-64
View File
@@ -1,64 +0,0 @@
#!/bin/bash
echo "==================================="
echo "LXD - Lux DEX Node Demo"
echo "==================================="
echo ""
# Build everything
echo "🔨 Building luxd and clients..."
make clean build > /dev/null 2>&1
go build -o bin/lux-client ./cmd/lux-client > /dev/null 2>&1
go build -o bin/ws-client ./cmd/ws-client > /dev/null 2>&1
echo "✅ Build complete"
echo ""
# Start luxd in background
echo "🚀 Starting luxd node..."
./bin/luxd > luxd.log 2>&1 &
LUXD_PID=$!
echo "✅ luxd started with PID $LUXD_PID"
echo ""
# Wait for startup
sleep 3
# Show node status
echo "📊 Node Status:"
tail -n 5 luxd.log | grep "LXD Node Status" | head -1
echo ""
# Test HTTP client
echo "🔍 Testing HTTP client..."
./bin/lux-client -action test 2>&1 | grep -E "(Client|order placed|Note:)"
echo ""
# Test WebSocket client
echo "🔍 Testing WebSocket client..."
timeout 2 ./bin/ws-client 2>&1 | grep -E "(Connecting|Note:|expected)"
echo ""
# Check database
echo "💾 Database Status:"
if [ -d "$HOME/.lxd/badgerdb" ]; then
echo "✅ BadgerDB initialized at ~/.lxd/badgerdb"
ls -la ~/.lxd/badgerdb/*.sst 2>/dev/null | head -3
else
echo "⚠️ Using in-memory database"
fi
echo ""
# Show performance
echo "⚡ Performance Metrics:"
tail -n 20 luxd.log | grep "Performance metrics" | tail -1
tail -n 20 luxd.log | grep "Block time achievement" | tail -1
echo ""
# Clean up
echo "🧹 Cleaning up..."
kill $LUXD_PID 2>/dev/null
wait $LUXD_PID 2>/dev/null
echo "✅ Demo complete"
echo ""
echo "To run luxd manually: ./bin/luxd"
echo "To test client: ./bin/lux-client -action test"
+3 -3
View File
@@ -47,9 +47,9 @@ check_prerequisites() {
build_images() {
log "Building Docker images..."
# Build backend image
docker build -f docker/backend/Dockerfile -t registry.lux.network/lxdex:${VERSION} .
docker build -f docker/backend/Dockerfile -t registry.lux.network/lxdex:${ENVIRONMENT} .
# Build dexd image (canonical Dockerfile, CPU)
docker build -f Dockerfile -t registry.lux.network/lxdex:${VERSION} .
docker build -f Dockerfile -t registry.lux.network/lxdex:${ENVIRONMENT} .
# Build UI image
docker build -f docker/ui/Dockerfile -t registry.lux.network/lxdex-ui:${VERSION} ./ui
+1 -2
View File
@@ -216,8 +216,7 @@ create_aliases() {
# LX Development Aliases
# Quick commands
alias lx-server='cd backend && go run ./cmd/dex-server'
alias lx-trader='cd backend && go run ./cmd/dex-trader'
alias lx-dexd='go run ./cmd/dexd run'
alias lx-bench='make bench'
alias lx-test='make test'
-415
View File
@@ -1,415 +0,0 @@
#!/bin/bash
# LX Performance Tuning Script
# Automatically finds optimal performance settings for your system
set -e
# Configuration
BACKEND_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../backend" && pwd)"
RESULTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/perf-results"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Performance test parameters
DURATIONS=(10 30 60)
TRADER_COUNTS=(100 500 1000 2000 5000 10000)
ENGINES=("go" "hybrid" "cpp")
BATCH_SIZES=(1 10 50 100 500)
# System information
get_system_info() {
echo -e "${BLUE}=== System Information ===${NC}"
# OS and kernel
echo "OS: $(uname -s) $(uname -r)"
# CPU info
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "CPU: $(sysctl -n machdep.cpu.brand_string)"
echo "Cores: $(sysctl -n hw.ncpu)"
echo "Memory: $(( $(sysctl -n hw.memsize) / 1024 / 1024 / 1024 )) GB"
else
echo "CPU: $(grep "model name" /proc/cpuinfo | head -1 | cut -d: -f2)"
echo "Cores: $(nproc)"
echo "Memory: $(free -h | grep Mem | awk '{print $2}')"
fi
# Go version
echo "Go: $(go version | awk '{print $3}')"
# Check if C++ compiler available
if command -v g++ &> /dev/null; then
echo "C++: $(g++ --version | head -1)"
else
echo "C++: Not available"
fi
echo
}
# Tune OS settings (requires sudo)
tune_os() {
echo -e "${YELLOW}Tuning OS settings (may require sudo)...${NC}"
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS tuning
echo "Tuning macOS network settings..."
# Increase max connections
sudo sysctl -w kern.maxfiles=65536 2>/dev/null || true
sudo sysctl -w kern.maxfilesperproc=65536 2>/dev/null || true
# Network tuning
sudo sysctl -w net.inet.tcp.msl=1000 2>/dev/null || true
sudo sysctl -w net.inet.tcp.sendspace=1048576 2>/dev/null || true
sudo sysctl -w net.inet.tcp.recvspace=1048576 2>/dev/null || true
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux tuning
echo "Tuning Linux network settings..."
# TCP settings
sudo sysctl -w net.ipv4.tcp_fin_timeout=10 2>/dev/null || true
sudo sysctl -w net.ipv4.tcp_tw_reuse=1 2>/dev/null || true
sudo sysctl -w net.ipv4.tcp_keepalive_time=60 2>/dev/null || true
# Connection limits
sudo sysctl -w net.core.somaxconn=65535 2>/dev/null || true
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535 2>/dev/null || true
# Buffer sizes
sudo sysctl -w net.core.rmem_max=134217728 2>/dev/null || true
sudo sysctl -w net.core.wmem_max=134217728 2>/dev/null || true
fi
echo -e "${GREEN}OS tuning complete${NC}"
echo
}
# Build all engine versions
build_engines() {
echo -e "${BLUE}Building all engine versions...${NC}"
cd "$BACKEND_DIR"
# Build Go version
echo "Building Pure Go engine..."
CGO_ENABLED=0 go build -o ../bin/lx-server-go ./cmd/dex-server
# Build Hybrid version if C++ available
if command -v g++ &> /dev/null; then
echo "Building Hybrid Go/C++ engine..."
CGO_ENABLED=1 go build -tags cgo -o ../bin/lx-server-hybrid ./cmd/dex-server
echo "Building Pure C++ benchmark..."
g++ -O3 -std=c++17 -pthread cpp/standalone_bench.cpp -o ../bin/lx-bench-cpp 2>/dev/null || true
fi
echo -e "${GREEN}Build complete${NC}"
echo
}
# Test different trader counts
test_trader_scaling() {
local engine=$1
local duration=$2
echo -e "${YELLOW}Testing trader scaling for $engine engine (${duration}s runs)...${NC}"
local result_file="$RESULTS_DIR/trader_scaling_${engine}_${duration}s_${TIMESTAMP}.csv"
echo "traders,orders_per_sec,latency_avg_ms,latency_p99_ms,errors" > "$result_file"
for traders in "${TRADER_COUNTS[@]}"; do
echo -n "Testing $traders traders... "
# Start server
case $engine in
"go")
../bin/lx-server-go -port 50051 > /dev/null 2>&1 &
;;
"hybrid")
../bin/lx-server-hybrid -port 50051 > /dev/null 2>&1 &
;;
esac
local server_pid=$!
sleep 2
# Run test
if output=$(go run ./cmd/mega-traders -traders "$traders" -duration "${duration}s" -grpc localhost:50051 2>&1); then
# Parse output
orders_per_sec=$(echo "$output" | grep "Orders/sec" | awk '{print $2}')
latency_avg=$(echo "$output" | grep "Avg latency" | awk '{print $3}')
latency_p99=$(echo "$output" | grep "P99 latency" | awk '{print $3}')
errors=$(echo "$output" | grep "Errors" | awk '{print $2}')
echo "$traders,$orders_per_sec,$latency_avg,$latency_p99,$errors" >> "$result_file"
echo -e "${GREEN}✓${NC} ${orders_per_sec} orders/sec"
else
echo -e "${RED}✗${NC} Failed"
fi
# Cleanup
kill $server_pid 2>/dev/null || true
wait $server_pid 2>/dev/null || true
done
echo "Results saved to: $result_file"
echo
}
# Test different batch sizes
test_batch_sizes() {
local engine=$1
echo -e "${YELLOW}Testing batch sizes for $engine engine...${NC}"
local result_file="$RESULTS_DIR/batch_sizes_${engine}_${TIMESTAMP}.csv"
echo "batch_size,orders_per_sec,latency_ms" > "$result_file"
for batch in "${BATCH_SIZES[@]}"; do
echo -n "Testing batch size $batch... "
# Run test with different batch sizes
if output=$(go run ./cmd/bench -iter 10000 -batch "$batch" 2>&1); then
orders_per_sec=$(echo "$output" | grep "throughput" | awk '{print $2}')
latency=$(echo "$output" | grep "latency" | awk '{print $2}')
echo "$batch,$orders_per_sec,$latency" >> "$result_file"
echo -e "${GREEN}✓${NC} ${orders_per_sec} orders/sec"
else
echo -e "${RED}✗${NC} Failed"
fi
done
echo "Results saved to: $result_file"
echo
}
# Find maximum throughput
find_max_throughput() {
local engine=$1
echo -e "${YELLOW}Finding maximum throughput for $engine engine...${NC}"
cd "$BACKEND_DIR"
case $engine in
"go")
echo "Running max performance test for Pure Go..."
go run ./cmd/max-perf-bench -target go -duration 30s -max-traders 10000 -step 500
;;
"hybrid")
echo "Running max performance test for Hybrid Go/C++..."
go run ./cmd/max-perf-bench -target hybrid -duration 30s -max-traders 10000 -step 500
;;
"cpp")
if [ -f "../bin/lx-bench-cpp" ]; then
echo "Running C++ standalone benchmark..."
../bin/lx-bench-cpp 1000 10
fi
;;
esac
echo
}
# Memory profiling
profile_memory() {
local engine=$1
echo -e "${YELLOW}Profiling memory usage for $engine engine...${NC}"
cd "$BACKEND_DIR"
# Start server
case $engine in
"go")
GODEBUG=gctrace=1 ../bin/lx-server-go -port 50051 > "$RESULTS_DIR/gc_trace_${engine}_${TIMESTAMP}.log" 2>&1 &
;;
"hybrid")
GODEBUG=gctrace=1 ../bin/lx-server-hybrid -port 50051 > "$RESULTS_DIR/gc_trace_${engine}_${TIMESTAMP}.log" 2>&1 &
;;
esac
local server_pid=$!
sleep 2
# Run load test while profiling
go run ./cmd/mega-traders -traders 1000 -duration 60s -grpc localhost:50051 &
local client_pid=$!
# Collect memory profile
sleep 30
go tool pprof -http=:8080 "http://localhost:6060/debug/pprof/heap" &
local pprof_pid=$!
wait $client_pid
# Cleanup
kill $server_pid $pprof_pid 2>/dev/null || true
echo -e "${GREEN}Memory profile saved${NC}"
echo
}
# Generate performance report
generate_report() {
echo -e "${BLUE}Generating performance report...${NC}"
local report_file="$RESULTS_DIR/performance_report_${TIMESTAMP}.md"
cat > "$report_file" << EOF
# LX Performance Report
Generated: $(date)
## System Information
$(get_system_info)
## Performance Results
### Maximum Throughput by Engine
EOF
# Find best results from CSV files
for engine in "${ENGINES[@]}"; do
if [ -f "$RESULTS_DIR/trader_scaling_${engine}_30s_${TIMESTAMP}.csv" ]; then
echo "#### $engine Engine" >> "$report_file"
echo '```' >> "$report_file"
sort -t, -k2 -nr "$RESULTS_DIR/trader_scaling_${engine}_30s_${TIMESTAMP}.csv" | head -5 >> "$report_file"
echo '```' >> "$report_file"
fi
done
cat >> "$report_file" << EOF
## Recommendations
Based on the performance testing:
1. **Optimal Engine**: $(determine_best_engine)
2. **Optimal Trader Count**: $(find_optimal_traders)
3. **Optimal Batch Size**: $(find_optimal_batch)
### Tuning Parameters
\`\`\`yaml
engine:
type: $(determine_best_engine)
performance:
max_traders: $(find_optimal_traders)
batch_size: $(find_optimal_batch)
runtime:
GOGC: 100
GOMEMLIMIT: 8GiB
GOMAXPROCS: $(nproc)
\`\`\`
## Next Steps
1. Apply recommended settings to config/production.yaml
2. Run extended stress tests with optimal settings
3. Monitor production metrics
4. Adjust based on real-world usage patterns
EOF
echo -e "${GREEN}Report saved to: $report_file${NC}"
# Display summary
echo
echo -e "${BLUE}=== Performance Summary ===${NC}"
cat "$report_file" | grep -A 10 "Recommendations"
}
# Helper functions for report generation
determine_best_engine() {
# Simple heuristic - would be improved with actual data analysis
if [ -f "../bin/lx-server-hybrid" ]; then
echo "hybrid"
else
echo "go"
fi
}
find_optimal_traders() {
# Find trader count with best throughput
echo "5000"
}
find_optimal_batch() {
# Find optimal batch size
echo "100"
}
# Main execution
main() {
echo -e "${BLUE}======================================${NC}"
echo -e "${BLUE} LX Performance Tuning Suite${NC}"
echo -e "${BLUE}======================================${NC}"
echo
# Create results directory
mkdir -p "$RESULTS_DIR"
# System info
get_system_info
# OS tuning (optional)
read -p "Tune OS settings? (requires sudo) [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
tune_os
fi
# Build engines
build_engines
# Run performance tests
for engine in "${ENGINES[@]}"; do
if [ "$engine" == "cpp" ] && [ ! -f "../bin/lx-bench-cpp" ]; then
continue
fi
if [ "$engine" == "hybrid" ] && [ ! -f "../bin/lx-server-hybrid" ]; then
continue
fi
echo -e "${BLUE}Testing $engine engine...${NC}"
# Test trader scaling
test_trader_scaling "$engine" 30
# Test batch sizes
if [ "$engine" != "cpp" ]; then
test_batch_sizes "$engine"
fi
# Find max throughput
find_max_throughput "$engine"
# Memory profiling
if [ "$engine" != "cpp" ]; then
profile_memory "$engine"
fi
done
# Generate report
generate_report
echo
echo -e "${GREEN}Performance tuning complete!${NC}"
echo "Results saved in: $RESULTS_DIR"
}
# Run if not sourced
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
main "$@"
fi
-197
View File
@@ -1,197 +0,0 @@
#!/bin/bash
# LX E2E Test Runner
# This script runs the full DEX server and performs end-to-end tests
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
PORT=8080
SERVER_PID=""
# Cleanup function
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
if [ ! -z "$SERVER_PID" ]; then
kill $SERVER_PID 2>/dev/null || true
fi
}
trap cleanup EXIT
echo "🚀 LX End-to-End Test Suite"
echo "================================"
echo ""
# Step 1: Build the server
echo -e "${BLUE}Step 1: Building DEX API Server...${NC}"
go build -o ./bin/dex-api-server ./cmd/dex-api-server/main.go
echo -e "${GREEN}✓ Server built successfully${NC}"
echo ""
# Step 2: Start the server
echo -e "${BLUE}Step 2: Starting DEX API Server on port $PORT...${NC}"
./bin/dex-api-server -port=$PORT > server.log 2>&1 &
SERVER_PID=$!
sleep 2
# Check if server started
if ! ps -p $SERVER_PID > /dev/null; then
echo -e "${RED}✗ Server failed to start${NC}"
cat server.log
exit 1
fi
echo -e "${GREEN}✓ Server started (PID: $SERVER_PID)${NC}"
echo ""
# Step 3: Wait for server to be ready
echo -e "${BLUE}Step 3: Waiting for server to be ready...${NC}"
for i in {1..10}; do
if curl -s http://localhost:$PORT/api/stats > /dev/null 2>&1; then
echo -e "${GREEN}✓ Server is ready${NC}"
break
fi
if [ $i -eq 10 ]; then
echo -e "${RED}✗ Server failed to become ready${NC}"
exit 1
fi
sleep 1
done
echo ""
# Step 4: Run E2E Tests
echo -e "${BLUE}Step 4: Running E2E Tests...${NC}"
echo ""
# Test 1: Health Check
echo "Test 1: Health Check"
if curl -s http://localhost:$PORT/api/stats | grep -q "operational"; then
echo -e "${GREEN}✓ Health check passed${NC}"
else
echo -e "${RED}✗ Health check failed${NC}"
exit 1
fi
# Test 2: Order Book Should Have Initial Orders
echo "Test 2: Initial Order Book"
ORDERBOOK=$(curl -s http://localhost:$PORT/api/orderbook)
if echo "$ORDERBOOK" | grep -q "bids" && echo "$ORDERBOOK" | grep -q "asks"; then
echo -e "${GREEN}✓ Order book initialized${NC}"
else
echo -e "${RED}✗ Order book initialization failed${NC}"
exit 1
fi
# Test 3: Place Orders
echo "Test 3: Place Orders"
# Place buy order
BUY_RESPONSE=$(curl -s -X POST http://localhost:$PORT/api/order \
-H "Content-Type: application/json" \
-d '{"type":"limit","side":"buy","price":49000,"size":1.0}')
if echo "$BUY_RESPONSE" | grep -q "success.*true"; then
echo -e "${GREEN}✓ Buy order placed${NC}"
else
echo -e "${RED}✗ Failed to place buy order${NC}"
echo "$BUY_RESPONSE"
exit 1
fi
# Place sell order
SELL_RESPONSE=$(curl -s -X POST http://localhost:$PORT/api/order \
-H "Content-Type: application/json" \
-d '{"type":"limit","side":"sell","price":51000,"size":1.0}')
if echo "$SELL_RESPONSE" | grep -q "success.*true"; then
echo -e "${GREEN}✓ Sell order placed${NC}"
else
echo -e "${RED}✗ Failed to place sell order${NC}"
echo "$SELL_RESPONSE"
exit 1
fi
# Test 4: Market Order Execution
echo "Test 4: Market Order Execution"
MARKET_RESPONSE=$(curl -s -X POST http://localhost:$PORT/api/order \
-H "Content-Type: application/json" \
-d '{"type":"market","side":"buy","price":0,"size":0.1}')
if echo "$MARKET_RESPONSE" | grep -q "success.*true"; then
echo -e "${GREEN}✓ Market order executed${NC}"
else
echo -e "${RED}✗ Market order failed${NC}"
echo "$MARKET_RESPONSE"
exit 1
fi
# Test 5: Check Trades
echo "Test 5: Trade History"
TRADES=$(curl -s http://localhost:$PORT/api/trades)
if echo "$TRADES" | grep -q "data"; then
echo -e "${GREEN}✓ Trades retrieved${NC}"
else
echo -e "${RED}✗ Failed to retrieve trades${NC}"
exit 1
fi
# Test 6: Stress Test - Place Many Orders
echo "Test 6: Stress Test (100 orders)"
SUCCESS_COUNT=0
for i in {1..100}; do
PRICE=$((49000 + RANDOM % 2000))
SIZE=$(echo "scale=2; $RANDOM/32768" | bc)
SIDE=$((RANDOM % 2))
if [ $SIDE -eq 0 ]; then
SIDE_STR="buy"
else
SIDE_STR="sell"
fi
RESPONSE=$(curl -s -X POST http://localhost:$PORT/api/order \
-H "Content-Type: application/json" \
-d "{\"type\":\"limit\",\"side\":\"$SIDE_STR\",\"price\":$PRICE,\"size\":0.1}" 2>/dev/null)
if echo "$RESPONSE" | grep -q "success.*true" 2>/dev/null; then
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
fi
done
if [ $SUCCESS_COUNT -gt 90 ]; then
echo -e "${GREEN}✓ Stress test passed ($SUCCESS_COUNT/100 orders successful)${NC}"
else
echo -e "${RED}✗ Stress test failed (only $SUCCESS_COUNT/100 orders successful)${NC}"
exit 1
fi
# Test 7: Final Stats Check
echo "Test 7: Final Statistics"
FINAL_STATS=$(curl -s http://localhost:$PORT/api/stats)
if echo "$FINAL_STATS" | grep -q "total_orders" && echo "$FINAL_STATS" | grep -q "13M"; then
echo -e "${GREEN}✓ Statistics endpoint working${NC}"
echo "$FINAL_STATS" | python3 -m json.tool 2>/dev/null | head -20
else
echo -e "${RED}✗ Statistics endpoint failed${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}✅ ALL E2E TESTS PASSED SUCCESSFULLY!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo "Server logs saved to: server.log"
echo "Server PID: $SERVER_PID"
echo ""
echo "To test manually:"
echo " curl http://localhost:$PORT/api/orderbook"
echo " curl http://localhost:$PORT/api/stats"
echo ""
echo "To stop the server:"
echo " kill $SERVER_PID"
-220
View File
@@ -1,220 +0,0 @@
#!/bin/bash
# Run LX Cluster with X-Chain and Q-Chain
echo "🚀 Starting LX Cluster (X-Chain + Q-Chain)"
echo "=============================================="
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Configuration
DATA_DIR="/tmp/lx-dex-cluster"
CLUSTER_SIZE=3 # Number of nodes for consensus
BASE_PORT=8080
BASE_WS_PORT=8081
BASE_P2P_PORT=5000
# Clean previous data
echo "Cleaning previous cluster data..."
rm -rf $DATA_DIR
mkdir -p $DATA_DIR/{node1,node2,node3}
# Build the DEX server if needed
echo "Building LX server..."
cd /Users/z/work/lx/dex/backend
go build -o ../bin/lx-dex ./cmd/dex-server
cd /Users/z/work/lx/dex
# Start cluster nodes
echo ""
echo "Starting LX Cluster Nodes..."
echo "================================"
# Node 1 (Bootstrap node)
echo -n "Starting Node 1 (Bootstrap): "
./bin/lx-dex \
--node-id node1 \
--http-port $BASE_PORT \
--ws-port $BASE_WS_PORT \
--p2p-port $BASE_P2P_PORT \
--data-dir $DATA_DIR/node1 \
--chain x-chain \
--consensus k=3 \
--bootstrap \
> $DATA_DIR/node1.log 2>&1 &
NODE1_PID=$!
echo -e "${GREEN}✅ PID: $NODE1_PID${NC}"
sleep 2
# Node 2
echo -n "Starting Node 2: "
./bin/lx-dex \
--node-id node2 \
--http-port $((BASE_PORT + 10)) \
--ws-port $((BASE_WS_PORT + 10)) \
--p2p-port $((BASE_P2P_PORT + 10)) \
--data-dir $DATA_DIR/node2 \
--chain x-chain \
--consensus k=3 \
--bootstrap-peer 127.0.0.1:$BASE_P2P_PORT \
> $DATA_DIR/node2.log 2>&1 &
NODE2_PID=$!
echo -e "${GREEN}✅ PID: $NODE2_PID${NC}"
sleep 2
# Node 3
echo -n "Starting Node 3: "
./bin/lx-dex \
--node-id node3 \
--http-port $((BASE_PORT + 20)) \
--ws-port $((BASE_WS_PORT + 20)) \
--p2p-port $((BASE_P2P_PORT + 20)) \
--data-dir $DATA_DIR/node3 \
--chain x-chain \
--consensus k=3 \
--bootstrap-peer 127.0.0.1:$BASE_P2P_PORT \
> $DATA_DIR/node3.log 2>&1 &
NODE3_PID=$!
echo -e "${GREEN}✅ PID: $NODE3_PID${NC}"
sleep 3
# Test cluster health
echo ""
echo "Testing Cluster Health..."
echo "========================"
# Function to check node health
check_node() {
local port=$1
local node=$2
echo -n "Node $node (port $port): "
if curl -s http://localhost:$port/health 2>/dev/null | grep -q "ok"; then
echo -e "${GREEN}✅ Healthy${NC}"
return 0
else
echo -e "${RED}❌ Not responding${NC}"
return 1
fi
}
check_node $BASE_PORT 1
check_node $((BASE_PORT + 10)) 2
check_node $((BASE_PORT + 20)) 3
# Test X-Chain RPC
echo ""
echo "Testing X-Chain RPC Endpoints..."
echo "================================"
# Test order book endpoint
echo -n "1. Order Book API: "
if curl -s http://localhost:$BASE_PORT/api/orderbook 2>/dev/null | grep -q "bids\|asks\|{}"; then
echo -e "${GREEN}✅ Working${NC}"
else
echo -e "${RED}❌ Failed${NC}"
fi
# Test market data
echo -n "2. Market Data API: "
if curl -s http://localhost:$BASE_PORT/api/markets 2>/dev/null | grep -q "\\[\\]\\|markets"; then
echo -e "${GREEN}✅ Working${NC}"
else
echo -e "${RED}❌ Failed${NC}"
fi
# Test WebSocket
echo -n "3. WebSocket Feed: "
if timeout 1 websocat ws://localhost:$BASE_WS_PORT/ws 2>/dev/null <<< '{"type":"ping"}' | grep -q "pong\|connected"; then
echo -e "${GREEN}✅ Connected${NC}"
else
echo -e "${YELLOW}⚠ WebSocket not ready${NC}"
fi
# Test consensus
echo -n "4. Consensus Status: "
CONSENSUS=$(curl -s http://localhost:$BASE_PORT/consensus/status 2>/dev/null)
if [ ! -z "$CONSENSUS" ]; then
echo -e "${GREEN}✅ K=3 Active${NC}"
else
echo -e "${YELLOW}⚠ Initializing${NC}"
fi
# Create test orders
echo ""
echo "Creating Test Orders..."
echo "======================"
# Submit a test order
ORDER_RESPONSE=$(curl -s -X POST http://localhost:$BASE_PORT/api/orders \
-H "Content-Type: application/json" \
-d '{
"symbol": "BTC-USD",
"side": "buy",
"price": 50000,
"size": 1.0,
"trader": "test-trader-1"
}' 2>/dev/null)
if echo "$ORDER_RESPONSE" | grep -q "id"; then
echo -e "${GREEN}✅ Order submitted successfully${NC}"
else
echo -e "${YELLOW}⚠ Order submission pending${NC}"
fi
# Monitor blocks
echo ""
echo "======================================"
echo -e "${GREEN}✅ LX Cluster is running!${NC}"
echo ""
echo "Cluster Nodes:"
echo " Node 1: http://localhost:$BASE_PORT (Bootstrap)"
echo " Node 2: http://localhost:$((BASE_PORT + 10))"
echo " Node 3: http://localhost:$((BASE_PORT + 20))"
echo ""
echo "WebSocket Feeds:"
echo " Node 1: ws://localhost:$BASE_WS_PORT"
echo " Node 2: ws://localhost:$((BASE_WS_PORT + 10))"
echo " Node 3: ws://localhost:$((BASE_WS_PORT + 20))"
echo ""
echo "Process IDs:"
echo " Node 1: $NODE1_PID"
echo " Node 2: $NODE2_PID"
echo " Node 3: $NODE3_PID"
echo ""
echo "Logs:"
echo " tail -f $DATA_DIR/node1.log"
echo " tail -f $DATA_DIR/node2.log"
echo " tail -f $DATA_DIR/node3.log"
echo ""
echo "To stop cluster: kill $NODE1_PID $NODE2_PID $NODE3_PID"
echo ""
echo "Monitoring block formation..."
echo "Press Ctrl+C to stop"
echo ""
# Monitor block production
while true; do
# Get block height from each node
for i in 0 10 20; do
PORT=$((BASE_PORT + i))
NODE=$((i/10 + 1))
BLOCK_INFO=$(curl -s http://localhost:$PORT/api/blocks/latest 2>/dev/null)
if [ ! -z "$BLOCK_INFO" ]; then
HEIGHT=$(echo "$BLOCK_INFO" | grep -o '"height":[0-9]*' | cut -d':' -f2)
if [ ! -z "$HEIGHT" ]; then
echo "Node $NODE - Block #$HEIGHT at $(date '+%H:%M:%S')"
fi
fi
done
echo "---"
sleep 5
done
-63
View File
@@ -1,63 +0,0 @@
#!/bin/bash
# LX - Run Script
# This script builds and runs various components of the LX
set -e
# Ensure CGO is disabled for compatibility
export CGO_ENABLED=0
case "$1" in
"demo")
echo "🚀 Running LX Demo..."
go run ./cmd/demo
;;
"server")
echo "🌐 Starting DEX Server..."
echo "Usage: $0 server [port]"
PORT=${2:-8080}
go run ./cmd/dex-server -port $PORT
;;
"memory")
echo "📊 Running Memory Analysis..."
go run ./cmd/memory-analysis
;;
"test")
echo "🧪 Running Tests..."
go test ./pkg/... -short -timeout 30s
;;
"build")
echo "🔨 Building all packages..."
go build ./pkg/...
echo "✅ Build successful!"
;;
"benchmark")
echo "⚡ Running Benchmarks..."
go test ./pkg/lx -bench=. -run=^$ -benchtime=10s
;;
*)
echo "LX - Ultra High-Performance Order Book"
echo ""
echo "Usage: ./run.sh [command]"
echo ""
echo "Commands:"
echo " demo - Run interactive order book demo"
echo " server - Start DEX server (default port: 8080)"
echo " memory - Analyze memory usage for 1M markets"
echo " test - Run all tests"
echo " build - Build all packages"
echo " benchmark - Run performance benchmarks"
echo ""
echo "Examples:"
echo " ./run.sh demo"
echo " ./run.sh server 9090"
echo " ./run.sh test"
;;
esac
-231
View File
@@ -1,231 +0,0 @@
#!/bin/bash
# E2E Test Script for LUX DEX
set -e
echo "🧪 LUX DEX E2E Test Suite"
echo "========================"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counter
TESTS_PASSED=0
TESTS_FAILED=0
# Helper functions
test_pass() {
echo -e "${GREEN}✅ $1${NC}"
((TESTS_PASSED++))
}
test_fail() {
echo -e "${RED}❌ $1${NC}"
((TESTS_FAILED++))
}
test_info() {
echo -e "${YELLOW}ℹ️ $1${NC}"
}
# 1. Test Database Connectivity
echo ""
echo "1. Testing Database Connectivity..."
if docker exec lux-dex-db pg_isready -U dexuser -d luxdex > /dev/null 2>&1; then
test_pass "PostgreSQL is running and accepting connections"
else
test_fail "PostgreSQL is not accessible"
fi
# 2. Test Redis Connectivity
echo ""
echo "2. Testing Redis Cache..."
if docker exec lux-dex-redis redis-cli ping | grep -q PONG; then
test_pass "Redis is running and responding"
else
test_fail "Redis is not accessible"
fi
# 3. Test Backend Build
echo ""
echo "3. Testing Backend Build..."
cd backend
if go build -o ../bin/test-server ./cmd/dex-server 2>/dev/null; then
test_pass "Backend builds successfully"
rm ../bin/test-server
else
test_fail "Backend build failed"
fi
cd ..
# 4. Test Order Book Package
echo ""
echo "4. Testing Order Book Implementation..."
cd backend
if go test ./pkg/lx/... -v -count=1 2>&1 | grep -q "PASS"; then
test_pass "Order book tests pass"
else
test_fail "Order book tests failed"
fi
cd ..
# 5. Test UI Build
echo ""
echo "5. Testing UI Build..."
cd ui
if npm run build > /dev/null 2>&1; then
test_pass "UI builds successfully"
else
test_fail "UI build failed"
fi
cd ..
# 6. Test WebSocket Order Book Server
echo ""
echo "6. Testing WebSocket Implementation..."
cd backend
if go test ./pkg/orderbook/... -v -count=1 2>&1 | grep -q "PASS"; then
test_pass "WebSocket order book tests pass"
else
test_fail "WebSocket order book tests failed"
fi
cd ..
# 7. Performance Benchmark
echo ""
echo "7. Running Performance Benchmark..."
cd backend/pkg/lx
BENCH_OUTPUT=$(go test -bench=BenchmarkOrderMatching -benchtime=1s -run=^$ 2>&1)
if echo "$BENCH_OUTPUT" | grep -q "ns/op"; then
LATENCY=$(echo "$BENCH_OUTPUT" | grep "BenchmarkOrderMatching" | awk '{print $3}')
test_pass "Order matching benchmark completed: ${LATENCY} ns/op"
# Check if we meet the <1μs target (1000ns)
LATENCY_NUM=$(echo "$LATENCY" | sed 's/[^0-9.]//g')
if (( $(echo "$LATENCY_NUM < 1000" | bc -l) )); then
test_pass "✨ Sub-microsecond latency achieved!"
else
test_info "Latency above 1μs target"
fi
else
test_fail "Benchmark failed to run"
fi
cd ../../..
# 8. Test Playwright Setup
echo ""
echo "8. Testing Playwright E2E Setup..."
cd ui
if npx playwright --version > /dev/null 2>&1; then
test_pass "Playwright is installed"
# Run a simple Playwright test
cat > test-simple.spec.ts << 'EOF'
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
// This is a placeholder test
expect(1 + 1).toBe(2);
});
EOF
if npx playwright test test-simple.spec.ts --reporter=line 2>&1 | grep -q "1 passed"; then
test_pass "Playwright tests can run"
else
test_fail "Playwright test execution failed"
fi
rm test-simple.spec.ts
else
test_fail "Playwright is not installed"
fi
cd ..
# 9. Integration Test: Order Flow
echo ""
echo "9. Testing Order Flow Integration..."
cat > test-orders.go << 'EOF'
package main
import (
"fmt"
"os"
"github.com/your-org/lx-dex/backend/pkg/lx"
)
func main() {
ob := lx.NewOrderBook("BTC-USD", 10000)
// Add buy order
buyOrder := &lx.Order{
ID: "buy-1",
Symbol: "BTC-USD",
Side: lx.Buy,
Price: 50000.0,
Size: 1.0,
Trader: "trader-1",
}
ob.AddOrder(buyOrder)
// Add sell order (should match)
sellOrder := &lx.Order{
ID: "sell-1",
Symbol: "BTC-USD",
Side: lx.Sell,
Price: 50000.0,
Size: 1.0,
Trader: "trader-2",
}
trades := ob.AddOrder(sellOrder)
if len(trades) == 1 && trades[0].Price == 50000.0 {
fmt.Println("PASS")
os.Exit(0)
}
fmt.Println("FAIL")
os.Exit(1)
}
EOF
cd backend
if go run ../test-orders.go 2>/dev/null | grep -q "PASS"; then
test_pass "Order matching integration works"
else
test_fail "Order matching integration failed"
fi
cd ..
rm test-orders.go
# 10. Test Docker Compose Validation
echo ""
echo "10. Testing Docker Compose Configuration..."
if docker compose -f docker/compose.dev.yml config > /dev/null 2>&1; then
test_pass "Docker Compose configuration is valid"
else
test_fail "Docker Compose configuration has errors"
fi
# Summary
echo ""
echo "======================================="
echo "E2E Test Results Summary"
echo "======================================="
echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
if [ $TESTS_FAILED -gt 0 ]; then
echo -e "${RED}Failed: $TESTS_FAILED${NC}"
echo ""
echo "⚠️ Some tests failed. Please review the output above."
exit 1
else
echo -e "${GREEN}All tests passed! 🎉${NC}"
echo ""
echo "✅ The LUX DEX stack is working correctly!"
echo " - Databases are running"
echo " - Backend builds and tests pass"
echo " - UI builds successfully"
echo " - Performance meets targets"
echo " - Integration tests pass"
exit 0
fi