Skip to content

Commit c398b0c

Browse files
authored
Merge pull request #8239 from ellemouton/loadSessionByActiveTower
wtclient: add DeactivateTower and TerminateSession commands
2 parents e53f7c1 + a3ccae9 commit c398b0c

24 files changed

+2728
-759
lines changed

cmd/lncli/wtclient.go

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
"github.com/urfave/cli"
1111
)
1212

13-
// wtclientCommands will return nil for non-wtclientrpc builds.
13+
// wtclientCommands is a list of commands that can be used to interact with the
14+
// watchtower client.
1415
func wtclientCommands() []cli.Command {
1516
return []cli.Command{
1617
{
@@ -20,10 +21,12 @@ func wtclientCommands() []cli.Command {
2021
Subcommands: []cli.Command{
2122
addTowerCommand,
2223
removeTowerCommand,
24+
deactivateTowerCommand,
2325
listTowersCommand,
2426
getTowerCommand,
2527
statsCommand,
2628
policyCommand,
29+
sessionCommands,
2730
},
2831
},
2932
}
@@ -84,6 +87,44 @@ func addTower(ctx *cli.Context) error {
8487
return nil
8588
}
8689

90+
var deactivateTowerCommand = cli.Command{
91+
Name: "deactivate",
92+
Usage: "Deactivate a watchtower to temporarily prevent its use for " +
93+
"sessions/backups.",
94+
ArgsUsage: "pubkey",
95+
Action: actionDecorator(deactivateTower),
96+
}
97+
98+
func deactivateTower(ctx *cli.Context) error {
99+
ctxc := getContext()
100+
101+
// Display the command's help message if the number of arguments/flags
102+
// is not what we expect.
103+
if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
104+
return cli.ShowCommandHelp(ctx, "deactivate")
105+
}
106+
107+
pubKey, err := hex.DecodeString(ctx.Args().First())
108+
if err != nil {
109+
return fmt.Errorf("invalid public key: %w", err)
110+
}
111+
112+
client, cleanUp := getWtclient(ctx)
113+
defer cleanUp()
114+
115+
req := &wtclientrpc.DeactivateTowerRequest{
116+
Pubkey: pubKey,
117+
}
118+
resp, err := client.DeactivateTower(ctxc, req)
119+
if err != nil {
120+
return err
121+
}
122+
123+
printRespJSON(resp)
124+
125+
return nil
126+
}
127+
87128
var removeTowerCommand = cli.Command{
88129
Name: "remove",
89130
Usage: "Remove a watchtower to prevent its use for future " +
@@ -333,3 +374,47 @@ func policy(ctx *cli.Context) error {
333374
printRespJSON(resp)
334375
return nil
335376
}
377+
378+
var sessionCommands = cli.Command{
379+
Name: "session",
380+
Subcommands: []cli.Command{
381+
terminateSessionCommand,
382+
},
383+
}
384+
385+
var terminateSessionCommand = cli.Command{
386+
Name: "terminate",
387+
ArgsUsage: "id",
388+
Action: actionDecorator(terminateSession),
389+
}
390+
391+
func terminateSession(ctx *cli.Context) error {
392+
ctxc := getContext()
393+
394+
// Display the command's help message if the number of arguments/flags
395+
// is not what we expect.
396+
if ctx.NArg() > 1 || ctx.NumFlags() != 0 {
397+
return cli.ShowCommandHelp(ctx, "terminate")
398+
}
399+
400+
client, cleanUp := getWtclient(ctx)
401+
defer cleanUp()
402+
403+
sessionID, err := hex.DecodeString(ctx.Args().First())
404+
if err != nil {
405+
return fmt.Errorf("invalid session ID: %w", err)
406+
}
407+
408+
resp, err := client.TerminateSession(
409+
ctxc, &wtclientrpc.TerminateSessionRequest{
410+
SessionId: sessionID,
411+
},
412+
)
413+
if err != nil {
414+
return err
415+
}
416+
417+
printRespJSON(resp)
418+
419+
return nil
420+
}

docs/release-notes/release-notes-0.18.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@
155155
about the txid and don't want the calling code to block while the channel
156156
drains the active HTLCs.
157157

158+
* [New watchtower client DeactivateTower and
159+
TerminateSession](https://github.com/lightningnetwork/lnd/pull/8239) commands
160+
have been added. The DeactivateTower command can be used to mark a tower as
161+
inactive so that its sessions are not loaded on startup and so that the tower
162+
is not considered for session negotiation. TerminateSession can be used to
163+
mark a specific session as terminal so that that specific is never used again.
164+
158165
## lncli Additions
159166

160167
* Deprecate `bumpclosefee` for `bumpforceclosefee` to accommodate for the fact

itest/list_on_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,8 @@ var allTestCases = []*lntest.TestCase{
519519
TestFunc: testLookupHtlcResolution,
520520
},
521521
{
522-
Name: "watchtower session management",
523-
TestFunc: testWatchtowerSessionManagement,
524-
},
525-
{
526-
// NOTE: this test must be put in the same tranche as
527-
// `testWatchtowerSessionManagement` to avoid parallel use of
528-
// the default watchtower port.
529-
Name: "revoked uncooperative close retribution altruist " +
530-
"watchtower",
531-
TestFunc: testRevokedCloseRetributionAltruistWatchtower,
522+
Name: "watchtower",
523+
TestFunc: testWatchtower,
532524
},
533525
{
534526
Name: "channel fundmax",

0 commit comments

Comments
 (0)