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

[pallet-revive] Add evm codegen #5926

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ members = [
"substrate/frame/revive/mock-network",
"substrate/frame/revive/proc-macro",
"substrate/frame/revive/rpc",
"substrate/frame/revive/rpc/codegen",
"substrate/frame/revive/uapi",
"substrate/frame/root-offences",
"substrate/frame/root-testing",
Expand Down
30 changes: 8 additions & 22 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: alloc::borrow::Cow::Borrowed("westmint"),
impl_name: alloc::borrow::Cow::Borrowed("westmint"),
authoring_version: 1,
spec_version: 1_016_006,
spec_version: 1_016_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 16,
Expand Down Expand Up @@ -2088,18 +2088,10 @@ impl_runtime_apis! {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
System::account_nonce(account)
}
fn eth_transact(
from: H160,
dest: Option<H160>,
value: U256,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::EthContractResult<Balance>

fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
{
use pallet_revive::AddressMapper;
let blockweights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();

let encoded_size = |pallet_call| {
let call = RuntimeCall::Revive(pallet_call);
Expand All @@ -2108,15 +2100,9 @@ impl_runtime_apis! {
};

Revive::bare_eth_transact(
origin,
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
tx,
blockweights.max_block,
encoded_size,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -2134,7 +2120,7 @@ impl_runtime_apis! {
dest,
value,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
Expand All @@ -2156,7 +2142,7 @@ impl_runtime_apis! {
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
code,
data,
salt,
Expand Down
13 changes: 13 additions & 0 deletions prdoc/pr_5926.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "[pallet-revive] add codegen for Ethereum RPC API"

doc:
- audience: Runtime Dev
description: |
Add codegen crate for generating Ethereum RPC methods and types from the spec.

crates:
- name: pallet-revive-rpc-codegen
bump: patch
25 changes: 5 additions & 20 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3218,18 +3218,9 @@ impl_runtime_apis! {
System::account_nonce(account)
}

fn eth_transact(
from: H160,
dest: Option<H160>,
value: U256,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::EthContractResult<Balance>
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
{
use pallet_revive::AddressMapper;
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);

let encoded_size = |pallet_call| {
let call = RuntimeCall::Revive(pallet_call);
Expand All @@ -3238,15 +3229,9 @@ impl_runtime_apis! {
};

Revive::bare_eth_transact(
origin,
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
tx,
blockweights.max_block,
encoded_size,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -3263,7 +3248,7 @@ impl_runtime_apis! {
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
Expand All @@ -3284,7 +3269,7 @@ impl_runtime_apis! {
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
code,
data,
salt,
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pallet-revive-fixtures = { workspace = true, default-features = true }
secp256k1 = { workspace = true, features = ["recovery"] }
serde_json = { workspace = true }
hex-literal = { workspace = true }
env_logger = { workspace = true }

# Polkadot SDK Dependencies
pallet-balances = { workspace = true, default-features = true }
Expand Down
18 changes: 18 additions & 0 deletions substrate/frame/revive/rpc/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "pallet-revive-rpc-codegen"
version = "0.1.0"
edition.workspace = true
publish = false

[dependencies]
Inflector = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
anyhow = { workspace = true }

[dev-dependencies]
pretty_assertions.workspace = true

[features]
default = ["std"]
std = ["anyhow/std", "serde/std", "serde_json/std"]
5 changes: 5 additions & 0 deletions substrate/frame/revive/rpc/codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Generates the Ethereum JSON-RPC API from the official specification.

- See <https://github.com/ethereum/execution-apis>
- See building instructions to re-generate the openrpc.json <https://github.com/ethereum/execution-apis?tab=readme-ov-file#building>
- Include fixes from <https://github.com/ethereum/execution-apis/pull/552>
Loading
Loading