Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fc89e7d
upgrade v0.9.22
zqhxuyuan May 21, 2022
d7ca928
migrate jsonrpc to jsonrpsee
zqhxuyuan May 21, 2022
ebce4d7
update orml
zqhxuyuan May 21, 2022
fe73322
fix xcm test
zqhxuyuan May 22, 2022
87f92e6
fix e2e test
zqhxuyuan May 22, 2022
4977267
update stable-asset and orml
zqhxuyuan May 24, 2022
1641de0
update orml fmt
zqhxuyuan May 24, 2022
b1953ae
update evm-tests and merge orml master
zqhxuyuan May 24, 2022
0e35305
fix xcm-interface test
zqhxuyuan May 24, 2022
17379fc
fix polkadot xcm test
zqhxuyuan May 24, 2022
4c25e52
fix ci
zjb0807 May 25, 2022
e935ba9
update evm logger
zqhxuyuan May 25, 2022
af10556
Merge branch 'polkadot-v0.9.22' of https://github.com/AcalaNetwork/Ac…
zqhxuyuan May 25, 2022
78d020d
update deps
zqhxuyuan May 25, 2022
944ecb9
update predeploy contracts
zqhxuyuan May 25, 2022
2e00c5e
revert predeploy contracts
zqhxuyuan May 25, 2022
f450f0a
evm internal_error
zqhxuyuan May 25, 2022
e6d0448
fix bench evm (#2162)
ermalkaleci May 26, 2022
d38c778
update orml
ermalkaleci May 26, 2022
7b87217
fix bench
ermalkaleci May 26, 2022
8a9c69e
Merge remote-tracking branch 'origin/master' into polkadot-v0.9.22
May 26, 2022
2c89e3b
make bench-evm
May 26, 2022
5a1009a
ignore unknown key. will be counted by entry call
ermalkaleci May 26, 2022
94490da
make bench-evm
May 26, 2022
bb179ca
update tests
ermalkaleci May 26, 2022
759a926
cargo run --profile production --color=never --bin=acala --features=r…
May 26, 2022
5114efc
make bench-evm
May 27, 2022
5bea6b9
cargo run --profile production --color=never --bin=acala --features=r…
May 27, 2022
9eeec31
Revert "update tests"
ermalkaleci May 27, 2022
6bffbe0
udpate ts-test
ermalkaleci May 27, 2022
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
Prev Previous commit
Next Next commit
migrate jsonrpc to jsonrpsee
  • Loading branch information
zqhxuyuan committed May 21, 2022
commit d7ca928b67d8e53855e948d00ffb9cf07a12588f
181 changes: 36 additions & 145 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions modules/evm/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ authors = ["Acala Developers"]
edition = "2021"

[dependencies]
jsonrpc-core = "18.0.0"
jsonrpc-derive = "18.0.0"
jsonrpsee = { version = "0.13.0", features = ["server", "macros"] }
rustc-hex = "2.1.0"
serde = { version = "1.0.136", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion modules/evm/rpc/src/call_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_core::{Bytes, H160, U256};
use sp_rpc::number::NumberOrHex;

/// Call request
#[derive(Debug, Default, PartialEq, Deserialize, Clone)]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct CallRequest {
Expand Down
22 changes: 11 additions & 11 deletions modules/evm/rpc/src/evm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@

//! EVM rpc interface.

use jsonrpc_core::Result;
use jsonrpc_derive::rpc;
use jsonrpsee::{
core::RpcResult,
proc_macros::rpc,
};
use primitives::evm::BlockLimits;
use sp_core::{Bytes, H160};

pub use rpc_impl_EVMApi::gen_server::EVMApi as EVMApiServer;

use crate::call_request::{CallRequest, EstimateResourcesResponse};

/// EVM rpc interface.
#[rpc(server)]
#[rpc(client, server)]
pub trait EVMApi<BlockHash> {
/// Call contract, returning the output data.
#[rpc(name = "evm_call")]
fn call(&self, _: CallRequest, at: Option<BlockHash>) -> Result<Bytes>;
#[method(name = "evm_call")]
fn call(&self, call_request: CallRequest, at: Option<BlockHash>) -> RpcResult<Bytes>;

/// Estimate resources needed for execution of given contract.
#[rpc(name = "evm_estimateResources")]
#[method(name = "evm_estimateResources")]
fn estimate_resources(
&self,
from: H160,
unsigned_extrinsic: Bytes,
at: Option<BlockHash>,
) -> Result<EstimateResourcesResponse>;
) -> RpcResult<EstimateResourcesResponse>;

/// Get max gas and storage limits per transaction
#[rpc(name = "evm_blockLimits")]
fn block_limits(&self, at: Option<BlockHash>) -> Result<BlockLimits>;
#[method(name = "evm_blockLimits")]
fn block_limits(&self, at: Option<BlockHash>) -> RpcResult<BlockLimits>;
}
172 changes: 103 additions & 69 deletions modules/evm/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#![allow(clippy::upper_case_acronyms)]

use frame_support::log;
use jsonrpc_core::{Error, ErrorCode, Result, Value};
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
};
use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi;
use rustc_hex::ToHex;
use sc_rpc_api::DenyUnsafe;
Expand All @@ -40,52 +44,71 @@ pub use module_evm::{ExitError, ExitReason};
pub use module_evm_rpc_runtime_api::EVMRuntimeRPCApi;
use primitives::evm::{BlockLimits, EstimateResourcesRequest};

