From 42c6e951edfdf3f47b9e3332557d39f362194e90 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 9 Jun 2025 10:19:31 +0200 Subject: [PATCH] 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. --- graph/db/graph.go | 4 +++- graph/db/graph_cache.go | 12 ++++++++---- graph/db/models/cached_edge_policy.go | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/graph/db/graph.go b/graph/db/graph.go index c57d904e1..30486adae 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -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 { diff --git a/graph/db/graph_cache.go b/graph/db/graph_cache.go index 2e85280ff..9d6e3af5f 100644 --- a/graph/db/graph_cache.go +++ b/graph/db/graph_cache.go @@ -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 } } diff --git a/graph/db/models/cached_edge_policy.go b/graph/db/models/cached_edge_policy.go index b770ec1fb..35614c5f1 100644 --- a/graph/db/models/cached_edge_policy.go +++ b/graph/db/models/cached_edge_policy.go @@ -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, } }