Skip to content

Commit

Permalink
Optional evm rpc (#833)
Browse files Browse the repository at this point in the history
* Disable EVM RPC by default, add CLI flag to enable it

* Enable EVM RPC for local/dev mode by default

* Added clap attribute to flag

* Bump version

* Enable EVM RPC on zombienet configs
  • Loading branch information
akru authored Jan 23, 2023
1 parent 71eb5b7 commit 8e40a2c
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 18 deletions.
10 changes: 5 additions & 5 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 bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "4.44.0"
version = "4.45.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
description = "Astar collator implementation in Rust."
build = "build.rs"
Expand Down
4 changes: 4 additions & 0 deletions bin/collator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub struct Cli {
#[clap(flatten)]
pub run: cumulus_client_cli::RunCmd,

/// Enable Ethereum compatible JSON-RPC servers (disabled by default).
#[clap(name = "enable-evm-rpc")]
pub enable_evm_rpc: bool,

/// Relaychain arguments
#[clap(raw = true)]
pub relaychain_args: Vec<String>,
Expand Down
6 changes: 3 additions & 3 deletions bin/collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,17 +701,17 @@ pub fn run() -> Result<()> {
);

if config.chain_spec.is_astar() {
start_astar_node(config, polkadot_config, collator_options, para_id)
start_astar_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_shiden() {
start_shiden_node(config, polkadot_config, collator_options, para_id)
start_shiden_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_shibuya() {
start_shibuya_node(config, polkadot_config, collator_options, para_id)
start_shibuya_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc)
.await
.map(|r| r.0)
.map_err(Into::into)
Expand Down
1 change: 1 addition & 0 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
fee_history_cache: fee_history_cache.clone(),
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc: true, // enable EVM RPC for dev node by default
};

crate::rpc::create_full(deps, subscription).map_err::<ServiceError, _>(Into::into)
Expand Down
8 changes: 8 additions & 0 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ async fn start_node_impl<RuntimeApi, Executor, BIQ, BIC>(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
enable_evm_rpc: bool,
build_import_queue: BIQ,
build_consensus: BIC,
) -> sc_service::error::Result<(
Expand Down Expand Up @@ -484,6 +485,7 @@ where
fee_history_cache: fee_history_cache.clone(),
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
enable_evm_rpc,
};

crate::rpc::create_full(deps, subscription).map_err(Into::into)
Expand Down Expand Up @@ -657,6 +659,7 @@ pub async fn start_astar_node(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
enable_evm_rpc: bool,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<Block, astar::RuntimeApi, NativeElseWasmExecutor<astar::Executor>>>,
Expand All @@ -666,6 +669,7 @@ pub async fn start_astar_node(
polkadot_config,
collator_options,
id,
enable_evm_rpc,
|client,
block_import,
config,
Expand Down Expand Up @@ -785,6 +789,7 @@ pub async fn start_shiden_node(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
enable_evm_rpc: bool,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<Block, shiden::RuntimeApi, NativeElseWasmExecutor<shiden::Executor>>>,
Expand All @@ -794,6 +799,7 @@ pub async fn start_shiden_node(
polkadot_config,
collator_options,
id,
enable_evm_rpc,
|client,
block_import,
config,
Expand Down Expand Up @@ -913,6 +919,7 @@ pub async fn start_shibuya_node(
polkadot_config: Configuration,
collator_options: CollatorOptions,
id: ParaId,
enable_evm_rpc: bool,
) -> sc_service::error::Result<(
TaskManager,
Arc<TFullClient<Block, shibuya::RuntimeApi, NativeElseWasmExecutor<shibuya::Executor>>>,
Expand All @@ -922,6 +929,7 @@ pub async fn start_shibuya_node(
polkadot_config,
collator_options,
id,
enable_evm_rpc,
|client,
block_import,
config,
Expand Down
10 changes: 8 additions & 2 deletions bin/collator/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub struct FullDeps<C, P, A: ChainApi> {
pub overrides: Arc<OverrideHandle<Block>>,
/// Cache for Ethereum block data.
pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
/// Enable EVM RPC servers
pub enable_evm_rpc: bool,
}

/// Instantiate all RPC extensions.
Expand Down Expand Up @@ -175,10 +177,16 @@ where
fee_history_cache,
overrides,
block_data_cache,
enable_evm_rpc,
} = deps;

io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
io.merge(sc_rpc::dev::Dev::new(client.clone(), deny_unsafe).into_rpc())?;

if !enable_evm_rpc {
return Ok(io);
}

let no_tx_converter: Option<fp_rpc::NoTransactionConverter> = None;

Expand Down Expand Up @@ -220,8 +228,6 @@ where

io.merge(Web3::new(client.clone()).into_rpc())?;

io.merge(sc_rpc::dev::Dev::new(client.clone(), deny_unsafe).into_rpc())?;

io.merge(
EthPubSub::new(pool, client, network, subscription_task_executor, overrides).into_rpc(),
)?;
Expand Down
2 changes: 1 addition & 1 deletion runtime/astar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-runtime"
version = "4.44.0"
version = "4.45.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "local-runtime"
version = "4.44.0"
version = "4.45.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shibuya-runtime"
version = "4.44.0"
version = "4.45.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
edition = "2021"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/shiden/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shiden-runtime"
version = "4.44.0"
version = "4.45.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
edition = "2021"
build = "build.rs"
Expand Down
4 changes: 2 additions & 2 deletions third-party/zombienet/multi_parachains.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cumulus_based = true
name = "collator1"
command = "./astar-collator"
rpc_port = 8545
args = [ "-l=xcm=trace" ]
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]

# For this one you can download or build some other para and run it.
# In this example, `astar-collator` is reused but `shiden-dev` chain is used
Expand All @@ -47,7 +47,7 @@ cumulus_based = true
[[parachains.collators]]
name = "collator2"
command = "./astar-collator"
args = [ "-l=xcm=trace" ]
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]

[[hrmp_channels]]
sender = 2000
Expand Down
3 changes: 2 additions & 1 deletion third-party/zombienet/single_parachain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ cumulus_based = true
[[parachains.collators]]
name = "collator1"
command = "./astar-collator"
args = [ "-l=xcm=trace" ]
args = [ "-l=xcm=trace", "--enable-evm-rpc" ]


[[parachains.collators]]
name = "collator2"
command = "./astar-collator"
args = [ "--enable-evm-rpc" ]

0 comments on commit 8e40a2c

Please sign in to comment.