From d4d5198e8525d4e28371ec02004e7b40f034fed4 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 23 Aug 2017 11:32:50 -0700 Subject: [PATCH] peer: if we don't have an advertised routing policy, fall back to default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a bug that could arise if either we had not, or the remote party had not advertised a routing policy for either outgoing channel edge. In this commit, we now detect if a policy wasn’t advertised, falling back to the default routing policy if so. Fixes #259. --- peer.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/peer.go b/peer.go index 3ff6e387f..788f4724e 100644 --- a/peer.go +++ b/peer.go @@ -321,7 +321,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { // need to fetch its current link-layer forwarding policy from // the database. graph := p.server.chanDB.ChannelGraph() - _, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint) + info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint) if err != nil { return err } @@ -334,17 +334,25 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { // TODO(roasbeef): can add helper method to get policy for // particular channel. var selfPolicy *channeldb.ChannelEdgePolicy - if !p1.Node.PubKey.IsEqual(p.server.identityPriv.PubKey()) { + if info.NodeKey1.IsEqual(p.server.identityPriv.PubKey()) { selfPolicy = p1 } else { selfPolicy = p2 } - forwardingPolicy := &htlcswitch.ForwardingPolicy{ - MinHTLC: selfPolicy.MinHTLC, - BaseFee: selfPolicy.FeeBaseMSat, - FeeRate: selfPolicy.FeeProportionalMillionths, - TimeLockDelta: uint32(selfPolicy.TimeLockDelta), + // If we don't yet have an advertised routing policy, then + // we'll use the current default, otherwise we'll translate the + // routing policy into a forwarding policy. + var forwardingPolicy *htlcswitch.ForwardingPolicy + if selfPolicy != nil { + forwardingPolicy = &htlcswitch.ForwardingPolicy{ + MinHTLC: selfPolicy.MinHTLC, + BaseFee: selfPolicy.FeeBaseMSat, + FeeRate: selfPolicy.FeeProportionalMillionths, + TimeLockDelta: uint32(selfPolicy.TimeLockDelta), + } + } else { + forwardingPolicy = &p.server.cc.routingPolicy } peerLog.Tracef("Using link policy of: %v", spew.Sdump(forwardingPolicy))