-
Notifications
You must be signed in to change notification settings - Fork 255
feat(pulse): optimize gas while keeping requests on-chain #2519
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5848112
feat: gas optimizations
tejasbadadare d24c070
fix: remove unnecessary concrete impl
tejasbadadare d5c61c2
add benchmarking for variable feeds
tejasbadadare 945e081
test: add out of order fulfillment benchmark
tejasbadadare 6f5eafa
update benchmark tests
tejasbadadare 84d2c9a
Merge branch 'main' of github.com:pyth-network/pyth-crosschain into t…
tejasbadadare 89517b1
fix test
tejasbadadare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,41 +10,62 @@ contract PulseState { | |
uint8 public constant MAX_PRICE_IDS = 10; | ||
|
||
struct Request { | ||
// Slot 1: 8 + 8 + 4 + 12 = 32 bytes | ||
uint64 sequenceNumber; | ||
uint64 publishTime; | ||
// TODO: this is going to absolutely explode gas costs. Need to do something smarter here. | ||
// possible solution is to hash the price ids and store the hash instead. | ||
// The ids themselves can be retrieved from the event. | ||
bytes32[MAX_PRICE_IDS] priceIds; | ||
uint8 numPriceIds; // Actual number of price IDs used | ||
uint256 callbackGasLimit; | ||
uint32 callbackGasLimit; | ||
uint96 fee; | ||
// Slot 2: 20 + 12 = 32 bytes | ||
address requester; | ||
// 12 bytes padding | ||
|
||
// Slot 3: 20 + 12 = 32 bytes | ||
address provider; | ||
uint128 fee; | ||
// 12 bytes padding | ||
|
||
// Dynamic array starts at its own slot | ||
// Store only first 8 bytes of each price ID to save gas | ||
bytes8[] priceIdPrefixes; | ||
} | ||
|
||
struct ProviderInfo { | ||
uint128 baseFeeInWei; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this particular ordering if we can pack it even more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we can do better than 3 slots for ProviderInfo unless i'm missing something? |
||
uint128 feePerFeedInWei; | ||
uint128 feePerGasInWei; | ||
// Slot 1: 12 + 12 + 8 = 32 bytes | ||
uint96 baseFeeInWei; | ||
uint96 feePerFeedInWei; | ||
// 8 bytes padding | ||
|
||
// Slot 2: 12 + 16 + 4 = 32 bytes | ||
uint96 feePerGasInWei; | ||
uint128 accruedFeesInWei; | ||
// 4 bytes padding | ||
|
||
// Slot 3: 20 + 1 + 11 = 32 bytes | ||
address feeManager; | ||
bool isRegistered; | ||
// 11 bytes padding | ||
} | ||
|
||
struct State { | ||
// Slot 1: 20 + 4 + 8 = 32 bytes | ||
address admin; | ||
uint128 pythFeeInWei; | ||
uint128 accruedFeesInWei; | ||
address pyth; | ||
uint32 exclusivityPeriodSeconds; | ||
uint64 currentSequenceNumber; | ||
// Slot 2: 20 + 8 + 4 = 32 bytes | ||
address pyth; | ||
uint64 firstUnfulfilledSeq; | ||
// 4 bytes padding | ||
|
||
// Slot 3: 20 + 12 = 32 bytes | ||
address defaultProvider; | ||
uint256 exclusivityPeriodSeconds; | ||
uint96 pythFeeInWei; | ||
// Slot 4: 16 + 16 = 32 bytes | ||
uint128 accruedFeesInWei; | ||
// 16 bytes padding | ||
|
||
// These take their own slots regardless of ordering | ||
Request[NUM_REQUESTS] requests; | ||
mapping(bytes32 => Request) requestsOverflow; | ||
mapping(address => ProviderInfo) providers; | ||
uint64 firstUnfulfilledSeq; // All sequences before this are fulfilled | ||
} | ||
|
||
State internal _state; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.