-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pallet-revive] eth-rpc minor fixes (#7325)
- Add option to specify database_url using DATABASE_URL environment variable - Add a eth-rpc-tester rust bin that can be used to test deployment before releasing eth-rpc - make evm_block non fallible so that it can return an Ok response for older blocks when the runtime API is not available - update cargo.lock to integrate changes from paritytech/subxt#1904 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ccd6337
commit 223bd28
Showing
10 changed files
with
198 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
title: '[pallet-revive] eth-rpc minor fixes' | ||
doc: | ||
- audience: Runtime Dev | ||
description: |- | ||
- Add option to specify database_url from an environment variable | ||
- Add a test-deployment.rs rust script that can be used to test deployment and call of a contract before releasing eth-rpc | ||
- Make evm_block non fallible so that it can return an Ok response for older blocks when the runtime API is not available | ||
- Update subxt version to integrate changes from https://github.com/paritytech/subxt/pull/1904 | ||
crates: | ||
- name: pallet-revive-eth-rpc | ||
bump: minor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// 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. | ||
use clap::Parser; | ||
use jsonrpsee::http_client::HttpClientBuilder; | ||
use pallet_revive::evm::{Account, BlockTag, ReceiptInfo}; | ||
use pallet_revive_eth_rpc::{ | ||
example::{wait_for_receipt, TransactionBuilder}, | ||
EthRpcClient, | ||
}; | ||
use tokio::{ | ||
io::{AsyncBufReadExt, BufReader}, | ||
process::{Child, ChildStderr, Command}, | ||
signal::unix::{signal, SignalKind}, | ||
}; | ||
|
||
const DOCKER_CONTAINER_NAME: &str = "eth-rpc-test"; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, about, version)] | ||
pub struct CliCommand { | ||
/// The parity docker image e.g eth-rpc:master-fb2e414f | ||
#[clap(long, default_value = "eth-rpc:master-fb2e414f")] | ||
docker_image: String, | ||
|
||
/// The docker binary | ||
/// Either docker or podman | ||
#[clap(long, default_value = "docker")] | ||
docker_bin: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let CliCommand { docker_bin, docker_image, .. } = CliCommand::parse(); | ||
|
||
let mut docker_process = start_docker(&docker_bin, &docker_image)?; | ||
let stderr = docker_process.stderr.take().unwrap(); | ||
|
||
tokio::select! { | ||
result = docker_process.wait() => { | ||
println!("docker failed: {result:?}"); | ||
} | ||
_ = interrupt() => { | ||
kill_docker().await?; | ||
} | ||
_ = test_eth_rpc(stderr) => { | ||
kill_docker().await?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn interrupt() { | ||
let mut sigint = signal(SignalKind::interrupt()).expect("failed to listen for SIGINT"); | ||
let mut sigterm = signal(SignalKind::terminate()).expect("failed to listen for SIGTERM"); | ||
|
||
tokio::select! { | ||
_ = sigint.recv() => {}, | ||
_ = sigterm.recv() => {}, | ||
} | ||
} | ||
|
||
fn start_docker(docker_bin: &str, docker_image: &str) -> anyhow::Result<Child> { | ||
let docker_process = Command::new(docker_bin) | ||
.args([ | ||
"run", | ||
"--name", | ||
DOCKER_CONTAINER_NAME, | ||
"--rm", | ||
"-p", | ||
"8545:8545", | ||
&format!("docker.io/paritypr/{docker_image}"), | ||
"--node-rpc-url", | ||
"wss://westend-asset-hub-rpc.polkadot.io", | ||
"--rpc-cors", | ||
"all", | ||
"--unsafe-rpc-external", | ||
"--log=sc_rpc_server:info", | ||
]) | ||
.stderr(std::process::Stdio::piped()) | ||
.kill_on_drop(true) | ||
.spawn()?; | ||
|
||
Ok(docker_process) | ||
} | ||
|
||
async fn kill_docker() -> anyhow::Result<()> { | ||
Command::new("docker").args(["kill", DOCKER_CONTAINER_NAME]).output().await?; | ||
Ok(()) | ||
} | ||
|
||
async fn test_eth_rpc(stderr: ChildStderr) -> anyhow::Result<()> { | ||
let mut reader = BufReader::new(stderr).lines(); | ||
while let Some(line) = reader.next_line().await? { | ||
println!("{line}"); | ||
if line.contains("Running JSON-RPC server") { | ||
break; | ||
} | ||
} | ||
|
||
let account = Account::default(); | ||
let data = vec![]; | ||
let (bytes, _) = pallet_revive_fixtures::compile_module("dummy")?; | ||
let input = bytes.into_iter().chain(data).collect::<Vec<u8>>(); | ||
|
||
println!("Account:"); | ||
println!("- address: {:?}", account.address()); | ||
let client = HttpClientBuilder::default().build("http://localhost:8545")?; | ||
|
||
let nonce = client.get_transaction_count(account.address(), BlockTag::Latest.into()).await?; | ||
let balance = client.get_balance(account.address(), BlockTag::Latest.into()).await?; | ||
println!("- nonce: {nonce:?}"); | ||
println!("- balance: {balance:?}"); | ||
|
||
println!("\n\n=== Deploying dummy contract ===\n\n"); | ||
let hash = TransactionBuilder::default().input(input).send(&client).await?; | ||
|
||
println!("Hash: {hash:?}"); | ||
println!("Waiting for receipt..."); | ||
let ReceiptInfo { block_number, gas_used, contract_address, .. } = | ||
wait_for_receipt(&client, hash).await?; | ||
|
||
let contract_address = contract_address.unwrap(); | ||
println!("\nReceipt:"); | ||
println!("Block explorer: https://westend-asset-hub-eth-explorer.parity.io/{hash:?}"); | ||
println!("- Block number: {block_number}"); | ||
println!("- Gas used: {gas_used}"); | ||
println!("- Address: {contract_address:?}"); | ||
|
||
println!("\n\n=== Calling dummy contract ===\n\n"); | ||
let hash = TransactionBuilder::default().to(contract_address).send(&client).await?; | ||
|
||
println!("Hash: {hash:?}"); | ||
println!("Waiting for receipt..."); | ||
|
||
let ReceiptInfo { block_number, gas_used, to, .. } = wait_for_receipt(&client, hash).await?; | ||
println!("\nReceipt:"); | ||
println!("Block explorer: https://westend-asset-hub-eth-explorer.parity.io/{hash:?}"); | ||
println!("- Block number: {block_number}"); | ||
println!("- Gas used: {gas_used}"); | ||
println!("- To: {to:?}"); | ||
Ok(()) | ||
} |
Oops, something went wrong.