mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
lnwire+channeldb: parse inbound fees
In this commit, the tlv extension of a channel update message is parsed. If an inbound fee schedule is encountered, it is reported in the graph rpc calls.
This commit is contained in:
21
rpcserver.go
21
rpcserver.go
@ -6059,6 +6059,23 @@ func marshalExtraOpaqueData(data []byte) map[uint64][]byte {
|
||||
return records
|
||||
}
|
||||
|
||||
// extractInboundFeeSafe tries to extract the inbound fee from the given extra
|
||||
// opaque data tlv block. If parsing fails, a zero inbound fee is returned. This
|
||||
// function is typically used on unvalidated data coming stored in the database.
|
||||
// There is not much we can do other than ignoring errors here.
|
||||
func extractInboundFeeSafe(data lnwire.ExtraOpaqueData) lnwire.Fee {
|
||||
var inboundFee lnwire.Fee
|
||||
|
||||
_, err := data.ExtractRecords(&inboundFee)
|
||||
if err != nil {
|
||||
// Return zero fee. Do not return the inboundFee variable
|
||||
// because it may be undefined.
|
||||
return lnwire.Fee{}
|
||||
}
|
||||
|
||||
return inboundFee
|
||||
}
|
||||
|
||||
func marshalDBEdge(edgeInfo *models.ChannelEdgeInfo,
|
||||
c1, c2 *models.ChannelEdgePolicy) *lnrpc.ChannelEdge {
|
||||
|
||||
@ -6108,6 +6125,7 @@ func marshalDBRoutingPolicy(
|
||||
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
|
||||
|
||||
customRecords := marshalExtraOpaqueData(policy.ExtraOpaqueData)
|
||||
inboundFee := extractInboundFeeSafe(policy.ExtraOpaqueData)
|
||||
|
||||
return &lnrpc.RoutingPolicy{
|
||||
TimeLockDelta: uint32(policy.TimeLockDelta),
|
||||
@ -6118,6 +6136,9 @@ func marshalDBRoutingPolicy(
|
||||
Disabled: disabled,
|
||||
LastUpdate: uint32(policy.LastUpdate.Unix()),
|
||||
CustomRecords: customRecords,
|
||||
|
||||
InboundFeeBaseMsat: inboundFee.BaseFee,
|
||||
InboundFeeRateMilliMsat: inboundFee.FeeRate,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user