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

EVM + Weight v2 support #1039

Merged
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4bab80e
wip `record_extarnal_cost`
tgmichel Apr 11, 2023
416d618
Add support for external cost recording from the EVM
tgmichel Apr 13, 2023
24c91b5
Add refund external cost support
tgmichel Apr 14, 2023
3dff83e
Separate dispatchables with weight limit
tgmichel Apr 17, 2023
3ace0af
introduce tbd EthereumWeigher
tgmichel Apr 17, 2023
6deaacb
Validate gas to weight conversion
tgmichel Apr 19, 2023
74708f5
Add static opcode recording with temp costs
tgmichel Apr 20, 2023
8ea977b
Add optional `transaction_len` parameter to `GasWeightMapping`
tgmichel Apr 20, 2023
dc95f98
Account for pallet and call indexes
tgmichel Apr 20, 2023
ac5ed2d
Rollback `transaction_len` param, use MAX_POV_SIZE ratio instead
tgmichel Apr 21, 2023
45c9e25
wip tests
tgmichel Apr 25, 2023
dc33686
Add `uncached_account_code_proof_size_accounting_works` test
tgmichel Apr 26, 2023
312146f
wip tests
tgmichel Apr 26, 2023
88c7c7c
Temp remove static external cost accounting
tgmichel Apr 27, 2023
163b0c5
fix build
tgmichel Apr 27, 2023
a17e331
Temp remove static external cost accounting 2
tgmichel Apr 27, 2023
8cc4568
warning cleanup
tgmichel Apr 27, 2023
3646639
fmt
tgmichel Apr 27, 2023
87e5f6f
clippy
tgmichel Apr 27, 2023
cc4e173
taplo
tgmichel Apr 27, 2023
eb2afed
Add `evm-with-weight-limit` to ci
tgmichel Apr 27, 2023
7814419
Temp set evm fork + update Cargo.lock
tgmichel Apr 27, 2023
255f663
Merge branch 'master' into tgm-record-external-costs
tgmichel Apr 27, 2023
00ffebc
handle `code_hash`
tgmichel Apr 27, 2023
5ab6432
taplo
tgmichel Apr 27, 2023
4bb5e70
fmt
tgmichel Apr 27, 2023
538c072
Handle `transact_with_weight_limit` as self contained
tgmichel Apr 28, 2023
7686543
fix ts tests
tgmichel Apr 28, 2023
e12afd7
suggestion
tgmichel Apr 28, 2023
cd77d2d
remove precompile test
tgmichel Apr 28, 2023
91ce2ed
some suggestions
tgmichel Apr 28, 2023
d6d7a00
remove `transact_with_weight_limit`
tgmichel Apr 28, 2023
83e228a
configurable `MaxPovSize`
tgmichel May 3, 2023
c369476
test pov size constants
tgmichel May 3, 2023
296cb2a
accessed storage overlayed cache
tgmichel May 4, 2023
c8138af
`new_from_weight_limit` suggestion
tgmichel May 4, 2023
34be73b
remove unnecessary check
tgmichel May 4, 2023
44c93c0
warnings cleanup
tgmichel May 5, 2023
17abbd3
set constant gas limit max pov size ratio
tgmichel May 5, 2023
3572aad
check state version for suicide
tgmichel May 5, 2023
4bbbe3d
just completely remove suicide accounting
tgmichel May 5, 2023
bd734b1
- `code` must be able to oog
tgmichel May 11, 2023
0a22130
Merge branch 'master' into tgm-record-external-costs
tgmichel May 12, 2023
1a1a47f
`is_empty` accounting
tgmichel May 12, 2023
a63f1d2
fix build
tgmichel May 12, 2023
e59eb9c
`SSTORE` must record account storage proof size
tgmichel May 12, 2023
91a5259
suggestion: move weight_limit checks
tgmichel May 16, 2023
3915652
editorconfig
tgmichel May 16, 2023
d09fc5b
fmt
tgmichel May 16, 2023
e9df020
rename `transaction_len` to `proof_size_base_cost` in runner
tgmichel May 16, 2023
a8fd45e
move `proof_size_base_cost` to validation primitive
tgmichel May 16, 2023
caefbec
gas limit saturated conversion
tgmichel May 24, 2023
df032b5
remove transaction proof size check outside validation
tgmichel May 24, 2023
e53da69
Merge branch 'master' into tgm-record-external-costs
tgmichel May 25, 2023
76c2f6c
pin evm
tgmichel May 25, 2023
6f6827a
pin evm+
tgmichel May 25, 2023
0154cc9
fix todos
tgmichel May 25, 2023
881f690
fix build
tgmichel May 25, 2023
eddef23
scope of already recorded codes and storages must be per transaction
tgmichel Jun 9, 2023
d6d4765
pin evm + implement new `record_external_operation`
tgmichel Jun 14, 2023
12fbeee
fix runtime api versioning + legacy `ExecutionInfo` handling
tgmichel Jun 19, 2023
8a968e9
Merge branch 'master' into tgm-record-external-costs
tgmichel Jun 19, 2023
da32bba
editorconfig
tgmichel Jun 19, 2023
5ba5fcc
cargo fmt
tgmichel Jun 19, 2023
6d3bfb3
clippy
tgmichel Jun 19, 2023
ebd1486
suggestion remove `evm-with-weight-limit` feature
tgmichel Jun 21, 2023
7198ca4
fmt
tgmichel Jun 21, 2023
d95b7ed
update comment
tgmichel Jun 21, 2023
d9f12de
update tests for additional `AccountBasicRead` in the evm
tgmichel Jun 21, 2023
074711b
update evm pin
tgmichel Jun 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
14 changes: 5 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bn = { package = "substrate-bn", version = "0.6", default-features = false }
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.39.0", default-features = false }
evm = { git = "https://github.com/purestake/evm", branch = "tgm-record-external-cost", default-features = false }
tgmichel marked this conversation as resolved.
Show resolved Hide resolved
hex-literal = { version = "0.3.4" }
impl-serde = { version = "0.4.0", default-features = false }
jsonrpsee = "0.16.2"
Expand Down
185 changes: 149 additions & 36 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sp_runtime::{traits::Block as BlockT, DispatchError, SaturatedConversion};
use sp_state_machine::OverlayedChanges;
// Frontier
use fc_rpc_core::types::*;
use fp_evm::CallInfo;
use fp_evm::{ExecutionInfo, ExecutionInfoV2};
use fp_rpc::{EthereumRuntimeRPCApi, RuntimeStorageOverride};
use fp_storage::{EVM_ACCOUNT_CODES, PALLET_EVM};

