Skip to content

Commit 1d65f5b

Browse files
committed
peer: refactor createChanCloser to use ChannelParty
1 parent 0996e4f commit 1d65f5b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

peer/brontide.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
10701070

10711071
chanCloser, err := p.createChanCloser(
10721072
lnChan, info.DeliveryScript.Val, feePerKw, nil,
1073-
info.LocalInitiator.Val,
1073+
info.Closer(),
10741074
)
10751075
if err != nil {
10761076
shutdownInfoErr = fmt.Errorf("unable to "+
@@ -2733,7 +2733,7 @@ func (p *Brontide) fetchActiveChanCloser(chanID lnwire.ChannelID) (
27332733
}
27342734

27352735
chanCloser, err = p.createChanCloser(
2736-
channel, deliveryScript, feePerKw, nil, false,
2736+
channel, deliveryScript, feePerKw, nil, lntypes.Remote,
27372737
)
27382738
if err != nil {
27392739
p.log.Errorf("unable to create chan closer: %v", err)
@@ -2970,12 +2970,13 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
29702970

29712971
// Determine whether we or the peer are the initiator of the coop
29722972
// close attempt by looking at the channel's status.
2973-
locallyInitiated := c.HasChanStatus(
2974-
channeldb.ChanStatusLocalCloseInitiator,
2975-
)
2973+
closingParty := lntypes.Remote
2974+
if c.HasChanStatus(channeldb.ChanStatusLocalCloseInitiator) {
2975+
closingParty = lntypes.Local
2976+
}
29762977

29772978
chanCloser, err := p.createChanCloser(
2978-
lnChan, deliveryScript, feePerKw, nil, locallyInitiated,
2979+
lnChan, deliveryScript, feePerKw, nil, closingParty,
29792980
)
29802981
if err != nil {
29812982
p.log.Errorf("unable to create chan closer: %v", err)
@@ -3004,7 +3005,7 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
30043005
func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
30053006
deliveryScript lnwire.DeliveryAddress, fee chainfee.SatPerKWeight,
30063007
req *htlcswitch.ChanClose,
3007-
locallyInitiated bool) (*chancloser.ChanCloser, error) {
3008+
closer lntypes.ChannelParty) (*chancloser.ChanCloser, error) {
30083009

30093010
_, startingHeight, err := p.cfg.ChainIO.GetBestBlock()
30103011
if err != nil {
@@ -3018,10 +3019,6 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
30183019
maxFee = req.MaxFee
30193020
}
30203021

3021-
closer := lntypes.Remote
3022-
if locallyInitiated {
3023-
closer = lntypes.Local
3024-
}
30253022
chanCloser := chancloser.NewChanCloser(
30263023
chancloser.ChanCloseCfg{
30273024
Channel: channel,
@@ -3101,7 +3098,8 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
31013098
}
31023099

31033100
chanCloser, err := p.createChanCloser(
3104-
channel, deliveryScript, req.TargetFeePerKw, req, true,
3101+
channel, deliveryScript, req.TargetFeePerKw, req,
3102+
lntypes.Local,
31053103
)
31063104
if err != nil {
31073105
p.log.Errorf(err.Error())

0 commit comments

Comments
 (0)