diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 4050d700f..4dca4f8aa 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -106,6 +106,12 @@ type ChanClose struct { // process for the cooperative closure transaction kicks off. TargetFeePerKw chainfee.SatPerKWeight + // MaxFee is the highest fee the caller is willing to pay. + // + // NOTE: This field is only respected if the caller is the initiator of + // the channel. + MaxFee chainfee.SatPerKWeight + // DeliveryScript is an optional delivery script to pay funds out to. DeliveryScript lnwire.DeliveryAddress @@ -1656,7 +1662,7 @@ func (s *Switch) teardownCircuit(pkt *htlcPacket) error { // optional parameter which sets a user specified script to close out to. func (s *Switch) CloseLink(chanPoint *wire.OutPoint, closeType contractcourt.ChannelCloseType, - targetFeePerKw chainfee.SatPerKWeight, + targetFeePerKw, maxFee chainfee.SatPerKWeight, deliveryScript lnwire.DeliveryAddress) (chan interface{}, chan error) { // TODO(roasbeef) abstract out the close updates. @@ -1668,6 +1674,7 @@ func (s *Switch) CloseLink(chanPoint *wire.OutPoint, ChanPoint: chanPoint, Updates: updateChan, TargetFeePerKw: targetFeePerKw, + MaxFee: maxFee, DeliveryScript: deliveryScript, Err: errChan, } diff --git a/peer/brontide.go b/peer/brontide.go index 83ee6f39c..ea6396f08 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -2697,6 +2697,12 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel, return nil, fmt.Errorf("cannot obtain best block") } + // The req will only be set if we initaited the co-op closing flow. + var maxFee chainfee.SatPerKWeight + if req != nil { + maxFee = req.MaxFee + } + chanCloser := chancloser.NewChanCloser( chancloser.ChanCloseCfg{ Channel: channel, @@ -2706,6 +2712,7 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel, op, false, ) }, + MaxFee: maxFee, Disconnect: func() error { return p.cfg.DisconnectPeer(p.IdentityKey()) }, diff --git a/rpcserver.go b/rpcserver.go index e8ae1c0b9..e20011446 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2508,9 +2508,12 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, } } + maxFee := chainfee.SatPerKVByte( + in.MaxFeePerVbyte * 1000, + ).FeePerKWeight() updateChan, errChan = r.server.htlcSwitch.CloseLink( chanPoint, contractcourt.CloseRegular, feeRate, - deliveryScript, + maxFee, deliveryScript, ) } out: diff --git a/server.go b/server.go index fef25b1dc..990c02352 100644 --- a/server.go +++ b/server.go @@ -1034,7 +1034,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, // Instruct the switch to close the channel. Provide no close out // delivery script or target fee per kw because user input is not // available when the remote peer closes the channel. - s.htlcSwitch.CloseLink(chanPoint, closureType, 0, nil) + s.htlcSwitch.CloseLink(chanPoint, closureType, 0, 0, nil) } // We will use the following channel to reliably hand off contract