peer: fetch forwarding policy from disk rather than using default

This commit modifies the logic when we are loading alll the channels
that we have with a particular peer to grab the current committed
forwarding policy from disk rather then using the default forwarding
policy. We do this as it’s now possible for active channels to have
distinct forwarding policies.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 23:53:21 -07:00
parent 475c3b6c0c
commit dd1d69b140
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

41
peer.go

@ -308,9 +308,6 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
return fmt.Errorf("peer shutting down")
}
// Register this new channel link with the HTLC Switch. This is
// necessary to properly route multi-hop payments, and forward
// new payments triggered by RPC clients.
blockEpoch, err := p.server.cc.chainNotifier.RegisterBlockEpochNtfn()
if err != nil {
return err
@ -319,6 +316,42 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
if err != nil {
return err
}
// Before we register this new link with the HTLC Switch, we'll
// need to fetch its current link-layer forwarding policy from
// the database.
graph := p.server.chanDB.ChannelGraph()
_, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
if err != nil {
return err
}
// We'll filter out our policy from the directional channel
// edges based whom the edge connects to. If it doesn't connect
// to us, then we know that we were the one that advertised the
// policy.
//
// 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()) {
selfPolicy = p1
} else {
selfPolicy = p2
}
forwardingPolicy := &htlcswitch.ForwardingPolicy{
MinHTLC: selfPolicy.MinHTLC,
BaseFee: selfPolicy.FeeBaseMSat,
FeeRate: selfPolicy.FeeProportionalMillionths,
TimeLockDelta: uint32(selfPolicy.TimeLockDelta),
}
peerLog.Tracef("Using link policy of: %v", spew.Sdump(forwardingPolicy))
// Register this new channel link with the HTLC Switch. This is
// necessary to properly route multi-hop payments, and forward
// new payments triggered by RPC clients.
linkCfg := htlcswitch.ChannelLinkConfig{
Peer: p,
DecodeHopIterator: p.server.sphinx.DecodeHopIterator,
@ -329,7 +362,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
DebugHTLC: cfg.DebugHTLC,
Registry: p.server.invoices,
Switch: p.server.htlcSwitch,
FwrdingPolicy: p.server.cc.routingPolicy,
FwrdingPolicy: *forwardingPolicy,
BlockEpochs: blockEpoch,
}
link := htlcswitch.NewChannelLink(linkCfg, lnChan,