-
Notifications
You must be signed in to change notification settings - Fork 517
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
Introduce a gas-based Storage limit per tx #1142
Conversation
@sorpaas can we review this one please. |
@ahmadkaouk you could use evm 0.41.0 now |
@koushiro Using evm 0.41.0 now. |
Co-authored-by: Qinxuan Chen <[email protected]>
@sorpaas We would like to merge this PR as we are cherry-picking it every release. |
Please merge the master, and I'll review and merge it later. @crystalin |
@boundless-forest I merged to master. PR is ready to be reviewed and merged |
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.
Just one comment, LGTM
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.