Commit Graph

65 Commits

Author SHA1 Message Date
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
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
aff4320208 multi: improve logging re resolution flow 2023-08-10 13:50:03 +08:00
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
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
1aa4d047fe sweep: add more debug/trace logs 2022-09-01 10:44:28 +08:00
0735522194 multi: fix make fmt 2022-08-23 22:10:24 +08:00
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
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
1ad6bbfbc2 multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
895a2e497b multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
530a2059e5 multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
0fc17238cd sweep: add label to sweep transactions 2021-10-26 12:52:22 +02:00
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
fdcd726f9a multi: replace DefaultDustLimit with script-specific DustLimitForSize
This commit updates call-sites to use the proper dust limits for
various script types. This also updates the default dust limit used
in the funding flow to be 354 satoshis instead of 573 satoshis.
2021-09-29 13:33:10 -04:00
3204e2d74b multi: add shutdown logs in subservers
This commit adds a simple shutdown to every subserver to assist
debugging.
2021-09-15 19:52:03 +08:00
185ba77f8e sweep: allow specified outputs to sweep tx
We'll use this to attach an output for the value reserved for anchor
commitments fee bumping if the user requests a send_all transaction.
2021-01-19 10:53:45 +01:00
77daa3dbe4 sweeper: avoid deadlock on shutdown
We risked deadlocking on shutdown if a client (in our case a contract
resolver) attempted to schedule a sweep of an input after the
ChainNotifier had been shut down. This would cause the `collector`
goroutine to exit, and not handle incoming requests, causing a deadlock
(since the ChainArbitrator is being stopped before the Sweeper in the
server).

To fix this we could change the order these subsystems are stopped, but
this doesn't ensure there aren't other clients that could end up in the
same deadlock scenario. So instead we keep handling the incoming
requests even after the collector has exited (immediatly returning an
error), until the sweeper is signalled to shutdown.
2020-12-10 13:19:59 +01:00
aa8fa9d0cf sweep: pass dustLimit to CreateSweepTx 2020-11-20 13:06:53 +01:00
efd6bc9501 sweep+input: add RequiredLockTime to inputs 2020-11-20 13:06:53 +01:00
fa4fd02cf1 sweep: add mergeClusters 2020-11-20 13:06:53 +01:00
128087044f sweeper: define method createInputClusters 2020-11-20 13:06:53 +01:00
681496b474 sweep: make sweeper aware of unconfirmed parent transactions.
Extend the fee estimator to take into account parent transactions with
their weights and fees.

Do not try to cpfp parent transactions that have a higher fee rate than
the sweep tx fee rate.
2020-09-17 12:30:39 +02:00
08bb8ec54e cnct: clear exclusive group on anchor sweep after confirmation
The sweeper call UpdateParams does not update the exclusive group
property of a pending sweep. This led to anchor outputs being swept
after confirmation with an exclusive group restriction, which is not
necessary.

This commit changes the anchor resolver to not use UpdateParams anymore,
but instead always re-offer the anchor input to the sweeper. The sweeper
is modified so that a re-offering also updates the sweep parameters.
2020-09-16 08:17:40 +02:00
75370ce6b4 multi: update WalletController PublishTransaction to include label
Add label parameter to PublishTransaction in WalletController
interface. A labels package is added to store generic labels that are
used for the different types of transactions that are published by lnd.

To keep commit size down, the two endpoints that require a label
parameter be passed down have a todo added, which will be removed in
subsequent commits.
2020-05-19 13:30:00 +02:00
99a45e968a sweep: add list sweeps function 2020-05-05 21:10:11 +02:00
c1d00a0c9b Merge pull request #4101 from ErikEk/typo_fixes_trivial
trivial: typo fixes
2020-03-19 21:36:38 +01:00
4e47181b99 trivial: typo fix 2020-03-19 05:43:49 +01:00
3b517390d8 cnct+sweeper: give contract court access to relay fee
Relay fee is needed later to sweep anchors at the minimum fee rate.
2020-03-17 16:25:37 +01:00
29e1489179 sweep: leave exclusive group unchanged on parameter update
Exclusive group is a static property that doesn't need to be updated.
Requiring the exclusive group to be passed into UpdateParams creates a
burden for the caller to make sure they supply the existing group.

