Skip to content

Commit faa4f24

Browse files
authored
Merge pull request #9182 from ziggie1984/fix-feebuffer
Deprecate dust-threshold config value
2 parents 3a14382 + aebf03a commit faa4f24

File tree

8 files changed

+96
-19
lines changed

8 files changed

+96
-19
lines changed

config.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ type Config struct {
450450

451451
GcCanceledInvoicesOnTheFly bool `long:"gc-canceled-invoices-on-the-fly" description:"If true, we'll delete newly canceled invoices on the fly."`
452452

453-
MaxFeeExposure uint64 `long:"dust-threshold" description:"Sets the max fee exposure in satoshis for a channel after which HTLC's will be failed."`
453+
DustThreshold uint64 `long:"dust-threshold" description:"DEPRECATED: Sets the max fee exposure in satoshis for a channel after which HTLC's will be failed." hidden:"true"`
454+
455+
MaxFeeExposure uint64 `long:"channel-max-fee-exposure" description:" Limits the maximum fee exposure in satoshis of a channel. This value is enforced for all channels and is independent of the channel initiator."`
454456

455457
Fee *lncfg.Fee `group:"fee" namespace:"fee"`
456458

@@ -710,7 +712,6 @@ func DefaultConfig() Config {
710712
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
711713
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
712714
MaxCommitFeeRateAnchors: lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte,
713-
MaxFeeExposure: uint64(htlcswitch.DefaultMaxFeeExposure.ToSatoshis()),
714715
LogRotator: build.NewRotatingLogWriter(),
715716
DB: lncfg.DefaultDB(),
716717
Cluster: lncfg.DefaultCluster(),
@@ -1714,6 +1715,27 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
17141715
cfg.Pprof.MutexProfile = cfg.MutexProfile
17151716
}
17161717

1718+
// Don't allow both the old dust-threshold and the new
1719+
// channel-max-fee-exposure to be set.
1720+
if cfg.DustThreshold != 0 && cfg.MaxFeeExposure != 0 {
1721+
return nil, mkErr("cannot set both dust-threshold and " +
1722+
"channel-max-fee-exposure")
1723+
}
1724+
1725+
switch {
1726+
// Use the old dust-threshold as the max fee exposure if it is set and
1727+
// the new option is not.
1728+
case cfg.DustThreshold != 0:
1729+
cfg.MaxFeeExposure = cfg.DustThreshold
1730+
1731+
// Use the default max fee exposure if the new option is not set and
1732+
// the old one is not set either.
1733+
case cfg.MaxFeeExposure == 0:
1734+
cfg.MaxFeeExposure = uint64(
1735+
htlcswitch.DefaultMaxFeeExposure.ToSatoshis(),
1736+
)
1737+
}
1738+
17171739
// Validate the subconfigs for workers, caches, and the tower client.
17181740
err = lncfg.Validate(
17191741
cfg.Workers,

docs/release-notes/release-notes-0.19.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
these options have also been increased from max 3 log files to 10 and from
140140
max 10 MB to 20 MB.
141141

142+
* [Deprecate `dust-threshold`
143+
config option](https://github.com/lightningnetwork/lnd/pull/9182) and introduce
144+
a new option `channel-max-fee-exposure` which is unambiguous in its description.
145+
The underlying functionality between those two options remain the same.
146+
142147
## Breaking Changes
143148
## Performance Improvements
144149

htlcswitch/link.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,14 +2814,26 @@ func (l *channelLink) exceedsFeeExposureLimit(
28142814
// future commitment transaction with the fee-rate.
28152815
totalLocalDust := localDustSum + lnwire.NewMSatFromSatoshis(localFee)
28162816
if totalLocalDust > l.cfg.MaxFeeExposure {
2817+
l.log.Debugf("ChannelLink(%v): exceeds fee exposure limit: "+
2818+
"local dust: %v, local fee: %v", l.ShortChanID(),
2819+
totalLocalDust, localFee)
2820+
28172821
return true, nil
28182822
}
28192823

28202824
totalRemoteDust := remoteDustSum + lnwire.NewMSatFromSatoshis(
28212825
remoteFee,
28222826
)
28232827

2824-
return totalRemoteDust > l.cfg.MaxFeeExposure, nil
2828+
if totalRemoteDust > l.cfg.MaxFeeExposure {
2829+
l.log.Debugf("ChannelLink(%v): exceeds fee exposure limit: "+
2830+
"remote dust: %v, remote fee: %v", l.ShortChanID(),
2831+
totalRemoteDust, remoteFee)
2832+
2833+
return true, nil
2834+
}
2835+
2836+
return false, nil
28252837
}
28262838

28272839
// isOverexposedWithHtlc calculates whether the proposed HTLC will make the
@@ -2860,8 +2872,10 @@ func (l *channelLink) isOverexposedWithHtlc(htlc *lnwire.UpdateAddHTLC,
28602872
commitFee = l.getCommitFee(true)
28612873
}
28622874

2863-
localDustSum += lnwire.NewMSatFromSatoshis(commitFee)
2864-
remoteDustSum += lnwire.NewMSatFromSatoshis(commitFee)
2875+
commitFeeMSat := lnwire.NewMSatFromSatoshis(commitFee)
2876+
2877+
localDustSum += commitFeeMSat
2878+
remoteDustSum += commitFeeMSat
28652879

28662880
// Calculate the additional fee increase if this is a non-dust HTLC.
28672881
weight := lntypes.WeightUnit(input.HTLCWeight)
@@ -2881,6 +2895,10 @@ func (l *channelLink) isOverexposedWithHtlc(htlc *lnwire.UpdateAddHTLC,
28812895

28822896
if localDustSum > l.cfg.MaxFeeExposure {
28832897
// The max fee exposure was exceeded.
2898+
l.log.Debugf("ChannelLink(%v): HTLC %v makes the channel "+
2899+
"overexposed, total local dust: %v (current commit "+
2900+
"fee: %v)", l.ShortChanID(), htlc, localDustSum)
2901+
28842902
return true
28852903
}
28862904

@@ -2894,7 +2912,16 @@ func (l *channelLink) isOverexposedWithHtlc(htlc *lnwire.UpdateAddHTLC,
28942912
remoteDustSum += additional
28952913
}
28962914

2897-
return remoteDustSum > l.cfg.MaxFeeExposure
2915+
if remoteDustSum > l.cfg.MaxFeeExposure {
2916+
// The max fee exposure was exceeded.
2917+
l.log.Debugf("ChannelLink(%v): HTLC %v makes the channel "+
2918+
"overexposed, total remote dust: %v (current commit "+
2919+
"fee: %v)", l.ShortChanID(), htlc, remoteDustSum)
2920+
2921+
return true
2922+
}
2923+
2924+
return false
28982925
}
28992926

29002927
// dustClosure is a function that evaluates whether an HTLC is dust. It returns

htlcswitch/switch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,8 +4516,8 @@ func TestSwitchDustForwarding(t *testing.T) {
45164516
}
45174517

45184518
// sendDustHtlcs is a helper function used to send many dust HTLC's to test the
4519-
// Switch's dust-threshold logic. It takes a boolean denoting whether or not
4520-
// Alice is the sender.
4519+
// Switch's channel-max-fee-exposure logic. It takes a boolean denoting whether
4520+
// or not Alice is the sender.
45214521
func sendDustHtlcs(t *testing.T, n *threeHopNetwork, alice bool,
45224522
amt lnwire.MilliSatoshi, sid lnwire.ShortChannelID, numHTLCs int) {
45234523

itest/lnd_payment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ func testBidirectionalAsyncPayments(ht *lntest.HarnessTest) {
820820
args := []string{
821821
// Increase the dust threshold to avoid the payments fail due
822822
// to threshold limit reached.
823-
"--dust-threshold=10000000",
823+
"--channel-max-fee-exposure=10000000",
824824

825825
// Increase the pending commit interval since there are lots of
826826
// commitment dances.

lntest/harness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
316316

317317
lndArgs := []string{
318318
"--default-remote-max-htlcs=483",
319-
"--dust-threshold=5000000",
319+
"--channel-max-fee-exposure=5000000",
320320
}
321321

322322
// Start the initial seeder nodes within the test network.

sample-lnd.conf

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,32 @@
474474
; propagation
475475
; max-commit-fee-rate-anchors=10
476476

477-
; A threshold defining the maximum amount of dust a given channel can have
478-
; after which forwarding and sending dust HTLC's to and from the channel will
479-
; fail. This amount is expressed in satoshis.
480-
; dust-threshold=500000
477+
; DEPRECATED: This value will be deprecated please use the new setting
478+
; "channel-max-fee-exposure". This value is equivalent to the new fee exposure
479+
; limit but was removed because the name was ambigious.
480+
; dust-threshold=
481+
482+
; This value replaces the old 'dust-threshold' setting and defines the maximum
483+
; amount of satoshis that a channel pays in fees in case the commitment
484+
; transaction is broadcasted. This is enforced in both directions either when
485+
; we are the channel intiator hence paying the fees but also applies to the
486+
; channel fee if we are NOT the channel initiator. It is
487+
; important to note that every HTLC adds fees to the channel state. Non-dust
488+
; HTLCs add just a new output onto the commitment transaction whereas dust
489+
; HTLCs are completely attributed the commitment fee. So this limit can also
490+
; influence adding new HTLCs onto the state. When the limit is reached we won't
491+
; allow any new HTLCs onto the channel state (outgoing and incoming). So
492+
; choosing a right limit here must be done with caution. Moreover this is a
493+
; limit for all channels universally meaning there is no difference made due to
494+
; the channel size. So it is recommended to use the default value. However if
495+
; you have a very small channel average size you might want to reduce this
496+
; value.
497+
; WARNING: Setting this value too low might cause force closes because the
498+
; lightning protocol has no way to roll back a channel state when your peer
499+
; proposes a channel update which exceeds this limit. There are only two options
500+
; to resolve this situation, either increasing the limit or one side force
501+
; closes the channel.
502+
; channel-max-fee-exposure=500000
481503

482504
; If true, lnd will abort committing a migration if it would otherwise have been
483505
; successful. This leaves the database unmodified, and still compatible with the

scripts/check-sample-lnd-conf.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ OPTIONS_NO_CONF="help lnddir configfile version end"
5454
# OPTIONS_NO_LND_DEFAULT_VALUE_CHECK is a list of options with default values
5555
# set, but there aren't any returned defaults by lnd --help. Defaults have to be
5656
# included in sample-lnd.conf but no further checks are performed.
57-
OPTIONS_NO_LND_DEFAULT_VALUE_CHECK="adminmacaroonpath readonlymacaroonpath \
58-
invoicemacaroonpath rpclisten restlisten listen backupfilepath maxchansize \
59-
bitcoin.chaindir bitcoin.defaultchanconfs bitcoin.defaultremotedelay \
60-
bitcoin.dnsseed signrpc.signermacaroonpath walletrpc.walletkitmacaroonpath \
61-
chainrpc.notifiermacaroonpath routerrpc.routermacaroonpath"
57+
OPTIONS_NO_LND_DEFAULT_VALUE_CHECK="channel-max-fee-exposure adminmacaroonpath \
58+
readonlymacaroonpath invoicemacaroonpath rpclisten restlisten listen \
59+
backupfilepath maxchansize bitcoin.chaindir bitcoin.defaultchanconfs \
60+
bitcoin.defaultremotedelay bitcoin.dnsseed signrpc.signermacaroonpath \
61+
walletrpc.walletkitmacaroonpath chainrpc.notifiermacaroonpath \
62+
routerrpc.routermacaroonpath"
6263

6364

6465
# EXITCODE is returned at the end after all checks are performed and set to 1

0 commit comments

Comments
 (0)