Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only Update Inbound Fee if specified. #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,12 @@ func updateChannelPolicy(ctx *cli.Context) error {
InboundFeeRatePpm: int32(inboundFeeRatePpm),
}

// Only apply the inbound fees if they are specified.
if ctx.IsSet("inbound_base_fee_msat") ||
ctx.IsSet("inbound_fee_rate_ppm") {
req.InboundFeeSpecified = true
}

if ctx.IsSet("min_htlc_msat") {
req.MinHtlcMsat = ctx.Uint64("min_htlc_msat")
req.MinHtlcMsatSpecified = true
Expand Down
1,612 changes: 812 additions & 800 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4404,6 +4404,9 @@ message PolicyUpdateRequest {

int32 inbound_base_fee_msat = 10;
int32 inbound_fee_rate_ppm = 11;

// If true, inbound_base_fee_msat and inbound_fee_rate_ppm are applied.
bool inbound_fee_specified = 12;
}

enum UpdateFailure {
Expand Down
4 changes: 4 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6592,6 +6592,10 @@
"inbound_fee_rate_ppm": {
"type": "integer",
"format": "int32"
},
"inbound_fee_specified": {
"type": "boolean",
"description": "If true, inbound_base_fee_msat and inbound_fee_rate_ppm are applied."
}
}
},
Expand Down
29 changes: 22 additions & 7 deletions routing/localchans/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
return nil
}

// extract the inbound fees from the edge we just updated.
var inboundFee lnwire.Fee
_, err = edge.ExtraOpaqueData.ExtractRecords(&inboundFee)
// We only handle chan policies of ourselves which works with
// or without specified inbound fees. So having a decoding error
// reveils another problem.
if err != nil {
return err
}

// Add updated edge to list of edges to send to gossiper.
edgesToUpdate = append(edgesToUpdate, discovery.EdgeWithInfo{
Info: info,
Expand All @@ -112,7 +122,9 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
TimeLockDelta: uint32(edge.TimeLockDelta),
MinHTLCOut: edge.MinHTLC,
MaxHTLC: edge.MaxHTLC,
InboundFee: newSchema.InboundFee,
InboundFee: models.NewInboundFeeFromWire(
inboundFee,
),
}

return nil
Expand Down Expand Up @@ -182,9 +194,14 @@ func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint,
newSchema.FeeRate,
)

inboundFee := newSchema.InboundFee.ToWire()
if err := edge.ExtraOpaqueData.PackRecords(&inboundFee); err != nil {
return err
if !newSchema.InboundFee.IsNone() {
inboundFee := newSchema.InboundFee.UnsafeFromSome()
inboundWireFee := inboundFee.ToWire()

err := edge.ExtraOpaqueData.PackRecords(&inboundWireFee)
if err != nil {
return err
}
}

edge.TimeLockDelta = uint16(newSchema.TimeLockDelta)
Expand Down Expand Up @@ -215,9 +232,7 @@ func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint,
}

// If a new min htlc is specified, update the edge.
if newSchema.MinHTLC != nil {
edge.MinHTLC = *newSchema.MinHTLC
}
edge.MinHTLC = newSchema.MinHTLC.UnwrapOr(edge.MinHTLC)

// If the MaxHtlc flag wasn't already set, we can set it now.
edge.MessageFlags |= lnwire.ChanUpdateRequiredMaxHtlc
Expand Down
5 changes: 3 additions & 2 deletions routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/kvdb"
Expand Down Expand Up @@ -290,7 +291,7 @@ type FeeSchema struct {

// InboundFee is the inbound fee schedule that applies to forwards
// coming in through a channel to which this FeeSchema pertains.
InboundFee models.InboundFee
InboundFee fn.Option[models.InboundFee]
}

// ChannelPolicy holds the parameters that determine the policy we enforce
Expand All @@ -310,7 +311,7 @@ type ChannelPolicy struct {

// MinHTLC is the minimum HTLC size including fees we are allowed to
// forward over this channel.
MinHTLC *lnwire.MilliSatoshi
MinHTLC fn.Option[lnwire.MilliSatoshi]
}

// Config defines the configuration for the ChannelRouter. ALL elements within
Expand Down
25 changes: 16 additions & 9 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -7208,21 +7209,27 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
}
}

baseFeeMsat := lnwire.MilliSatoshi(req.BaseFeeMsat)
feeSchema := routing.FeeSchema{
BaseFee: baseFeeMsat,
FeeRate: feeRateFixed,
InboundFee: models.InboundFee{
// In case inbound fees are not specified no inbound fees will be
// applied but the previous value will be kept.
inboundFee := fn.None[models.InboundFee]()
if req.InboundFeeSpecified {
inboundFee = fn.Some(models.InboundFee{
Base: req.InboundBaseFeeMsat,
Rate: req.InboundFeeRatePpm,
},
})
}

baseFeeMsat := lnwire.MilliSatoshi(req.BaseFeeMsat)
feeSchema := routing.FeeSchema{
BaseFee: baseFeeMsat,
FeeRate: feeRateFixed,
InboundFee: inboundFee,
}

maxHtlc := lnwire.MilliSatoshi(req.MaxHtlcMsat)
var minHtlc *lnwire.MilliSatoshi
minHtlc := fn.None[lnwire.MilliSatoshi]()
if req.MinHtlcMsatSpecified {
min := lnwire.MilliSatoshi(req.MinHtlcMsat)
minHtlc = &min
minHtlc = fn.Some(lnwire.MilliSatoshi(req.MinHtlcMsat))
}

chanPolicy := routing.ChannelPolicy{
Expand Down
Loading