Commit Graph

16509 Commits

Author SHA1 Message Date
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
yyforyongyu
465332f409
multi: deprecate batchwindowduration config option 2024-04-19 21:33:26 +08:00
yyforyongyu
c03509397f
sweep: add mocks and patch unit test for sweepPendingInputs 2024-04-19 21:33:26 +08:00
yyforyongyu
210b7838c7
sweep: move mocks into one file 2024-04-19 21:33:25 +08:00
yyforyongyu
ae43764e31
sweep: remove deprecated rand.Seed 2024-04-19 21:33:25 +08:00
yyforyongyu
0110a09595
sweep: decrease coin selection lock scope
This commit changes how `WithCoinSelectLock` is used - previously the
lock is held when creating the input sets, now it's only be held after
the input sets have been created and explicitly signal they need wallet
inputs.
2024-04-19 21:33:25 +08:00
yyforyongyu
b536e9bd3f
sweep: deepen the interface Aggregator
This commit makes the `ClusterInputs` directly returning the `InputSet`
so the sweeper doesn't know about the existence of `Cluster` interface.
This way we can have a deeper interface as the sweeper only needs to
interact with `Aggregator` only to get the final input sets, leaving the
implementation details being managed by `SimpleAggregator` and future
aggregators.
2024-04-19 21:33:25 +08:00
yyforyongyu
1530fee9b3
sweep: add new inteface InputSet to manage inputs in a tx
Previously the fee rate is tracked at cluster level, which may not be
accurate as each cluster is then divided into input sets. And these sets
are what's actually included in the final sweeping tx. To properly
reflect the final fee rate used in the sweeping tx, `InputSet` is added
so more customized clustering logic can be implemented in the future.
For intance, atm it's clustered by fee rates, while we may also cluster
by deadlines, urgencies, etc.
2024-04-19 21:33:25 +08:00
yyforyongyu
9d5ddf29f3
sweep: add new interface Cluster to manage grouping inputs
This commit adds a new interface `Cluster` to manage cluster-level
inputs grouping. This new interface replaces the `inputCluster` and will
be futher refactored so the sweeper can use a much smaller coin
selection lock.
2024-04-19 21:33:25 +08:00
yyforyongyu
a7e9c08baf
sweep: make sweeper block-driven instead of time-driven
This commit changes the source that drives the state changes in the
sweeper. Previously we used a ticker with default interval of 30s to
trigger sweepings periodically. The assumption is, within this 30s we'd
batch multiple inputs into one transaction to maximize profits. However,
the efficacy of this batch is questionable.

At a high level, we can put our inputs into two categories - one that's
forced, and one that's not. For forced inputs, we should sweep them
immediately as the force flag indicates they are very urgent, eg,
CPFPing the force closing tx. For non-forced inputs, such as anchors
or HTLCs with CLTV that's far away, we can wait to sweep them till a new
block comes in and triggers the sweeping process.

Eventually, all inputs will be deadline-aware, and the sweeper will
consult our fee bumper about the most economical fee rate to be used for
a given deadline. Since the deadlines here are blockstamp, it's also
easier to manage them if the sweeper is also using blockstamp instead of
timestamp.
2024-04-19 21:33:24 +08:00
yyforyongyu
df4e51e2e0
sweep: refactor attachAvailableRBFInfo to decideStateAndRBFInfo
Thus this method `decideStateAndRBFInfo` won't touch the state changes
of a given input.
2024-04-19 21:33:24 +08:00
yyforyongyu
6f5b7a9fd3
lntest+itest: fix testOpenChannelLockedBalance 2024-04-19 21:33:24 +08:00
yyforyongyu
536ac9f8a4
docs: update release notes 2024-04-19 21:33:24 +08:00
yyforyongyu
5fce91caf9
chainntnfs+sweep: add LookupInputMempoolSpend and use it in the
sweeper

This commit implements a new method, `LookupInputMempoolSpend` to do
lookups in the mempool. This method is useful in the case when we only
want to know whether an input is already been spent in the mempool by
the time we call.
2024-04-19 21:33:24 +08:00
yyforyongyu
ebef3679ac
btcdnotify: use chain.NewRPCClientWithConfig to init RPC client
So we can use the methods implemented on the chain RPC client.
2024-04-19 21:33:24 +08:00
yyforyongyu
b5e4384e24
lnd+sweep: remove unused NextAttemptDeltaFunc 2024-04-19 21:33:23 +08:00
yyforyongyu
5496d02b27
sweep: fix logging 2024-04-19 21:33:23 +08:00
yyforyongyu
124d1764f7
sweep: remove unused param testSpendChan 2024-04-19 21:33:23 +08:00
yyforyongyu
fd922942a7
sweep: patch unit tests for markInputsSwept and markInputsPendingPublish
Now that the refactor is done, we start patching unit tests for these
two methods. Minor changes are also made based on the feedback from the
tests.
2024-04-19 21:33:23 +08:00
yyforyongyu
34b6a3d718
sweep: add method markInputFailed 2024-04-19 21:33:23 +08:00
yyforyongyu
a8f5a09dea
sweep: don't give up an input based on number of attempts
This commit removes the logic where we remove an input when it's been
published more than 10 times. This is needed as in our future fee
bumper, we might start with a low fee and rebroadcast the same input for
hundred of blocks.
2024-04-19 21:33:23 +08:00
yyforyongyu
8b876be3b6
sweep: add fee info for published inputs
This commit attaches RBFInfo to an input before it's been published or
it's already been published.
2024-04-19 21:33:22 +08:00
yyforyongyu
a263d68fb9
sweep: delete pending inputs based on their states
This commit uniforms and put the deletion of pending inputs in a single
point.
2024-04-19 21:33:22 +08:00
yyforyongyu
47478718d4
multi: query mempool spend when a new input is received
This commit changes how a new input sweep request is handled - now we
will query the mempool and see if it's already been spent. If so, we'll
update its state as we may need to RBF this input.
2024-04-19 21:33:22 +08:00
yyforyongyu
6a2e3fb203
sweep: make pending input stateful
This commit starts tracking the state of a pending input so it's easier
to control the sweeping flow and provide RBF awareness in the future.
2024-04-19 21:33:22 +08:00