mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
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
1 changed files with 15 additions and 7 deletions
22
peer.go
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
|
// need to fetch its current link-layer forwarding policy from
|
||||||
// the database.
|
// the database.
|
||||||
graph := p.server.chanDB.ChannelGraph()
|
graph := p.server.chanDB.ChannelGraph()
|
||||||
_, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
|
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -334,17 +334,25 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||||
// TODO(roasbeef): can add helper method to get policy for
|
// TODO(roasbeef): can add helper method to get policy for
|
||||||
// particular channel.
|
// particular channel.
|
||||||
var selfPolicy *channeldb.ChannelEdgePolicy
|
var selfPolicy *channeldb.ChannelEdgePolicy
|
||||||
if !p1.Node.PubKey.IsEqual(p.server.identityPriv.PubKey()) {
|
if info.NodeKey1.IsEqual(p.server.identityPriv.PubKey()) {
|
||||||
selfPolicy = p1
|
selfPolicy = p1
|
||||||
} else {
|
} else {
|
||||||
selfPolicy = p2
|
selfPolicy = p2
|
||||||
}
|
}
|
||||||
|
|
||||||
forwardingPolicy := &htlcswitch.ForwardingPolicy{
|
// If we don't yet have an advertised routing policy, then
|
||||||
MinHTLC: selfPolicy.MinHTLC,
|
// we'll use the current default, otherwise we'll translate the
|
||||||
BaseFee: selfPolicy.FeeBaseMSat,
|
// routing policy into a forwarding policy.
|
||||||
FeeRate: selfPolicy.FeeProportionalMillionths,
|
var forwardingPolicy *htlcswitch.ForwardingPolicy
|
||||||
TimeLockDelta: uint32(selfPolicy.TimeLockDelta),
|
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))
|
peerLog.Tracef("Using link policy of: %v", spew.Sdump(forwardingPolicy))
|
||||||
|
|
Loading…
Add table
Reference in a new issue