Skip to content

Commit 0b2bc38

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.
1 parent 126ac50 commit 0b2bc38

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 4 additions & 0 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>, ()>;
@@ -430,6 +432,7 @@ pub trait WalletSource {
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: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
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.
3848
fn sign_psbt(&self, psbt: Psbt) -> Result<Transaction, ()>;
3949
}
4050

@@ -74,7 +84,12 @@ where
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.
7893
pub struct WalletSync<W: Deref + MaybeSync + MaybeSend, L: Deref + MaybeSync + MaybeSend>
7994
where
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.
140162
pub 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.
192258
pub struct BumpTransactionEventHandlerSync<B: Deref, C: Deref, SP: Deref, L: Deref>
193259
where
194260
B::Target: BroadcasterInterface,

0 commit comments

Comments
 (0)