Skip to content

Commit cb16c71

Browse files
committed
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.
1 parent 9890d74 commit cb16c71

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

graph/db/graph_cache.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
180180
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
181181
toNode route.Vertex, edge1 bool) {
182182

183-
// Extract inbound fee if possible and available. If there is a decoding
184-
// error, ignore this policy.
185-
var inboundFee lnwire.Fee
186-
_, err := policy.ExtraOpaqueData.ExtractRecords(&inboundFee)
187-
if err != nil {
188-
log.Errorf("Failed to extract records from edge policy %v: %v",
189-
policy.ChannelID, err)
190-
191-
return
192-
}
193-
194183
c.mtx.Lock()
195184
defer c.mtx.Unlock()
196185

@@ -216,13 +205,17 @@ func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
216205
// policy for node 1.
217206
case channel.IsNode1 && edge1:
218207
channel.OutPolicySet = true
219-
channel.InboundFee = inboundFee
208+
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
209+
channel.InboundFee = fee
210+
})
220211

221212
// This is node 2, and it is edge 2, so this is the outgoing
222213
// policy for node 2.
223214
case !channel.IsNode1 && !edge1:
224215
channel.OutPolicySet = true
225-
channel.InboundFee = inboundFee
216+
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
217+
channel.InboundFee = fee
218+
})
226219

227220
// The other two cases left mean it's the inbound policy for the
228221
// node.

graph/db/graph_cache_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"testing"
66

7+
"github.com/lightningnetwork/lnd/fn/v2"
78
"github.com/lightningnetwork/lnd/graph/db/models"
89
"github.com/lightningnetwork/lnd/lnwire"
910
"github.com/lightningnetwork/lnd/routing/route"
@@ -37,11 +38,17 @@ func TestGraphCacheAddNode(t *testing.T) {
3738
channelFlagA, channelFlagB = 1, 0
3839
}
3940

41+
inboundFee := lnwire.Fee{
42+
BaseFee: 10,
43+
FeeRate: 20,
44+
}
45+
4046
outPolicy1 := &models.ChannelEdgePolicy{
4147
ChannelID: 1000,
4248
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
4349
ToNode: nodeB,
4450
// Define an inbound fee.
51+
InboundFee: fn.Some(inboundFee),
4552
ExtraOpaqueData: []byte{
4653
253, 217, 3, 8, 0, 0, 0, 10, 0, 0, 0, 20,
4754
},

routing/pathfind_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,25 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
666666
return nil, err
667667
}
668668

669-
getExtraData := func(
670-
end *testChannelEnd) lnwire.ExtraOpaqueData {
669+
getInboundFees := func(
670+
end *testChannelEnd) fn.Option[lnwire.Fee] {
671671

672-
var extraData lnwire.ExtraOpaqueData
673672
inboundFee := lnwire.Fee{
674673
BaseFee: int32(end.InboundFeeBaseMsat),
675674
FeeRate: int32(end.InboundFeeRate),
676675
}
677-
require.NoError(t, extraData.PackRecords(&inboundFee))
676+
677+
return fn.Some(inboundFee)
678+
}
679+
getExtraData := func(
680+
end *testChannelEnd) lnwire.ExtraOpaqueData {
681+
682+
var extraData lnwire.ExtraOpaqueData
683+
684+
inboundFee := getInboundFees(end)
685+
inboundFee.WhenSome(func(fee lnwire.Fee) {
686+
require.NoError(t, extraData.PackRecords(&fee))
687+
})
678688

679689
return extraData
680690
}
@@ -701,6 +711,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
701711
FeeBaseMSat: node1.FeeBaseMsat,
702712
FeeProportionalMillionths: node1.FeeRate,
703713
ToNode: node2Vertex,
714+
InboundFee: getInboundFees(node1), //nolint:ll
704715
ExtraOpaqueData: getExtraData(node1),
705716
}
706717
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
@@ -731,6 +742,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
731742
FeeBaseMSat: node2.FeeBaseMsat,
732743
FeeProportionalMillionths: node2.FeeRate,
733744
ToNode: node1Vertex,
745+
InboundFee: getInboundFees(node2), //nolint:ll
734746
ExtraOpaqueData: getExtraData(node2),
735747
}
736748
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {

0 commit comments

Comments
 (0)