Commit graph

318 commits

Author SHA1 Message Date
yyforyongyu
74161f0d57
sweep: make sure recovered inputs are retried
Previously, when a given input is found spent in the mempool, we'd mark
it as Published and never offer it to the fee bumper. This is dangerous
as the input will never be fee bumped. We now fix it by always
initializing the input with state Init, and only use mempool to check
for fee and fee rate.

This changes the current restart behavior - as previously when a
sweeping tx is broadcast, the node shuts down, when it starts again, the
input will be offered to the sweeper again, but not to the fee bumper,
which means the sweeping tx will stay in the mempool with the last-tried
fee rate. After this change, after a restart, the input will be swept
again, and the fee bumper will monitor its status. The restart will also
behave like a fee bump if there's already an existing sweeping tx in the
mempool.
2025-02-20 14:40:54 +08:00
yyforyongyu
4bd1a344b9
sweep: signal tx in markInputFatal
This commit adds the failed tx to the result when marking the input as
fatal, which is used in the commit resolver when handling revoked
outputs.
2025-02-20 14:40:54 +08:00
yyforyongyu
b184afe227
sweep: handle missing inputs during fee bumping
This commit handles the case when the input is missing during the RBF
process, which could happen when the bumped tx has inputs being spent by
a third party. Normally we should be able to catch the spend early via
the spending notification and never attempt to fee bump the record.
However, due to the possible race between block notification and spend
notification, this cannot be guaranteed. Thus, we need to handle the
case during the RBF when seeing a `ErrMissingInputs`, which can only
happen when the inputs are spent by others.
2025-02-20 14:40:53 +08:00
yyforyongyu
4f469de18e
sweep: refactor handleInitialTxError and createAndCheckTx
This commit refactors `handleInitialTxError` and `createAndCheckTx` to
take a `monitorRecord` param, which prepares for the following commit
where we start handling missing inputs.
2025-02-20 14:40:53 +08:00
yyforyongyu
f614e7aed9
sweep: add createUnknownSpentBumpResult
A minor refactor to break the method `handleUnknownSpent` into two
steps, which prepares the following commit where we start handling
missing inputs.
2025-02-20 14:40:53 +08:00
yyforyongyu
db8319d70b
sweep: add method handleReplacementTxError
This is a minor refactor so the `createAndPublishTx` flow becomes more
clear, also prepares for the following commit where we start to handle
missing inputs.
2025-02-20 14:40:53 +08:00
yyforyongyu
42818949dc
sweep: retry sweeping inputs upon TxUnknownSpend
We now start handling `TxUnknownSpend` in our sweeper to make sure the
failed inputs are retried when possible.
2025-02-20 14:40:53 +08:00
yyforyongyu
2f1205a394
sweep: start tracking inputs spent by unknown tx
This commit adds a new field `InputsSpent` to the `BumpResult` so they
can be used to track inputs spent by txns not recoginized by the fee
bumper.
2025-02-20 14:40:53 +08:00
yyforyongyu
db351e1908
sweep: rename methods for clarity
We now rename "third party" to "unknown" as the inputs can be spent via
an older sweeping tx, a third party (anchor), or a remote party (pin).
In fee bumper we don't have the info to distinguish the above cases, and
leave them to be further handled by the sweeper as it has more context.
2025-02-20 14:40:52 +08:00
yyforyongyu
121116cff7
sweep: remove dead code and add better logging 2025-02-20 14:40:52 +08:00
yyforyongyu
50bc191feb
sweep: handle unknown spent in processRecords
This commit refactors the `processRecords` to always handle the inputs
spent when processing the records. We now make sure to handle unknown
spends for all backends (previously only neutrino), and rely solely on
the spending notification to give us the onchain status of inputs.
2025-02-20 14:40:52 +08:00
yyforyongyu
61cec43951
sweep: add a new event TxUnknownSpend 2025-02-20 14:40:52 +08:00
yyforyongyu
8c9ba327cc
sweep: add method getSpentInputs
To track the input and its spending tx, which will be used later to
detect unknown spends.
2025-02-20 14:40:52 +08:00
yyforyongyu
e5f39dd644
sweep: refactor storeRecord to updateRecord
To make it clear we are only updating fields, which will be handy for
the following commit where we start tracking for spending notifications.
2025-02-05 19:49:09 +08:00
yyforyongyu
7eea7a7e9a
sweep: add requestID to monitorRecord
This way we can greatly simplify the method signatures, also paving the
upcoming changes where we wanna make it clear when updating the
monitorRecord, we only touch a portion of it.
2025-02-05 19:49:04 +08:00
yyforyongyu
bde5124e1b
sweep: shorten storeRecord method signature
This commit shortens the function signature of `storeRecord`, also makes
sure we don't call `t.records.Store` directly but always using
`storeRecord` instead so it's easier to trace the record creation.
2025-02-05 19:48:18 +08:00
yyforyongyu
c68b8e8c1e
sweep: rename Failed to Fatal
This commit renames `Failed` to `Fatal` as it sounds too close to
`PublishFailed`. We also wanna emphasize that inputs in this state won't
be retried.
2025-02-05 19:48:18 +08:00
yyforyongyu
4806b2fda7
multi: optimize loggings around changes from blockbeat 2024-12-20 17:54:08 +08:00
yyforyongyu
1d53e7d081
multi: improve loggings 2024-12-20 17:54:03 +08:00
yyforyongyu
545cea0546
multi: start consumers with a starting blockbeat
This is needed so the consumers have an initial state about the current
block.
2024-12-20 17:54:02 +08:00
yyforyongyu
3ac6752a77
sweep: remove redundant notifications during shutdown
This commit removes the hack introduced in #4851. Previously we had this
issue because the chain notifier was stopped before the sweeper, which
was changed a while back and we now always stop the chain notifier last.
In addition, since we no longer subscribe to the block epoch chan
directly, this issue can no longer happen.
2024-12-20 17:54:01 +08:00
yyforyongyu
e113f39d26
sweep: remove block subscription in UtxoSweeper and TxPublisher
This commit removes the independent block subscriptions in `UtxoSweeper`
and `TxPublisher`. These subsystems now listen to the `BlockbeatChan`
for new blocks.
2024-12-20 17:54:01 +08:00
yyforyongyu
801fd6b85b
multi: implement Consumer on subsystems
This commit implements `Consumer` on `TxPublisher`, `UtxoSweeper`,
`ChainArbitrator` and `ChannelArbitrator`.
2024-12-20 17:54:01 +08:00
yyforyongyu
30ee450091
sweep: make sure nil tx is handled
After previous commit, it should be clear that the tx may be failed to
created in a `TxFailed` event. We now make sure to catch it to avoid
panic.
2024-12-20 17:54:00 +08:00
yyforyongyu
78ce757e7b
sweep: break initialBroadcast into two steps
With the combination of the following commit we can have a more granular
control over the bump result when handling it in the sweeper.
2024-12-20 17:54:00 +08:00
yyforyongyu
f0c4e6dba1
sweep: remove redundant loopvar assign 2024-12-20 17:54:00 +08:00
yyforyongyu
7545bbfa92
sweep: make sure defaultDeadline is derived from the mature height 2024-12-20 17:54:00 +08:00
yyforyongyu
afc08c6623
sweep: add method isMature on SweeperInput
Also updated `handlePendingSweepsReq` to skip immature inputs so the
returned results are the same as those in pre-0.18.0.
2024-12-20 17:53:59 +08:00
yyforyongyu
ba238962d6
sweep: add method handleBumpEventError and fix markInputFailed
Previously in `markInputFailed`, we'd remove all inputs under the same
group via `removeExclusiveGroup`. This is wrong as when the current
sweep fails for this input, it shouldn't affect other inputs.
2024-12-20 17:53:59 +08:00
yyforyongyu
719ca5b229
sweep: remove redundant error from Broadcast 2024-12-20 17:53:59 +08:00
yyforyongyu
77ff2c0585
sweep: add handleInitialBroadcast to handle initial broadcast
This commit adds a new method `handleInitialBroadcast` to handle the
initial broadcast. Previously we'd broadcast immediately inside
`Broadcast`, which soon will not work after the `blockbeat` is
implemented as the action to publish is now always triggered by a new
block. Meanwhile, we still keep the option to bypass the block trigger
so users can broadcast immediately by setting `Immediate` to true.
2024-12-20 17:53:59 +08:00
yyforyongyu
2479dc7f2e
sweep: handle inputs locally instead of relying on the tx
This commit changes how inputs are handled upon receiving a bump result.
Previously the inputs are taken from the `BumpResult.Tx`, which is now
instead being handled locally as we will remember the input set when
sending the bump request, and handle this input set when a result is
received.
2024-12-20 17:53:59 +08:00
yyforyongyu
d0c7fd8aac
sweep: add new interface method Immediate
This prepares the following commit where we now let the fee bumpr
decides whether to broadcast immediately or not.
2024-12-20 17:53:59 +08:00
yyforyongyu
5f64280df4
sweep: add new error ErrZeroFeeRateDelta 2024-12-20 17:53:59 +08:00
yyforyongyu
6c2e8b9a00
sweep: add new state TxFatal for erroneous sweepings
Also updated the loggings. This new state will be used in the following
commit.
2024-12-20 17:53:58 +08:00
Keagan McClelland
ed2989ae33
multi: update to fn v2 2024-12-04 13:19:00 -07:00
Elle Mouton
ab7aae0708
multi: rename nolint:lll to nolint:ll
Find and replace all nolint instances refering to the `lll` linter and
replace with `ll` which is the name of our custom version of the `lll`
linter which can be used to ignore log lines during linting.

