-
Notifications
You must be signed in to change notification settings - Fork 278
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
Conversation
…dates w/ accumulator data
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
There was a problem hiding this 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.
target_chains/ethereum/contracts/contracts/pyth/PythAccumulator.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/contracts/pyth/PythAccumulator.sol
Outdated
Show resolved
Hide resolved
function verifyAndParsePriceFeedFromMerkleProof( | ||
bytes20 digest, | ||
bytes memory encoded, | ||
uint offset |
There was a problem hiding this comment.
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.
target_chains/ethereum/contracts/contracts/pyth/PythAccumulator.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
There was a problem hiding this 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.
refactor, add parse revert tests
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
target_chains/ethereum/contracts/contracts/pyth/PythAccumulator.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
There was a problem hiding this 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.
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 |
There was a problem hiding this 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.
target_chains/ethereum/contracts/contracts/pyth/PythAccumulator.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Show resolved
Hide resolved
target_chains/ethereum/contracts/forge-test/Pyth.WormholeMerkleAccumulator.t.sol
Outdated
Show resolved
Hide resolved
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{ |
There was a problem hiding this comment.
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
Summary
Add support accumulator update data in
parsePriceFeeds
Changes
PythAccumulator.sol
and Pyth.sol` and add support for purely parsing