htlcswitch: modify forwarding fee assertion to compare emperical fees

In this commit, we fix a bug that was uncovered by the recent change to
lnwire.MilliSatoshi. Rather than manually compute the diff in fees,
we’ll directly compare the fee that is given against the fee that we
expect.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-24 19:21:42 -08:00
parent b8d0df998a
commit 7031b5d217
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 11 additions and 8 deletions

View File

@ -1729,15 +1729,18 @@ func (l *channelLink) processLockedInHtlcs(
fwdInfo.AmountToForward, fwdInfo.AmountToForward,
) )
// If the amount of the incoming HTLC, minus // If the actual fee is less than our expected
// our expected fee isn't equal to the // fee, then we'll reject this HTLC as it
// forwarding instructions, then either the // didn't provide a sufficient amount of fees,
// values have been tampered with, or the send // or the values have been tampered with, or
// used incorrect/dated information to // the send used incorrect/dated information to
// construct the forwarding information for // construct the forwarding information for
// this hop. In any case, we'll cancel this // this hop. In any case, we'll cancel this
// HTLC. // HTLC.
if pd.Amount-expectedFee < fwdInfo.AmountToForward { actualFee := pd.Amount - fwdInfo.AmountToForward
if pd.Amount < fwdInfo.AmountToForward ||
actualFee < expectedFee {
log.Errorf("Incoming htlc(%x) has "+ log.Errorf("Incoming htlc(%x) has "+
"insufficient fee: expected "+ "insufficient fee: expected "+
"%v, got %v", pd.RHash[:], "%v, got %v", pd.RHash[:],

View File

@ -777,7 +777,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
testStartingHeight, testStartingHeight,
n.firstBobChannelLink, n.carolChannelLink) n.firstBobChannelLink, n.carolChannelLink)
// First, send this 1 BTC payment over the three hops, the payment // First, send this 10 mSAT payment over the three hops, the payment
// should succeed, and all balances should be updated accordingly. // should succeed, and all balances should be updated accordingly.
payResp, err := n.makePayment(n.aliceServer, n.carolServer, payResp, err := n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amountNoFee, htlcAmt, n.bobServer.PubKey(), hops, amountNoFee, htlcAmt,
@ -827,7 +827,7 @@ func TestUpdateForwardingPolicy(t *testing.T) {
n.firstBobChannelLink.UpdateForwardingPolicy(newPolicy) n.firstBobChannelLink.UpdateForwardingPolicy(newPolicy)
// Next, we'll send the payment again, using the exact same per-hop // Next, we'll send the payment again, using the exact same per-hop
// payload for each node. This payment should fail as it wont' factor // payload for each node. This payment should fail as it won't factor
// in Bob's new fee policy. // in Bob's new fee policy.
_, err = n.makePayment(n.aliceServer, n.carolServer, _, err = n.makePayment(n.aliceServer, n.carolServer,
n.bobServer.PubKey(), hops, amountNoFee, htlcAmt, n.bobServer.PubKey(), hops, amountNoFee, htlcAmt,