funding: properly pass in channel state as argument of closure in Start
This commit is contained in:
parent
a3cd248404
commit
6e3d231619
@ -472,41 +472,31 @@ func (f *fundingManager) Start() error {
|
|||||||
// successfully send the fundingLocked message to the
|
// successfully send the fundingLocked message to the
|
||||||
// peer, so let's do that now.
|
// peer, so let's do that now.
|
||||||
f.wg.Add(1)
|
f.wg.Add(1)
|
||||||
go func() {
|
go func(dbChan *channeldb.OpenChannel) {
|
||||||
defer f.wg.Done()
|
defer f.wg.Done()
|
||||||
|
|
||||||
err := f.handleFundingConfirmation(channel, shortChanID)
|
err := f.handleFundingConfirmation(dbChan, shortChanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fndgLog.Errorf("failed to handle funding"+
|
fndgLog.Errorf("failed to handle funding"+
|
||||||
"confirmation: %v", err)
|
"confirmation: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}(channel)
|
||||||
|
|
||||||
case fundingLockedSent:
|
case fundingLockedSent:
|
||||||
// fundingLocked was sent to peer, but the channel
|
// fundingLocked was sent to peer, but the channel
|
||||||
// announcement was not sent.
|
// announcement was not sent.
|
||||||
f.wg.Add(1)
|
f.wg.Add(1)
|
||||||
go func() {
|
go func(dbChan *channeldb.OpenChannel) {
|
||||||
defer f.wg.Done()
|
defer f.wg.Done()
|
||||||
|
|
||||||
lnChannel, err := lnwallet.NewLightningChannel(
|
err = f.sendChannelAnnouncement(dbChan, shortChanID)
|
||||||
nil, nil, f.cfg.FeeEstimator, channel)
|
|
||||||
if err != nil {
|
|
||||||
fndgLog.Errorf("error creating "+
|
|
||||||
"lightning channel: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer lnChannel.Stop()
|
|
||||||
|
|
||||||
err = f.sendChannelAnnouncement(channel, lnChannel,
|
|
||||||
shortChanID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fndgLog.Errorf("error sending channel "+
|
fndgLog.Errorf("error sending channel "+
|
||||||
"announcement: %v", err)
|
"announcement: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}(channel)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fndgLog.Errorf("undefined channelState: %v",
|
fndgLog.Errorf("undefined channelState: %v",
|
||||||
@ -760,7 +750,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// port with default advertised port
|
// port with default advertised port
|
||||||
chainHash := chainhash.Hash(msg.ChainHash)
|
chainHash := chainhash.Hash(msg.ChainHash)
|
||||||
reservation, err := f.cfg.Wallet.InitChannelReservation(amt, 0,
|
reservation, err := f.cfg.Wallet.InitChannelReservation(amt, 0,
|
||||||
msg.PushAmount, btcutil.Amount(msg.FeePerKiloWeight),
|
msg.PushAmount, btcutil.Amount(msg.FeePerKiloWeight), 0,
|
||||||
fmsg.peerAddress.IdentityKey, fmsg.peerAddress.Address,
|
fmsg.peerAddress.IdentityKey, fmsg.peerAddress.Address,
|
||||||
&chainHash)
|
&chainHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1512,7 +1502,10 @@ func (f *fundingManager) handleFundingConfirmation(completeChan *channeldb.OpenC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer lnChannel.Stop()
|
defer func() {
|
||||||
|
lnChannel.Stop()
|
||||||
|
lnChannel.CancelObserver()
|
||||||
|
}()
|
||||||
|
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
|
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
|
||||||
|
|
||||||
@ -1522,7 +1515,7 @@ func (f *fundingManager) handleFundingConfirmation(completeChan *channeldb.OpenC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed sending fundingLocked: %v", err)
|
return fmt.Errorf("failed sending fundingLocked: %v", err)
|
||||||
}
|
}
|
||||||
err = f.sendChannelAnnouncement(completeChan, lnChannel, shortChanID)
|
err = f.sendChannelAnnouncement(completeChan, shortChanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed sending channel announcement: %v",
|
return fmt.Errorf("failed sending channel announcement: %v",
|
||||||
err)
|
err)
|
||||||
@ -1605,7 +1598,7 @@ func (f *fundingManager) sendFundingLocked(completeChan *channeldb.OpenChannel,
|
|||||||
// is sent (channelState is 'fundingLockedSent') and the channel is ready to
|
// is sent (channelState is 'fundingLockedSent') and the channel is ready to
|
||||||
// be used.
|
// be used.
|
||||||
func (f *fundingManager) sendChannelAnnouncement(completeChan *channeldb.OpenChannel,
|
func (f *fundingManager) sendChannelAnnouncement(completeChan *channeldb.OpenChannel,
|
||||||
channel *lnwallet.LightningChannel, shortChanID *lnwire.ShortChannelID) error {
|
shortChanID *lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
// TODO(eugene) wait for 6 confirmations here
|
// TODO(eugene) wait for 6 confirmations here
|
||||||
|
|
||||||
@ -1618,8 +1611,8 @@ func (f *fundingManager) sendChannelAnnouncement(completeChan *channeldb.OpenCha
|
|||||||
// Register the new link with the L3 routing manager so this new
|
// Register the new link with the L3 routing manager so this new
|
||||||
// channel can be utilized during path finding.
|
// channel can be utilized during path finding.
|
||||||
err := f.announceChannel(f.cfg.IDKey, completeChan.IdentityPub,
|
err := f.announceChannel(f.cfg.IDKey, completeChan.IdentityPub,
|
||||||
channel.LocalFundingKey, channel.RemoteFundingKey,
|
completeChan.LocalChanCfg.MultiSigKey,
|
||||||
*shortChanID, chanID)
|
completeChan.RemoteChanCfg.MultiSigKey, *shortChanID, chanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("channel announcement failed: %v", err)
|
return fmt.Errorf("channel announcement failed: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user