graph/db: add CachedEdgePolicy helpers
This commit is contained in:
3 files changed
+15
-7
No files matched your search
@@ -185,8 +185,6 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
|||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
defer c.mtx.Unlock()
|
defer c.mtx.Unlock()
|
||||||
|
|
||||||
isEdge1 := policy.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
|
||||||
|
|
||||||
updatePolicy := func(nodeKey route.Vertex) {
|
updatePolicy := func(nodeKey route.Vertex) {
|
||||||
if len(c.nodeChannels[nodeKey]) == 0 {
|
if len(c.nodeChannels[nodeKey]) == 0 {
|
||||||
log.Warnf("Node=%v not found in graph cache", nodeKey)
|
log.Warnf("Node=%v not found in graph cache", nodeKey)
|
||||||
@@ -207,7 +205,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
|||||||
switch {
|
switch {
|
||||||
// This is node 1, and it is edge 1, so this is the outgoing
|
// This is node 1, and it is edge 1, so this is the outgoing
|
||||||
// policy for node 1.
|
// policy for node 1.
|
||||||
case channel.IsNode1 && isEdge1:
|
case channel.IsNode1 && policy.IsNode1():
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
channel.InboundFee = fee
|
channel.InboundFee = fee
|
||||||
@@ -215,7 +213,7 @@ func (c *GraphCache) UpdatePolicy(policy *models.CachedEdgePolicy, fromNode,
|
|||||||
|
|
||||||
// This is node 2, and it is edge 2, so this is the outgoing
|
// This is node 2, and it is edge 2, so this is the outgoing
|
||||||
// policy for node 2.
|
// policy for node 2.
|
||||||
case !channel.IsNode1 && !isEdge1:
|
case !channel.IsNode1 && !policy.IsNode1():
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
channel.InboundFee = fee
|
channel.InboundFee = fee
|
||||||
|
|||||||
@@ -75,6 +75,18 @@ func (c *CachedEdgePolicy) ComputeFee(
|
|||||||
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDisabled returns true if the channel is disabled in the direction from the
|
||||||
|
// advertising node.
|
||||||
|
func (c *CachedEdgePolicy) IsDisabled() bool {
|
||||||
|
return c.ChannelFlags&lnwire.ChanUpdateDisabled != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNode1 returns true if this policy was announced by the channel's node_1
|
||||||
|
// node.
|
||||||
|
func (c *CachedEdgePolicy) IsNode1() bool {
|
||||||
|
return c.ChannelFlags&lnwire.ChanUpdateDirection == 0
|
||||||
|
}
|
||||||
|
|
||||||
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
|
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
|
||||||
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
|
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
|
||||||
return &CachedEdgePolicy{
|
return &CachedEdgePolicy{
|
||||||
|
|||||||
@@ -360,9 +360,7 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For network channels, skip the disabled ones.
|
// For network channels, skip the disabled ones.
|
||||||
edgeFlags := edge.policy.ChannelFlags
|
if edge.policy.IsDisabled() {
|
||||||
isDisabled := edgeFlags&lnwire.ChanUpdateDisabled != 0
|
|
||||||
if isDisabled {
|
|
||||||
log.Debugf("Skipped edge %v due to it being disabled",
|
log.Debugf("Skipped edge %v due to it being disabled",
|
||||||
edge.policy.ChannelID)
|
edge.policy.ChannelID)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in new issue
Block a user