open-runtime-module-library
open-runtime-module-library copied to clipboard
Oracle using outdated values
If I understand the code correctly, each reported value is only valid for a certain amount of time. However, the aggregated value only gets updated after a new price feed has been received. As such, when one of the input values of the aggregate expires, the aggregate should update. Most significantly, if an oracle client stops submitting values altogether, the reported value will retain the last reported value forever.
Is my understanding of the code correct? If so, is this something that you guys are open to including a fix for in this pallet?
If all oracle operators stoped reporting value, I am not sure what else can we do.
Do you have a suggestion on how to better handling it?
I think two changes would be required:
- Invalidate the aggregate when the oldest value included in the aggregate expires
- If there are no values that are not expired, the getter should return
None
I can't think an efficient way to do the invalidation. Can you propose one?
It already returns a timestamped value, so consumer can ignore old value.
I can't think an efficient way to do the invalidation. Can you propose one?
When you aggregate the values, you can iterate over the elements to find the oldest one, and based on that, set a ValidUntil storage item. Then change the getter as such:
pub fn get(key: &T::OracleKey) -> Option<TimestampedValueOf<T, I>> {
- if Self::is_updated(key) {
+ if Self::is_updated(key) && !Self::is_outdated(key) {
<Values<T, I>>::get(key)
} else {
let timestamped = Self::combined(key)?;
<Values<T, I>>::insert(key, timestamped.clone());
IsUpdated::<T, I>::insert(key, true);
Some(timestamped)
}
}
Right. That will work. PR are welcome!