-
Notifications
You must be signed in to change notification settings - Fork 521
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
improve weight per gas calculation #995
Merged
sorpaas
merged 1 commit into
polkadot-evm:master
from
koushiro:improve-weight-per-gas-calc
Feb 8, 2023
Merged
Changes from all commits
Commits
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 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
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.
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.
How did you get this
BLOCK_GAS_LIMIT
? There seems to be a dead loop in your solution. When you calculate theBLOCK_GAS_LIMIT
, you also needWeightPerGas
.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.
actually, you need to know
BLOCK_GAS_LIMIT
firstly, then calculate the weight per gas.if not that, how did you get the original
WEIGHT_PER_GAS
?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 remembered that the const value was estimated by the benchmark.
https://github.com/paritytech/frontier/blob/master/frame/evm/src/benchmarking.rs
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's just reversed order -- previously we get block gas limit from weight per gas. Now we get weight per gas from block gas limit.
Both are equivalent, but I'd honestly like the new approach slightly more. The thing is -- one can get a much more accurate estimate of the overall block gas limit through benchmarking (because it's aggregated), than weight per gas, and thus fixing the former would be better.
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'm working on #994 , an issue that has some relevance to the current pr.
block_gas_limit
was previously calculated fromblock_max_weight
andweight_per_gas
.block_max_weight
is known in runtime andweight_per_gas
can be obtained from pallet_evm's benchmark.block_gas_limit = block_max_weight / weight_per_gas.
Can you go a bit deeper into your idea? @sorpaas
Benchmark the maximum value of transaction gas that a block of fixed weight size can hold? That doesn't seem to work, the Ethereum::transact() call's weight calculation requires
weight_per_gas
, and theweigth_per_gas
calculation requiresblock_gas_limit
, which is like a loop.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 just mean they are equivalent. When you know
block_gas_limit
, you knowweight_per_gas
, and vice versa. The formula is always fixed:We just need to get any of the value. Previously we get
weight_per_gas
first and then calculateblock_gas_limit
. After this PR we getblock_gas_limit
first and then calculateweight_per_gas
.I don't see any loops -- we use
pallet_evm::Config::WeightPerGas
for transaction / execution related gas calculation through theWeightGasMapping
.pallet_evm::Config::BlockGasLimit
is not used for them, and instead is only used for populating the Ethereum block gas limit. However, indeed, the config valueBlockGasLimit
should probably belong topallet_ethereum
instead ofpallet_evm
.Regarding benchmarking, the normal benchmark process for Substrate is different than benchmarking
BlockGasLimit
/WeightPerGas
. Substrate has strict definition of what weight is (10^12 Weight as 1 second of computation on the physical machine used for benchmarking), and the whole Substrate benchmarking process is based on that. However, forBlockGasLimit
/WeightPerGas
, the process is different -- we have to figure out the maximum allowable value through a trial and error process.This is why I say the new method (fixing
BlockGasLimit
instead ofWeightPerGas
) is better. Technically the old and new method will get the same result (because it's equivalent). However, usingBlockGasLimit
is aggregated, and more intuitive because that's the actual value that we're comparing against in benchmarking.