Skip to content

Commit 7c52250

Browse files
authored
Fix balance fuzz tests (#3251)
Those tests started randomly failing after moving to anchor outputs. The reason is that anchor outputs have a bigger commit weight than non anchor channels, and with our initial balance allocation we sometimes reached a point where the *remote* had exhausted all of its balance to pay commit fees (when the feerate was around 10 000 sat/kw), so the *local* couldn't send HTLCs (`RemoteCannotAffordFeesForNewHtlc`). This is an expected situation where we cannot do anything except wait for pending HTLCs to resolve before sending other HTLCs. We simply increase the initial balance to avoid running into this case. We also remove the `skip` case (which wasn't working at all, we should have used the `cancel` scalatest helper if we wanted to interrupt the test without failing it) and allow failures during the initial HTLC setup (which can happen if HTLCs are larger than the available balance).
1 parent ea183c3 commit 7c52250

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

eclair-core/src/test/scala/fr/acinq/eclair/channel/CommitmentsSpec.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,25 +415,25 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
415415
}
416416

417417
test("should always be able to send availableForSend", Tag("fuzzy")) { f =>
418-
val maxPendingHtlcAmount = 1000000.msat
418+
val maxPendingHtlcAmount = 1_000_000.msat
419419
case class FuzzTest(isInitiator: Boolean, pendingHtlcs: Int, feeRatePerKw: FeeratePerKw, dustLimit: Satoshi, toLocal: MilliSatoshi, toRemote: MilliSatoshi)
420420
for (_ <- 1 to 100) {
421421
val t = FuzzTest(
422422
isInitiator = Random.nextInt(2) == 0,
423423
pendingHtlcs = Random.nextInt(10),
424-
feeRatePerKw = FeeratePerKw(Random.nextInt(10000).max(1).sat),
424+
feeRatePerKw = FeeratePerKw(Random.nextInt(10_000).max(1).sat),
425425
dustLimit = Random.nextInt(1000).sat,
426-
// We make sure both sides have enough to send/receive at least the initial pending HTLCs.
427-
toLocal = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat,
428-
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
426+
// We make sure both sides have enough to send/receive at least the initial pending HTLCs while paying the commit fees.
427+
toLocal = maxPendingHtlcAmount * 2 * 15 + Random.nextInt(1_000_000_000).msat,
428+
toRemote = maxPendingHtlcAmount * 2 * 15 + Random.nextInt(1_000_000_000).msat)
429429
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isInitiator)
430430
// Add some initial HTLCs to the pending list (bigger commit tx).
431431
for (_ <- 1 to t.pendingHtlcs) {
432432
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat.max(1 msat)
433433
val (_, cmdAdd) = makeCmdAdd(amount, randomKey().publicKey, f.currentBlockHeight)
434434
c.sendAdd(cmdAdd, f.currentBlockHeight, TestConstants.Alice.nodeParams.channelConf, feeConfNoMismatch) match {
435435
case Right((cc, _)) => c = cc
436-
case Left(e) => ignore(s"$t -> could not setup initial htlcs: $e")
436+
case Left(e) => // we ignore failures (the HTLC amount probably exceeded availableBalanceForSend)
437437
}
438438
}
439439
if (c.availableBalanceForSend > 0.msat) {
@@ -445,25 +445,25 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
445445
}
446446

447447
test("should always be able to receive availableForReceive", Tag("fuzzy")) { f =>
448-
val maxPendingHtlcAmount = 1000000.msat
448+
val maxPendingHtlcAmount = 1_000_000.msat
449449
case class FuzzTest(isInitiator: Boolean, pendingHtlcs: Int, feeRatePerKw: FeeratePerKw, dustLimit: Satoshi, toLocal: MilliSatoshi, toRemote: MilliSatoshi)
450450
for (_ <- 1 to 100) {
451451
val t = FuzzTest(
452452
isInitiator = Random.nextInt(2) == 0,
453453
pendingHtlcs = Random.nextInt(10),
454-
feeRatePerKw = FeeratePerKw(Random.nextInt(10000).max(1).sat),
454+
feeRatePerKw = FeeratePerKw(Random.nextInt(10_000).max(1).sat),
455455
dustLimit = Random.nextInt(1000).sat,
456-
// We make sure both sides have enough to send/receive at least the initial pending HTLCs.
457-
toLocal = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat,
458-
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
456+
// We make sure both sides have enough to send/receive at least the initial pending HTLCs while paying the commit fees.
457+
toLocal = maxPendingHtlcAmount * 2 * 15 + Random.nextInt(1_000_000_000).msat,
458+
toRemote = maxPendingHtlcAmount * 2 * 15 + Random.nextInt(1_000_000_000).msat)
459459
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isInitiator)
460460
// Add some initial HTLCs to the pending list (bigger commit tx).
461461
for (_ <- 1 to t.pendingHtlcs) {
462462
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat.max(1 msat)
463463
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, amount, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None, accountable = false, None)
464464
c.receiveAdd(add) match {
465465
case Right(cc) => c = cc
466-
case Left(e) => ignore(s"$t -> could not setup initial htlcs: $e")
466+
case Left(e) => // we ignore failures (the HTLC amount probably exceeded availableBalanceForReceive)
467467
}
468468
}
469469
if (c.availableBalanceForReceive > 0.msat) {

0 commit comments

Comments
 (0)