polkadot-evm / frontier

Ethereum compatibility layer for Substrate.
Apache License 2.0
564 stars 471 forks source link

Benchmark of Precompile executed code #1348

Open PierreOssun opened 5 months ago

PierreOssun commented 5 months ago

Question

Hello, I would like to know if there is a way to benchmark code executed in a precompile prior to the pallet dispatch call. For example in this code it first:

to finally dispatch the call on behalf of this AccountId. However only the Weight from the dispatched call will be charged, not the weight for this pre-execution. As a DoS protection we are charging a overestimated ref_time amount.

Is there a way to properly benchmark this piece of code ?

boundless-forest commented 5 months ago

I think the gas fee has been handled in the try_dispatch, no need to record_gas manually before try_dispatch.

PierreOssun commented 5 months ago

Hi @boundless-forest, In try_dispatch only the weight of the RuntimeCall is recorded. See here. Also in this test that the expect_cost charged is equal to the weight of the call (prior calling dispatch, the weight of the call calculated by benchmarking) and the const gas that is charged at the beginning of the precompile. But all the execution in the precompile prior to dispatch the call is not automatically charged, hence will need proper benchmarking

magecnion commented 5 months ago

I'm facing the same problem; I need to benchmark the precompiles properly. Any updates on that?