funding: make MaxWaitNumBlocksFundingConf public to be used to compute

`FundingExpiryBlocks`.
This commit is contained in:
Maxwell Sayles 2023-03-14 16:13:40 -07:00
parent e549096b88
commit 9dea695079
2 changed files with 18 additions and 15 deletions

View file

@ -104,10 +104,10 @@ const (
// TODO(roasbeef): tune. // TODO(roasbeef): tune.
msgBufferSize = 50 msgBufferSize = 50
// maxWaitNumBlocksFundingConf is the maximum number of blocks to wait // MaxWaitNumBlocksFundingConf is the maximum number of blocks to wait
// for the funding transaction to be confirmed before forgetting // for the funding transaction to be confirmed before forgetting
// channels that aren't initiated by us. 2016 blocks is ~2 weeks. // channels that aren't initiated by us. 2016 blocks is ~2 weeks.
maxWaitNumBlocksFundingConf = 2016 MaxWaitNumBlocksFundingConf = 2016
// pendingChansLimit is the maximum number of pending channels that we // pendingChansLimit is the maximum number of pending channels that we
// can have. After this point, pending channel opens will start to be // can have. After this point, pending channel opens will start to be
@ -2535,7 +2535,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
pendingID [32]byte) error { pendingID [32]byte) error {
// We'll get a timeout if the number of blocks mined since the channel // We'll get a timeout if the number of blocks mined since the channel
// was initiated reaches maxWaitNumBlocksFundingConf and we are not the // was initiated reaches MaxWaitNumBlocksFundingConf and we are not the
// channel initiator. // channel initiator.
localBalance := c.LocalCommitment.LocalBalance.ToSatoshis() localBalance := c.LocalCommitment.LocalBalance.ToSatoshis()
closeInfo := &channeldb.ChannelCloseSummary{ closeInfo := &channeldb.ChannelCloseSummary{
@ -2597,7 +2597,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
// waitForFundingWithTimeout is a wrapper around waitForFundingConfirmation and // waitForFundingWithTimeout is a wrapper around waitForFundingConfirmation and
// waitForTimeout that will return ErrConfirmationTimeout if we are not the // waitForTimeout that will return ErrConfirmationTimeout if we are not the
// channel initiator and the maxWaitNumBlocksFundingConf has passed from the // channel initiator and the MaxWaitNumBlocksFundingConf has passed from the
// funding broadcast height. In case of confirmation, the short channel ID of // funding broadcast height. In case of confirmation, the short channel ID of
// the channel and the funding transaction will be returned. // the channel and the funding transaction will be returned.
func (f *Manager) waitForFundingWithTimeout( func (f *Manager) waitForFundingWithTimeout(
@ -2754,7 +2754,7 @@ func (f *Manager) waitForFundingConfirmation(
} }
} }
// waitForTimeout will close the timeout channel if maxWaitNumBlocksFundingConf // waitForTimeout will close the timeout channel if MaxWaitNumBlocksFundingConf
// has passed from the broadcast height of the given channel. In case of error, // has passed from the broadcast height of the given channel. In case of error,
// the error is sent on timeoutChan. The wait can be canceled by closing the // the error is sent on timeoutChan. The wait can be canceled by closing the
// cancelChan. // cancelChan.
@ -2777,7 +2777,7 @@ func (f *Manager) waitForTimeout(completeChan *channeldb.OpenChannel,
// On block maxHeight we will cancel the funding confirmation wait. // On block maxHeight we will cancel the funding confirmation wait.
broadcastHeight := completeChan.BroadcastHeight() broadcastHeight := completeChan.BroadcastHeight()
maxHeight := broadcastHeight + maxWaitNumBlocksFundingConf maxHeight := broadcastHeight + MaxWaitNumBlocksFundingConf
for { for {
select { select {
case epoch, ok := <-epochClient.Epochs: case epoch, ok := <-epochClient.Epochs:
@ -2793,7 +2793,7 @@ func (f *Manager) waitForTimeout(completeChan *channeldb.OpenChannel,
log.Warnf("Waited for %v blocks without "+ log.Warnf("Waited for %v blocks without "+
"seeing funding transaction confirmed,"+ "seeing funding transaction confirmed,"+
" cancelling.", " cancelling.",
maxWaitNumBlocksFundingConf) MaxWaitNumBlocksFundingConf)
// Notify the caller of the timeout. // Notify the caller of the timeout.
close(timeoutChan) close(timeoutChan)

View file

@ -2192,14 +2192,15 @@ func TestFundingManagerFundingTimeout(t *testing.T) {
// We expect Bob to forget the channel after 2016 blocks (2 weeks), so // We expect Bob to forget the channel after 2016 blocks (2 weeks), so
// mine 2016-1, and check that it is still pending. // mine 2016-1, and check that it is still pending.
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf - 1, Height: fundingBroadcastHeight +
MaxWaitNumBlocksFundingConf - 1,
} }
// Bob should still be waiting for the channel to open. // Bob should still be waiting for the channel to open.
assertNumPendingChannelsRemains(t, bob, 1) assertNumPendingChannelsRemains(t, bob, 1)
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf, Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
} }
// Bob should have sent an Error message to Alice. // Bob should have sent an Error message to Alice.
@ -2245,14 +2246,16 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
t.Fatalf("alice did not publish funding tx") t.Fatalf("alice did not publish funding tx")
} }
// Increase the height to 1 minus the maxWaitNumBlocksFundingConf // Increase the height to 1 minus the MaxWaitNumBlocksFundingConf
// height. // height.
alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf - 1, Height: fundingBroadcastHeight +
MaxWaitNumBlocksFundingConf - 1,
} }
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf - 1, Height: fundingBroadcastHeight +
MaxWaitNumBlocksFundingConf - 1,
} }
// Assert both and Alice and Bob still have 1 pending channels. // Assert both and Alice and Bob still have 1 pending channels.
@ -2260,13 +2263,13 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
assertNumPendingChannelsRemains(t, bob, 1) assertNumPendingChannelsRemains(t, bob, 1)
// Increase both Alice and Bob to maxWaitNumBlocksFundingConf height. // Increase both Alice and Bob to MaxWaitNumBlocksFundingConf height.
alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf, Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
} }
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{ bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
Height: fundingBroadcastHeight + maxWaitNumBlocksFundingConf, Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
} }
// Since Alice was the initiator, the channel should not have timed out. // Since Alice was the initiator, the channel should not have timed out.