pub use crate::evm_api::{EVMApi as EVMApiT, EVMApiServer};

mod call_request;
mod evm_api;
// mod evm_api;

fn internal_err<T: ToString>(message: T) -> Error {
Error {
code: ErrorCode::InternalError,
message: message.to_string(),
data: None,
}
/// EVM rpc interface.
#[rpc(client, server)]
pub trait EVMApi<BlockHash> {
/// Call contract, returning the output data.
#[method(name = "evm_call")]
fn call(&self, call_request: CallRequest, at: Option<BlockHash>) -> RpcResult<Bytes>;

/// Estimate resources needed for execution of given contract.
#[method(name = "evm_estimateResources")]
fn estimate_resources(
&self,
from: H160,
unsigned_extrinsic: Bytes,
at: Option<BlockHash>,
) -> RpcResult<EstimateResourcesResponse>;

/// Get max gas and storage limits per transaction
#[method(name = "evm_blockLimits")]
fn block_limits(&self, at: Option<BlockHash>) -> RpcResult<BlockLimits>;
}

fn internal_err<T: ToString>(message: T) -> JsonRpseeError {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
message.to_string(),
None::<()>,
)))
}

#[allow(dead_code)]
fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<()> {
fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> RpcResult<()> {
match reason {
ExitReason::Succeed(_) => Ok(()),
ExitReason::Error(e) => {
if *e == ExitError::OutOfGas {
// `ServerError(0)` will be useful in estimate gas
return Err(Error {
code: ErrorCode::ServerError(0),
message: "out of gas".to_string(),
data: None,
});
Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::ServerError(0).code(),
"out of gas".to_string(),
None::<()>,
))))
} else {
Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
format!("execution error: {:?}", e),
Some("0x".to_string()),
))))
}
Err(Error {
code: ErrorCode::InternalError,
message: format!("execution error: {:?}", e),
data: Some(Value::String("0x".to_string())),
})
}
ExitReason::Revert(_) => {
let message = "VM Exception while processing transaction: execution revert".to_string();
Err(Error {
code: ErrorCode::InternalError,
message: decode_revert_message(data)
.map_or(message.clone(), |reason| format!("{} {}", message, reason)),
data: Some(Value::String(format!("0x{}", data.to_hex::<String>()))),
})
Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
decode_revert_message(data).map_or(message.clone(), |reason| format!("{} {}", message, reason)),
Some(format!("0x{}", data.to_hex::<String>())),
))))
}
ExitReason::Fatal(e) => Err(Error {
code: ErrorCode::InternalError,
message: format!("execution fatal: {:?}", e),
data: Some(Value::String("0x".to_string())),
}),
ExitReason::Fatal(e) => Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
format!("execution fatal: {:?}", e),
Some("0x".to_string()),
)))),
}
}

