Skip to content

Commit 2917fd2

Browse files
committed
Add missing Listen/Readable/methods for OutputSweeperSync
It appears we just forgot to add these when we added the sync wrapper.
1 parent 19a9dbd commit 2917fd2

File tree

1 file changed

+69
-15
lines changed

1 file changed

+69
-15
lines changed

lightning/src/util/sweep.rs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -977,21 +977,6 @@ where
977977
Self { sweeper }
978978
}
979979

980-
/// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
981-
/// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
982-
pub fn regenerate_and_broadcast_spend_if_necessary(&self) -> Result<(), ()> {
983-
let mut fut = Box::pin(self.sweeper.regenerate_and_broadcast_spend_if_necessary());
984-
let mut waker = dummy_waker();
985-
let mut ctx = task::Context::from_waker(&mut waker);
986-
match fut.as_mut().poll(&mut ctx) {
987-
task::Poll::Ready(result) => result,
988-
task::Poll::Pending => {
989-
// In a sync context, we can't wait for the future to complete.
990-
unreachable!("OutputSweeper::regenerate_and_broadcast_spend_if_necessary should not be pending in a sync context");
991-
},
992-
}
993-
}
994-
995980
/// Wrapper around [`OutputSweeper::track_spendable_outputs`].
996981
pub fn track_spendable_outputs(
997982
&self, output_descriptors: Vec<SpendableOutputDescriptor>, channel_id: Option<ChannelId>,
@@ -1019,6 +1004,27 @@ where
10191004
self.sweeper.tracked_spendable_outputs()
10201005
}
10211006

1007+
/// Gets the latest best block which was connected either via [`Listen`] or [`Confirm`]
1008+
/// interfaces.
1009+
pub fn current_best_block(&self) -> BestBlock {
1010+
self.sweeper.current_best_block()
1011+
}
1012+
1013+
/// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
1014+
/// [`OutputSweeper::regenerate_and_broadcast_spend_if_necessary`].
1015+
pub fn regenerate_and_broadcast_spend_if_necessary(&self) -> Result<(), ()> {
1016+
let mut fut = Box::pin(self.sweeper.regenerate_and_broadcast_spend_if_necessary());
1017+
let mut waker = dummy_waker();
1018+
let mut ctx = task::Context::from_waker(&mut waker);
1019+
match fut.as_mut().poll(&mut ctx) {
1020+
task::Poll::Ready(result) => result,
1021+
task::Poll::Pending => {
1022+
// In a sync context, we can't wait for the future to complete.
1023+
unreachable!("OutputSweeper::regenerate_and_broadcast_spend_if_necessary should not be pending in a sync context");
1024+
},
1025+
}
1026+
}
1027+
10221028
/// Fetch the inner async sweeper.
10231029
///
10241030
/// In general you shouldn't have much reason to use this - you have a sync [`KVStore`] backing
@@ -1034,6 +1040,28 @@ where
10341040
}
10351041
}
10361042

1043+
impl<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref> Listen
1044+
for OutputSweeperSync<B, D, E, F, K, L, O>
1045+
where
1046+
B::Target: BroadcasterInterface,
1047+
D::Target: ChangeDestinationSourceSync,
1048+
E::Target: FeeEstimator,
1049+
F::Target: Filter + Sync + Send,
1050+
K::Target: KVStoreSync,
1051+
L::Target: Logger,
1052+
O::Target: OutputSpender,
1053+
{
1054+
fn filtered_block_connected(
1055+
&self, header: &Header, txdata: &chain::transaction::TransactionData, height: u32,
1056+
) {
1057+
self.sweeper.filtered_block_connected(header, txdata, height);
1058+
}
1059+
1060+
fn blocks_disconnected(&self, fork_point: BestBlock) {
1061+
self.sweeper.blocks_disconnected(fork_point);
1062+
}
1063+
}
1064+
10371065
impl<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref> Confirm
10381066
for OutputSweeperSync<B, D, E, F, K, L, O>
10391067
where
@@ -1063,3 +1091,29 @@ where
10631091
self.sweeper.get_relevant_txids()
10641092
}
10651093
}
1094+
1095+
impl<B: Deref, D: Deref, E: Deref, F: Deref, K: Deref, L: Deref, O: Deref>
1096+
ReadableArgs<(B, E, Option<F>, O, D, K, L)> for (BestBlock, OutputSweeperSync<B, D, E, F, K, L, O>)
1097+
where
1098+
B::Target: BroadcasterInterface,
1099+
D::Target: ChangeDestinationSourceSync,
1100+
E::Target: FeeEstimator,
1101+
F::Target: Filter + Sync + Send,
1102+
K::Target: KVStoreSync,
1103+
L::Target: Logger,
1104+
O::Target: OutputSpender,
1105+
{
1106+
#[inline]
1107+
fn read<R: io::Read>(
1108+
reader: &mut R, args: (B, E, Option<F>, O, D, K, L),
1109+
) -> Result<Self, DecodeError> {
1110+
let (a, b, c, d, change_destination_source, kv_store, e) = args;
1111+
let change_destination_source =
1112+
ChangeDestinationSourceSyncWrapper::new(change_destination_source);
1113+
let kv_store = KVStoreSyncWrapper(kv_store);
1114+
let args = (a, b, c, d, change_destination_source, kv_store, e);
1115+
let (best_block, sweeper) =
1116+
<(BestBlock, OutputSweeper<_, _, _, _, _, _, _>)>::read(reader, args)?;
1117+
Ok((best_block, OutputSweeperSync { sweeper }))
1118+
}
1119+
}

0 commit comments

Comments
 (0)