fundingmanager: remove unnecessary Peer param to sendFundingLocked

This commit is contained in:
Johan T. Halseth 2019-09-18 11:27:34 +02:00
parent 5b8e97da29
commit 9f3fbda71f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -851,23 +851,7 @@ func (f *fundingManager) stateStep(channel *channeldb.OpenChannel,
// The funding transaction was confirmed, but we did not successfully // The funding transaction was confirmed, but we did not successfully
// send the fundingLocked message to the peer, so let's do that now. // send the fundingLocked message to the peer, so let's do that now.
case markedOpen: case markedOpen:
peerChan := make(chan lnpeer.Peer, 1) err := f.sendFundingLocked(channel, lnChannel, shortChanID)
var peerKey [33]byte
copy(peerKey[:], channel.IdentityPub.SerializeCompressed())
f.cfg.NotifyWhenOnline(peerKey, peerChan)
var peer lnpeer.Peer
select {
case peer = <-peerChan:
case <-f.quit:
return ErrFundingManagerShuttingDown
}
err := f.sendFundingLocked(
peer, channel, lnChannel, shortChanID,
)
if err != nil { if err != nil {
return fmt.Errorf("failed sending fundingLocked: %v", return fmt.Errorf("failed sending fundingLocked: %v",
err) err)
@ -2057,7 +2041,7 @@ func (f *fundingManager) handleFundingConfirmation(
// sendFundingLocked creates and sends the fundingLocked message. // sendFundingLocked creates and sends the fundingLocked message.
// This should be called after the funding transaction has been confirmed, // This should be called after the funding transaction has been confirmed,
// and the channelState is 'markedOpen'. // and the channelState is 'markedOpen'.
func (f *fundingManager) sendFundingLocked(peer lnpeer.Peer, func (f *fundingManager) sendFundingLocked(
completeChan *channeldb.OpenChannel, channel *lnwallet.LightningChannel, completeChan *channeldb.OpenChannel, channel *lnwallet.LightningChannel,
shortChanID *lnwire.ShortChannelID) error { shortChanID *lnwire.ShortChannelID) error {
@ -2088,8 +2072,18 @@ func (f *fundingManager) sendFundingLocked(peer lnpeer.Peer,
// send fundingLocked until we succeed, or the fundingManager is shut // send fundingLocked until we succeed, or the fundingManager is shut
// down. // down.
for { for {
fndgLog.Debugf("Sending FundingLocked for ChannelID(%v) to "+ connected := make(chan lnpeer.Peer, 1)
"peer %x", chanID, peerKey) f.cfg.NotifyWhenOnline(peerKey, connected)
var peer lnpeer.Peer
select {
case peer = <-connected:
case <-f.quit:
return ErrFundingManagerShuttingDown
}
fndgLog.Infof("Peer(%x) is online, sending FundingLocked "+
"for ChannelID(%v)", peerKey, chanID)
if err := peer.SendMessage(false, fundingLockedMsg); err == nil { if err := peer.SendMessage(false, fundingLockedMsg); err == nil {
// Sending succeeded, we can break out and continue the // Sending succeeded, we can break out and continue the
@ -2099,20 +2093,6 @@ func (f *fundingManager) sendFundingLocked(peer lnpeer.Peer,
fndgLog.Warnf("Unable to send fundingLocked to peer %x: %v. "+ fndgLog.Warnf("Unable to send fundingLocked to peer %x: %v. "+
"Will retry when online", peerKey, err) "Will retry when online", peerKey, err)
connected := make(chan lnpeer.Peer, 1)
f.cfg.NotifyWhenOnline(peerKey, connected)
select {
case <-connected:
fndgLog.Infof("Peer(%x) came back online, will retry "+
"sending FundingLocked for ChannelID(%v)",
peerKey, chanID)
// Retry sending.
case <-f.quit:
return ErrFundingManagerShuttingDown
}
} }
return nil return nil