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 [MBIP-5] #2452

Merged
merged 26 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ec950e3
temporarily pim frontier and evm local changes
ahmadkaouk Aug 25, 2023
0aa9802
support to record storage growth in precompiles
ahmadkaouk Aug 25, 2023
38d7d69
add GasLimitStorageGrowth
ahmadkaouk Aug 25, 2023
1429e4d
add GasLimitStorageGrowth in mocks
ahmadkaouk Aug 25, 2023
f805738
Merge branch 'master' into ahmad-mbip-5
ahmadkaouk Aug 27, 2023
5a86eaf
add storage growth for precompiles
ahmadkaouk Aug 27, 2023
8cf9e31
fix tests
ahmadkaouk Aug 28, 2023
995a3b7
add typescript tests
ahmadkaouk Aug 28, 2023
fabcccc
update frontier and evm dependencies
ahmadkaouk Aug 29, 2023
cfb7f69
use the moonbeam-foundation org for the evm dependency
ahmadkaouk Aug 29, 2023
c56abde
fix tests
ahmadkaouk Aug 29, 2023
7acc7a7
Merge branch 'master' into ahmad-mbip-5
ahmadkaouk Aug 29, 2023
3dd1d48
fix formatting
ahmadkaouk Aug 29, 2023
bcf28b8
Merge branch 'master' into ahmad-mbip-5
ahmadkaouk Aug 29, 2023
321fd53
Update precompiles/utils/src/substrate.rs
ahmadkaouk Aug 29, 2023
f8dec39
fix expected gas for precompile proxy
ahmadkaouk Aug 29, 2023
a9d6a72
Update test/suites/dev/test-storage-growth/test-evm-create-storage-gr…
crystalin Aug 29, 2023
627d3e6
add tests of storage growth for precompiles
ahmadkaouk Aug 29, 2023
75771b9
disable MBIP 5 on moonriver and moonbeam
ahmadkaouk Aug 29, 2023
3c30736
fix tests
ahmadkaouk Aug 29, 2023
08ba2bd
fix typo
ahmadkaouk Aug 29, 2023
942a9a3
Merge branch 'master' into ahmad-mbip-5
crystalin Aug 29, 2023
4b54b75
adds rustls-webpki to accepted licenses
crystalin Aug 29, 2023
f55a843
set storage_growth to 0 for add_proxy precompile
ahmadkaouk Aug 29, 2023
555dcae
set growth ratio as a constant
ahmadkaouk Aug 29, 2023
9c1a1af
fix formatting
ahmadkaouk Aug 29, 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
827 changes: 463 additions & 364 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ ethereum = { version = "0.14.0", default-features = false, features = [
"with-codec",
] }
ethereum-types = { version = "0.14", default-features = false }
evm = { git = "https://github.com/moonbeam-foundation/evm", branch = "tgm-record-external-cost", default-features = false }
evm-gasometer = { git = "https://github.com/moonbeam-foundation/evm", branch = "tgm-record-external-cost", default-features = false }
evm-runtime = { git = "https://github.com/moonbeam-foundation/evm", branch = "tgm-record-external-cost", default-features = false }
evm = { git = "https://github.com/moonbeam-foundation/evm", rev = "a33ac87ad7462b7e7029d12c385492b2a8311d1c", default-features = false }
evm-gasometer = { git = "https://github.com/moonbeam-foundation/evm", rev = "a33ac87ad7462b7e7029d12c385492b2a8311d1c", default-features = false }
evm-runtime = { git = "https://github.com/moonbeam-foundation/evm", rev = "a33ac87ad7462b7e7029d12c385492b2a8311d1c", default-features = false }
fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v0.9.43", default-features = false }
Expand Down
7 changes: 7 additions & 0 deletions pallets/ethereum-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ impl FindAuthor<H160> for FindAuthorTruncated {
}

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block storage limit in bytes. Set to 40 KB.
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;

parameter_types! {
pub const TransactionByteFee: u64 = 1;
Expand All @@ -157,6 +159,10 @@ parameter_types! {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(MAX_POV_SIZE)
};
pub GasLimitStorageGrowthRatio: u64 = {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
};
}

