-
Notifications
You must be signed in to change notification settings - Fork 301
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
fix: use simulation to estimate gas used #11211
base: master
Are you sure you want to change the base?
Conversation
a3586fb
to
dc8198a
Compare
Co-authored-by: Santiago Palladino <[email protected]>
Co-authored-by: Santiago Palladino <[email protected]>
Co-authored-by: Santiago Palladino <[email protected]>
@@ -528,17 +528,19 @@ describe('L1Publisher integration', () => { | |||
await expect(publisher.proposeL2Block(block)).resolves.toEqual(false); | |||
|
|||
// Test for both calls | |||
expect(loggerErrorSpy).toHaveBeenCalledTimes(2); | |||
// NOTE: First error is from the simulate fn, which isn't supported by anvil |
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.
The simulate with time
overrides?
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.
yep
yarn-project/ethereum/src/utils.ts
Outdated
* @param abi - The ABI to use for decoding. | ||
* @returns A FormattedViemError instance. | ||
*/ | ||
export function formatViemError(error: any, abi: Abi = RollupAbi): FormattedViemError { |
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 altered the script that we use to generate the artifacts such that the errors should be included inside the other ABIs. So they are in the rollup one or whetever is being used. But maybe it should not be specifically the RollupAbi
that is being checked against here. Mainly if some other contract were used this formatter gets pretty strange.
https://github.com/AztecProtocol/aztec-packages/pull/10697/files
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which | ||
// make time consistency checks break. |
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.
Should not be the case. Also, we should be able to get rid of the validateBlockForSubmission
here if the send can actually simulate it.
// @note we override checkBlob to false since blobs are not part simulate() | ||
stateDiff: [ | ||
{ | ||
slot: toHex(9n, true), |
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 we could probably just use the forge inspect <CONTRACT> storageLayout --json
to populate, then it should be fairly easy to fetch from there. Sounds like a good idea to have.
Its a kinda annoying one though, as ideally the variable itself should not exists 😬.
], | ||
); | ||
|
||
if (simulationResult === -1n) { |
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.
Throwing an error as mentioner earlier would make more sense to me here.
This reverts commit ab9ce34.
Changes to public function bytecode sizes
🧾 Summary (100% most significant diffs)
Full diff report 👇
|
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.
LGTM! Just an issue with the things being thrown.
if [ -n "${EXTERNAL_ETHEREUM_HOST}" ]; then | ||
export ETHEREUM_HOST="${EXTERNAL_ETHEREUM_HOST}" | ||
fi |
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.
Curious why we have two different env vars
const formattedError = formatViemError(err); | ||
|
||
const res = err; | ||
// console.log('res', res); |
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.
// console.log('res', res); |
throw formattedErr; | ||
const { message, metaMessages } = formatViemError(err); | ||
this.logger?.error(`Failed to send L1 transaction`, message, { metaMessages }); | ||
throw { ...err, message, metaMessages }; |
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.
Heads up that you're not throwing an Error
here, but a plain object. So any checks downstream for instanceof Error
will fail, and any formatting specific to errors (such as printing the stack trace) will get lost. We should always throw a proper Error (or subclass) instance to avoid issues.
if (err.message?.includes('reverted')) { | ||
throw formattedErr; | ||
throw { ...error, message }; |
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.
Same as above
if (simErr instanceof MethodNotFoundRpcError || simErr instanceof MethodNotSupportedRpcError) { | ||
// @note node doesn't support simulation API, we will use gas guesstimate | ||
this.log.warn('Using gas guesstimate'); | ||
simulationResult = L1Publisher.PROPOSE_GAS_GUESS; | ||
} else { | ||
throw simErr; | ||
} |
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.
It seems that we'll be doing this pretty often. Should we have simulateGasUsed
accept a fallbackGasIfMethodNotSupported
option to handle this automatically?
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which | ||
// make time consistency checks break. |
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 take it this will be addressed in another PR then, right?
Relevant to #10991 but not 'Fixes' because anvil doesn't support
eth_simulateV1
so we can't yet remove all time-based inputs in L1Fixes #11341
simulate
the 'propose' & 'proposeAndClaim' transactions, using the appropriate timestamp, instead of using hardcoded 12M gas.Follow-up from this: #11390 #11440