Commit Graph

148 Commits

Author SHA1 Message Date
ziggie
22b504db7c
sweep: add TODO to the sweeper behavior.
Make sure we only trigger the sweep of a specific input when
updating its fee parameters not the all the current pending
registered sweeps.
2024-08-09 19:41:27 +02:00
yyforyongyu
d992cf94d6
multi: add SpewLogClosure to avoid code repetition 2024-07-25 22:18:49 +08:00
yyforyongyu
b6049ff94b
multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
2024-07-25 21:25:23 +08:00
yyforyongyu
347537791e
sweep: improve loggings based on feedback
This commit changes the logging levels and add a few more loggings based
on the testing results from the testnet/mainnet.
2024-05-21 00:53:24 +08:00
ziggie
62a52b4d7c
multi: Utxo restriction single funding case.
Restrict the utxo selection when opening a single internal wallet
funded backed channel.
2024-04-24 13:58:19 +01:00
yyforyongyu
9c5124e117
sweep: remove unused param Fee 2024-04-23 04:44:00 +08:00
yyforyongyu
a50cdd64c5
sweep: assign deadline values to inputs in handleNewInput
This commit changes how we transform from a deadline option to a
concrete deadline value - previously this is done when we decide to
cluster inputs, and we now move it to a step earlier - once an input is
received via `SweeperInput`, we will immediately transform its optional
deadline into a real value. For inputs that come with a deadline option,
since the Some will be used, it makes no difference. For inputs with
None as their deadlines, we need this change to make sure the default
deadlines are assigned accurately.
2024-04-19 21:33:39 +08:00
yyforyongyu
11a276e222
walletrpc+sweep: update PendingSweeps to return the new params 2024-04-19 21:33:38 +08:00
yyforyongyu
8804947179
walletrpc+sweep: refactor BumpFee to properly handle sweep request 2024-04-19 21:33:38 +08:00
yyforyongyu
9be5b370a7
sweep+contractcourt: replace ParamsUpdate with Params 2024-04-19 21:33:38 +08:00
yyforyongyu
b6a2984167
sweep: allow specifying starting fee rate for fee func 2024-04-19 21:33:37 +08:00
yyforyongyu
db3aad31aa
lnrpc+sweep: rename Force to Immediate for clarity 2024-04-19 21:33:37 +08:00
yyforyongyu
94e0e32c74
multi: add itest testSweepAnchorCPFPLocalForceClose
This commit adds an itest case that focuses on validating the CPFP logic
in anchor sweeping.
2024-04-19 21:33:36 +08:00
yyforyongyu
a2b8f4e19c
sweep: allow published input to be marked as PublishFailed
If anything happens during the fee bumping process, and causes the input
to be failed, we should be able to mark it as `PublishFailed`.
2024-04-19 21:33:35 +08:00
yyforyongyu
acde08c65a
contractcourt: offer second-level outputs at CSV-1
This commit moves the offering of second-level outputs one block
earlier. The sweeper will check the required locktime and wait until it
matures. This is needed so the second-level outputs can be aggregated
properly.
2024-04-19 21:33:35 +08:00
yyforyongyu
dc7d90c16f
contractcourt+sweep: offer direct-preimage spend via SweepInput
This commit removes the method `CreateSweepTx` and makes sure when
sweeping the htlc output via the direct-preimage spend, it's offered via
the `SweepInput` interface.
2024-04-19 21:33:35 +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
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
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
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
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
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
d0a8f27d84
sweep: change MaxInputsPerTx from int to uint32 2024-04-19 21:33:26 +08:00
yyforyongyu
465332f409
multi: deprecate batchwindowduration config option 2024-04-19 21:33:26 +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
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
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