-
Notifications
You must be signed in to change notification settings - Fork 486
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
Introduce a gas-based Storage limit per tx #1142
Open
ahmadkaouk
wants to merge
45
commits into
polkadot-evm:master
Choose a base branch
from
moonbeam-foundation:ahmad-add-storage-limit-per-tx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Introduce a gas-based Storage limit per tx #1142
ahmadkaouk
wants to merge
45
commits into
polkadot-evm:master
from
moonbeam-foundation:ahmad-add-storage-limit-per-tx
Conversation
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
notlesh
reviewed
Aug 14, 2023
notlesh
reviewed
Aug 14, 2023
notlesh
reviewed
Aug 14, 2023
notlesh
reviewed
Aug 14, 2023
notlesh
reviewed
Aug 23, 2023
boundless-forest
approved these changes
Aug 31, 2023
@sorpaas can we review this one please. |
@ahmadkaouk you could use evm 0.41.0 now |
@koushiro Using evm 0.41.0 now. |
koushiro
reviewed
Nov 21, 2023
Co-authored-by: Qinxuan Chen <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Introduction
This pull request tackles the challenge of unsustainable storage growth in our blockchain, a complex issue constrained by the Evm gasometer's ability to record only gas usage. Storage growth refers to the new storage added on-chain after an execution. Without control, this can lead to storage congestions.
Approach: Introduce a gas-based Storage limit
The proposed solution tackles the problem of unsustainable storage growth within blockchains by introducing a concept of mapping storage to gas. By translating bytes into gas units and setting a storage limit per transaction, it establishes a flexible and effective control mechanism. The proposed solution maintains the existing behaviour of the EVM gasometer. It introduces controls for storage growth without altering the core gas tracking system within the EVM.
The core of this approach revolves around the definition of a ratio that encapsulates the relationship between storage growth (in bytes) and gas. For example:
RATIO
=BLOCK_GAS_LIMIT
/BLOCK_STORAGE_LIMIT
Once this ratio is established, we can further define a transaction-wide storage growth limit:
TX_STORAGE_LIMIT
=TX_GAS_LIMIT
/RATIO
The storage growth is dynamically monitored throughout the execution of the transaction. Each time the EVM steps into an opcode, the corresponding storage growth is calculated and recorded. Should the recorded storage growth exceed the pre-established
TX_STORAGE_LIMIT
, the transaction will trigger anOutOfGas
error.Example
Given:
BLOCK_GAS_LIMIT
= 15,000,000 (Maximum gas per block)BLOCK_STORAGE_LIMIT
= 40 * 1024 bytes (40 KB per block)The ratio between gas and storage is:
RATIO
=BLOCK_GAS_LIMIT
/BLOCK_STORAGE_LIMIT
= 15,000,000 / (40 * 1024) ≈ 366For a transaction with
TX_GAS_LIMIT
= 1,000,000, the storage limit is:TX_STORAGE_LIMIT
=TX_GAS_LIMIT
/RATIO
= 1,000,000 / 366 ≈ 2,732 bytesChanges Introduced
The following changes are introduced to address storage growth within the EVM:
GasLimitStorageGrowthRatio
: A new configurable parameter inpallet-evm
, defining the ratio of gas to storage. It serves to control the mapping of storage growth to gas. When set to 0, it disables recording the storage growth.StorageMeter
: An utility struct withinSubstrateStackState
to track and manage storage growth during execution.SSTORE
, Storage growth is recorded during pre-execution inrecord_external_dynamic_opcode_cost
, which is called frompre_validate
in the executor (that is per each evm runtime step).CREATE
andCREATE2
, since the bytecode size to be stored is unknown before execution, recording occurs inrecord_external_operation
during execution, specifically incleanup_for_create
before storing the contract bytecode.