Skip to content

Commit aba1981

Browse files
committed
Use pin_project
1 parent 4514a45 commit aba1981

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/store/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ hex = { version = "0.4" }
2626
indexmap = { workspace = true }
2727
libsqlite3-sys = { workspace = true }
2828
miden-block-prover = { workspace = true }
29+
pin-project = "1"
2930
miden-crypto = { features = ["concurrent"], workspace = true }
3031
miden-large-smt-backend-rocksdb = { optional = true, workspace = true }
3132
miden-node-db = { workspace = true }

‎crates/store/src/server/replica.rs‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use miden_node_proto::generated::store::{
1010
store_replica_server,
1111
};
1212
use miden_protocol::block::BlockNumber;
13+
use pin_project::pin_project;
1314
use tokio::sync::OwnedSemaphorePermit;
1415
use tokio_stream::wrappers::BroadcastStream;
1516
use 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

Comments
 (0)