@@ -190,7 +190,7 @@ class NormalStateSpec extends TestkitBaseClass with StateTestsHelperMethods {
190
190
val initialState = alice.stateData.asInstanceOf [DATA_NORMAL ]
191
191
val add = CMD_ADD_HTLC (MilliSatoshi (Int .MaxValue ), randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
192
192
sender.send(alice, add)
193
- val error = InsufficientFunds (channelId(alice), amount = MilliSatoshi (Int .MaxValue ), missing = 1376443 sat, reserve = 20000 sat, fees = 8960 sat)
193
+ val error = InsufficientFunds (channelId(alice), amount = MilliSatoshi (Int .MaxValue ), missing = 1379883 sat, reserve = 20000 sat, fees = 8960 sat)
194
194
sender.expectMsg(Failure (AddHtlcFailed (channelId(alice), add.paymentHash, error, Origin .Local (add.upstream.asInstanceOf [Upstream .Local ].id, Some (sender.ref)), Some (initialState.channelUpdate), Some (add))))
195
195
alice2bob.expectNoMsg(200 millis)
196
196
}
@@ -207,19 +207,27 @@ class NormalStateSpec extends TestkitBaseClass with StateTestsHelperMethods {
207
207
alice2bob.expectNoMsg(200 millis)
208
208
}
209
209
210
- test(" recv CMD_ADD_HTLC (HTLC dips remote funder below reserve)" ) { f =>
210
+ test(" recv CMD_ADD_HTLC (HTLC dips into remote funder fee reserve)" ) { f =>
211
211
import f ._
212
212
val sender = TestProbe ()
213
- addHtlc(771000000 msat, alice, bob, alice2bob, bob2alice)
213
+ addHtlc(767600000 msat, alice, bob, alice2bob, bob2alice)
214
214
crossSign(alice, bob, alice2bob, bob2alice)
215
- assert(alice.stateData.asInstanceOf [DATA_NORMAL ].commitments.availableBalanceForSend === 40000 .msat)
215
+ assert(alice.stateData.asInstanceOf [DATA_NORMAL ].commitments.availableBalanceForSend === 0 .msat)
216
216
217
217
// actual test begins
218
- // at this point alice has the minimal amount to sustain a channel (29000 sat ~= alice reserve + commit fee)
219
- val add = CMD_ADD_HTLC (120000000 msat, randomBytes32, CltvExpiry (400144 ), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
220
- sender.send(bob, add)
221
- val error = RemoteCannotAffordFeesForNewHtlc (channelId(bob), add.amount, missing = 1680 sat, 10000 sat, 10680 sat)
222
- sender.expectMsg(Failure (AddHtlcFailed (channelId(bob), add.paymentHash, error, Origin .Local (add.upstream.asInstanceOf [Upstream .Local ].id, Some (sender.ref)), Some (bob.stateData.asInstanceOf [DATA_NORMAL ].channelUpdate), Some (add))))
218
+ // at this point alice has the minimal amount to sustain a channel
219
+ // alice maintains an extra reserve to accommodate for a few more HTLCs, so the first two HTLCs should be allowed
220
+ sender.send(bob, CMD_ADD_HTLC (12000000 msat, randomBytes32, CltvExpiry (400144 ), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID())))
221
+ sender.expectMsg(ChannelCommandResponse .Ok )
222
+
223
+ sender.send(bob, CMD_ADD_HTLC (12500000 msat, randomBytes32, CltvExpiry (400144 ), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID())))
224
+ sender.expectMsg(ChannelCommandResponse .Ok )
225
+
226
+ // but this one will dip alice below her reserve: we must wait for the two previous HTLCs to settle before sending any more
227
+ val failedAdd = CMD_ADD_HTLC (11000000 msat, randomBytes32, CltvExpiry (400144 ), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
228
+ sender.send(bob, failedAdd)
229
+ val error = RemoteCannotAffordFeesForNewHtlc (channelId(bob), failedAdd.amount, missing = 1720 sat, 10000 sat, 14120 sat)
230
+ sender.expectMsg(Failure (AddHtlcFailed (channelId(bob), failedAdd.paymentHash, error, Origin .Local (failedAdd.upstream.asInstanceOf [Upstream .Local ].id, Some (sender.ref)), Some (bob.stateData.asInstanceOf [DATA_NORMAL ].channelUpdate), Some (failedAdd))))
223
231
}
224
232
225
233
test(" recv CMD_ADD_HTLC (insufficient funds w/ pending htlcs and 0 balance)" ) { f =>
@@ -232,7 +240,7 @@ class NormalStateSpec extends TestkitBaseClass with StateTestsHelperMethods {
232
240
sender.send(alice, CMD_ADD_HTLC (200000000 msat, randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID())))
233
241
sender.expectMsg(ChannelCommandResponse .Ok )
234
242
alice2bob.expectMsgType[UpdateAddHtlc ]
235
- sender.send(alice, CMD_ADD_HTLC (67600000 msat, randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID())))
243
+ sender.send(alice, CMD_ADD_HTLC (64160000 msat, randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID())))
236
244
sender.expectMsg(ChannelCommandResponse .Ok )
237
245
alice2bob.expectMsgType[UpdateAddHtlc ]
238
246
val add = CMD_ADD_HTLC (1000000 msat, randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
@@ -254,7 +262,7 @@ class NormalStateSpec extends TestkitBaseClass with StateTestsHelperMethods {
254
262
alice2bob.expectMsgType[UpdateAddHtlc ]
255
263
val add = CMD_ADD_HTLC (500000000 msat, randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
256
264
sender.send(alice, add)
257
- val error = InsufficientFunds (channelId(alice), amount = 500000000 msat, missing = 332400 sat, reserve = 20000 sat, fees = 12400 sat)
265
+ val error = InsufficientFunds (channelId(alice), amount = 500000000 msat, missing = 335840 sat, reserve = 20000 sat, fees = 12400 sat)
258
266
sender.expectMsg(Failure (AddHtlcFailed (channelId(alice), add.paymentHash, error, Origin .Local (add.upstream.asInstanceOf [Upstream .Local ].id, Some (sender.ref)), Some (initialState.channelUpdate), Some (add))))
259
267
alice2bob.expectNoMsg(200 millis)
260
268
}
@@ -316,7 +324,7 @@ class NormalStateSpec extends TestkitBaseClass with StateTestsHelperMethods {
316
324
// this is over channel-capacity
317
325
val add2 = CMD_ADD_HTLC (TestConstants .fundingSatoshis.toMilliSatoshi * 2 / 3 , randomBytes32, CltvExpiryDelta (144 ).toCltvExpiry(currentBlockHeight), TestConstants .emptyOnionPacket, Upstream .Local (UUID .randomUUID()))
318
326
sender.send(alice, add2)
319
- val error = InsufficientFunds (channelId(alice), add2.amount, 564013 sat, 20000 sat, 10680 sat)
327
+ val error = InsufficientFunds (channelId(alice), add2.amount, 567453 sat, 20000 sat, 10680 sat)
320
328
sender.expectMsg(Failure (AddHtlcFailed (channelId(alice), add2.paymentHash, error, Origin .Local (add2.upstream.asInstanceOf [Upstream .Local ].id, Some (sender.ref)), Some (initialState.channelUpdate), Some (add2))))
321
329
alice2bob.expectNoMsg(200 millis)
322
330
}
0 commit comments