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

feat(pulse): Gas optimizations #2492

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat(pulse): Gas optimizations #2492

wants to merge 5 commits into from

Conversation

jayantk
Copy link
Contributor

@jayantk jayantk commented Mar 17, 2025

Summary

Two changes here to bring down the gas usage of the basic pulse flow.

  • use a hash of price ids instead of an array
  • don't maintain the set of unfulfilled requests on the blockchain

I also twiddled some of the struct field orders to bring down the number of storage slots used.

I suggest starting with PulseState to see the essence of the changes. The rest of the stuff is pretty mechanical fallout from there.

Rationale

These two features exist because we were concerned about the reliability of listening to the events on the chain. However, @tejasbadadare and I thought about this a bit and came up with a good solution to ensure we don't miss anything: you track the latest N block hashes and the events in each block, then on new blocks, you can make sure you're building on the same chain tip, or roll back and rebuild the chain as needed. The set of open requests is constructed by playing forward the events (both the create request & fulfill request events) in those blocks.

Given that, we can save a lot of gas by removing information from the chain state and moving it to the events.

How has this been tested?

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

Gas usage benchmark before this PR (cold storage case):

Ran 2 tests for forge-test/PulseGasBenchmark.t.sol:PulseGasBenchmark
[PASS] testBasicFlow() (gas: 453192)
[PASS] testDataMocking() (gas: 11724)

After this PR:

Ran 2 tests for forge-test/PulseGasBenchmark.t.sol:PulseGasBenchmark
[PASS] testBasicFlow() (gas: 277400)
[PASS] testDataMocking() (gas: 11724)

Hot storage case

Before

Ran 2 tests for forge-test/PulseGasBenchmark.t.sol:PulseGasBenchmark
[PASS] testBasicFlow() (gas: 408192)
[PASS] testDataMocking() (gas: 11724)

After

Ran 2 tests for forge-test/PulseGasBenchmark.t.sol:PulseGasBenchmark
[PASS] testBasicFlow() (gas: 217400)
[PASS] testDataMocking() (gas: 11724)

Copy link

vercel bot commented Mar 17, 2025

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

6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm
component-library ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm
entropy-debugger ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm
insights ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm
proposals ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm
staking ⬜️ Ignored (Inspect) Visit Preview Mar 17, 2025 3:57pm

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.

2 participants