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(builder): only include paymaster gas if there is a postOp #457

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

alex-miao
Copy link
Collaborator

#349

Proposed Changes

  • In the gas limit calculation, only multiply the verification gas limit by 3 if we know the user operation uses a paymaster that has a postOp

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #457 (d2abe8f) into main (b253c48) will increase coverage by 0.31%.
The diff coverage is 98.49%.

Impacted file tree graph

Files Coverage Δ
crates/sim/src/gas/gas.rs 89.34% <100.00%> (-3.57%) ⬇️
crates/sim/src/precheck.rs 68.40% <100.00%> (ø)
crates/sim/src/simulation/simulation.rs 85.91% <100.00%> (+0.03%) ⬆️
crates/builder/src/bundle_proposer.rs 90.09% <99.45%> (+1.18%) ⬆️
crates/sim/src/gas/polygon.rs 0.00% <0.00%> (ø)
Flag Coverage Δ
unit-tests 52.56% <98.49%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
rundler binary 0.00% <ø> (ø)
builder 47.98% <99.45%> (+2.67%) ⬆️
dev 0.00% <ø> (ø)
pool 59.54% <ø> (ø)
provider 1.33% <ø> (ø)
rpc 18.26% <ø> (ø)
sim 82.20% <88.23%> (-0.42%) ⬇️
tasks ∅ <ø> (∅)
types 93.56% <ø> (ø)
utils 7.20% <ø> (ø)

op,
chain_id,
false,
Some(op_with_sim.simulation.requires_post_op),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Totally forgot that we run the simulation in the builder so this information is available to us after that. Won't be the case when we remove the simulation, but works for now!

@@ -536,7 +539,7 @@ where
let mut gas_left = U256::from(self.settings.max_bundle_gas);
let mut ops_in_bundle = Vec::new();
for op in ops {
let gas = gas::user_operation_gas_limit(&op.uo, self.settings.chain_id, false);
let gas = gas::user_operation_gas_limit(&op.uo, self.settings.chain_id, false, None);
Copy link
Collaborator

@dancoombs dancoombs Oct 9, 2023

Choose a reason for hiding this comment

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

Why is post-op None here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we need to account for that when we're limiting the gas in the bundle.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is annoying, however, since we don't have this information here since we haven't simulated yet. Ideally we limit gas in bundle before simulating...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep agree we need to account for it when limiting gas in the bundle, so the way it gets accounted for is that the gas::user_operation_gas_limit function takes in an Option<bool> representing whether we have a postOp or not. The None state represents when we have not done simulation yet, and the gas::verification_gas_limit_multiplier function defaults to the worst case of 3. We pass in Some(true) and Some(false) only post-simulation when we actually know if we use postOp or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't that mean that we're going to create bundles well below our limit if they all use postops?

Copy link
Collaborator Author

@alex-miao alex-miao Oct 9, 2023

Choose a reason for hiding this comment

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

One approach we could do is to have an initial pre-sim bundle gas limiting phase like we have now. We can add UOs up until the gas limit, but for UOs that have a paymaster, we can compute an optimistic and worst-case gas usage (optimistic being that they all have no postOp, pessimistic being they all use postOp). We then sim these UOs, but also a set of UOs that have a total gas limit bounded by the difference of the pessimistic and optimistic case. We deem these UOs as "backup" in the case that we end up having more space than we expected.

Copy link
Collaborator

@dancoombs dancoombs Oct 9, 2023

Choose a reason for hiding this comment

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

Hm, improving the gas limit we submit the bundle with doesn't really improve our ability to land more UOs on chain. We likely need to do more.

How about this?

  • Limit bundle assuming that none of the UOs use post op
  • Simulate
  • Further limit after knowing if UOs use post op.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we had a similar idea. It must be good then...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, since this represents a shift to limiting post sim, might also make sense here to take into account UOs that fail validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made #461 to address this issue, would be good to get this one in first since #461 depends on this.

crates/sim/src/gas/gas.rs Outdated Show resolved Hide resolved
@alex-miao alex-miao force-pushed the alex/paymaster-postop-gas branch 2 times, most recently from 5de4c82 to b2e2c3f Compare October 10, 2023 23:31
Copy link
Collaborator

@dancoombs dancoombs left a comment

Choose a reason for hiding this comment

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

Initial LGTM. Will wait to review once #461 merges

@alex-miao alex-miao force-pushed the alex/paymaster-postop-gas branch from c131f4b to d2abe8f Compare October 11, 2023 18:52
Copy link
Collaborator

@dancoombs dancoombs left a comment

Choose a reason for hiding this comment

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

🚢

@alex-miao alex-miao merged commit fbf0127 into main Oct 11, 2023
7 checks passed
@alex-miao alex-miao deleted the alex/paymaster-postop-gas branch October 11, 2023 19:06
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