Commit Graph

156 Commits

Author SHA1 Message Date
yyforyongyu
dba4c8e5ad
trivial: fix typo and nits 2023-10-23 13:01:52 +08:00
yyforyongyu
92837621ec
sweep: remove possible RBF when creating sweeping tx for new inputs
This commit changes how we create the input sets which are used to
construct the sweeping transactions. Assume the sweeper has two inputs,
one is new and one is retried, we'd end up having two transactions,
- tx1: which spends both the new and old inputs.
- tx2: which spends the new inputs only.
When publishing these txes, depending on which one gets into the mempool
first, the other one will be viewed as an RBF for the first one since
they both spending the same input(the new input).

This is now fixed by only attempt to publish the second tx when there
isn't a first tx - when there is a tx1, it means the new inputs are
already used in this tx along with retried inputs, hence there's no need
to publish tx2 which spends the new inputs only.
2023-10-23 10:48:51 +08:00
yyforyongyu
acc15d8113
sweep: add new method rescheduleInputs and refactor sweep 2023-10-23 10:44:46 +08:00
yyforyongyu
7de4186766
sweep: simplify polling logic in sweeper
This commit attempts to make the polling logic in sweeper more linear.
Previously, the sweep's timer is reset/restarted in multiple places,
such as when a new input comes in, or a new block comes in, or a
previous input being spent, making it difficult to follow. We now remove
the old timer and replaces it with a simple polling logic - we will
schedule sweeps every 5s(default), and if there's no input to be swept,
we'd skip, just like the previous `scheduleSweep` does.
It's also worthy noting that, although `scheduleSweep` triggers the
timer to tick, by the time we do the actual sweep in `sweepCluster`,
conditions may have changed. This is now also fixed because we only have
one place to create the clusters and sweeps.
2023-10-23 10:24:58 +08:00
yyforyongyu
4ba09098d1
sweep+lnd: move ticker creation into sweeper 2023-10-23 10:24:58 +08:00
yyforyongyu
62b5869f87
sweep: add new method handleSweep 2023-10-23 10:24:58 +08:00
yyforyongyu
f1d0f9f74e
sweep: add new method handleInputSpent 2023-10-23 10:24:58 +08:00
yyforyongyu
39a7cc6434
sweep: rename waitForSpend to monitorSpend to avoid confusion
The method `waitForSpend` makes it sounding like it's blocking while
it's not, thus it's renamed to avoid confusion.
2023-10-23 10:24:58 +08:00
yyforyongyu
39973687aa
sweep: add new method handleNewInput 2023-10-23 10:24:58 +08:00
yyforyongyu
551102a0f3
sweep: fix make lint 2023-10-13 17:00:53 +08:00
yyforyongyu
34e0c7b5e0
input+sweep: make sure input with no fee rate is not added to cluster
This commit makes sure an input is only added to the cluster when it has
successfully estimated its fee rate. Previously, when an error is
returned from `feeRateForPreference`, we'd still add this input to the
cluster, resulting a **lower** fee rates being used because when
averaging the fee rates, we'd think this input has zero fee rate
specified.

An unit test is patched to make the method `clusterByLockTime` more
robust.
2023-10-13 17:00:53 +08:00
yyforyongyu
a46168e669
sweep: remove redundant map inputFeeRates when creating cluster
This commit removes the map `inputFeeRates` inside `clusterByLockTime`
as the fee rate can already be access via `input.lastFeeRate`.
2023-10-13 17:00:53 +08:00
yyforyongyu
497f421009
sweep: patch unit test for feeRateForPreference 2023-10-13 17:00:53 +08:00
yyforyongyu
82053970ef
lnd+sweep: move DetermineFeePerKw into config
This commit makes `DetermineFeePerKw` configurable on sweeper so it's
easier to write unit tests for it.
2023-10-13 14:44:20 +08:00
Yong
939375f1a5
sweeper: relax anchor sweeping when there's no deadline pressure (#7965)
* sweep: use longer variable name for clarity in `addToState`

* sweeper: add more docs and debug logs

* sweep: prioritize smaller inputs when adding wallet UTXOs

This commit sorts wallet UTXOs by their values when using them for
sweeping inputs. This way we'd avoid locking large UTXOs when sweeping
inputs and also provide an opportunity to aggregate wallet UTXOs.

* contractcourt+itest: relax anchor sweeping for CPFP purpose

This commit changes from always sweeping anchor for a local force close
to only do so when there is an actual time pressure. After this change,
a forced anchor sweeping will only be attempted when the deadline is
less than 144 blocks.

* docs: update release notes

* itest: update test `testMultiHopHtlcLocalChainClaim` to skip CPFP

Since we now only perform CPFP when both the fee rate is higher and the
deadline is less than 144, we need to update the test to reflect that
Bob will not CPFP the force close tx for the channle Alice->Bob.

* itest: fix `testMultiHopRemoteForceCloseOnChainHtlcTimeout`

* itest: update related tests to reflect anchor sweeping

This commit updates all related tests to reflect the latest anchor
sweeping behavior. Previously, anchor sweeping is always attempted as
CPFP when a force close is broadcast, while now it only happens when the
deadline is less than 144. For non-CPFP purpose sweeping, it will happen
after one block is mined after the force close transaction is confirmed
as the anchor will be resent to the sweeper with a floor fee rate, hence
making it economical to sweep.
2023-10-12 17:18:59 +02:00
yyforyongyu
25d82fd62b rpcserver+sweep: fix linter re unused params 2023-10-06 16:34:47 -07:00
yyforyongyu
24fa35ec80 multi: make sure CPFP won't exceed max allowed fee rate
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.
2023-10-06 16:34:47 -07:00
yyforyongyu
42ff52bbfb sweep: cap to max fee rate instead of failing
This commit caps the estimated fee rate at the configged max fee rate
instead of returning an error.
2023-10-06 16:34:47 -07:00
yyforyongyu
258fe7999b sweep+itest: change MaxFeeRate to use SatPerVbyte 2023-10-06 16:34:47 -07:00
yyforyongyu
60a44c3f53 sweep: lower the max allowed fee rate for sweeping inputs
This commit changes the DefaultMaxFeeRate from 10,120 sat/vb to 1,000
sat/vb.
2023-10-06 16:34:47 -07:00
yyforyongyu
66b8700c0b multi: add debug logs to catch slow shutdown 2023-10-06 16:34:47 -07:00
Oliver Gugger
b565f4f536
Merge pull request #7880 from yyforyongyu/fix-channel-arb
trivial: fix loggings, variable names and conf notification order
2023-08-15 16:25:54 +02:00
ziggie
07502a8fb0
sweep: Remove publishing last-tx logic.
We remove the publishing of the last published sweep tx during the
startup of the sweeper. This republishing can lead to situations
where funds of the default wallet might be locked for neutrino
backend clients.
Moreover all related tests are removed as well.
2023-08-15 10:00:29 +02:00
yyforyongyu
aff4320208
multi: improve logging re resolution flow 2023-08-10 13:50:03 +08:00
shaurya947
25097f0993
sweep: update fee estimator fee-below-floor test case
Handle error in test case, as well as add new test case for below
relay fee input.
2023-05-26 11:16:51 -04:00
shaurya947
2292f3fbd0
sweep: use relay fee rate as floor for specified fee rate
This ensures that for transactions where a fee rate is specified
(instead of a confirmation target), lnd doesn't accept transactions
which would be ultimately ignored by the underlying chain's RPC.
2023-05-26 11:16:42 -04:00
Olaoluwa Osuntokun
3d2daeefd8
sweep: remove conflicted sweep txns from the rebroadcaster
In this commit, we an existing gap in our rebroadcast handling logic. As
is, if we're trying to sweep a transaction and a conflicting transaction
is mined (timeout lands on chain, anchor swept), then we'll continue to
try to rebroadcast the tx in the background.

To resolve this, we give the sweeper a new closure function that it can
use to mark conflicted transactions as no longer requiring rebroadcast.
2023-04-21 11:53:08 -07:00
yyforyongyu
edba938996
multi: add new build tag integration
This commit adds a new build tag `integration` and removes the old tag
`rpctest` for clarity. Multiple unnecessary usages of `build !rpctest`
is also removed.
2023-02-23 21:56:09 +08:00
Oliver Gugger
55b53555e9
multi: improve readability of goroutine defers
This commit fixes the readability of some of the defer calls in
goroutines by making sure the defer stands out properly.
2022-11-21 13:54:24 +01:00
Eng Zer Jun
c70e39cd21
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:46:54 +08:00
yyforyongyu
1aa4d047fe
sweep: add more debug/trace logs 2022-09-01 10:44:28 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
Olaoluwa Osuntokun
b711120dca
sweep: change outputs are now P2TR 2022-08-11 17:26:16 -07:00
Oliver Gugger
17014b592e
Merge pull request #6730 from Roasbeef/notifier-optional-block
chainntfns: add new option for conf notifications to send block
2022-08-10 13:52:49 +02:00
eugene
6ec2826f6c
sweep: account for all script types in craftSweepTx
With this change, transactions created via craftSweepTx will be
standard. Previously, p2wsh/p2pkh scripts passed in via SendCoins would
be weighted as p2wpkh scripts. With a feerate of 1 sat/vbyte,
transactions returned would be non-standard. Luckily, the critical
sweeper subsystem only used p2wpkh scripts so this only affected
callers from the rpcserver.

Also added is an integration test that fails if SendCoins manages
to generate a non-standard transaction. All script types are now
accounted for in getWeightEstimate, which now errors if an unknown
script type is passed in.
2022-08-08 15:33:00 -04:00
Olaoluwa Osuntokun
08f1c2e93a
chainntfns: add new option for conf notifications to send block
In this commit, we add a new option for the existing confirmation
notification system that optionally allows the caller to specify that a
block should be included as well.

The only quirk w/ the implementation here is the neutrino backend:
usually we get filtered blocks, we so need to first fetch the block
again so we can deliver the full block to the notifier. On the notifier
end, it'll only be checking for the transactions we care about, to
sending a full block doesn't affect the correctness.

We also extend the `testBatchConfirmationNotification` test to assert
that a block is only included if the caller specifies it.
2022-08-01 19:59:21 -07:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Oliver Gugger
a3e4db60cd
sweep: allow sweeper to sweep P2TR inputs 2022-06-10 22:03:41 +02:00
Oliver Gugger
c73cf03a55
multi: add p2tr keyspend wallet support 2022-03-24 18:02:38 +01:00
Oliver Gugger
f130eddb92
multi: use prev output fetcher where possible 2022-03-24 18:02:37 +01:00
Oliver Gugger
72c9582b85
multi: bump btcd to taproot aware version 2022-03-24 15:00:25 +01:00
Olaoluwa Osuntokun
e1e9de24df
sweep: remove all unconfirmed descendant transactions when a sweep conflicts
Before this commit, we we were trying to sweep an anchor output, and
that output was spent by someone else (not the sweeper), then we would
report this back to the original resolver (allowing it to be cleaned
up), and also remove the set of inputs spent by that transaction from
the set we need to sweep.

However, it's possible that if a user is spending unconfirmed outputs,
then the wallet is holding onto an invalid transaction, as the outputs
that were used as inputs have been double spent elsewhere.

In this commit, we fix this issue by recursively removing all descendant
transactions of our past sweeps that have an intersecting input set as
the spending transaction. In cases where a user spent an unconfirmed
output to funding a channel, and that output was a descendant of the now
swept anchor output, the funds will now properly be marked as available.

Fixes #6241
2022-03-17 16:36:47 -07:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
yyforyongyu
1ad6bbfbc2
multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Joost Jager
d997bbf6b3
channeldb/test: test with postgres 2021-10-29 10:54:44 +02:00
Bjarne Magnussen
0fc17238cd
sweep: add label to sweep transactions 2021-10-26 12:52:22 +02:00
Wilmer Paulino
e1c269c7ed
sweep: remove previous exclusive group upon re-offered inputs
This aims to cover an edge case and also serves as an optimization of
what happens when an input that was offered to the Sweeper with an
exclusive group is re-offered without one. This happens every time we
attempt to sweep the different possible anchors of a channel at the time
of broadcast, as we don't know which commitment transaction will end up
confirming in the chain. Once the commitment transaction confirms
however, we know which anchor output to act upon and re-offer it to the
Sweeper without an exclusive group. At this point, the Sweeper will
continue to attempt sweeping the other anchor output versions even know
we know they are not valid.
2021-10-19 18:30:40 -07:00
Oliver Gugger
0b4e03f5fc
multi: add golang 1.17 compatible build tags
With go 1.17 a change to the build flags was implemented:
https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md

The formatter now automatically adds the forward-compatible build tag
format and the linter checks for them, so we need to include them in our
code.
2021-09-29 17:31:37 -07:00