|
2 | 2 |
|
3 | 3 | use crate::{types::Height, Block, Heightable}; |
4 | 4 | use commonware_cryptography::Digestible; |
5 | | -use commonware_utils::sync::Mutex; |
6 | 5 | use futures::{ |
7 | 6 | future::{BoxFuture, OptionFuture}, |
8 | 7 | FutureExt, Stream, |
@@ -49,16 +48,12 @@ pub struct ErasedBlockProvider<B: Block> { |
49 | 48 |
|
50 | 49 | impl<B: Block> ErasedBlockProvider<B> { |
51 | 50 | /// Erase a concrete [`BlockProvider`] into a type-erased provider. |
52 | | - /// |
53 | | - /// The provider is wrapped in a `Mutex` so that the resulting closure |
54 | | - /// is `Sync` (required by `Arc<dyn Fn + Send + Sync>`). The lock is |
55 | | - /// held only for the duration of `clone()`, never across an await. |
56 | | - pub fn new<M: BlockProvider<Block = B>>(provider: M) -> Self { |
57 | | - let provider = Arc::new(Mutex::new(provider)); |
| 51 | + pub fn new<M: BlockProvider<Block = B> + Sync>(provider: M) -> Self { |
| 52 | + let provider = Arc::new(provider); |
58 | 53 | Self { |
59 | 54 | fetch: Arc::new(move |digest| { |
60 | | - let p = provider.lock().clone(); |
61 | | - Box::pin(async move { p.fetch_block(digest).await }) |
| 55 | + let p = provider.as_ref().clone(); |
| 56 | + Box::pin(p.fetch_block(digest)) |
62 | 57 | }), |
63 | 58 | } |
64 | 59 | } |
@@ -87,7 +82,7 @@ pub struct AncestorStream<M, B: Block> { |
87 | 82 | pending: OptionFuture<BoxFuture<'static, Option<B>>>, |
88 | 83 | } |
89 | 84 |
|
90 | | -impl<M, B: Block> AncestorStream<M, B> { |
| 85 | +impl<M: Send + Sync, B: Block> AncestorStream<M, B> { |
91 | 86 | /// Returns a reference to the next block that will be yielded by the |
92 | 87 | /// stream, without consuming it. |
93 | 88 | /// |
|
0 commit comments