htlcswitch: return FEE_INSUFFICIENT before checking balance
This commit is contained in:
3 files changed
+27
-12
No files matched your search
+13
-12
@@ -2551,17 +2551,8 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte,
|
|||||||
policy := l.cfg.FwrdingPolicy
|
policy := l.cfg.FwrdingPolicy
|
||||||
l.RUnlock()
|
l.RUnlock()
|
||||||
|
|
||||||
// First check whether the outgoing htlc satisfies the channel policy.
|
// Using the amount of the incoming HTLC, we'll calculate the expected
|
||||||
err := l.canSendHtlc(
|
// fee this incoming HTLC must carry in order to satisfy the
|
||||||
policy, payHash, amtToForward, outgoingTimeout, heightNow,
|
|
||||||
originalScid,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, using the amount of the incoming HTLC, we'll calculate the
|
|
||||||
// expected fee this incoming HTLC must carry in order to satisfy the
|
|
||||||
// constraints of the outgoing link.
|
// constraints of the outgoing link.
|
||||||
expectedFee := ExpectedFee(policy, amtToForward)
|
expectedFee := ExpectedFee(policy, amtToForward)
|
||||||
|
|
||||||
@@ -2569,7 +2560,8 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte,
|
|||||||
// this HTLC as it didn't provide a sufficient amount of fees, or the
|
// this HTLC as it didn't provide a sufficient amount of fees, or the
|
||||||
// values have been tampered with, or the send used incorrect/dated
|
// values have been tampered with, or the send used incorrect/dated
|
||||||
// information to construct the forwarding information for this hop. In
|
// information to construct the forwarding information for this hop. In
|
||||||
// any case, we'll cancel this HTLC.
|
// any case, we'll cancel this HTLC. We're checking for this case first
|
||||||
|
// to leak as little information as possible.
|
||||||
actualFee := incomingHtlcAmt - amtToForward
|
actualFee := incomingHtlcAmt - amtToForward
|
||||||
if incomingHtlcAmt < amtToForward || actualFee < expectedFee {
|
if incomingHtlcAmt < amtToForward || actualFee < expectedFee {
|
||||||
l.log.Warnf("outgoing htlc(%x) has insufficient fee: "+
|
l.log.Warnf("outgoing htlc(%x) has insufficient fee: "+
|
||||||
@@ -2585,6 +2577,15 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte,
|
|||||||
return NewLinkError(failure)
|
return NewLinkError(failure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether the outgoing htlc satisfies the channel policy.
|
||||||
|
err := l.canSendHtlc(
|
||||||
|
policy, payHash, amtToForward, outgoingTimeout, heightNow,
|
||||||
|
originalScid,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, we'll ensure that the time-lock on the outgoing HTLC meets
|
// Finally, we'll ensure that the time-lock on the outgoing HTLC meets
|
||||||
// the following constraint: the incoming time-lock minus our time-lock
|
// the following constraint: the incoming time-lock minus our time-lock
|
||||||
// delta should equal the outgoing time lock. Otherwise, whether the
|
// delta should equal the outgoing time lock. Otherwise, whether the
|
||||||
|
|||||||
@@ -5643,6 +5643,19 @@ func TestCheckHtlcForward(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Test that insufficient fee error takes preference over insufficient
|
||||||
|
// channel balance.
|
||||||
|
t.Run("insufficient fee error preference", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
result := link.CheckHtlcForward(
|
||||||
|
hash, 100005, 100000, 200,
|
||||||
|
150, 0, lnwire.ShortChannelID{},
|
||||||
|
)
|
||||||
|
_, ok := result.WireMessage().(*lnwire.FailFeeInsufficient)
|
||||||
|
require.True(t, ok, "expected FailFeeInsufficient failure code")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("expiry too soon", func(t *testing.T) {
|
t.Run("expiry too soon", func(t *testing.T) {
|
||||||
result := link.CheckHtlcForward(hash, 1500, 1000,
|
result := link.CheckHtlcForward(hash, 1500, 1000,
|
||||||
200, 150, 190, lnwire.ShortChannelID{})
|
200, 150, 190, lnwire.ShortChannelID{})
|
||||||
|
|||||||
@@ -5339,6 +5339,7 @@ func testSwitchHandlePacketForward(t *testing.T, zeroConf, private,
|
|||||||
ogPacket := &htlcPacket{
|
ogPacket := &htlcPacket{
|
||||||
incomingChanID: bobLink.ShortChanID(),
|
incomingChanID: bobLink.ShortChanID(),
|
||||||
incomingHTLCID: 0,
|
incomingHTLCID: 0,
|
||||||
|
incomingAmount: 1000,
|
||||||
obfuscator: NewMockObfuscator(),
|
obfuscator: NewMockObfuscator(),
|
||||||
htlc: &lnwire.UpdateAddHTLC{
|
htlc: &lnwire.UpdateAddHTLC{
|
||||||
PaymentHash: rhash,
|
PaymentHash: rhash,
|
||||||
|
|||||||
Reference in new issue
Block a user