mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
cli: add command "loop stop"
* add StopDaemon RPC with permissions + REST binding * expose `loop stop` CLI (with optional --wait) and wait logic * pass daemon shutdown callback + unit test and regenerate docs/protos
This commit is contained in:
parent
c4d6c29fc0
commit
a4dc59099b
15 changed files with 1997 additions and 1532 deletions
|
|
@ -746,6 +746,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
withdrawalManager: withdrawalManager,
|
||||
staticLoopInManager: staticLoopInManager,
|
||||
assetClient: d.assetClient,
|
||||
stopDaemon: d.Stop,
|
||||
}
|
||||
|
||||
// Retrieve all currently existing swaps from the database.
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ type swapClientServer struct {
|
|||
nextSubscriberID int
|
||||
swapsLock sync.Mutex
|
||||
mainCtx context.Context
|
||||
|
||||
// stopDaemon is invoked to trigger a graceful shutdown of the daemon.
|
||||
stopDaemon func()
|
||||
}
|
||||
|
||||
// LoopOut initiates a loop out swap with the given parameters. The call returns
|
||||
|
|
@ -1346,6 +1349,22 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
|
|||
}, nil
|
||||
}
|
||||
|
||||
// StopDaemon triggers a graceful shutdown of the daemon process.
|
||||
func (s *swapClientServer) StopDaemon(ctx context.Context,
|
||||
_ *looprpc.StopDaemonRequest) (*looprpc.StopDaemonResponse, error) {
|
||||
|
||||
// Ensure we have a shutdown handler to invoke.
|
||||
if s.stopDaemon == nil {
|
||||
return nil, status.Error(codes.Unimplemented,
|
||||
"stop daemon not supported")
|
||||
}
|
||||
|
||||
// Initiate the shutdown sequence.
|
||||
s.stopDaemon()
|
||||
|
||||
return &looprpc.StopDaemonResponse{}, nil
|
||||
}
|
||||
|
||||
// GetLiquidityParams gets our current liquidity manager's parameters.
|
||||
func (s *swapClientServer) GetLiquidityParams(_ context.Context,
|
||||
_ *looprpc.GetLiquidityParamsRequest) (*looprpc.LiquidityParameters,
|
||||
|
|
|
|||
|
|
@ -261,6 +261,29 @@ func TestValidateLoopInRequest(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestSwapClientServerStopDaemon ensures that calling StopDaemon triggers the
|
||||
// daemon shutdown.
|
||||
func TestSwapClientServerStopDaemon(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Prepare a server instance that tracks whether shutdown is requested.
|
||||
var stopCalled bool
|
||||
server := &swapClientServer{
|
||||
stopDaemon: func() {
|
||||
stopCalled = true
|
||||
},
|
||||
}
|
||||
|
||||
// Request the daemon to stop and assert the callback executed.
|
||||
_, err := server.StopDaemon(
|
||||
context.Background(), &looprpc.StopDaemonRequest{},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure our shutdown callback executed.
|
||||
require.True(t, stopCalled)
|
||||
}
|
||||
|
||||
// TestValidateLoopOutRequest tests validation of loop out requests.
|
||||
func TestValidateLoopOutRequest(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue