Skip to content

Commit

Permalink
Merge branch 'master' into v2.0-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
peilun-conflux committed Oct 29, 2024
2 parents 5cd7968 + d1240ee commit 22f63e3
Show file tree
Hide file tree
Showing 27 changed files with 751 additions and 355 deletions.
211 changes: 175 additions & 36 deletions Cargo.lock

Large diffs are not rendered by default.

48 changes: 32 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ members = [
"crates/rpc/rpc-cfx-types",
"crates/rpc/rpc-eth-api",
"crates/cfxcore/parity-trace-types",
"crates/rpc/rpc", "crates/util/util-macros",
"crates/rpc/rpc",
"crates/util/util-macros",
"crates/rpc/rpc-utils",
]

resolver = "2"
Expand Down Expand Up @@ -151,40 +153,46 @@ cfx-rpc-cfx-types = { path = "./crates/rpc/rpc-cfx-types" }
cfx-parity-trace-types = { path = "./crates/cfxcore/parity-trace-types" }
cfx-rpc-eth-api = { path = "./crates/rpc/rpc-eth-api" }
cfx-util-macros = { path = "./crates/util/util-macros" }
cfx-rpc = { path = "./crates/rpc/rpc" }
cfx-rpc-utils = { path = "./crates/rpc/rpc-utils" }

serde = { version = "1.0", features = ["derive", "alloc"] }
serde_json = "1.0"
serde_derive = "1.0"
rlp = "0.4.0"
rlp_derive = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "1597a9cab02343eb2322ca0ac58d39b64e3f42d1" }
hex = "0.4.3"
rustc-hex = "2.1"

fail = "0.4.0"
thiserror = "1.0.63"
anyhow = "1.0"
chrono = "=0.4.38"
error-chain = { version = "0.12" }
jsonrpc-core = { version = "15.1.0" }
log = "0.4"
strum = "0.20"
strum_macros = "0.20"
lazy_static = "1.4"

# parallelism
parking_lot = "0.11"
rayon = "1.10"
jsonrpsee = "0.24.4"
once_cell = "1.17.1"
rand = "0.7"
itertools = "0.10.0"

byteorder = "1.2.7"
rlp = "0.4.0"
rlp_derive = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "1597a9cab02343eb2322ca0ac58d39b64e3f42d1" }
hex = "0.4.3"
rustc-hex = "2.1"

# alloy & revm
alloy-sol-types = "0.7.2"
alloy-primitives = "0.7.2"
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "4e22b9e" }
alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "4e22b9e" }
revm = "8.0"

bls-signatures = { git = "https://github.com/Conflux-Chain/bls-signatures.git", rev = "fb52187df92d27c365642cb7e7b2aaf60437cf9c", default-features = false, features = ["multicore", "blst"] }
# jsonrpc framework(old)
jsonrpc-core = "15.1.0"
jsonrpc-tcp-server = "15.1.0"
jsonrpc-http-server = "15.1.0"
jsonrpc-derive = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-pubsub = "15.1.0"
jsonrpc-ws-server = "15.1.0"

# jsonrpc framework(new)
jsonrpsee = "0.24.4"

# async
async-trait = "0.1"
Expand All @@ -193,6 +201,14 @@ async-trait = "0.1"
fixed-hash = "0.5"
keccak-hash = "0.5"
tiny-keccak = "2.0.2"
bls-signatures = { git = "https://github.com/Conflux-Chain/bls-signatures.git", rev = "fb52187df92d27c365642cb7e7b2aaf60437cf9c", default-features = false, features = ["multicore", "blst"] }

# misc
clap = "2"
rand = "0.7"
log = "0.4"
lazy_static = "1.4"
itertools = "0.10.0"
once_cell = "1.17.1"
chrono = "=0.4.38"
byteorder = "1.2.7"
16 changes: 6 additions & 10 deletions bins/conflux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ description.workspace = true
documentation.workspace = true

