@@ -223,16 +223,80 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
223
223
// closure is attempted, therefore the passed context should be a child derived
224
224
// via timeout from a base parent. Additionally, once the channel has been
225
225
// detected as closed, an assertion checks that the transaction is found within
226
- // a block.
226
+ // a block. Finally, this assertion verifies that the node always sends out a
227
+ // disable update when closing the channel if the channel was previously enabled.
228
+ //
229
+ // NOTE: This method assumes that the provided funding point is confirmed
230
+ // on-chain AND that the edge exists in the node's channel graph. If the funding
231
+ // transactions was reorged out at some point, use closeReorgedChannelAndAssert.
227
232
func closeChannelAndAssert (ctx context.Context , t * harnessTest ,
228
233
net * lntest.NetworkHarness , node * lntest.HarnessNode ,
229
234
fundingChanPoint * lnrpc.ChannelPoint , force bool ) * chainhash.Hash {
230
235
236
+ // Fetch the current channel policy. If the channel is currently
237
+ // enabled, we will register for graph notifications before closing to
238
+ // assert that the node sends out a disabling update as a result of the
239
+ // channel being closed.
240
+ curPolicy := getChannelPolicies (t , node , node .PubKeyStr , fundingChanPoint )[0 ]
241
+ expectDisable := ! curPolicy .Disabled
242
+
243
+ // If the current channel policy is enabled, begin subscribing the graph
244
+ // updates before initiating the channel closure.
245
+ var graphSub * graphSubscription
246
+ if expectDisable {
247
+ sub := subscribeGraphNotifications (t , ctx , node )
248
+ graphSub = & sub
249
+ defer close (graphSub .quit )
250
+ }
251
+
252
+ closeUpdates , _ , err := net .CloseChannel (ctx , node , fundingChanPoint , force )
253
+ if err != nil {
254
+ t .Fatalf ("unable to close channel: %v" , err )
255
+ }
256
+
257
+ // If the channel policy was enabled prior to the closure, wait until we
258
+ // received the disabled update.
259
+ if expectDisable {
260
+ curPolicy .Disabled = true
261
+ waitForChannelUpdate (
262
+ t , * graphSub ,
263
+ []expectedChanUpdate {
264
+ {node .PubKeyStr , curPolicy , fundingChanPoint },
265
+ },
266
+ )
267
+ }
268
+
269
+ return assertChannelClosed (ctx , t , net , node , fundingChanPoint , closeUpdates )
270
+ }
271
+
272
+ // closeReorgedChannelAndAssert attempts to close a channel identified by the
273
+ // passed channel point owned by the passed Lightning node. A fully blocking
274
+ // channel closure is attempted, therefore the passed context should be a child
275
+ // derived via timeout from a base parent. Additionally, once the channel has
276
+ // been detected as closed, an assertion checks that the transaction is found
277
+ // within a block.
278
+ //
279
+ // NOTE: This method does not verify that the node sends a disable update for
280
+ // the closed channel.
281
+ func closeReorgedChannelAndAssert (ctx context.Context , t * harnessTest ,
282
+ net * lntest.NetworkHarness , node * lntest.HarnessNode ,
283
+ fundingChanPoint * lnrpc.ChannelPoint , force bool ) * chainhash.Hash {
284
+
231
285
closeUpdates , _ , err := net .CloseChannel (ctx , node , fundingChanPoint , force )
232
286
if err != nil {
233
287
t .Fatalf ("unable to close channel: %v" , err )
234
288
}
235
289
290
+ return assertChannelClosed (ctx , t , net , node , fundingChanPoint , closeUpdates )
291
+ }
292
+
293
+ // assertChannelClosed asserts that the channel is properly cleaned up after
294
+ // initiating a cooperative or local close.
295
+ func assertChannelClosed (ctx context.Context , t * harnessTest ,
296
+ net * lntest.NetworkHarness , node * lntest.HarnessNode ,
297
+ fundingChanPoint * lnrpc.ChannelPoint ,
298
+ closeUpdates lnrpc.Lightning_CloseChannelClient ) * chainhash.Hash {
299
+
236
300
txidHash , err := getChanPointFundingTxid (fundingChanPoint )
237
301
if err != nil {
238
302
t .Fatalf ("unable to get txid: %v" , err )
@@ -989,7 +1053,6 @@ out:
989
1053
select {
990
1054
case graphUpdate := <- subscription .updateChan :
991
1055
for _ , update := range graphUpdate .ChannelUpdates {
992
-
993
1056
// For each expected update, check if it matches
994
1057
// the update we just received.
995
1058
for i , exp := range expUpdates {
@@ -1070,11 +1133,12 @@ func assertNoChannelUpdates(t *harnessTest, subscription graphSubscription,
1070
1133
}
1071
1134
}
1072
1135
1073
- // assertChannelPolicy asserts that the passed node's known channel policy for
1074
- // the passed chanPoint is consistent with the expected policy values.
1075
- func assertChannelPolicy (t * harnessTest , node * lntest.HarnessNode ,
1076
- advertisingNode string , expectedPolicy * lnrpc.RoutingPolicy ,
1077
- chanPoints ... * lnrpc.ChannelPoint ) {
1136
+ // getChannelPolicies queries the channel graph and retrieves the current edge
1137
+ // policies for the provided channel points.
1138
+ func getChannelPolicies (t * harnessTest , node * lntest.HarnessNode ,
1139
+ advertisingNode string ,
1140
+ chanPoints ... * lnrpc.ChannelPoint ) []* lnrpc.RoutingPolicy {
1141
+
1078
1142
ctxb := context .Background ()
1079
1143
1080
1144
descReq := & lnrpc.ChannelGraphRequest {
@@ -1086,25 +1150,18 @@ func assertChannelPolicy(t *harnessTest, node *lntest.HarnessNode,
1086
1150
t .Fatalf ("unable to query for alice's graph: %v" , err )
1087
1151
}
1088
1152
1153
+ var policies []* lnrpc.RoutingPolicy
1089
1154
out:
1090
1155
for _ , chanPoint := range chanPoints {
1091
1156
for _ , e := range chanGraph .Edges {
1092
1157
if e .ChanPoint != txStr (chanPoint ) {
1093
1158
continue
1094
1159
}
1095
1160
1096
- var err error
1097
1161
if e .Node1Pub == advertisingNode {
1098
- err = checkChannelPolicy (
1099
- e .Node1Policy , expectedPolicy ,
1100
- )
1162
+ policies = append (policies , e .Node1Policy )
1101
1163
} else {
1102
- err = checkChannelPolicy (
1103
- e .Node2Policy , expectedPolicy ,
1104
- )
1105
- }
1106
- if err != nil {
1107
- t .Fatalf (err .Error ())
1164
+ policies = append (policies , e .Node2Policy )
1108
1165
}
1109
1166
1110
1167
continue out
@@ -1114,6 +1171,23 @@ out:
1114
1171
// able to find this specific one, then we'll fail.
1115
1172
t .Fatalf ("did not find edge %v" , txStr (chanPoint ))
1116
1173
}
1174
+
1175
+ return policies
1176
+ }
1177
+
1178
+ // assertChannelPolicy asserts that the passed node's known channel policy for
1179
+ // the passed chanPoint is consistent with the expected policy values.
1180
+ func assertChannelPolicy (t * harnessTest , node * lntest.HarnessNode ,
1181
+ advertisingNode string , expectedPolicy * lnrpc.RoutingPolicy ,
1182
+ chanPoints ... * lnrpc.ChannelPoint ) {
1183
+
1184
+ policies := getChannelPolicies (t , node , advertisingNode , chanPoints ... )
1185
+ for _ , policy := range policies {
1186
+ err := checkChannelPolicy (policy , expectedPolicy )
1187
+ if err != nil {
1188
+ t .Fatalf (err .Error ())
1189
+ }
1190
+ }
1117
1191
}
1118
1192
1119
1193
// checkChannelPolicy checks that the policy matches the expected one.
@@ -1872,7 +1946,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
1872
1946
assertTxInBlock (t , block , fundingTxID )
1873
1947
1874
1948
ctxt , _ = context .WithTimeout (ctxb , channelCloseTimeout )
1875
- closeChannelAndAssert (ctxt , t , net , net .Alice , chanPoint , false )
1949
+ closeReorgedChannelAndAssert (ctxt , t , net , net .Alice , chanPoint , false )
1876
1950
}
1877
1951
1878
1952
// testDisconnectingTargetPeer performs a test which
0 commit comments