Commit Graph

16583 Commits

Author SHA1 Message Date
yyforyongyu
9c1e6941c3
contractcourt: specify deadline and budget for nursery 2024-04-19 21:33:34 +08:00
yyforyongyu
33abbe1942
contractcourt+lnd: make IncubateOutputs take fn.Option
`IncubateOutputs` never takes more than one HTLC, so we change the
params to be optional, which helps with the following commit where we
pass the deadline height when incubating outgoing HTLCs.
2024-04-19 21:33:34 +08:00
yyforyongyu
6f0c2b5bab
contractcourt: specify deadline and budget for anchor output 2024-04-19 21:33:34 +08:00
yyforyongyu
f4035ade05
contractcourt: calculate value left when searching for commit deadline
This commit changes `findCommitmentDeadline` to
`findCommitmentDeadlineAndValue` to calculate the value left from all
the time-sensitive HTLCs after subtracting their budgets. This value is
then used to calculate the budget to be used when sweeping the anchor
output.
2024-04-19 21:33:34 +08:00
yyforyongyu
cab180a52e
contractcourt: specify deadline and budget for htlc timeout 2024-04-19 21:33:34 +08:00
yyforyongyu
d1ad07fa21
contractcourt+lnwallet: specify deadline and budget for htlc success 2024-04-19 21:33:33 +08:00
yyforyongyu
01fd4e5642
contractcourt: specify deadline and budget for commit sweep 2024-04-19 21:33:33 +08:00
yyforyongyu
aa44197f88
contractcourt: init BudgetConfig in unit tests 2024-04-19 21:33:33 +08:00
yyforyongyu
0a611aae00
multi: add new config option BudgetConfig and NoDeadlineConfTarget
This commit adds a new group config `BudgetConfig` to allow users
specifying their own preference when sweeping outputs. And a new config
option `NoDeadlineConfTarget` is added in case the user wants to use a
different "lazy" conf target.
2024-04-19 21:33:33 +08:00
yyforyongyu
c44b8a4b45
lnd: start using BudgetAggregator 2024-04-19 21:33:33 +08:00
yyforyongyu
54ade99ce2
sweep: apply fn.NewSet and fn.Map in validateInputs 2024-04-19 21:33:33 +08:00
yyforyongyu
4c13ea1747
sweep: pass default deadline height when clustering inputs
This commit changes the method `ClusterInputs` to also take a default
deadline height. Previously, when calculating the default deadline
height for a non-time sensitive input, we would first cluster it with
other non-time sensitive inputs, then give it a deadline before we are
about to `sweep`. This is now moved to the step where we decide to
cluster inputs, allowing time-sensitive and non-sensitive inputs to be
grouped together, if they happen to share the same deadline heights.
2024-04-19 21:33:32 +08:00
yyforyongyu
15588355b3
sweep: exit when handleNewInput fails
When `handleNewInput` fails, it means there's something terribly wrong
with the chain backend, which means we need to stop the current process
and let user handle it.
2024-04-19 21:33:32 +08:00
yyforyongyu
e771993785
multi: make input.OutPoint return wire.OutPoint 2024-04-19 21:33:32 +08:00
yyforyongyu
fce86f9b22
sweep: cancel rebroadcasting of failed/replaced/confirmed txns 2024-04-19 21:33:32 +08:00
yyforyongyu
106b97ce33
sweep: improve loggings 2024-04-19 21:33:32 +08:00
yyforyongyu
59526988cf
sweep: add a dedicated method to create sweeping txns
This takes the old `createSweepTx` and refactors it to be
sweep-specific. A sweeping txns differs from a normal tx as it doesn't
need to take outputs as params.
2024-04-19 21:33:32 +08:00
yyforyongyu
59fbcb18d5
sweep: rename fee() to feeWithParent() for clarity
To make sure the caller has a better idea about what this method is
doing.
2024-04-19 21:33:31 +08:00
yyforyongyu
370e4ce98d
lnd+sweep: remove unused config MaxSweepAttempts 2024-04-19 21:33:31 +08:00
yyforyongyu
0b30d4ba3e
lnrpc+sweep: make FeeEstimateInfo an optional param
This is needed as we soon will remove the usage of the fee preference
when sweeping inputs.
2024-04-19 21:33:31 +08:00
yyforyongyu
658ba445ea
sweep: delay sweeping inputs with future locktimes
This commit fixes an edge case that the sweeper's best known block
height is behind arbitrator's, which may cause an issue when creating
sweeping tx, as we may end up using an old block height from
arbitrator's view.
2024-04-19 21:33:31 +08:00
yyforyongyu
0527b2d7a6
sweep: make sure exclusive inputs are not grouped
This commit fixes the grouping logic in `BudgetAggregator` to make sure
the exclusive inputs are never grouped.
2024-04-19 21:33:31 +08:00
yyforyongyu
0fc5301d12
lnwallet+sweep: cap conf target used in fee estimator 2024-04-19 21:33:31 +08:00
yyforyongyu
1fa8ca72ee
sweep: fix handlePendingSweepsReq linter issue
Turns out the param was never used, we now fix it by sending the
response in the method and also catch the quit channel.
2024-04-19 21:33:30 +08:00
yyforyongyu
28df2d7327
lnrpc+sweep: make sure public interface takes public types as params
This commit exports and renames the following variable names:
- `PendingInput` is now `PendingInputResponse` as it's responding to a
  request.