[dependencies]
mio = "0.6.8"
clap = { workspace = true, features = ["yaml"] }
textwrap = "0.9"
toml = "0.5.8"
Expand All @@ -24,12 +23,11 @@ cfxcore-accounts = { workspace = true }
home = "0.5.0"
rpassword = "4.0.1"
io = { workspace = true }
runtime = { workspace = true }
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git", rev="b523017108bb2d571a7a69bd97bc406e63bc7a9d" }
jsonrpc-core = "15.1.0"
jsonrpc-tcp-server = "15.1.0"
jsonrpc-http-server = "15.1.0"
jsonrpc-core-client = { version = "15.1.0", features = ["http"] }
jsonrpc-core = "18.0.0"
jsonrpc-tcp-server = "18.0.0"
jsonrpc-http-server = "18.0.0"
jsonrpc-core-client = { version = "18.0.0", features = ["http"] }
error-chain = { version = "0.12" }
log = "0.4"
slab = "0.4"
Expand All @@ -47,8 +45,6 @@ rand = "0.8.3"
kvdb-rocksdb = { workspace = true }
client = { workspace = true }
cfx-types = { workspace = true }
threadpool = "1.7"
futures = "0.1.29"
docopt = "1.0"
cfxkey = { workspace = true }
parity-wordlist = "1.3.0"
Expand All @@ -58,15 +54,15 @@ malloc_size_of = { workspace = true }
diem-crypto = { path= "../../crates/cfxcore/core/src/pos/crypto/crypto" }
diem-types = { path= "../../crates/cfxcore/core/src/pos/types" }
pos-ledger-db = { path = "../../crates/cfxcore/core/src/pos/storage/pos-ledger-db" }
executor-types = { path = "../../crates/cfxcore/core/src/pos/types/executor-types" }
executor = { path = "../../crates/cfxcore/core/src/pos/consensus/executor" }
executor = { path = "../../crates/cfxcore/core/src/pos/consensus/executor" } # used by pos-genesis-tool
storage-interface = { path = "../../crates/cfxcore/core/src/pos/storage/storage-interface" }
move-core-types = { path = "../../crates/cfxcore/core/src/pos/types/move-core-types" }
bcs = "0.1.3"
tempdir = "0.3.7"
hex = "0.3.0"
base64ct = "=1.1.1"
parity-version = { workspace = true }
tokio = { version = "1", features = ["rt"] }

[target.'cfg(not(target_env = "msvc"))'.dependencies.jemallocator]
version = "0.3.2"
Expand Down
36 changes: 10 additions & 26 deletions bins/conflux/src/command/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use crate::command::helpers::{input_password, password_prompt};
use clap::ArgMatches;
use futures::future::Future;
use jsonrpc_core::{Params, Value};
use jsonrpc_core_client::{transports::http::connect, RawClient};
use jsonrpc_http_server::hyper::rt;
use serde_json::Map;
use std::{str::FromStr, sync::mpsc::channel};
use std::str::FromStr;

pub struct RpcCommand {
pub url: String,
Expand Down Expand Up @@ -54,29 +52,15 @@ impl RpcCommand {
}))
}

pub fn execute(self) -> Result<String, String> {
let (sender, receiver) = channel();

rt::run(
connect::<RawClient>(self.url.as_str())
.and_then(move |client| {
client.call_method(self.method.as_str(), self.args).then(
move |result| {
sender
.send(result)
.expect("channel should work fine");
Ok(())
},
)
})
.map_err(|e| eprintln!("future error: {:?}", e)),
);

receiver
.recv()
.expect("channel should work fine")
.map(|result| format!("{:#}", result))
.map_err(|e| format!("{:?}", e))
pub async fn execute(self) -> Result<String, String> {
let client = connect::<RawClient>(self.url.as_str())
.await
.map_err(|e| e.to_string())?;
let result = client
.call_method(self.method.as_str(), self.args)
.await
.map_err(|e| e.to_string())?;
Ok(format!("{:#}", result))
}
}

Expand Down
4 changes: 3 additions & 1 deletion bins/conflux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ fn handle_sub_command(matches: &ArgMatches) -> Result<Option<String>, String> {
}

if let Some(cmd) = RpcCommand::parse(subcmd_matches)? {
return Ok(Some(cmd.execute()?));
let rt = tokio::runtime::Runtime::new().unwrap();
let result = rt.block_on(cmd.execute())?;
return Ok(Some(result));
}

