@@ -23,45 +23,24 @@ where
2323{
2424}
2525
26- /// An interface for providing blocks.
26+ /// An interface for providing parent blocks.
2727pub trait BlockProvider : Clone + Send + ' static {
2828 /// The block type the provider walks.
2929 type Block : Block ;
3030
31- /// Subscribe to a block by its digest without requesting it from the network .
31+ /// Subscribe to the parent of a known block .
3232 ///
33- /// If the block is found available locally, the block will be returned immediately.
33+ /// If the parent is found available locally, the parent will be returned immediately.
3434 ///
35- /// If the block is not available locally, the subscription will be registered and the caller
36- /// will be notified when the block is available. If the block is not finalized, it's possible
35+ /// If the parent is not available locally, the subscription will be registered and the caller
36+ /// will be notified when the parent is available. If the parent is not finalized, it's possible
3737 /// that it may never become available.
3838 ///
3939 /// Returns `None` when the subscription is canceled or the provider can no longer deliver
40- /// the block .
40+ /// the parent .
4141 ///
42- /// This is intentionally narrower than [`Self::subscribe_parent`]. A digest is enough to
43- /// identify a block in local storage, but it may not be enough to form the network request
44- /// used by a marshal variant. Variants whose consensus commitment contains extra context
45- /// should keep that logic in [`Self::subscribe_parent`], where the known child block is
46- /// still available.
47- fn subscribe (
48- self ,
49- digest : <Self :: Block as Digestible >:: Digest ,
50- ) -> impl Future < Output = Option < Self :: Block > > + Send ;
51-
52- /// Subscribe to the parent of a known block.
53- ///
54- /// This is a separate hook from [`Self::subscribe`] because the child block can carry
55- /// variant-specific context needed to retrieve its parent. The default implementation
56- /// follows the digest link and waits locally, but providers may override this to derive a
57- /// full parent commitment and issue a fetching subscription.
58- fn subscribe_parent (
59- self ,
60- block : Self :: Block ,
61- ) -> impl Future < Output = Option < Self :: Block > > + Send {
62- let digest = block. parent ( ) ;
63- self . subscribe ( digest)
64- }
42+ /// The child block can carry variant-specific context needed to retrieve its parent.
43+ fn subscribe ( self , block : Self :: Block ) -> impl Future < Output = Option < Self :: Block > > + Send ;
6544}
6645
6746/// Yields the ancestors of a block while prefetching parents, _not_ including the genesis block.
@@ -124,10 +103,10 @@ where
124103 // If a result has been buffered, return it and queue the parent fetch if needed.
125104 if let Some ( block) = this. buffered . pop ( ) {
126105 let height = block. height ( ) ;
127- let should_subscribe_parent = height > END_BOUND ;
106+ let should_walk_parent = height > END_BOUND ;
128107 let end_of_buffered = this. buffered . is_empty ( ) ;
129- if should_subscribe_parent && end_of_buffered {
130- let future = this. marshal . clone ( ) . subscribe_parent ( block. clone ( ) ) . boxed ( ) ;
108+ if should_walk_parent && end_of_buffered {
109+ let future = this. marshal . clone ( ) . subscribe ( block. clone ( ) ) . boxed ( ) ;
131110 * this. pending . as_mut ( ) = Some ( future) . into ( ) ;
132111
133112 // Explicitly poll the next future to kick off the fetch. If it's already ready,
@@ -141,7 +120,7 @@ where
141120 }
142121 Poll :: Ready ( None ) | Poll :: Pending => { }
143122 }
144- } else if !should_subscribe_parent {
123+ } else if !should_walk_parent {
145124 // No more parents to fetch; Finish the stream.
146125 * this. pending . as_mut ( ) = None . into ( ) ;
147126 }
@@ -157,9 +136,9 @@ where
157136 }
158137 Poll :: Ready ( Some ( Some ( block) ) ) => {
159138 let height = block. height ( ) ;
160- let should_subscribe_parent = height > END_BOUND ;
161- if should_subscribe_parent {
162- let future = this. marshal . clone ( ) . subscribe_parent ( block. clone ( ) ) . boxed ( ) ;
139+ let should_walk_parent = height > END_BOUND ;
140+ if should_walk_parent {
141+ let future = this. marshal . clone ( ) . subscribe ( block. clone ( ) ) . boxed ( ) ;
163142 * this. pending . as_mut ( ) = Some ( future) . into ( ) ;
164143
165144 // Explicitly poll the next future to kick off the fetch. If it's already ready,
@@ -197,8 +176,9 @@ mod test {
197176 impl BlockProvider for MockProvider {
198177 type Block = Block < Sha256Digest , ( ) > ;
199178
200- async fn subscribe ( self , digest : Sha256Digest ) -> Option < Self :: Block > {
201- self . 0 . into_iter ( ) . find ( |b| b. digest ( ) == digest)
179+ async fn subscribe ( self , block : Self :: Block ) -> Option < Self :: Block > {
180+ let parent = block. parent ;
181+ self . 0 . into_iter ( ) . find ( |b| b. digest ( ) == parent)
202182 }
203183 }
204184
0 commit comments