multi: Utxo restriction single funding case.
Restrict the utxo selection when opening a single internal wallet funded backed channel.
This commit is contained in:
6 files changed
+87
-12
No files matched your search
@@ -334,7 +334,8 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
|
||||
}
|
||||
for _, coin := range manuallySelectedCoins {
|
||||
if _, ok := unspent[coin.OutPoint]; !ok {
|
||||
return fmt.Errorf("outpoint already spent: %v",
|
||||
return fmt.Errorf("outpoint already spent or "+
|
||||
"locked by another subsystem: %v",
|
||||
coin.OutPoint)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2963,7 +2963,9 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
// we'll create a new chanfunding.Assembler hacked by Alice's wallet.
|
||||
aliceChanFunder := chanfunding.NewWalletAssembler(
|
||||
chanfunding.WalletConfig{
|
||||
CoinSource: lnwallet.NewCoinSource(alice),
|
||||
CoinSource: lnwallet.NewCoinSource(
|
||||
alice, nil,
|
||||
),
|
||||
CoinSelectLocker: alice,
|
||||
CoinLeaser: alice,
|
||||
Signer: alice.Cfg.Signer,
|
||||
|
||||
+30
-4
@@ -184,6 +184,15 @@ type InitFundingReserveMsg struct {
|
||||
// used.
|
||||
ChanFunder chanfunding.Assembler
|
||||
|
||||
// AllowUtxoForFunding enables the channel funding workflow to restrict
|
||||
// the selection of utxos when selecting the inputs for the channel
|
||||
// opening. This does ONLY apply for the internal wallet backed channel
|
||||
// opening case.
|
||||
//
|
||||
// NOTE: This is very useful when opening channels with unconfirmed
|
||||
// inputs to make sure stable non-replaceable inputs are used.
|
||||
AllowUtxoForFunding func(Utxo) bool
|
||||
|
||||
// ZeroConf is a boolean that is true if a zero-conf channel was
|
||||
// negotiated.
|
||||
ZeroConf bool
|
||||
@@ -849,7 +858,9 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
||||
// P2WPKH dust limit and to avoid threading through two
|
||||
// different dust limits.
|
||||
cfg := chanfunding.WalletConfig{
|
||||
CoinSource: &CoinSource{l},
|
||||
CoinSource: NewCoinSource(
|
||||
l, req.AllowUtxoForFunding,
|
||||
),
|
||||
CoinSelectLocker: l,
|
||||
CoinLeaser: l,
|
||||
Signer: l.Cfg.Signer,
|
||||
@@ -2525,12 +2536,16 @@ func (l *LightningWallet) CancelRebroadcast(txid chainhash.Hash) {
|
||||
// CoinSource is a wrapper around the wallet that implements the
|
||||
// chanfunding.CoinSource interface.
|
||||
type CoinSource struct {
|
||||
wallet *LightningWallet
|
||||
wallet *LightningWallet
|
||||
allowUtxo func(Utxo) bool
|
||||
}
|
||||
|
||||
// NewCoinSource creates a new instance of the CoinSource wrapper struct.
|
||||
func NewCoinSource(w *LightningWallet) *CoinSource {
|
||||
return &CoinSource{wallet: w}
|
||||
func NewCoinSource(w *LightningWallet, allowUtxo func(Utxo) bool) *CoinSource {
|
||||
return &CoinSource{
|
||||
wallet: w,
|
||||
allowUtxo: allowUtxo,
|
||||
}
|
||||
}
|
||||
|
||||
// ListCoins returns all UTXOs from the source that have between
|
||||
@@ -2546,7 +2561,18 @@ func (c *CoinSource) ListCoins(minConfs int32,
|
||||
}
|
||||
|
||||
var coins []wallet.Coin
|
||||
|
||||
for _, utxo := range utxos {
|
||||
// If there is a filter function supplied all utxos not adhering
|
||||
// to these conditions will be discared.
|
||||
if c.allowUtxo != nil && !c.allowUtxo(*utxo) {
|
||||
walletLog.Infof("Cannot use unconfirmed "+
|
||||
"utxo=%v because it is unstable and could be "+
|
||||
"replaced", utxo.OutPoint)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
coins = append(coins, wallet.Coin{
|
||||
TxOut: wire.TxOut{
|
||||
Value: int64(utxo.Value),
|
||||
|
||||
Reference in new issue
Block a user