@@ -52,14 +52,19 @@ use {
5252        } , 
5353        sync:: Arc , 
5454        time:: { 
55-             Duration , 
5655            SystemTime , 
5756            UNIX_EPOCH , 
5857        } , 
5958    } , 
60-     tokio:: sync:: { 
61-         mpsc:: Sender , 
62-         RwLock , 
59+     tokio:: { 
60+         sync:: { 
61+             mpsc:: Sender , 
62+             RwLock , 
63+         } , 
64+         time:: { 
65+             Duration , 
66+             Instant , 
67+         } , 
6368    } , 
6469    wormhole_sdk:: { 
6570        Address , 
@@ -74,10 +79,11 @@ pub mod types;
7479pub  mod  wormhole; 
7580
7681pub  struct  Store  { 
77-     pub  storage :            StorageInstance , 
78-     pub  observed_vaa_seqs :  Cache < u64 ,  bool > , 
79-     pub  guardian_set :       RwLock < BTreeMap < u32 ,  GuardianSet > > , 
80-     pub  update_tx :          Sender < ( ) > , 
82+     pub  storage :                   StorageInstance , 
83+     pub  observed_vaa_seqs :         Cache < u64 ,  bool > , 
84+     pub  guardian_set :              RwLock < BTreeMap < u32 ,  GuardianSet > > , 
85+     pub  update_tx :                 Sender < ( ) > , 
86+     pub  last_completed_update_at :  RwLock < Option < Instant > > , 
8187} 
8288
8389impl  Store  { 
@@ -90,6 +96,7 @@ impl Store {
9096                . build ( ) , 
9197            guardian_set :  RwLock :: new ( Default :: default ( ) ) , 
9298            update_tx, 
99+             last_completed_update_at :  RwLock :: new ( None ) , 
93100        } ) 
94101    } 
95102
@@ -170,6 +177,11 @@ impl Store {
170177
171178        self . update_tx . send ( ( ) ) . await ?; 
172179
180+         self . last_completed_update_at 
181+             . write ( ) 
182+             . await 
183+             . replace ( Instant :: now ( ) ) ; 
184+ 
173185        Ok ( ( ) ) 
174186    } 
175187
@@ -258,4 +270,16 @@ impl Store {
258270            . map ( |key| PriceIdentifier :: new ( key. id ) ) 
259271            . collect ( ) 
260272    } 
273+ 
274+     pub  async  fn  is_ready ( & self )  -> bool  { 
275+         const  STALENESS_THRESHOLD :  Duration  = Duration :: from_secs ( 30 ) ; 
276+ 
277+         let  last_completed_update_at = self . last_completed_update_at . read ( ) . await ; 
278+         match  last_completed_update_at. as_ref ( )  { 
279+             Some ( last_completed_update_at)  => { 
280+                 last_completed_update_at. elapsed ( )  < STALENESS_THRESHOLD 
281+             } 
282+             None  => false , 
283+         } 
284+     } 
261285} 
0 commit comments