- `pendingInput` is now renamed and exported as `SweeperInput`.
- `pendingInputs` is now renamed and exported as `InputsMap`.

This commit is first made from running:
```
gofmt -d -w -r 'PendingInput -> PendingInputResponse' .
gofmt -d -w -r 'pendingInput -> SweeperInput' .
gofmt -d -w -r 'pendingInputs -> InputsMap' .
```
And followed by some docs and variable names fixes.
2024-04-19 21:33:30 +08:00
yyforyongyu
9e7d4b7e0b
sweep: rename pendingInputs to inputs on sweeper
There's no need use the prefix `pending` as the inputs in the sweeper
can only be pending, so it's renamed, also to avoid the confusion with
the type `pendingInputs`.
2024-04-19 21:33:30 +08:00
yyforyongyu
0063770cb7
sweep: remove the prefix used in SweepState types
Don't prefix with `State` we already have information to determine what
the type is. Generated this commit using,
```
gofmt -d -w -r 'StateInit -> Init' .
gofmt -d -w -r 'StatePendingPublish -> PendingPublish' .
gofmt -d -w -r 'StatePublished -> Published' .
gofmt -d -w -r 'StatePublishFailed -> PublishFailed' .
gofmt -d -w -r 'StateSwept -> Swept' .
gofmt -d -w -r 'StateExcluded -> Excluded' .
gofmt -d -w -r 'StateFailed -> Failed' .
```

and some string matching to fix the docs.
2024-04-19 21:33:30 +08:00
yyforyongyu
19265ac8ed
sweep: make sure non-fee related errors are notified
So these inputs can be retried by the sweeper.
2024-04-19 21:33:30 +08:00
yyforyongyu
b76ccab17b
docs: update release notes for fee bumper 2024-04-19 21:33:30 +08:00
yyforyongyu
94390fc775
itest: fix existing itests 2024-04-19 21:33:29 +08:00
yyforyongyu
7fb18bc0d5
sweep: increase delta fee rate precision in fee function
This commit adds a private type `mSatPerKWeight` that expresses a given
fee rate in millisatoshi per kw. This is needed to increase the
precision of the fee function. When sweeping anchor inputs, if using a
deadline delta of over 1000, it's likely the delta will be 0 sat/kw due
to precision.
2024-04-19 21:33:29 +08:00
yyforyongyu
23feef7e6c
lnd: init publisher when creating new server 2024-04-19 21:33:29 +08:00
yyforyongyu
90e727a776
sweep: add monitor loop to TxPublisher
This commit finishes the implementation of `TxPublisher` by adding the
monitor process. Whenever a new block arrives, the publisher will check
all its monitored records and attempt fee bumping them if necessary.
2024-04-19 21:33:29 +08:00
yyforyongyu
11f7e455d1
lnwallet+sweep: introduce TxPublisher to handle fee bump
This commit adds `TxPublisher` which implements `Bumper` interface. This
is part one of the implementation that focuses on implementing the
`Broadcast` method which guarantees a tx can be published with
RBF-compliant. It does so by leveraging the `testmempoolaccept` API,
keep increasing the fee rate until an RBF-compliant tx is made and
broadcasts it.

