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] Eth RPC integration #5866

Merged
merged 163 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
4f4efcc
Add RPC integration
pgherveou Sep 30, 2024
43a7bf0
Add prdoc
pgherveou Sep 30, 2024
e74852d
Add missing license headers
pgherveou Sep 30, 2024
5b242f8
missing license header
pgherveou Sep 30, 2024
93f25dd
rm unwrap
pgherveou Oct 1, 2024
e4d6543
Add tests
pgherveou Oct 1, 2024
4a9ca42
fix docstr
pgherveou Oct 1, 2024
658f3ac
fix docstring
pgherveou Oct 1, 2024
b75fa99
rm log
pgherveou Oct 2, 2024
c2f4bee
Improve fee checking logic
pgherveou Oct 3, 2024
38fd681
Make tests pass again
pgherveou Oct 4, 2024
e8947bc
fixes
pgherveou Oct 4, 2024
a5f6f75
fixes
pgherveou Oct 4, 2024
2c5242a
Remove unused
pgherveou Oct 4, 2024
8c35821
Rm additional details from prdoc
pgherveou Oct 4, 2024
dd56741
prep kitchensink integration
pgherveou Oct 4, 2024
62ffb24
fix kitchensink
pgherveou Oct 4, 2024
0b5f646
use subxt-signer & eth feature
pgherveou Oct 4, 2024
ad3c0ee
Move rpc stuff to new PR
pgherveou Oct 7, 2024
74ba6dc
Merge branch 'master' into pg/revive-rpc-fixes-v2
athei Oct 7, 2024
5634757
Fixing compilation issues
pgherveou Oct 7, 2024
7f6a356
rustdoc fixes
pgherveou Oct 7, 2024
059f247
Fix doclink
pgherveou Oct 7, 2024
3893465
fix prdoc
pgherveou Oct 7, 2024
8ad166d
fix keyring
pgherveou Oct 7, 2024
766a6c8
fix
pgherveou Oct 7, 2024
2f22e12
add misssing dep
pgherveou Oct 7, 2024
b4fff28
fix lock
pgherveou Oct 7, 2024
f228f16
fix
pgherveou Oct 7, 2024
034420a
fix
pgherveou Oct 7, 2024
14e8eb6
fix
pgherveou Oct 7, 2024
acd95d8
fixes
pgherveou Oct 7, 2024
feaa973
fix tx-pool
pgherveou Oct 7, 2024
ff86aae
Merge branch 'pg/revive-rpc-fixes-v2' of https://github.com/paritytec…
pgherveou Oct 7, 2024
03bc881
fix
pgherveou Oct 7, 2024
ea0d57d
fix
pgherveou Oct 7, 2024
c69817c
tmp fix
pgherveou Oct 7, 2024
b401c60
fix nonce logic
pgherveou Oct 7, 2024
3cd7491
cleanup tests
pgherveou Oct 8, 2024
e93ef66
fix tests
pgherveou Oct 8, 2024
804f402
fix fee dispatch_call
pgherveou Oct 8, 2024
179c2e3
Fix fees
pgherveou Oct 8, 2024
0ac59c2
why not
pgherveou Oct 8, 2024
b9ce758
restore test as they were
pgherveou Oct 8, 2024
3783095
wip
pgherveou Oct 8, 2024
ab8d7db
fix comp issue
pgherveou Oct 8, 2024
741c366
fix
pgherveou Oct 8, 2024
b8840e7
fix test
pgherveou Oct 8, 2024
4b85368
fix rlp encoding
pgherveou Oct 9, 2024
3739e45
wip
pgherveou Oct 10, 2024
46166f8
PR review
pgherveou Oct 10, 2024
2e12a9d
reorg use / mod
pgherveou Oct 10, 2024
4d909c7
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 10, 2024
5100f67
merge fixes
pgherveou Oct 10, 2024
b44294f
fix license
pgherveou Oct 10, 2024
75ca3f9
Add pallet-revive Ethereum JSON-RPC
pgherveou Oct 7, 2024
19dbf4c
wip
pgherveou Oct 7, 2024
595e66a
fixes
pgherveou Oct 7, 2024
96fa31d
wip
pgherveou Oct 8, 2024
551cd3d
update rpc stuff
pgherveou Oct 8, 2024
2a90e9b
rlp encoding
pgherveou Oct 8, 2024
4dede9c
Update
pgherveou Oct 8, 2024
c2609fa
add js stuff
pgherveou Oct 9, 2024
444970b
update yarn.lock
pgherveou Oct 9, 2024
f10cf13
nit
pgherveou Oct 9, 2024
f0e21af
server fixes
pgherveou Oct 9, 2024
205d8ab
fix demo
pgherveou Oct 9, 2024
0011601
undo log
pgherveou Oct 9, 2024
ed4c0d0
wip
pgherveou Oct 9, 2024
de0b0ef
rpc updates
pgherveou Oct 10, 2024
a745fb0
fixes
pgherveou Oct 10, 2024
75d39a6
fix examples
pgherveou Oct 10, 2024
7fea557
fix examples
pgherveou Oct 10, 2024
8c7fc93
clean up
pgherveou Oct 10, 2024
865acc4
fixes
pgherveou Oct 10, 2024
9f6bc42
kitchensink node fixes
pgherveou Oct 10, 2024
e806110
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 10, 2024
c95a99f
Update substrate/frame/transaction-payment/Cargo.toml
pgherveou Oct 10, 2024
a4ca32b
fix cargo
pgherveou Oct 10, 2024
53c72c5
fixes
pgherveou Oct 10, 2024
511842f
fix
pgherveou Oct 10, 2024
c43a520
Add prdoc
pgherveou Oct 10, 2024
f7053f1
Fix lock
pgherveou Oct 10, 2024
a1c0ad1
Add missing licenses
pgherveou Oct 10, 2024
4341122
fix markdown
pgherveou Oct 10, 2024
87a84ed
fix
pgherveou Oct 10, 2024
d3f536b
fixes
pgherveou Oct 10, 2024
87a52d1
fix clippy
pgherveou Oct 10, 2024
ef0b614
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 10, 2024
026453f
fix examples lint
pgherveou Oct 11, 2024
71cc897
fix clippy
pgherveou Oct 11, 2024
0446289
CI fixes
pgherveou Oct 11, 2024
a6bad6d
fix lint
pgherveou Oct 11, 2024
91cb4d5
taplo
pgherveou Oct 11, 2024
2afd66b
use blob_length from cyril's branch
pgherveou Oct 11, 2024
e59e9f2
fix test
pgherveou Oct 11, 2024
f1e612b
make it safe
pgherveou Oct 11, 2024
1a6cbec
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
a82401f
use blob_length
pgherveou Oct 11, 2024
9a0b3c6
fix
pgherveou Oct 11, 2024
26abb73
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
3183d67
Fix tests
pgherveou Oct 11, 2024
9539434
Update generated types
pgherveou Oct 11, 2024
7527e9f
Add eth_syncing
pgherveou Oct 11, 2024
c06133d
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
21ff12c
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 11, 2024
5493d17
Refacor import
pgherveou Oct 11, 2024
222a557
PR review get rid of signed extension
pgherveou Oct 12, 2024
bcd5675
nit
pgherveou Oct 12, 2024
42393f4
fix taplo
pgherveou Oct 12, 2024
e695c13
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 14, 2024
02059a4
Use new polkavm release
pgherveou Oct 15, 2024
e04242b
Fix version
pgherveou Oct 16, 2024
4384b5c
update lock
pgherveou Oct 16, 2024
4be1916
fix bare_eth params
pgherveou Oct 16, 2024
ad463ed
PR review use refactor
pgherveou Oct 17, 2024
abe59ff
Get rid of EthTransactKind
pgherveou Oct 17, 2024
44cd6cc
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 17, 2024
680a83b
rpc rm transact_kind
pgherveou Oct 17, 2024
6b5a956
Get rid codegen in this PR
pgherveou Oct 17, 2024
565a367
Use generic parameter for unchecked extrinsic
pgherveou Oct 17, 2024
39d1fd4
Get rid of ethcontractresultdetails
pgherveou Oct 17, 2024
7bfff66
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
6d91b2e
fix rpc
pgherveou Oct 18, 2024
ab6591e
Add tip
pgherveou Oct 18, 2024
0ec05bf
better log
pgherveou Oct 18, 2024
6eddc80
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
a340467
Fix fees calculuation
pgherveou Oct 18, 2024
dcc72c5
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
87d2bf8
update client
pgherveou Oct 18, 2024
419c4dc
fixes
pgherveou Oct 18, 2024
71a2439
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
b359f32
wip
pgherveou Oct 18, 2024
5894fb5
Fix fee calculation
pgherveou Oct 18, 2024
da1ec2d
actual_fee_no_tip -> actual_fee
pgherveou Oct 18, 2024
c419f71
missing
pgherveou Oct 18, 2024
417fa32
fix bad merge
pgherveou Oct 19, 2024
f35e668
rm rpc
pgherveou Oct 19, 2024
f646c9e
Update substrate/frame/revive/src/primitives.rs
pgherveou Oct 19, 2024
50015cb
gas_limit pr review
pgherveou Oct 19, 2024
2c09850
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 20, 2024
483b638
Update substrate/bin/node/runtime/src/lib.rs
pgherveou Oct 20, 2024
6a58fa5
Add comment on GAS_PRICE constant
pgherveou Oct 20, 2024
13fed3d
rm demo.rs
pgherveou Oct 20, 2024
83c0a38
fix tests
pgherveou Oct 20, 2024
9d06cfe
fix
pgherveou Oct 21, 2024
9e98cbb
simplify
pgherveou Oct 21, 2024
07a6717
Rename things to match #3685
pgherveou Oct 21, 2024
58a6942
typo
pgherveou Oct 21, 2024
d1de70f
fix
pgherveou Oct 21, 2024
e3f3f4b
CI build fixes
pgherveou Oct 21, 2024
f6a94ee
fix clippy
pgherveou Oct 21, 2024
4ecebf8
fix umbrella
pgherveou Oct 21, 2024
be79683
taplo fix
pgherveou Oct 21, 2024
133c776
fix
pgherveou Oct 21, 2024
3ec812e
fix
pgherveou Oct 21, 2024
4c408eb
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 21, 2024
5eff463
fixes
pgherveou Oct 21, 2024
848e4d8
taplo
pgherveou Oct 21, 2024
022a732
Apply suggestions from code review
pgherveou Oct 22, 2024
5261c37
fix prdoc
pgherveou Oct 22, 2024
4378397
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 22, 2024
87f1990
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 22, 2024
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
73 changes: 71 additions & 2 deletions Cargo.lock

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

