mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
`lux dev start` could not bring up a node built from the current tree, for
three reasons that share a shape with the chain-segment rename: the CLI
spelled out an address the node had already left behind, and nothing failed
to compile.
The health service moved onto typed ops. /v1/health is gone, so every probe
written against it read a healthy node as unhealthy and every printed
endpoint sent a reader to a 404. route.Health, route.Liveness and
route.Readiness compose the three addresses the node answers on, next to
route.Chain and off the same base, and the ten call sites that had it
written out now ask for the one they mean: a probe polls readiness, a
report reads the full checks, a printed endpoint offers the report.
Two luxd flags no longer exist, and passing an unknown flag is fatal, so
the node refused the config before it read any of it:
--api-keystore-enabled the keystore API is gone
--automine-interval block cadence is the C-Chain's own
enable-automining, read by the block builder from
the chain config dir, not a node flag
The --automine duration flag went with the second: it named a knob that
does not exist.
`lux dev stop` looked only in the default data-dir, and otherwise pkill'd
anything whose command line carried a quorum size of one — a pattern that
fits every dev node on the machine, not just the one this command started.
It takes the same --data-dir as start now, resolved by the same function,
and reads the PID from there; no PID file is an answer rather than a reason
to guess.
Health gets composition but not the guard that pins chain addresses:
pkg/ssh still asks for health as a JSON-RPC method, and the whole
JSON-RPC-over-SSH family it belongs to is owed the same move onto typed
ops. A guard added before that migration would need an exemption for it,
and an exemption is how a guard rots.
Measured against luxd 1.36.181 (constants v1.6.4): start reaches ready,
prints /v1/chain/C/rpc and /v1/health/ops/health, both answer 200, and
stop interrupts the node it started and reports plainly when there is
none.
Co-authored-by: Hanzo Dev <[email protected]>
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package devcmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/luxfi/cli/pkg/ux"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Deprecated. New code uses `lux down <brand>/<env>` (cmd/downcmd) which
|
|
// identifies the node by service (port + networkID handshake) rather
|
|
// than by PID file. This subcommand stays as the anvil-compat shortcut
|
|
// for `lux dev start`.
|
|
func newStopCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "stop",
|
|
Short: "Stop the anvil-compat dev node started by `lux dev start`",
|
|
Long: `Stops the node whose PID ` + "`lux dev start`" + ` recorded in its data-dir.
|
|
Pass the same --data-dir you started with. For sovereign-L1 nodes booted
|
|
via ` + "`lux up <brand>/<env>`" + `, use ` + "`lux down <brand>/<env>`" + ` instead.`,
|
|
RunE: stopDevNode,
|
|
Args: cobra.ExactArgs(0),
|
|
SilenceUsage: true,
|
|
}
|
|
cmd.Flags().StringVar(&dataDir, "data-dir", "", "luxd data-dir the node was started with (default ~/.lux/devnet)")
|
|
return cmd
|
|
}
|
|
|
|
func stopDevNode(*cobra.Command, []string) error {
|
|
ux.Logger.PrintToUser("Stopping Lux dev node...")
|
|
|
|
// The node to stop is the one this data-dir names. Matching on a command
|
|
// line instead reaches nodes this command never started: the pattern it
|
|
// used, a quorum size of one, fits every dev node on the machine. So the
|
|
// PID file is the only address, and its absence is an answer rather than
|
|
// a reason to guess.
|
|
pidFile := devPIDFile()
|
|
pidData, err := os.ReadFile(pidFile) //nolint:gosec // the caller's own data-dir
|
|
if err != nil {
|
|
ux.Logger.PrintToUser("No dev node recorded at %s", pidFile)
|
|
return nil
|
|
}
|
|
pid, err := strconv.Atoi(strings.TrimSpace(string(pidData)))
|
|
if err != nil {
|
|
return fmt.Errorf("unreadable PID in %s: %w", pidFile, err)
|
|
}
|
|
process, err := os.FindProcess(pid)
|
|
if err != nil {
|
|
return fmt.Errorf("no process %d from %s: %w", pid, pidFile, err)
|
|
}
|
|
if err := process.Signal(os.Interrupt); err != nil {
|
|
_ = os.Remove(pidFile)
|
|
ux.Logger.PrintToUser("PID %d from %s is already gone", pid, pidFile)
|
|
return nil
|
|
}
|
|
_ = os.Remove(pidFile)
|
|
ux.Logger.PrintToUser("Sent interrupt to PID %d", pid)
|
|
return nil
|
|
}
|