pub struct HashedAddressMapping;
Expand Down Expand Up @@ -188,6 +194,7 @@ impl pallet_evm::Config for Test {
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type OnCreate = ();
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Test>;
}
Expand Down
15 changes: 15 additions & 0 deletions precompiles/assets-erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ where
id: asset_id.clone().into(),
delegate: Runtime::Lookup::unlookup(spender.clone()),
},
0,
)?;
}
// Dispatch call (if enough gas).
Expand All @@ -288,6 +289,7 @@ where
delegate: Runtime::Lookup::unlookup(spender),
amount,
},
0,
)?;

Ok(())
Expand Down Expand Up @@ -319,6 +321,7 @@ where
target: Runtime::Lookup::unlookup(to),
amount: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}

Expand Down Expand Up @@ -366,6 +369,7 @@ where
destination: Runtime::Lookup::unlookup(to),
amount: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
} else {
// Dispatch call (if enough gas).
Expand All @@ -377,6 +381,7 @@ where
target: Runtime::Lookup::unlookup(to),
amount: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}
}
Expand Down Expand Up @@ -551,6 +556,7 @@ where
beneficiary: Runtime::Lookup::unlookup(to),
amount: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}

Expand Down Expand Up @@ -596,6 +602,7 @@ where
who: Runtime::Lookup::unlookup(from),
amount: value,
},
0,
)?;
}

Expand Down Expand Up @@ -636,6 +643,7 @@ where
id: asset_id.into(),
who: Runtime::Lookup::unlookup(account),
},
0,
)?;
}

Expand Down Expand Up @@ -667,6 +675,7 @@ where
id: asset_id.into(),
who: Runtime::Lookup::unlookup(account),
},
0,
)?;
}

Expand Down Expand Up @@ -694,6 +703,7 @@ where
pallet_assets::Call::<Runtime, Instance>::freeze_asset {
id: asset_id.into(),
},
0,
)?;
}

Expand Down Expand Up @@ -721,6 +731,7 @@ where
pallet_assets::Call::<Runtime, Instance>::thaw_asset {
id: asset_id.into(),
},
0,
)?;
}

Expand Down Expand Up @@ -754,6 +765,7 @@ where
id: asset_id.into(),
owner: Runtime::Lookup::unlookup(owner),
},
0,
)?;
}

Expand Down Expand Up @@ -794,6 +806,7 @@ where
admin: Runtime::Lookup::unlookup(admin),
freezer: Runtime::Lookup::unlookup(freezer),
},
0,
)?;
}

Expand Down Expand Up @@ -827,6 +840,7 @@ where
symbol: symbol.into(),
decimals,
},
0,
)?;
}

Expand Down Expand Up @@ -854,6 +868,7 @@ where
pallet_assets::Call::<Runtime, Instance>::clear_metadata {
id: asset_id.into(),
},
0,
)?;
}

Expand Down
7 changes: 7 additions & 0 deletions precompiles/assets-erc20/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pub type LocalPCall = Erc20AssetsPrecompileSetCall<Runtime, IsLocal, pallet_asse
pub type ForeignPCall = Erc20AssetsPrecompileSetCall<Runtime, IsLocal, pallet_assets::Instance1>;

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block Storage Limit in bytes. Set to 40KB.
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(u64::MAX);
Expand All @@ -189,6 +191,10 @@ parameter_types! {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(MAX_POV_SIZE)
};
pub GasLimitStorageGrowthRatio: u64 = {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
};
}

impl pallet_evm::Config for Runtime {
Expand All @@ -210,6 +216,7 @@ impl pallet_evm::Config for Runtime {
type FindAuthor = ();
type OnCreate = ();
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}
Expand Down
10 changes: 5 additions & 5 deletions precompiles/author-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = AuthorMappingCall::<Runtime>::add_association { nimbus_id };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call, 0)?;

Ok(())
}
Expand All @@ -104,7 +104,7 @@ where
new_nimbus_id,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call, 0)?;

Ok(())
}
Expand All @@ -122,7 +122,7 @@ where
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = AuthorMappingCall::<Runtime>::clear_association { nimbus_id };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call, 0)?;

