@@ -564,7 +564,15 @@ class COutput
564564{
565565public:
566566 const CWalletTx *tx;
567+
568+ /* * Index in tx->vout. */
567569 int i;
570+
571+ /* *
572+ * Depth in block chain.
573+ * If > 0: the tx is on chain and has this many confirmations.
574+ * If = 0: the tx is waiting confirmation.
575+ * If < 0: a conflicting tx is on chain and has this many confirmations. */
568576 int nDepth;
569577
570578 /* * Pre-computed estimated size of this output as a fully-signed input in a transaction. Can be -1 if it could not be calculated */
@@ -604,17 +612,30 @@ class COutput
604612 }
605613};
606614
615+ /* * Parameters for one iteration of Coin Selection. */
607616struct CoinSelectionParams
608617{
618+ /* * Toggles use of Branch and Bound instead of Knapsack solver. */
609619 bool use_bnb = true ;
620+ /* * Size of a change output in bytes, determined by the output type. */
610621 size_t change_output_size = 0 ;
622+ /* * Size of the input to spend a change output in virtual bytes. */
611623 size_t change_spend_size = 0 ;
624+ /* * The targeted feerate of the transaction being built. */
612625 CFeeRate m_effective_feerate;
626+ /* * The feerate estimate used to estimate an upper bound on what should be sufficient to spend
627+ * the change output sometime in the future. */
613628 CFeeRate m_long_term_feerate;
629+ /* * If the cost to spend a change output at the discard feerate exceeds its value, drop it to fees. */
614630 CFeeRate m_discard_feerate;
631+ /* * Size of the transaction before coin selection, consisting of the header and recipient
632+ * output(s), excluding the inputs and change output(s). */
615633 size_t tx_noinputs_size = 0 ;
616634 /* * Indicate that we are subtracting the fee from outputs */
617635 bool m_subtract_fee_outputs = false ;
636+ /* * When true, always spend all (up to OUTPUT_GROUP_MAX_ENTRIES) or none of the outputs
637+ * associated with the same address. This helps reduce privacy leaks resulting from address
638+ * reuse. Dust outputs are not eligible to be added to output groups and thus not considered. */
618639 bool m_avoid_partial_spends = false ;
619640
620641 CoinSelectionParams (bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_feerate,
@@ -652,7 +673,10 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
652673 // ! the current wallet version: clients below this version are not able to load the wallet
653674 int nWalletVersion GUARDED_BY (cs_wallet){FEATURE_BASE};
654675
676+ /* * The next scheduled rebroadcast of wallet transactions. */
655677 int64_t nNextResend = 0 ;
678+ /* * Whether this wallet will submit newly created transactions to the node's mempool and
679+ * prompt rebroadcasts (see ResendWalletTransactions()). */
656680 bool fBroadcastTransactions = false ;
657681 // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
658682 std::atomic<int64_t > m_best_block_time {0 };
@@ -694,6 +718,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
694718 * Should be called with non-zero block_hash and posInBlock if this is for a transaction that is included in a block. */
695719 void SyncTransaction (const CTransactionRef& tx, CWalletTx::Confirmation confirm, bool update_tx = true ) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
696720
721+ /* * WalletFlags set on this wallet. */
697722 std::atomic<uint64_t > m_wallet_flags{0 };
698723
699724 bool SetAddressBookWithDB (WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose);
@@ -753,8 +778,11 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
753778
754779 /* *
755780 * Select a set of coins such that nValueRet >= nTargetValue and at least
756- * all coins from coinControl are selected; Never select unconfirmed coins
757- * if they are not ours
781+ * all coins from coin_control are selected; never select unconfirmed coins if they are not ours
782+ * param@[out] setCoinsRet Populated with inputs including pre-selected inputs from
783+ * coin_control and Coin Selection if successful.
784+ * param@[out] nValueRet Total value of selected coins including pre-selected ones
785+ * from coin_control and Coin Selection if successful.
758786 */
759787 bool SelectCoins (const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
760788 const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool & bnb_used) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@@ -788,6 +816,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
788816 /* * Interface to assert chain access */
789817 bool HaveChain () const { return m_chain ? true : false ; }
790818
819+ /* * Map from txid to CWalletTx for all transactions this wallet is
820+ * interested in, including received and sent transactions. */
791821 std::map<uint256, CWalletTx> mapWallet GUARDED_BY (cs_wallet);
792822
793823 typedef std::multimap<int64_t , CWalletTx*> TxItems;
@@ -799,6 +829,10 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
799829 std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY (cs_wallet);
800830 const CAddressBookData* FindAddressBookEntry (const CTxDestination&, bool allow_change = false ) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
801831
832+ /* * Set of Coins owned by this wallet that we won't try to spend from. A
833+ * Coin may be locked if it has already been used to fund a transaction
834+ * that hasn't confirmed yet. We wouldn't consider the Coin spent already,
835+ * but also shouldn't try to use it again. */
802836 std::set<COutPoint> setLockedCoins GUARDED_BY (cs_wallet);
803837
804838 /* * Registered interfaces::Chain::Notifications handler. */
@@ -833,6 +867,11 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
833867 * small change; This method is stochastic for some inputs and upon
834868 * completion the coin set and corresponding actual target value is
835869 * assembled
870+ * param@[in] coins Set of UTXOs to consider. These will be categorized into
871+ * OutputGroups and filtered using eligibility_filter before
872+ * selecting coins.
873+ * param@[out] setCoinsRet Populated with the coins selected if successful.
874+ * param@[out] nValueRet Used to return the total value of selected coins.
836875 */
837876 bool SelectCoinsMinConf (const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<COutput> coins,
838877 std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CoinSelectionParams& coin_selection_params, bool & bnb_used) const ;
@@ -1015,6 +1054,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10151054
10161055 CFeeRate m_pay_tx_fee{DEFAULT_PAY_TX_FEE};
10171056 unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};
1057+ /* * Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it
1058+ * cannot fund the transaction otherwise. */
10181059 bool m_spend_zero_conf_change{DEFAULT_SPEND_ZEROCONF_CHANGE};
10191060 bool m_signal_rbf{DEFAULT_WALLET_RBF};
10201061 bool m_allow_fallback_fee{true }; // !< will be false if -fallbackfee=0
@@ -1025,7 +1066,12 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10251066 * Override with -fallbackfee
10261067 */
10271068 CFeeRate m_fallback_fee{DEFAULT_FALLBACK_FEE};
1069+
1070+ /* * If the cost to spend a change output at this feerate is greater than the value of the
1071+ * output itself, just drop it to fees. */
10281072 CFeeRate m_discard_rate{DEFAULT_DISCARD_FEE};
1073+
1074+ /* * The maximum fee amount we're willing to pay to prioritize partial spend avoidance. */
10291075 CAmount m_max_aps_fee{DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}; // !< note: this is absolute fee, not fee rate
10301076 OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE};
10311077 /* *
0 commit comments