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 Ethereum JSON-RPC server #5953

Open
wants to merge 44 commits into
base: pg/revive-rpc-fixes-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
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
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
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
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
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
26abb73
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
3183d67
Fix tests
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
e695c13
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 14, 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
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
157 changes: 156 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ members = [
"substrate/frame/revive/fixtures",
"substrate/frame/revive/mock-network",
"substrate/frame/revive/proc-macro",
"substrate/frame/revive/rpc",
"substrate/frame/revive/uapi",
"substrate/frame/root-offences",
"substrate/frame/root-testing",
Expand Down Expand Up @@ -958,6 +959,7 @@ pallet-recovery = { path = "substrate/frame/recovery", default-features = false
pallet-referenda = { path = "substrate/frame/referenda", default-features = false }
pallet-remark = { default-features = false, path = "substrate/frame/remark" }
pallet-revive = { path = "substrate/frame/revive", default-features = false }
pallet-revive-eth-rpc = { path = "substrate/frame/revive/rpc", default-features = false }
pallet-revive-fixtures = { path = "substrate/frame/revive/fixtures", default-features = false }
pallet-revive-mock-network = { default-features = false, path = "substrate/frame/revive/mock-network" }
pallet-revive-proc-macro = { path = "substrate/frame/revive/proc-macro", default-features = false }
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_5953.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: "[pallet-revive] Ethereum JSON-RPC"

doc:
- audience: Runtime Dev
description: |
Add a new Ethereum JSON-RPC server that can be used a substrate chain configured with pallet-revive
crates:
- name: pallet-revive-eth-rpc
bump: patch
- name: pallet-revive-fixtures
bump: patch
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ std = [
"serde_json/std",
"sp-debug-derive/std",
"substrate-wasm-builder",
"sp-debug-derive/std"
]
runtime-benchmarks = [
"pallet-example-mbm/runtime-benchmarks",
Expand Down
9 changes: 7 additions & 2 deletions substrate/frame/revive/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ mod build {
}

/// Collect all contract entries from the given source directory.
/// Contracts that have already been compiled are filtered out.
fn collect_entries(contracts_dir: &Path) -> Vec<Entry> {
fs::read_dir(contracts_dir)
.expect("src dir exists; qed")
Expand Down Expand Up @@ -184,7 +183,13 @@ mod build {
let fixtures_dir: PathBuf = env::var("CARGO_MANIFEST_DIR")?.into();
let contracts_dir = fixtures_dir.join("contracts");
let uapi_dir = fixtures_dir.parent().expect("uapi dir exits; qed").join("uapi");
let out_dir: PathBuf = env::var("OUT_DIR")?.into();
let ws_dir: PathBuf = env::var("CARGO_WORKSPACE_ROOT_DIR")?.into();
let out_dir: PathBuf = ws_dir.join("target").join("pallet-revive-fixtures");

// create out_dir if it does not exist
if !out_dir.exists() {
fs::create_dir_all(&out_dir)?;
}

// the fixtures have a dependency on the uapi crate
println!("cargo::rerun-if-changed={}", fixtures_dir.display());
Expand Down
36 changes: 36 additions & 0 deletions substrate/frame/revive/fixtures/contracts/demo.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a better name than just "demo". Maybe "rpc_demo".

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// 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.

#![no_std]
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {
input!(128, data: [u8],);
api::deposit_event(&[], data);
}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
input!(128, data: [u8],);
api::deposit_event(&[], data);
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert the selector here? ether.js should derive a selector from the provided ABI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right yes it does, might be easier to add the assert in the js code directly, since that's where we define the "fake ABI"

}
24 changes: 12 additions & 12 deletions substrate/frame/revive/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ extern crate alloc;
/// Load a given wasm module and returns a wasm binary contents along with it's hash.
#[cfg(feature = "std")]
pub fn compile_module(fixture_name: &str) -> anyhow::Result<(Vec<u8>, sp_core::H256)> {
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
use anyhow::Context;
use std::{env, path::PathBuf};
let ws_dir: PathBuf = env::var("CARGO_WORKSPACE_ROOT_DIR")?.into();
let out_dir: PathBuf = ws_dir.join("target").join("pallet-revive-fixtures");
let fixture_path = out_dir.join(format!("{fixture_name}.polkavm"));
log::debug!("Loading fixture from {fixture_path:?}");
let binary = std::fs::read(fixture_path)?;
let binary = std::fs::read(fixture_path.clone())
.with_context(|| format!("fixture not found {fixture_path:?}"))?;
let code_hash = sp_io::hashing::keccak_256(&binary);
Ok((binary, sp_core::H256(code_hash)))
}
Expand All @@ -40,7 +44,12 @@ pub mod bench {
#[cfg(feature = "riscv")]
macro_rules! fixture {
($name: literal) => {
include_bytes!(concat!(env!("OUT_DIR"), "/", $name, ".polkavm"))
include_bytes!(concat!(
env!("CARGO_WORKSPACE_ROOT_DIR"),
"target/pallet-revive-fixtures/",
$name,
".polkavm"
))
};
}
#[cfg(not(feature = "riscv"))]
Expand All @@ -63,12 +72,3 @@ pub mod bench {
dummy
}
}

#[cfg(test)]
mod test {
#[test]
fn out_dir_should_have_compiled_mocks() {
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
assert!(out_dir.join("dummy.polkavm").exists());
}
}
Loading
Loading