mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-29 19:42:40 +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 {
|
if c.graphCache != nil {
|
||||||
var isUpdate1 bool
|
c.graphCache.UpdatePolicy(edge, from, to)
|
||||||
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
|
||||||
isUpdate1 = true
|
|
||||||
}
|
|
||||||
|
|
||||||
c.graphCache.UpdatePolicy(edge, from, to, isUpdate1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@@ -150,16 +150,14 @@ func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
|
|||||||
if policy1.ToNode != info.NodeKey2Bytes {
|
if policy1.ToNode != info.NodeKey2Bytes {
|
||||||
fromNode, toNode = toNode, fromNode
|
fromNode, toNode = toNode, fromNode
|
||||||
}
|
}
|
||||||
isEdge1 := policy1.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
c.UpdatePolicy(policy1, fromNode, toNode)
|
||||||
c.UpdatePolicy(policy1, fromNode, toNode, isEdge1)
|
|
||||||
}
|
}
|
||||||
if policy2 != nil {
|
if policy2 != nil {
|
||||||
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
|
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
|
||||||
if policy2.ToNode != info.NodeKey1Bytes {
|
if policy2.ToNode != info.NodeKey1Bytes {
|
||||||
fromNode, toNode = toNode, fromNode
|
fromNode, toNode = toNode, fromNode
|
||||||
}
|
}
|
||||||
isEdge1 := policy2.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
c.UpdatePolicy(policy2, fromNode, toNode)
|
||||||
c.UpdatePolicy(policy2, fromNode, toNode, isEdge1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
// channel edge was added beforehand so that the directed channel struct already
|
||||||
// exists in the cache.
|
// exists in the cache.
|
||||||
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||||
toNode route.Vertex, edge1 bool) {
|
toNode route.Vertex) {
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
defer c.mtx.Unlock()
|
defer c.mtx.Unlock()
|
||||||
|
|
||||||
|
isEdge1 := policy.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
||||||
|
|
||||||
updatePolicy := func(nodeKey route.Vertex) {
|
updatePolicy := func(nodeKey route.Vertex) {
|
||||||
if len(c.nodeChannels[nodeKey]) == 0 {
|
if len(c.nodeChannels[nodeKey]) == 0 {
|
||||||
log.Warnf("Node=%v not found in graph cache", nodeKey)
|
log.Warnf("Node=%v not found in graph cache", nodeKey)
|
||||||
@@ -203,7 +203,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
|||||||
switch {
|
switch {
|
||||||
// This is node 1, and it is edge 1, so this is the outgoing
|
// This is node 1, and it is edge 1, so this is the outgoing
|
||||||
// policy for node 1.
|
// policy for node 1.
|
||||||
case channel.IsNode1 && edge1:
|
case channel.IsNode1 && isEdge1:
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
channel.InboundFee = 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
|
// This is node 2, and it is edge 2, so this is the outgoing
|
||||||
// policy for node 2.
|
// policy for node 2.
|
||||||
case !channel.IsNode1 && !edge1:
|
case !channel.IsNode1 && !isEdge1:
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
channel.InboundFee = fee
|
channel.InboundFee = fee
|
||||||
|
Reference in New Issue
Block a user