Skip to content

Commit 2d6e017

Browse files
authored
Merge pull request #4203 from TheBlueMatt/2025-11-0.2-doc-tweaks
Bindings doc updates for 0.2
2 parents 3f96d12 + 4bc993c commit 2d6e017

File tree

15 files changed

+276
-29
lines changed

15 files changed

+276
-29
lines changed

lightning-invoice/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ use crate::ser::Base32Iterable;
9191
#[allow(missing_docs)]
9292
#[derive(PartialEq, Eq, Debug, Clone)]
9393
pub enum Bolt11ParseError {
94-
Bech32Error(CheckedHrpstringError),
94+
Bech32Error(
95+
/// This is not exported to bindings users as the details don't matter much
96+
CheckedHrpstringError,
97+
),
9598
ParseAmountError(ParseIntError),
9699
MalformedSignature(bitcoin::secp256k1::Error),
97100
BadPrefix,

lightning/src/chain/chainmonitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ impl<ChannelSigner: EcdsaChannelSigner> Deref for LockedChannelMonitor<'_, Chann
253253

254254
/// An unconstructable [`Persist`]er which is used under the hood when you call
255255
/// [`ChainMonitor::new_async_beta`].
256+
///
257+
/// This is not exported to bindings users as async is not supported outside of Rust.
256258
pub struct AsyncPersister<
257259
K: Deref + MaybeSend + MaybeSync + 'static,
258260
S: FutureSpawner,
@@ -431,6 +433,8 @@ impl<
431433
/// [`MonitorUpdatingPersisterAsync`] and thus allows persistence to be completed async.
432434
///
433435
/// Note that async monitor updating is considered beta, and bugs may be triggered by its use.
436+
///
437+
/// This is not exported to bindings users as async is not supported outside of Rust.
434438
pub fn new_async_beta(
435439
chain_source: Option<C>, broadcaster: T, logger: L, feeest: F,
436440
persister: MonitorUpdatingPersisterAsync<K, S, L, ES, SP, T, F>, _entropy_source: ES,

lightning/src/events/bump_transaction/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ pub struct CoinSelection {
353353
/// which can provide a default implementation of this trait when used with [`Wallet`].
354354
///
355355
/// For a synchronous version of this trait, see [`sync::CoinSelectionSourceSync`].
356+
///
357+
/// 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.
356359
pub trait CoinSelectionSource {
357360
/// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
358361
/// available to spend. Implementations are free to pick their coin selection algorithm of
@@ -404,6 +407,9 @@ pub trait CoinSelectionSource {
404407
/// provide a default implementation to [`CoinSelectionSource`].
405408
///
406409
/// For a synchronous version of this trait, see [`sync::WalletSourceSync`].
410+
///
411+
/// 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.
407413
pub trait WalletSource {
408414
/// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
409415
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>, ()>;
@@ -419,11 +425,14 @@ pub trait WalletSource {
419425
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()>;
420426
}
421427

422-
/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
423-
/// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
424-
/// 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.
425431
///
426432
/// For a synchronous version of this wrapper, see [`sync::WalletSync`].
433+
///
434+
/// 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.
427436
pub struct Wallet<W: Deref + MaybeSync + MaybeSend, L: Deref + MaybeSync + MaybeSend>
428437
where
429438
W::Target: WalletSource + MaybeSend,
@@ -670,7 +679,10 @@ where
670679
///
671680
/// For a synchronous version of this handler, see [`sync::BumpTransactionEventHandlerSync`].
672681
///
682+
/// This is not exported to bindings users as async is only supported in Rust.
683+
///
673684
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
685+
// Note that updates to documentation on this struct should be copied to the synchronous version.
674686
pub struct BumpTransactionEventHandler<B: Deref, C: Deref, SP: Deref, L: Deref>
675687
where
676688
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,

lightning/src/ln/funding.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
//! Types pertaining to funding channels.
1111
12+
use alloc::vec::Vec;
13+
1214
use bitcoin::{Amount, ScriptBuf, SignedAmount, TxOut};
1315
use bitcoin::{Script, Sequence, Transaction, Weight};
1416

1517
use crate::events::bump_transaction::Utxo;
1618
use crate::ln::chan_utils::EMPTY_SCRIPT_SIG_WEIGHT;
17-
use crate::prelude::Vec;
1819
use crate::sign::{P2TR_KEY_PATH_WITNESS_WEIGHT, P2WPKH_WITNESS_WEIGHT};
1920

2021
/// The components of a splice's funding transaction that are contributed by one party.

lightning/src/offers/flow.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ where
597597
///
598598
/// Returns an error if the parameterized [`Router`] is unable to create a blinded path for the offer.
599599
///
600+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
601+
///
600602
/// [`DefaultMessageRouter`]: crate::onion_message::messenger::DefaultMessageRouter
601603
pub fn create_offer_builder<ES: Deref>(
602604
&self, entropy_source: ES, peers: Vec<MessageForwardNode>,
@@ -618,6 +620,8 @@ where
618620
/// This gives users full control over how the [`BlindedMessagePath`] is constructed,
619621
/// including the option to omit it entirely.
620622
///
623+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
624+
///
621625
/// See [`Self::create_offer_builder`] for more details on usage.
622626
pub fn create_offer_builder_using_router<ME: Deref, ES: Deref>(
623627
&self, router: ME, entropy_source: ES, peers: Vec<MessageForwardNode>,
@@ -644,6 +648,8 @@ where
644648
/// 2. Use [`Self::create_static_invoice_builder`] to create a [`StaticInvoice`] from this
645649
/// [`Offer`] plus the returned [`Nonce`], and provide the static invoice to the
646650
/// aforementioned always-online node.
651+
///
652+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
647653
pub fn create_async_receive_offer_builder<ES: Deref>(
648654
&self, entropy_source: ES, message_paths_to_always_online_node: Vec<BlindedMessagePath>,
649655
) -> Result<(OfferBuilder<'_, DerivedMetadata, secp256k1::All>, Nonce), Bolt12SemanticError>
@@ -726,6 +732,8 @@ where
726732
/// - `amount_msats` is invalid, or
727733
/// - The parameterized [`Router`] is unable to create a blinded path for the refund.
728734
///
735+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
736+
///
729737
/// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
730738
/// [`RouteParameters::from_payment_params_and_value`]: crate::routing::router::RouteParameters::from_payment_params_and_value
731739
pub fn create_refund_builder<ES: Deref>(
@@ -762,6 +770,8 @@ where
762770
/// return an error if the provided [`MessageRouter`] fails to construct a valid
763771
/// [`BlindedMessagePath`] for the refund.
764772
///
773+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
774+
///
765775
/// [`Refund`]: crate::offers::refund::Refund
766776
/// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath
767777
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
@@ -797,6 +807,8 @@ where
797807
/// # Nonce
798808
/// The nonce is used to create a unique [`InvoiceRequest::payer_metadata`] for the invoice request.
799809
/// These will be used to verify the corresponding [`Bolt12Invoice`] when it is received.
810+
///
811+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
800812
pub fn create_invoice_request_builder<'a>(
801813
&'a self, offer: &'a Offer, nonce: Nonce, payment_id: PaymentId,
802814
) -> Result<InvoiceRequestBuilder<'a, 'a, secp256k1::All>, Bolt12SemanticError> {
@@ -812,6 +824,8 @@ where
812824

813825
/// Creates a [`StaticInvoiceBuilder`] from the corresponding [`Offer`] and [`Nonce`] that were
814826
/// created via [`Self::create_async_receive_offer_builder`].
827+
///
828+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
815829
pub fn create_static_invoice_builder<'a, ES: Deref, R: Deref>(
816830
&self, router: &R, entropy_source: ES, offer: &'a Offer, offer_nonce: Nonce,
817831
payment_secret: PaymentSecret, relative_expiry_secs: u32,
@@ -884,6 +898,8 @@ where
884898
///
885899
/// Returns an error if the refund targets a different chain or if no valid
886900
/// blinded path can be constructed.
901+
///
902+
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
887903
pub fn create_invoice_builder_from_refund<'a, ES: Deref, R: Deref, F>(
888904
&'a self, router: &R, entropy_source: ES, refund: &'a Refund,
889905
usable_channels: Vec<ChannelDetails>, get_payment_info: F,

lightning/src/offers/merkle.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub enum SignError {
9494
}
9595

9696
/// A function for signing a [`TaggedHash`].
97+
///
98+
/// This is not exported to bindings users as signing functions should just be used per-signed-type
99+
/// instead.
97100
pub trait SignFn<T: AsRef<TaggedHash>> {
98101
/// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
99102
fn sign(&self, message: &T) -> Result<Signature, ()>;

lightning/src/offers/parse.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ pub enum Bolt12ParseError {
142142
/// being parsed.
143143
InvalidBech32Hrp,
144144
/// The string could not be bech32 decoded.
145-
Bech32(CheckedHrpstringError),
145+
Bech32(
146+
/// This is not exported to bindings users as the details don't matter much
147+
CheckedHrpstringError,
148+
),
146149
/// The bech32 decoded string could not be decoded as the expected message type.
147150
Decode(DecodeError),
148151
/// The parsed message has invalid semantics.

lightning/src/sign/ecdsa.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ use bitcoin::secp256k1::ecdsa::Signature;
77
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
88

99
use crate::ln::chan_utils::{
10-
ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction,
10+
ChannelTransactionParameters, ClosingTransaction, CommitmentTransaction,
11+
HTLCOutputInCommitment, HolderCommitmentTransaction,
1112
};
1213
use crate::ln::msgs::UnsignedChannelAnnouncement;
1314
use crate::types::payment::PaymentPreimage;
1415

1516
#[allow(unused_imports)]
1617
use crate::prelude::*;
1718

18-
use crate::sign::{ChannelSigner, ChannelTransactionParameters, HTLCDescriptor};
19+
use crate::sign::{ChannelSigner, HTLCDescriptor};
1920

2021
/// A trait to sign Lightning channel transactions as described in
2122
/// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).

lightning/src/sign/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,8 @@ pub trait SignerProvider {
10581058

10591059
/// A helper trait that describes an on-chain wallet capable of returning a (change) destination
10601060
/// script.
1061+
///
1062+
/// This is not exported to bindings users as async is only supported in Rust.
10611063
pub trait ChangeDestinationSource {
10621064
/// Returns a script pubkey which can be used as a change destination for
10631065
/// [`OutputSpender::spend_spendable_outputs`].
@@ -1069,6 +1071,9 @@ pub trait ChangeDestinationSource {
10691071

10701072
/// A synchronous helper trait that describes an on-chain wallet capable of returning a (change) destination script.
10711073
pub trait ChangeDestinationSourceSync {
1074+
/// Returns a script pubkey which can be used as a change destination for
1075+
/// [`OutputSpender::spend_spendable_outputs`].
1076+
///
10721077
/// This method should return a different value each time it is called, to avoid linking
10731078
/// on-chain funds controlled to the same user.
10741079
fn get_change_destination_script(&self) -> Result<ScriptBuf, ()>;

0 commit comments

Comments
 (0)