Skip to content

Conversation

@ayushboss
Copy link
Contributor

@ayushboss ayushboss commented May 23, 2025

Summary

I updated the parsePriceFeedUpdatesInternal function to be more flexible and take an additional flag indicating whether or not parsed prices need to be stored.

Rationale

Recent changes added the parsePriceFeedUpdatesInternal function to prevent invocations of that function from updating storage. An additional flag allows us to be flexible with use cases that may need to update storage while performing parsing.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Tested using existing tests. Additionally, I added tests to verify the new parse function both when storage is enabled and disabled, checking that the parsed price signatures are found in the former case, and making sure that the price signatures are not updated in the latter. Also added gas benchmark tests.

@vercel
Copy link

vercel bot commented May 23, 2025

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

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 6:16pm
7 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
developer-hub ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
entropy-debugger ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
entropy-explorer ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
insights ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
proposals ⬜️ Skipped (Inspect) May 29, 2025 6:16pm
staking ⬜️ Skipped (Inspect) May 29, 2025 6:16pm

@ayushboss ayushboss changed the title Optional storage flag when parsing price feed updates refactor: Optional storage flag when parsing price feed updates May 26, 2025
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – staking May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 26, 2025 22:03 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – staking May 26, 2025 22:53 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 26, 2025 22:53 Inactive
Copy link
Contributor

@tejasbadadare tejasbadadare left a comment

Choose a reason for hiding this comment

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

Thanks! Couple notes

  • Can we add a test case that asserts that when the param is enabled it actually updates the underlying public feed, and the negative case as well?
  • Can we add a test to the gas benchmark to check how expensive parsing + storing is?
  • Do the updated contracts fit within size limits? (forge build --sizes)

Comment on lines 89 to 103
function parsePriceFeedUpdatesWithConfig(
bytes[] calldata updateData,
bytes32[] calldata priceIds,
uint64 minPublishTime,
uint64 maxPublishTime,
bool unique
uint64 minAllowedPublishTime,
uint64 maxAllowedPublishTime,
bool checkUniqueness,
bool checkUpdateDataIsMinimal,
bool storeUpdatesIfFresh
)
internal
returns (PythStructs.PriceFeed[] memory feeds, uint64[] memory slots)
public
payable
returns (
PythStructs.PriceFeed[] memory feeds,
uint64[] memory slots
)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this is a little confusing as a public API since it exposes lots of options (prone to misconfiguration) and also returns data most people won't need (slots). Might be better to keep this as a private method and expose public APIs targeted at specific use cases. The only thing using storeUpdatesIfFresh would be Pulse via parsePriceFeedUpdatesWithSlotsStrict, so we could expose the storeUpdatesIfFresh param there. Curious on your thoughts on this @ali-bahjati .

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm I think the practice I've seen elsewhere is a combination of both. You'd keep easy to understand shortcuts for people but one that is not often used (likely we only use it ourselves) because at the same time making API for every combo is not good (it comes more as confusing to people).

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it makes sense. lets make sure to include a note in the natspec doc that it's recommended in most cases to use the standard parsePriceFeedUpdates or parsePriceFeedUpdatesStrict methods.

@vercel vercel bot temporarily deployed to Preview – staking May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 28, 2025 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 28, 2025 18:32 Inactive
Copy link
Contributor

@tejasbadadare tejasbadadare left a comment

Choose a reason for hiding this comment

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

nice! couple small things, please address before merging. also looks like you may need to run the formatter to get CI to pass (pre-commit should help take care of this automatically going forward, see .pre-commit-config.yaml)


// Check all price feeds were found
for (uint k = 0; k < priceIds.length; k++) {
for (uint k = 0; k < priceIds.length; ++k) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how is preincrement different here?

// Should revert in strict mode
vm.expectRevert(PythErrors.InvalidArgument.selector);
pyth.parsePriceFeedUpdatesWithSlotsStrict{value: updateFee}(
pyth.parsePriceFeedUpdatesWithConfig{value: updateFee}(
Copy link
Contributor

Choose a reason for hiding this comment

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

can we update the names of these tests please

Copy link
Contributor

Choose a reason for hiding this comment

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

let's bump the version() to 1.4.5-alpha.1

override
returns (PythStructs.PriceFeed[] memory priceFeeds);

function parsePriceFeedUpdatesWithSlotsStrict(
Copy link
Contributor

Choose a reason for hiding this comment

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

did we squeeze within the size limit with this? :)

@vercel vercel bot temporarily deployed to Preview – proposals May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – staking May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger May 29, 2025 18:14 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub May 29, 2025 18:14 Inactive
@ayushboss ayushboss merged commit 9867275 into main Jun 2, 2025
12 checks passed
@ayushboss ayushboss deleted the parse-price-feed-update-optional-storage branch June 2, 2025 15:42
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.

4 participants