26 changes: 26 additions & 0 deletions prdoc/pr_5866.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
title: "[pallet-revive] Ethereum JSON-RPC integration"

doc:
- audience: Runtime Dev
description: |
Related PR: https://github.com/paritytech/revive-ethereum-rpc/pull/5

Changes Included:
- A new pallet::call eth_transact.
- A custom UncheckedExtrinsic struct to dispatch unsigned eth_transact calls from an Ethereum JSON-RPC proxy.
- Generated types and traits to support implementing a JSON-RPC Ethereum proxy.

Flow Overview:
- A user submits a transaction via MetaMask or another Ethereum-compatible wallet.
- The proxy dry run the transaction and add metadata to the call ( gas limit in Weight, Storage deposit limit, bytecode and constructor length for contract instantiation)
- The raw transaction, along with the additional metadata, is submitted to the node as an unsigned extrinsic.
- On the node, the custom UncheckedExtrinsic struct has a custom Checkable implementation that converts the unsigned extrinsics into checked ones
- It recovers the signer
- validates the payload, and injects default signed extensions, allowing the system to increment the nonce and charge the appropriate fees.
- re-route the call to pallet-revive::Call::call or pallet-revive::Call::instantiateWithCode
crates:
- name: pallet-revive
bump: patch
- name: polkadot-sdk
bump: patch

