2019-12-10 15:32:57 +01:00
|
|
|
package sweep
|
|
|
|
|
|
|
|
import (
|
2024-06-04 08:06:17 +02:00
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
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-02-18 03:25:30 +01:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2019-12-10 15:32:57 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2024-06-04 08:06:17 +02:00
|
|
|
"github.com/lightningnetwork/lnd/fn"
|
|
|
|
"github.com/lightningnetwork/lnd/input"
|
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
2019-12-10 16:06:45 +01:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
2019-12-10 15:32:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Wallet contains all wallet related functionality required by sweeper.
|
|
|
|
type Wallet interface {
|
|
|
|
// PublishTransaction performs cursory validation (dust checks, etc) and
|
|
|
|
// broadcasts the passed transaction to the Bitcoin network.
|
2020-05-18 14:13:23 +02:00
|
|
|
PublishTransaction(tx *wire.MsgTx, label string) error
|
2019-12-10 16:06:45 +01:00
|
|
|
|
2021-02-20 02:41:50 +01:00
|
|
|
// ListUnspentWitnessFromDefaultAccount returns all unspent outputs
|
|
|
|
// which are version 0 witness programs from the default wallet account.
|
2021-04-22 19:04:00 +02:00
|
|
|
// The 'minConfs' and 'maxConfs' parameters indicate the minimum
|
2021-02-20 02:41:50 +01:00
|
|
|
// and maximum number of confirmations an output needs in order to be
|
|
|
|
// returned by this method.
|
2021-04-22 19:04:00 +02:00
|
|
|
ListUnspentWitnessFromDefaultAccount(minConfs, maxConfs int32) (
|
2021-02-20 02:41:50 +01:00
|
|
|
[]*lnwallet.Utxo, error)
|
2019-12-10 16:06:45 +01:00
|
|
|
|
|
|
|
// WithCoinSelectLock will execute the passed function closure in a
|
|
|
|
// synchronized manner preventing any coin selection operations from
|
2020-03-19 05:43:49 +01:00
|
|
|
// proceeding while the closure is executing. This can be seen as the
|
2019-12-10 16:06:45 +01:00
|
|
|
// ability to execute a function closure under an exclusive coin
|
|
|
|
// selection lock.
|
|
|
|
WithCoinSelectLock(f func() error) error
|
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-02-18 03:25:30 +01:00
|
|
|
|
|
|
|
// RemoveDescendants removes any wallet transactions that spends
|
|
|
|
// outputs created by the specified transaction.
|
|
|
|
RemoveDescendants(*wire.MsgTx) error
|
|
|
|
|
|
|
|
// FetchTx returns the transaction that corresponds to the transaction
|
|
|
|
// hash passed in. If the transaction can't be found then a nil
|
|
|
|
// transaction pointer is returned.
|
|
|
|
FetchTx(chainhash.Hash) (*wire.MsgTx, error)
|
2023-04-14 23:58:13 +02:00
|
|
|
|
|
|
|
// CancelRebroadcast is used to inform the rebroadcaster sub-system
|
|
|
|
// that it no longer needs to try to rebroadcast a transaction. This is
|
|
|
|
// used to ensure that invalid transactions (inputs spent) aren't
|
|
|
|
// retried in the background.
|
|
|
|
CancelRebroadcast(tx chainhash.Hash)
|
2024-02-28 20:07:22 +01:00
|
|
|
|
|
|
|
// CheckMempoolAcceptance checks whether a transaction follows mempool
|
|
|
|
// policies and returns an error if it cannot be accepted into the
|
|
|
|
// mempool.
|
|
|
|
CheckMempoolAcceptance(tx *wire.MsgTx) error
|
2024-02-29 12:36:37 +01:00
|
|
|
|
|
|
|
// GetTransactionDetails returns a detailed description of a tx given
|
|
|
|
// its transaction hash.
|
|
|
|
GetTransactionDetails(txHash *chainhash.Hash) (
|
|
|
|
*lnwallet.TransactionDetail, error)
|
2024-04-12 19:11:54 +02:00
|
|
|
|
|
|
|
// BackEnd returns a name for the wallet's backing chain service,
|
|
|
|
// which could be e.g. btcd, bitcoind, neutrino, or another consensus
|
|
|
|
// service.
|
|
|
|
BackEnd() string
|
2019-12-10 15:32:57 +01:00
|
|
|
}
|
2024-06-04 08:06:17 +02:00
|
|
|
|
|
|
|
// SweepOutput is an output used to sweep funds from a channel output.
|
|
|
|
type SweepOutput struct { //nolint:revive
|
|
|
|
wire.TxOut
|
|
|
|
|
|
|
|
// IsExtra indicates whether this output is an extra output that was
|
|
|
|
// added by a party other than the sweeper.
|
|
|
|
IsExtra bool
|
|
|
|
|
|
|
|
// InternalKey is the taproot internal key of the extra output. This is
|
|
|
|
// None, if this isn't a taproot output.
|
|
|
|
InternalKey fn.Option[keychain.KeyDescriptor]
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuxSweeper is used to enable a 3rd party to further shape the sweeping
|
|
|
|
// transaction by adding a set of extra outputs to the sweeping transaction.
|
|
|
|
type AuxSweeper interface {
|
|
|
|
// DeriveSweepAddr takes a set of inputs, and the change address we'd
|
|
|
|
// use to sweep them, and maybe results an extra sweep output that we
|
|
|
|
// should add to the sweeping transaction.
|
|
|
|
DeriveSweepAddr(inputs []input.Input,
|
|
|
|
change lnwallet.AddrWithKey) fn.Result[SweepOutput]
|
|
|
|
|
2024-06-04 08:08:37 +02:00
|
|
|
// ExtraBudgetForInputs is used to determine the extra budget that
|
|
|
|
// should be allocated to sweep the given set of inputs. This can be
|
|
|
|
// used to add extra funds to the sweep transaction, for example to
|
|
|
|
// cover fees for additional outputs of custom channels.
|
|
|
|
ExtraBudgetForInputs(inputs []input.Input) fn.Result[btcutil.Amount]
|
|
|
|
|
2024-06-04 08:06:17 +02:00
|
|
|
// NotifyBroadcast is used to notify external callers of the broadcast
|
|
|
|
// of a sweep transaction, generated by the passed BumpRequest.
|
|
|
|
NotifyBroadcast(req *BumpRequest, tx *wire.MsgTx,
|
|
|
|
totalFees btcutil.Amount) error
|
|
|
|
}
|