@@ -94,7 +94,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
94
94
val sender = TestProbe ()
95
95
val h = randomBytes32()
96
96
for (i <- 0 until 10 ) {
97
- alice ! CMD_ADD_HTLC (sender.ref, 50000000 msat, h, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
97
+ alice ! CMD_ADD_HTLC (sender.ref, 500000 msat, h, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
98
98
sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
99
99
val htlc = alice2bob.expectMsgType[UpdateAddHtlc ]
100
100
assert(htlc.id == i && htlc.paymentHash == h)
@@ -237,7 +237,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
237
237
bob2alice.expectNoMsg(200 millis)
238
238
}
239
239
240
- test(" recv CMD_ADD_HTLC (HTLC dips into remote funder fee reserve)" ) { f =>
240
+ test(" recv CMD_ADD_HTLC (HTLC dips into remote funder fee reserve)" , Tag ( StateTestsTags . NoMaxHtlcValueInFlight ) ) { f =>
241
241
import f ._
242
242
val sender = TestProbe ()
243
243
addHtlc(758640000 msat, alice, bob, alice2bob, bob2alice)
@@ -246,21 +246,20 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
246
246
247
247
// actual test begins
248
248
// at this point alice has the minimal amount to sustain a channel
249
- // alice maintains an extra reserve to accommodate for a few more HTLCs, so the first two HTLCs should be allowed
249
+ // alice maintains an extra reserve to accommodate for a few more HTLCs, so the first few HTLCs should be allowed
250
250
for (_ <- 1 to 7 ) {
251
251
bob ! CMD_ADD_HTLC (sender.ref, 12000000 msat, randomBytes32(), CltvExpiry (400144 ), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
252
252
sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
253
253
}
254
254
255
- // but this one will dip alice below her reserve: we must wait for the two previous HTLCs to settle before sending any more
256
255
// but this one will dip alice below her reserve: we must wait for the previous HTLCs to settle before sending any more
257
256
val failedAdd = CMD_ADD_HTLC (sender.ref, 11000000 msat, randomBytes32(), CltvExpiry (400144 ), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
258
257
bob ! failedAdd
259
258
val error = RemoteCannotAffordFeesForNewHtlc (channelId(bob), failedAdd.amount, missing = 1360 sat, 10000 sat, 22720 sat)
260
259
sender.expectMsg(RES_ADD_FAILED (failedAdd, error, Some (bob.stateData.asInstanceOf [DATA_NORMAL ].channelUpdate)))
261
260
}
262
261
263
- test(" recv CMD_ADD_HTLC (insufficient funds w/ pending htlcs and 0 balance)" ) { f =>
262
+ test(" recv CMD_ADD_HTLC (insufficient funds w/ pending htlcs and 0 balance)" , Tag ( StateTestsTags . NoMaxHtlcValueInFlight ) ) { f =>
264
263
import f ._
265
264
val sender = TestProbe ()
266
265
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
@@ -280,7 +279,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
280
279
alice2bob.expectNoMsg(200 millis)
281
280
}
282
281
283
- test(" recv CMD_ADD_HTLC (insufficient funds w/ pending htlcs 2/2)" ) { f =>
282
+ test(" recv CMD_ADD_HTLC (insufficient funds w/ pending htlcs 2/2)" , Tag ( StateTestsTags . NoMaxHtlcValueInFlight ) ) { f =>
284
283
import f ._
285
284
val sender = TestProbe ()
286
285
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
@@ -297,21 +296,25 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
297
296
alice2bob.expectNoMsg(200 millis)
298
297
}
299
298
300
- test(" recv CMD_ADD_HTLC (over max inflight htlc value)" ) { f =>
299
+ test(" recv CMD_ADD_HTLC (over remote max inflight htlc value)" , Tag ( StateTestsTags . AliceLowMaxHtlcValueInFlight ) ) { f =>
301
300
import f ._
302
301
val sender = TestProbe ()
303
302
val initialState = bob.stateData.asInstanceOf [DATA_NORMAL ]
303
+ assert(initialState.commitments.localParams.maxHtlcValueInFlightMsat === UInt64 .MaxValue )
304
+ assert(initialState.commitments.remoteParams.maxHtlcValueInFlightMsat === UInt64 (150000000 ))
304
305
val add = CMD_ADD_HTLC (sender.ref, 151000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
305
306
bob ! add
306
307
val error = HtlcValueTooHighInFlight (channelId(bob), maximum = 150000000 , actual = 151000000 msat)
307
308
sender.expectMsg(RES_ADD_FAILED (add, error, Some (initialState.channelUpdate)))
308
309
bob2alice.expectNoMsg(200 millis)
309
310
}
310
311
311
- test(" recv CMD_ADD_HTLC (over max inflight htlc value with duplicate amounts)" ) { f =>
312
+ test(" recv CMD_ADD_HTLC (over remote max inflight htlc value with duplicate amounts)" , Tag ( StateTestsTags . AliceLowMaxHtlcValueInFlight ) ) { f =>
312
313
import f ._
313
314
val sender = TestProbe ()
314
315
val initialState = bob.stateData.asInstanceOf [DATA_NORMAL ]
316
+ assert(initialState.commitments.localParams.maxHtlcValueInFlightMsat === UInt64 .MaxValue )
317
+ assert(initialState.commitments.remoteParams.maxHtlcValueInFlightMsat === UInt64 (150000000 ))
315
318
val add = CMD_ADD_HTLC (sender.ref, 75500000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
316
319
bob ! add
317
320
sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
@@ -323,12 +326,26 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
323
326
bob2alice.expectNoMsg(200 millis)
324
327
}
325
328
326
- test(" recv CMD_ADD_HTLC (over max accepted htlcs) " ) { f =>
329
+ test(" recv CMD_ADD_HTLC (over local max inflight htlc value) " , Tag ( StateTestsTags . AliceLowMaxHtlcValueInFlight ) ) { f =>
327
330
import f ._
328
331
val sender = TestProbe ()
329
332
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
330
- // Bob accepts a maximum of 30 htlcs
331
- for (i <- 0 until 30 ) {
333
+ assert(initialState.commitments.localParams.maxHtlcValueInFlightMsat === UInt64 (150000000 ))
334
+ assert(initialState.commitments.remoteParams.maxHtlcValueInFlightMsat === UInt64 .MaxValue )
335
+ val add = CMD_ADD_HTLC (sender.ref, 151000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
336
+ alice ! add
337
+ val error = HtlcValueTooHighInFlight (channelId(alice), maximum = 150000000 , actual = 151000000 msat)
338
+ sender.expectMsg(RES_ADD_FAILED (add, error, Some (initialState.channelUpdate)))
339
+ alice2bob.expectNoMsg(200 millis)
340
+ }
341
+
342
+ test(" recv CMD_ADD_HTLC (over remote max accepted htlcs)" ) { f =>
343
+ import f ._
344
+ val sender = TestProbe ()
345
+ val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
346
+ assert(initialState.commitments.localParams.maxAcceptedHtlcs === 100 )
347
+ assert(initialState.commitments.remoteParams.maxAcceptedHtlcs === 30 ) // Bob accepts a maximum of 30 htlcs
348
+ for (_ <- 0 until 30 ) {
332
349
alice ! CMD_ADD_HTLC (sender.ref, 10000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
333
350
sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
334
351
alice2bob.expectMsgType[UpdateAddHtlc ]
@@ -340,7 +357,25 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
340
357
alice2bob.expectNoMsg(200 millis)
341
358
}
342
359
343
- test(" recv CMD_ADD_HTLC (over capacity)" ) { f =>
360
+ test(" recv CMD_ADD_HTLC (over local max accepted htlcs)" ) { f =>
361
+ import f ._
362
+ val sender = TestProbe ()
363
+ val initialState = bob.stateData.asInstanceOf [DATA_NORMAL ]
364
+ assert(initialState.commitments.localParams.maxAcceptedHtlcs === 30 ) // Bob accepts a maximum of 30 htlcs
365
+ assert(initialState.commitments.remoteParams.maxAcceptedHtlcs === 100 ) // Alice accepts more, but Bob will stop at 30 HTLCs
366
+ for (_ <- 0 until 30 ) {
367
+ bob ! CMD_ADD_HTLC (sender.ref, 2500000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
368
+ sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
369
+ bob2alice.expectMsgType[UpdateAddHtlc ]
370
+ }
371
+ val add = CMD_ADD_HTLC (sender.ref, 2500000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
372
+ bob ! add
373
+ val error = TooManyAcceptedHtlcs (channelId(bob), maximum = 30 )
374
+ sender.expectMsg(RES_ADD_FAILED (add, error, Some (initialState.channelUpdate)))
375
+ bob2alice.expectNoMsg(200 millis)
376
+ }
377
+
378
+ test(" recv CMD_ADD_HTLC (over capacity)" , Tag (StateTestsTags .NoMaxHtlcValueInFlight )) { f =>
344
379
import f ._
345
380
val sender = TestProbe ()
346
381
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
@@ -405,14 +440,14 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
405
440
val sender = TestProbe ()
406
441
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
407
442
// let's make alice send an htlc
408
- val add1 = CMD_ADD_HTLC (sender.ref, 500000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
443
+ val add1 = CMD_ADD_HTLC (sender.ref, 50000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
409
444
alice ! add1
410
445
sender.expectMsgType[RES_SUCCESS [CMD_ADD_HTLC ]]
411
446
// at the same time bob initiates a closing
412
447
bob ! CMD_CLOSE (sender.ref, None )
413
448
sender.expectMsgType[RES_SUCCESS [CMD_CLOSE ]]
414
449
// this command will be received by alice right after having received the shutdown
415
- val add2 = CMD_ADD_HTLC (sender.ref, 100000000 msat, randomBytes32(), CltvExpiry (300000 ), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
450
+ val add2 = CMD_ADD_HTLC (sender.ref, 10000000 msat, randomBytes32(), CltvExpiry (300000 ), TestConstants .emptyOnionPacket, localOrigin(sender.ref))
416
451
// messages cross
417
452
alice2bob.expectMsgType[UpdateAddHtlc ]
418
453
alice2bob.forward(bob)
@@ -527,7 +562,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
527
562
bob2blockchain.expectMsgType[WatchTxConfirmed ]
528
563
}
529
564
530
- test(" recv UpdateAddHtlc (over max inflight htlc value)" ) { f =>
565
+ test(" recv UpdateAddHtlc (over max inflight htlc value)" , Tag ( StateTestsTags . AliceLowMaxHtlcValueInFlight ) ) { f =>
531
566
import f ._
532
567
val tx = alice.stateData.asInstanceOf [DATA_NORMAL ].commitments.localCommit.publishableTxs.commitTx.tx
533
568
alice2bob.forward(alice, UpdateAddHtlc (ByteVector32 .Zeroes , 0 , 151000000 msat, randomBytes32(), CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket))
0 commit comments