Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracles: Move feeders to collection level #1672

Merged
merged 11 commits into from
Jan 9, 2024

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Jan 4, 2024

Description

Move the feeder concept by collection instead of by key.

@lemunozm lemunozm self-assigned this Jan 4, 2024
@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 4, 2024

Already compiling with cargo check -p pallet-oracle-collection

@lemunozm lemunozm force-pushed the oracle/feeders-by-collection-level branch from ce58e28 to dfb8aa2 Compare January 5, 2024 11:16
@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 5, 2024

It's now quite simple, and I would say it fits our requirements (by now).

  • If update_collection() is called and there is a key under use that has no associated feeder value for it, the method fails.
  • Only registered values are added to the collection when the collection is updated.

@lemunozm lemunozm marked this pull request as ready for review January 5, 2024 12:40
@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 5, 2024

This is ready @mustermeiszer 🙌🏻

@wischli wischli added this to the Centrifuge 1025 milestone Jan 8, 2024
.try_into()
.map_err(|_| Error::<T>::NoOracleCollectionChangeId)?;

Self::update_feeders(collection_id, key, feeders.clone())?;
CollectionInfo::<T>::insert(collection_id, info.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should forbid any non-allowed feeder to feed any further values at this point. Basically, iterate over all keys in the storage and remove unknown feeders.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good point

Basically, iterate over all keys in the storage and remove unknown feeders.

I would say this could be more complex because some existing keys could have lost some of their feeders (but not all), and then the aggregated values could have changed or not been validated.

Could we consider that if we call apply_update_collection_info(), then you should call later update_collection() to reflect those changes? We can understand the current collection as the values the collection had at the moment of updating. If we see this in such a way, then there is no problem if feeders are modified because the collection at that point contained such previous feeders and values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree with me, it could be interesting to add a last_updated field to the collection to know if the content of the collection reflects a moment in the past.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to add a last_updated field to the collection to know if the content of the collection reflects a moment in the past.

I thought that is already the case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider that if we call apply_update_collection_info(), then you should call later update_collection() to reflect those changes? We can understand the current collection as the values the collection had at the moment of updating. If we see this in such a way, then there is no problem if feeders are modified because the collection at that point contained such previous feeders and values.

Yes, that is a good idea. update_collection will filter them already, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, apply_update_collection_info should just purge the CachedCollection storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to purge it 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that is already the case?

The timestamp stored in the collection is the timestamp of the older Oracle value, not the timestamp of when the collection was outdated. So now we will store both

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So purge or store outdated timestamp?

Copy link
Contributor Author

@lemunozm lemunozm Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use both. Store the last_updated each time we call update_collection() and purge when apply.

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about the iteration of the Keys storage during this review and this is a possibly unbounded iteration.

We should use CountedStorageMap instead OR restrict register_id to not store anymore keys if MaxKeysPerCollection is reached.

@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 9, 2024

That is a very good point! Thanks for your profound review.

I think I'll need to do it by myself in register_id, because the map is a DoubleStorageMap, and the CountedStorageNMap counts all elements. I need a counter per collection, not a counter per key in all collections.

@lemunozm lemunozm requested a review from mustermeiszer January 9, 2024 07:40
.try_into()
.map_err(|_| Error::<T>::NoOracleCollectionChangeId)?;

Self::update_feeders(collection_id, key, feeders.clone())?;
CollectionInfo::<T>::insert(collection_id, info.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to add a last_updated field to the collection to know if the content of the collection reflects a moment in the past.

I thought that is already the case?

.try_into()
.map_err(|_| Error::<T>::NoOracleCollectionChangeId)?;

Self::update_feeders(collection_id, key, feeders.clone())?;
CollectionInfo::<T>::insert(collection_id, info.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider that if we call apply_update_collection_info(), then you should call later update_collection() to reflect those changes? We can understand the current collection as the values the collection had at the moment of updating. If we see this in such a way, then there is no problem if feeders are modified because the collection at that point contained such previous feeders and values.

Yes, that is a good idea. update_collection will filter them already, right?

.try_into()
.map_err(|_| Error::<T>::NoOracleCollectionChangeId)?;

Self::update_feeders(collection_id, key, feeders.clone())?;
CollectionInfo::<T>::insert(collection_id, info.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, apply_update_collection_info should just purge the CachedCollection storage?

pallets/oracle-collection/src/lib.rs Show resolved Hide resolved
@lemunozm lemunozm requested a review from mustermeiszer January 9, 2024 09:55
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience! Thats looks like a good iteration to the final version!

@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 9, 2024

Thanks for all your feedback! Very appreciated and accurate! 🙌🏻

@lemunozm lemunozm merged commit 433211e into main Jan 9, 2024
9 checks passed
@lemunozm lemunozm deleted the oracle/feeders-by-collection-level branch January 9, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants