@@ -119,19 +119,13 @@ pub mod module {
119
119
pub type RawValues < T : Config < I > , I : ' static = ( ) > =
120
120
StorageDoubleMap < _ , Twox64Concat , T :: AccountId , Twox64Concat , T :: OracleKey , TimestampedValueOf < T , I > > ;
121
121
122
- /// True if Self::values(key) is up to date, otherwise the value is stale
123
- #[ pallet:: storage]
124
- #[ pallet:: getter( fn is_updated) ]
125
- pub type IsUpdated < T : Config < I > , I : ' static = ( ) > =
126
- StorageMap < _ , Twox64Concat , <T as Config < I > >:: OracleKey , bool , ValueQuery > ;
127
-
128
- /// Combined value, may not be up to date
122
+ /// Up to date combined value from Raw Values
129
123
#[ pallet:: storage]
130
124
#[ pallet:: getter( fn values) ]
131
125
pub type Values < T : Config < I > , I : ' static = ( ) > =
132
126
StorageMap < _ , Twox64Concat , <T as Config < I > >:: OracleKey , TimestampedValueOf < T , I > > ;
133
127
134
- /// If an oracle operator has feed a value in this block
128
+ /// If an oracle operator has fed a value in this block
135
129
#[ pallet:: storage]
136
130
pub ( crate ) type HasDispatched < T : Config < I > , I : ' static = ( ) > =
137
131
StorageValue < _ , OrderedSet < T :: AccountId , T :: MaxHasDispatchedSize > , ValueQuery > ;
@@ -182,42 +176,14 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
182
176
. collect ( )
183
177
}
184
178
185
- /// Returns fresh combined value if has update, or latest combined
186
- /// value.
187
- ///
188
- /// Note this will update values storage if has update.
179
+ /// Fetch current combined value.
189
180
pub fn get ( key : & T :: OracleKey ) -> Option < TimestampedValueOf < T , I > > {
190
- if Self :: is_updated ( key) {
191
- <Values < T , I > >:: get ( key)
192
- } else {
193
- let timestamped = Self :: combined ( key) ?;
194
- <Values < T , I > >:: insert ( key, timestamped. clone ( ) ) ;
195
- IsUpdated :: < T , I > :: insert ( key, true ) ;
196
- Some ( timestamped)
197
- }
198
- }
199
-
200
- /// Returns fresh combined value if has update, or latest combined
201
- /// value.
202
- ///
203
- /// This is a no-op function which would not change storage.
204
- pub fn get_no_op ( key : & T :: OracleKey ) -> Option < TimestampedValueOf < T , I > > {
205
- if Self :: is_updated ( key) {
206
- Self :: values ( key)
207
- } else {
208
- Self :: combined ( key)
209
- }
181
+ Self :: values ( key)
210
182
}
211
183
212
184
#[ allow( clippy:: complexity) ]
213
185
pub fn get_all_values ( ) -> Vec < ( T :: OracleKey , Option < TimestampedValueOf < T , I > > ) > {
214
- <Values < T , I > >:: iter ( )
215
- . map ( |( key, _) | key)
216
- . map ( |key| {
217
- let v = Self :: get_no_op ( & key) ;
218
- ( key, v)
219
- } )
220
- . collect ( )
186
+ <Values < T , I > >:: iter ( ) . map ( |( k, v) | ( k, Some ( v) ) ) . collect ( )
221
187
}
222
188
223
189
fn combined ( key : & T :: OracleKey ) -> Option < TimestampedValueOf < T , I > > {
@@ -247,7 +213,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
247
213
timestamp : now,
248
214
} ;
249
215
RawValues :: < T , I > :: insert ( & who, & key, timestamped) ;
250
- IsUpdated :: < T , I > :: remove ( & key) ;
216
+
217
+ // Update `Values` storage if `combined` yielded result.
218
+ if let Some ( combined) = Self :: combined ( key) {
219
+ <Values < T , I > >:: insert ( key, combined) ;
220
+ }
251
221
252
222
T :: OnNewData :: on_new_data ( & who, key, value) ;
253
223
}
@@ -262,9 +232,6 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
262
232
for removed in outgoing {
263
233
RawValues :: < T , I > :: remove_prefix ( removed, None ) ;
264
234
}
265
-
266
- // not bothering to track which key needs recompute, just update all
267
- IsUpdated :: < T , I > :: remove_all ( None ) ;
268
235
}
269
236
270
237
fn set_prime ( _prime : Option < T :: AccountId > ) {
@@ -279,7 +246,7 @@ impl<T: Config<I>, I: 'static> DataProvider<T::OracleKey, T::OracleValue> for Pa
279
246
}
280
247
impl < T : Config < I > , I : ' static > DataProviderExtended < T :: OracleKey , TimestampedValueOf < T , I > > for Pallet < T , I > {
281
248
fn get_no_op ( key : & T :: OracleKey ) -> Option < TimestampedValueOf < T , I > > {
282
- Self :: get_no_op ( key)
249
+ Self :: get ( key)
283
250
}
284
251
285
252
#[ allow( clippy:: complexity) ]
0 commit comments