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:
parent
d0b192c636
commit
d4d5198e85
14
peer.go
14
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,18 +334,26 @@ 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{
|
||||
// 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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user