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

Polkadot v1.1.0 upgrade #185

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
92268df
update ACCOUNT_BASIC_PROOF_SIZE constant
koushiro Jun 27, 2023
d478968
use moonbeam fork
librelois Jul 3, 2023
d3799c9
use moonbeam evm fork
librelois Jul 3, 2023
7512b0f
catch ethereum execution info
tgmichel Mar 1, 2023
55cf4dc
make Pending storage public
Agusrodri Jul 4, 2023
721b7b7
refactor evm recursion lock
librelois Aug 14, 2023
06d2703
fix benchmarking for different node templates (#179)
nbaztec Aug 18, 2023
1c9f248
create helper function max_transaction_encoded_size
librelois Aug 18, 2023
550ec5a
Fix refund base fee (#1118)
tgmichel Jul 27, 2023
7f07e26
A new trait for recording foreign metrics
ahmadkaouk Jul 31, 2023
a8d0f3f
Remove Metric trait
ahmadkaouk Aug 2, 2023
1303f0c
rename BasicMetric to Metric
ahmadkaouk Aug 2, 2023
8e3fffa
add unit tests and a new MetricError enum
ahmadkaouk Aug 2, 2023
9143345
Add ProofSizeMeter
ahmadkaouk Aug 3, 2023
c473838
Add ProofSizeMeter to WeightInfo
ahmadkaouk Aug 3, 2023
1be13df
formatting
ahmadkaouk Aug 3, 2023
07ba5f5
Add RefTimeMeter to WeightInfo
ahmadkaouk Aug 3, 2023
7a8c09e
add storage meter to WeightInfo
ahmadkaouk Aug 4, 2023
1ab2dc3
rename metric to resource
ahmadkaouk Aug 4, 2023
6b41b63
code refactor
noandrea Aug 28, 2023
e23b067
remove unused functions
ahmadkaouk Aug 8, 2023
fc51e2d
make clippy happy
ahmadkaouk Aug 8, 2023
534fd4c
minor improvements
ahmadkaouk Aug 9, 2023
5d5d5b0
rename meter to resource
ahmadkaouk Aug 9, 2023
faa4424
compute new storage created by SSTORE
ahmadkaouk Aug 10, 2023
8ae7446
revert changes
ahmadkaouk Aug 14, 2023
9236488
compute storage growth for opcodes
ahmadkaouk Aug 17, 2023
aa640bf
compute the storage quota per tx
ahmadkaouk Aug 18, 2023
8adaac2
pin evm temporarily
ahmadkaouk Aug 20, 2023
71d9356
record storage growth for opcodes
ahmadkaouk Aug 20, 2023
a8cd2a0
update GAS_LIMIT_STORAGE_GROWTH_RATIO for tests
ahmadkaouk Aug 21, 2023
d094584
add support to record storage growth for precompiles
ahmadkaouk Aug 21, 2023
82075c4
fix tests
ahmadkaouk Aug 21, 2023
c26aaf2
fix formatting
ahmadkaouk Aug 21, 2023
91b8d02
fix storage growth parameters for tests
ahmadkaouk Aug 22, 2023
359d900
add rust integration tests
ahmadkaouk Aug 23, 2023
51f03bf
fix typo
ahmadkaouk Aug 23, 2023
2222259
fix recording storage growth of a special use case of SSTORE
ahmadkaouk Aug 28, 2023
01899fc
use saturating add
ahmadkaouk Aug 28, 2023
c929018
minor improvements
ahmadkaouk Aug 28, 2023
9e47f69
add license to meter.rs
ahmadkaouk Aug 28, 2023
8924c07
fix clippy warnings
ahmadkaouk Aug 28, 2023
18d9071
pin evm to master
ahmadkaouk Aug 28, 2023
4564774
update evm to the latest commit
ahmadkaouk Aug 29, 2023
cc8c93d
use the moonbeam-foundation org for the evm dependency
noandrea Aug 29, 2023
c35e19c
Upgrade dependencies to polkadot-v1.1.0
Sep 14, 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
2,344 changes: 1,346 additions & 998 deletions Cargo.lock

Large diffs are not rendered by default.

137 changes: 69 additions & 68 deletions Cargo.toml

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions client/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<Block: BlockT, I: Clone + BlockImport<Block>, C> Clone for FrontierBlockImp
impl<B, I, C> FrontierBlockImport<B, I, C>
where
B: BlockT,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>>,
I: BlockImport<B>,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
Expand All @@ -98,13 +98,12 @@ where
impl<B, I, C> BlockImport<B> for FrontierBlockImport<B, I, C>
where
B: BlockT,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync,
I: BlockImport<B> + Send + Sync,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B> + Send + Sync,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
{
type Error = ConsensusError;
type Transaction = sp_api::TransactionFor<C, B>;

async fn check_block(
&mut self,
Expand All @@ -115,7 +114,7 @@ where

async fn import_block(
&mut self,
block: BlockImportParams<B, Self::Transaction>,
block: BlockImportParams<B>,
) -> Result<ImportResult, Self::Error> {
// We validate that there are only one frontier log. No other
// actions are needed and mapping syncing is delegated to a separate
Expand Down
8 changes: 2 additions & 6 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ use sc_client_api::backend::{Backend, StorageProvider};
use sc_transaction_pool::ChainApi;
use sp_api::{
ApiExt, CallApiAt, CallApiAtParams, CallContext, Extensions, ProvideRuntimeApi,
StorageTransactionCache,
};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::HeaderBackend;
use sp_inherents::CreateInherentDataProviders;
use sp_io::hashing::{blake2_128, twox_128};
use sp_runtime::{traits::Block as BlockT, DispatchError, SaturatedConversion};
use sp_runtime::{traits::{Block as BlockT, HashingFor}, DispatchError, SaturatedConversion};
use sp_state_machine::OverlayedChanges;
// Frontier
use fc_rpc_core::types::*;
Expand Down Expand Up @@ -241,14 +240,11 @@ where
api_version,
state_overrides,
)?;
let storage_transaction_cache =
RefCell::<StorageTransactionCache<B, C::StateBackend>>::default();
let params = CallApiAtParams {
at: substrate_hash,
function: "EthereumRuntimeRPCApi_call",
arguments: encoded_params,
overlayed_changes: &RefCell::new(overlayed_changes),
storage_transaction_cache: &storage_transaction_cache,
call_context: CallContext::Offchain,
recorder: &None,
extensions: &RefCell::new(Extensions::new()),
Expand Down Expand Up @@ -888,7 +884,7 @@ where
block_hash: B::Hash,
api_version: u32,
state_overrides: Option<BTreeMap<H160, CallStateOverride>>,
) -> RpcResult<OverlayedChanges> {
) -> RpcResult<OverlayedChanges<HashingFor<B>>> {
let mut overlayed_changes = OverlayedChanges::default();
if let Some(state_overrides) = state_overrides {
for (address, state_override) in state_overrides {
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod frontier_backend_client {
use sp_io::hashing::{blake2_128, twox_128};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, UniqueSaturatedInto, Zero},
traits::{Block as BlockT, UniqueSaturatedInto, Zero, HashingFor},
};
use sp_state_machine::OverlayedChanges;
// Frontier
Expand All @@ -95,7 +95,7 @@ pub mod frontier_backend_client {

fn set_overlayed_changes(
client: &C,
overlayed_changes: &mut OverlayedChanges,
overlayed_changes: &mut OverlayedChanges<HashingFor<B>>,
block: B::Hash,
_version: u32,
address: H160,
Expand Down Expand Up @@ -148,7 +148,7 @@ pub mod frontier_backend_client {

fn set_overlayed_changes(
client: &C,
overlayed_changes: &mut OverlayedChanges,
overlayed_changes: &mut OverlayedChanges<HashingFor<B>>,
block: B::Hash,
_version: u32,
address: H160,
Expand Down
2 changes: 2 additions & 0 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = { workspace = true }
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
environmental = { workspace = true }
ethereum = { workspace = true, features = ["with-codec"] }
ethereum-types = { workspace = true }
evm = { workspace = true, features = ["with-codec"] }
Expand Down Expand Up @@ -44,6 +45,7 @@ fp-self-contained = { workspace = true, features = ["default"] }
[features]
default = ["std"]
std = [
"environmental/std",
"ethereum/std",
"evm/std",
"ethereum-types/std",
Expand Down
32 changes: 32 additions & 0 deletions frame/ethereum/src/catch_exec_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0
// This file is part of Frontier.
//
// Copyright (c) 2020-2022 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use fp_evm::CallOrCreateInfo;

environmental::environmental!(GLOBAL: Option<CallOrCreateInfo>);

// Allow to catch informations of an ethereum execution inside the provided closure.
pub fn catch_exec_info<R, F: FnOnce() -> R>(
execution_info: &mut Option<CallOrCreateInfo>,
f: F,
) -> R {
GLOBAL::using(execution_info, f)
}

pub(super) fn fill_exec_info(execution_info: &CallOrCreateInfo) {
GLOBAL::with(|exec_info| exec_info.replace(execution_info.clone()));
}
48 changes: 34 additions & 14 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
#![allow(clippy::comparison_chain, clippy::large_enum_variant)]
#![warn(unused_crate_dependencies)]

mod catch_exec_info;
#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
mod tests;

pub use catch_exec_info::catch_exec_info;

use ethereum_types::{Bloom, BloomInput, H160, H256, H64, U256};
use evm::ExitReason;
use fp_consensus::{PostLog, PreLog, FRONTIER_ENGINE_ID};
Expand All @@ -41,14 +44,14 @@ use fp_evm::{
};
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
scale_info::TypeInfo,
pallet_prelude::TypeInfo,
traits::{EnsureOrigin, Get, PalletInfoAccess, Time},
weights::Weight,
};
use frame_system::{pallet_prelude::OriginFor, CheckWeight, WeightInfo};
use pallet_evm::{BlockHashMapping, FeeCalculator, GasWeightMapping, Runner};
use scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::{
generic::DigestItem,
traits::{DispatchInfoOf, Dispatchable, One, Saturating, UniqueSaturatedInto, Zero},
Expand Down Expand Up @@ -317,7 +320,7 @@ pub mod pallet {

/// Current building block's transactions and receipts.
#[pallet::storage]
pub(super) type Pending<T: Config> =
pub type Pending<T: Config> =
StorageValue<_, Vec<(Transaction, TransactionStatus, Receipt)>, ValueQuery>;

/// The current Ethereum block.
Expand Down Expand Up @@ -356,17 +359,14 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// The call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof.
fn proof_size_base_cost(transaction: &Transaction) -> u64 {
transaction
.encode()
.len()
// pallet index
.saturating_add(1)
// call index
.saturating_add(1) as u64
}

/// The call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof.
fn proof_size_base_cost(transaction: &Transaction) -> u64 {
transaction
.encoded_size()
// pallet index + call index
.saturating_add(2) as u64
}

fn recover_signer(transaction: &Transaction) -> Option<H160> {
let mut sig = [0u8; 65];
let mut msg = [0u8; 32];
Expand Down Expand Up @@ -564,6 +564,8 @@ impl<T: Config> Pallet<T> {
) -> DispatchResultWithPostInfo {
let (to, _, info) = Self::execute(source, &transaction, None)?;

catch_exec_info::fill_exec_info(&info);

let pending = Pending::<T>::get();
let transaction_hash = transaction.hash();
let transaction_index = pending.len() as u32;
Expand Down Expand Up @@ -856,6 +858,24 @@ impl<T: Config> Pallet<T> {
}
}

/// Estimated maximal SCALE encoded size of an ethereum transaction
pub fn max_transaction_encoded_size(input: &[u8], access_list: &[(H160, Vec<H256>)]) -> u64 {
Self::proof_size_base_cost(&Transaction::EIP1559(ethereum::EIP1559Transaction{
chain_id: 0,
nonce: Default::default(),
max_priority_fee_per_gas: Default::default(),
max_fee_per_gas: Default::default(),
gas_limit: Default::default(),
action: ethereum::TransactionAction::Call(Default::default()),
value: Default::default(),
input: input.to_vec(),
access_list: access_list.iter().map(|(address, storage_keys)| AccessListItem { address: *address, storage_keys: storage_keys.to_vec() }).collect(),
odd_y_parity: false,
r: Default::default(),
s: Default::default(),
}))
}

/// Validate an Ethereum transaction already in block
///
/// This function must be called during the pre-dispatch phase
Expand Down
6 changes: 4 additions & 2 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use ethereum::{TransactionAction, TransactionSignature};
use frame_support::{
dispatch::Dispatchable,
parameter_types,
traits::{ConstU32, FindAuthor},
weights::Weight,
Expand Down Expand Up @@ -131,13 +130,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 @@ -169,6 +170,7 @@ impl pallet_evm::Config for Test {
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
type Timestamp = Timestamp;
type WeightInfo = ();
}
Expand Down
1 change: 0 additions & 1 deletion frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ std = [
"environmental?/std",
"evm/std",
"evm/with-serde",
"hex?/std",
"log/std",
"rlp?/std",
"scale-codec/std",
Expand Down
2 changes: 2 additions & 0 deletions frame/evm/precompile/dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ frame-support = { workspace = true }
# Frontier
fp-evm = { workspace = true }
pallet-evm = { workspace = true }
sp-runtime = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }

[dev-dependencies]
scale-codec = { package = "parity-scale-codec", workspace = true }
Expand Down
12 changes: 8 additions & 4 deletions frame/evm/precompile/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ mod mock;
mod tests;

use alloc::format;
use scale_codec::{Decode, DecodeLimit};
use sp_runtime::traits::Dispatchable;
use core::marker::PhantomData;
use fp_evm::{
ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput,
PrecompileResult,
};
use frame_support::{
codec::{Decode, DecodeLimit as _},
dispatch::{DispatchClass, Dispatchable, GetDispatchInfo, Pays, PostDispatchInfo},
dispatch::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo},
traits::{ConstU32, Get},
};
use pallet_evm::{AddressMapping, GasWeightMapping};
Expand Down Expand Up @@ -81,8 +82,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 @@ -153,6 +153,7 @@ impl pallet_evm::Config for Test {
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type GasLimitPovSizeRatio = ();
type GasLimitStorageGrowthRatio = ();
type Timestamp = Timestamp;
type WeightInfo = ();
}
Expand Down Expand Up @@ -183,6 +184,7 @@ impl PrecompileHandle for MockHandle {
&mut self,
_ref_time: Option<u64>,
_proof_size: Option<u64>,
_storage_growth: Option<u64>,
) -> Result<(), ExitError> {
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions frame/evm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ benchmarks! {

let x in 1..10000000;

use frame_benchmarking::vec;
use sp_std::vec;
use rlp::RlpStream;
use sp_core::{H160, U256};

Expand Down Expand Up @@ -71,7 +71,7 @@ benchmarks! {

let caller = "1000000000000000000000000000000000000001".parse::<H160>().unwrap();

let mut nonce: u64 = 1;
let mut nonce: u64 = 0;
let nonce_as_u256: U256 = nonce.into();

let value = U256::default();
Expand All @@ -83,8 +83,8 @@ benchmarks! {
contract_bytecode,
value,
gas_limit_create,
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(nonce_as_u256),
Vec::new(),
is_transactional,
Expand Down Expand Up @@ -120,8 +120,8 @@ benchmarks! {
encoded_call,
value,
gas_limit_call,
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(U256::from(1_000_000_000_000_000u128)),
Some(nonce_as_u256),
Vec::new(),
is_transactional,
Expand Down
Loading