peer: refactor createChanCloser to use ChannelParty

This commit is contained in:
Keagan McClelland
2024-07-30 17:03:47 -07:00
parent 0996e4f163
commit 1d65f5bd12

View File

@ -1070,7 +1070,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
chanCloser, err := p.createChanCloser( chanCloser, err := p.createChanCloser(
lnChan, info.DeliveryScript.Val, feePerKw, nil, lnChan, info.DeliveryScript.Val, feePerKw, nil,
info.LocalInitiator.Val, info.Closer(),
) )
if err != nil { if err != nil {
shutdownInfoErr = fmt.Errorf("unable to "+ shutdownInfoErr = fmt.Errorf("unable to "+
@ -2733,7 +2733,7 @@ func (p *Brontide) fetchActiveChanCloser(chanID lnwire.ChannelID) (
} }
chanCloser, err = p.createChanCloser( chanCloser, err = p.createChanCloser(
channel, deliveryScript, feePerKw, nil, false, channel, deliveryScript, feePerKw, nil, lntypes.Remote,
) )
if err != nil { if err != nil {
p.log.Errorf("unable to create chan closer: %v", err) p.log.Errorf("unable to create chan closer: %v", err)
@ -2970,12 +2970,13 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
// Determine whether we or the peer are the initiator of the coop // Determine whether we or the peer are the initiator of the coop
// close attempt by looking at the channel's status. // close attempt by looking at the channel's status.
locallyInitiated := c.HasChanStatus( closingParty := lntypes.Remote
channeldb.ChanStatusLocalCloseInitiator, if c.HasChanStatus(channeldb.ChanStatusLocalCloseInitiator) {
) closingParty = lntypes.Local
}
chanCloser, err := p.createChanCloser( chanCloser, err := p.createChanCloser(
lnChan, deliveryScript, feePerKw, nil, locallyInitiated, lnChan, deliveryScript, feePerKw, nil, closingParty,
) )
if err != nil { if err != nil {
p.log.Errorf("unable to create chan closer: %v", err) p.log.Errorf("unable to create chan closer: %v", err)
@ -3004,7 +3005,7 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel, func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
deliveryScript lnwire.DeliveryAddress, fee chainfee.SatPerKWeight, deliveryScript lnwire.DeliveryAddress, fee chainfee.SatPerKWeight,
req *htlcswitch.ChanClose, req *htlcswitch.ChanClose,
locallyInitiated bool) (*chancloser.ChanCloser, error) { closer lntypes.ChannelParty) (*chancloser.ChanCloser, error) {
_, startingHeight, err := p.cfg.ChainIO.GetBestBlock() _, startingHeight, err := p.cfg.ChainIO.GetBestBlock()
if err != nil { if err != nil {
@ -3018,10 +3019,6 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
maxFee = req.MaxFee maxFee = req.MaxFee
} }
closer := lntypes.Remote
if locallyInitiated {
closer = lntypes.Local
}
chanCloser := chancloser.NewChanCloser( chanCloser := chancloser.NewChanCloser(
chancloser.ChanCloseCfg{ chancloser.ChanCloseCfg{
Channel: channel, Channel: channel,
@ -3101,7 +3098,8 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
} }
chanCloser, err := p.createChanCloser( chanCloser, err := p.createChanCloser(
channel, deliveryScript, req.TargetFeePerKw, req, true, channel, deliveryScript, req.TargetFeePerKw, req,
lntypes.Local,
) )
if err != nil { if err != nil {
p.log.Errorf(err.Error()) p.log.Errorf(err.Error())