From 84a08dbf8ab03875c8afd0e6643f82c8cbb30198 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 9 Mar 2022 18:15:30 +0000 Subject: [PATCH] Make lightning-block-sync's init module slightly more generic Users who want to use lightning-block-sync's init module would be reasonable in wanting to use it in a multithreaded environment, however because it takes a list of listeners as dyn chain::Listen without any Send or Sync bound they fail in doing so. Here we make the type bounds on `chain::Listen` generic across `chain::Listen + ?Sized`, which the existing bound of `&dyn chain::Listen` satisfies. Thus, this is strictly less restrictive and allows for the use of `&dyn chain::Listen + Send + Sync`. --- lightning-block-sync/src/init.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lightning-block-sync/src/init.rs b/lightning-block-sync/src/init.rs index c0e37ac0b..d971cadcf 100644 --- a/lightning-block-sync/src/init.rs +++ b/lightning-block-sync/src/init.rs @@ -121,11 +121,11 @@ BlockSourceResult { /// [`SpvClient`]: crate::SpvClient /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`ChannelMonitor`]: lightning::chain::channelmonitor::ChannelMonitor -pub async fn synchronize_listeners( +pub async fn synchronize_listeners<'a, B: BlockSource, C: Cache, L: chain::Listen + ?Sized>( block_source: &mut B, network: Network, header_cache: &mut C, - mut chain_listeners: Vec<(BlockHash, &dyn chain::Listen)>, + mut chain_listeners: Vec<(BlockHash, &'a L)>, ) -> BlockSourceResult { let best_header = validate_best_block_header(block_source).await?; @@ -198,9 +198,9 @@ impl<'a, C: Cache> Cache for ReadOnlyCache<'a, C> { } /// Wrapper for supporting dynamically sized chain listeners. -struct DynamicChainListener<'a>(&'a dyn chain::Listen); +struct DynamicChainListener<'a, L: chain::Listen + ?Sized>(&'a L); -impl<'a> chain::Listen for DynamicChainListener<'a> { +impl<'a, L: chain::Listen + ?Sized> chain::Listen for DynamicChainListener<'a, L> { fn block_connected(&self, _block: &Block, _height: u32) { unreachable!() } @@ -211,9 +211,9 @@ impl<'a> chain::Listen for DynamicChainListener<'a> { } /// A set of dynamically sized chain listeners, each paired with a starting block height. -struct ChainListenerSet<'a>(Vec<(u32, &'a dyn chain::Listen)>); +struct ChainListenerSet<'a, L: chain::Listen + ?Sized>(Vec<(u32, &'a L)>); -impl<'a> chain::Listen for ChainListenerSet<'a> { +impl<'a, L: chain::Listen + ?Sized> chain::Listen for ChainListenerSet<'a, L> { fn block_connected(&self, block: &Block, height: u32) { for (starting_height, chain_listener) in self.0.iter() { if height > *starting_height { -- 2.39.5