multi: Inbound fees are retained when not provided

Fixes the problem that inbound base fee and fee rate are overwritten
with 0 if they are not specified in PolicyUpdateRequest. This ensures
backward compatibility with older rpc clients that do not yet support
the inbound feature.
This commit is contained in:
feelancer21
2024-05-14 00:21:26 +02:00
parent 87d5170dec
commit f62c00fe34
8 changed files with 1457 additions and 1322 deletions

View File

@@ -46,6 +46,7 @@ import (
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
@@ -7216,27 +7217,35 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
}
// By default, positive inbound fees are rejected.
if !r.cfg.AcceptPositiveInboundFees {
if req.InboundBaseFeeMsat > 0 {
if !r.cfg.AcceptPositiveInboundFees && req.InboundFee != nil {
if req.InboundFee.BaseFeeMsat > 0 {
return nil, fmt.Errorf("positive values for inbound "+
"base fee msat are not supported: %v",
req.InboundBaseFeeMsat)
req.InboundFee.BaseFeeMsat)
}
if req.InboundFeeRatePpm > 0 {
if req.InboundFee.FeeRatePpm > 0 {
return nil, fmt.Errorf("positive values for inbound "+
"fee rate ppm are not supported: %v",
req.InboundFeeRatePpm)
req.InboundFee.FeeRatePpm)
}
}
// If no inbound fees have been specified, we indicate with an empty
// option that the previous inbound fee should be retained during the
// edge update.
inboundFee := fn.None[models.InboundFee]()
if req.InboundFee != nil {
inboundFee = fn.Some(models.InboundFee{
Base: req.InboundFee.BaseFeeMsat,
Rate: req.InboundFee.FeeRatePpm,
})
}
baseFeeMsat := lnwire.MilliSatoshi(req.BaseFeeMsat)
feeSchema := routing.FeeSchema{
BaseFee: baseFeeMsat,
FeeRate: feeRateFixed,
InboundFee: models.InboundFee{
Base: req.InboundBaseFeeMsat,
Rate: req.InboundFeeRatePpm,
},
BaseFee: baseFeeMsat,
FeeRate: feeRateFixed,
InboundFee: inboundFee,
}
maxHtlc := lnwire.MilliSatoshi(req.MaxHtlcMsat)