graph/db: refactor CachedEdgePolicy to use explicit boolean fields
Replace MessageFlags and ChannelFlags bitfields in CachedEdgePolicy with explicit boolean fields to improve clarity and support both v1 and v2 channel updates: - Replace MessageFlags with HasMaxHTLC boolean. - Replace ChannelFlags with IsNode1 and IsDisabled booleans. - Update NewCachedPolicy to extract these fields version-appropriately: - For v1: derive from MessageFlags and ChannelFlags bits. - For v2: derive from policy.SecondPeer and policy.DisableFlags. Update all call sites that used method calls IsNode1() and IsDisabled() to instead access the fields directly. This includes: - graph_cache.go: policy direction and disable checks - unified_edges.go: HasMaxHTLC and IsDisabled checks - Tests: policy construction and assertions This refactoring improves readability by making the cached policy's state explicit rather than encoded in bitfields, and enables seamless support for both gossip protocol versions.
This commit is contained in:
5 files changed
+59
-45
No files matched your search
@@ -142,8 +142,8 @@ func (c *GraphCache) AddChannel(info *models.CachedEdgeInfo,
|
||||
// Skip adding policies if both are disabled, as the channel is
|
||||
// currently unusable for routing. However, we still add the channel
|
||||
// structure above so that policy updates can later enable it.
|
||||
if policy1 != nil && policy1.IsDisabled() &&
|
||||
policy2 != nil && policy2.IsDisabled() {
|
||||
if policy1 != nil && policy1.IsDisabled &&
|
||||
policy2 != nil && policy2.IsDisabled {
|
||||
|
||||
log.Debugf("Skipping policies for channel %v: both "+
|
||||
"policies are disabled (channel structure still "+
|
||||
@@ -156,14 +156,14 @@ func (c *GraphCache) AddChannel(info *models.CachedEdgeInfo,
|
||||
// of node 2 then we have the policy 1 as seen from node 1.
|
||||
if policy1 != nil {
|
||||
fromNode, toNode := info.NodeKey1Bytes, info.NodeKey2Bytes
|
||||
if !policy1.IsNode1() {
|
||||
if !policy1.IsNode1 {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
c.UpdatePolicy(policy1, fromNode, toNode)
|
||||
}
|
||||
if policy2 != nil {
|
||||
fromNode, toNode := info.NodeKey2Bytes, info.NodeKey1Bytes
|
||||
if policy2.IsNode1() {
|
||||
if policy2.IsNode1 {
|
||||
fromNode, toNode = toNode, fromNode
|
||||
}
|
||||
c.UpdatePolicy(policy2, fromNode, toNode)
|
||||
@@ -210,7 +210,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
||||
switch {
|
||||
// This is node 1, and it is edge 1, so this is the outgoing
|
||||
// policy for node 1.
|
||||
case channel.IsNode1 && policy.IsNode1():
|
||||
case channel.IsNode1 && policy.IsNode1:
|
||||
channel.OutPolicySet = true
|
||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||
channel.InboundFee = fee
|
||||
@@ -218,7 +218,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
||||
|
||||
// This is node 2, and it is edge 2, so this is the outgoing
|
||||
// policy for node 2.
|
||||
case !channel.IsNode1 && !policy.IsNode1():
|
||||
case !channel.IsNode1 && !policy.IsNode1:
|
||||
channel.OutPolicySet = true
|
||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||
channel.InboundFee = fee
|
||||
|
||||
Reference in new issue
Block a user