Ok(())
}
Expand All @@ -138,7 +138,7 @@ where
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = AuthorMappingCall::<Runtime>::remove_keys {};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call, 0)?;

Ok(())
}
Expand All @@ -152,7 +152,7 @@ where
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = AuthorMappingCall::<Runtime>::set_keys { keys: keys.into() };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call, 0)?;

Ok(())
}
Expand Down
7 changes: 7 additions & 0 deletions precompiles/author-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub type PCall = AuthorMappingPrecompileCall<Runtime>;
mock_account!(AuthorMappingAccount, |_| MockAccount::from_u64(1));

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block storage limit in bytes. Set to 40 KB.
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(u64::MAX);
Expand All @@ -117,6 +119,10 @@ parameter_types! {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(MAX_POV_SIZE)
};
pub GasLimitStorageGrowthRatio: u64 = {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
};
}

impl pallet_evm::Config for Runtime {
Expand All @@ -138,6 +144,7 @@ impl pallet_evm::Config for Runtime {
type FindAuthor = ();
type OnCreate = ();
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}
Expand Down
3 changes: 3 additions & 0 deletions precompiles/balances-erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ where
dest: Runtime::Lookup::unlookup(to),
value: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}

Expand Down Expand Up @@ -353,6 +354,7 @@ where
dest: Runtime::Lookup::unlookup(to),
value: value,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}

Expand Down Expand Up @@ -414,6 +416,7 @@ where
dest: Runtime::Lookup::unlookup(caller),
value: amount,
},
SYSTEM_ACCOUNT_SIZE,
)?;

log2(
Expand Down
7 changes: 7 additions & 0 deletions precompiles/balances-erc20/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub type Precompiles<R> = PrecompileSetBuilder<
pub type PCall = Erc20BalancesPrecompileCall<Runtime, NativeErc20Metadata, ()>;

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block storage limit in bytes. Set to 40 KB.
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(u64::MAX);
Expand All @@ -110,6 +112,10 @@ parameter_types! {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(MAX_POV_SIZE)
};
pub GasLimitStorageGrowthRatio: u64 = {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
};
}

impl pallet_evm::Config for Runtime {
Expand All @@ -131,6 +137,7 @@ impl pallet_evm::Config for Runtime {
type FindAuthor = ();
type OnCreate = ();
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}
Expand Down
7 changes: 7 additions & 0 deletions precompiles/batch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ mock_account!(Batch, |_| MockAccount::from_u64(1));
mock_account!(Revert, |_| MockAccount::from_u64(2));

const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
/// Block storage limit in bytes. Set to 40 KB.
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(u64::MAX);
Expand All @@ -131,6 +133,10 @@ parameter_types! {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(MAX_POV_SIZE)
};
pub GasLimitStorageGrowthRatio: u64 = {
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT)
};
}

impl pallet_evm::Config for Runtime {
Expand All @@ -152,6 +158,7 @@ impl pallet_evm::Config for Runtime {
type FindAuthor = ();
type OnCreate = ();
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}
Expand Down
1 change: 1 addition & 0 deletions precompiles/call-permit/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl pallet_evm::Config for Runtime {
type FindAuthor = ();
type OnCreate = ();
type GasLimitPovSizeRatio = ();
type GasLimitStorageGrowthRatio = ();
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}
Expand Down
4 changes: 4 additions & 0 deletions precompiles/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ where
proposal,
length_bound: proposal_length,
},
SYSTEM_ACCOUNT_SIZE,
)?;

log.record(handle)?;
Expand Down Expand Up @@ -196,6 +197,7 @@ where
proposal,
length_bound: proposal_length,
},
SYSTEM_ACCOUNT_SIZE,
)?;
}

Expand Down Expand Up @@ -230,6 +232,7 @@ where
index: proposal_index,
approve,
},
SYSTEM_ACCOUNT_SIZE,
)?;

log.record(handle)?;
Expand Down Expand Up @@ -262,6 +265,7 @@ where
),
length_bound,
},
SYSTEM_ACCOUNT_SIZE,
)?;

// We can know if the proposal was executed or not based on the `pays_fee` in
Expand Down
Loading
Loading