peer: if we don't have an advertised routing policy, fall back to default

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-23 11:32:50 -07:00
parent d0b192c636
commit d4d5198e85
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

22
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))