@@ -28,13 +28,26 @@ 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.
48+ ///
49+ /// [`TxIn::script_sig`]: bitcoin::TxIn::script_sig
50+ /// [`TxIn::witness`]: bitcoin::TxIn::witness
3851 fn sign_psbt ( & self , psbt : Psbt ) -> Result < Transaction , ( ) > ;
3952}
4053
7487 }
7588}
7689
77- /// A synchronous wrapper around [`Wallet`] to be used in contexts where async is not available.
90+ /// A wrapper over [`WalletSourceSync`] that implements [`CoinSelectionSourceSync`] by preferring
91+ /// UTXOs that would avoid conflicting double spends. If not enough UTXOs are available to do so,
92+ /// conflicting double spends may happen.
93+ ///
94+ /// For an asynchronous version of this wrapper, see [`Wallet`].
95+ // Note that updates to documentation on this struct should be copied to the asynchronous version.
7896pub struct WalletSync < W : Deref + MaybeSync + MaybeSend , L : Deref + MaybeSync + MaybeSend >
7997where
8098 W :: Target : WalletSourceSync + MaybeSend ,
@@ -136,15 +154,59 @@ where
136154 }
137155}
138156
139- /// A synchronous version of the [`CoinSelectionSource`] trait.
157+ /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
158+ /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
159+ /// which most wallets should be able to satisfy. Otherwise, consider implementing
160+ /// [`WalletSourceSync`], which can provide a default implementation of this trait when used with
161+ /// [`WalletSync`].
162+ ///
163+ /// For an asynchronous version of this trait, see [`CoinSelectionSource`].
164+ // Note that updates to documentation on this trait should be copied to the asynchronous version.
140165pub trait CoinSelectionSourceSync {
141- /// A synchronous version of [`CoinSelectionSource::select_confirmed_utxos`].
166+ /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
167+ /// available to spend. Implementations are free to pick their coin selection algorithm of
168+ /// choice, as long as the following requirements are met:
169+ ///
170+ /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
171+ /// throughout coin selection, but must not be returned as part of the result.
172+ /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
173+ /// throughout coin selection. In some cases, like when funding an anchor transaction, this
174+ /// set is empty. Implementations should ensure they handle this correctly on their end,
175+ /// e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
176+ /// provided, in which case a zero-value empty OP_RETURN output can be used instead.
177+ /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
178+ /// inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
179+ /// 4. The final transaction must have a weight smaller than `max_tx_weight`; if this
180+ /// constraint can't be met, return an `Err`. In the case of counterparty-signed HTLC
181+ /// transactions, we will remove a chunk of HTLCs and try your algorithm again. As for
182+ /// anchor transactions, we will try your coin selection again with the same input-output
183+ /// set when you call [`ChannelMonitor::rebroadcast_pending_claims`], as anchor transactions
184+ /// cannot be downsized.
185+ ///
186+ /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
187+ /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
188+ /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
189+ /// delaying block inclusion.
190+ ///
191+ /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
192+ /// can be re-used within new fee-bumped iterations of the original claiming transaction,
193+ /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
194+ /// transaction associated with it, and all of the available UTXOs have already been assigned to
195+ /// other claims, implementations must be willing to double spend their UTXOs. The choice of
196+ /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
197+ /// set of other claims being double spent to a minimum.
198+ ///
199+ /// [`ChannelMonitor::rebroadcast_pending_claims`]: crate::chain::channelmonitor::ChannelMonitor::rebroadcast_pending_claims
142200 fn select_confirmed_utxos (
143201 & self , claim_id : ClaimId , must_spend : Vec < Input > , must_pay_to : & [ TxOut ] ,
144202 target_feerate_sat_per_1000_weight : u32 , max_tx_weight : u64 ,
145203 ) -> Result < CoinSelection , ( ) > ;
146204
147- /// A synchronous version of [`CoinSelectionSource::sign_psbt`].
205+ /// Signs and provides the full witness for all inputs within the transaction known to the
206+ /// trait (i.e., any provided via [`CoinSelectionSourceSync::select_confirmed_utxos`]).
207+ ///
208+ /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
209+ /// unsigned transaction and then sign it with your wallet.
148210 fn sign_psbt ( & self , psbt : Psbt ) -> Result < Transaction , ( ) > ;
149211}
150212
@@ -188,7 +250,14 @@ where
188250 }
189251}
190252
191- /// A synchronous wrapper around [`BumpTransactionEventHandler`] to be used in contexts where async is not available.
253+ /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
254+ /// [`CoinSelectionSourceSync`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
255+ /// Replace-By-Fee (RBF).
256+ ///
257+ /// For an asynchronous version of this handler, see [`BumpTransactionEventHandler`].
258+ ///
259+ /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
260+ // Note that updates to documentation on this struct should be copied to the synchronous version.
192261pub struct BumpTransactionEventHandlerSync < B : Deref , C : Deref , SP : Deref , L : Deref >
193262where
194263 B :: Target : BroadcasterInterface ,
0 commit comments