Expand All @@ -108,13 +131,13 @@ fn decode_revert_message(data: &[u8]) -> Option<String> {
None
}

pub struct EVMApi<B, C, Balance> {
pub struct EVMRpc<B, C, Balance> {
client: Arc<C>,
_deny_unsafe: DenyUnsafe,
_marker: PhantomData<(B, Balance)>,
}

impl<B, C, Balance> EVMApi<B, C, Balance> {
impl<B, C, Balance> EVMRpc<B, C, Balance> {
pub fn new(client: Arc<C>, _deny_unsafe: DenyUnsafe) -> Self {
Self {
client,
Expand All @@ -128,15 +151,16 @@ fn to_u128(val: NumberOrHex) -> std::result::Result<u128, ()> {
val.into_u256().try_into().map_err(|_| ())
}

impl<B, C, Balance> EVMApiT<<B as BlockT>::Hash> for EVMApi<B, C, Balance>
#[async_trait]
impl<B, C, Balance> EVMApiServer<<B as BlockT>::Hash> for EVMRpc<B, C, Balance>
where
B: BlockT,
C: ProvideRuntimeApi<B> + HeaderBackend<B> + Send + Sync + 'static,
C::Api: EVMRuntimeRPCApi<B, Balance>,
C::Api: TransactionPaymentApi<B, Balance>,
Balance: Codec + MaybeDisplay + MaybeFromStr + Default + Send + Sync + 'static + TryFrom<u128> + Into<U256>,
{
fn call(&self, request: CallRequest, at: Option<<B as BlockT>::Hash>) -> Result<Bytes> {
fn call(&self, request: CallRequest, at: Option<<B as BlockT>::Hash>) -> RpcResult<Bytes> {
let api = self.client.runtime_api();

let hash = at.unwrap_or_else(|| self.client.info().best_hash);
Expand All @@ -162,19 +186,19 @@ where

let gas_limit = gas_limit.unwrap_or(gas_limit_cap);
if gas_limit > gas_limit_cap {
return Err(Error {
code: ErrorCode::InvalidParams,
message: format!("GasLimit exceeds capped allowance: {}", gas_limit_cap),
data: None,
});
return Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("GasLimit exceeds capped allowance: {}", gas_limit_cap),
None::<()>,
))));
}
let storage_limit = storage_limit.unwrap_or(block_limits.max_storage_limit);
if storage_limit > block_limits.max_storage_limit {
return Err(Error {
code: ErrorCode::InvalidParams,
message: format!("StorageLimit exceeds allowance: {}", block_limits.max_storage_limit),
data: None,
});
return Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("StorageLimit exceeds allowance: {}", block_limits.max_storage_limit),
None::<()>,
))));
}
let data = data.map(|d| d.0).unwrap_or_default();

Expand All @@ -184,10 +208,12 @@ where
Ok(Default::default())
};

let balance_value = balance_value.map_err(|_| Error {
code: ErrorCode::InvalidParams,
message: format!("Invalid parameter value: {:?}", value),
data: None,
let balance_value = balance_value.map_err(|_| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("Invalid parameter value: {:?}", value),
None::<()>,
)))
})?;

match to {
Expand Down Expand Up @@ -248,7 +274,7 @@ where
from: H160,
unsigned_extrinsic: Bytes,
at: Option<<B as BlockT>::Hash>,
) -> Result<EstimateResourcesResponse> {
) -> RpcResult<EstimateResourcesResponse> {
let hash = at.unwrap_or_else(|| self.client.info().best_hash);

let block_id = BlockId::Hash(hash);
Expand Down Expand Up @@ -299,7 +325,7 @@ where
}

