Skip to content

Commit dbe62e0

Browse files
committed
multi: add StopDaemon method to Lit
In this commit, a new Proxy service is added with a StopDaemon method. This method can be used to stop the Litd service. This will be useful in remote-mode itests where we want to restart Litd without also restarting LND. It also provides a nice way of shutting down Litd in remote-mode. A GetInfo method is also added to the service which for now just returns the Litd version. The reason for adding this method now is so that access to the new Proxy service can be tested in the itests withouth actually shutting down Litd.
1 parent cea367c commit dbe62e0

File tree

10 files changed

+663
-0
lines changed

10 files changed

+663
-0
lines changed

cmd/litcli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func main() {
7575
app.Commands = append(app.Commands, listActionsCommand)
7676
app.Commands = append(app.Commands, privacyMapCommands)
7777
app.Commands = append(app.Commands, autopilotCommands)
78+
app.Commands = append(app.Commands, litCommands...)
7879

7980
err := app.Run(os.Args)
8081
if err != nil {

cmd/litcli/proxy.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/lightninglabs/lightning-terminal/litrpc"
8+
"github.com/urfave/cli"
9+
)
10+
11+
var litCommands = []cli.Command{
12+
{
13+
Name: "stop",
14+
Usage: "shutdown the LiT daemon",
15+
Category: "LiT",
16+
Action: shutdownLit,
17+
},
18+
{
19+
Name: "getinfo",
20+
Usage: "Returns basic information related to the active " +
21+
"daemon.",
22+
Category: "LiT",
23+
Action: getInfo,
24+
},
25+
}
26+
27+
func getInfo(ctx *cli.Context) error {
28+
clientConn, cleanup, err := connectClient(ctx)
29+
if err != nil {
30+
return err
31+
}
32+
defer cleanup()
33+
client := litrpc.NewProxyClient(clientConn)
34+
35+
ctxb := context.Background()
36+
resp, err := client.GetInfo(ctxb, &litrpc.GetInfoRequest{})
37+
if err != nil {
38+
return err
39+
}
40+
41+
printRespJSON(resp)
42+
43+
return nil
44+
}
45+
46+
func shutdownLit(ctx *cli.Context) error {
47+
clientConn, cleanup, err := connectClient(ctx)
48+
if err != nil {
49+
return err
50+
}
51+
defer cleanup()
52+
client := litrpc.NewProxyClient(clientConn)
53+
54+
ctxb := context.Background()
55+
_, err = client.StopDaemon(ctxb, &litrpc.StopDaemonRequest{})
56+
if err != nil {
57+
return err
58+
}
59+
60+
fmt.Println("Successfully shutdown LiTd")
61+
62+
return nil
63+
}

itest/litd_mode_integrated_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ var (
161161
ctx, &litrpc.ListAutopilotFeaturesRequest{},
162162
)
163163
}
164+
proxyRequestFn = func(ctx context.Context,
165+
c grpc.ClientConnInterface) (proto.Message, error) {
166+
167+
litConn := litrpc.NewProxyClient(c)
168+
return litConn.GetInfo(ctx, &litrpc.GetInfoRequest{})
169+
}
164170
litMacaroonFn = func(cfg *LitNodeConfig) string {
165171
return cfg.LitMacPath
166172
}
@@ -247,6 +253,13 @@ var (
247253
successPattern: "\"features\":{",
248254
allowedThroughLNC: true,
249255
grpcWebURI: "/litrpc.Autopilot/ListAutopilotFeatures",
256+
}, {
257+
name: "litrpc-proxy",
258+
macaroonFn: litMacaroonFn,
259+
requestFn: proxyRequestFn,
260+
successPattern: "\"version\":",
261+
allowedThroughLNC: false,
262+
grpcWebURI: "/litrpc.Proxy/GetInfo",
250263
}}
251264

252265
// customURIs is a map of endpoint URIs that we want to allow via a

0 commit comments

Comments
 (0)