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.
This commit is contained in:
Johan T. Halseth 2018-08-22 09:32:43 +02:00
parent f4f7b64b2d
commit 229fd88289
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

16
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 {