28 changes: 26 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3005,14 +3005,38 @@ impl_runtime_apis! {

impl pallet_revive::ReviveApi<Block, AccountId, Balance, BlockNumber, EventRecord> for Runtime
{
fn eth_transact(
from: H160,
dest: Option<H160>,
value: Balance,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::ContractResult<pallet_revive::EthTransactReturnValue, Balance, EventRecord>
{
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_contract(&from);
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
Revive::bare_eth_transact(
RuntimeOrigin::signed(origin),
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

fn call(
origin: AccountId,
dest: H160,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_revive::ContractExecResult<Balance, EventRecord> {
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
Expand All @@ -3033,7 +3057,7 @@ impl_runtime_apis! {
code: pallet_revive::Code,
data: Vec<u8>,
salt: Option<[u8; 32]>,
) -> pallet_revive::ContractInstantiateResult<Balance, EventRecord>
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
{
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
Expand Down
24 changes: 21 additions & 3 deletions substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ codec = { features = [
], workspace = true }
scale-info = { features = ["derive"], workspace = true }
log = { workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
serde = { features = ["alloc", "derive"], workspace = true, default-features = false }
impl-trait-for-tuples = { workspace = true }
rlp = { workspace = true }
derive_more.workspace = true
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
hex = { workspace = true }
jsonrpsee = { workspace = true, features = ["full"], optional = true }
ethereum-types = { workspace = true, features = ["codec", "rlp", "serialize"] }

# Polkadot SDK Dependencies
frame-benchmarking = { optional = true, workspace = true }
Expand All @@ -39,19 +43,21 @@ pallet-balances = { optional = true, workspace = true }
pallet-revive-fixtures = { workspace = true, default-features = false }
pallet-revive-uapi = { workspace = true, default-features = true }
pallet-revive-proc-macro = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-weights = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }

[dev-dependencies]
array-bytes = { workspace = true, default-features = true }
assert_matches = { workspace = true }
pretty_assertions = { workspace = true }
wat = { workspace = true }
pallet-revive-fixtures = { workspace = true, default-features = true }

# Polkadot SDK Dependencies
Expand All @@ -64,6 +70,9 @@ pallet-proxy = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
xcm-builder = { workspace = true, default-features = true }
secp256k1 = { workspace = true, features = ["recovery"] }
serde_json.workspace = true
hex-literal.workspace = true

[features]
default = ["std"]
Expand All @@ -77,6 +86,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"jsonrpsee",
"log/std",
"pallet-balances?/std",
"pallet-proxy/std",
Expand All @@ -86,13 +96,20 @@ std = [
"polkavm/std",
"rlp/std",
"scale-info/std",
"serde",
"ethereum-types/std",
"hex/std",
"pallet-transaction-payment/std",
"secp256k1/std",
"serde/std",
"serde_json/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime/std",
"sp-std/std",
"sp-weights/std",
"xcm-builder/std",
"xcm/std",
]
Expand All @@ -117,6 +134,7 @@ try-runtime = [
"pallet-message-queue/try-runtime",
"pallet-proxy/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"sp-runtime/try-runtime",
]
4 changes: 3 additions & 1 deletion substrate/frame/revive/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Functions that deal contract addresses.

use crate::LOG_TARGET;
use alloc::vec::Vec;
use sp_core::H160;
use sp_io::hashing::keccak_256;
Expand All @@ -34,7 +35,7 @@ use sp_runtime::AccountId32;
/// case for all existing runtimes as of right now. Reasing is that this will allow
/// us to reverse an address -> account_id mapping by just stripping the prefix.
pub trait AddressMapper<T>: private::Sealed {
/// Convert an account id to an ethereum adress.
/// Convert an account id to an ethereum address.
///
/// This mapping is **not** required to be reversible.
fn to_address(account_id: &T) -> H160;
Expand Down Expand Up @@ -77,6 +78,7 @@ impl AddressMapper<AccountId32> for DefaultAddressMapper {

/// Determine the address of a contract using CREATE semantics.
pub fn create1(deployer: &H160, nonce: u64) -> H160 {
log::debug!(target: LOG_TARGET, "create1: deployer={deployer:?}, nonce={nonce}");
let mut list = rlp::RlpStream::new_list(2);
list.append(&deployer.as_bytes());
list.append(&nonce);
Expand Down
6 changes: 6 additions & 0 deletions substrate/frame/revive/src/evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//!Types, and traits to integrate pallet-revive with EVM.
#![warn(missing_docs)]

mod api;
pub use api::*;
pub mod runtime;
Loading
Loading