@@ -28,13 +28,23 @@ use super::{
2828 WalletSource ,
2929} ;
3030
31- /// A synchronous version of the [`WalletSource`] trait.
31+ /// An alternative to [`CoinSelectionSourceSync`] that can be implemented and used along
32+ /// [`WalletSync`] to provide a default implementation to [`CoinSelectionSourceSync`].
33+ ///
34+ /// For an asynchronous version of this trait, see [`WalletSource`].
35+ // Note that updates to documentation on this trait should be copied to the asynchronous version.
3236pub trait WalletSourceSync {
33- /// A synchronous version of [`WalletSource::list_confirmed_utxos`] .
37+ /// Returns all UTXOs, with at least 1 confirmation each, that are available to spend .
3438 fn list_confirmed_utxos ( & self ) -> Result < Vec < Utxo > , ( ) > ;
35- /// A synchronous version of [`WalletSource::get_change_script`].
39+ /// Returns a script to use for change above dust resulting from a successful coin selection
40+ /// attempt.
3641 fn get_change_script ( & self ) -> Result < ScriptBuf , ( ) > ;
37- /// A Synchronous version of [`WalletSource::sign_psbt`].
42+ /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
43+ /// the transaction known to the wallet (i.e., any provided via
44+ /// [`WalletSource::list_confirmed_utxos`]).
45+ ///
46+ /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
47+ /// unsigned transaction and then sign it with your wallet.
3848 fn sign_psbt ( & self , psbt : Psbt ) -> Result < Transaction , ( ) > ;
3949}
4050
7484 }
7585}
7686
77- /// A synchronous wrapper around [`Wallet`] to be used in contexts where async is not available.
87+ /// A wrapper over [`WalletSourceSync`] that implements [`CoinSelectionSync`] by preferring UTXOs
88+ /// that would avoid conflicting double spends. If not enough UTXOs are available to do so,
89+ /// conflicting double spends may happen.
90+ ///
91+ /// For an asynchronous version of this wrapper, see [`Wallet`].
92+ // Note that updates to documentation on this struct should be copied to the asynchronous version.
7893pub struct WalletSync < W : Deref + MaybeSync + MaybeSend , L : Deref + MaybeSync + MaybeSend >
7994where
8095 W :: Target : WalletSourceSync + MaybeSend ,
@@ -136,15 +151,59 @@ where
136151 }
137152}
138153
139- /// A synchronous version of the [`CoinSelectionSource`] trait.
154+ /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
155+ /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
156+ /// which most wallets should be able to satisfy. Otherwise, consider implementing
157+ /// [`WalletSourceSync`], which can provide a default implementation of this trait when used with
158+ /// [`WalletSync`].
159+ ///
160+ /// For an asynchronous version of this trait, see [`CoinSelectionSource`].
161+ // Note that updates to documentation on this trait should be copied to the asynchronous version.
140162pub trait CoinSelectionSourceSync {
141- /// A synchronous version of [`CoinSelectionSource::select_confirmed_utxos`].
163+ /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
164+ /// available to spend. Implementations are free to pick their coin selection algorithm of
165+ /// choice, as long as the following requirements are met:
166+ ///
167+ /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
168+ /// throughout coin selection, but must not be returned as part of the result.
169+ /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
170+ /// throughout coin selection. In some cases, like when funding an anchor transaction, this
171+ /// set is empty. Implementations should ensure they handle this correctly on their end,
172+ /// e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
173+ /// provided, in which case a zero-value empty OP_RETURN output can be used instead.
174+ /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
175+ /// inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
176+ /// 4. The final transaction must have a weight smaller than `max_tx_weight`; if this
177+ /// constraint can't be met, return an `Err`. In the case of counterparty-signed HTLC
178+ /// transactions, we will remove a chunk of HTLCs and try your algorithm again. As for
179+ /// anchor transactions, we will try your coin selection again with the same input-output
180+ /// set when you call [`ChannelMonitor::rebroadcast_pending_claims`], as anchor transactions
181+ /// cannot be downsized.
182+ ///
183+ /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
184+ /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
185+ /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
186+ /// delaying block inclusion.
187+ ///
188+ /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
189+ /// can be re-used within new fee-bumped iterations of the original claiming transaction,
190+ /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
191+ /// transaction associated with it, and all of the available UTXOs have already been assigned to
192+ /// other claims, implementations must be willing to double spend their UTXOs. The choice of
193+ /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
194+ /// set of other claims being double spent to a minimum.
195+ ///
196+ /// [`ChannelMonitor::rebroadcast_pending_claims`]: crate::chain::channelmonitor::ChannelMonitor::rebroadcast_pending_claims
142197 fn select_confirmed_utxos (
143198 & self , claim_id : ClaimId , must_spend : Vec < Input > , must_pay_to : & [ TxOut ] ,
144199 target_feerate_sat_per_1000_weight : u32 , max_tx_weight : u64 ,
145200 ) -> Result < CoinSelection , ( ) > ;
146201
147- /// A synchronous version of [`CoinSelectionSource::sign_psbt`].
202+ /// Signs and provides the full witness for all inputs within the transaction known to the
203+ /// trait (i.e., any provided via [`CoinSelectionSourceSync::select_confirmed_utxos`]).
204+ ///
205+ /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
206+ /// unsigned transaction and then sign it with your wallet.
148207 fn sign_psbt ( & self , psbt : Psbt ) -> Result < Transaction , ( ) > ;
149208}
150209
@@ -188,7 +247,14 @@ where
188247 }
189248}
190249
191- /// A synchronous wrapper around [`BumpTransactionEventHandler`] to be used in contexts where async is not available.
250+ /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
251+ /// [`CoinSelectionSourceSync`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
252+ /// Replace-By-Fee (RBF).
253+ ///
254+ /// For an asynchronous version of this handler, see [`BumpTransactionEventHandler`].
255+ ///
256+ /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
257+ // Note that updates to documentation on this struct should be copied to the synchronous version.
192258pub struct BumpTransactionEventHandlerSync < B : Deref , C : Deref , SP : Deref , L : Deref >
193259where
194260 B :: Target : BroadcasterInterface ,
0 commit comments