Skip to content

Commit

Permalink
Merge pull request #3702 from carlaKC/lnrpc-addcloseaddress
Browse files Browse the repository at this point in the history
Add optional close address
  • Loading branch information
wpaulino committed Dec 10, 2019
2 parents d01feb5 + 94d3eb6 commit 3c6be62
Show file tree
Hide file tree
Showing 11 changed files with 970 additions and 602 deletions.
8 changes: 4 additions & 4 deletions chancloser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var (
// a message while it is in an unknown state.
ErrInvalidState = fmt.Errorf("invalid state")

// errUpfrontShutdownScriptMismatch is returned when our peer sends us a
// shutdown message with a script that does not match the upfront shutdown
// script previously set.
errUpfrontShutdownScriptMismatch = fmt.Errorf("peer's shutdown " +
// errUpfrontShutdownScriptMismatch is returned when a peer or end user
// provides a script to cooperatively close out to which does not match
// the upfront shutdown script previously set for that party.
errUpfrontShutdownScriptMismatch = fmt.Errorf("shutdown " +
"script does not match upfront shutdown script")
)

Expand Down
23 changes: 18 additions & 5 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,16 @@ var closeChannelCommand = cli.Command{
transaction will be broadcast to the network. As a result, any settled
funds will be time locked for a few blocks before they can be spent.
In the case of a cooperative closure, One can manually set the fee to
In the case of a cooperative closure, one can manually set the fee to
be used for the closing transaction via either the --conf_target or
--sat_per_byte arguments. This will be the starting value used during
fee negotiation. This is optional.
In the case of a cooperative closure, one can manually set the address
to deliver funds to upon closure. This is optional, and may only be used
if an upfront shutdown address has not already been set. If neither are
set the funds will be delivered to a new wallet address.
To view which funding_txids/output_indexes can be used for a channel close,
see the channel_point values within the listchannels command output.
The format for a channel_point is 'funding_txid:output_index'.`,
Expand Down Expand Up @@ -874,6 +879,13 @@ var closeChannelCommand = cli.Command{
"sat/byte that should be used when crafting " +
"the transaction",
},
cli.StringFlag{
Name: "delivery_addr",
Usage: "(optional) an address to deliver funds " +
"upon cooperative channel closing, may only " +
"be used if an upfront shutdown addresss is not" +
"already set",
},
},
Action: actionDecorator(closeChannel),
}
Expand All @@ -895,10 +907,11 @@ func closeChannel(ctx *cli.Context) error {

// TODO(roasbeef): implement time deadline within server
req := &lnrpc.CloseChannelRequest{
ChannelPoint: channelPoint,
Force: ctx.Bool("force"),
TargetConf: int32(ctx.Int64("conf_target")),
SatPerByte: ctx.Int64("sat_per_byte"),
ChannelPoint: channelPoint,
Force: ctx.Bool("force"),
TargetConf: int32(ctx.Int64("conf_target")),
SatPerByte: ctx.Int64("sat_per_byte"),
DeliveryAddress: ctx.String("delivery_addr"),
}

// After parsing the request, we'll spin up a goroutine that will
Expand Down
17 changes: 11 additions & 6 deletions htlcswitch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ type ChanClose struct {
// process for the cooperative closure transaction kicks off.
TargetFeePerKw chainfee.SatPerKWeight

// DeliveryScript is an optional delivery script to pay funds out to.
DeliveryScript lnwire.DeliveryAddress

// Updates is used by request creator to receive the notifications about
// execution of the close channel request.
Updates chan interface{}
Expand Down Expand Up @@ -1365,12 +1368,13 @@ func (s *Switch) teardownCircuit(pkt *htlcPacket) error {
}

// CloseLink creates and sends the close channel command to the target link
// directing the specified closure type. If the closure type if CloseRegular,
// then the last parameter should be the ideal fee-per-kw that will be used as
// a starting point for close negotiation.
func (s *Switch) CloseLink(chanPoint *wire.OutPoint, closeType ChannelCloseType,
targetFeePerKw chainfee.SatPerKWeight) (chan interface{},
chan error) {
// directing the specified closure type. If the closure type is CloseRegular,
// targetFeePerKw parameter should be the ideal fee-per-kw that will be used as
// a starting point for close negotiation. The deliveryScript parameter is an
// optional parameter which sets a user specified script to close out to.
func (s *Switch) CloseLink(chanPoint *wire.OutPoint,
closeType ChannelCloseType, targetFeePerKw chainfee.SatPerKWeight,
deliveryScript lnwire.DeliveryAddress) (chan interface{}, chan error) {

// TODO(roasbeef) abstract out the close updates.
updateChan := make(chan interface{}, 2)
Expand All @@ -1381,6 +1385,7 @@ func (s *Switch) CloseLink(chanPoint *wire.OutPoint, closeType ChannelCloseType,
ChanPoint: chanPoint,
Updates: updateChan,
TargetFeePerKw: targetFeePerKw,
DeliveryScript: deliveryScript,
Err: errChan,
}

Expand Down
Loading

0 comments on commit 3c6be62

Please sign in to comment.