Skip to content

Commit

Permalink
Merge pull request #3809 from joostjager/anchor-sweeper
Browse files Browse the repository at this point in the history
sweep: allow force sweeping of negatively yielding inputs
  • Loading branch information
joostjager authored Jan 23, 2020
2 parents f8418ab + b0aae13 commit ae9c6fa
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 146 deletions.
31 changes: 15 additions & 16 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"context"
"fmt"
"sort"

"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
Expand Down Expand Up @@ -113,7 +112,13 @@ var bumpFeeCommand = cli.Command{
Note that this command currently doesn't perform any validation checks
on the fee preference being provided. For now, the responsibility of
ensuring that the new fee preference is sufficient is delegated to the
user.`,
user.
The force flag enables sweeping of inputs that are negatively yielding.
Normally it does not make sense to lose money on sweeping, unless a
parent transaction needs to get confirmed and there is only a small
output available to attach the child transaction to.
`,
Flags: []cli.Flag{
cli.Uint64Flag{
Name: "conf_target",
Expand All @@ -125,14 +130,18 @@ var bumpFeeCommand = cli.Command{
Usage: "a manual fee expressed in sat/byte that " +
"should be used when sweeping the output",
},
cli.BoolFlag{
Name: "force",
Usage: "sweep even if the yield is negative",
},
},
Action: actionDecorator(bumpFee),
}

func bumpFee(ctx *cli.Context) error {
// Display the command's help message if we do not have the expected
// number of arguments/flags.
if ctx.NArg() != 1 || ctx.NumFlags() != 1 {
if ctx.NArg() != 1 {
return cli.ShowCommandHelp(ctx, "bumpfee")
}

Expand All @@ -142,24 +151,14 @@ func bumpFee(ctx *cli.Context) error {
return err
}

var confTarget, satPerByte uint32
switch {
case ctx.IsSet("conf_target") && ctx.IsSet("sat_per_byte"):
return fmt.Errorf("either conf_target or sat_per_byte should " +
"be set, but not both")
case ctx.IsSet("conf_target"):
confTarget = uint32(ctx.Uint64("conf_target"))
case ctx.IsSet("sat_per_byte"):
satPerByte = uint32(ctx.Uint64("sat_per_byte"))
}

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

resp, err := client.BumpFee(context.Background(), &walletrpc.BumpFeeRequest{
Outpoint: protoOutPoint,
TargetConf: confTarget,
SatPerByte: satPerByte,
TargetConf: uint32(ctx.Uint64("conf_target")),
SatPerByte: uint32(ctx.Uint64("sat_per_byte")),
Force: ctx.Bool("force"),
})
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/lncli/walletrpc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type PendingSweep struct {
SatPerByte uint32 `json:"sat_per_byte"`
BroadcastAttempts uint32 `json:"broadcast_attempts"`
NextBroadcastHeight uint32 `json:"next_broadcast_height"`
RequestedSatPerByte uint32 `json:"requested_sat_per_byte"`
RequestedConfTarget uint32 `json:"requested_conf_target"`
Force bool `json:"force"`
}

// NewPendingSweepFromProto converts the walletrpc.PendingSweep proto type into
Expand All @@ -23,5 +26,8 @@ func NewPendingSweepFromProto(pendingSweep *walletrpc.PendingSweep) *PendingSwee
SatPerByte: pendingSweep.SatPerByte,
BroadcastAttempts: pendingSweep.BroadcastAttempts,
NextBroadcastHeight: pendingSweep.NextBroadcastHeight,
RequestedSatPerByte: pendingSweep.RequestedSatPerByte,
RequestedConfTarget: pendingSweep.RequestedConfTarget,
Force: pendingSweep.Force,
}
}
172 changes: 108 additions & 64 deletions lnrpc/walletrpc/walletkit.pb.go

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

18 changes: 18 additions & 0 deletions lnrpc/walletrpc/walletkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ message PendingSweep {
sweep transaction of the output.
*/
uint32 next_broadcast_height = 6 [json_name = "next_broadcast_height"];

// The requested confirmation target for this output.
uint32 requested_conf_target = 8 [json_name = "requested_conf_target"];

// The requested fee rate, expressed in sat/byte, for this output.
uint32 requested_sat_per_byte = 9 [json_name = "requested_sat_per_byte"];

/**
Whether this input must be force-swept. This means that it is swept even
if it has a negative yield.
*/
bool force = 7 [json_name = "force"];
}

message PendingSweepsRequest {
Expand All @@ -215,6 +227,12 @@ message BumpFeeRequest {
with.
*/
uint32 sat_per_byte = 3 [json_name = "sat_per_byte"];

/**
Whether this input must be force-swept. This means that it is swept even
if it has a negative yield.
*/
bool force = 4 [json_name = "force"];
}

message BumpFeeResponse {
Expand Down
Loading

0 comments on commit ae9c6fa

Please sign in to comment.