refactored to merge client & client
This commit is contained in:
parent
4f732972bc
commit
8e252d5f1b
@ -29,7 +29,7 @@ ethcore-devtools = { path = "../devtools" }
|
|||||||
ethjson = { path = "../json" }
|
ethjson = { path = "../json" }
|
||||||
bloomchain = "0.1"
|
bloomchain = "0.1"
|
||||||
"ethcore-ipc" = { path = "../ipc/rpc" }
|
"ethcore-ipc" = { path = "../ipc/rpc" }
|
||||||
ethminer = { path = "../miner" }
|
rayon = "0.3.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jit = ["evmjit"]
|
jit = ["evmjit"]
|
||||||
|
@ -48,6 +48,7 @@ use trace;
|
|||||||
pub use types::blockchain_info::BlockChainInfo;
|
pub use types::blockchain_info::BlockChainInfo;
|
||||||
pub use types::block_status::BlockStatus;
|
pub use types::block_status::BlockStatus;
|
||||||
use evm::Factory as EvmFactory;
|
use evm::Factory as EvmFactory;
|
||||||
|
use miner::{Miner, MinerService, TransactionImportResult, AccountDetails};
|
||||||
|
|
||||||
impl fmt::Display for BlockChainInfo {
|
impl fmt::Display for BlockChainInfo {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
@ -90,7 +91,7 @@ pub struct Client<V = CanonVerifier> where V: Verifier {
|
|||||||
panic_handler: Arc<PanicHandler>,
|
panic_handler: Arc<PanicHandler>,
|
||||||
verifier: PhantomData<V>,
|
verifier: PhantomData<V>,
|
||||||
vm_factory: Arc<EvmFactory>,
|
vm_factory: Arc<EvmFactory>,
|
||||||
miner: Arc<MinerService>,
|
miner: Arc<Miner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const HISTORY: u64 = 1200;
|
const HISTORY: u64 = 1200;
|
||||||
@ -103,8 +104,8 @@ const CLIENT_DB_VER_STR: &'static str = "5.3";
|
|||||||
|
|
||||||
impl Client<CanonVerifier> {
|
impl Client<CanonVerifier> {
|
||||||
/// Create a new client with given spec and DB path.
|
/// Create a new client with given spec and DB path.
|
||||||
pub fn new(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel<NetSyncMessage> ) -> Result<Arc<Client>, ClientError> {
|
pub fn new(config: ClientConfig, spec: Spec, path: &Path, miner: Arc<Miner>, message_channel: IoChannel<NetSyncMessage> ) -> Result<Arc<Client>, ClientError> {
|
||||||
Client::<CanonVerifier>::new_with_verifier(config, spec, path, message_channel)
|
Client::<CanonVerifier>::new_with_verifier(config, spec, path, miner, message_channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +132,7 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
config: ClientConfig,
|
config: ClientConfig,
|
||||||
spec: Spec,
|
spec: Spec,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
|
miner: Arc<Miner>,
|
||||||
message_channel: IoChannel<NetSyncMessage>)
|
message_channel: IoChannel<NetSyncMessage>)
|
||||||
-> Result<Arc<Client<V>>, ClientError>
|
-> Result<Arc<Client<V>>, ClientError>
|
||||||
{
|
{
|
||||||
@ -162,6 +164,7 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
panic_handler: panic_handler,
|
panic_handler: panic_handler,
|
||||||
verifier: PhantomData,
|
verifier: PhantomData,
|
||||||
vm_factory: Arc::new(EvmFactory::new(config.vm_type)),
|
vm_factory: Arc::new(EvmFactory::new(config.vm_type)),
|
||||||
|
miner: miner,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Arc::new(client))
|
Ok(Arc::new(client))
|
||||||
@ -335,13 +338,13 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
{
|
{
|
||||||
if !imported_blocks.is_empty() && self.block_queue.queue_info().is_empty() {
|
if !imported_blocks.is_empty() && self.block_queue.queue_info().is_empty() {
|
||||||
let (enacted, retracted) = self.calculate_enacted_retracted(import_results);
|
let (enacted, retracted) = self.calculate_enacted_retracted(import_results);
|
||||||
self.miner.chain_new_blocks(imported_blocks, invalid_blocks, enacted, retracted);
|
self.miner.chain_new_blocks(self, &imported_blocks, &invalid_blocks, &enacted, &retracted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if self.chain_info().best_block_hash != original_best {
|
if self.chain_info().best_block_hash != original_best {
|
||||||
self.miner.update_sealing(&self);
|
self.miner.update_sealing(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,10 +708,21 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
fn last_hashes(&self) -> LastHashes {
|
fn last_hashes(&self) -> LastHashes {
|
||||||
self.build_last_hashes(self.chain.best_block_hash())
|
self.build_last_hashes(self.chain.best_block_hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, Error>> {
|
||||||
|
let fetch_account = |a: &Address| AccountDetails {
|
||||||
|
nonce: self.latest_nonce(a),
|
||||||
|
balance: self.latest_balance(a),
|
||||||
|
};
|
||||||
|
self.miner.import_transactions(transactions, fetch_account)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
|
self.miner.all_transactions()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> ExtendedBlockChainClient for Client<V> where V: Verifier {
|
impl<V> ExtendedBlockChainClient for Client<V> where V: Verifier {
|
||||||
// TODO [todr] Should be moved to miner crate eventually.
|
|
||||||
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
||||||
-> (Option<ClosedBlock>, HashSet<H256>) {
|
-> (Option<ClosedBlock>, HashSet<H256>) {
|
||||||
let engine = self.engine.deref().deref();
|
let engine = self.engine.deref().deref();
|
||||||
@ -774,26 +788,11 @@ impl<V> ExtendedBlockChainClient for Client<V> where V: Verifier {
|
|||||||
(Some(b), invalid_transactions)
|
(Some(b), invalid_transactions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO [todr] Should be moved to miner crate eventually.
|
|
||||||
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
||||||
block.try_seal(self.engine.deref().deref(), seal)
|
block.try_seal(self.engine.deref().deref(), seal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MiningClient for Client {
|
|
||||||
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, Error>> {
|
|
||||||
let fetch_account = |a: &Address| AccountDetails {
|
|
||||||
nonce: self.latest_nonce(a),
|
|
||||||
balance: self.latest_balance(a),
|
|
||||||
};
|
|
||||||
self.miner.import_transactions(transactions, fetch_account)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
|
||||||
self.miner.all_transactions()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MayPanic for Client {
|
impl MayPanic for Client {
|
||||||
fn on_panic<F>(&self, closure: F) where F: OnPanicListener {
|
fn on_panic<F>(&self, closure: F) where F: OnPanicListener {
|
||||||
self.panic_handler.on_panic(closure);
|
self.panic_handler.on_panic(closure);
|
||||||
|
@ -46,6 +46,8 @@ use error::{ImportResult, ExecutionError};
|
|||||||
use receipt::LocalizedReceipt;
|
use receipt::LocalizedReceipt;
|
||||||
use trace::LocalizedTrace;
|
use trace::LocalizedTrace;
|
||||||
use evm::Factory as EvmFactory;
|
use evm::Factory as EvmFactory;
|
||||||
|
use miner::{TransactionImportResult, AccountDetails};
|
||||||
|
use error::Error as EthError;
|
||||||
|
|
||||||
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
||||||
pub trait BlockChainClient : Sync + Send {
|
pub trait BlockChainClient : Sync + Send {
|
||||||
@ -174,6 +176,12 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
|
|
||||||
/// Get last hashes starting from best block.
|
/// Get last hashes starting from best block.
|
||||||
fn last_hashes(&self) -> LastHashes;
|
fn last_hashes(&self) -> LastHashes;
|
||||||
|
|
||||||
|
/// import transactions from network/other 3rd party
|
||||||
|
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, EthError>>;
|
||||||
|
|
||||||
|
/// list all transactions
|
||||||
|
fn all_transactions(&self) -> Vec<SignedTransaction>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended client interface used for mining
|
/// Extended client interface used for mining
|
||||||
@ -185,12 +193,3 @@ pub trait ExtendedBlockChainClient : BlockChainClient {
|
|||||||
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
||||||
-> (Option<ClosedBlock>, HashSet<H256>);
|
-> (Option<ClosedBlock>, HashSet<H256>);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended client interface that supports mining
|
|
||||||
pub trait MiningClient : BlockChainClient {
|
|
||||||
/// import transactions from network/other 3rd party
|
|
||||||
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, Error>>;
|
|
||||||
|
|
||||||
/// list all transactions
|
|
||||||
fn all_transactions(&self) -> Vec<SignedTransaction>;
|
|
||||||
}
|
|
||||||
|
@ -35,6 +35,9 @@ use executive::Executed;
|
|||||||
use error::{ExecutionError};
|
use error::{ExecutionError};
|
||||||
use trace::LocalizedTrace;
|
use trace::LocalizedTrace;
|
||||||
|
|
||||||
|
use miner::{TransactionImportResult, AccountDetails};
|
||||||
|
use error::Error as EthError;
|
||||||
|
|
||||||
/// Test client.
|
/// Test client.
|
||||||
pub struct TestBlockChainClient {
|
pub struct TestBlockChainClient {
|
||||||
/// Blocks.
|
/// Blocks.
|
||||||
@ -479,4 +482,12 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
fn block_traces(&self, _trace: BlockID) -> Option<Vec<LocalizedTrace>> {
|
fn block_traces(&self, _trace: BlockID) -> Option<Vec<LocalizedTrace>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, EthError>> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ extern crate crossbeam;
|
|||||||
extern crate ethjson;
|
extern crate ethjson;
|
||||||
extern crate bloomchain;
|
extern crate bloomchain;
|
||||||
#[macro_use] extern crate ethcore_ipc as ipc;
|
#[macro_use] extern crate ethcore_ipc as ipc;
|
||||||
|
extern crate rayon;
|
||||||
|
|
||||||
#[cfg(test)] extern crate ethcore_devtools as devtools;
|
#[cfg(test)] extern crate ethcore_devtools as devtools;
|
||||||
#[cfg(feature = "jit" )] extern crate evmjit;
|
#[cfg(feature = "jit" )] extern crate evmjit;
|
||||||
@ -109,6 +110,7 @@ pub mod views;
|
|||||||
pub mod pod_state;
|
pub mod pod_state;
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
pub mod migrations;
|
pub mod migrations;
|
||||||
|
pub mod miner;
|
||||||
|
|
||||||
mod blooms;
|
mod blooms;
|
||||||
mod db;
|
mod db;
|
||||||
|
@ -19,16 +19,16 @@ use std::sync::atomic::AtomicBool;
|
|||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use util::keys::store::{AccountService, AccountProvider};
|
use util::keys::store::{AccountService, AccountProvider};
|
||||||
use ethcore::views::{BlockView, HeaderView};
|
use views::{BlockView, HeaderView};
|
||||||
use ethcore::client::{ExtendedBlockChainClient, BlockID};
|
use client::{ExtendedBlockChainClient, BlockID};
|
||||||
use ethcore::block::{ClosedBlock, IsBlock};
|
use block::{ClosedBlock, IsBlock};
|
||||||
use ethcore::error::*;
|
use error::*;
|
||||||
use ethcore::client::{Executive, Executed, EnvInfo, TransactOptions};
|
use client::{Executive, Executed, EnvInfo, TransactOptions};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use transaction::SignedTransaction;
|
||||||
use ethcore::receipt::{Receipt};
|
use receipt::{Receipt};
|
||||||
use ethcore::spec::Spec;
|
use spec::Spec;
|
||||||
use ethcore::engine::Engine;
|
use engine::Engine;
|
||||||
use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
use miner::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
||||||
|
|
||||||
/// Keeps track of transactions using priority queue and holds currently mined block.
|
/// Keeps track of transactions using priority queue and holds currently mined block.
|
||||||
pub struct Miner {
|
pub struct Miner {
|
@ -26,12 +26,11 @@
|
|||||||
//! ```rust
|
//! ```rust
|
||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_util as util;
|
||||||
//! extern crate ethcore;
|
//! extern crate ethcore;
|
||||||
//! extern crate ethminer;
|
|
||||||
//! use std::env;
|
//! use std::env;
|
||||||
//! use util::network::{NetworkService, NetworkConfiguration};
|
//! use util::network::{NetworkService, NetworkConfiguration};
|
||||||
//! use ethcore::client::{Client, ClientConfig};
|
//! use client::{Client, ClientConfig};
|
||||||
//! use ethcore::ethereum;
|
//! use ethereum;
|
||||||
//! use ethminer::{Miner, MinerService};
|
//! use ethcore::miner::{Miner, MinerService};
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let miner: Miner = Miner::default();
|
//! let miner: Miner = Miner::default();
|
||||||
@ -43,30 +42,21 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate ethcore_util as util;
|
|
||||||
extern crate ethcore;
|
|
||||||
extern crate env_logger;
|
|
||||||
extern crate rayon;
|
|
||||||
|
|
||||||
mod miner;
|
mod miner;
|
||||||
mod external;
|
mod external;
|
||||||
mod transaction_queue;
|
mod transaction_queue;
|
||||||
|
|
||||||
pub use transaction_queue::{TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
pub use self::transaction_queue::{TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
||||||
pub use miner::{Miner};
|
pub use self::miner::{Miner};
|
||||||
pub use external::{ExternalMiner, ExternalMinerService};
|
pub use self::external::{ExternalMiner, ExternalMinerService};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use util::{H256, U256, Address, Bytes};
|
use util::{H256, U256, Address, Bytes};
|
||||||
use ethcore::client::{ExtendedBlockChainClient, Executed};
|
use client::{ExtendedBlockChainClient, Executed};
|
||||||
use ethcore::block::ClosedBlock;
|
use block::ClosedBlock;
|
||||||
use ethcore::receipt::Receipt;
|
use receipt::Receipt;
|
||||||
use ethcore::error::{Error, ExecutionError};
|
use error::{Error, ExecutionError};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use transaction::SignedTransaction;
|
||||||
|
|
||||||
/// Miner client API
|
/// Miner client API
|
||||||
pub trait MinerService : Send + Sync {
|
pub trait MinerService : Send + Sync {
|
@ -89,8 +89,8 @@ use std::collections::{HashMap, BTreeSet};
|
|||||||
use util::numbers::{Uint, U256};
|
use util::numbers::{Uint, U256};
|
||||||
use util::hash::{Address, H256};
|
use util::hash::{Address, H256};
|
||||||
use util::table::*;
|
use util::table::*;
|
||||||
use ethcore::transaction::*;
|
use transaction::*;
|
||||||
use ethcore::error::{Error, TransactionError};
|
use error::{Error, TransactionError};
|
||||||
|
|
||||||
/// Transaction origin
|
/// Transaction origin
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
@ -21,6 +21,7 @@ use util::panics::*;
|
|||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use error::*;
|
use error::*;
|
||||||
use client::{Client, ClientConfig};
|
use client::{Client, ClientConfig};
|
||||||
|
use miner::Miner;
|
||||||
|
|
||||||
/// Message type for external and internal events
|
/// Message type for external and internal events
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -54,14 +55,14 @@ pub struct ClientService {
|
|||||||
|
|
||||||
impl ClientService {
|
impl ClientService {
|
||||||
/// Start the service in a separate thread.
|
/// Start the service in a separate thread.
|
||||||
pub fn start(config: ClientConfig, spec: Spec, net_config: NetworkConfiguration, db_path: &Path) -> Result<ClientService, Error> {
|
pub fn start(config: ClientConfig, spec: Spec, net_config: NetworkConfiguration, db_path: &Path, miner: Arc<Miner>) -> Result<ClientService, Error> {
|
||||||
let panic_handler = PanicHandler::new_in_arc();
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
let mut net_service = try!(NetworkService::start(net_config));
|
let mut net_service = try!(NetworkService::start(net_config));
|
||||||
panic_handler.forward_from(&net_service);
|
panic_handler.forward_from(&net_service);
|
||||||
|
|
||||||
info!("Starting {}", net_service.host_info());
|
info!("Starting {}", net_service.host_info());
|
||||||
info!("Configured for {} using {:?} engine", spec.name, spec.engine.name());
|
info!("Configured for {} using {:?} engine", spec.name, spec.engine.name());
|
||||||
let client = try!(Client::new(config, spec, db_path, net_service.io().channel()));
|
let client = try!(Client::new(config, spec, db_path, miner, net_service.io().channel()));
|
||||||
panic_handler.forward_from(client.deref());
|
panic_handler.forward_from(client.deref());
|
||||||
let client_io = Arc::new(ClientIoHandler {
|
let client_io = Arc::new(ClientIoHandler {
|
||||||
client: client.clone()
|
client: client.clone()
|
||||||
|
Loading…
Reference in New Issue
Block a user