Major sync <-> client interactions refactoring (#1572)
* chain notify trait * replaced network service with io service * fix ethcore crate warnings * refactored network service without generic * ethcore fix * ethsync refactoring * proper linking of notify * manage network interface * rpc crate rebinding * full rewire * sync internal io service * fix deadlock * fix warnings and removed async io * sync imported message propagation * fix rpc warnings * binart warnings * test fixes * rpc mocks and tests * fix util doctest * fix message name and removed empty notifier * pointers mess & dark mode fixed * fixed sync doctest * added few warnings * fix review * new convention match * fix error unwraps * doctest fix
This commit is contained in:
committed by
Arkadiy Paronyan
parent
2382d779ca
commit
d3695d0b72
@@ -19,26 +19,26 @@ use std::sync::{Arc, Weak};
|
||||
use jsonrpc_core::*;
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::client::MiningBlockChainClient;
|
||||
use ethcore::service::SyncMessage;
|
||||
use util::network::{NetworkService, NonReservedPeerMode};
|
||||
use ethsync::ManageNetwork;
|
||||
use util::network::NonReservedPeerMode;
|
||||
use v1::traits::EthcoreSet;
|
||||
use v1::types::{Bytes, H160, U256};
|
||||
|
||||
/// Ethcore-specific rpc interface for operations altering the settings.
|
||||
pub struct EthcoreSetClient<C, M> where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService {
|
||||
|
||||
M: MinerService
|
||||
{
|
||||
client: Weak<C>,
|
||||
miner: Weak<M>,
|
||||
net: Weak<NetworkService<SyncMessage>>,
|
||||
net: Weak<ManageNetwork>,
|
||||
}
|
||||
|
||||
impl<C, M> EthcoreSetClient<C, M> where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService {
|
||||
/// Creates new `EthcoreSetClient`.
|
||||
pub fn new(client: &Arc<C>, miner: &Arc<M>, net: &Arc<NetworkService<SyncMessage>>) -> Self {
|
||||
pub fn new(client: &Arc<C>, miner: &Arc<M>, net: &Arc<ManageNetwork>) -> Self {
|
||||
EthcoreSetClient {
|
||||
client: Arc::downgrade(client),
|
||||
miner: Arc::downgrade(miner),
|
||||
@@ -144,4 +144,14 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
|
||||
take_weak!(self.net).set_non_reserved_mode(NonReservedPeerMode::Accept);
|
||||
to_value(&true)
|
||||
}
|
||||
|
||||
fn start_network(&self, _: Params) -> Result<Value, Error> {
|
||||
take_weak!(self.net).start_network();
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
|
||||
fn stop_network(&self, _: Params) -> Result<Value, Error> {
|
||||
take_weak!(self.net).stop_network();
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,4 @@ impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
|
||||
fn start_network(&self, _: Params) -> Result<Value, Error> {
|
||||
take_weak!(self.sync).start_network();
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
|
||||
fn stop_network(&self, _: Params) -> Result<Value, Error> {
|
||||
take_weak!(self.sync).stop_network();
|
||||
Ok(Value::Bool(true))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,5 @@ impl SyncProvider for TestSyncProvider {
|
||||
fn status(&self) -> SyncStatus {
|
||||
self.status.unwrapped_read().clone()
|
||||
}
|
||||
|
||||
fn start_network(&self) {
|
||||
}
|
||||
|
||||
fn stop_network(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ use std::str::FromStr;
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::{EthcoreSet, EthcoreSetClient};
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::service::SyncMessage;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
use util::numbers::*;
|
||||
use util::network::{NetworkConfiguration, NetworkService};
|
||||
use rustc_serialize::hex::FromHex;
|
||||
use super::manage_network::TestManageNetwork;
|
||||
use ethsync::ManageNetwork;
|
||||
|
||||
fn miner_service() -> Arc<TestMinerService> {
|
||||
Arc::new(TestMinerService::default())
|
||||
@@ -34,12 +34,12 @@ fn client_service() -> Arc<TestBlockChainClient> {
|
||||
Arc::new(TestBlockChainClient::default())
|
||||
}
|
||||
|
||||
fn network_service() -> Arc<NetworkService<SyncMessage>> {
|
||||
Arc::new(NetworkService::new(NetworkConfiguration::new()).unwrap())
|
||||
fn network_service() -> Arc<TestManageNetwork> {
|
||||
Arc::new(TestManageNetwork)
|
||||
}
|
||||
|
||||
fn ethcore_set_client(client: &Arc<TestBlockChainClient>, miner: &Arc<TestMinerService>, net: &Arc<NetworkService<SyncMessage>>) -> EthcoreSetClient<TestBlockChainClient, TestMinerService> {
|
||||
EthcoreSetClient::new(client, miner, net)
|
||||
fn ethcore_set_client(client: &Arc<TestBlockChainClient>, miner: &Arc<TestMinerService>, net: &Arc<TestManageNetwork>) -> EthcoreSetClient<TestBlockChainClient, TestMinerService> {
|
||||
EthcoreSetClient::new(client, miner, &(net.clone() as Arc<ManageNetwork>))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
30
rpc/src/v1/tests/mocked/manage_network.rs
Normal file
30
rpc/src/v1/tests/mocked/manage_network.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethsync::ManageNetwork;
|
||||
use util::network::NetworkConfiguration;
|
||||
|
||||
pub struct TestManageNetwork;
|
||||
|
||||
// TODO: rob, gavin (originally introduced this functions) - proper tests and test state
|
||||
impl ManageNetwork for TestManageNetwork {
|
||||
fn set_non_reserved_mode(&self, _mode: ::util::network::NonReservedPeerMode) {}
|
||||
fn remove_reserved_peer(&self, _peer: &str) -> Result<(), String> { Ok(()) }
|
||||
fn add_reserved_peer(&self, _peer: &str) -> Result<(), String> { Ok(()) }
|
||||
fn start_network(&self) {}
|
||||
fn stop_network(&self) {}
|
||||
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::new_local() }
|
||||
}
|
||||
@@ -26,3 +26,4 @@ mod personal_signer;
|
||||
mod ethcore;
|
||||
mod ethcore_set;
|
||||
mod rpc;
|
||||
mod manage_network;
|
||||
|
||||
@@ -55,6 +55,12 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static {
|
||||
/// Accept non-reserved peers (default behavior)
|
||||
fn accept_non_reserved_peers(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Start the network.
|
||||
fn start_network(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Stop the network.
|
||||
fn stop_network(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Should be used to convert object to io delegate.
|
||||
fn to_delegate(self) -> IoDelegate<Self> {
|
||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
||||
|
||||
@@ -30,12 +30,6 @@ pub trait Net: Sized + Send + Sync + 'static {
|
||||
/// Otherwise false.
|
||||
fn is_listening(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Start the network.
|
||||
fn start_network(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Stop the network.
|
||||
fn stop_network(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Should be used to convert object to io delegate.
|
||||
fn to_delegate(self) -> IoDelegate<Self> {
|
||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
||||
|
||||
Reference in New Issue
Block a user