Skip to content

Commit 02ecfe1

Browse files
committed
Introduce marshal ancestry stream alias
1 parent c06078b commit 02ecfe1

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

consensus/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ stability_scope!(ALPHA {
237237
});
238238
stability_scope!(ALPHA, cfg(not(target_arch = "wasm32")) {
239239
use commonware_cryptography::certificate::Scheme;
240-
use futures::Stream;
240+
use crate::marshal::ancestry::Ancestry;
241241
use commonware_runtime::{Clock, Metrics, Spawner};
242242
use rand::Rng;
243243

@@ -272,7 +272,7 @@ stability_scope!(ALPHA, cfg(not(target_arch = "wasm32")) {
272272
fn propose(
273273
&mut self,
274274
context: (E, Self::Context),
275-
ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
275+
ancestry: impl Ancestry<Self::Block>,
276276
) -> impl Future<Output = Option<Self::Block>> + Send;
277277

278278
/// Verify a block produced by the application's proposer, relative to its ancestry.
@@ -287,7 +287,7 @@ stability_scope!(ALPHA, cfg(not(target_arch = "wasm32")) {
287287
fn verify(
288288
&mut self,
289289
context: (E, Self::Context),
290-
ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
290+
ancestry: impl Ancestry<Self::Block>,
291291
) -> impl Future<Output = bool> + Send;
292292
}
293293
});

consensus/src/marshal/ancestry.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ use std::{
1313
task::{Context, Poll},
1414
};
1515

16+
/// A stream of blocks used by application propose and verify calls.
17+
pub trait Ancestry<B: Block>: Stream<Item = B> + Send + Unpin + 'static {}
18+
19+
impl<T, B> Ancestry<B> for T
20+
where
21+
T: Stream<Item = B> + Send + Unpin + 'static,
22+
B: Block,
23+
{
24+
}
25+
1626
/// An interface for providing blocks.
1727
pub trait BlockProvider: Clone + Send + 'static {
1828
/// The block type the provider walks.

consensus/src/marshal/mocks/verifying.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
//! `Application` trait, suitable for testing the `Marshaled` wrapper in
55
//! both standard and coding variants.
66
7-
use crate::{CertifiableBlock, Epochable};
7+
use crate::{marshal::ancestry::Ancestry, CertifiableBlock, Epochable};
88
use commonware_runtime::deterministic;
99
use commonware_utils::{
1010
channel::{fallible::OneshotExt, oneshot},
1111
sync::Mutex,
1212
};
13-
use futures::Stream;
1413
use std::{marker::PhantomData, sync::Arc};
1514

1615
/// A mock application that implements `Application` for testing.
@@ -75,15 +74,15 @@ where
7574
async fn propose(
7675
&mut self,
7776
_context: (deterministic::Context, Self::Context),
78-
_ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
77+
_ancestry: impl Ancestry<Self::Block>,
7978
) -> Option<Self::Block> {
8079
self.propose_result.clone()
8180
}
8281

8382
async fn verify(
8483
&mut self,
8584
_context: (deterministic::Context, Self::Context),
86-
_ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
85+
_ancestry: impl Ancestry<Self::Block>,
8786
) -> bool {
8887
self.verify_result
8988
}
@@ -136,15 +135,15 @@ where
136135
async fn propose(
137136
&mut self,
138137
_context: (deterministic::Context, Self::Context),
139-
_ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
138+
_ancestry: impl Ancestry<Self::Block>,
140139
) -> Option<Self::Block> {
141140
None
142141
}
143142

144143
async fn verify(
145144
&mut self,
146145
_context: (deterministic::Context, Self::Context),
147-
_ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
146+
_ancestry: impl Ancestry<Self::Block>,
148147
) -> bool {
149148
if let Some(started) = self.started.lock().take() {
150149
started.send_lossy(());

examples/reshare/src/application/core.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
dkg,
66
};
77
use commonware_consensus::{
8+
marshal::ancestry::Ancestry,
89
simplex::types::Context,
910
types::{Epoch, Round, View},
1011
Heightable,
@@ -14,7 +15,7 @@ use commonware_cryptography::{
1415
Signer,
1516
};
1617
use commonware_runtime::{Clock, Metrics, Spawner};
17-
use futures::{Stream, StreamExt};
18+
use futures::StreamExt;
1819
use rand::Rng;
1920
use std::marker::PhantomData;
2021

@@ -88,7 +89,7 @@ where
8889
async fn propose(
8990
&mut self,
9091
(_, context): (E, Self::Context),
91-
mut ancestry: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
92+
mut ancestry: impl Ancestry<Self::Block>,
9293
) -> Option<Self::Block> {
9394
// Fetch the parent block from the ancestry stream.
9495
let parent_block = ancestry.next().await?;
@@ -110,11 +111,7 @@ where
110111
))
111112
}
112113

113-
async fn verify(
114-
&mut self,
115-
_: (E, Self::Context),
116-
_: impl Stream<Item = Self::Block> + Send + Unpin + 'static,
117-
) -> bool {
114+
async fn verify(&mut self, _: (E, Self::Context), _: impl Ancestry<Self::Block>) -> bool {
118115
// We wrap this application with `Marshaled`, which handles ancestry
119116
// verification (parent commitment and height contiguity).
120117
//

0 commit comments

Comments
 (0)