mirror of
https://github.com/luxfi/bridge.git
synced 2026-09-24 00:26:46 +00:00
112 lines
3.7 KiB
Bash
Executable File
112 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
echo "==================================="
|
|
echo "Starting Lux MPC Network"
|
|
echo "==================================="
|
|
echo ""
|
|
|
|
if ! command -v lux-mpc &> /dev/null; then
|
|
echo "❌ lux-mpc not found. Please run ./scripts/install-mpc-tools.sh first."
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v lux-mpc-cli &> /dev/null; then
|
|
echo "❌ lux-mpc-cli not found. Please run ./scripts/install-mpc-tools.sh first."
|
|
exit 1
|
|
fi
|
|
|
|
MPC_DATA_DIR="${MPC_DATA_DIR:-./data/mpc}"
|
|
MPC_CONFIG_DIR="${MPC_CONFIG_DIR:-./config/mpc}"
|
|
# ZapDB encryption password — read by mpcd's hsm/env provider. Same constant
|
|
# as the previous implementation's badger_password so on-disk state stays
|
|
# decryptable across the migration.
|
|
export MPC_PASSWORD="${MPC_PASSWORD:-12345678901234567890123456789012}"
|
|
|
|
# Node layout — same external HTTP API ports as the legacy script (6000-6002)
|
|
# so existing bridge consumers don't need to change endpoints. The :9090-9092
|
|
# range moves from "gRPC" to mpcd's ZAP P2P transport.
|
|
NODES=(node0 node1 node2)
|
|
P2P_PORTS=(9090 9091 9092)
|
|
API_PORTS=(6000 6001 6002)
|
|
DASH_PORTS=(8081 8082 8083)
|
|
THRESHOLD=2
|
|
|
|
mkdir -p "$MPC_CONFIG_DIR" logs
|
|
for n in "${NODES[@]}"; do
|
|
mkdir -p "$MPC_DATA_DIR/$n/data" "$MPC_DATA_DIR/$n/keys"
|
|
done
|
|
|
|
# Per-node Ed25519 identities are generated by mpcd itself on first start
|
|
# (cmd/mpcd/main.go:loadOrGenerateIdentity), written to
|
|
# <keys>/<node>_identity.json with the {node_id, public_key, private_key}
|
|
# shape it expects. Peer pubkeys are then exchanged at the ZAP transport
|
|
# layer — no need to pre-share. The lux-mpc-cli generate-identity output
|
|
# uses a different schema and would be clobbered, so we don't pre-generate.
|
|
|
|
start_node() {
|
|
local idx=$1
|
|
local name=${NODES[$idx]}
|
|
local p2p=${P2P_PORTS[$idx]}
|
|
local api=${API_PORTS[$idx]}
|
|
local dash=${DASH_PORTS[$idx]}
|
|
|
|
local peer_args=()
|
|
for j in "${!NODES[@]}"; do
|
|
[ "$j" = "$idx" ] && continue
|
|
peer_args+=(--peer "${NODES[$j]}@127.0.0.1:${P2P_PORTS[$j]}")
|
|
done
|
|
|
|
echo "Starting $name (P2P :$p2p, API :$api, dashboard :$dash)..."
|
|
local log_file="$(pwd)/logs/${name}.log"
|
|
|
|
nohup lux-mpc start \
|
|
--node-id "$name" \
|
|
--listen ":$p2p" \
|
|
--api ":$api" \
|
|
--api-listen ":$dash" \
|
|
--data "$MPC_DATA_DIR/$name/data" \
|
|
--keys "$MPC_DATA_DIR/$name/keys" \
|
|
--threshold "$THRESHOLD" \
|
|
--log-level "${LOG_LEVEL:-info}" \
|
|
--kms-zap-listen "" \
|
|
--threshold-listen "" \
|
|
"${peer_args[@]}" \
|
|
> "$log_file" 2>&1 &
|
|
|
|
echo "$name started with PID $!"
|
|
}
|
|
|
|
echo "Checking infrastructure services..."
|
|
nc -z localhost 4223 2>/dev/null || echo "⚠️ NATS not running on :4223 — only required for legacy mode; consensus-mode mpcd doesn't use it."
|
|
nc -z localhost 8501 2>/dev/null || echo "⚠️ Consul not running on :8501 — only required for legacy mode; consensus-mode mpcd doesn't use it."
|
|
nc -z localhost 8200 2>/dev/null || echo "⚠️ KMS not running on :8200 — required if bridge server uses real KMS."
|
|
nc -z localhost 8000 2>/dev/null || echo "⚠️ Lux ID not running on :8000 — required if bridge server uses real auth."
|
|
echo ""
|
|
|
|
for i in "${!NODES[@]}"; do
|
|
start_node "$i"
|
|
sleep 2
|
|
done
|
|
|
|
echo ""
|
|
echo "==================================="
|
|
echo "MPC Network Started!"
|
|
echo "==================================="
|
|
echo ""
|
|
echo "Nodes:"
|
|
for i in "${!NODES[@]}"; do
|
|
echo " - ${NODES[$i]}: API=http://localhost:${API_PORTS[$i]}, P2P=:${P2P_PORTS[$i]}, dashboard=:${DASH_PORTS[$i]}"
|
|
done
|
|
echo ""
|
|
echo "Logs:"
|
|
for n in "${NODES[@]}"; do
|
|
echo " - logs/${n}.log"
|
|
done
|
|
echo ""
|
|
echo "To check health:"
|
|
echo " curl http://localhost:${API_PORTS[0]}/healthz"
|
|
echo ""
|
|
echo "To stop the network:"
|
|
echo " ./scripts/stop-mpc-network.sh"
|