open-runtime-module-library icon indicating copy to clipboard operation
open-runtime-module-library copied to clipboard

Oracle using outdated values

Open sander2 opened this issue 4 years ago • 5 comments

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?

sander2 avatar Jul 05 '21 08:07 sander2

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?

xlc avatar Jul 05 '21 08:07 xlc

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

sander2 avatar Jul 05 '21 08:07 sander2

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.

xlc avatar Jul 05 '21 09:07 xlc

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)
  }
}

sander2 avatar Jul 05 '21 10:07 sander2

Right. That will work. PR are welcome!

xlc avatar Jul 05 '21 10:07 xlc