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: ability to mark a session as borked #7545

Closed
48 changes: 47 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 @@ -24,6 +25,7 @@ func wtclientCommands() []cli.Command {
getTowerCommand,
statsCommand,
policyCommand,
sessionCommand,
},
},
}
Expand Down Expand Up @@ -325,3 +327,47 @@ func policy(ctx *cli.Context) error {
printRespJSON(resp)
return nil
}

var sessionCommand = cli.Command{
Name: "session",
Subcommands: []cli.Command{
markSessionBorkedCommand,
},
}

var markSessionBorkedCommand = cli.Command{
Name: "mark-borked",
ArgsUsage: "session-id",
Action: actionDecorator(markSessionBorked),
}

func markSessionBorked(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, "mark-borked")
}

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

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

req := &wtclientrpc.MarkSessionBorkedRequest{
SessionId: sessionID,
}

resp, err := client.MarkSessionBorked(ctxc, req)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}
2 changes: 2 additions & 0 deletions docs/release-notes/release-notes-0.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
queue](https://github.com/lightningnetwork/lnd/pull/7380)
* [Replay pending and un-acked updates onto the main task pipeline if a tower
is being removed](https://github.com/lightningnetwork/lnd/pull/6895)
* Add the ability to [mark a session as
borked](https://github.com/lightningnetwork/lnd/pull/7545)

* [Add defaults](https://github.com/lightningnetwork/lnd/pull/7771) to the
wtclient and watchtower config structs and use these to populate the defaults
Expand Down
25 changes: 25 additions & 0 deletions lnrpc/wtclientrpc/watchtowerclient.pb.json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions lnrpc/wtclientrpc/wtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ var (
Entity: "offchain",
Action: "read",
}},
"/wtclientrpc.WatchtowerClient/MarkSessionBorked": {{
Entity: "offchain",
Action: "write",
}},
}

// ErrWtclientNotActive signals that RPC calls cannot be processed
Expand Down Expand Up @@ -483,6 +487,35 @@ func (c *WatchtowerClient) Policy(ctx context.Context,
}, nil
}

// MarkSessionBorked will set the status of the given session to Borked so that
// the session is not used for any future updates.
func (c *WatchtowerClient) MarkSessionBorked(_ context.Context,
req *MarkSessionBorkedRequest) (*MarkSessionBorkedResponse, error) {

if err := c.isActive(); err != nil {
return nil, err
}

pubKey, err := btcec.ParsePubKey(req.SessionId)
if err != nil {
return nil, err
}

sessionID := wtdb.NewSessionIDFromPubKey(pubKey)

err = c.cfg.Client.MarkSessionBorked(&sessionID)
if err != nil {
return nil, err
}

err = c.cfg.AnchorClient.MarkSessionBorked(&sessionID)
if err != nil {
return nil, err
}

return &MarkSessionBorkedResponse{}, nil
}

// marshallTower converts a client registered watchtower into its corresponding
// RPC type.
func marshallTower(tower *wtclient.RegisteredTower, policyType PolicyType,
Expand Down
Loading