lnwallet: add verbose log for ErrBelowChanReserve
This commit is contained in:
2 files changed
+36
-45
No files matched your search
+22
-11
@@ -3566,9 +3566,12 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
// balance to satisfy the final evaluated HTLC's.
|
// balance to satisfy the final evaluated HTLC's.
|
||||||
switch {
|
switch {
|
||||||
case int64(ourBalance) < 0:
|
case int64(ourBalance) < 0:
|
||||||
return ErrBelowChanReserve
|
return fmt.Errorf("%w: negative local balance",
|
||||||
|
ErrBelowChanReserve)
|
||||||
|
|
||||||
case int64(theirBalance) < 0:
|
case int64(theirBalance) < 0:
|
||||||
return ErrBelowChanReserve
|
return fmt.Errorf("%w: negative remote balance",
|
||||||
|
ErrBelowChanReserve)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the fee being applied is enough to be relayed across the
|
// Ensure that the fee being applied is enough to be relayed across the
|
||||||
@@ -3580,17 +3583,25 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
|
|
||||||
// If the added HTLCs will decrease the balance, make sure they won't
|
// If the added HTLCs will decrease the balance, make sure they won't
|
||||||
// dip the local and remote balances below the channel reserves.
|
// dip the local and remote balances below the channel reserves.
|
||||||
|
ourReserve := lnwire.NewMSatFromSatoshis(
|
||||||
|
lc.channelState.LocalChanCfg.ChanReserve,
|
||||||
|
)
|
||||||
|
theirReserve := lnwire.NewMSatFromSatoshis(
|
||||||
|
lc.channelState.RemoteChanCfg.ChanReserve,
|
||||||
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case ourBalance < ourInitialBalance &&
|
case ourBalance < ourInitialBalance && ourBalance < ourReserve:
|
||||||
ourBalance < lnwire.NewMSatFromSatoshis(
|
lc.log.Debugf("Funds below chan reserve: ourBalance=%v, "+
|
||||||
lc.channelState.LocalChanCfg.ChanReserve):
|
"ourReserve=%v", ourBalance, ourReserve)
|
||||||
|
return fmt.Errorf("%w: our balance below chan reserve",
|
||||||
|
ErrBelowChanReserve)
|
||||||
|
|
||||||
return ErrBelowChanReserve
|
case theirBalance < theirInitialBalance && theirBalance < theirReserve:
|
||||||
case theirBalance < theirInitialBalance &&
|
lc.log.Debugf("Funds below chan reserve: theirBalance=%v, "+
|
||||||
theirBalance < lnwire.NewMSatFromSatoshis(
|
"theirReserve=%v", theirBalance, theirReserve)
|
||||||
lc.channelState.RemoteChanCfg.ChanReserve):
|
return fmt.Errorf("%w: their balance below chan reserve",
|
||||||
|
ErrBelowChanReserve)
|
||||||
return ErrBelowChanReserve
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateUpdates take a set of updates, and validates them against
|
// validateUpdates take a set of updates, and validates them against
|
||||||
|
|||||||
+14
-34
@@ -2737,10 +2737,7 @@ func TestAddHTLCNegativeBalance(t *testing.T) {
|
|||||||
htlcAmt = lnwire.NewMSatFromSatoshis(2 * btcutil.SatoshiPerBitcoin)
|
htlcAmt = lnwire.NewMSatFromSatoshis(2 * btcutil.SatoshiPerBitcoin)
|
||||||
htlc, _ := createHTLC(numHTLCs+1, htlcAmt)
|
htlc, _ := createHTLC(numHTLCs+1, htlcAmt)
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected balance below channel reserve, instead "+
|
|
||||||
"got: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertNoChanSyncNeeded is a helper function that asserts that upon restart,
|
// assertNoChanSyncNeeded is a helper function that asserts that upon restart,
|
||||||
@@ -5642,10 +5639,8 @@ func TestDesyncHTLCs(t *testing.T) {
|
|||||||
// balance is unavailable.
|
// balance is unavailable.
|
||||||
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
|
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
|
||||||
htlc, _ = createHTLC(1, htlcAmt)
|
htlc, _ = createHTLC(1, htlcAmt)
|
||||||
if _, err = aliceChannel.AddHTLC(htlc, nil); err != ErrBelowChanReserve {
|
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||||
t.Fatalf("expected ErrInsufficientBalance, instead received: %v",
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now do a state transition, which will ACK the FailHTLC, making Alice
|
// Now do a state transition, which will ACK the FailHTLC, making Alice
|
||||||
// able to add the new HTLC.
|
// able to add the new HTLC.
|
||||||
@@ -6063,14 +6058,11 @@ func TestChanReserve(t *testing.T) {
|
|||||||
htlc, _ = createHTLC(bobIndex, htlcAmt)
|
htlc, _ = createHTLC(bobIndex, htlcAmt)
|
||||||
bobIndex++
|
bobIndex++
|
||||||
_, err := bobChannel.AddHTLC(htlc, nil)
|
_, err := bobChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alice will reject this htlc upon receiving the htlc.
|
// Alice will reject this htlc upon receiving the htlc.
|
||||||
if _, err := aliceChannel.ReceiveHTLC(htlc); err != ErrBelowChanReserve {
|
_, err = aliceChannel.ReceiveHTLC(htlc)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
}
|
|
||||||
|
|
||||||
// We must setup the channels again, since a violation of the channel
|
// We must setup the channels again, since a violation of the channel
|
||||||
// constraints leads to channel shutdown.
|
// constraints leads to channel shutdown.
|
||||||
@@ -6105,14 +6097,11 @@ func TestChanReserve(t *testing.T) {
|
|||||||
htlc, _ = createHTLC(aliceIndex, htlcAmt)
|
htlc, _ = createHTLC(aliceIndex, htlcAmt)
|
||||||
aliceIndex++
|
aliceIndex++
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Likewise, Bob will reject receiving the htlc because of the same reason.
|
// Likewise, Bob will reject receiving the htlc because of the same reason.
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != ErrBelowChanReserve {
|
_, err = bobChannel.ReceiveHTLC(htlc)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
}
|
|
||||||
|
|
||||||
// We must setup the channels again, since a violation of the channel
|
// We must setup the channels again, since a violation of the channel
|
||||||
// constraints leads to channel shutdown.
|
// constraints leads to channel shutdown.
|
||||||
@@ -6218,22 +6207,15 @@ func TestChanReserveRemoteInitiator(t *testing.T) {
|
|||||||
// Bob should refuse to add this HTLC, since he realizes it will create
|
// Bob should refuse to add this HTLC, since he realizes it will create
|
||||||
// an invalid commitment.
|
// an invalid commitment.
|
||||||
_, err = bobChannel.AddHTLC(htlc, nil)
|
_, err = bobChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Of course Alice will also not have enough balance to add it herself.
|
// Of course Alice will also not have enough balance to add it herself.
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Same for Alice, she should refuse to accept this second HTLC.
|
// Same for Alice, she should refuse to accept this second HTLC.
|
||||||
if _, err := aliceChannel.ReceiveHTLC(htlc); err != ErrBelowChanReserve {
|
_, err = aliceChannel.ReceiveHTLC(htlc)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestChanReserveLocalInitiatorDustHtlc tests that fee the initiator must pay
|
// TestChanReserveLocalInitiatorDustHtlc tests that fee the initiator must pay
|
||||||
@@ -6276,9 +6258,7 @@ func TestChanReserveLocalInitiatorDustHtlc(t *testing.T) {
|
|||||||
// Alice should realize that the fee she must pay to add this HTLC to
|
// Alice should realize that the fee she must pay to add this HTLC to
|
||||||
// the local commitment would take her below the channel reserve.
|
// the local commitment would take her below the channel reserve.
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
_, err = aliceChannel.AddHTLC(htlc, nil)
|
||||||
if err != ErrBelowChanReserve {
|
require.ErrorIs(t, err, ErrBelowChanReserve)
|
||||||
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMinHTLC tests that the ErrBelowMinHTLC error is thrown if an HTLC is added
|
// TestMinHTLC tests that the ErrBelowMinHTLC error is thrown if an HTLC is added
|
||||||
|
|||||||
Reference in new issue
Block a user