Skip to content

Commit f95588c

Browse files
committed
graph/db: add CachedEdgePolicy helpers
1 parent 42c6e95 commit f95588c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

graph/db/graph_cache.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
185185
c.mtx.Lock()
186186
defer c.mtx.Unlock()
187187

188-
isEdge1 := policy.ChannelFlags&lnwire.ChanUpdateDirection == 0
189-
190188
updatePolicy := func(nodeKey route.Vertex) {
191189
if len(c.nodeChannels[nodeKey]) == 0 {
192190
log.Warnf("Node=%v not found in graph cache", nodeKey)
@@ -207,15 +205,15 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
207205
switch {
208206
// This is node 1, and it is edge 1, so this is the outgoing
209207
// policy for node 1.
210-
case channel.IsNode1 && isEdge1:
208+
case channel.IsNode1 && policy.IsNode1():
211209
channel.OutPolicySet = true
212210
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
213211
channel.InboundFee = fee
214212
})
215213

216214
// This is node 2, and it is edge 2, so this is the outgoing
217215
// policy for node 2.
218-
case !channel.IsNode1 && !isEdge1:
216+
case !channel.IsNode1 && !policy.IsNode1():
219217
channel.OutPolicySet = true
220218
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
221219
channel.InboundFee = fee

graph/db/models/cached_edge_policy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ func (c *CachedEdgePolicy) ComputeFee(
7575
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
7676
}
7777

78+
// IsDisabled returns true if the channel is disabled in the direction from the
79+
// advertising node.
80+
func (c *CachedEdgePolicy) IsDisabled() bool {
81+
return c.ChannelFlags&lnwire.ChanUpdateDisabled != 0
82+
}
83+
84+
// IsNode1 returns true if this policy was announced by the channel's node_1
85+
// node.
86+
func (c *CachedEdgePolicy) IsNode1() bool {
87+
return c.ChannelFlags&lnwire.ChanUpdateDirection == 0
88+
}
89+
7890
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
7991
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
8092
return &CachedEdgePolicy{

routing/unified_edges.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
360360
}
361361

362362
// For network channels, skip the disabled ones.
363-
edgeFlags := edge.policy.ChannelFlags
364-
isDisabled := edgeFlags&lnwire.ChanUpdateDisabled != 0
365-
if isDisabled {
363+
if edge.policy.IsDisabled() {
366364
log.Debugf("Skipped edge %v due to it being disabled",
367365
edge.policy.ChannelID)
368366
continue

0 commit comments

Comments
 (0)