Commit graph

16390 commits

Author SHA1 Message Date
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
yyforyongyu
1e6e443a0b
docs: update release notes 2024-04-19 21:33:22 +08:00
yyforyongyu
61e9c11881
rpcserver: skip calculating fee rate for PSBT funding 2024-04-19 21:33:22 +08:00
yyforyongyu
519a8749ef
lntest: reflect the updated fee estimator in tests 2024-04-19 21:33:21 +08:00
yyforyongyu
1870caf39c
sweep+lnd: introduce UtxoAggregator to handle clustering inputs
This commit refactors the grouping logic into a new interface
`UtxoAggregator`, which makes it easier to write tests and opens
possibility for future customized clustering strategies.

The old clustering logic is kept as and moved into `SimpleAggregator`.
2024-04-19 21:33:21 +08:00
yyforyongyu
3bcac318eb
sweep+lnrpc: add new interface FeePreference
This commit adds a new interface `FeePreference` which makes it easier
to write unit tests and allows more customized implementation in
following commits.
2024-04-19 21:33:21 +08:00
yyforyongyu
530eed92a0
multi: rename FeePreference to FeeEstimateInfo
Results from running,
```
gofmt -d -w -r 'FeePreference -> FeeEstimateInfo' .
```
2024-04-19 21:33:21 +08:00
yyforyongyu
6ff6c86155
multi: merge DetermineFeePerKw and Estimate
This commit moves `DetermineFeePerKw` into the `Estimate` method on
`FeePreference`. A few callsites previously calling `DetermineFeePerKw`
without the max fee rate is now also temporarily fixed by forcing them
to use `Estimate` with the default sweeper max fee rate.
2024-04-19 21:33:21 +08:00
yyforyongyu
18b06b7303
sweep: replace feeRateForPreference with Estimate
This commit refactors the sweeper so the method `feeRateForPreference`
is now moved to `FeePreference`, which makes our following refactor
easier to handle.
2024-04-19 21:33:20 +08:00
yyforyongyu
84a6fdcda3
sweep+contractcourt: track best height in UtxoSweeper
Thus we can use shorter method signatures. In doing so we also remove an
old TODO in one use case of `CreateSweepTx`.
2024-04-19 21:33:20 +08:00
yyforyongyu
ca0813b1bf
docs: update release docs 2024-04-19 21:33:20 +08:00
yyforyongyu
f13a3a8053
sweep: use testify/mock for MockSweeperStore 2024-04-19 21:33:20 +08:00
yyforyongyu
8b9d5e0548
sweep: add new methods GetTx and DeleteTx to manage TxRecord 2024-04-19 21:33:20 +08:00
yyforyongyu
b37444d0de
sweep: expand sweeper store to also save RBF-related info
This commit modifies the sweeper store to save a `TxRecord` in db
instead of an empty byte slice. This record will later be used to bring
RBF-awareness to our sweeper.
2024-04-19 21:33:20 +08:00
yyforyongyu
1ace1fdf4c
sweep: return fees from method createSweepTx
Which will be used to make the sweeper RBF-aware.
2024-04-19 21:33:19 +08:00
yyforyongyu
e86843da6e
sweep: rename NotifyPublishTx to StoreTx
To properly reflect what the method really does. We also changes the
method signature so only a hash is used.
2024-04-19 21:33:19 +08:00
Olaoluwa Osuntokun
d4c1937572
Merge pull request #8573 from guggero/bitcoind-27
GitHub: use bitcoind v27.0 for CI
2024-04-18 14:36:58 -07:00