Skip to content

Commit 6d8bc63

Browse files
committed
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.
1 parent 420001a commit 6d8bc63

File tree

3 files changed

+11
-38
lines changed

3 files changed

+11
-38
lines changed

discovery/gossiper.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,29 +3257,10 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
32573257
MaxHTLC: upd.HtlcMaximumMsat,
32583258
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
32593259
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
3260+
InboundFee: upd.InboundFee.ValOpt(),
32603261
ExtraOpaqueData: upd.ExtraOpaqueData,
32613262
}
32623263

3263-
// Extract the inbound fee from the ExtraOpaqueData, if present.
3264-
//
3265-
// TODO(elle): this can be removed once we define the optional TLV
3266-
// field on the lnwire.ChannelUpdate itself.
3267-
var inboundFee lnwire.Fee
3268-
typeMap, err := upd.ExtraOpaqueData.ExtractRecords(&inboundFee)
3269-
if err != nil {
3270-
rErr := fmt.Errorf("%w: %w", graphdb.ErrParsingExtraTLVBytes,
3271-
err)
3272-
3273-
log.Error(rErr)
3274-
nMsg.err <- rErr
3275-
return nil, false
3276-
}
3277-
3278-
val, ok := typeMap[lnwire.FeeRecordType]
3279-
if ok && val == nil {
3280-
update.InboundFee = fn.Some(inboundFee)
3281-
}
3282-
32833264
if err := d.cfg.Graph.UpdateEdge(update, ops...); err != nil {
32843265
if graph.IsError(
32853266
err, graph.ErrOutdated,

graph/builder.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/go-errors/errors"
1212
"github.com/lightningnetwork/lnd/batch"
1313
"github.com/lightningnetwork/lnd/chainntnfs"
14-
"github.com/lightningnetwork/lnd/fn/v2"
1514
graphdb "github.com/lightningnetwork/lnd/graph/db"
1615
"github.com/lightningnetwork/lnd/graph/db/models"
1716
"github.com/lightningnetwork/lnd/lnutils"
@@ -955,25 +954,10 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
955954
MaxHTLC: msg.HtlcMaximumMsat,
956955
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
957956
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
957+
InboundFee: msg.InboundFee.ValOpt(),
958958
ExtraOpaqueData: msg.ExtraOpaqueData,
959959
}
960960

961-
// Extract the inbound fee from the ExtraOpaqueData, if present.
962-
//
963-
// TODO(elle): this can be removed once we define the optional TLV
964-
// field on the lnwire.ChannelUpdate itself.
965-
var inboundFee lnwire.Fee
966-
typeMap, err := update.ExtraOpaqueData.ExtractRecords(&inboundFee)
967-
if err != nil {
968-
log.Errorf("%v: %v", graphdb.ErrParsingExtraTLVBytes, err)
969-
return false
970-
}
971-
972-
val, ok := typeMap[lnwire.FeeRecordType]
973-
if ok && val == nil {
974-
update.InboundFee = fn.Some(inboundFee)
975-
}
976-
977961
err = b.UpdateEdge(update)
978962
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
979963
log.Errorf("Unable to apply channel update: %v", err)

netann/channel_update.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/lightningnetwork/lnd/keychain"
1414
"github.com/lightningnetwork/lnd/lnwallet"
1515
"github.com/lightningnetwork/lnd/lnwire"
16+
"github.com/lightningnetwork/lnd/tlv"
1617
"github.com/pkg/errors"
1718
)
1819

@@ -138,7 +139,7 @@ func ExtractChannelUpdate(ownerPubKey []byte,
138139
func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
139140
policy *models.ChannelEdgePolicy) *lnwire.ChannelUpdate1 {
140141

141-
return &lnwire.ChannelUpdate1{
142+
update := &lnwire.ChannelUpdate1{
142143
ChainHash: info.ChainHash,
143144
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
144145
Timestamp: uint32(policy.LastUpdate.Unix()),
@@ -151,6 +152,13 @@ func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
151152
FeeRate: uint32(policy.FeeProportionalMillionths),
152153
ExtraOpaqueData: policy.ExtraOpaqueData,
153154
}
155+
policy.InboundFee.WhenSome(func(fee lnwire.Fee) {
156+
update.InboundFee = tlv.SomeRecordT(
157+
tlv.NewRecordT[tlv.TlvType55555, lnwire.Fee](fee),
158+
)
159+
})
160+
161+
return update
154162
}
155163

156164
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge

0 commit comments

Comments
 (0)