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

sweeper: lower the default max fee rate and make it configurable #7823

Merged
merged 8 commits into from
Sep 20, 2023

Conversation

yyforyongyu
Copy link
Member

@yyforyongyu yyforyongyu commented Jul 12, 2023

This PR decreases the max fee rate by 10x and makes it configurable.


This change is Reviewable

@yyforyongyu yyforyongyu self-assigned this Jul 12, 2023
@yyforyongyu yyforyongyu added fees Related to the fees paid for transactions (both LN and funding/commitment transactions) utxo sweeping labels Jul 12, 2023
lncfg/sweeper.go Outdated
)

//nolint:lll
type Sweeper struct {
BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."`
BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."`
MaxFeeRate chainfee.SatPerKWeight `long:"maxfeerate" description:"Maximum fee rate in sat/kw that the sweeper is allowed to pay."`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be in sat/vb? that way users don't need to do the conversion to sat/kw?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sat/vb can be nice, tho one day we may want it to be decimal or use sat/kvb instead in case bitcoin goes to 1m.

sample-lnd.conf Outdated Show resolved Hide resolved
@feelancer21
Copy link
Contributor

Thank you for the pull request. I agree with giving more control over the feerates for sweeps. However, I am cautious about the proposed minimum limit of 100 sat/vb. I would prefer to completely remove the limit and instead provide a clear warning message in the sample-lnd.conf and the help section, emphasizing that setting too low of a value could risk the funds. All Noderunners who still decide to modify the option despite the warning will presumably be aware of the potential risks.

Even with 100 sat/vb, there is no guarantee that all funds will be safely swept. In early May, some cases required as much as 500 sat/vb.

Copy link
Member Author

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Noderunners who still decide to modify the option despite the warning will presumably be aware of the potential risks.

I'm getting very different feedback here. Tho I'm leaning towards making it purely determined by node runners, some sanity check here is necessary - you will only hit this number if the mempool is very congested, in which case you probably wanna have a higher fee rate. If we decide to remove the limits, I'd say we should remove it gradually. Plus in my mind, a better config for the sweeper is to limit by fees paid proportional to the input value, not fee rate, which is something I'm working on atm.

Even with 100 sat/vb, there is no guarantee that all funds will be safely swept. In early May, some cases required as much as 500 sat/vb.

Yeah that's why we have a default of 1000.

lncfg/sweeper.go Outdated
)

//nolint:lll
type Sweeper struct {
BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."`
BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."`
MaxFeeRate chainfee.SatPerKWeight `long:"maxfeerate" description:"Maximum fee rate in sat/kw that the sweeper is allowed to pay."`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sat/vb can be nice, tho one day we may want it to be decimal or use sat/kvb instead in case bitcoin goes to 1m.

lncfg/sweeper.go Show resolved Hide resolved
sample-lnd.conf Outdated Show resolved Hide resolved
@yyforyongyu yyforyongyu force-pushed the lower-max-fee-rate branch 2 times, most recently from e7a1418 to 804ed98 Compare July 26, 2023 09:12
@yyforyongyu yyforyongyu requested review from Roasbeef and removed request for feelancer21 and Roasbeef August 10, 2023 17:41
@yyforyongyu
Copy link
Member Author

cc @ziggie1984

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TACK. I think it is definitely worth decreasing the max fee rate giving node runners a piece of mind so that their sweep fees will not skyrock.
This fee limit relates to the effective feerate currently meaning that when we CPFP a transaction fees can even go higher and here I would suggest to limit the fee rate to the maximum fee rate of a transaction. CPFPing big parents (big commitment transaction) could overshoot this limit highly and I think users are not aware of this wdyt ?

I am in favour of setting a minimum and allow for a gradual change. Different inputs have different priorities in terms of getting confirmed so I highly recommend to add a limit so that node runners do not shoot themselves into the foot.

Reviewed 8 of 11 files at r1.
Reviewable status: 8 of 11 files reviewed, 8 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @yyforyongyu)


sample-lnd.conf line 1785 at r1 (raw file):

; sweeper.batchwindowduration=30s

; The max fee rate in sat/vb can be used when sweeping funds. Setting this

... in sat/vb which can be ....


sample-lnd.conf line 1787 at r1 (raw file):

; The max fee rate in sat/vb can be used when sweeping funds. Setting this
; value too low can result in transactions not being confirmed in time, causing
; HTLCs to expire.

... HTLCs to expire hence potentially losing funds.


docs/release-notes/release-notes-0.17.0.md line 133 at r1 (raw file):

  time, which could result in fund loss.
  Please note that the actual fee rate to be used is deteremined by the fee
  estimator used(for instance `bitcoind`), and this value is a cap on the max

I think it is worth pointing out, that the fee estimation is not really capped at the value 1000 but rather fee estimation fails completely when overestimating ?


sweep/sweeper.go line 500 at r1 (raw file):

			"rate %v, minimum is %v", feeRate, s.relayFeeRate)
	}
	if feeRate > s.cfg.MaxFeeRate.FeePerKWeight() {

What do you think about capping the value here instead of returning an error, rather publish a transaction with the capped limit than not publishing at all?

Copy link
Member Author

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 8 of 11 files reviewed, 8 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @ziggie1984)


sample-lnd.conf line 1785 at r1 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

... in sat/vb which can be ....

Done.


sample-lnd.conf line 1787 at r1 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

... HTLCs to expire hence potentially losing funds.

Done.


docs/release-notes/release-notes-0.17.0.md line 133 at r1 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

