Skip to content

Ethereum/parse price feed updates accumulators #855

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

Merged
merged 10 commits into from
Jun 7, 2023

Conversation

swimricky
Copy link
Contributor

Summary

Add support accumulator update data in parsePriceFeeds

Changes

  • Refactor PythAccumulator.sol and Pyth.sol` and add support for purely parsing
  • Add test for parsePriceFeedUpdates with Accumulator update data

@vercel
Copy link

vercel bot commented May 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Jun 7, 2023 6:36pm
xc-admin-frontend ⬜️ Ignored (Inspect) Jun 7, 2023 6:36pm

@swimricky swimricky marked this pull request as ready for review June 1, 2023 19:12
@swimricky swimricky requested review from jayantk and guibescos June 1, 2023 19:13
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

I left you some suggestions for improvements here. I think @ali-bahjati should definitely look at this too because iirc there are weird gas efficiency hacks that he's the most knowledgable about.

function verifyAndParsePriceFeedFromMerkleProof(
bytes20 digest,
bytes memory encoded,
uint offset
Copy link
Contributor

Choose a reason for hiding this comment

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

why do some of these functions take an offset while other ones assume you've sliced off any prefixed bytes already? I think it's better to be consistent.

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

I think the code is great. It needs some improvements that Jayant has pointed out. Many of them are there because of my pervious code bad choices and I'm sorry about it. Some of them were gas optimisation considerations that we will do in a separate PR.

I think we can merge this once comments are addressed and you have added more tests.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

thanks this code is much clearer now. I think there's still some work to be done on the tests though -- see inline comments.

publishTime < minPublishTime ||
publishTime > maxPublishTime
publishTime >= minPublishTime &&
publishTime <= maxPublishTime
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... so whenever you have a check like this for a start/end, you usually want one side to be >= and the other side to be < so that you can specify any arbitrary sized interval. In this case, you can't specify a zero-length interval. The typical convention is the start is inclusive and the end is exclusive.

anyway, i realize this check existed before you wrote this code, and we probably don't want to change the behavior now, so whatever. this is just an fyi.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"you can't specify a zero-length interval" is wrong. We don't have zero-length on inclusive end too.

I decided to have inclusive end interval because it's more intuitive with the minPublishTime and maxPublishTime.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the typical convention is >= and <, and following that will be more intuitive to most people.

Copy link
Collaborator

@ali-behjati ali-behjati Jun 7, 2023

Choose a reason for hiding this comment

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

idk :D maybe you are right and it's very personal. I agree that with array ranges (slices) [start, end) is the convention. but when there is min & max, I feel [min, max] is more intuitive. On slice you say all indexes that are less than end. but for max min you say that a publish time that is minimum min and maximum max. Anyway,
i might be totally wrong.

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

thanks this code is much clearer now. I think there's still some work to be done on the tests though -- see inline comments.

Copy link
Collaborator

@ali-behjati ali-behjati 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 two comments that are mostly my opinions and would be great to discuss them:

  • It was hard for me to follow the code flow and I think we don't need this many methods.
  • I think although it's easier to add code to updatePriceFeeds tests to avoid duplication but it makes tests more complex for a new test reader and makes debugging more difficult. I believe each test should be as simple as possible and test only a single scenario. I would break the tests in testParsePriceFeedWithWormholeMerkleWorks in multiple tests and also will probably create a separate file for all the parse price feeds tests.

@swimricky
Copy link
Contributor Author

I have two comments that are mostly my opinions and would be great to discuss them:

  • It was hard for me to follow the code flow and I think we don't need this many methods.
  • I think although it's easier to add code to updatePriceFeeds tests to avoid duplication but it makes tests more complex for a new test reader and makes debugging more difficult. I believe each test should be as simple as possible and test only a single scenario. I would break the tests in testParsePriceFeedWithWormholeMerkleWorks in multiple tests and also will probably create a separate file for all the parse price feeds tests.

i'll clean up and reduce the number of methods in a separate PR for gas optimization

for your second point about breaking up the tests, i don't mind separating out parsing portion into their own tests. Since the setups between the parse and update versions will be largely the same i'm not too sure if the gain in simplicity will really be that significant. I think it would make sense to bundle them together in some of the tests just to highlight the differences between updatePriceFeeds and parsePriceFeedUpdates`

@swimricky swimricky requested review from jayantk and ali-behjati June 7, 2023 12:24
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

thanks this looks good to me. I agree with @ali-bahjati that it can be a little hard to understand the tests, but let's look at ways to refactor them to simplify in a subsequent PR. This one is already quite big.

priceIds[2] = priceFeedMessages2[0].priceId;
// parse price feeds before updating since parsing price feeds should be independent
// of whatever is currently stored in the contract.
PythStructs.PriceFeed[] memory priceFeeds = pyth.parsePriceFeedUpdates{
Copy link
Contributor

Choose a reason for hiding this comment

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

comment for later: I notice that there's a code block like this that's repeated a lot, where you have some messages, then you do some work to extract ids, call parsePriceFeedUpdates, then do the assert below. You could simplify the tests by extracting this block out to a common helper function

@swimricky swimricky merged commit 9ddc7fd into main Jun 7, 2023
@swimricky swimricky deleted the ethereum/parsePriceFeedUpdatesAccumulators branch June 7, 2023 19:44
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