Expand Down Expand Up @@ -210,7 +210,7 @@ where

error_on_execution_failure(&info.exit_reason, &info.value)?;
Ok(Bytes(info.value))
} else if api_version == 4 {
} else if api_version == 4 || api_version == 5 {
// Post-london + access list support
let encoded_params = Encode::encode(&(
&from.unwrap_or_default(),
Expand Down Expand Up @@ -247,23 +247,47 @@ where
recorder: &None,
};

let info = self
.client
.call_api_at(params)
.and_then(|r| {
Result::map_err(
<Result<CallInfo, DispatchError> as Decode>::decode(&mut &r[..]),
|error| sp_api::ApiError::FailedToDecodeReturnValue {
function: "EthereumRuntimeRPCApi_call",
error,
},
)
})
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
let value = if api_version == 4 {
let info = self
.client
.call_api_at(params)
.and_then(|r| {
Result::map_err(
<Result<ExecutionInfo::<Vec<u8>>, DispatchError> as Decode>::decode(&mut &r[..]),
|error| sp_api::ApiError::FailedToDecodeReturnValue {
function: "EthereumRuntimeRPCApi_call",
error,
},
)
})
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

error_on_execution_failure(&info.exit_reason, &info.value)?;
Ok(Bytes(info.value))
error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else if api_version == 5 {
let info = self
.client
.call_api_at(params)
.and_then(|r| {
Result::map_err(
<Result<ExecutionInfoV2::<Vec<u8>>, DispatchError> as Decode>::decode(&mut &r[..]),
|error| sp_api::ApiError::FailedToDecodeReturnValue {
function: "EthereumRuntimeRPCApi_call",
error,
},
)
})
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else {
unreachable!("invalid version");
};

Ok(Bytes(value))
} else {
Err(internal_err("failed to retrieve Runtime Api version"))
}
Expand Down Expand Up @@ -315,6 +339,36 @@ where
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
Ok(Bytes(code))
} else if api_version == 4 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
#[allow(deprecated)]
let info = api.create_before_version_5(
substrate_hash,
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
false,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

error_on_execution_failure(&info.exit_reason, &[])?;

let code = api
.account_code_at(substrate_hash, info.value)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
Ok(Bytes(code))
} else if api_version == 5 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
let info = api
Expand Down Expand Up @@ -515,10 +569,10 @@ where

let (exit_reason, data, used_gas) = match to {
Some(to) => {
let info = if api_version == 1 {
if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
api.call_before_version_2(
let info = api.call_before_version_2(
substrate_hash,
from.unwrap_or_default(),
to,
Expand All @@ -530,11 +584,33 @@ where
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, info.value, info.used_gas)
} else if api_version < 4 {
// Post-london
#[allow(deprecated)]
api.call_before_version_4(
let info = api.call_before_version_4(
substrate_hash,
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, info.value, info.used_gas)
} else if api_version == 4 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
#[allow(deprecated)]
let info = api.call_before_version_5(
substrate_hash,
from.unwrap_or_default(),
to,
Expand All @@ -545,13 +621,21 @@ where
max_priority_fee_per_gas,
nonce,
estimate_mode,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, info.value, info.used_gas)
} else {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
api.call(
let info = api.call(
substrate_hash,
from.unwrap_or_default(),
to,
Expand All @@ -570,16 +654,16 @@ where
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
};
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, info.value, info.used_gas)
(info.exit_reason, info.value, info.used_gas.effective)
}
}
None => {
let info = if api_version == 1 {
if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
api.create_before_version_2(
let info = api.create_before_version_2(
substrate_hash,
from.unwrap_or_default(),
data,
Expand All @@ -590,11 +674,13 @@ where
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, Vec::new(), info.used_gas)
} else if api_version < 4 {
// Post-london
#[allow(deprecated)]
api.create_before_version_4(
let info = api.create_before_version_4(
substrate_hash,
from.unwrap_or_default(),
data,
Expand All @@ -606,11 +692,38 @@ where
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, Vec::new(), info.used_gas)
} else if api_version == 4 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
#[allow(deprecated)]
let info = api.create_before_version_5(
substrate_hash,
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, Vec::new(), info.used_gas)
} else {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
api.create(
let info = api.create(
substrate_hash,
from.unwrap_or_default(),
data,
Expand All @@ -628,10 +741,10 @@ where
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
};
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;

(info.exit_reason, Vec::new(), info.used_gas)
(info.exit_reason, Vec::new(), info.used_gas.effective)
}
}
};
Ok(ExecutableResult {
Expand Down
Loading