// Create a helper to check if a gas allowance results in an executable transaction
let executable = move |request: CallRequest, gas: u64| -> Result<ExecutableResult> {
let executable = move |request: CallRequest, gas: u64| -> RpcResult<ExecutableResult> {
let CallRequest {
from,
to,
Expand All @@ -324,10 +350,12 @@ where
Ok(Default::default())
};

let balance_value = balance_value.map_err(|_| Error {
code: ErrorCode::InvalidParams,
message: format!("Invalid parameter value: {:?}", value),
data: None,
let balance_value = balance_value.map_err(|_| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("Invalid parameter value: {:?}", value),
None::<()>,
)))
})?;

let (exit_reason, data, used_gas, used_storage) = match to {
Expand Down Expand Up @@ -450,20 +478,24 @@ where
}
}

let uxt: <B as traits::Block>::Extrinsic = Decode::decode(&mut &*unsigned_extrinsic).map_err(|e| Error {
code: ErrorCode::InternalError,
message: "Unable to dry run extrinsic.".into(),
data: Some(format!("{:?}", e).into()),
let uxt: <B as traits::Block>::Extrinsic = Decode::decode(&mut &*unsigned_extrinsic).map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
"Unable to dry run extrinsic.",
Some(e.to_string()),
)))
})?;

let fee = self
.client
.runtime_api()
.query_fee_details(&block_id, uxt, unsigned_extrinsic.len() as u32)
.map_err(|e| Error {
code: ErrorCode::InternalError,
message: "Unable to query fee details.".into(),
data: Some(format!("{:?}", e).into()),
.map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
"Unable to query fee details.",
Some(e.to_string()),
)))
})?;

let adjusted_weight_fee = fee
Expand All @@ -477,7 +509,7 @@ where
})
}

fn block_limits(&self, at: Option<<B as BlockT>::Hash>) -> Result<BlockLimits> {
fn block_limits(&self, at: Option<<B as BlockT>::Hash>) -> RpcResult<BlockLimits> {
let hash = at.unwrap_or_else(|| self.client.info().best_hash);

let block_id = BlockId::Hash(hash);
Expand All @@ -495,10 +527,12 @@ where
})?;

let block_limits = if version > 1 {
self.client.runtime_api().block_limits(&block_id).map_err(|e| Error {
code: ErrorCode::InternalError,
message: "Unable to query block limits.".into(),
data: Some(format!("{:?}", e).into()),
self.client.runtime_api().block_limits(&block_id).map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InternalError.code(),
"Unable to query block limits.",
Some(e.to_string()),
)))
})?
} else {
BlockLimits {
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "acala"
path = "src/main.rs"

[dependencies]
futures = "0.3.15"
futures = "0.3.21"
parity-util-mem = { version = "0.11", default-features = false, features = ["jemalloc-global"] }
acala-cli = { path = "cli" }
acala-service = { path = "service" }
Expand Down
5 changes: 4 additions & 1 deletion node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::cli::{Cli, RelayChainCli, Subcommand};
use codec::Encode;
use cumulus_client_service::genesis::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::BenchmarkCmd;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result,
Expand Down Expand Up @@ -309,6 +309,9 @@ pub fn run() -> sc_cli::Result<()> {
cmd.run(config, partials.client.clone(), db, storage)
}),
BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()),
BenchmarkCmd::Machine(cmd) => {
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()))
}
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion node/e2e-tests/test-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async-trait = "0.1.42"
tokio = { version = "1.10", features = ["macros"] }
criterion = { version = "0.3.5", features = [ "async_tokio" ] }
parking_lot = "0.12.0"
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.13.0", features = ["server", "macros"] }
log = "0.4.17"
futures = { package = "futures", version = "0.3", features = ["compat"] }
hex-literal = "0.3.1"
Expand Down
Loading