@@ -18,7 +18,7 @@ use crate::{
1818 scheme:: Scheme ,
1919 types:: { verify_certificates, Finalization , Notarization , Subject } ,
2020 } ,
21- types:: { Epoch , Epocher , Height , Round , ViewDelta } ,
21+ types:: { Epoch , Epocher , Height , Round , View , ViewDelta } ,
2222 Block , Epochable , Heightable , Reporter ,
2323} ;
2424use bytes:: Bytes ;
@@ -54,7 +54,11 @@ use std::{collections::BTreeMap, future::Future, num::NonZeroUsize, sync::Arc};
5454use tracing:: { debug, warn} ;
5555
5656/// The key used to store the last application-acknowledged height.
57- const LATEST_KEY : U64 = U64 :: new ( 0xFF ) ;
57+ const LATEST_HEIGHT_KEY : U64 = U64 :: new ( 0xFF ) ;
58+ /// The key used to store the epoch component of the processed round floor.
59+ const LATEST_ROUND_EPOCH_KEY : U64 = U64 :: new ( 0xFE ) ;
60+ /// The key used to store the view component of the processed round floor.
61+ const LATEST_ROUND_VIEW_KEY : U64 = U64 :: new ( 0xFD ) ;
5862
5963// Resolver request keys are expressed in the variant commitment type, which
6064// may differ from the block digest for coded variants.
@@ -195,7 +199,7 @@ where
195199 )
196200 . await
197201 . expect ( "failed to initialize application metadata" ) ;
198- let last_applied_height = application_metadata. get ( & LATEST_KEY ) . copied ( ) ;
202+ let last_applied_height = application_metadata. get ( & LATEST_HEIGHT_KEY ) . copied ( ) ;
199203 let processed_floor_height = last_applied_height. unwrap_or ( Height :: zero ( ) ) ;
200204
201205 // Genesis is seeded as a local anchor. If the application has not
@@ -215,8 +219,11 @@ where
215219 }
216220 Start :: Floor ( finalization) => Some ( finalization) ,
217221 } ;
218- let last_processed_round =
222+ let height_derived_processed_round =
219223 Self :: latest_processed_round ( & finalizations_by_height, processed_floor_height) . await ;
224+ let last_processed_round = Self :: metadata_round_floor ( & application_metadata)
225+ . unwrap_or ( Round :: zero ( ) )
226+ . max ( height_derived_processed_round) ;
220227
221228 // Create metrics
222229 let finalized_height = context. gauge ( "finalized_height" , "Finalized height of application" ) ;
@@ -485,7 +492,7 @@ where
485492 }
486493 } ;
487494
488- // Persist buffered processed-height updates once after draining all ready acks.
495+ // Persist buffered progress updates once after draining all ready acks.
489496 self . application_metadata
490497 . sync ( )
491498 . await
@@ -2042,7 +2049,7 @@ where
20422049 > ,
20432050 ) {
20442051 self . last_applied_height = Some ( height) ;
2045- self . application_metadata . put ( LATEST_KEY , height) ;
2052+ self . application_metadata . put ( LATEST_HEIGHT_KEY , height) ;
20462053 self . floor . set_processed_height ( height) ;
20472054 let _ = self
20482055 . processed_height
@@ -2052,6 +2059,13 @@ where
20522059 resolver. retain ( handler:: above_height_floor :: < V :: Commitment > ( height) ) ;
20532060 }
20542061
2062+ /// Returns the durably stored processed round floor, if present.
2063+ fn metadata_round_floor ( metadata : & Metadata < E , U64 , Height > ) -> Option < Round > {
2064+ let epoch = metadata. get ( & LATEST_ROUND_EPOCH_KEY ) ?;
2065+ let view = metadata. get ( & LATEST_ROUND_VIEW_KEY ) ?;
2066+ Some ( Round :: new ( Epoch :: new ( epoch. get ( ) ) , View :: new ( view. get ( ) ) ) )
2067+ }
2068+
20552069 /// Returns the latest known finalization round at or below the processed height.
20562070 async fn latest_processed_round ( finalizations_by_height : & FC , height : Height ) -> Round {
20572071 let Some ( finalization_height) = finalizations_by_height
@@ -2106,6 +2120,10 @@ where
21062120
21072121 let previous = self . floor . processed_round ( ) ;
21082122 self . floor . set_processed_round ( round) ;
2123+ self . application_metadata
2124+ . put ( LATEST_ROUND_EPOCH_KEY , Height :: new ( round. epoch ( ) . get ( ) ) ) ;
2125+ self . application_metadata
2126+ . put ( LATEST_ROUND_VIEW_KEY , Height :: new ( round. view ( ) . get ( ) ) ) ;
21092127
21102128 // Retain view-indexed cache data for a window behind the previously
21112129 // processed finalized block.
0 commit comments