Merge branch 'master' into light-poa
This commit is contained in:
@@ -47,12 +47,13 @@ ethjson = { path = "../json" }
|
||||
ethcore-devtools = { path = "../devtools" }
|
||||
ethcore-light = { path = "../ethcore/light" }
|
||||
ethcore-logger = { path = "../logger" }
|
||||
vm = { path = "../ethcore/vm" }
|
||||
parity-updater = { path = "../updater" }
|
||||
parity-reactor = { path = "../util/reactor" }
|
||||
rlp = { path = "../util/rlp" }
|
||||
fetch = { path = "../util/fetch" }
|
||||
node-health = { path = "../dapps/node-health" }
|
||||
parity-reactor = { path = "../util/reactor" }
|
||||
parity-updater = { path = "../updater" }
|
||||
rlp = { path = "../util/rlp" }
|
||||
stats = { path = "../util/stats" }
|
||||
vm = { path = "../ethcore/vm" }
|
||||
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
pretty_assertions = "0.1"
|
||||
|
||||
@@ -55,6 +55,7 @@ extern crate ethsync;
|
||||
extern crate ethcore_logger;
|
||||
extern crate vm;
|
||||
extern crate fetch;
|
||||
extern crate node_health;
|
||||
extern crate parity_reactor;
|
||||
extern crate parity_updater as updater;
|
||||
extern crate rlp;
|
||||
|
||||
@@ -584,8 +584,9 @@ fn decrypt(accounts: &AccountProvider, address: Address, msg: Bytes, password: S
|
||||
}
|
||||
|
||||
/// Extract the default gas price from a client and miner.
|
||||
pub fn default_gas_price<C, M>(client: &C, miner: &M) -> U256
|
||||
where C: MiningBlockChainClient, M: MinerService
|
||||
pub fn default_gas_price<C, M>(client: &C, miner: &M) -> U256 where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService,
|
||||
{
|
||||
client.gas_price_corpus(100).median().cloned().unwrap_or_else(|| miner.sensible_gas_price())
|
||||
}
|
||||
|
||||
@@ -24,21 +24,23 @@ use jsonrpc_core::Error;
|
||||
use v1::helpers::CallRequest;
|
||||
use v1::helpers::dispatch::default_gas_price;
|
||||
|
||||
pub fn sign_call<B: MiningBlockChainClient, M: MinerService>(
|
||||
client: &Arc<B>,
|
||||
pub fn sign_call<C: MiningBlockChainClient, M: MinerService> (
|
||||
client: &Arc<C>,
|
||||
miner: &Arc<M>,
|
||||
request: CallRequest,
|
||||
gas_cap: bool,
|
||||
) -> Result<SignedTransaction, Error> {
|
||||
let from = request.from.unwrap_or(0.into());
|
||||
let mut gas = request.gas.unwrap_or(U256::max_value());
|
||||
if gas_cap {
|
||||
let max_gas = 50_000_000.into();
|
||||
if gas > max_gas {
|
||||
let max_gas = 50_000_000.into();
|
||||
let gas = match request.gas {
|
||||
Some(gas) if gas_cap && gas > max_gas => {
|
||||
warn!("Gas limit capped to {} (from {})", max_gas, gas);
|
||||
gas = max_gas
|
||||
max_gas
|
||||
}
|
||||
}
|
||||
Some(gas) => gas,
|
||||
None if gas_cap => max_gas,
|
||||
None => U256::from(2) << 50,
|
||||
};
|
||||
let from = request.from.unwrap_or(0.into());
|
||||
|
||||
Ok(Transaction {
|
||||
nonce: request.nonce.unwrap_or_else(|| client.latest_nonce(&from)),
|
||||
|
||||
@@ -19,15 +19,15 @@ use std::sync::Arc;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use futures::{future, Future, BoxFuture};
|
||||
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use util::misc::version_data;
|
||||
|
||||
use crypto::ecies;
|
||||
use crypto::{ecies, DEFAULT_MAC};
|
||||
use ethkey::{Brain, Generator};
|
||||
use ethstore::random_phrase;
|
||||
use ethsync::LightSyncProvider;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use crypto::DEFAULT_MAC;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use node_health::{NodeHealth, Health};
|
||||
|
||||
use light::client::LightChainClient;
|
||||
|
||||
@@ -53,6 +53,7 @@ pub struct ParityClient {
|
||||
accounts: Arc<AccountProvider>,
|
||||
logger: Arc<RotatingLogger>,
|
||||
settings: Arc<NetworkSettings>,
|
||||
health: NodeHealth,
|
||||
signer: Option<Arc<SignerService>>,
|
||||
dapps_address: Option<(String, u16)>,
|
||||
ws_address: Option<(String, u16)>,
|
||||
@@ -67,18 +68,20 @@ impl ParityClient {
|
||||
accounts: Arc<AccountProvider>,
|
||||
logger: Arc<RotatingLogger>,
|
||||
settings: Arc<NetworkSettings>,
|
||||
health: NodeHealth,
|
||||
signer: Option<Arc<SignerService>>,
|
||||
dapps_address: Option<(String, u16)>,
|
||||
ws_address: Option<(String, u16)>,
|
||||
) -> Self {
|
||||
ParityClient {
|
||||
light_dispatch: light_dispatch,
|
||||
accounts: accounts,
|
||||
logger: logger,
|
||||
settings: settings,
|
||||
signer: signer,
|
||||
dapps_address: dapps_address,
|
||||
ws_address: ws_address,
|
||||
light_dispatch,
|
||||
accounts,
|
||||
logger,
|
||||
settings,
|
||||
health,
|
||||
signer,
|
||||
dapps_address,
|
||||
ws_address,
|
||||
eip86_transition: client.eip86_transition(),
|
||||
}
|
||||
}
|
||||
@@ -393,4 +396,10 @@ impl Parity for ParityClient {
|
||||
fn call(&self, _meta: Self::Metadata, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> BoxFuture<Vec<Bytes>, Error> {
|
||||
future::err(errors::light_unimplemented(None)).boxed()
|
||||
}
|
||||
|
||||
fn node_health(&self) -> BoxFuture<Health, Error> {
|
||||
self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err))
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,10 @@ use std::str::FromStr;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use futures::{future, Future, BoxFuture};
|
||||
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use util::Address;
|
||||
use util::misc::version_data;
|
||||
|
||||
use crypto::ecies;
|
||||
use crypto::{DEFAULT_MAC, ecies};
|
||||
use ethkey::{Brain, Generator};
|
||||
use ethstore::random_phrase;
|
||||
use ethsync::{SyncProvider, ManageNetwork};
|
||||
@@ -34,8 +33,9 @@ use ethcore::ids::BlockId;
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::mode::Mode;
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use node_health::{NodeHealth, Health};
|
||||
use updater::{Service as UpdateService};
|
||||
use crypto::DEFAULT_MAC;
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use jsonrpc_macros::Trailing;
|
||||
@@ -53,17 +53,13 @@ use v1::types::{
|
||||
};
|
||||
|
||||
/// Parity implementation.
|
||||
pub struct ParityClient<C, M, S: ?Sized, U> where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService,
|
||||
S: SyncProvider,
|
||||
U: UpdateService,
|
||||
{
|
||||
pub struct ParityClient<C, M, U> {
|
||||
client: Arc<C>,
|
||||
miner: Arc<M>,
|
||||
sync: Arc<S>,
|
||||
updater: Arc<U>,
|
||||
sync: Arc<SyncProvider>,
|
||||
net: Arc<ManageNetwork>,
|
||||
health: NodeHealth,
|
||||
accounts: Option<Arc<AccountProvider>>,
|
||||
logger: Arc<RotatingLogger>,
|
||||
settings: Arc<NetworkSettings>,
|
||||
@@ -73,39 +69,39 @@ pub struct ParityClient<C, M, S: ?Sized, U> where
|
||||
eip86_transition: u64,
|
||||
}
|
||||
|
||||
impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
|
||||
impl<C, M, U> ParityClient<C, M, U> where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService,
|
||||
S: SyncProvider,
|
||||
U: UpdateService,
|
||||
{
|
||||
/// Creates new `ParityClient`.
|
||||
pub fn new(
|
||||
client: &Arc<C>,
|
||||
miner: &Arc<M>,
|
||||
sync: &Arc<S>,
|
||||
updater: &Arc<U>,
|
||||
net: &Arc<ManageNetwork>,
|
||||
store: &Option<Arc<AccountProvider>>,
|
||||
client: Arc<C>,
|
||||
miner: Arc<M>,
|
||||
sync: Arc<SyncProvider>,
|
||||
updater: Arc<U>,
|
||||
net: Arc<ManageNetwork>,
|
||||
health: NodeHealth,
|
||||
accounts: Option<Arc<AccountProvider>>,
|
||||
logger: Arc<RotatingLogger>,
|
||||
settings: Arc<NetworkSettings>,
|
||||
signer: Option<Arc<SignerService>>,
|
||||
dapps_address: Option<(String, u16)>,
|
||||
ws_address: Option<(String, u16)>,
|
||||
) -> Self {
|
||||
let eip86_transition = client.eip86_transition();
|
||||
ParityClient {
|
||||
client: client.clone(),
|
||||
miner: miner.clone(),
|
||||
sync: sync.clone(),
|
||||
updater: updater.clone(),
|
||||
net: net.clone(),
|
||||
accounts: store.clone(),
|
||||
logger: logger,
|
||||
settings: settings,
|
||||
signer: signer,
|
||||
dapps_address: dapps_address,
|
||||
ws_address: ws_address,
|
||||
eip86_transition: client.eip86_transition(),
|
||||
client,
|
||||
miner,
|
||||
sync,
|
||||
updater,
|
||||
net,
|
||||
health,
|
||||
accounts,
|
||||
logger,
|
||||
settings,
|
||||
signer,
|
||||
dapps_address,
|
||||
ws_address,
|
||||
eip86_transition,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,10 +112,9 @@ impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
|
||||
M: MinerService + 'static,
|
||||
impl<C, M, U> Parity for ParityClient<C, M, U> where
|
||||
C: MiningBlockChainClient + 'static,
|
||||
S: SyncProvider + 'static,
|
||||
M: MinerService + 'static,
|
||||
U: UpdateService + 'static,
|
||||
{
|
||||
type Metadata = Metadata;
|
||||
@@ -429,4 +424,10 @@ impl<C, M, S: ?Sized, U> Parity for ParityClient<C, M, S, U> where
|
||||
|
||||
future::done(result).boxed()
|
||||
}
|
||||
|
||||
fn node_health(&self) -> BoxFuture<Health, Error> {
|
||||
self.health.health()
|
||||
.map_err(|err| errors::internal("Health API failure.", err))
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,15 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use util::{Address, U256};
|
||||
use ethsync::ManageNetwork;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::{TestBlockChainClient, Executed};
|
||||
use ethcore::miner::LocalTransactionStatus;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use ethstore::ethkey::{Generator, Random};
|
||||
use ethsync::ManageNetwork;
|
||||
use node_health::{self, NodeHealth};
|
||||
use parity_reactor;
|
||||
use util::Address;
|
||||
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::{Parity, ParityClient};
|
||||
@@ -30,13 +32,14 @@ use v1::helpers::{SignerService, NetworkSettings};
|
||||
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService, TestUpdater};
|
||||
use super::manage_network::TestManageNetwork;
|
||||
|
||||
pub type TestParityClient = ParityClient<TestBlockChainClient, TestMinerService, TestSyncProvider, TestUpdater>;
|
||||
pub type TestParityClient = ParityClient<TestBlockChainClient, TestMinerService, TestUpdater>;
|
||||
|
||||
pub struct Dependencies {
|
||||
pub miner: Arc<TestMinerService>,
|
||||
pub client: Arc<TestBlockChainClient>,
|
||||
pub sync: Arc<TestSyncProvider>,
|
||||
pub updater: Arc<TestUpdater>,
|
||||
pub health: NodeHealth,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
pub settings: Arc<NetworkSettings>,
|
||||
pub network: Arc<ManageNetwork>,
|
||||
@@ -54,6 +57,11 @@ impl Dependencies {
|
||||
network_id: 3,
|
||||
num_peers: 120,
|
||||
})),
|
||||
health: NodeHealth::new(
|
||||
Arc::new(FakeSync),
|
||||
node_health::TimeChecker::new::<String>(&[], node_health::CpuPool::new(1)),
|
||||
parity_reactor::Remote::new_sync(),
|
||||
),
|
||||
updater: Arc::new(TestUpdater::default()),
|
||||
logger: Arc::new(RotatingLogger::new("rpc=trace".to_owned())),
|
||||
settings: Arc::new(NetworkSettings {
|
||||
@@ -75,12 +83,13 @@ impl Dependencies {
|
||||
let opt_accounts = Some(self.accounts.clone());
|
||||
|
||||
ParityClient::new(
|
||||
&self.client,
|
||||
&self.miner,
|
||||
&self.sync,
|
||||
&self.updater,
|
||||
&self.network,
|
||||
&opt_accounts,
|
||||
self.client.clone(),
|
||||
self.miner.clone(),
|
||||
self.sync.clone(),
|
||||
self.updater.clone(),
|
||||
self.network.clone(),
|
||||
self.health.clone(),
|
||||
opt_accounts.clone(),
|
||||
self.logger.clone(),
|
||||
self.settings.clone(),
|
||||
signer,
|
||||
@@ -102,6 +111,13 @@ impl Dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FakeSync;
|
||||
impl node_health::SyncStatus for FakeSync {
|
||||
fn is_major_importing(&self) -> bool { false }
|
||||
fn peers(&self) -> (usize, usize) { (4, 25) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_parity_accounts_info() {
|
||||
let deps = Dependencies::new();
|
||||
@@ -507,6 +523,8 @@ fn rpc_parity_cid() {
|
||||
|
||||
#[test]
|
||||
fn rpc_parity_call() {
|
||||
use util::U256;
|
||||
|
||||
let deps = Dependencies::new();
|
||||
deps.client.set_execution_result(Ok(Executed {
|
||||
exception: None,
|
||||
@@ -541,3 +559,14 @@ fn rpc_parity_call() {
|
||||
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_parity_node_health() {
|
||||
let deps = Dependencies::new();
|
||||
let io = deps.default_client();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_nodeHealth", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"peers":{"details":[4,25],"message":"","status":"ok"},"sync":{"details":false,"message":"","status":"ok"},"time":{"details":0,"message":"","status":"ok"}},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use jsonrpc_core::Error;
|
||||
use jsonrpc_macros::Trailing;
|
||||
use futures::BoxFuture;
|
||||
|
||||
use node_health::Health;
|
||||
use v1::types::{
|
||||
H160, H256, H512, U256, Bytes, CallRequest,
|
||||
Peers, Transaction, RpcSettings, Histogram,
|
||||
@@ -207,5 +208,9 @@ build_rpc_trait! {
|
||||
/// Call contract, returning the output data.
|
||||
#[rpc(meta, name = "parity_call")]
|
||||
fn call(&self, Self::Metadata, Vec<CallRequest>, Trailing<BlockNumber>) -> BoxFuture<Vec<Bytes>, Error>;
|
||||
|
||||
/// Returns node's health report.
|
||||
#[rpc(async, name = "parity_nodeHealth")]
|
||||
fn node_health(&self) -> BoxFuture<Health, Error>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user