mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-25 19:46:52 +02:00
graph/db: let GraphCache.UpdatePolicy take a cached policy
Update the GraphCache.UpdatePolicy method to take a `models.CachedEdgePolicy` instead of a `models.ChannelEdgePolicy`. Doing this will allow us later on to only fetch the necessary info for populating the CachedEdgePolicy when we are populating the cache via UpdatePolicy.
This commit is contained in:
@@ -566,7 +566,9 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
|
||||
}
|
||||
|
||||
if c.graphCache != nil {
|
||||
c.graphCache.UpdatePolicy(edge, from, to)
|
||||
c.graphCache.UpdatePolicy(
|
||||
models.NewCachedPolicy(edge), from, to,
|
||||
)
|
||||
}
|
||||
|
||||
select {
|
||||
|
@@ -150,14 +150,18 @@ func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
|
||||
if policy1.ToNode != info.NodeKey2Bytes {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
c.UpdatePolicy(policy1, fromNode, toNode)
|
||||
c.UpdatePolicy(
|
||||
models.NewCachedPolicy(policy1), fromNode, toNode,
|
||||
)
|
||||
}
|
||||
if policy2 != nil {
|
||||
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
|
||||
if policy2.ToNode != info.NodeKey1Bytes {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
c.UpdatePolicy(policy2, fromNode, toNode)
|
||||
c.UpdatePolicy(
|
||||
models.NewCachedPolicy(policy2), fromNode, toNode,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +179,7 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
|
||||
// of the from and to node is not strictly important. But we assume that a
|
||||
// channel edge was added beforehand so that the directed channel struct already
|
||||
// exists in the cache.
|
||||
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||
func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
||||
toNode route.Vertex) {
|
||||
|
||||
c.mtx.Lock()
|
||||
@@ -220,7 +224,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||
// The other two cases left mean it's the inbound policy for the
|
||||
// node.
|
||||
default:
|
||||
channel.InPolicy = models.NewCachedPolicy(policy)
|
||||
channel.InPolicy = policy
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
)
|
||||
@@ -48,6 +49,9 @@ type CachedEdgePolicy struct {
|
||||
// HTLCs for each millionth of a satoshi forwarded.
|
||||
FeeProportionalMillionths lnwire.MilliSatoshi
|
||||
|
||||
// InboundFee is the fee that the node will charge for incoming HTLCs.
|
||||
InboundFee fn.Option[lnwire.Fee]
|
||||
|
||||
// ToNodePubKey is a function that returns the to node of a policy.
|
||||
// Since we only ever store the inbound policy, this is always the node
|
||||
// that we query the channels for in ForEachChannel(). Therefore, we can
|
||||
@@ -82,5 +86,6 @@ func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
|
||||
MaxHTLC: policy.MaxHTLC,
|
||||
FeeBaseMSat: policy.FeeBaseMSat,
|
||||
FeeProportionalMillionths: policy.FeeProportionalMillionths,
|
||||
InboundFee: policy.InboundFee,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user