@@ -877,6 +877,92 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
877
877
ht .MineBlocksAndAssertNumTxes (1 , 1 )
878
878
}
879
879
880
+ // testConfirmationUntilConfirmedOnPending verifies that for a pending channel,
881
+ // after the funding transaction has been confirmed but before the channel is
882
+ // fully opened, the ConfirmationUntilConfirmed field of the PendingChannel
883
+ // decreases to 0 as expected.
884
+ func testConfirmationUntilConfirmedOnPending (ht * lntest.HarnessTest ) {
885
+ const (
886
+ numConfs = int32 (5 )
887
+ chanAmt = 100000
888
+ )
889
+
890
+ // As we need to create a channel that requires more than 1 confirmation
891
+ // before it's open, with the current set of defaults, we'll need to
892
+ // create a new node instance.
893
+ alice := ht .NewNodeWithCoins ("Alice" , nil )
894
+ bob := ht .NewNode ("Bob" , []string {
895
+ fmt .Sprintf ("--bitcoin.defaultchanconfs=%v" , numConfs ),
896
+ })
897
+
898
+ // Ensure Alice and Bob are connected.
899
+ ht .EnsureConnected (alice , bob )
900
+
901
+ // Alice initiates a channel opening to Bob.
902
+ param := lntest.OpenChannelParams {Amt : chanAmt }
903
+ ht .OpenChannelAssertPending (alice , bob , param )
904
+
905
+ // Both Alice and Bob have one pending open channel.
906
+ ht .AssertNumPendingOpenChannels (alice , 1 )
907
+ ht .AssertNumPendingOpenChannels (bob , 1 )
908
+
909
+ // Since the funding transaction is not confirmed yet,
910
+ // ConfirmationUntilConfirmed will always be numConfs.
911
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (alice ,
912
+ 1 )[0 ].ConfirmationUntilConfirmed )
913
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (bob , 1 )[0 ].
914
+ ConfirmationUntilConfirmed )
915
+
916
+ // Ensure that even if a block is mined and the funding transaction
917
+ // remains unconfirmed, ConfirmationUntilConfirmed still equals numConfs
918
+ ht .MineEmptyBlocks (1 )
919
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (alice ,
920
+ 1 )[0 ].ConfirmationUntilConfirmed )
921
+ require .Equal (ht , numConfs , ht .AssertNumPendingOpenChannels (bob , 1 )[0 ].
922
+ ConfirmationUntilConfirmed )
923
+
924
+ // Mine the first block containing the funding transaction, This
925
+ // confirms the funding transaction but does not yet open the channel.
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
+ // ConfirmationUntilConfirmed 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
+ // ConfirmationUntilConfirmed 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
+ ConfirmationUntilConfirmed )
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
+ ConfirmationUntilConfirmed )
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 open.
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