From e170ad44d9495d30eaaf32190b9130053df77ac4 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 4 Jun 2025 12:33:58 +0200 Subject: [PATCH] graph/db+rpcserver: remove inbound fee extraction For any call-site where we extract inbound fees from a models.ChannelEdgePolicy object that was deserialised from disk, we can now just use the new InboundFee field on the object since we know that it would have been populated at deserialisation time. Note that for all these call-sites, if a failure previously happened on decoding of the TLV stream, the error would be ignored and the edge would just be skipped. This behaviour is now still the same given how ErrParsingExtraTLVBytes is handled on the DB layer. --- graph/db/kv_store.go | 17 ++++++----------- rpcserver.go | 11 +++-------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 290c2f54c..51a1d8483 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -482,16 +482,6 @@ func (c *KVStore) forEachNodeDirectedChannel(tx kvdb.RTx, cachedInPolicy.ToNodeFeatures = toNodeFeatures } - var inboundFee lnwire.Fee - if p1 != nil { - // Extract inbound fee. If there is a decoding error, - // skip this edge. - _, err := p1.ExtraOpaqueData.ExtractRecords(&inboundFee) - if err != nil { - return nil - } - } - directedChannel := &DirectedChannel{ ChannelID: e.ChannelID, IsNode1: node == e.NodeKey1Bytes, @@ -499,7 +489,12 @@ func (c *KVStore) forEachNodeDirectedChannel(tx kvdb.RTx, Capacity: e.Capacity, OutPolicySet: p1 != nil, InPolicy: cachedInPolicy, - InboundFee: inboundFee, + } + + if p1 != nil { + p1.InboundFee.WhenSome(func(fee lnwire.Fee) { + directedChannel.InboundFee = fee + }) } if node == e.NodeKey2Bytes { diff --git a/rpcserver.go b/rpcserver.go index 79d91e646..f9f8a5a9c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6842,7 +6842,7 @@ func marshalDBRoutingPolicy( disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0 customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData) - inboundFee := extractInboundFeeSafe(policy.ExtraOpaqueData) + inboundFee := policy.InboundFee.UnwrapOr(lnwire.Fee{}) return &lnrpc.RoutingPolicy{ TimeLockDelta: uint32(policy.TimeLockDelta), @@ -7698,14 +7698,9 @@ func (r *rpcServer) FeeReport(ctx context.Context, edgePolicy.FeeProportionalMillionths feeRate := float64(feeRateFixedPoint) / feeBase - // Decode inbound fee from extra data. - var inboundFee lnwire.Fee - _, err := edgePolicy.ExtraOpaqueData.ExtractRecords( - &inboundFee, + inboundFee := edgePolicy.InboundFee.UnwrapOr( + lnwire.Fee{}, ) - if err != nil { - return err - } // TODO(roasbeef): also add stats for revenue for each // channel