Skip to content

Commit

Permalink
MBIP 5 (#2452)
Browse files Browse the repository at this point in the history
* temporarily pim frontier and evm local changes

* support to record storage growth in precompiles

* add GasLimitStorageGrowth

* add GasLimitStorageGrowth in mocks

* add storage growth for precompiles

* fix tests

* add typescript tests

* update frontier and evm dependencies

* use the moonbeam-foundation org for the evm dependency

* fix tests

* fix formatting

* Update precompiles/utils/src/substrate.rs

Co-authored-by: Agustín Rodriguez <[email protected]>

* fix expected gas for precompile proxy

* Update test/suites/dev/test-storage-growth/test-evm-create-storage-growth.ts

Co-authored-by: Agustín Rodriguez <[email protected]>

* add tests of storage growth for precompiles

* disable MBIP 5 on moonriver and moonbeam

* fix tests

* fix typo

* adds rustls-webpki to accepted licenses

* set storage_growth to 0 for add_proxy precompile

Co-authored-by: Éloïs <[email protected]>

* set growth ratio as a constant

* fix formatting

---------

Co-authored-by: Agustín Rodriguez <[email protected]>
Co-authored-by: Alan Sapede <[email protected]>
Co-authored-by: Crystalin <[email protected]>
Co-authored-by: Éloïs <[email protected]>
  • Loading branch information
5 people authored Aug 30, 2023
1 parent bce21c3 commit 7759b61
Show file tree
Hide file tree
Showing 64 changed files with 1,135 additions and 466 deletions.
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

0 comments on commit 7759b61

Please sign in to comment.