graph/db: use InboundFee directly from ChannelEdgePolicy
Now that we know that the InboundFee on the ChannelEdgePolicy is always set appropriately, we can update the GraphCache UpdatePolicy method to take the InboundFee directly from the ChannelEdgePolicy object.
This commit is contained in:
3 files changed
+29
-17
No files matched your search
+6
-13
@@ -180,17 +180,6 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
|
|||||||
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||||
toNode route.Vertex, edge1 bool) {
|
toNode route.Vertex, edge1 bool) {
|
||||||
|
|
||||||
// Extract inbound fee if possible and available. If there is a decoding
|
|
||||||
// error, ignore this policy.
|
|
||||||
var inboundFee lnwire.Fee
|
|
||||||
_, err := policy.ExtraOpaqueData.ExtractRecords(&inboundFee)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to extract records from edge policy %v: %v",
|
|
||||||
policy.ChannelID, err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
defer c.mtx.Unlock()
|
defer c.mtx.Unlock()
|
||||||
|
|
||||||
@@ -216,13 +205,17 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
|||||||
// policy for node 1.
|
// policy for node 1.
|
||||||
case channel.IsNode1 && edge1:
|
case channel.IsNode1 && edge1:
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
channel.InboundFee = inboundFee
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
|
channel.InboundFee = fee
|
||||||
|
})
|
||||||
|
|
||||||
// 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 && !edge1:
|
case !channel.IsNode1 && !edge1:
|
||||||
channel.OutPolicySet = true
|
channel.OutPolicySet = true
|
||||||
channel.InboundFee = inboundFee
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
|
channel.InboundFee = fee
|
||||||
|
})
|
||||||
|
|
||||||
// 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.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/fn/v2"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@@ -37,11 +38,17 @@ func TestGraphCacheAddNode(t *testing.T) {
|
|||||||
channelFlagA, channelFlagB = 1, 0
|
channelFlagA, channelFlagB = 1, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inboundFee := lnwire.Fee{
|
||||||
|
BaseFee: 10,
|
||||||
|
FeeRate: 20,
|
||||||
|
}
|
||||||
|
|
||||||
outPolicy1 := &models.ChannelEdgePolicy{
|
outPolicy1 := &models.ChannelEdgePolicy{
|
||||||
ChannelID: 1000,
|
ChannelID: 1000,
|
||||||
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
|
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
|
||||||
ToNode: nodeB,
|
ToNode: nodeB,
|
||||||
// Define an inbound fee.
|
// Define an inbound fee.
|
||||||
|
InboundFee: fn.Some(inboundFee),
|
||||||
ExtraOpaqueData: []byte{
|
ExtraOpaqueData: []byte{
|
||||||
253, 217, 3, 8, 0, 0, 0, 10, 0, 0, 0, 20,
|
253, 217, 3, 8, 0, 0, 0, 10, 0, 0, 0, 20,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -666,15 +666,25 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
getExtraData := func(
|
getInboundFees := func(
|
||||||
end *testChannelEnd) lnwire.ExtraOpaqueData {
|
end *testChannelEnd) fn.Option[lnwire.Fee] {
|
||||||
|
|
||||||
var extraData lnwire.ExtraOpaqueData
|
|
||||||
inboundFee := lnwire.Fee{
|
inboundFee := lnwire.Fee{
|
||||||
BaseFee: int32(end.InboundFeeBaseMsat),
|
BaseFee: int32(end.InboundFeeBaseMsat),
|
||||||
FeeRate: int32(end.InboundFeeRate),
|
FeeRate: int32(end.InboundFeeRate),
|
||||||
}
|
}
|
||||||
require.NoError(t, extraData.PackRecords(&inboundFee))
|
|
||||||
|
return fn.Some(inboundFee)
|
||||||
|
}
|
||||||
|
getExtraData := func(
|
||||||
|
end *testChannelEnd) lnwire.ExtraOpaqueData {
|
||||||
|
|
||||||
|
var extraData lnwire.ExtraOpaqueData
|
||||||
|
|
||||||
|
inboundFee := getInboundFees(end)
|
||||||
|
inboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
|
require.NoError(t, extraData.PackRecords(&fee))
|
||||||
|
})
|
||||||
|
|
||||||
return extraData
|
return extraData
|
||||||
}
|
}
|
||||||
@@ -701,6 +711,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
FeeBaseMSat: node1.FeeBaseMsat,
|
FeeBaseMSat: node1.FeeBaseMsat,
|
||||||
FeeProportionalMillionths: node1.FeeRate,
|
FeeProportionalMillionths: node1.FeeRate,
|
||||||
ToNode: node2Vertex,
|
ToNode: node2Vertex,
|
||||||
|
InboundFee: getInboundFees(node1), //nolint:ll
|
||||||
ExtraOpaqueData: getExtraData(node1),
|
ExtraOpaqueData: getExtraData(node1),
|
||||||
}
|
}
|
||||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||||
@@ -731,6 +742,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
FeeBaseMSat: node2.FeeBaseMsat,
|
FeeBaseMSat: node2.FeeBaseMsat,
|
||||||
FeeProportionalMillionths: node2.FeeRate,
|
FeeProportionalMillionths: node2.FeeRate,
|
||||||
ToNode: node1Vertex,
|
ToNode: node1Vertex,
|
||||||
|
InboundFee: getInboundFees(node2), //nolint:ll
|
||||||
ExtraOpaqueData: getExtraData(node2),
|
ExtraOpaqueData: getExtraData(node2),
|
||||||
}
|
}
|
||||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user