@@ -877,6 +877,114 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
877
877
ht.MineBlocksAndAssertNumTxes(1, 1)
878
878
}
879
879
880
+ // testPendingChannelConfirmationUntilActive verifies the value for the rpc
881
+ // filed ConfirmationUntilActive decreases as expected as soon as blocks are
882
+ // confirmed.
883
+ func testPendingChannelConfirmationUntilActive(ht *lntest.HarnessTest) {
884
+ var (
885
+ numConfs uint32 = 5
886
+ chanAmt btcutil.Amount = 100000
887
+ )
888
+
889
+ // Since we want Bob's channels to require more than 1 on-chain
890
+ // confirmation before active, we will launch Bob with the custom
891
+ // defaultchanconfs flag.
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, and confirmation
910
+ // height will be 0.
911
+ require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice,
912
+ 1)[0].ConfirmationsUntilActive)
913
+ require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(bob, 1)[0].
914
+ ConfirmationsUntilActive)
915
+ require.Equal(
916
+ ht, uint32(0),
917
+ ht.AssertNumPendingOpenChannels(alice, 1)[0].ConfirmationHeight,
918
+ )
919
+ require.Equal(
920
+ ht, uint32(0),
921
+ ht.AssertNumPendingOpenChannels(bob, 1)[0].ConfirmationHeight,
922
+ )
923
+
924
+ // Mine the first block containing the funding transaction, This
925
+ // confirms the funding transaction but the channel should still remain
926
+ // pending.
927
+ ht.MineBlocksAndAssertNumTxes(1, 1)
928
+
929
+ // Decrement numConfs to reflect that one confirmation has been
930
+ // received.
931
+ numConfs--
932
+
933
+ // Since the funding transaction has been mined, the best block height
934
+ // corresponds to the confirmation height of the channel's opening tx.
935
+ _, expectedConfirmationHeight := ht.GetBestBlock()
936
+
937
+ // Channel remains pending after the first confirmation.
938
+ ht.AssertNumPendingOpenChannels(alice, 1)
939
+ ht.AssertNumPendingOpenChannels(bob, 1)
940
+
941
+ // Restart both nodes to test that the appropriate state has been
942
+ // persisted and that both nodes recover gracefully.
943
+ ht.RestartNode(alice)
944
+ ht.RestartNode(bob)
945
+ ht.EnsureConnected(alice, bob)
946
+
947
+ // ConfirmationsUntilActive field should decrease as each block is
948
+ // mined until the required number of confirmations is reached. Let's
949
+ // mine a few blocks and verify the value of ConfirmationsUntilActive at
950
+ // each step.
951
+ for i := numConfs; i > 0; i-- {
952
+ expectedConfirmationsLeft := i
953
+
954
+ // Retrieve pending channels for Alice and verify the remaining
955
+ // confirmations and confirmation height.
956
+ pendingAlice := ht.AssertNumPendingOpenChannels(alice, 1)
957
+ require.Equal(
958
+ ht, expectedConfirmationsLeft,
959
+ pendingAlice[0].ConfirmationsUntilActive,
960
+ )
961
+ require.Equal(
962
+ ht, uint32(expectedConfirmationHeight),
963
+ pendingAlice[0].ConfirmationHeight,
964
+ )
965
+
966
+ // Retrieve pending channels for Bob and verify the remaining
967
+ // confirmations and confirmation height.
968
+ pendingBob := ht.AssertNumPendingOpenChannels(bob, 1)
969
+ require.Equal(
970
+ ht, expectedConfirmationsLeft,
971
+ pendingBob[0].ConfirmationsUntilActive,
972
+ )
973
+ require.Equal(
974
+ ht, uint32(expectedConfirmationHeight),
975
+ pendingBob[0].ConfirmationHeight,
976
+ )
977
+
978
+ // Mine the next block.
979
+ ht.MineBlocks(1)
980
+ }
981
+
982
+ // After the required number of confirmations, the channel should be
983
+ // marked as active.
984
+ ht.AssertNumPendingOpenChannels(alice, 0)
985
+ ht.AssertNumPendingOpenChannels(bob, 0)
986
+ }
987
+
880
988
// testSimpleTaprootChannelActivation ensures that a simple taproot channel is
881
989
// active if the initiator disconnects and reconnects in between channel opening
882
990
// and channel confirmation.
0 commit comments