@@ -10,6 +10,7 @@ use miden_node_proto::generated::store::{
1010 store_replica_server,
1111} ;
1212use miden_protocol:: block:: BlockNumber ;
13+ use pin_project:: pin_project;
1314use tokio:: sync:: OwnedSemaphorePermit ;
1415use tokio_stream:: wrappers:: BroadcastStream ;
1516use tokio_stream:: wrappers:: errors:: BroadcastStreamRecvError ;
@@ -23,16 +24,18 @@ use crate::state::{BlockNotification, Finality, ProofNotification, State};
2324// ================================================================================================
2425
2526/// Wraps a stream and holds a semaphore permit for its lifetime, releasing it on drop.
26- struct GuardedStream < S : Stream + Unpin > {
27+ #[ pin_project]
28+ struct GuardedStream < S : Stream > {
29+ #[ pin]
2730 inner : S ,
2831 _permit : OwnedSemaphorePermit ,
2932}
3033
31- impl < S : Stream + Unpin > Stream for GuardedStream < S > {
34+ impl < S : Stream > Stream for GuardedStream < S > {
3235 type Item = S :: Item ;
3336
34- fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
35- Pin :: new ( & mut self . inner ) . poll_next ( cx)
37+ fn poll_next ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
38+ self . project ( ) . inner . poll_next ( cx)
3639 }
3740}
3841
@@ -85,8 +88,7 @@ impl store_replica_server::StoreReplica for StoreApi {
8588 // Subscribe to the live broadcast BEFORE replay to eliminate the gap race.
8689 let live_rx = self . block_sender . subscribe ( ) ;
8790
88- let stream =
89- Box :: pin ( build_block_stream ( from, chain_tip, Arc :: clone ( & self . state ) , live_rx) ) ;
91+ let stream = build_block_stream ( from, chain_tip, Arc :: clone ( & self . state ) , live_rx) ;
9092 Ok ( Response :: new ( Box :: pin ( GuardedStream { inner : stream, _permit : permit } ) ) )
9193 }
9294
@@ -111,8 +113,7 @@ impl store_replica_server::StoreReplica for StoreApi {
111113 // Subscribe to the live broadcast BEFORE replay.
112114 let live_rx = self . proof_sender . subscribe ( ) ;
113115
114- let stream =
115- Box :: pin ( build_proof_stream ( from, proven_tip, Arc :: clone ( & self . state ) , live_rx) ) ;
116+ let stream = build_proof_stream ( from, proven_tip, Arc :: clone ( & self . state ) , live_rx) ;
116117 Ok ( Response :: new ( Box :: pin ( GuardedStream { inner : stream, _permit : permit } ) ) )
117118 }
118119}
0 commit comments