This tx will then be monitored by the `TxPublisher` and in the following
commit, the monitoring process will be added.
2024-04-19 21:33:29 +08:00
yyforyongyu
ecd471ac75
lnwallet+sweep: calculate max allowed feerate on BumpResult
This commit adds the method `MaxFeeRateAllowed` to calculate the max fee
rate. The caller may specify a large MaxFeeRate value, which cannot be
cover by the budget. In that case, we default to use the max feerate
calculated using `budget/weight`.
2024-04-19 21:33:29 +08:00
yyforyongyu
f85661d94a
lnwallet+sweep: add new method CheckMempoolAcceptance 2024-04-19 21:33:28 +08:00
yyforyongyu
cd5d074099
sweep: add FeeFunction interface and a linear implementation
This commit adds a new interface, `FeeFunction`, to deal with
calculating fee rates. In addition, a simple linear function is
implemented, hence `LinearFeeFunction`, which will be used to calculate
fee rates when bumping fees. Check #4215 for other type of fee functions
that can be implemented.
2024-04-19 21:33:28 +08:00
yyforyongyu
f7bc82a22d
sweep: remove FeeRate() from InputSet interface
As shown in the following commit, fee rate calculation will now be
handled by the fee bumper, hence there's no need to expose this on
`InputSet` interface.
2024-04-19 21:33:28 +08:00
yyforyongyu
6d6c544414
sweep: remove RBF related tests
As there will be dedicated new tests for them.
2024-04-19 21:33:28 +08:00
yyforyongyu
21aff324a3
sweeper: fix existing sweeper tests 2024-04-19 21:33:28 +08:00
yyforyongyu
1187b868ad
sweep: introduce Bumper interface to handle RBF
This commit adds a new interface, `Bumper`, to handle RBF for a given
input set. It's responsible for creating the sweeping tx using the input
set, and monitors its confirmation status to decide whether a RBF should
be attempted or not.

We leave implementation details to future commits, and focus on mounting
this `Bumper` interface to our sweeper in this commit.
2024-04-19 21:33:27 +08:00
yyforyongyu
a088501e47
sweep: introduce BudgetAggregator to cluster inputs by deadlines
This commit adds `BudgetAggregator` as a new implementation of
`UtxoAggregator`. This aggregator will group inputs by their deadline
heights and create input sets that can be used directly by the fee
bumper for fee calculations.
2024-04-19 21:33:27 +08:00
yyforyongyu
e7400f6a94
sweep: introduce BudgetInputSet to manage budget-based inputs
This commit adds `BudgetInputSet` which implements `InputSet`. It
handles the pending inputs based on the supplied budgets and will be
used in the following commit.
2024-04-19 21:33:27 +08:00
yyforyongyu
bd5eec8e1f
sweep: refactor markInputsPendingPublish to take InputSet
This commit changes `markInputsPendingPublish` to take `InputSet` only.
This is needed for the following commits as we won't be able to know the
tx being created beforehand, yet we still want to make sure these inputs
won't be grouped to another input set as it complicates our RBF process.
2024-04-19 21:33:27 +08:00
yyforyongyu
6202c59cb3
sweep: change markInputsPublishFailed to take outpoints
This way it's easier to pass values to this method in various callsites.
2024-04-19 21:33:27 +08:00
yyforyongyu
db7eae97ff
sweep: expand InputSet with more interface methods
This commit adds more interface methods to `InputSet` to prepare the
addition of budget-based aggregator.
2024-04-19 21:33:27 +08:00
yyforyongyu
d0a8f27d84
sweep: change MaxInputsPerTx from int to uint32 2024-04-19 21:33:26 +08:00
yyforyongyu
521b1fc34a
itest+lntest: fix itest re the new block driven behavior 2024-04-19 21:33:26 +08:00
yyforyongyu
558d9bd3ce
walletrpc: pass Force flag when sweeping via BumpFee 2024-04-19 21:33:26 +08:00
yyforyongyu
d8f976f8fc
trivial: fix comments and docs 2024-04-19 21:33:26 +08:00