discovery+graph: get inbound fee directly from ChannelUpdate
Remove the previously added TODOs which would extract InboundFee info from the ExtraOpaqueData of a ChannelUpdate at the time of ChannelEdgePolicy construction. These can now be replaced by using the newly added InboundFee record on the ChannelUpdate message.
This commit is contained in:
3 files changed
+11
-38
No files matched your search
+1
-20
@@ -3257,29 +3257,10 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
|||||||
MaxHTLC: upd.HtlcMaximumMsat,
|
MaxHTLC: upd.HtlcMaximumMsat,
|
||||||
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
|
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
|
||||||
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
|
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
|
||||||
|
InboundFee: upd.InboundFee.ValOpt(),
|
||||||
ExtraOpaqueData: upd.ExtraOpaqueData,
|
ExtraOpaqueData: upd.ExtraOpaqueData,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the inbound fee from the ExtraOpaqueData, if present.
|
|
||||||
//
|
|
||||||
// TODO(elle): this can be removed once we define the optional TLV
|
|
||||||
// field on the lnwire.ChannelUpdate itself.
|
|
||||||
var inboundFee lnwire.Fee
|
|
||||||
typeMap, err := upd.ExtraOpaqueData.ExtractRecords(&inboundFee)
|
|
||||||
if err != nil {
|
|
||||||
rErr := fmt.Errorf("%w: %w", graphdb.ErrParsingExtraTLVBytes,
|
|
||||||
err)
|
|
||||||
|
|
||||||
log.Error(rErr)
|
|
||||||
nMsg.err <- rErr
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok := typeMap[lnwire.FeeRecordType]
|
|
||||||
if ok && val == nil {
|
|
||||||
update.InboundFee = fn.Some(inboundFee)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := d.cfg.Graph.UpdateEdge(update, ops...); err != nil {
|
if err := d.cfg.Graph.UpdateEdge(update, ops...); err != nil {
|
||||||
if graph.IsError(
|
if graph.IsError(
|
||||||
err, graph.ErrOutdated,
|
err, graph.ErrOutdated,
|
||||||
|
|||||||
+1
-17
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/fn/v2"
|
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lnutils"
|
"github.com/lightningnetwork/lnd/lnutils"
|
||||||
@@ -955,25 +954,10 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
|
|||||||
MaxHTLC: msg.HtlcMaximumMsat,
|
MaxHTLC: msg.HtlcMaximumMsat,
|
||||||
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
|
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
|
||||||
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
||||||
|
InboundFee: msg.InboundFee.ValOpt(),
|
||||||
ExtraOpaqueData: msg.ExtraOpaqueData,
|
ExtraOpaqueData: msg.ExtraOpaqueData,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the inbound fee from the ExtraOpaqueData, if present.
|
|
||||||
//
|
|
||||||
// TODO(elle): this can be removed once we define the optional TLV
|
|
||||||
// field on the lnwire.ChannelUpdate itself.
|
|
||||||
var inboundFee lnwire.Fee
|
|
||||||
typeMap, err := update.ExtraOpaqueData.ExtractRecords(&inboundFee)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("%v: %v", graphdb.ErrParsingExtraTLVBytes, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val, ok := typeMap[lnwire.FeeRecordType]
|
|
||||||
if ok && val == nil {
|
|
||||||
update.InboundFee = fn.Some(inboundFee)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = b.UpdateEdge(update)
|
err = b.UpdateEdge(update)
|
||||||
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
|
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
|
||||||
log.Errorf("Unable to apply channel update: %v", err)
|
log.Errorf("Unable to apply channel update: %v", err)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,7 +139,7 @@ func ExtractChannelUpdate(ownerPubKey []byte,
|
|||||||
func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
|
func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
|
||||||
policy *models.ChannelEdgePolicy) *lnwire.ChannelUpdate1 {
|
policy *models.ChannelEdgePolicy) *lnwire.ChannelUpdate1 {
|
||||||
|
|
||||||
return &lnwire.ChannelUpdate1{
|
update := &lnwire.ChannelUpdate1{
|
||||||
ChainHash: info.ChainHash,
|
ChainHash: info.ChainHash,
|
||||||
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
|
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
|
||||||
Timestamp: uint32(policy.LastUpdate.Unix()),
|
Timestamp: uint32(policy.LastUpdate.Unix()),
|
||||||
@@ -151,6 +152,13 @@ func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
|
|||||||
FeeRate: uint32(policy.FeeProportionalMillionths),
|
FeeRate: uint32(policy.FeeProportionalMillionths),
|
||||||
ExtraOpaqueData: policy.ExtraOpaqueData,
|
ExtraOpaqueData: policy.ExtraOpaqueData,
|
||||||
}
|
}
|
||||||
|
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
|
||||||
|
update.InboundFee = tlv.SomeRecordT(
|
||||||
|
tlv.NewRecordT[tlv.TlvType55555, lnwire.Fee](fee),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return update
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
||||||
|
|||||||
Reference in new issue
Block a user