Ok(None)
Expand Down
3 changes: 2 additions & 1 deletion crates/cfxcore/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ tempdir = "0.3"
threadpool = "1.0"
throttling = { workspace = true }
toml = "0.5.8"
tokio02 = { version = "0.2", package="tokio", features = ["full"] }
tokio = { version = "1.6", features = ["full"] }
tokio-timer = "0.2.13"
tokio-stream = "0.1.4"
Expand Down Expand Up @@ -141,6 +140,8 @@ alloy-rpc-types-trace = { workspace = true }
geth-tracer = { workspace = true }
cfx-rpc-cfx-types = { workspace = true }
cfx-rpc-eth-types = { workspace = true }
jsonrpsee = { workspace = true, features = ["jsonrpsee-types"] }
cfx-rpc-utils = { workspace = true }


[dev-dependencies]
Expand Down
7 changes: 3 additions & 4 deletions crates/cfxcore/core/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::UniqueId;
use cfx_types::H256;
use parking_lot::RwLock;
use std::{collections::BTreeMap, sync::Arc, time::Duration};
use tokio02::{runtime, sync::mpsc, time::timeout};
use tokio::{runtime, sync::mpsc, time::timeout};

pub use tokio02::{sync::mpsc::error::TryRecvError, time::Elapsed};
pub use tokio::{sync::mpsc::error::TryRecvError, time::error::Elapsed};

pub struct Receiver<T> {
pub id: u64,
Expand All @@ -29,8 +29,7 @@ impl<T> Receiver<T> {
pub fn recv_with_timeout(
&mut self, wait_for: Duration,
) -> Result<Option<T>, Elapsed> {
runtime::Builder::new()
.basic_scheduler()
runtime::Builder::new_current_thread()
.enable_time()
.build()
.expect("Runtime can be created")
Expand Down
11 changes: 9 additions & 2 deletions crates/cfxcore/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
// See http://www.gnu.org/licenses/
use crate::light_protocol::Error as LightProtocolError;
use cfx_rpc_eth_types::Error as EthRpcError;
pub use cfx_rpc_utils::error::error_codes::EXCEPTION_ERROR;
use cfx_statedb::Error as StateDbError;
use cfx_storage::Error as StorageError;
use jsonrpc_core::{futures::future, Error as JsonRpcError, ErrorCode};
use jsonrpsee::types::ErrorObjectOwned;
use primitives::{account::AccountError, filter::FilterError};
use rlp::DecoderError;
use serde_json::Value;
use std::fmt::{Debug, Display};
use thiserror::Error;

pub const EXCEPTION_ERROR: i64 = -32016;

#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Expand Down Expand Up @@ -72,6 +72,13 @@ impl From<Error> for JsonRpcError {
}
}

impl From<Error> for ErrorObjectOwned {
fn from(e: Error) -> ErrorObjectOwned {
let err: JsonRpcError = e.into();
ErrorObjectOwned::owned(err.code.code() as i32, err.message, err.data)
}
}

impl From<&str> for Error {
fn from(s: &str) -> Error { Error::Msg(s.into()) }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/core/src/sync/synchronization_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cfx_parameters::consensus_internal::ELASTICITY_MULTIPLIER;
use futures::executor::block_on;
use parking_lot::RwLock;
use slab::Slab;
use tokio02::sync::mpsc::error::TryRecvError;
use tokio::sync::mpsc::error::TryRecvError;
use unexpected::{Mismatch, OutOfBounds};

use cfx_executor::machine::Machine;
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl SynchronizationGraph {
warn!("Duplicate block = {} sent to the consensus worker", hash);
},
Err(TryRecvError::Empty) => break 'inner,
Err(TryRecvError::Closed) => break 'outer,
Err(TryRecvError::Disconnected) => break 'outer,
}
}
if let Some((_, hash)) = priority_queue.pop() {
Expand Down
40 changes: 40 additions & 0 deletions crates/cfxcore/core/src/transaction_pool/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use cfx_rpc_utils::error::errors::{
EthApiError, RpcInvalidTransactionError, RpcPoolError,
};
use cfx_types::{H256, U256};
use primitives::transaction::TransactionError;

Expand Down Expand Up @@ -43,3 +46,40 @@ impl From<cfx_statedb::Error> for TransactionPoolError {
))
}
}

