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:
Elle Mouton
2025-06-09 10:19:31 +02:00
parent 0816645328
commit 42c6e951ed
3 changed files with 16 additions and 5 deletions

View File

@@ -566,7 +566,9 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
} }
if c.graphCache != nil { if c.graphCache != nil {
c.graphCache.UpdatePolicy(edge, from, to) c.graphCache.UpdatePolicy(
models.NewCachedPolicy(edge), from, to,
)
} }
select { select {

View File

@@ -150,14 +150,18 @@ 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
} }
c.UpdatePolicy(policy1, fromNode, toNode) c.UpdatePolicy(
models.NewCachedPolicy(policy1), fromNode, toNode,
)
} }
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
} }
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 // 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 // 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.CachedEdgePolicy, fromNode,
toNode route.Vertex) { toNode route.Vertex) {
c.mtx.Lock() 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 // The other two cases left mean it's the inbound policy for the
// node. // node.
default: default:
channel.InPolicy = models.NewCachedPolicy(policy) channel.InPolicy = policy
} }
} }

View File

@@ -1,6 +1,7 @@
package models package models
import ( import (
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
) )
@@ -48,6 +49,9 @@ type CachedEdgePolicy struct {
// HTLCs for each millionth of a satoshi forwarded. // HTLCs for each millionth of a satoshi forwarded.
FeeProportionalMillionths lnwire.MilliSatoshi 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. // 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 // Since we only ever store the inbound policy, this is always the node
// that we query the channels for in ForEachChannel(). Therefore, we can // that we query the channels for in ForEachChannel(). Therefore, we can
@@ -82,5 +86,6 @@ func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
MaxHTLC: policy.MaxHTLC, MaxHTLC: policy.MaxHTLC,
FeeBaseMSat: policy.FeeBaseMSat, FeeBaseMSat: policy.FeeBaseMSat,
FeeProportionalMillionths: policy.FeeProportionalMillionths, FeeProportionalMillionths: policy.FeeProportionalMillionths,
InboundFee: policy.InboundFee,
} }
} }