fundingmanager: extract opening logic into new method handleFundingConfirmation
This commit moves the opening logic found within waitForFundingConfirmation into a new method handleFundingConfirmation. This will make it easier to later break up waitForFundingConfirmation, and avoid code duplication.
This commit is contained in:
parent
b2a7e42f44
commit
b51b76b469
@ -1990,12 +1990,35 @@ func (f *fundingManager) waitForFundingConfirmation(
|
|||||||
TxPosition: uint16(fundingPoint.Index),
|
TxPosition: uint16(fundingPoint.Index),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = f.handleFundingConfirmation(completeChan, shortChanID)
|
||||||
|
if err != nil {
|
||||||
|
fndgLog.Errorf("Unable to handle funding confirmation: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case confChan <- &shortChanID:
|
||||||
|
case <-f.quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleFundingConfirmation marks a channel as open in the database, and set
|
||||||
|
// the channelOpeningState markedOpen. In addition it will report the now
|
||||||
|
// decided short channel ID to the switch, and close the local discovery signal
|
||||||
|
// for this channel.
|
||||||
|
func (f *fundingManager) handleFundingConfirmation(
|
||||||
|
completeChan *channeldb.OpenChannel,
|
||||||
|
shortChanID lnwire.ShortChannelID) error {
|
||||||
|
|
||||||
|
fundingPoint := completeChan.FundingOutpoint
|
||||||
|
chanID := lnwire.NewChanIDFromOutPoint(&fundingPoint)
|
||||||
|
|
||||||
// Now that the channel has been fully confirmed, we'll mark it as open
|
// Now that the channel has been fully confirmed, we'll mark it as open
|
||||||
// within the database.
|
// within the database.
|
||||||
if err := completeChan.MarkAsOpen(shortChanID); err != nil {
|
if err := completeChan.MarkAsOpen(shortChanID); err != nil {
|
||||||
fndgLog.Errorf("error setting channel pending flag to false: "+
|
return fmt.Errorf("error setting channel pending flag to false: "+
|
||||||
"%v", err)
|
"%v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform the ChannelNotifier that the channel has transitioned from
|
// Inform the ChannelNotifier that the channel has transitioned from
|
||||||
@ -2013,12 +2036,10 @@ func (f *fundingManager) waitForFundingConfirmation(
|
|||||||
// TODO(halseth): make the two db transactions (MarkChannelAsOpen and
|
// TODO(halseth): make the two db transactions (MarkChannelAsOpen and
|
||||||
// saveChannelOpeningState) atomic by doing them in the same transaction.
|
// saveChannelOpeningState) atomic by doing them in the same transaction.
|
||||||
// Needed to be properly fault-tolerant.
|
// Needed to be properly fault-tolerant.
|
||||||
err = f.saveChannelOpeningState(&completeChan.FundingOutpoint, markedOpen,
|
err := f.saveChannelOpeningState(&fundingPoint, markedOpen, &shortChanID)
|
||||||
&shortChanID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fndgLog.Errorf("error setting channel state to markedOpen: %v",
|
return fmt.Errorf("error setting channel state to markedOpen: %v",
|
||||||
err)
|
err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// As there might already be an active link in the switch with an
|
// As there might already be an active link in the switch with an
|
||||||
@ -2029,12 +2050,6 @@ func (f *fundingManager) waitForFundingConfirmation(
|
|||||||
fndgLog.Errorf("unable to report short chan id: %v", err)
|
fndgLog.Errorf("unable to report short chan id: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
|
||||||
case confChan <- &shortChanID:
|
|
||||||
case <-f.quit:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the discoverySignal channel, indicating to a separate
|
// Close the discoverySignal channel, indicating to a separate
|
||||||
// goroutine that the channel now is marked as open in the database
|
// goroutine that the channel now is marked as open in the database
|
||||||
// and that it is acceptable to process funding locked messages
|
// and that it is acceptable to process funding locked messages
|
||||||
@ -2044,6 +2059,8 @@ func (f *fundingManager) waitForFundingConfirmation(
|
|||||||
close(discoverySignal)
|
close(discoverySignal)
|
||||||
}
|
}
|
||||||
f.localDiscoveryMtx.Unlock()
|
f.localDiscoveryMtx.Unlock()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendFundingLocked creates and sends the fundingLocked message.
|
// sendFundingLocked creates and sends the fundingLocked message.
|
||||||
|
Loading…
Reference in New Issue
Block a user