11use super :: Variant ;
22use crate :: {
33 marshal:: {
4- ancestry:: { AncestorStream , BlockProvider } ,
4+ ancestry:: { AncestorStream , Ancestry , BlockProvider } ,
55 Identifier ,
66 } ,
77 simplex:: types:: { Activity , Finalization , Notarization } ,
@@ -15,7 +15,6 @@ use commonware_actor::{
1515use commonware_cryptography:: { certificate:: Scheme , Digestible } ;
1616use commonware_p2p:: Recipients ;
1717use commonware_utils:: { channel:: oneshot, vec:: NonEmptyVec } ;
18- use futures:: Stream ;
1918use std:: collections:: { btree_map:: Entry , BTreeMap , VecDeque } ;
2019
2120/// Messages sent to the marshal [Actor](super::Actor).
@@ -49,6 +48,11 @@ pub(crate) enum Message<S: Scheme, V: Variant> {
4948 /// A channel to send the retrieved finalization.
5049 response : oneshot:: Sender < Option < Finalization < S , V :: Commitment > > > ,
5150 } ,
51+ /// A request to retrieve the latest processed height.
52+ GetProcessedHeight {
53+ /// A channel to send the latest processed height.
54+ response : oneshot:: Sender < Height > ,
55+ } ,
5256 /// A hint that a finalized block may be available at a given height.
5357 ///
5458 /// This triggers a network fetch if the finalization is not available locally.
@@ -253,7 +257,8 @@ impl<S: Scheme, V: Variant> Message<S, V> {
253257 | Self :: GetInfo {
254258 identifier : Identifier :: Digest ( _) | Identifier :: Latest ,
255259 ..
256- } => false ,
260+ }
261+ | Self :: GetProcessedHeight { .. } => false ,
257262 Self :: HintNotarized { .. } => false ,
258263 Self :: SubscribeByDigest { .. }
259264 | Self :: SubscribeByCommitment { .. }
@@ -273,6 +278,7 @@ impl<S: Scheme, V: Variant> Message<S, V> {
273278 response. is_closed ( )
274279 }
275280 Self :: GetFinalization { response, .. } => response. is_closed ( ) ,
281+ Self :: GetProcessedHeight { response } => response. is_closed ( ) ,
276282 Self :: SubscribeByDigest { response, .. }
277283 | Self :: SubscribeByCommitment { response, .. } => response. is_closed ( ) ,
278284 Self :: HintNotarized { .. } => false ,
@@ -532,7 +538,7 @@ impl<S: Scheme, V: Variant> Mailbox<S, V> {
532538 pub ( crate ) fn ancestor_stream < I > (
533539 & self ,
534540 initial : I ,
535- ) -> impl Stream < Item = V :: ApplicationBlock > + Send + use < S , V , I >
541+ ) -> impl Ancestry < V :: ApplicationBlock > + use < S , V , I >
536542 where
537543 Self : BlockProvider < Block = V :: ApplicationBlock > ,
538544 I : IntoIterator < Item = V :: Block > ,
@@ -579,6 +585,15 @@ impl<S: Scheme, V: Variant> Mailbox<S, V> {
579585 receiver. await . ok ( ) . flatten ( )
580586 }
581587
588+ /// Retrieve the latest processed height.
589+ pub async fn get_processed_height ( & self ) -> Option < Height > {
590+ let ( response, receiver) = oneshot:: channel ( ) ;
591+ let _ = self
592+ . sender
593+ . enqueue ( Message :: GetProcessedHeight { response } ) ;
594+ receiver. await . ok ( )
595+ }
596+
582597 /// Hints that a finalized block may be available at the given height.
583598 ///
584599 /// This method will request the finalization from the network via the resolver
@@ -679,7 +694,7 @@ impl<S: Scheme, V: Variant> Mailbox<S, V> {
679694 pub async fn ancestry (
680695 & self ,
681696 ( fallback, start_digest) : ( DigestFallback , <V :: Block as Digestible >:: Digest ) ,
682- ) -> Option < impl Stream < Item = V :: ApplicationBlock > + Send + use < S , V > >
697+ ) -> Option < impl Ancestry < V :: ApplicationBlock > + use < S , V > >
683698 where
684699 Self : BlockProvider < Block = V :: ApplicationBlock > ,
685700 {
0 commit comments