Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wtclient: add DeactivateTower and TerminateSession commands #8239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 86 additions & 1 deletion cmd/lncli/wtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"github.com/urfave/cli"
)

// wtclientCommands will return nil for non-wtclientrpc builds.
// wtclientCommands is a list of commands that can be used to interact with the
// watchtower client.
func wtclientCommands() []cli.Command {
return []cli.Command{
{
Expand All @@ -20,10 +21,12 @@ func wtclientCommands() []cli.Command {
Subcommands: []cli.Command{
addTowerCommand,
removeTowerCommand,
deactivateTowerCommand,
listTowersCommand,
getTowerCommand,
statsCommand,
policyCommand,
sessionCommands,
},
},
}
Expand Down Expand Up @@ -84,6 +87,44 @@ func addTower(ctx *cli.Context) error {
return nil
}

var deactivateTowerCommand = cli.Command{
Name: "deactivate",
Usage: "Deactivate a watchtower to temporarily prevent its use for " +
"sessions/backups.",
ArgsUsage: "pubkey",
Action: actionDecorator(deactivateTower),
}

func deactivateTower(ctx *cli.Context) error {
ctxc := getContext()

// Display the command's help message if the number of arguments/flags
// is not what we expect.
if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
return cli.ShowCommandHelp(ctx, "deactivate")
}

pubKey, err := hex.DecodeString(ctx.Args().First())
if err != nil {
return fmt.Errorf("invalid public key: %w", err)
}

client, cleanUp := getWtclient(ctx)
defer cleanUp()

req := &wtclientrpc.DeactivateTowerRequest{
Pubkey: pubKey,
}
resp, err := client.DeactivateTower(ctxc, req)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

var removeTowerCommand = cli.Command{
Name: "remove",
Usage: "Remove a watchtower to prevent its use for future " +
Expand Down Expand Up @@ -333,3 +374,47 @@ func policy(ctx *cli.Context) error {
printRespJSON(resp)
return nil
}

var sessionCommands = cli.Command{
Name: "session",
Subcommands: []cli.Command{
terminateSessionCommand,
},
}

var terminateSessionCommand = cli.Command{
Name: "terminate",
ArgsUsage: "id",
Action: actionDecorator(terminateSession),
}

func terminateSession(ctx *cli.Context) error {
ctxc := getContext()

// Display the command's help message if the number of arguments/flags
// is not what we expect.
if ctx.NArg() > 1 || ctx.NumFlags() != 0 {
return cli.ShowCommandHelp(ctx, "terminate")
}

client, cleanUp := getWtclient(ctx)
defer cleanUp()

sessionID, err := hex.DecodeString(ctx.Args().First())
if err != nil {
return fmt.Errorf("invalid session ID: %w", err)
}

resp, err := client.TerminateSession(
ctxc, &wtclientrpc.TerminateSessionRequest{
SessionId: sessionID,
},
)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}
7 changes: 7 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
about the txid and don't want the calling code to block while the channel
drains the active HTLCs.

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

## lncli Additions

* Deprecate `bumpclosefee` for `bumpforceclosefee` to accommodate for the fact
Expand Down
12 changes: 2 additions & 10 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,8 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testLookupHtlcResolution,
},
{
Name: "watchtower session management",
TestFunc: testWatchtowerSessionManagement,
},
{
// NOTE: this test must be put in the same tranche as
// `testWatchtowerSessionManagement` to avoid parallel use of
// the default watchtower port.
Name: "revoked uncooperative close retribution altruist " +
"watchtower",
TestFunc: testRevokedCloseRetributionAltruistWatchtower,
Name: "watchtower",
TestFunc: testWatchtower,
},
{
Name: "channel fundmax",
Expand Down