@@ -184,6 +184,15 @@ type InitFundingReserveMsg struct {
184184 // used.
185185 ChanFunder chanfunding.Assembler
186186
187+ // AllowUtxoForFunding enables the channel funding workflow to restrict
188+ // the selection of utxos when selecting the inputs for the channel
189+ // opening. This does ONLY apply for the internal wallet backed channel
190+ // opening case.
191+ //
192+ // NOTE: This is very useful when opening channels with unconfirmed
193+ // inputs to make sure stable non-replaceable inputs are used.
194+ AllowUtxoForFunding func (Utxo ) bool
195+
187196 // ZeroConf is a boolean that is true if a zero-conf channel was
188197 // negotiated.
189198 ZeroConf bool
@@ -849,7 +858,9 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
849858 // P2WPKH dust limit and to avoid threading through two
850859 // different dust limits.
851860 cfg := chanfunding.WalletConfig {
852- CoinSource : & CoinSource {l },
861+ CoinSource : NewCoinSource (
862+ l , req .AllowUtxoForFunding ,
863+ ),
853864 CoinSelectLocker : l ,
854865 CoinLeaser : l ,
855866 Signer : l .Cfg .Signer ,
@@ -2525,12 +2536,16 @@ func (l *LightningWallet) CancelRebroadcast(txid chainhash.Hash) {
25252536// CoinSource is a wrapper around the wallet that implements the
25262537// chanfunding.CoinSource interface.
25272538type CoinSource struct {
2528- wallet * LightningWallet
2539+ wallet * LightningWallet
2540+ allowUtxo func (Utxo ) bool
25292541}
25302542
25312543// NewCoinSource creates a new instance of the CoinSource wrapper struct.
2532- func NewCoinSource (w * LightningWallet ) * CoinSource {
2533- return & CoinSource {wallet : w }
2544+ func NewCoinSource (w * LightningWallet , allowUtxo func (Utxo ) bool ) * CoinSource {
2545+ return & CoinSource {
2546+ wallet : w ,
2547+ allowUtxo : allowUtxo ,
2548+ }
25342549}
25352550
25362551// ListCoins returns all UTXOs from the source that have between
@@ -2546,7 +2561,18 @@ func (c *CoinSource) ListCoins(minConfs int32,
25462561 }
25472562
25482563 var coins []wallet.Coin
2564+
25492565 for _ , utxo := range utxos {
2566+ // If there is a filter function supplied all utxos not adhering
2567+ // to these conditions will be discared.
2568+ if c .allowUtxo != nil && ! c .allowUtxo (* utxo ) {
2569+ walletLog .Infof ("Cannot use unconfirmed " +
2570+ "utxo=%v because it is unstable and could be " +
2571+ "replaced" , utxo .OutPoint )
2572+
2573+ continue
2574+ }
2575+
25502576 coins = append (coins , wallet.Coin {
25512577 TxOut : wire.TxOut {
25522578 Value : int64 (utxo .Value ),
0 commit comments