multi: Add itest for funding timeout
This commit adds an integration test that verifies the funding timeout behavior in the funding manager, in dev/integration test. Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
This commit is contained in:
9 files changed
+132
-22
No files matched your search
+20
-7
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/labels"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
@@ -101,11 +102,6 @@ const (
|
||||
|
||||
msgBufferSize = 50
|
||||
|
||||
// MaxWaitNumBlocksFundingConf is the maximum number of blocks to wait
|
||||
// for the funding transaction to be confirmed before forgetting
|
||||
// channels that aren't initiated by us. 2016 blocks is ~2 weeks.
|
||||
MaxWaitNumBlocksFundingConf = 2016
|
||||
|
||||
// pendingChansLimit is the maximum number of pending channels that we
|
||||
// can have. After this point, pending channel opens will start to be
|
||||
// rejected.
|
||||
@@ -339,6 +335,11 @@ type DevConfig struct {
|
||||
// remote node's channel ready message once the channel as been marked
|
||||
// as `channelReadySent`.
|
||||
ProcessChannelReadyWait time.Duration
|
||||
|
||||
// MaxWaitNumBlocksFundingConf is the maximum number of blocks to wait
|
||||
// for the funding transaction to be confirmed before forgetting
|
||||
// channels that aren't initiated by us.
|
||||
MaxWaitNumBlocksFundingConf uint32
|
||||
}
|
||||
|
||||
// Config defines the configuration for the FundingManager. All elements
|
||||
@@ -3164,9 +3165,21 @@ func (f *Manager) waitForTimeout(completeChan *channeldb.OpenChannel,
|
||||
|
||||
defer epochClient.Cancel()
|
||||
|
||||
// The value of waitBlocksForFundingConf is adjusted in a development
|
||||
// environment to enhance test capabilities. Otherwise, it is set to
|
||||
// DefaultMaxWaitNumBlocksFundingConf.
|
||||
waitBlocksForFundingConf := uint32(
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf,
|
||||
)
|
||||
|
||||
if lncfg.IsDevBuild() {
|
||||
waitBlocksForFundingConf =
|
||||
f.cfg.Dev.MaxWaitNumBlocksFundingConf
|
||||
}
|
||||
|
||||
// On block maxHeight we will cancel the funding confirmation wait.
|
||||
broadcastHeight := completeChan.BroadcastHeight()
|
||||
maxHeight := broadcastHeight + MaxWaitNumBlocksFundingConf
|
||||
maxHeight := broadcastHeight + waitBlocksForFundingConf
|
||||
for {
|
||||
select {
|
||||
case epoch, ok := <-epochClient.Epochs:
|
||||
@@ -3182,7 +3195,7 @@ func (f *Manager) waitForTimeout(completeChan *channeldb.OpenChannel,
|
||||
log.Warnf("Waited for %v blocks without "+
|
||||
"seeing funding transaction confirmed,"+
|
||||
" cancelling.",
|
||||
MaxWaitNumBlocksFundingConf)
|
||||
waitBlocksForFundingConf)
|
||||
|
||||
// Notify the caller of the timeout.
|
||||
close(timeoutChan)
|
||||
|
||||
+12
-8
@@ -2334,14 +2334,15 @@ func TestFundingManagerFundingTimeout(t *testing.T) {
|
||||
// mine 2016-1, and check that it is still pending.
|
||||
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight +
|
||||
MaxWaitNumBlocksFundingConf - 1,
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf - 1,
|
||||
}
|
||||
|
||||
// Bob should still be waiting for the channel to open.
|
||||
assertNumPendingChannelsRemains(t, bob, 1)
|
||||
|
||||
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
|
||||
Height: fundingBroadcastHeight +
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf,
|
||||
}
|
||||
|
||||
// Bob should have sent an Error message to Alice.
|
||||
@@ -2387,16 +2388,16 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
|
||||
t.Fatalf("alice did not publish funding tx")
|
||||
}
|
||||
|
||||
// Increase the height to 1 minus the MaxWaitNumBlocksFundingConf
|
||||
// Increase the height to 1 minus the DefaultMaxWaitNumBlocksFundingConf
|
||||
// height.
|
||||
alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight +
|
||||
MaxWaitNumBlocksFundingConf - 1,
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf - 1,
|
||||
}
|
||||
|
||||
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight +
|
||||
MaxWaitNumBlocksFundingConf - 1,
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf - 1,
|
||||
}
|
||||
|
||||
// Assert both and Alice and Bob still have 1 pending channels.
|
||||
@@ -2404,13 +2405,16 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
|
||||
|
||||
assertNumPendingChannelsRemains(t, bob, 1)
|
||||
|
||||
// Increase both Alice and Bob to MaxWaitNumBlocksFundingConf height.
|
||||
// Increase both Alice and Bob to DefaultMaxWaitNumBlocksFundingConf
|
||||
// height.
|
||||
alice.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
|
||||
Height: fundingBroadcastHeight +
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf,
|
||||
}
|
||||
|
||||
bob.mockNotifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: fundingBroadcastHeight + MaxWaitNumBlocksFundingConf,
|
||||
Height: fundingBroadcastHeight +
|
||||
lncfg.DefaultMaxWaitNumBlocksFundingConf,
|
||||
}
|
||||
|
||||
// Since Alice was the initiator, the channel should not have timed out.
|
||||
|
||||
Reference in new issue
Block a user