From 229fd882895a6f6c15a92da56cf397d78952d518 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 22 Aug 2018 09:32:43 +0200 Subject: [PATCH] peer: use custom MinHTLC value at initial link add This commit fixes a bug within the peer, where we would always use the default forwarding policy when adding new links to the switch. Mostly this wasn't a problem, as we most often are using default values for new channels, but the min_htlc value is a value that is set by the remote, not us. If the remote specified a custom min_htlc during channel creation, we would still use our DefaultMinHtlc value when first adding the link, making us try to forward HTLCs that would be rejected by the remote. We fix this by getting the required min_htlc value from the channel state machine, and setting this for the link's forwarding policy. Note that on restarts we will query the database for our latest ChannelEdgePolicy, and use that to craft the forwardingPolicy. This means that the value will be set correctly if the policy is found in the database. --- peer.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/peer.go b/peer.go index f6366c80..9145a97c 100644 --- a/peer.go +++ b/peer.go @@ -1550,9 +1550,23 @@ out: continue } + // We'll query the localChanCfg of the new channel to + // determine the minimum HTLC value that can be + // forwarded. For fees we'll use the default values, as + // they currently are always set to the default values + // at initial channel creation. + fwdMinHtlc := newChan.FwdMinHtlc() + defaultPolicy := p.server.cc.routingPolicy + forwardingPolicy := &htlcswitch.ForwardingPolicy{ + MinHTLC: fwdMinHtlc, + BaseFee: defaultPolicy.BaseFee, + FeeRate: defaultPolicy.FeeRate, + TimeLockDelta: defaultPolicy.TimeLockDelta, + } + // Create the link and add it to the switch. err = p.addLink( - chanPoint, newChan, &p.server.cc.routingPolicy, + chanPoint, newChan, forwardingPolicy, chainEvents, currentHeight, false, ) if err != nil {