Skip to content

Commit 9890d74

Browse files
committed
multi: set the InboundFee on ChannelEdgePolicy
In this commit, we make sure to set the new field wherever appropriate. This will be any place where the ChannelEdgePolicy is constructed other than its disk deserialisation.
1 parent 1d16221 commit 9890d74

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

discovery/gossiper.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,26 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
32603260
ExtraOpaqueData: upd.ExtraOpaqueData,
32613261
}
32623262

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+
32633283
if err := d.cfg.Graph.UpdateEdge(update, ops...); err != nil {
32643284
if graph.IsError(
32653285
err, graph.ErrOutdated,

graph/builder.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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"
1415
graphdb "github.com/lightningnetwork/lnd/graph/db"
1516
"github.com/lightningnetwork/lnd/graph/db/models"
1617
"github.com/lightningnetwork/lnd/lnutils"
@@ -943,7 +944,7 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
943944
return false
944945
}
945946

946-
err = b.UpdateEdge(&models.ChannelEdgePolicy{
947+
update := &models.ChannelEdgePolicy{
947948
SigBytes: msg.Signature.ToSignatureBytes(),
948949
ChannelID: msg.ShortChannelID.ToUint64(),
949950
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
@@ -955,7 +956,25 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
955956
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
956957
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
957958
ExtraOpaqueData: msg.ExtraOpaqueData,
958-
})
959+
}
960+
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+
977+
err = b.UpdateEdge(update)
959978
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
960979
log.Errorf("Unable to apply channel update: %v", err)
961980
return false

graph/notifications_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID,
121121
FeeBaseMSat: lnwire.MilliSatoshi(prand.Int31()),
122122
FeeProportionalMillionths: lnwire.MilliSatoshi(prand.Int31()),
123123
ToNode: node.PubKeyBytes,
124+
InboundFee: fn.Some(inboundFee),
124125
ExtraOpaqueData: extraOpaqueData,
125126
}, nil
126127
}

routing/localchans/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,10 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
127127
Edge: edge,
128128
})
129129

130-
// Extract inbound fees from the ExtraOpaqueData.
131130
var inboundWireFee lnwire.Fee
132-
_, err = edge.ExtraOpaqueData.ExtractRecords(&inboundWireFee)
133-
if err != nil {
134-
return err
135-
}
131+
edge.InboundFee.WhenSome(func(fee lnwire.Fee) {
132+
inboundWireFee = fee
133+
})
136134
inboundFee := models.NewInboundFeeFromWire(inboundWireFee)
137135

138136
// Add updated policy to list of policies to send to switch.
@@ -372,6 +370,8 @@ func (r *Manager) updateEdge(chanPoint wire.OutPoint,
372370
err = fn.MapOptionZ(newSchema.InboundFee,
373371
func(f models.InboundFee) error {
374372
inboundWireFee := f.ToWire()
373+
edge.InboundFee = fn.Some(inboundWireFee)
374+
375375
return edge.ExtraOpaqueData.PackRecords(
376376
&inboundWireFee,
377377
)

0 commit comments

Comments
 (0)