@@ -52,14 +52,19 @@ use {
52
52
} ,
53
53
sync:: Arc ,
54
54
time:: {
55
- Duration ,
56
55
SystemTime ,
57
56
UNIX_EPOCH ,
58
57
} ,
59
58
} ,
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
+ } ,
63
68
} ,
64
69
wormhole_sdk:: {
65
70
Address ,
@@ -74,10 +79,11 @@ pub mod types;
74
79
pub mod wormhole;
75
80
76
81
pub 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 > > ,
81
87
}
82
88
83
89
impl Store {
@@ -90,6 +96,7 @@ impl Store {
90
96
. build ( ) ,
91
97
guardian_set : RwLock :: new ( Default :: default ( ) ) ,
92
98
update_tx,
99
+ last_completed_update_at : RwLock :: new ( None ) ,
93
100
} )
94
101
}
95
102
@@ -170,6 +177,11 @@ impl Store {
170
177
171
178
self . update_tx . send ( ( ) ) . await ?;
172
179
180
+ self . last_completed_update_at
181
+ . write ( )
182
+ . await
183
+ . replace ( Instant :: now ( ) ) ;
184
+
173
185
Ok ( ( ) )
174
186
}
175
187
@@ -258,4 +270,16 @@ impl Store {
258
270
. map ( |key| PriceIdentifier :: new ( key. id ) )
259
271
. collect ( )
260
272
}
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
+ }
261
285
}
0 commit comments