Merge branch 'master' into ethminer_crate
Conflicts: ethcore/src/client.rs parity/main.rs rpc/src/v1/impls/eth.rs sync/src/chain.rs
This commit is contained in:
commit
92022ac14d
@ -190,6 +190,7 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
|
|
||||||
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
||||||
fn try_seal(&self, block: ClosedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, ClosedBlock>;
|
fn try_seal(&self, block: ClosedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, ClosedBlock>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug, Eq, PartialEq)]
|
#[derive(Default, Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -25,7 +25,7 @@ use ethcore::transaction::SignedTransaction;
|
|||||||
use transaction_queue::{TransactionQueue};
|
use transaction_queue::{TransactionQueue};
|
||||||
|
|
||||||
/// Miner client API
|
/// Miner client API
|
||||||
pub trait MinerService {
|
pub trait MinerService : Send + Sync {
|
||||||
|
|
||||||
/// Returns miner's status.
|
/// Returns miner's status.
|
||||||
fn status(&self) -> MinerStatus;
|
fn status(&self) -> MinerStatus;
|
||||||
|
@ -50,7 +50,7 @@ use ethcore::spec::*;
|
|||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::service::{ClientService, NetSyncMessage};
|
use ethcore::service::{ClientService, NetSyncMessage};
|
||||||
use ethcore::ethereum;
|
use ethcore::ethereum;
|
||||||
use ethsync::{EthSync, SyncConfig};
|
use ethsync::{EthSync, SyncConfig, SyncStatusProvider};
|
||||||
use ethminer::{Miner, MinerService};
|
use ethminer::{Miner, MinerService};
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use daemonize::Daemonize;
|
use daemonize::Daemonize;
|
||||||
|
@ -84,7 +84,7 @@ impl<F, T> PollManager<F, T> where T: Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns number of block when last poll happend.
|
/// Returns number of block when last poll happend.
|
||||||
pub fn get_poll_info(&mut self, id: &PollId) -> Option<&PollInfo<F>> {
|
pub fn poll_info(&mut self, id: &PollId) -> Option<&PollInfo<F>> {
|
||||||
self.polls.prune();
|
self.polls.prune();
|
||||||
self.polls.get(id)
|
self.polls.get(id)
|
||||||
}
|
}
|
||||||
@ -124,21 +124,21 @@ mod tests {
|
|||||||
|
|
||||||
*time.borrow_mut() = 10;
|
*time.borrow_mut() = 10;
|
||||||
indexer.update_poll(&0, 21);
|
indexer.update_poll(&0, 21);
|
||||||
assert_eq!(indexer.get_poll_info(&0).unwrap().filter, false);
|
assert_eq!(indexer.poll_info(&0).unwrap().filter, false);
|
||||||
assert_eq!(indexer.get_poll_info(&0).unwrap().block_number, 21);
|
assert_eq!(indexer.poll_info(&0).unwrap().block_number, 21);
|
||||||
|
|
||||||
*time.borrow_mut() = 30;
|
*time.borrow_mut() = 30;
|
||||||
indexer.update_poll(&1, 23);
|
indexer.update_poll(&1, 23);
|
||||||
assert_eq!(indexer.get_poll_info(&1).unwrap().filter, true);
|
assert_eq!(indexer.poll_info(&1).unwrap().filter, true);
|
||||||
assert_eq!(indexer.get_poll_info(&1).unwrap().block_number, 23);
|
assert_eq!(indexer.poll_info(&1).unwrap().block_number, 23);
|
||||||
|
|
||||||
*time.borrow_mut() = 75;
|
*time.borrow_mut() = 75;
|
||||||
indexer.update_poll(&0, 30);
|
indexer.update_poll(&0, 30);
|
||||||
assert!(indexer.get_poll_info(&0).is_none());
|
assert!(indexer.poll_info(&0).is_none());
|
||||||
assert_eq!(indexer.get_poll_info(&1).unwrap().filter, true);
|
assert_eq!(indexer.poll_info(&1).unwrap().filter, true);
|
||||||
assert_eq!(indexer.get_poll_info(&1).unwrap().block_number, 23);
|
assert_eq!(indexer.poll_info(&1).unwrap().block_number, 23);
|
||||||
|
|
||||||
indexer.remove_poll(&1);
|
indexer.remove_poll(&1);
|
||||||
assert!(indexer.get_poll_info(&1).is_none());
|
assert!(indexer.poll_info(&1).is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Weak, Mutex, RwLock};
|
use std::sync::{Arc, Weak, Mutex, RwLock};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use ethsync::{EthSync, SyncState};
|
use ethsync::{SyncStatusProvider, SyncState};
|
||||||
use ethminer::{Miner, MinerService};
|
use ethminer::{MinerService};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
@ -27,7 +27,6 @@ use util::rlp::encode;
|
|||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::block::{IsBlock};
|
use ethcore::block::{IsBlock};
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
//#[macro_use] extern crate log;
|
|
||||||
use ethcore::ethereum::Ethash;
|
use ethcore::ethereum::Ethash;
|
||||||
use ethcore::ethereum::denominations::shannon;
|
use ethcore::ethereum::denominations::shannon;
|
||||||
use v1::traits::{Eth, EthFilter};
|
use v1::traits::{Eth, EthFilter};
|
||||||
@ -35,16 +34,20 @@ use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncIn
|
|||||||
use v1::helpers::{PollFilter, PollManager};
|
use v1::helpers::{PollFilter, PollManager};
|
||||||
|
|
||||||
/// Eth rpc implementation.
|
/// Eth rpc implementation.
|
||||||
pub struct EthClient {
|
pub struct EthClient<C, S, M>
|
||||||
client: Weak<Client>,
|
where C: BlockChainClient,
|
||||||
sync: Weak<EthSync>,
|
S: SyncStatusProvider,
|
||||||
miner: Weak<Miner>,
|
M: MinerService {
|
||||||
|
client: Weak<C>,
|
||||||
|
sync: Weak<S>,
|
||||||
|
miner: Weak<M>,
|
||||||
hashrates: RwLock<HashMap<H256, u64>>,
|
hashrates: RwLock<HashMap<H256, u64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthClient {
|
impl<C, S, M> EthClient<C, S, M> where C: BlockChainClient, S: SyncStatusProvider, M: MinerService {
|
||||||
|
|
||||||
/// Creates new EthClient.
|
/// Creates new EthClient.
|
||||||
pub fn new(client: &Arc<Client>, sync: &Arc<EthSync>, miner: &Arc<Miner>) -> Self {
|
pub fn new(client: &Arc<C>, sync: &Arc<S>, miner: &Arc<M>) -> Self {
|
||||||
EthClient {
|
EthClient {
|
||||||
client: Arc::downgrade(client),
|
client: Arc::downgrade(client),
|
||||||
sync: Arc::downgrade(sync),
|
sync: Arc::downgrade(sync),
|
||||||
@ -99,7 +102,10 @@ impl EthClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eth for EthClient {
|
impl<C, S, M> Eth for EthClient<C, S, M>
|
||||||
|
where C: BlockChainClient + 'static,
|
||||||
|
S: SyncStatusProvider + 'static,
|
||||||
|
M: MinerService + 'static {
|
||||||
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
||||||
match params {
|
match params {
|
||||||
Params::None => to_value(&U256::from(take_weak!(self.sync).status().protocol_version)),
|
Params::None => to_value(&U256::from(take_weak!(self.sync).status().protocol_version)),
|
||||||
@ -262,14 +268,14 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Eth filter rpc implementation.
|
/// Eth filter rpc implementation.
|
||||||
pub struct EthFilterClient {
|
pub struct EthFilterClient<C> where C: BlockChainClient {
|
||||||
client: Weak<Client>,
|
client: Weak<C>,
|
||||||
polls: Mutex<PollManager<PollFilter>>,
|
polls: Mutex<PollManager<PollFilter>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthFilterClient {
|
impl<C> EthFilterClient<C> where C: BlockChainClient {
|
||||||
/// Creates new Eth filter client.
|
/// Creates new Eth filter client.
|
||||||
pub fn new(client: &Arc<Client>) -> Self {
|
pub fn new(client: &Arc<C>) -> Self {
|
||||||
EthFilterClient {
|
EthFilterClient {
|
||||||
client: Arc::downgrade(client),
|
client: Arc::downgrade(client),
|
||||||
polls: Mutex::new(PollManager::new())
|
polls: Mutex::new(PollManager::new())
|
||||||
@ -277,7 +283,7 @@ impl EthFilterClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthFilter for EthFilterClient {
|
impl<C> EthFilter for EthFilterClient<C> where C: BlockChainClient + 'static {
|
||||||
fn new_filter(&self, params: Params) -> Result<Value, Error> {
|
fn new_filter(&self, params: Params) -> Result<Value, Error> {
|
||||||
from_params::<(Filter,)>(params)
|
from_params::<(Filter,)>(params)
|
||||||
.and_then(|(filter,)| {
|
.and_then(|(filter,)| {
|
||||||
@ -313,7 +319,7 @@ impl EthFilter for EthFilterClient {
|
|||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
from_params::<(Index,)>(params)
|
from_params::<(Index,)>(params)
|
||||||
.and_then(|(index,)| {
|
.and_then(|(index,)| {
|
||||||
let info = self.polls.lock().unwrap().get_poll_info(&index.value()).cloned();
|
let info = self.polls.lock().unwrap().poll_info(&index.value()).cloned();
|
||||||
match info {
|
match info {
|
||||||
None => Ok(Value::Array(vec![] as Vec<Value>)),
|
None => Ok(Value::Array(vec![] as Vec<Value>)),
|
||||||
Some(info) => match info.filter {
|
Some(info) => match info.filter {
|
||||||
|
@ -17,24 +17,24 @@
|
|||||||
//! Net rpc implementation.
|
//! Net rpc implementation.
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use ethsync::EthSync;
|
use ethsync::SyncStatusProvider;
|
||||||
use v1::traits::Net;
|
use v1::traits::Net;
|
||||||
|
|
||||||
/// Net rpc implementation.
|
/// Net rpc implementation.
|
||||||
pub struct NetClient {
|
pub struct NetClient<S> where S: SyncStatusProvider {
|
||||||
sync: Weak<EthSync>
|
sync: Weak<S>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetClient {
|
impl<S> NetClient<S> where S: SyncStatusProvider {
|
||||||
/// Creates new NetClient.
|
/// Creates new NetClient.
|
||||||
pub fn new(sync: &Arc<EthSync>) -> Self {
|
pub fn new(sync: &Arc<S>) -> Self {
|
||||||
NetClient {
|
NetClient {
|
||||||
sync: Arc::downgrade(sync)
|
sync: Arc::downgrade(sync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Net for NetClient {
|
impl<S> Net for NetClient<S> where S: SyncStatusProvider + 'static {
|
||||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||||
Ok(Value::U64(take_weak!(self.sync).status().protocol_version as u64))
|
Ok(Value::U64(take_weak!(self.sync).status().protocol_version as u64))
|
||||||
}
|
}
|
||||||
|
@ -1275,7 +1275,6 @@ impl ChainSync {
|
|||||||
pub fn chain_new_head(&mut self, io: &mut SyncIo) {
|
pub fn chain_new_head(&mut self, io: &mut SyncIo) {
|
||||||
self.miner.prepare_sealing(io.chain());
|
self.miner.prepare_sealing(io.chain());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -93,6 +93,12 @@ impl Default for SyncConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Current sync status
|
||||||
|
pub trait SyncStatusProvider: Send + Sync {
|
||||||
|
/// Get sync status
|
||||||
|
fn status(&self) -> SyncStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/// Ethereum network protocol handler
|
/// Ethereum network protocol handler
|
||||||
pub struct EthSync {
|
pub struct EthSync {
|
||||||
/// Shared blockchain client. TODO: this should evetually become an IPC endpoint
|
/// Shared blockchain client. TODO: this should evetually become an IPC endpoint
|
||||||
@ -114,11 +120,6 @@ impl EthSync {
|
|||||||
sync
|
sync
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get sync status
|
|
||||||
pub fn status(&self) -> SyncStatus {
|
|
||||||
self.sync.read().unwrap().status()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stop sync
|
/// Stop sync
|
||||||
pub fn stop(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
pub fn stop(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
||||||
self.sync.write().unwrap().abort(&mut NetSyncIo::new(io, self.chain.deref()));
|
self.sync.write().unwrap().abort(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||||
@ -128,6 +129,14 @@ impl EthSync {
|
|||||||
pub fn restart(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
pub fn restart(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
||||||
self.sync.write().unwrap().restart(&mut NetSyncIo::new(io, self.chain.deref()));
|
self.sync.write().unwrap().restart(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncStatusProvider for EthSync {
|
||||||
|
/// Get sync status
|
||||||
|
fn status(&self) -> SyncStatus {
|
||||||
|
self.sync.read().unwrap().status()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
||||||
|
@ -15,18 +15,18 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use ::SyncConfig;
|
||||||
use ethcore::client::{BlockChainClient, BlockStatus, TreeRoute, BlockChainInfo, TransactionId, BlockId, BlockQueueInfo};
|
use ethcore::client::{BlockChainClient, BlockStatus, TreeRoute, BlockChainInfo, TransactionId, BlockId, BlockQueueInfo};
|
||||||
use ethcore::header::{Header as BlockHeader, BlockNumber};
|
use ethcore::header::{Header as BlockHeader, BlockNumber};
|
||||||
use ethcore::block::*;
|
|
||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethminer::Miner;
|
|
||||||
use io::SyncIo;
|
|
||||||
use chain::ChainSync;
|
|
||||||
use ::SyncConfig;
|
|
||||||
use ethcore::receipt::Receipt;
|
use ethcore::receipt::Receipt;
|
||||||
use ethcore::transaction::{LocalizedTransaction, SignedTransaction, Transaction, Action};
|
use ethcore::transaction::{LocalizedTransaction, SignedTransaction, Transaction, Action};
|
||||||
use ethcore::filter::Filter;
|
use ethcore::filter::Filter;
|
||||||
use ethcore::log_entry::LocalizedLogEntry;
|
use ethcore::log_entry::LocalizedLogEntry;
|
||||||
|
use ethcore::block::{ClosedBlock, SealedBlock};
|
||||||
|
use ethminer::Miner;
|
||||||
|
use io::SyncIo;
|
||||||
|
use chain::ChainSync;
|
||||||
|
|
||||||
pub struct TestBlockChainClient {
|
pub struct TestBlockChainClient {
|
||||||
pub blocks: RwLock<HashMap<H256, Bytes>>,
|
pub blocks: RwLock<HashMap<H256, Bytes>>,
|
||||||
|
Loading…
Reference in New Issue
Block a user