Skip to content

Commit 1e556aa

Browse files
committed
multi: thread through the new max fee field for co-op close
In this commit, we parse the new max fee field, and pass it through the switch, all the way to the peer where it's ultimately passed into the chan closer state machine.
1 parent c791b18 commit 1e556aa

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

htlcswitch/switch.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ type ChanClose struct {
106106
// process for the cooperative closure transaction kicks off.
107107
TargetFeePerKw chainfee.SatPerKWeight
108108

109+
// MaxFee is the highest fee the caller is willing to pay.
110+
//
111+
// NOTE: This field is only respected if the caller is the initiator of
112+
// the channel.
113+
MaxFee chainfee.SatPerKWeight
114+
109115
// DeliveryScript is an optional delivery script to pay funds out to.
110116
DeliveryScript lnwire.DeliveryAddress
111117

@@ -1656,7 +1662,7 @@ func (s *Switch) teardownCircuit(pkt *htlcPacket) error {
16561662
// optional parameter which sets a user specified script to close out to.
16571663
func (s *Switch) CloseLink(chanPoint *wire.OutPoint,
16581664
closeType contractcourt.ChannelCloseType,
1659-
targetFeePerKw chainfee.SatPerKWeight,
1665+
targetFeePerKw, maxFee chainfee.SatPerKWeight,
16601666
deliveryScript lnwire.DeliveryAddress) (chan interface{}, chan error) {
16611667

16621668
// TODO(roasbeef) abstract out the close updates.
@@ -1668,6 +1674,7 @@ func (s *Switch) CloseLink(chanPoint *wire.OutPoint,
16681674
ChanPoint: chanPoint,
16691675
Updates: updateChan,
16701676
TargetFeePerKw: targetFeePerKw,
1677+
MaxFee: maxFee,
16711678
DeliveryScript: deliveryScript,
16721679
Err: errChan,
16731680
}

peer/brontide.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,12 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
26972697
return nil, fmt.Errorf("cannot obtain best block")
26982698
}
26992699

2700+
// The req will only be set if we initaited the co-op closing flow.
2701+
var maxFee chainfee.SatPerKWeight
2702+
if req != nil {
2703+
maxFee = req.MaxFee
2704+
}
2705+
27002706
chanCloser := chancloser.NewChanCloser(
27012707
chancloser.ChanCloseCfg{
27022708
Channel: channel,
@@ -2706,6 +2712,7 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
27062712
op, false,
27072713
)
27082714
},
2715+
MaxFee: maxFee,
27092716
Disconnect: func() error {
27102717
return p.cfg.DisconnectPeer(p.IdentityKey())
27112718
},

rpcserver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,9 +2508,12 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
25082508
}
25092509
}
25102510

2511+
maxFee := chainfee.SatPerKVByte(
2512+
in.MaxFeePerVbyte * 1000,
2513+
).FeePerKWeight()
25112514
updateChan, errChan = r.server.htlcSwitch.CloseLink(
25122515
chanPoint, contractcourt.CloseRegular, feeRate,
2513-
deliveryScript,
2516+
maxFee, deliveryScript,
25142517
)
25152518
}
25162519
out:

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
10341034
// Instruct the switch to close the channel. Provide no close out
10351035
// delivery script or target fee per kw because user input is not
10361036
// available when the remote peer closes the channel.
1037-
s.htlcSwitch.CloseLink(chanPoint, closureType, 0, nil)
1037+
s.htlcSwitch.CloseLink(chanPoint, closureType, 0, 0, nil)
10381038
}
10391039

10401040
// We will use the following channel to reliably hand off contract

0 commit comments

Comments
 (0)