mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-29 17:53:21 +02:00
graph/db: simplify GraphCache.UpdatePolicy signature
Remove the redundant "edge2" param and rather use the "policy" param to derive the boolean.
This commit is contained in:
@@ -566,12 +566,7 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
|
||||
}
|
||||
|
||||
if c.graphCache != nil {
|
||||
var isUpdate1 bool
|
||||
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
||||
isUpdate1 = true
|
||||
}
|
||||
|
||||
c.graphCache.UpdatePolicy(edge, from, to, isUpdate1)
|
||||
c.graphCache.UpdatePolicy(edge, from, to)
|
||||
}
|
||||
|
||||
select {
|
||||
|
@@ -150,16 +150,14 @@ func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
|
||||
if policy1.ToNode != info.NodeKey2Bytes {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
isEdge1 := policy1.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
||||
c.UpdatePolicy(policy1, fromNode, toNode, isEdge1)
|
||||
c.UpdatePolicy(policy1, fromNode, toNode)
|
||||
}
|
||||
if policy2 != nil {
|
||||
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
|
||||
if policy2.ToNode != info.NodeKey1Bytes {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
isEdge1 := policy2.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
||||
c.UpdatePolicy(policy2, fromNode, toNode, isEdge1)
|
||||
c.UpdatePolicy(policy2, fromNode, toNode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +176,13 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
|
||||
// channel edge was added beforehand so that the directed channel struct already
|
||||
// exists in the cache.
|
||||
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||
toNode route.Vertex, edge1 bool) {
|
||||
toNode route.Vertex) {
|
||||
|
||||
c.mtx.Lock()
|
||||
defer c.mtx.Unlock()
|
||||
|
||||
isEdge1 := policy.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
||||
|
||||
updatePolicy := func(nodeKey route.Vertex) {
|
||||
if len(c.nodeChannels[nodeKey]) == 0 {
|
||||
log.Warnf("Node=%v not found in graph cache", nodeKey)
|
||||
@@ -203,7 +203,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||
switch {
|
||||
// This is node 1, and it is edge 1, so this is the outgoing
|
||||
// policy for node 1.
|
||||
case channel.IsNode1 && edge1:
|
||||
case channel.IsNode1 && isEdge1:
|
||||
channel.OutPolicySet = true
|
||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||
channel.InboundFee = fee
|
||||
@@ -211,7 +211,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||
|
||||
// This is node 2, and it is edge 2, so this is the outgoing
|
||||
// policy for node 2.
|
||||
case !channel.IsNode1 && !edge1:
|
||||
case !channel.IsNode1 && !isEdge1:
|
||||
channel.OutPolicySet = true
|
||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||
channel.InboundFee = fee
|
||||
|
Reference in New Issue
Block a user