Merge branch 'ethminer_crate' into rpc_pending_filter
Conflicts: rpc/src/v1/helpers/poll_manager.rs rpc/src/v1/impls/eth.rs
This commit is contained in:
commit
2fd036b073
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -299,6 +299,7 @@ dependencies = [
|
||||
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -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.
|
||||
fn try_seal(&self, block: ClosedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, ClosedBlock>;
|
||||
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, Eq, PartialEq)]
|
||||
|
2
hook.sh
2
hook.sh
@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo "#!/bin/sh\ncargo test -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethminer --features dev-clippy" > ./.git/hooks/pre-push
|
||||
echo "#!/bin/sh\ncargo build --features dev-clippy && cargo test --no-run -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethminer --features dev-clippy" > ./.git/hooks/pre-push
|
||||
chmod +x ./.git/hooks/pre-push
|
||||
|
@ -15,8 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(feature="dev", feature(plugin))]
|
||||
#![cfg_attr(feature="dev", plugin(clippy))]
|
||||
#![cfg_attr(all(nightly, feature="dev"), feature(plugin))]
|
||||
#![cfg_attr(all(nightly, feature="dev"), plugin(clippy))]
|
||||
|
||||
//! Miner module
|
||||
//! Keeps track of transactions and mined block.
|
||||
@ -62,5 +62,6 @@ extern crate rayon;
|
||||
mod miner;
|
||||
mod transaction_queue;
|
||||
|
||||
pub use transaction_queue::TransactionQueue;
|
||||
pub use miner::{Miner, MinerService};
|
||||
|
||||
|
@ -25,7 +25,7 @@ use ethcore::transaction::SignedTransaction;
|
||||
use transaction_queue::{TransactionQueue};
|
||||
|
||||
/// Miner client API
|
||||
pub trait MinerService {
|
||||
pub trait MinerService : Send + Sync {
|
||||
|
||||
/// Returns miner's status.
|
||||
fn status(&self) -> MinerStatus;
|
||||
|
@ -28,13 +28,13 @@
|
||||
//! ```rust
|
||||
//! extern crate ethcore_util as util;
|
||||
//! extern crate ethcore;
|
||||
//! extern crate ethsync;
|
||||
//! extern crate ethminer;
|
||||
//! extern crate rustc_serialize;
|
||||
//!
|
||||
//! use util::crypto::KeyPair;
|
||||
//! use util::hash::Address;
|
||||
//! use util::numbers::{Uint, U256};
|
||||
//! use ethsync::TransactionQueue;
|
||||
//! use ethminer::TransactionQueue;
|
||||
//! use ethcore::transaction::*;
|
||||
//! use rustc_serialize::hex::FromHex;
|
||||
//!
|
||||
|
@ -50,7 +50,7 @@ use ethcore::spec::*;
|
||||
use ethcore::client::*;
|
||||
use ethcore::service::{ClientService, NetSyncMessage};
|
||||
use ethcore::ethereum;
|
||||
use ethsync::{EthSync, SyncConfig};
|
||||
use ethsync::{EthSync, SyncConfig, SyncProvider};
|
||||
use ethminer::{Miner, MinerService};
|
||||
use docopt::Docopt;
|
||||
use daemonize::Daemonize;
|
||||
@ -81,7 +81,7 @@ Protocol Options:
|
||||
or olympic, frontier, homestead, mainnet, morden, or testnet [default: homestead].
|
||||
--testnet Equivalent to --chain testnet (geth-compatible).
|
||||
--networkid INDEX Override the network identifier from the chain we are on.
|
||||
--archive Client should not prune the state/storage trie.
|
||||
--pruning Client should prune the state/storage trie.
|
||||
-d --datadir PATH Specify the database & configuration directory path [default: $HOME/.parity]
|
||||
--keys-path PATH Specify the path for JSON key files to be found [default: $HOME/.web3/keys]
|
||||
--identity NAME Specify your node's name.
|
||||
@ -143,7 +143,7 @@ struct Args {
|
||||
flag_identity: String,
|
||||
flag_cache: Option<usize>,
|
||||
flag_keys_path: String,
|
||||
flag_archive: bool,
|
||||
flag_pruning: bool,
|
||||
flag_no_bootstrap: bool,
|
||||
flag_listen_address: String,
|
||||
flag_public_address: Option<String>,
|
||||
@ -364,7 +364,7 @@ impl Configuration {
|
||||
client_config.blockchain.max_cache_size = self.args.flag_cache_max_size;
|
||||
}
|
||||
}
|
||||
client_config.prefer_journal = !self.args.flag_archive;
|
||||
client_config.prefer_journal = self.args.flag_pruning;
|
||||
client_config.name = self.args.flag_identity.clone();
|
||||
client_config.queue.max_mem_use = self.args.flag_queue_max_size;
|
||||
client_config
|
||||
|
@ -97,7 +97,7 @@ impl<F, T> PollManager<F, T> where T: Timer {
|
||||
}
|
||||
|
||||
/// 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.prune();
|
||||
self.polls.get(id)
|
||||
}
|
||||
@ -156,22 +156,22 @@ mod tests {
|
||||
|
||||
*time.borrow_mut() = 10;
|
||||
indexer.update_poll(&0, 21);
|
||||
assert_eq!(indexer.get_poll_info(&0).unwrap().filter, false);
|
||||
assert_eq!(indexer.get_poll_info(&0).unwrap().block_number, 21);
|
||||
assert_eq!(indexer.poll_info(&0).unwrap().filter, false);
|
||||
assert_eq!(indexer.poll_info(&0).unwrap().block_number, 21);
|
||||
|
||||
*time.borrow_mut() = 30;
|
||||
indexer.update_poll(&1, 23);
|
||||
assert_eq!(indexer.get_poll_info(&1).unwrap().filter, true);
|
||||
assert_eq!(indexer.get_poll_info(&1).unwrap().block_number, 23);
|
||||
assert_eq!(indexer.poll_info(&1).unwrap().filter, true);
|
||||
assert_eq!(indexer.poll_info(&1).unwrap().block_number, 23);
|
||||
|
||||
*time.borrow_mut() = 75;
|
||||
indexer.update_poll(&0, 30);
|
||||
assert!(indexer.get_poll_info(&0).is_none());
|
||||
assert_eq!(indexer.get_poll_info(&1).unwrap().filter, true);
|
||||
assert_eq!(indexer.get_poll_info(&1).unwrap().block_number, 23);
|
||||
assert!(indexer.poll_info(&0).is_none());
|
||||
assert_eq!(indexer.poll_info(&1).unwrap().filter, true);
|
||||
assert_eq!(indexer.poll_info(&1).unwrap().block_number, 23);
|
||||
|
||||
indexer.remove_poll(&1);
|
||||
assert!(indexer.get_poll_info(&1).is_none());
|
||||
assert!(indexer.poll_info(&1).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -18,8 +18,8 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::{Arc, Weak, Mutex, RwLock};
|
||||
use std::ops::Deref;
|
||||
use ethsync::{EthSync, SyncState};
|
||||
use ethminer::{Miner, MinerService};
|
||||
use ethsync::{SyncProvider, SyncState};
|
||||
use ethminer::{MinerService};
|
||||
use jsonrpc_core::*;
|
||||
use util::numbers::*;
|
||||
use util::sha3::*;
|
||||
@ -27,7 +27,6 @@ use util::rlp::encode;
|
||||
use ethcore::client::*;
|
||||
use ethcore::block::{IsBlock};
|
||||
use ethcore::views::*;
|
||||
//#[macro_use] extern crate log;
|
||||
use ethcore::ethereum::Ethash;
|
||||
use ethcore::ethereum::denominations::shannon;
|
||||
use v1::traits::{Eth, EthFilter};
|
||||
@ -35,16 +34,22 @@ use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncIn
|
||||
use v1::helpers::{PollFilter, PollManager};
|
||||
|
||||
/// Eth rpc implementation.
|
||||
pub struct EthClient {
|
||||
client: Weak<Client>,
|
||||
sync: Weak<EthSync>,
|
||||
miner: Weak<Miner>,
|
||||
pub struct EthClient<C, S, M>
|
||||
where C: BlockChainClient,
|
||||
S: SyncProvider,
|
||||
M: MinerService {
|
||||
client: Weak<C>,
|
||||
sync: Weak<S>,
|
||||
miner: Weak<M>,
|
||||
hashrates: RwLock<HashMap<H256, u64>>,
|
||||
}
|
||||
|
||||
impl EthClient {
|
||||
impl<C, S, M> EthClient<C, S, M>
|
||||
where C: BlockChainClient,
|
||||
S: SyncProvider,
|
||||
M: MinerService {
|
||||
/// 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 {
|
||||
client: Arc::downgrade(client),
|
||||
sync: Arc::downgrade(sync),
|
||||
@ -99,7 +104,10 @@ impl EthClient {
|
||||
}
|
||||
}
|
||||
|
||||
impl Eth for EthClient {
|
||||
impl<C, S, M> Eth for EthClient<C, S, M>
|
||||
where C: BlockChainClient + 'static,
|
||||
S: SyncProvider + 'static,
|
||||
M: MinerService + 'static {
|
||||
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => to_value(&U256::from(take_weak!(self.sync).status().protocol_version)),
|
||||
@ -262,15 +270,21 @@ impl Eth for EthClient {
|
||||
}
|
||||
|
||||
/// Eth filter rpc implementation.
|
||||
pub struct EthFilterClient {
|
||||
client: Weak<Client>,
|
||||
miner: Weak<Miner>,
|
||||
pub struct EthFilterClient<C, M>
|
||||
where C: BlockChainClient,
|
||||
M: MinerService {
|
||||
|
||||
client: Weak<C>,
|
||||
miner: Weak<M>,
|
||||
polls: Mutex<PollManager<PollFilter>>,
|
||||
}
|
||||
|
||||
impl EthFilterClient {
|
||||
impl<C, M> EthFilterClient<C, M>
|
||||
where C: BlockChainClient,
|
||||
M: MinerService {
|
||||
|
||||
/// Creates new Eth filter client.
|
||||
pub fn new(client: &Arc<Client>, miner: &Arc<Miner>) -> Self {
|
||||
pub fn new(client: &Arc<C>, miner: &Arc<M>) -> Self {
|
||||
EthFilterClient {
|
||||
client: Arc::downgrade(client),
|
||||
miner: Arc::downgrade(miner),
|
||||
@ -279,7 +293,10 @@ impl EthFilterClient {
|
||||
}
|
||||
}
|
||||
|
||||
impl EthFilter for EthFilterClient {
|
||||
impl<C, M> EthFilter for EthFilterClient<C, M>
|
||||
where C: BlockChainClient + 'static,
|
||||
M: MinerService + 'static {
|
||||
|
||||
fn new_filter(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Filter,)>(params)
|
||||
.and_then(|(filter,)| {
|
||||
@ -320,7 +337,7 @@ impl EthFilter for EthFilterClient {
|
||||
let client = take_weak!(self.client);
|
||||
from_params::<(Index,)>(params)
|
||||
.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 {
|
||||
None => Ok(Value::Array(vec![] as Vec<Value>)),
|
||||
Some(info) => match info.filter {
|
||||
|
@ -17,24 +17,24 @@
|
||||
//! Net rpc implementation.
|
||||
use std::sync::{Arc, Weak};
|
||||
use jsonrpc_core::*;
|
||||
use ethsync::EthSync;
|
||||
use ethsync::SyncProvider;
|
||||
use v1::traits::Net;
|
||||
|
||||
/// Net rpc implementation.
|
||||
pub struct NetClient {
|
||||
sync: Weak<EthSync>
|
||||
pub struct NetClient<S> where S: SyncProvider {
|
||||
sync: Weak<S>
|
||||
}
|
||||
|
||||
impl NetClient {
|
||||
impl<S> NetClient<S> where S: SyncProvider {
|
||||
/// Creates new NetClient.
|
||||
pub fn new(sync: &Arc<EthSync>) -> Self {
|
||||
pub fn new(sync: &Arc<S>) -> Self {
|
||||
NetClient {
|
||||
sync: Arc::downgrade(sync)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Net for NetClient {
|
||||
impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
|
||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||
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) {
|
||||
self.miner.prepare_sealing(io.chain());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -31,18 +31,21 @@
|
||||
//! extern crate ethcore_util as util;
|
||||
//! extern crate ethcore;
|
||||
//! extern crate ethsync;
|
||||
//! extern crate ethminer;
|
||||
//! use std::env;
|
||||
//! use std::sync::Arc;
|
||||
//! use util::network::{NetworkService, NetworkConfiguration};
|
||||
//! use ethcore::client::{Client, ClientConfig};
|
||||
//! use ethsync::{EthSync, SyncConfig};
|
||||
//! use ethminer::Miner;
|
||||
//! use ethcore::ethereum;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut service = NetworkService::start(NetworkConfiguration::new()).unwrap();
|
||||
//! let dir = env::temp_dir();
|
||||
//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()).unwrap();
|
||||
//! EthSync::register(&mut service, SyncConfig::default(), client);
|
||||
//! let miner = Miner::new();
|
||||
//! EthSync::register(&mut service, SyncConfig::default(), client, miner);
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
@ -93,6 +96,12 @@ impl Default for SyncConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Current sync status
|
||||
pub trait SyncProvider: Send + Sync {
|
||||
/// Get sync status
|
||||
fn status(&self) -> SyncStatus;
|
||||
}
|
||||
|
||||
/// Ethereum network protocol handler
|
||||
pub struct EthSync {
|
||||
/// Shared blockchain client. TODO: this should evetually become an IPC endpoint
|
||||
@ -114,11 +123,6 @@ impl EthSync {
|
||||
sync
|
||||
}
|
||||
|
||||
/// Get sync status
|
||||
pub fn status(&self) -> SyncStatus {
|
||||
self.sync.read().unwrap().status()
|
||||
}
|
||||
|
||||
/// Stop sync
|
||||
pub fn stop(&mut self, io: &mut NetworkContext<SyncMessage>) {
|
||||
self.sync.write().unwrap().abort(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||
@ -130,6 +134,13 @@ impl EthSync {
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncProvider for EthSync {
|
||||
/// Get sync status
|
||||
fn status(&self) -> SyncStatus {
|
||||
self.sync.read().unwrap().status()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
||||
fn initialize(&self, io: &NetworkContext<SyncMessage>) {
|
||||
io.register_timer(0, 1000).expect("Error registering sync timer");
|
||||
|
@ -15,18 +15,18 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use util::*;
|
||||
use ::SyncConfig;
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, TreeRoute, BlockChainInfo, TransactionId, BlockId, BlockQueueInfo};
|
||||
use ethcore::header::{Header as BlockHeader, BlockNumber};
|
||||
use ethcore::block::*;
|
||||
use ethcore::error::*;
|
||||
use ethminer::Miner;
|
||||
use io::SyncIo;
|
||||
use chain::ChainSync;
|
||||
use ::SyncConfig;
|
||||
use ethcore::receipt::Receipt;
|
||||
use ethcore::transaction::{LocalizedTransaction, SignedTransaction, Transaction, Action};
|
||||
use ethcore::filter::Filter;
|
||||
use ethcore::log_entry::LocalizedLogEntry;
|
||||
use ethcore::block::{ClosedBlock, SealedBlock};
|
||||
use ethminer::Miner;
|
||||
use io::SyncIo;
|
||||
use chain::ChainSync;
|
||||
|
||||
pub struct TestBlockChainClient {
|
||||
pub blocks: RwLock<HashMap<H256, Bytes>>,
|
||||
|
Loading…
Reference in New Issue
Block a user