Skip to content

Commit 4bc993c

Browse files
committed
Copy docs from OutputSweeper to OutputSweeperSync
When we added the async wrapper for `OutputSweeper`, 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 9516400 commit 4bc993c

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

lightning/src/util/sweep.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ impl_writeable_tlv_based_enum!(OutputSpendStatus,
317317
);
318318

319319
/// A utility that keeps track of [`SpendableOutputDescriptor`]s, persists them in a given
320-
/// [`KVStoreSync`] and regularly retries sweeping them based on a callback given to the constructor
320+
/// [`KVStore`] and regularly retries sweeping them based on a callback given to the constructor
321321
/// methods.
322322
///
323-
/// Users should call [`Self::track_spendable_outputs`] for any [`SpendableOutputDescriptor`]s received via [`Event::SpendableOutputs`].
323+
/// Users should call [`Self::track_spendable_outputs`] for any [`SpendableOutputDescriptor`]s
324+
/// received via [`Event::SpendableOutputs`].
324325
///
325326
/// This needs to be notified of chain state changes either via its [`Listen`] or [`Confirm`]
326327
/// implementation and hence has to be connected with the utilized chain data sources.
@@ -329,9 +330,12 @@ impl_writeable_tlv_based_enum!(OutputSpendStatus,
329330
/// required to give their chain data sources (i.e., [`Filter`] implementation) to the respective
330331
/// constructor.
331332
///
333+
/// For a synchronous version of this struct, see [`OutputSweeperSync`].
334+
///
332335
/// This is not exported to bindings users as async is not supported outside of Rust.
333336
///
334337
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
338+
// Note that updates to documentation on this struct should be copied to the synchronous version.
335339
pub struct OutputSweeper<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref>
336340
where
337341
B::Target: BroadcasterInterface,
@@ -878,7 +882,24 @@ where
878882
}
879883
}
880884

881-
/// A synchronous wrapper around [`OutputSweeper`] to be used in contexts where async is not available.
885+
/// A utility that keeps track of [`SpendableOutputDescriptor`]s, persists them in a given
886+
/// [`KVStoreSync`] and regularly retries sweeping them based on a callback given to the constructor
887+
/// methods.
888+
///
889+
/// Users should call [`Self::track_spendable_outputs`] for any [`SpendableOutputDescriptor`]s
890+
/// received via [`Event::SpendableOutputs`].
891+
///
892+
/// This needs to be notified of chain state changes either via its [`Listen`] or [`Confirm`]
893+
/// implementation and hence has to be connected with the utilized chain data sources.
894+
///
895+
/// If chain data is provided via the [`Confirm`] interface or via filtered blocks, users are
896+
/// required to give their chain data sources (i.e., [`Filter`] implementation) to the respective
897+
/// constructor.
898+
///
899+
/// For an asynchronous version of this struct, see [`OutputSweeper`].
900+
///
901+
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
902+
// Note that updates to documentation on this struct should be copied to the asynchronous version.
882903
pub struct OutputSweeperSync<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref>
883904
where
884905
B::Target: BroadcasterInterface,
@@ -905,6 +926,9 @@ where
905926
O::Target: OutputSpender,
906927
{
907928
/// Constructs a new [`OutputSweeperSync`] instance.
929+
///
930+
/// If chain data is provided via the [`Confirm`] interface or via filtered blocks, users also
931+
/// need to register their [`Filter`] implementation via the given `chain_data_source`.
908932
pub fn new(
909933
best_block: BestBlock, broadcaster: B, fee_estimator: E, chain_data_source: Option<F>,
910934
output_spender: O, change_destination_source: D, kv_store: K, logger: L,
@@ -927,7 +951,21 @@ where
927951
Self { sweeper }
928952
}
929953

930-
/// Wrapper around [`OutputSweeper::track_spendable_outputs`].
954+
/// Tells the sweeper to track the given outputs descriptors.
955+
///
956+
/// Usually, this should be called based on the values emitted by the
957+
/// [`Event::SpendableOutputs`].
958+
///
959+
/// The given `exclude_static_outputs` flag controls whether the sweeper will filter out
960+
/// [`SpendableOutputDescriptor::StaticOutput`]s, which may be handled directly by the on-chain
961+
/// wallet implementation.
962+
///
963+
/// If `delay_until_height` is set, we will delay the spending until the respective block
964+
/// height is reached. This can be used to batch spends, e.g., to reduce on-chain fees.
965+
///
966+
/// Returns `Err` on persistence failure, in which case the call may be safely retried.
967+
///
968+
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
931969
pub fn track_spendable_outputs(
932970
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
933971
exclude_static_outputs: bool, delay_until_height: Option<u32>,
@@ -949,7 +987,9 @@ where
949987
}
950988
}
951989

952-
/// Returns a list of the currently tracked spendable outputs. Wraps [`OutputSweeper::tracked_spendable_outputs`].
990+
/// Returns a list of the currently tracked spendable outputs.
991+
///
992+
/// Wraps [`OutputSweeper::tracked_spendable_outputs`].
953993
pub fn tracked_spendable_outputs(&self) -> Vec<TrackedSpendableOutput> {
954994
self.sweeper.tracked_spendable_outputs()
955995
}
@@ -960,8 +1000,10 @@ where
9601000
self.sweeper.current_best_block()
9611001
}
9621002

963-
/// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
964-
/// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
1003+
/// Regenerates and broadcasts the spending transaction for any outputs that are pending. This method will be a
1004+
/// no-op if a sweep is already pending.
1005+
///
1006+
/// Wraps [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
9651007
pub fn regenerate_and_broadcast_spend_if_necessary(&self) -> Result<(), ()> {
9661008
let mut fut = Box::pin(self.sweeper.regenerate_and_broadcast_spend_if_necessary());
9671009
let mut waker = dummy_waker();

0 commit comments

Comments
 (0)