The next commit will do the configuration of the custom linter and
disable the default one.
2024-12-02 09:14:21 +02:00
chuangjinglu
bcfd8d5b47 multi: fix some function names in interface comment
Signed-off-by: chuangjinglu <chuangjinglu@outlook.com>
2024-11-25 10:49:00 +08:00
Olaoluwa Osuntokun
7ed2c10671
sweep: update storeRecord to include utxo index
In this commit, we complete a recently added feature by ensuring that
even if we go through the RBF loop to create a txn, that we still
populate the `outpointToIndex` map. Unit tests have been updated to
ensure this is always set as expected.
2024-11-18 18:12:41 -08:00
Olaoluwa Osuntokun
414894348a
sweep: update BudgetInputSet.Budget() to factor in extra budget
In this commit, we update the `Budget()` call to factor in the
`extraBudget` value. Otherwise, when we go to intialize the fee
function, we won't factor in the extra budget, and will determine that
we can't broadcast/bump.
2024-11-14 16:09:59 -08:00
Olaoluwa Osuntokun
ba16a74491
sweep: expand NotifyBroadcast to include an outpoint index
In this commit, we expand the `NotifyBroadcast` to include an outpoint
index. This is useful as it indicates the index of a given required tx
out input.
2024-11-14 16:09:58 -08:00
Elle Mouton
23602e017e
multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
Olaoluwa Osuntokun
bdaa9f4146
sweep: ensure we factor in extra change addrs in MaxFeeRateAllowed 2024-10-02 18:10:14 -07:00
Olaoluwa Osuntokun
eaea11e48f
sweep: update sweeper to use AuxSweeper to add extra change addr
In this commit, we start to use the AuxSweeper (if present) to obtain a
new extra change addr we should add to the sweeping transaction. With
this, we'll take the set of inputs and our change addr, and then maybe
gain a new change addr to add to the sweep transaction.