This change will be beneficial for users that bump anchor sweeps that
have exclusive groups set.
2020-03-17 14:19:39 +01:00
1c93e9e03d sweep: isolate min fee rate bucket 2020-03-17 14:19:37 +01:00
9dc349488b sweep: add exclusive groups
Allows certain sweep inputs to be kept in separate transactions at all
times. This is a preparation for anchor outputs. Before the commitment
tx confirms, there are three potential anchors that can be cpfp'ed. We
want to cpfp them all, but if done in the same transaction, the
transaction would guaranteed to be invalid. Exponential backoff would
eventually get the txes published, but having exclusive groups makes the
process faster.
2020-02-13 09:52:21 +01:00
69a6107d06 sweep: log full parameter struct 2020-02-12 09:59:43 +01:00
b0aae13d70 sweep: allow force sweeps 2020-01-15 16:56:44 +01:00
16832cefa3 sweep: allow updating all sweep parameters
This is a preparation for adding additional parameters besides the fee
preference.
2020-01-15 16:56:40 +01:00
280611ab6e sweep+walletrpc+lncli: report requested fee preference for pending sweeps
Previously only the fee rate used for the last sweep (the sweep bucket
average) was reported. This commit adds the request fee preference to
the report, which is used to select a bucket and the sweep tx fee rate.
2020-01-09 14:56:08 +01:00
e01600fdb8 sweep: add wallet inputs to reach dust limit
This commit allows sweeper to sweep inputs that on its own are not able
to form a sweep transaction that meets the dust limit.

This functionality is useful for sweeping small outputs. In the future,
this will be particularly important to sweep anchors. Anchors will
typically be spent with a relatively large fee to pay for the parent tx.
It will then be necessary to attach an additional wallet utxo.
2019-12-17 22:00:39 +01:00
8353b6fd6e sweep: extract sweepCluster method
Prepares for adding another level of nesting.
2019-12-17 22:00:37 +01:00
34c9193bfc sweep: create wallet interface
We need access to additional wallet functionality. This commit creates
an interface to prevent passing in multiple function pointers.
2019-12-17 22:00:35 +01:00
b325aae4f2 sweep: extract positive input set struct
A refactoring that introduces no functional changes. This prepares for
the addition of wallet utxos to push the sweep tx above the dust limit.

It also enabled access to input-specific sweep parameters during tx
generation. This will be used in later commits to control the sweep
process.
2019-12-17 22:00:34 +01:00
071c57d4a4 sweep: embed input.Input interface
Get rid of needless referencing of the embedded object.
2019-12-13 12:02:44 +01:00
38adfd7ecc sweep: create sweep parameters struct
Prepares for adding more input-specific sweep parameters.
2019-12-13 12:02:42 +01:00
e2bf6b49e9 sweep: fix bucket clustering
Fixes a bug where bucket sizes were not the configured size, but the
configured size plus the min relay fee.
2019-12-13 11:08:09 +01:00
50078216ca sweep: use bucket ids
Using a fee rate just as an identifier can be confusing.
2019-12-13 11:08:07 +01:00
777ed104a3 chainfee: create new chainfee package extracting fees from lnwallet
In this commit, we create a new chainfee package, that houses all fee
related functionality used within the codebase. The creation of this new
package furthers our long-term goal of extracting functionality from the
bloated `lnwallet` package into new distinct packages. Additionally,
this new packages resolves a class of import cycle that could arise if a
new package that was imported by something in `lnwallet` wanted to use
the existing fee related functions in the prior `lnwallet` package.
2019-10-31 16:41:57 -07:00
8e4a897a60 sweep: use chain notifier instead of chain IO for best block
Because the BestBlock method of ChainIO is not exposed through any
RPC we want to get rid of it so we can use the sweeper outside of
lnd too. Since the chain notifier now also delivers the current best
block we don't need the BestBlock method any more.
2019-10-14 15:32:54 +02:00
e69d93949c sweep: allow fee bumps of inputs/transactions within UtxoSweeper
In this commit, we introduce the ability to bump the fee of an input
within the UtxoSweeper. Once its fee rate is bumped, a replacement
transaction (RBF) will be broadcast with the newer fee rate (assuming
the newer fee rate is high enough to be valid), replacing any
conflicting lower fee rate transactions.

Note that this currently doesn't validate the fee preference of the
bump. This responsibility is delegated to the caller, so care must be
taken to ensure the new fee preference is sufficient.
2019-06-11 15:06:38 -07:00
c70858dc46 sweep: prevent default fee preference fallback
We want to make sure clients are aware of their own fee preferences,
rather than relying on defaults.
2019-06-11 15:06:35 -07:00
d75fac26bc sweep: expose pending input sweeps within the UtxoSweeper 2019-06-05 12:10:32 -07:00
50a8f188a3 sweep: add lastFeeRate field to PendingInput
This will serve useful when exposing the pending inputs over RPC, since
we currently don't keep track of the last fee rate used for an input.
2019-06-05 12:10:31 -07:00