Skip to content
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
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5b8860f
A new trait for recording foreign metrics
ahmadkaouk Jul 31, 2023
d692104
Remove Metric trait
ahmadkaouk Aug 2, 2023
523b18c
rename BasicMetric to Metric
ahmadkaouk Aug 2, 2023
b168105
add unit tests and a new MetricError enum
ahmadkaouk Aug 2, 2023
ce75d15
Add ProofSizeMeter
ahmadkaouk Aug 3, 2023
26a85ad
Add ProofSizeMeter to WeightInfo
ahmadkaouk Aug 3, 2023
78273fb
formatting
ahmadkaouk Aug 3, 2023
df4f5cf
Add RefTimeMeter to WeightInfo
ahmadkaouk Aug 3, 2023
1f86da7
add storage meter to WeightInfo
ahmadkaouk Aug 4, 2023
230879a
rename metric to resource
ahmadkaouk Aug 4, 2023
54b7c01
code refactor
ahmadkaouk Aug 7, 2023
d9f04e2
remove unused functions
ahmadkaouk Aug 8, 2023
af358ad
make clippy happy
ahmadkaouk Aug 8, 2023
8fa4dd2
minor improvements
ahmadkaouk Aug 9, 2023
65d8b97
rename meter to resource
ahmadkaouk Aug 9, 2023
6a344db
compute new storage created by SSTORE
ahmadkaouk Aug 10, 2023
dea63f6
revert changes
ahmadkaouk Aug 14, 2023
4c45d4f
compute storage growth for opcodes
ahmadkaouk Aug 17, 2023
cea9817
compute the storage quota per tx
ahmadkaouk Aug 18, 2023
e412643
pin evm temporarily
ahmadkaouk Aug 20, 2023
dbf0370
record storage growth for opcodes
ahmadkaouk Aug 20, 2023
84b487f
update GAS_LIMIT_STORAGE_GROWTH_RATIO for tests
ahmadkaouk Aug 21, 2023
cce7cf5
add support to record storage growth for precompiles
ahmadkaouk Aug 21, 2023
4670129
fix tests
ahmadkaouk Aug 21, 2023
dee68d8
fix formatting
ahmadkaouk Aug 21, 2023
f110333
fix storage growth parameters for tests
ahmadkaouk Aug 22, 2023
332bde7
add rust integration tests
ahmadkaouk Aug 23, 2023
1623f9c
fix typo
ahmadkaouk Aug 23, 2023
19ba629
fix recording storage growth of a special use case of SSTORE
ahmadkaouk Aug 28, 2023
7578175
use saturating add
ahmadkaouk Aug 28, 2023
d0304fe
minor improvements
ahmadkaouk Aug 28, 2023
fb31dac
add license to meter.rs
ahmadkaouk Aug 28, 2023
a6da7ef
fix clippy warnings
ahmadkaouk Aug 28, 2023
4a6ea48
pin evm to master
ahmadkaouk Aug 28, 2023
ba9552d
update evm to the latest commit
ahmadkaouk Aug 29, 2023
f14d3e2
check limit exceedance before updating the usage
ahmadkaouk Sep 12, 2023
ca9e4d3
Use BtreeSet
ahmadkaouk Sep 15, 2023
21bf9d0
Merge remote-tracking branch 'upstream/master' into ahmad-add-storage…
ahmadkaouk Sep 15, 2023
4a343e6
add support for storage growth in precompiles
ahmadkaouk Sep 15, 2023
e72809d
clippy warnings
ahmadkaouk Sep 15, 2023
de7876e
Merge remote-tracking branch 'upstream/master' into ahmad-add-storage…
ahmadkaouk Nov 2, 2023
e46e222
Merge remote-tracking branch 'upstream/master' into ahmad-add-storage…
ahmadkaouk Nov 21, 2023
553984f
update to evm 0.41.0
ahmadkaouk Nov 21, 2023
063ea9d
Update Cargo.toml
ahmadkaouk Nov 21, 2023
74f321c
update Cargo.lock
ahmadkaouk Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ bn = { package = "substrate-bn", version = "0.6", default-features = false }
clap = { version = "4.4.3", features = ["derive", "deprecated"] }
derive_more = "0.99"
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum = { version = "0.15.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "d543f105c2ce61494f9cedd6011f7f14989fd611", default-features = false }
ahmadkaouk marked this conversation as resolved.
Show resolved Hide resolved
futures = "0.3.28"
hash-db = { version = "0.16.0", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
Expand Down
5 changes: 4 additions & 1 deletion frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ impl FindAuthor<H160> for FindAuthorTruncated {

const BLOCK_GAS_LIMIT: u64 = 150_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;

/// The maximum storage growth per block in bytes.
const MAX_STORAGE_GROWTH: u64 = 800 * 1024;
parameter_types! {
pub const TransactionByteFee: u64 = 1;
pub const ChainId: u64 = 42;
pub const EVMModuleId: PalletId = PalletId(*b"py/evmpa");
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
pub const GasLimitStorageGrowthRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_STORAGE_GROWTH);
pub const WeightPerGas: Weight = Weight::from_parts(20_000, 0);
}

Expand Down Expand Up @@ -174,6 +176,7 @@ impl pallet_evm::Config for Test {
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type SuicideQuickClearLimit = SuicideQuickClearLimit;
type Timestamp = Timestamp;
type WeightInfo = ();
Expand Down
7 changes: 5 additions & 2 deletions frame/evm/precompile/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ where
return Err(err);
}

handle
.record_external_cost(Some(info.weight.ref_time()), Some(info.weight.proof_size()))?;
handle.record_external_cost(
Some(info.weight.ref_time()),
Some(info.weight.proof_size()),
None,
)?;

match call.dispatch(Some(origin).into()) {
Ok(post_info) => {
Expand Down
2 changes: 2 additions & 0 deletions frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl pallet_evm::Config for Test {
type FindAuthor = FindAuthorTruncated;
type SuicideQuickClearLimit = SuicideQuickClearLimit;
type GasLimitPovSizeRatio = ();
type GasLimitStorageGrowthRatio = ();
type Timestamp = Timestamp;
type WeightInfo = ();
}
Expand Down Expand Up @@ -185,6 +186,7 @@ impl PrecompileHandle for MockHandle {
&mut self,
_ref_time: Option<u64>,
_proof_size: Option<u64>,
_storage_growth: Option<u64>,
) -> Result<(), ExitError> {
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ pub mod pallet {
/// Define the quick clear limit of storage clearing when a contract suicides. Set to 0 to disable it.
type SuicideQuickClearLimit: Get<u32>;

/// Gas limit storage growth ratio.
type GasLimitStorageGrowthRatio: Get<u64>;

/// Get the timestamp for the current block.
type Timestamp: Time;

Expand Down
4 changes: 4 additions & 0 deletions frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ impl FindAuthor<H160> for FindAuthorTruncated {
}
const BLOCK_GAS_LIMIT: u64 = 150_000_000;
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// The maximum storage growth per block in bytes.
const MAX_STORAGE_GROWTH: u64 = 400 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
pub const GasLimitStorageGrowthRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_STORAGE_GROWTH);
pub WeightPerGas: Weight = Weight::from_parts(20_000, 0);
pub MockPrecompiles: MockPrecompileSet = MockPrecompileSet;
pub SuicideQuickClearLimit: u32 = 0;
Expand Down Expand Up @@ -153,6 +156,7 @@ impl crate::Config for Test {
type FindAuthor = FindAuthorTruncated;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type SuicideQuickClearLimit = SuicideQuickClearLimit;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = ();
}
Expand Down
27 changes: 27 additions & 0 deletions frame/evm/src/res/StorageGrowthTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.2;

contract StorageGrowthTest {
mapping(uint256 => uint256) public map;
uint256 foo;
uint256 bar;
uint256 baz;

constructor() {
foo = 1;
bar = 2;
baz = 3;
}

function store() public {
map[0] = 1;
map[1] = 2;
map[2] = 3;
}

function update() public {
foo = 2;
bar = 3;
baz = 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b506001808190555060028081905550600380819055506101c7806100356000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063975057e714610046578063a2e6204514610050578063b8dda9c71461005a575b600080fd5b61004e61008a565b005b6100586100d6565b005b610074600480360381019061006f919061011d565b6100f0565b6040516100819190610155565b60405180910390f35b6001600080808152602001908152602001600020819055506002600080600181526020019081526020016000208190555060036000806002815260200190815260200160002081905550565b600260018190555060036002819055506004600381905550565b60006020528060005260406000206000915090505481565b6000813590506101178161017a565b92915050565b60006020828403121561012f57600080fd5b600061013d84828501610108565b91505092915050565b61014f81610170565b82525050565b600060208201905061016a6000830184610146565b92915050565b6000819050919050565b61018381610170565b811461018e57600080fd5b5056fea2646970667358221220b25685afab962e465f0b43f6c4de10c82a565f50f6995c1cd444b002bcdd43e964736f6c63430008020033
Loading
Loading