impl From<TransactionPoolError> for EthApiError {
fn from(err: TransactionPoolError) -> Self {
match err {
TransactionPoolError::TransactionError(tx_err) => match tx_err {
TransactionError::AlreadyImported => Self::PoolError(RpcPoolError::ReplaceUnderpriced),
TransactionError::ChainIdMismatch { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::InvalidChainId),
TransactionError::EpochHeightOutOfBound { .. } => Self::InvalidBlockRange,
TransactionError::NotEnoughBaseGas { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::GasTooLow),
TransactionError::Stale => Self::InvalidTransaction(RpcInvalidTransactionError::NonceTooLow),
TransactionError::TooCheapToReplace => Self::PoolError(RpcPoolError::ReplaceUnderpriced),
TransactionError::LimitReached => Self::PoolError(RpcPoolError::TxPoolOverflow),
TransactionError::InsufficientGasPrice { .. } => Self::PoolError(RpcPoolError::Underpriced),
TransactionError::InsufficientGas { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::GasTooLow),
TransactionError::InsufficientBalance { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::InsufficientFundsForTransfer),
TransactionError::GasLimitExceeded { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::GasTooHigh),
TransactionError::InvalidGasLimit(_) => Self::InvalidTransaction(RpcInvalidTransactionError::GasUintOverflow),
TransactionError::InvalidSignature(_) => Self::InvalidTransactionSignature,
TransactionError::TooBig => Self::InvalidTransaction(RpcInvalidTransactionError::MaxInitCodeSizeExceeded),
TransactionError::InvalidRlp(_) => Self::FailedToDecodeSignedTransaction,
TransactionError::ZeroGasPrice => Self::PoolError(RpcPoolError::Underpriced),
TransactionError::FutureTransactionType => Self::InvalidTransaction(RpcInvalidTransactionError::TxTypeNotSupported),
TransactionError::InvalidReceiver => Self::Other("Invalid receiver".to_string()),
TransactionError::TooLargeNonce => Self::InvalidTransaction(RpcInvalidTransactionError::NonceMaxValue),
},
TransactionPoolError::GasLimitExceeded { .. } => Self::PoolError(RpcPoolError::ExceedsGasLimit),
TransactionPoolError::GasPriceLessThanMinimum { .. } => Self::PoolError(RpcPoolError::Underpriced),
TransactionPoolError::RlpDecodeError(_) => Self::FailedToDecodeSignedTransaction,
TransactionPoolError::NonceTooDistant { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::NonceTooHigh),
TransactionPoolError::NonceTooStale { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::NonceTooLow),
TransactionPoolError::OutOfBalance { .. } => Self::InvalidTransaction(RpcInvalidTransactionError::InsufficientFundsForTransfer),
TransactionPoolError::TxPoolFull => Self::PoolError(RpcPoolError::TxPoolOverflow),
TransactionPoolError::HigherGasPriceNeeded {..} => Self::PoolError(RpcPoolError::ReplaceUnderpriced),
TransactionPoolError::StateDbError(_) => Self::InternalEthError,
}
}
}
14 changes: 8 additions & 6 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ app_dirs = "1.2.1"
dir = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "1597a9cab02343eb2322ca0ac58d39b64e3f42d1" }
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git", rev="b523017108bb2d571a7a69bd97bc406e63bc7a9d" }
jsonrpc-core = { workspace = true }
jsonrpc-tcp-server = "15.1.0"
jsonrpc-http-server = "15.1.0"
jsonrpc-derive = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-pubsub = "15.1.0"
jsonrpc-ws-server = "15.1.0"
jsonrpc-tcp-server = { workspace = true }
jsonrpc-http-server = { workspace = true }
jsonrpc-derive = { workspace = true }
jsonrpc-core-client = { workspace = true }
jsonrpc-pubsub = { workspace = true }
jsonrpc-ws-server = { workspace = true }
error-chain = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
Expand Down Expand Up @@ -113,6 +113,8 @@ cfx-rpc-eth-types = { workspace = true }
cfx-rpc-cfx-types = { workspace = true }
cfx-rpc-primitives = { workspace = true }
cfx-util-macros = { workspace = true }
cfx-rpc = { workspace = true }
cfx-rpc-utils = { workspace = true }

[dev-dependencies]
criterion = "0.3"
Expand Down
10 changes: 3 additions & 7 deletions crates/client/src/rpc/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
pub mod error_codes;
mod error_helpers;
mod errors;

pub use error_codes as codes;
pub use error_helpers::*;
pub use errors::*;
pub use cfx_rpc_utils::error::{
error_codes, error_codes as codes, errors::*, jsonrpc_error_helpers::*,
};
Loading

0 comments on commit 22f63e3

Please sign in to comment.