htlcswitch: return FEE_INSUFFICIENT before checking balance

This commit is contained in:
yyforyongyu committed 2023-03-16 08:30:38 +08:00
1 parent 098bb36114
commit 4054ace4e1
3 files changed
+27 -12

No files matched your search

+13 -12
View File
@@ -2551,17 +2551,8 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte,
policy := l.cfg.FwrdingPolicy
l.RUnlock()
// First check whether the outgoing htlc satisfies the channel policy.
err := l.canSendHtlc(
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
// 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.
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
// values have been tampered with, or the send used incorrect/dated
// 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
if incomingHtlcAmt < amtToForward || actualFee < expectedFee {
l.log.Warnf("outgoing htlc(%x) has insufficient fee: "+
@@ -2585,6 +2577,15 @@ func (l *channelLink) CheckHtlcForward(payHash [32]byte,
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
// the following constraint: the incoming time-lock minus our time-lock
// delta should equal the outgoing time lock. Otherwise, whether the