I think it is worth pointing out, that the fee estimation is not really capped at the value 1000 but rather fee estimation fails completely when overestimating ?

What do you mean fee estimation fails completely when overestimating ??


sweep/sweeper.go line 500 at r1 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

What do you think about capping the value here instead of returning an error, rather publish a transaction with the capped limit than not publishing at all?

Yeah I like it, but let's do it in another PR to limit the scope.

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 11 files reviewed, 8 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @yyforyongyu)


docs/release-notes/release-notes-0.17.0.md line 133 at r1 (raw file):

Previously, yyforyongyu (Yong) wrote…

What do you mean fee estimation fails completely when overestimating ??

meaning that we fail the fee-estimation when we overestimate rather than cap on the max, for me cap on the max means we cap it and return, relates to the comment where I suggest capping the value to the max fee instead of failing.

Copy link
Member Author

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 11 files reviewed, 8 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @ziggie1984)


docs/release-notes/release-notes-0.17.0.md line 133 at r1 (raw file):

Previously, ziggie1984 (ziggieXXX) wrote…

meaning that we fail the fee-estimation when we overestimate rather than cap on the max, for me cap on the max means we cap it and return, relates to the comment where I suggest capping the value to the max fee instead of failing.

gotya, yeah make sense. Added a commit to cap it instead as I think it'd be confusing if we change the behavior again and update the release notes. Will see the build results, hopefully it's a small change.

Copy link
Member Author

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't CPFP should or would go over the limit? We have a check here, https://github.com/lightningnetwork/lnd/blob/master/sweep/sweeper.go#L995

So we'd do CPFP only when the newly estimated fee rate exceeds the parent fee rate. But I do remember some issues related to the parent fee calculation, but yeah we shouldn't allow it to happen.

Reviewable status: 3 of 11 files reviewed, 8 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @ziggie1984)

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool PR, I like that we also cap now the child transaction as well :)

Apart from the logging of feerates instead of absolute fees this PR ready to hit the road
:lgtm:

Reviewed 2 of 11 files at r1, 1 of 11 files at r4.
Reviewable status: 6 of 20 files reviewed, 7 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @yyforyongyu)


-- commits line 26 at r4:
Nit s/the/when/g


sweep/weight_estimator.go line 136 at r4 (raw file):

	maxFee := w.maxFeeRate.FeeForWeight(childWeight)
	if fee > maxFee {
		log.Warnf("Estimated fee %v exceeds max allowed fee %v, using "+

can we log the feer rates instead of the absolute fee values or maybe both ?


sweep/weight_estimator_test.go line 107 at r4 (raw file):

	require.NoError(t, w.add(&childInput))

	// The child weight should be 322 bytes.

weight units rather than bytes ?

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@saubyk saubyk added this to the v0.18.0 milestone Aug 29, 2023
@yyforyongyu yyforyongyu changed the base branch from master to 0-18-staging September 1, 2023 09:20
sweep/sweeper.go Outdated Show resolved Hide resolved
itest/lnd_onchain_test.go Outdated Show resolved Hide resolved
sweep/sweeper.go Show resolved Hide resolved
lncfg/sweeper.go Show resolved Hide resolved
}

// Clamp the fee to the max fee rate.
maxFee := w.maxFeeRate.FeeForWeight(childWeight)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR: I think we should be using a different function in the non-channel code because FeeForWeight rounds down and is necessary to agree on a fee with your peer, but in the sweeper and other places you can round up

@@ -118,11 +121,12 @@ type txInputSet struct {
}

// newTxInputSet constructs a new, empty input set.
func newTxInputSet(wallet Wallet, feePerKW chainfee.SatPerKWeight,
func newTxInputSet(wallet Wallet, feePerKW, maxFeeRrate chainfee.SatPerKWeight,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maxFeeRate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@lightninglabs-deploy
Copy link

@yyforyongyu, remember to re-request review from reviewers when ready

Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit

sweep/weight_estimator.go Show resolved Hide resolved
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 17 files at r6, all commit messages.
Reviewable status: 4 of 21 files reviewed, 11 unresolved discussions (waiting on @Crypt-iQ, @feelancer21, and @yyforyongyu)


docs/release-notes/release-notes-0.18.0.md line 32 at r8 (raw file):

  time, which could result in fund loss.
  Please note that the actual fee rate to be used is deteremined by the fee
  estimator used(for instance `bitcoind`), and this value is a cap on the max

Nit: Space

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥨

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two inputs from my end, other than that looks good!

lncfg/sweeper.go Outdated Show resolved Hide resolved
lncfg/sweeper.go Outdated Show resolved Hide resolved
This commit caps the estimated fee rate at the configged max fee rate
instead of returning an error.
This commit updates the `fee()` method in `weightEstimator` to make sure
when doing CPFP we are not exceeding the max allowed fee rate. In order
to use the max fee rate, we need to modify several methods to pass the
configured value to the estimator.
@guggero guggero merged commit 27aab00 into lightningnetwork:0-18-staging Sep 20, 2023
23 of 25 checks passed
@yyforyongyu yyforyongyu deleted the lower-max-fee-rate branch September 20, 2023 11:54
funds. The default value is 1000 sat/vb. Setting this value below 100 sat/vb
is not allowed, as low fee rate can cause transactions not confirming in
time, which could result in fund loss.
Please note that the actual fee rate to be used is deteremined by the fee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deteremined -> determined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fees Related to the fees paid for transactions (both LN and funding/commitment transactions) utxo sweeping
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants