@@ -877,6 +877,92 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
877
877
ht .MineBlocksAndAssertNumTxes (1 , 1 )
878
878
}
879
879
880
+ // testConfirmationsUntilActiveOnPending verifies that as a channel status
881
+ // transitions from pending to active, the ConfirmationsUntilActive field of the
882
+ // PendingChannel decreases to 0 as expected.
883
+ func testConfirmationsUntilActiveOnPending (ht * lntest.HarnessTest ) {
884
+ const (
885
+ numConfs = int32 (5 )
886
+ chanAmt = 100000
887
+ )
888
+
889
+ // As we need to create a channel that requires more than 1 confirmation
890
+ // before it's open, with the current set of defaults, we'll need to
891
+ // create a new node instance.
892
+ alice := ht .NewNodeWithCoins ("Alice" , nil )
893
+ bob := ht .NewNode ("Bob" , []string {
894
+ fmt .Sprintf ("--bitcoin.defaultchanconfs=%v" , numConfs ),
895
+ })
896
+
897
+ // Ensure Alice and Bob are connected.
898
+ ht .EnsureConnected (alice , bob )
899
+
900
+ // Alice initiates a channel opening to Bob.
901
+ param := lntest.OpenChannelParams {Amt : chanAmt }
902
+ ht .OpenChannelAssertPending (alice , bob , param )
903
+
904
+ // Both Alice and Bob have one pending open channel.
905
+ ht .AssertNumPendingOpenChannels (alice , 1 )
906
+ ht .AssertNumPendingOpenChannels (bob , 1 )
907
+
908
+ // Since the funding transaction is not confirmed yet,
909
+ // ConfirmationsUntilActive will always be numConfs.
910
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (alice ,
911
+ 1 )[0 ].ConfirmationsUntilActive )
912
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (bob , 1 )[0 ].
913
+ ConfirmationsUntilActive )
914
+
915
+ // Ensure that even if a block is mined and the funding transaction
916
+ // remains unconfirmed, ConfirmationsUntilActive still equals numConfs
917
+ ht .MineEmptyBlocks (1 )
918
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (alice ,
919
+ 1 )[0 ].ConfirmationsUntilActive )
920
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (bob , 1 )[0 ].
921
+ ConfirmationsUntilActive )
922
+
923
+ // Mine the first block containing the funding transaction, This
924
+ // confirms the funding transaction but does not change the channel
925
+ // status.
926
+ ht .MineBlocksAndAssertNumTxes (1 , 1 )
927
+
928
+ // Channel remains pending after the first confirmation.
929
+ ht .AssertNumPendingOpenChannels (alice , 1 )
930
+ ht .AssertNumPendingOpenChannels (bob , 1 )
931
+
932
+ // Restart both nodes to test that the appropriate state has been
933
+ // persisted and that both nodes recover gracefully.
934
+ ht .RestartNode (alice )
935
+ ht .RestartNode (bob )
936
+
937
+ // ConfirmationsUntilActive field should decrease as each block is
938
+ // mined until the required number of confirmations is reached. Let's
939
+ // mine a few empty blocks and verify the value of
940
+ // ConfirmationsUntilActive at each step.
941
+ for i := int32 (1 ); i < numConfs ; i ++ {
942
+ expectedConfirmationsLeft := numConfs - i
943
+
944
+ // Retrieve pending channels for Alice and verify the remaining
945
+ // confirmations.
946
+ pendingAlice := ht .AssertNumPendingOpenChannels (alice , 1 )
947
+ require .Equal (ht , expectedConfirmationsLeft , pendingAlice [0 ].
948
+ ConfirmationsUntilActive )
949
+
950
+ // Retrieve pending channels for Bob and verify the remaining
951
+ // confirmations.
952
+ pendingBob := ht .AssertNumPendingOpenChannels (bob , 1 )
953
+ require .Equal (ht , expectedConfirmationsLeft , pendingBob [0 ].
954
+ ConfirmationsUntilActive )
955
+
956
+ // Mine the next block.
957
+ ht .MineEmptyBlocks (1 )
958
+ }
959
+
960
+ // After the required number of confirmations, the channel should be
961
+ // marked as active.
962
+ ht .AssertNumPendingOpenChannels (alice , 0 )
963
+ ht .AssertNumPendingOpenChannels (bob , 0 )
964
+ }
965
+
880
966
// testSimpleTaprootChannelActivation ensures that a simple taproot channel is
881
967
// active if the initiator disconnects and reconnects in between channel opening
882
968
// and channel confirmation.
0 commit comments