Skip to content

Commit c311447

Browse files
committed
Copy async docs from async bump transaction objects to sync ones
When we added the async traits and wrapper structs for the transaction-bumping logic, we didn't bother copying the documentation to the sync wrappers as we figured the links sufficed. Sadly, however, this means that our bindings logic will have no docs but a broken link to an async object that doesn't exist. Instead, here, we copy the docs from the async objects to the sync ones, at least leaving behind a comment noting that both need updating whenever one gets updated. We also fix one bogus link in `Wallet`'s docs.
1 parent 126ac50 commit c311447

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ pub struct CoinSelection {
355355
/// For a synchronous version of this trait, see [`sync::CoinSelectionSourceSync`].
356356
///
357357
/// This is not exported to bindings users as async is only supported in Rust.
358+
// Note that updates to documentation on this trait should be copied to the synchronous version.
358359
pub trait CoinSelectionSource {
359360
/// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
360361
/// available to spend. Implementations are free to pick their coin selection algorithm of
@@ -408,6 +409,7 @@ pub trait CoinSelectionSource {
408409
/// For a synchronous version of this trait, see [`sync::WalletSourceSync`].
409410
///
410411
/// This is not exported to bindings users as async is only supported in Rust.
412+
// Note that updates to documentation on this trait should be copied to the synchronous version.
411413
pub trait WalletSource {
412414
/// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
413415
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>, ()>;
@@ -423,13 +425,14 @@ pub trait WalletSource {
423425
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()>;
424426
}
425427

426-
/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
427-
/// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
428-
/// spends may happen.
428+
/// A wrapper over [`WalletSource`] that implements [`CoinSelectionSource`] by preferring UTXOs
429+
/// that would avoid conflicting double spends. If not enough UTXOs are available to do so,
430+
/// conflicting double spends may happen.
429431
///
430432
/// For a synchronous version of this wrapper, see [`sync::WalletSync`].
431433
///
432434
/// This is not exported to bindings users as async is only supported in Rust.
435+
// Note that updates to documentation on this struct should be copied to the synchronous version.
433436
pub struct Wallet<W: Deref + MaybeSync + MaybeSend, L: Deref + MaybeSync + MaybeSend>
434437
where
435438
W::Target: WalletSource + MaybeSend,
@@ -679,6 +682,7 @@ where
679682
/// This is not exported to bindings users as async is only supported in Rust.
680683
///
681684
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
685+
// Note that updates to documentation on this struct should be copied to the synchronous version.
682686
pub struct BumpTransactionEventHandler<B: Deref, C: Deref, SP: Deref, L: Deref>
683687
where
684688
B::Target: BroadcasterInterface,

lightning/src/events/bump_transaction/sync.rs

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3236
pub 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

@@ -74,7 +87,12 @@ where
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.
7896
pub struct WalletSync<W: Deref + MaybeSync + MaybeSend, L: Deref + MaybeSync + MaybeSend>
7997
where
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.
140165
pub 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.
192261
pub struct BumpTransactionEventHandlerSync<B: Deref, C: Deref, SP: Deref, L: Deref>
193262
where
194263
B::Target: BroadcasterInterface,

0 commit comments

Comments
 (0)