Skip to content

Commit

Permalink
lnwallet: Change utxo selection for chan opening.
Browse files Browse the repository at this point in the history
Disallow the usage of unconfirmed funds resulting from the sweeper
subsystem. This avoids side effects because those utxos can still
be RBFed by the sweeper.
  • Loading branch information
ziggie1984 committed Mar 13, 2024
1 parent ad8592b commit 546e369
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lnwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math"
"net"
"strings"
"sync"
"sync/atomic"

Expand All @@ -25,6 +26,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/labels"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
Expand Down Expand Up @@ -2544,6 +2546,28 @@ func (c *CoinSource) ListCoins(minConfs int32,

var coins []wallet.Coin
for _, utxo := range utxos {
// We don't include utxos which are unconfirmed yet and
// resulted from the sweeper subsystem, because those
// unconfirmed utxos can still be RBFed therefore causing side
// effects especially when opening zeroconf channels.
if utxo.Confirmations == 0 {
label, err := c.wallet.FetchTxLabel(utxo.Hash)
if err != nil {
return nil, err
}

sweepLabel := labels.MakeLabel(
labels.LabelTypeSweepTransaction, nil)

if strings.Contains(label, sweepLabel) {
walletLog.Infof("Cannot use unconfirmed "+
"utxo=%v because it used by the "+
"sweeper", utxo.OutPoint)

continue
}
}

coins = append(coins, wallet.Coin{
TxOut: wire.TxOut{
Value: int64(utxo.Value),
Expand Down

0 comments on commit 546e369

Please sign in to comment.