The extra change addr will be treated as an extra required tx out,
shared across all the relevant inputs. This'll also be used in
NeedWalletInput to make sure that we add an extra input if needed to be
able to pay for the change addr.
2024-10-02 18:09:58 -07:00
Olaoluwa Osuntokun
cb93f8c01a
sweep: add new AuxSweeper interface
In this commit, we add a new AuxSweeper interface. This'll take a set of
inputs, and a change addr for the sweep transaction, then optionally
return a new sweep output to be added to the sweep transaction.

We also add a new NotifyBroadcast method.  This'll be used to notify
that we're _about_ to broadcast a sweeping transaction. The set of
inputs is passed in, which allows the caller to prepare for the ultimate
broadcast of the sweeping transaction.

We also add ExtraTxOut to BumpRequest pass fees to NotifyBroadcast. This
allows the callee to know the total fee of the sweeping transaction.
2024-10-02 18:09:57 -07:00
Olaoluwa Osuntokun
d52d30d46e
server+sweep: convert GenSweepScript to use new addr type
We convert it to use lnwallet.AddrWithKey, as in the future, knowing the
internal key for an address will be useful.
2024-10-02 18:09:56 -07:00
Olaoluwa Osuntokun
e0ced8e629
lnwallet+peer: move internalKeyForAddr to lnwallet package
This way we can re-use it. We also make it slightly more generalized.
2024-10-02 18:09:52 -07:00
Olaoluwa Osuntokun
cc9e2b783e
Merge pull request #8961 from yyforyongyu/fix-leaseoutput
Improve the performace of `LeaseOutput`
2024-08-21 16:31:26 -07:00
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
3e36adf476
mulit: remove ListLeasedOutputs in LeaseOutput
This commit removes the call toe `ListLeasedOutputs` in `LeaseOutput` -
the returned info from `ListLeasedOutputs` can easily be accessed via
`FetchInputInfo` and this info is only used at one callsite.
`ListLeasedOutputs` then becomes unnecessary here, plus it's very slow
and needs to be refactored in `btcwallet` instead.
2024-08-09 22:01:57 +08:00