From 7031b5d2171f41bcccb8f348191e83e4ecf6140b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Feb 2018 19:21:42 -0800 Subject: [PATCH] htlcswitch: modify forwarding fee assertion to compare emperical fees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- htlcswitch/link.go | 15 +++++++++------ htlcswitch/link_test.go | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index ae923277..09257ff4 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -1729,15 +1729,18 @@ func (l *channelLink) processLockedInHtlcs( fwdInfo.AmountToForward, ) - // If the amount of the incoming HTLC, minus - // our expected fee isn't equal to the - // forwarding instructions, then either the - // values have been tampered with, or the send - // used incorrect/dated information to + // If the actual fee is less than our expected + // fee, then we'll reject 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. - if pd.Amount-expectedFee < fwdInfo.AmountToForward { + actualFee := pd.Amount - fwdInfo.AmountToForward + if pd.Amount < fwdInfo.AmountToForward || + actualFee < expectedFee { + log.Errorf("Incoming htlc(%x) has "+ "insufficient fee: expected "+ "%v, got %v", pd.RHash[:], diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 8add4e84..6602dd5a 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -777,7 +777,7 @@ func TestUpdateForwardingPolicy(t *testing.T) { testStartingHeight, 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. payResp, err := n.makePayment(n.aliceServer, n.carolServer, n.bobServer.PubKey(), hops, amountNoFee, htlcAmt, @@ -827,7 +827,7 @@ func TestUpdateForwardingPolicy(t *testing.T) { n.firstBobChannelLink.UpdateForwardingPolicy(newPolicy) // 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. _, err = n.makePayment(n.aliceServer, n.carolServer, n.bobServer.PubKey(), hops, amountNoFee, htlcAmt,