Merge pull request #1195 from ethcore/client-refact
Client & Miner refactoring
This commit is contained in:
commit
e170916563
@ -33,7 +33,7 @@ env:
|
|||||||
global:
|
global:
|
||||||
# GH_TOKEN
|
# GH_TOKEN
|
||||||
- secure: bumJASbZSU8bxJ0EyPUJmu16AiV9EXOpyOj86Jlq/Ty9CfwGqsSXt96uDyE+OUJf34RUFQMsw0nk37/zC4lcn6kqk2wpuH3N/o85Zo/cVZY/NusBWLQqtT5VbYWsV+u2Ua4Tmmsw8yVYQhYwU2ZOejNpflL+Cs9XGgORp1L+/gMRMC2y5Se6ZhwnKPQlRJ8LGsG1dzjQULxzADIt3/zuspNBS8a2urJwlHfGMkvHDoUWCviP/GXoSqw3TZR7FmKyxE19I8n9+iSvm9+oZZquvcgfUxMHn8Gq/b44UbPvjtFOg2yam4xdWXF/RyWCHdc/R9EHorSABeCbefIsm+zcUF3/YQxwpSxM4IZEeH2rTiC7dcrsKw3XsO16xFQz5YI5Bay+CT/wTdMmJd7DdYz7Dyf+pOvcM9WOf/zorxYWSBOMYy0uzbusU2iyIghQ82s7E/Ahg+WARtPgkuTLSB5aL1oCTBKHqQscMr7lo5Ti6RpWLxEdTQMBznc+bMr+6dEtkEcG9zqc6cE9XX+ox3wTU6+HVMfQ1ltCntJ4UKcw3A6INEbw9wgocQa812CIASQ2fE+SCAbz6JxBjIAlFUnD1lUB7S8PdMPwn9plfQgKQ2A5YZqg6FnBdf0rQXIJYxQWKHXj/rBHSUCT0tHACDlzTA+EwWggvkP5AGIxRxm8jhw=
|
- secure: bumJASbZSU8bxJ0EyPUJmu16AiV9EXOpyOj86Jlq/Ty9CfwGqsSXt96uDyE+OUJf34RUFQMsw0nk37/zC4lcn6kqk2wpuH3N/o85Zo/cVZY/NusBWLQqtT5VbYWsV+u2Ua4Tmmsw8yVYQhYwU2ZOejNpflL+Cs9XGgORp1L+/gMRMC2y5Se6ZhwnKPQlRJ8LGsG1dzjQULxzADIt3/zuspNBS8a2urJwlHfGMkvHDoUWCviP/GXoSqw3TZR7FmKyxE19I8n9+iSvm9+oZZquvcgfUxMHn8Gq/b44UbPvjtFOg2yam4xdWXF/RyWCHdc/R9EHorSABeCbefIsm+zcUF3/YQxwpSxM4IZEeH2rTiC7dcrsKw3XsO16xFQz5YI5Bay+CT/wTdMmJd7DdYz7Dyf+pOvcM9WOf/zorxYWSBOMYy0uzbusU2iyIghQ82s7E/Ahg+WARtPgkuTLSB5aL1oCTBKHqQscMr7lo5Ti6RpWLxEdTQMBznc+bMr+6dEtkEcG9zqc6cE9XX+ox3wTU6+HVMfQ1ltCntJ4UKcw3A6INEbw9wgocQa812CIASQ2fE+SCAbz6JxBjIAlFUnD1lUB7S8PdMPwn9plfQgKQ2A5YZqg6FnBdf0rQXIJYxQWKHXj/rBHSUCT0tHACDlzTA+EwWggvkP5AGIxRxm8jhw=
|
||||||
- TARGETS="-p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethminer -p ethjson -p ethcore-dapps -p ethcore-signer"
|
- TARGETS="-p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethjson -p ethcore-dapps -p ethcore-signer"
|
||||||
- ARCHIVE_SUFFIX="-${TRAVIS_OS_NAME}-${TRAVIS_TAG}"
|
- ARCHIVE_SUFFIX="-${TRAVIS_OS_NAME}-${TRAVIS_TAG}"
|
||||||
- KCOV_FEATURES=""
|
- KCOV_FEATURES=""
|
||||||
- KCOV_CMD="./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /usr/,/.cargo,/root/.multirust,src/tests,util/json-tests,util/src/network/tests,sync/src/tests,ethcore/src/tests,ethcore/src/evm/tests target/kcov"
|
- KCOV_CMD="./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /usr/,/.cargo,/root/.multirust,src/tests,util/json-tests,util/src/network/tests,sync/src/tests,ethcore/src/tests,ethcore/src/evm/tests target/kcov"
|
||||||
@ -72,7 +72,6 @@ after_success: |
|
|||||||
$KCOV_CMD target/debug/deps/ethcore_rpc-* &&
|
$KCOV_CMD target/debug/deps/ethcore_rpc-* &&
|
||||||
$KCOV_CMD target/debug/deps/ethcore_dapps-* &&
|
$KCOV_CMD target/debug/deps/ethcore_dapps-* &&
|
||||||
$KCOV_CMD target/debug/deps/ethcore_signer-* &&
|
$KCOV_CMD target/debug/deps/ethcore_signer-* &&
|
||||||
$KCOV_CMD target/debug/deps/ethminer-* &&
|
|
||||||
$KCOV_CMD target/debug/deps/ethjson-* &&
|
$KCOV_CMD target/debug/deps/ethjson-* &&
|
||||||
$KCOV_CMD target/debug/parity-* &&
|
$KCOV_CMD target/debug/parity-* &&
|
||||||
[ $TRAVIS_BRANCH = master ] &&
|
[ $TRAVIS_BRANCH = master ] &&
|
||||||
|
18
Cargo.lock
generated
18
Cargo.lock
generated
@ -17,7 +17,6 @@ dependencies = [
|
|||||||
"ethcore-rpc 1.2.0",
|
"ethcore-rpc 1.2.0",
|
||||||
"ethcore-signer 1.2.0",
|
"ethcore-signer 1.2.0",
|
||||||
"ethcore-util 1.2.0",
|
"ethcore-util 1.2.0",
|
||||||
"ethminer 1.2.0",
|
|
||||||
"ethsync 1.2.0",
|
"ethsync 1.2.0",
|
||||||
"fdlimit 0.1.0",
|
"fdlimit 0.1.0",
|
||||||
"hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -255,6 +254,7 @@ dependencies = [
|
|||||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rayon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -334,7 +334,6 @@ dependencies = [
|
|||||||
"ethcore-devtools 1.2.0",
|
"ethcore-devtools 1.2.0",
|
||||||
"ethcore-util 1.2.0",
|
"ethcore-util 1.2.0",
|
||||||
"ethjson 0.1.0",
|
"ethjson 0.1.0",
|
||||||
"ethminer 1.2.0",
|
|
||||||
"ethsync 1.2.0",
|
"ethsync 1.2.0",
|
||||||
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
|
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
|
||||||
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -410,20 +409,6 @@ dependencies = [
|
|||||||
"syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ethminer"
|
|
||||||
version = "1.2.0"
|
|
||||||
dependencies = [
|
|
||||||
"clippy 0.0.69 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"ethcore 1.2.0",
|
|
||||||
"ethcore-util 1.2.0",
|
|
||||||
"log 0.3.6 (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.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ethsync"
|
name = "ethsync"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@ -432,7 +417,6 @@ dependencies = [
|
|||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethcore 1.2.0",
|
"ethcore 1.2.0",
|
||||||
"ethcore-util 1.2.0",
|
"ethcore-util 1.2.0",
|
||||||
"ethminer 1.2.0",
|
|
||||||
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -27,7 +27,6 @@ clippy = { version = "0.0.69", optional = true}
|
|||||||
ethcore = { path = "ethcore" }
|
ethcore = { path = "ethcore" }
|
||||||
ethcore-util = { path = "util" }
|
ethcore-util = { path = "util" }
|
||||||
ethsync = { path = "sync" }
|
ethsync = { path = "sync" }
|
||||||
ethminer = { path = "miner" }
|
|
||||||
ethcore-devtools = { path = "devtools" }
|
ethcore-devtools = { path = "devtools" }
|
||||||
ethcore-rpc = { path = "rpc", optional = true }
|
ethcore-rpc = { path = "rpc", optional = true }
|
||||||
ethcore-signer = { path = "signer", optional = true }
|
ethcore-signer = { path = "signer", optional = true }
|
||||||
@ -46,7 +45,7 @@ default-features = false
|
|||||||
default = ["rpc", "dapps", "ethcore-signer"]
|
default = ["rpc", "dapps", "ethcore-signer"]
|
||||||
rpc = ["ethcore-rpc"]
|
rpc = ["ethcore-rpc"]
|
||||||
dapps = ["ethcore-dapps"]
|
dapps = ["ethcore-dapps"]
|
||||||
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev", "ethcore-rpc/dev", "ethminer/dev",
|
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev", "ethcore-rpc/dev",
|
||||||
"ethcore-dapps/dev", "ethcore-signer/dev"]
|
"ethcore-dapps/dev", "ethcore-signer/dev"]
|
||||||
travis-beta = ["ethcore/json-tests"]
|
travis-beta = ["ethcore/json-tests"]
|
||||||
travis-nightly = ["ethcore/json-tests", "dev"]
|
travis-nightly = ["ethcore/json-tests", "dev"]
|
||||||
|
@ -29,6 +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" }
|
||||||
|
rayon = "0.3.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jit = ["evmjit"]
|
jit = ["evmjit"]
|
||||||
|
@ -37,7 +37,7 @@ use filter::Filter;
|
|||||||
use log_entry::LocalizedLogEntry;
|
use log_entry::LocalizedLogEntry;
|
||||||
use block_queue::{BlockQueue, BlockQueueInfo};
|
use block_queue::{BlockQueue, BlockQueueInfo};
|
||||||
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
||||||
use client::{BlockID, TransactionID, UncleID, TraceId, ClientConfig, BlockChainClient, TraceFilter};
|
use client::{BlockID, TransactionID, UncleID, TraceId, ClientConfig, BlockChainClient, MiningBlockChainClient, TraceFilter};
|
||||||
use client::Error as ClientError;
|
use client::Error as ClientError;
|
||||||
use env_info::EnvInfo;
|
use env_info::EnvInfo;
|
||||||
use executive::{Executive, Executed, TransactOptions, contract_address};
|
use executive::{Executive, Executed, TransactOptions, contract_address};
|
||||||
@ -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,6 +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<Miner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const HISTORY: u64 = 1200;
|
const HISTORY: u64 = 1200;
|
||||||
@ -102,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,14 @@ pub fn append_path(path: &Path, item: &str) -> String {
|
|||||||
|
|
||||||
impl<V> Client<V> where V: Verifier {
|
impl<V> Client<V> where V: Verifier {
|
||||||
/// Create a new client with given spec and DB path and custom verifier.
|
/// Create a new client with given spec and DB path and custom verifier.
|
||||||
pub fn new_with_verifier(config: ClientConfig, spec: Spec, path: &Path, message_channel: IoChannel<NetSyncMessage> ) -> Result<Arc<Client<V>>, ClientError> {
|
pub fn new_with_verifier(
|
||||||
|
config: ClientConfig,
|
||||||
|
spec: Spec,
|
||||||
|
path: &Path,
|
||||||
|
miner: Arc<Miner>,
|
||||||
|
message_channel: IoChannel<NetSyncMessage>)
|
||||||
|
-> Result<Arc<Client<V>>, ClientError>
|
||||||
|
{
|
||||||
let path = get_db_path(path, config.pruning, spec.genesis_header().hash());
|
let path = get_db_path(path, config.pruning, spec.genesis_header().hash());
|
||||||
let gb = spec.genesis_block();
|
let gb = spec.genesis_block();
|
||||||
let chain = Arc::new(BlockChain::new(config.blockchain, &gb, &path));
|
let chain = Arc::new(BlockChain::new(config.blockchain, &gb, &path));
|
||||||
@ -155,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))
|
||||||
@ -328,6 +338,11 @@ 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);
|
||||||
|
|
||||||
|
if self.queue_info().is_empty() {
|
||||||
|
self.miner.chain_new_blocks(self, &imported_blocks, &invalid_blocks, &enacted, &retracted);
|
||||||
|
}
|
||||||
|
|
||||||
io.send(NetworkIoMessage::User(SyncMessage::NewChainBlocks {
|
io.send(NetworkIoMessage::User(SyncMessage::NewChainBlocks {
|
||||||
imported: imported_blocks,
|
imported: imported_blocks,
|
||||||
invalid: invalid_blocks,
|
invalid: invalid_blocks,
|
||||||
@ -339,7 +354,7 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
|
|
||||||
{
|
{
|
||||||
if self.chain_info().best_block_hash != original_best {
|
if self.chain_info().best_block_hash != original_best {
|
||||||
io.send(NetworkIoMessage::User(SyncMessage::NewChainHead)).unwrap();
|
self.miner.update_sealing(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,81 +463,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
Executive::new(&mut state, &env_info, self.engine.deref().deref(), &self.vm_factory).transact(t, options)
|
Executive::new(&mut state, &env_info, self.engine.deref().deref(), &self.vm_factory).transact(t, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO [todr] Should be moved to miner crate eventually.
|
|
||||||
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
|
||||||
block.try_seal(self.engine.deref().deref(), seal)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_factory(&self) -> &EvmFactory {
|
fn vm_factory(&self) -> &EvmFactory {
|
||||||
&self.vm_factory
|
&self.vm_factory
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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>)
|
|
||||||
-> (Option<ClosedBlock>, HashSet<H256>) {
|
|
||||||
let engine = self.engine.deref().deref();
|
|
||||||
let h = self.chain.best_block_hash();
|
|
||||||
let mut invalid_transactions = HashSet::new();
|
|
||||||
|
|
||||||
let mut b = OpenBlock::new(
|
|
||||||
engine,
|
|
||||||
&self.vm_factory,
|
|
||||||
false, // TODO: this will need to be parameterised once we want to do immediate mining insertion.
|
|
||||||
self.state_db.lock().unwrap().boxed_clone(),
|
|
||||||
match self.chain.block_header(&h) { Some(ref x) => x, None => { return (None, invalid_transactions) } },
|
|
||||||
self.build_last_hashes(h.clone()),
|
|
||||||
author,
|
|
||||||
gas_floor_target,
|
|
||||||
extra_data,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add uncles
|
|
||||||
self.chain
|
|
||||||
.find_uncle_headers(&h, engine.maximum_uncle_age())
|
|
||||||
.unwrap()
|
|
||||||
.into_iter()
|
|
||||||
.take(engine.maximum_uncle_count())
|
|
||||||
.foreach(|h| {
|
|
||||||
b.push_uncle(h).unwrap();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add transactions
|
|
||||||
let block_number = b.block().header().number();
|
|
||||||
let min_tx_gas = U256::from(self.engine.schedule(&b.env_info()).tx_gas);
|
|
||||||
|
|
||||||
for tx in transactions {
|
|
||||||
// Push transaction to block
|
|
||||||
let hash = tx.hash();
|
|
||||||
let import = b.push_transaction(tx, None);
|
|
||||||
|
|
||||||
match import {
|
|
||||||
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, .. })) => {
|
|
||||||
trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash);
|
|
||||||
// Exit early if gas left is smaller then min_tx_gas
|
|
||||||
if gas_limit - gas_used < min_tx_gas {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
invalid_transactions.insert(hash);
|
|
||||||
trace!(target: "miner",
|
|
||||||
"Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}",
|
|
||||||
block_number, hash, e);
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// And close
|
|
||||||
let b = b.close();
|
|
||||||
trace!(target: "miner", "Sealing: number={}, hash={}, diff={}",
|
|
||||||
b.block().header().number(),
|
|
||||||
b.hash(),
|
|
||||||
b.block().header().difficulty()
|
|
||||||
);
|
|
||||||
(Some(b), invalid_transactions)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
||||||
Self::block_hash(&self.chain, id).and_then(|hash| self.chain.block(&hash).map(|bytes| BlockView::new(&bytes).rlp().at(0).as_raw().to_vec()))
|
Self::block_hash(&self.chain, id).and_then(|hash| self.chain.block(&hash).map(|bytes| BlockView::new(&bytes).rlp().at(0).as_raw().to_vec()))
|
||||||
}
|
}
|
||||||
@ -774,6 +718,89 @@ 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> MiningBlockChainClient for Client<V> where V: Verifier {
|
||||||
|
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
||||||
|
-> (Option<ClosedBlock>, HashSet<H256>) {
|
||||||
|
let engine = self.engine.deref().deref();
|
||||||
|
let h = self.chain.best_block_hash();
|
||||||
|
let mut invalid_transactions = HashSet::new();
|
||||||
|
|
||||||
|
let mut b = OpenBlock::new(
|
||||||
|
engine,
|
||||||
|
&self.vm_factory,
|
||||||
|
false, // TODO: this will need to be parameterised once we want to do immediate mining insertion.
|
||||||
|
self.state_db.lock().unwrap().boxed_clone(),
|
||||||
|
match self.chain.block_header(&h) { Some(ref x) => x, None => { return (None, invalid_transactions) } },
|
||||||
|
self.build_last_hashes(h.clone()),
|
||||||
|
author,
|
||||||
|
gas_floor_target,
|
||||||
|
extra_data,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add uncles
|
||||||
|
self.chain
|
||||||
|
.find_uncle_headers(&h, engine.maximum_uncle_age())
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.take(engine.maximum_uncle_count())
|
||||||
|
.foreach(|h| {
|
||||||
|
b.push_uncle(h).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add transactions
|
||||||
|
let block_number = b.block().header().number();
|
||||||
|
let min_tx_gas = U256::from(self.engine.schedule(&b.env_info()).tx_gas);
|
||||||
|
|
||||||
|
for tx in transactions {
|
||||||
|
// Push transaction to block
|
||||||
|
let hash = tx.hash();
|
||||||
|
let import = b.push_transaction(tx, None);
|
||||||
|
|
||||||
|
match import {
|
||||||
|
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, .. })) => {
|
||||||
|
trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash);
|
||||||
|
// Exit early if gas left is smaller then min_tx_gas
|
||||||
|
if gas_limit - gas_used < min_tx_gas {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
invalid_transactions.insert(hash);
|
||||||
|
trace!(target: "miner",
|
||||||
|
"Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}",
|
||||||
|
block_number, hash, e);
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And close
|
||||||
|
let b = b.close();
|
||||||
|
trace!(target: "miner", "Sealing: number={}, hash={}, diff={}",
|
||||||
|
b.block().header().number(),
|
||||||
|
b.hash(),
|
||||||
|
b.block().header().difficulty()
|
||||||
|
);
|
||||||
|
(Some(b), invalid_transactions)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
||||||
|
block.try_seal(self.engine.deref().deref(), seal)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MayPanic for Client {
|
impl MayPanic for Client {
|
||||||
|
@ -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};
|
||||||
|
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 {
|
||||||
@ -154,15 +156,6 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
/// Returns logs matching given filter.
|
/// Returns logs matching given filter.
|
||||||
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;
|
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;
|
||||||
|
|
||||||
// TODO [todr] Should be moved to miner crate eventually.
|
|
||||||
/// Returns ClosedBlock prepared for sealing.
|
|
||||||
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
|
||||||
-> (Option<ClosedBlock>, HashSet<H256>);
|
|
||||||
|
|
||||||
// TODO [todr] Should be moved to miner crate eventually.
|
|
||||||
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
|
||||||
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
|
|
||||||
|
|
||||||
/// Makes a non-persistent transaction call.
|
/// Makes a non-persistent transaction call.
|
||||||
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
||||||
|
|
||||||
@ -183,5 +176,20 @@ 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
|
||||||
|
pub trait MiningBlockChainClient : BlockChainClient {
|
||||||
|
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
||||||
|
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
|
||||||
|
|
||||||
|
/// Returns ClosedBlock prepared for sealing.
|
||||||
|
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
||||||
|
-> (Option<ClosedBlock>, HashSet<H256>);
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
|
|||||||
use util::*;
|
use util::*;
|
||||||
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
||||||
use blockchain::TreeRoute;
|
use blockchain::TreeRoute;
|
||||||
use client::{BlockChainClient, BlockChainInfo, BlockStatus, BlockID, TransactionID, UncleID, TraceId, TraceFilter, LastHashes};
|
use client::{BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID, TransactionID, UncleID, TraceId, TraceFilter, LastHashes};
|
||||||
use header::{Header as BlockHeader, BlockNumber};
|
use header::{Header as BlockHeader, BlockNumber};
|
||||||
use filter::Filter;
|
use filter::Filter;
|
||||||
use log_entry::LocalizedLogEntry;
|
use log_entry::LocalizedLogEntry;
|
||||||
@ -28,6 +28,7 @@ use receipt::{Receipt, LocalizedReceipt};
|
|||||||
use blockchain::extras::BlockReceipts;
|
use blockchain::extras::BlockReceipts;
|
||||||
use error::{ImportResult};
|
use error::{ImportResult};
|
||||||
use evm::Factory as EvmFactory;
|
use evm::Factory as EvmFactory;
|
||||||
|
use miner::{Miner, MinerService};
|
||||||
|
|
||||||
use block_queue::BlockQueueInfo;
|
use block_queue::BlockQueueInfo;
|
||||||
use block::{SealedBlock, ClosedBlock, LockedBlock};
|
use block::{SealedBlock, ClosedBlock, LockedBlock};
|
||||||
@ -35,6 +36,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.
|
||||||
@ -61,6 +65,8 @@ pub struct TestBlockChainClient {
|
|||||||
pub receipts: RwLock<HashMap<TransactionID, LocalizedReceipt>>,
|
pub receipts: RwLock<HashMap<TransactionID, LocalizedReceipt>>,
|
||||||
/// Block queue size.
|
/// Block queue size.
|
||||||
pub queue_size: AtomicUsize,
|
pub queue_size: AtomicUsize,
|
||||||
|
/// Miner
|
||||||
|
pub miner: Arc<Miner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -99,6 +105,7 @@ impl TestBlockChainClient {
|
|||||||
execution_result: RwLock::new(None),
|
execution_result: RwLock::new(None),
|
||||||
receipts: RwLock::new(HashMap::new()),
|
receipts: RwLock::new(HashMap::new()),
|
||||||
queue_size: AtomicUsize::new(0),
|
queue_size: AtomicUsize::new(0),
|
||||||
|
miner: Arc::new(Miner::default()),
|
||||||
};
|
};
|
||||||
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
||||||
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
||||||
@ -232,6 +239,17 @@ impl TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MiningBlockChainClient for TestBlockChainClient {
|
||||||
|
fn try_seal(&self, block: LockedBlock, _seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
||||||
|
Err(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn prepare_sealing(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes, _transactions: Vec<SignedTransaction>) -> (Option<ClosedBlock>, HashSet<H256>) {
|
||||||
|
(None, HashSet::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BlockChainClient for TestBlockChainClient {
|
impl BlockChainClient for TestBlockChainClient {
|
||||||
fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||||
Ok(self.execution_result.read().unwrap().clone().unwrap())
|
Ok(self.execution_result.read().unwrap().clone().unwrap())
|
||||||
@ -296,14 +314,6 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_sealing(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes, _transactions: Vec<SignedTransaction>) -> (Option<ClosedBlock>, HashSet<H256>) {
|
|
||||||
(None, HashSet::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_seal(&self, block: LockedBlock, _seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
|
||||||
Err(block)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
||||||
self.block_hash(id).and_then(|hash| self.blocks.read().unwrap().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
self.block_hash(id).and_then(|hash| self.blocks.read().unwrap().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
||||||
}
|
}
|
||||||
@ -476,4 +486,19 @@ 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>> {
|
||||||
|
let nonces = self.nonces.read().unwrap();
|
||||||
|
let balances = self.balances.read().unwrap();
|
||||||
|
let fetch_account = |a: &Address| AccountDetails {
|
||||||
|
nonce: nonces[a],
|
||||||
|
balance: balances[a],
|
||||||
|
};
|
||||||
|
|
||||||
|
self.miner.import_transactions(transactions, &fetch_account)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||||
|
self.miner.all_transactions()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ use tests::helpers::*;
|
|||||||
use devtools::*;
|
use devtools::*;
|
||||||
use spec::Genesis;
|
use spec::Genesis;
|
||||||
use ethjson;
|
use ethjson;
|
||||||
|
use miner::Miner;
|
||||||
|
|
||||||
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||||
init_log();
|
init_log();
|
||||||
@ -53,7 +54,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
|||||||
|
|
||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
{
|
{
|
||||||
let client = Client::new(ClientConfig::default(), spec, temp.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), spec, temp.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
for b in &blockchain.blocks_rlp() {
|
for b in &blockchain.blocks_rlp() {
|
||||||
if Block::is_good(&b) {
|
if Block::is_good(&b) {
|
||||||
let _ = client.import_block(b.clone());
|
let _ = client.import_block(b.clone());
|
||||||
|
@ -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;
|
||||||
|
@ -18,17 +18,17 @@ use rayon::prelude::*;
|
|||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::{AccountProvider};
|
||||||
use ethcore::views::{BlockView, HeaderView};
|
use views::{BlockView, HeaderView};
|
||||||
use ethcore::client::{BlockChainClient, BlockID};
|
use client::{MiningBlockChainClient, 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 {
|
||||||
@ -104,7 +104,7 @@ impl Miner {
|
|||||||
/// Prepares new block for sealing including top transactions from queue.
|
/// Prepares new block for sealing including top transactions from queue.
|
||||||
#[cfg_attr(feature="dev", allow(match_same_arms))]
|
#[cfg_attr(feature="dev", allow(match_same_arms))]
|
||||||
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
|
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
|
||||||
fn prepare_sealing(&self, chain: &BlockChainClient) {
|
fn prepare_sealing(&self, chain: &MiningBlockChainClient) {
|
||||||
trace!(target: "miner", "prepare_sealing: entering");
|
trace!(target: "miner", "prepare_sealing: entering");
|
||||||
let transactions = self.transaction_queue.lock().unwrap().top_transactions();
|
let transactions = self.transaction_queue.lock().unwrap().top_transactions();
|
||||||
let mut sealing_work = self.sealing_work.lock().unwrap();
|
let mut sealing_work = self.sealing_work.lock().unwrap();
|
||||||
@ -205,14 +205,14 @@ impl Miner {
|
|||||||
trace!(target: "miner", "prepare_sealing: leaving (last={:?})", sealing_work.peek_last_ref().map(|b| b.block().fields().header.hash()));
|
trace!(target: "miner", "prepare_sealing: leaving (last={:?})", sealing_work.peek_last_ref().map(|b| b.block().fields().header.hash()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_gas_limit(&self, chain: &BlockChainClient) {
|
fn update_gas_limit(&self, chain: &MiningBlockChainClient) {
|
||||||
let gas_limit = HeaderView::new(&chain.best_block_header()).gas_limit();
|
let gas_limit = HeaderView::new(&chain.best_block_header()).gas_limit();
|
||||||
let mut queue = self.transaction_queue.lock().unwrap();
|
let mut queue = self.transaction_queue.lock().unwrap();
|
||||||
queue.set_gas_limit(gas_limit);
|
queue.set_gas_limit(gas_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if we had to prepare new pending block
|
/// Returns true if we had to prepare new pending block
|
||||||
fn enable_and_prepare_sealing(&self, chain: &BlockChainClient) -> bool {
|
fn enable_and_prepare_sealing(&self, chain: &MiningBlockChainClient) -> bool {
|
||||||
trace!(target: "miner", "enable_and_prepare_sealing: entering");
|
trace!(target: "miner", "enable_and_prepare_sealing: entering");
|
||||||
let have_work = self.sealing_work.lock().unwrap().peek_last_ref().is_some();
|
let have_work = self.sealing_work.lock().unwrap().peek_last_ref().is_some();
|
||||||
trace!(target: "miner", "enable_and_prepare_sealing: have_work={}", have_work);
|
trace!(target: "miner", "enable_and_prepare_sealing: have_work={}", have_work);
|
||||||
@ -236,7 +236,7 @@ const SEALING_TIMEOUT_IN_BLOCKS : u64 = 5;
|
|||||||
|
|
||||||
impl MinerService for Miner {
|
impl MinerService for Miner {
|
||||||
|
|
||||||
fn clear_and_reset(&self, chain: &BlockChainClient) {
|
fn clear_and_reset(&self, chain: &MiningBlockChainClient) {
|
||||||
self.transaction_queue.lock().unwrap().clear();
|
self.transaction_queue.lock().unwrap().clear();
|
||||||
self.update_sealing(chain);
|
self.update_sealing(chain);
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
fn call(&self, chain: &MiningBlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||||
let sealing_work = self.sealing_work.lock().unwrap();
|
let sealing_work = self.sealing_work.lock().unwrap();
|
||||||
match sealing_work.peek_last_ref() {
|
match sealing_work.peek_last_ref() {
|
||||||
Some(work) => {
|
Some(work) => {
|
||||||
@ -287,7 +287,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256 {
|
fn balance(&self, chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||||
let sealing_work = self.sealing_work.lock().unwrap();
|
let sealing_work = self.sealing_work.lock().unwrap();
|
||||||
sealing_work.peek_last_ref().map_or_else(
|
sealing_work.peek_last_ref().map_or_else(
|
||||||
|| chain.latest_balance(address),
|
|| chain.latest_balance(address),
|
||||||
@ -295,7 +295,7 @@ impl MinerService for Miner {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256 {
|
fn storage_at(&self, chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256 {
|
||||||
let sealing_work = self.sealing_work.lock().unwrap();
|
let sealing_work = self.sealing_work.lock().unwrap();
|
||||||
sealing_work.peek_last_ref().map_or_else(
|
sealing_work.peek_last_ref().map_or_else(
|
||||||
|| chain.latest_storage_at(address, position),
|
|| chain.latest_storage_at(address, position),
|
||||||
@ -303,12 +303,12 @@ impl MinerService for Miner {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonce(&self, chain: &BlockChainClient, address: &Address) -> U256 {
|
fn nonce(&self, chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||||
let sealing_work = self.sealing_work.lock().unwrap();
|
let sealing_work = self.sealing_work.lock().unwrap();
|
||||||
sealing_work.peek_last_ref().map_or_else(|| chain.latest_nonce(address), |b| b.block().fields().state.nonce(address))
|
sealing_work.peek_last_ref().map_or_else(|| chain.latest_nonce(address), |b| b.block().fields().state.nonce(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(&self, chain: &BlockChainClient, address: &Address) -> Option<Bytes> {
|
fn code(&self, chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes> {
|
||||||
let sealing_work = self.sealing_work.lock().unwrap();
|
let sealing_work = self.sealing_work.lock().unwrap();
|
||||||
sealing_work.peek_last_ref().map_or_else(|| chain.code(address), |b| b.block().fields().state.code(address))
|
sealing_work.peek_last_ref().map_or_else(|| chain.code(address), |b| b.block().fields().state.code(address))
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ impl MinerService for Miner {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_own_transaction<T>(&self, chain: &BlockChainClient, transaction: SignedTransaction, fetch_account: T) ->
|
fn import_own_transaction<T>(&self, chain: &MiningBlockChainClient, transaction: SignedTransaction, fetch_account: T) ->
|
||||||
Result<TransactionImportResult, Error>
|
Result<TransactionImportResult, Error>
|
||||||
where T: Fn(&Address) -> AccountDetails {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
let hash = transaction.hash();
|
let hash = transaction.hash();
|
||||||
@ -469,7 +469,7 @@ impl MinerService for Miner {
|
|||||||
self.transaction_queue.lock().unwrap().last_nonce(address)
|
self.transaction_queue.lock().unwrap().last_nonce(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_sealing(&self, chain: &BlockChainClient) {
|
fn update_sealing(&self, chain: &MiningBlockChainClient) {
|
||||||
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||||
let current_no = chain.chain_info().best_block_number;
|
let current_no = chain.chain_info().best_block_number;
|
||||||
let has_local_transactions = self.transaction_queue.lock().unwrap().has_local_pending_transactions();
|
let has_local_transactions = self.transaction_queue.lock().unwrap().has_local_pending_transactions();
|
||||||
@ -489,7 +489,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_sealing_work<F, T>(&self, chain: &BlockChainClient, f: F) -> Option<T> where F: FnOnce(&ClosedBlock) -> T {
|
fn map_sealing_work<F, T>(&self, chain: &MiningBlockChainClient, f: F) -> Option<T> where F: FnOnce(&ClosedBlock) -> T {
|
||||||
trace!(target: "miner", "map_sealing_work: entering");
|
trace!(target: "miner", "map_sealing_work: entering");
|
||||||
self.enable_and_prepare_sealing(chain);
|
self.enable_and_prepare_sealing(chain);
|
||||||
trace!(target: "miner", "map_sealing_work: sealing prepared");
|
trace!(target: "miner", "map_sealing_work: sealing prepared");
|
||||||
@ -499,7 +499,7 @@ impl MinerService for Miner {
|
|||||||
ret.map(f)
|
ret.map(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_seal(&self, chain: &BlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error> {
|
fn submit_seal(&self, chain: &MiningBlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error> {
|
||||||
if let Some(b) = self.sealing_work.lock().unwrap().take_used_if(|b| &b.hash() == &pow_hash) {
|
if let Some(b) = self.sealing_work.lock().unwrap().take_used_if(|b| &b.hash() == &pow_hash) {
|
||||||
match chain.try_seal(b.lock(), seal) {
|
match chain.try_seal(b.lock(), seal) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -522,8 +522,8 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chain_new_blocks(&self, chain: &BlockChainClient, _imported: &[H256], _invalid: &[H256], enacted: &[H256], retracted: &[H256]) {
|
fn chain_new_blocks(&self, chain: &MiningBlockChainClient, _imported: &[H256], _invalid: &[H256], enacted: &[H256], retracted: &[H256]) {
|
||||||
fn fetch_transactions(chain: &BlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
fn fetch_transactions(chain: &MiningBlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
||||||
let block = chain
|
let block = chain
|
||||||
.block(BlockID::Hash(*hash))
|
.block(BlockID::Hash(*hash))
|
||||||
// Client should send message after commit to db and inserting to chain.
|
// Client should send message after commit to db and inserting to chain.
|
||||||
@ -584,13 +584,13 @@ impl MinerService for Miner {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use MinerService;
|
use super::super::MinerService;
|
||||||
use super::{Miner};
|
use super::Miner;
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::client::{TestBlockChainClient, EachBlockWith};
|
use client::{TestBlockChainClient, EachBlockWith};
|
||||||
use ethcore::block::*;
|
use block::*;
|
||||||
|
|
||||||
// TODO [ToDr] To uncomment when TestBlockChainClient can actually return a ClosedBlock.
|
// TODO [ToDr] To uncomment` when TestBlockChainClient can actually return a ClosedBlock.
|
||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn should_prepare_block_to_seal() {
|
fn should_prepare_block_to_seal() {
|
@ -26,12 +26,10 @@
|
|||||||
//! ```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 ethcore::client::{Client, ClientConfig};
|
||||||
//! use ethcore::ethereum;
|
//! use ethcore::miner::{Miner, MinerService};
|
||||||
//! use ethminer::{Miner, MinerService};
|
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let miner: Miner = Miner::default();
|
//! let miner: Miner = Miner::default();
|
||||||
@ -43,30 +41,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::{BlockChainClient, Executed};
|
use client::{MiningBlockChainClient, 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 {
|
||||||
@ -110,7 +99,7 @@ pub trait MinerService : Send + Sync {
|
|||||||
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
||||||
|
|
||||||
/// Imports own (node owner) transaction to queue.
|
/// Imports own (node owner) transaction to queue.
|
||||||
fn import_own_transaction<T>(&self, chain: &BlockChainClient, transaction: SignedTransaction, fetch_account: T) ->
|
fn import_own_transaction<T>(&self, chain: &MiningBlockChainClient, transaction: SignedTransaction, fetch_account: T) ->
|
||||||
Result<TransactionImportResult, Error>
|
Result<TransactionImportResult, Error>
|
||||||
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
||||||
|
|
||||||
@ -118,20 +107,20 @@ pub trait MinerService : Send + Sync {
|
|||||||
fn pending_transactions_hashes(&self) -> Vec<H256>;
|
fn pending_transactions_hashes(&self) -> Vec<H256>;
|
||||||
|
|
||||||
/// Removes all transactions from the queue and restart mining operation.
|
/// Removes all transactions from the queue and restart mining operation.
|
||||||
fn clear_and_reset(&self, chain: &BlockChainClient);
|
fn clear_and_reset(&self, chain: &MiningBlockChainClient);
|
||||||
|
|
||||||
/// Called when blocks are imported to chain, updates transactions queue.
|
/// Called when blocks are imported to chain, updates transactions queue.
|
||||||
fn chain_new_blocks(&self, chain: &BlockChainClient, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256]);
|
fn chain_new_blocks(&self, chain: &MiningBlockChainClient, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256]);
|
||||||
|
|
||||||
/// New chain head event. Restart mining operation.
|
/// New chain head event. Restart mining operation.
|
||||||
fn update_sealing(&self, chain: &BlockChainClient);
|
fn update_sealing(&self, chain: &MiningBlockChainClient);
|
||||||
|
|
||||||
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
||||||
/// Will check the seal, but not actually insert the block into the chain.
|
/// Will check the seal, but not actually insert the block into the chain.
|
||||||
fn submit_seal(&self, chain: &BlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error>;
|
fn submit_seal(&self, chain: &MiningBlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error>;
|
||||||
|
|
||||||
/// Get the sealing work package and if `Some`, apply some transform.
|
/// Get the sealing work package and if `Some`, apply some transform.
|
||||||
fn map_sealing_work<F, T>(&self, chain: &BlockChainClient, f: F) -> Option<T>
|
fn map_sealing_work<F, T>(&self, chain: &MiningBlockChainClient, f: F) -> Option<T>
|
||||||
where F: FnOnce(&ClosedBlock) -> T, Self: Sized;
|
where F: FnOnce(&ClosedBlock) -> T, Self: Sized;
|
||||||
|
|
||||||
/// Query pending transactions for hash.
|
/// Query pending transactions for hash.
|
||||||
@ -156,19 +145,19 @@ pub trait MinerService : Send + Sync {
|
|||||||
fn sensible_gas_limit(&self) -> U256 { 21000.into() }
|
fn sensible_gas_limit(&self) -> U256 { 21000.into() }
|
||||||
|
|
||||||
/// Latest account balance in pending state.
|
/// Latest account balance in pending state.
|
||||||
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256;
|
fn balance(&self, chain: &MiningBlockChainClient, address: &Address) -> U256;
|
||||||
|
|
||||||
/// Call into contract code using pending state.
|
/// Call into contract code using pending state.
|
||||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
fn call(&self, chain: &MiningBlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
||||||
|
|
||||||
/// Get storage value in pending state.
|
/// Get storage value in pending state.
|
||||||
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256;
|
fn storage_at(&self, chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256;
|
||||||
|
|
||||||
/// Get account nonce in pending state.
|
/// Get account nonce in pending state.
|
||||||
fn nonce(&self, chain: &BlockChainClient, address: &Address) -> U256;
|
fn nonce(&self, chain: &MiningBlockChainClient, address: &Address) -> U256;
|
||||||
|
|
||||||
/// Get contract code in pending state.
|
/// Get contract code in pending state.
|
||||||
fn code(&self, chain: &BlockChainClient, address: &Address) -> Option<Bytes>;
|
fn code(&self, chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mining status
|
/// Mining status
|
@ -26,13 +26,12 @@
|
|||||||
//! ```rust
|
//! ```rust
|
||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_util as util;
|
||||||
//! extern crate ethcore;
|
//! extern crate ethcore;
|
||||||
//! extern crate ethminer;
|
|
||||||
//! extern crate rustc_serialize;
|
//! extern crate rustc_serialize;
|
||||||
//!
|
//!
|
||||||
//! use util::crypto::KeyPair;
|
//! use util::crypto::KeyPair;
|
||||||
//! use util::hash::Address;
|
//! use util::hash::Address;
|
||||||
//! use util::numbers::{Uint, U256};
|
//! use util::numbers::{Uint, U256};
|
||||||
//! use ethminer::{TransactionQueue, AccountDetails, TransactionOrigin};
|
//! use ethcore::miner::{TransactionQueue, AccountDetails, TransactionOrigin};
|
||||||
//! use ethcore::transaction::*;
|
//! use ethcore::transaction::*;
|
||||||
//! use rustc_serialize::hex::FromHex;
|
//! use rustc_serialize::hex::FromHex;
|
||||||
//!
|
//!
|
||||||
@ -89,8 +88,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)]
|
||||||
@ -778,8 +777,8 @@ mod test {
|
|||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
use util::table::*;
|
use util::table::*;
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::transaction::*;
|
use transaction::*;
|
||||||
use ethcore::error::{Error, TransactionError};
|
use error::{Error, TransactionError};
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::{TransactionSet, TransactionOrder, VerifiedTransaction};
|
use super::{TransactionSet, TransactionOrder, VerifiedTransaction};
|
||||||
|
|
@ -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()
|
||||||
@ -141,12 +142,14 @@ mod tests {
|
|||||||
use util::network::*;
|
use util::network::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
use client::ClientConfig;
|
use client::ClientConfig;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use miner::Miner;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_can_be_started() {
|
fn it_can_be_started() {
|
||||||
let spec = get_test_spec();
|
let spec = get_test_spec();
|
||||||
let temp_path = RandomTempPath::new();
|
let temp_path = RandomTempPath::new();
|
||||||
let service = ClientService::start(ClientConfig::default(), spec, NetworkConfiguration::new_local(), &temp_path.as_path());
|
let service = ClientService::start(ClientConfig::default(), spec, NetworkConfiguration::new_local(), &temp_path.as_path(), Arc::new(Miner::default()));
|
||||||
assert!(service.is_ok());
|
assert!(service.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,17 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use client::{BlockChainClient, Client, ClientConfig, BlockID};
|
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
||||||
use block::IsBlock;
|
use block::IsBlock;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
|
use miner::Miner;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn imports_from_empty() {
|
fn imports_from_empty() {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
client.import_verified_blocks(&IoChannel::disconnected());
|
client.import_verified_blocks(&IoChannel::disconnected());
|
||||||
client.flush_queue();
|
client.flush_queue();
|
||||||
}
|
}
|
||||||
@ -41,7 +42,7 @@ fn returns_state_root_basic() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn imports_good_block() {
|
fn imports_good_block() {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
let good_block = get_good_dummy_block();
|
let good_block = get_good_dummy_block();
|
||||||
if let Err(_) = client.import_block(good_block) {
|
if let Err(_) = client.import_block(good_block) {
|
||||||
panic!("error importing block being good by definition");
|
panic!("error importing block being good by definition");
|
||||||
@ -56,7 +57,7 @@ fn imports_good_block() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn query_none_block() {
|
fn query_none_block() {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
|
|
||||||
let non_existant = client.block_header(BlockID::Number(188));
|
let non_existant = client.block_header(BlockID::Number(188));
|
||||||
assert!(non_existant.is_none());
|
assert!(non_existant.is_none());
|
||||||
|
@ -23,6 +23,7 @@ use evm::Schedule;
|
|||||||
use engine::*;
|
use engine::*;
|
||||||
use ethereum;
|
use ethereum;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
|
use miner::Miner;
|
||||||
|
|
||||||
#[cfg(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
pub enum ChainEra {
|
pub enum ChainEra {
|
||||||
@ -139,7 +140,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[&SignedTrans
|
|||||||
pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>> {
|
pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>> {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
|
|
||||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
let test_spec = get_test_spec();
|
let test_spec = get_test_spec();
|
||||||
let test_engine = &test_spec.engine;
|
let test_engine = &test_spec.engine;
|
||||||
let state_root = test_spec.genesis_header().state_root;
|
let state_root = test_spec.genesis_header().state_root;
|
||||||
@ -205,7 +206,7 @@ pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting
|
|||||||
|
|
||||||
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<Client>> {
|
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<Client>> {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), get_test_spec(), dir.as_path(), Arc::new(Miner::default()), IoChannel::disconnected()).unwrap();
|
||||||
for block in &blocks {
|
for block in &blocks {
|
||||||
if let Err(_) = client.import_block(block.clone()) {
|
if let Err(_) = client.import_block(block.clone()) {
|
||||||
panic!("panic importing block which is well-formed");
|
panic!("panic importing block which is well-formed");
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
[package]
|
|
||||||
description = "Ethminer library"
|
|
||||||
homepage = "http://ethcore.io"
|
|
||||||
license = "GPL-3.0"
|
|
||||||
name = "ethminer"
|
|
||||||
version = "1.2.0"
|
|
||||||
authors = ["Ethcore <admin@ethcore.io>"]
|
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
rustc_version = "0.1"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
ethcore-util = { path = "../util" }
|
|
||||||
ethcore = { path = "../ethcore" }
|
|
||||||
log = "0.3"
|
|
||||||
env_logger = "0.3"
|
|
||||||
rustc-serialize = "0.3"
|
|
||||||
rayon = "0.3.1"
|
|
||||||
clippy = { version = "0.0.69", optional = true}
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = []
|
|
||||||
dev = ["clippy"]
|
|
@ -1,25 +0,0 @@
|
|||||||
// 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/>.
|
|
||||||
|
|
||||||
extern crate rustc_version;
|
|
||||||
|
|
||||||
use rustc_version::{version_meta, Channel};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
if let Channel::Nightly = version_meta().channel {
|
|
||||||
println!("cargo:rustc-cfg=nightly");
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,6 @@ extern crate rustc_serialize;
|
|||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate ethsync;
|
extern crate ethsync;
|
||||||
extern crate ethminer;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log as rlog;
|
extern crate log as rlog;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
@ -86,7 +85,7 @@ use ethcore::error::{Error, ImportError};
|
|||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::spec::Spec;
|
use ethcore::spec::Spec;
|
||||||
use ethsync::EthSync;
|
use ethsync::EthSync;
|
||||||
use ethminer::{Miner, MinerService, ExternalMiner};
|
use ethcore::miner::{Miner, MinerService, ExternalMiner};
|
||||||
use daemonize::Daemonize;
|
use daemonize::Daemonize;
|
||||||
use migration::migrate;
|
use migration::migrate;
|
||||||
use informant::Informant;
|
use informant::Informant;
|
||||||
@ -174,14 +173,6 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
|||||||
// Secret Store
|
// Secret Store
|
||||||
let account_service = Arc::new(conf.account_service());
|
let account_service = Arc::new(conf.account_service());
|
||||||
|
|
||||||
// Build client
|
|
||||||
let mut service = ClientService::start(
|
|
||||||
client_config, spec, net_settings, Path::new(&conf.path())
|
|
||||||
).unwrap_or_else(|e| die_with_error("Client", e));
|
|
||||||
|
|
||||||
panic_handler.forward_from(&service);
|
|
||||||
let client = service.client();
|
|
||||||
|
|
||||||
// Miner
|
// Miner
|
||||||
let miner = Miner::with_accounts(conf.args.flag_force_sealing, conf.spec(), account_service.clone());
|
let miner = Miner::with_accounts(conf.args.flag_force_sealing, conf.spec(), account_service.clone());
|
||||||
miner.set_author(conf.author());
|
miner.set_author(conf.author());
|
||||||
@ -190,11 +181,19 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
|||||||
miner.set_minimal_gas_price(conf.gas_price());
|
miner.set_minimal_gas_price(conf.gas_price());
|
||||||
miner.set_transactions_limit(conf.args.flag_tx_limit);
|
miner.set_transactions_limit(conf.args.flag_tx_limit);
|
||||||
|
|
||||||
|
// Build client
|
||||||
|
let mut service = ClientService::start(
|
||||||
|
client_config, spec, net_settings, Path::new(&conf.path()), miner.clone()
|
||||||
|
).unwrap_or_else(|e| die_with_error("Client", e));
|
||||||
|
|
||||||
|
panic_handler.forward_from(&service);
|
||||||
|
let client = service.client();
|
||||||
|
|
||||||
let external_miner = Arc::new(ExternalMiner::default());
|
let external_miner = Arc::new(ExternalMiner::default());
|
||||||
let network_settings = Arc::new(conf.network_settings());
|
let network_settings = Arc::new(conf.network_settings());
|
||||||
|
|
||||||
// Sync
|
// Sync
|
||||||
let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone());
|
let sync = EthSync::register(service.network(), sync_config, client.clone());
|
||||||
|
|
||||||
let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
|
let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
|
||||||
signer_enabled: conf.args.flag_signer,
|
signer_enabled: conf.args.flag_signer,
|
||||||
@ -292,7 +291,7 @@ fn execute_export(conf: Configuration) {
|
|||||||
|
|
||||||
// Build client
|
// Build client
|
||||||
let service = ClientService::start(
|
let service = ClientService::start(
|
||||||
client_config, spec, net_settings, Path::new(&conf.path())
|
client_config, spec, net_settings, Path::new(&conf.path()), Arc::new(Miner::default()),
|
||||||
).unwrap_or_else(|e| die_with_error("Client", e));
|
).unwrap_or_else(|e| die_with_error("Client", e));
|
||||||
|
|
||||||
panic_handler.forward_from(&service);
|
panic_handler.forward_from(&service);
|
||||||
@ -363,7 +362,7 @@ fn execute_import(conf: Configuration) {
|
|||||||
|
|
||||||
// Build client
|
// Build client
|
||||||
let service = ClientService::start(
|
let service = ClientService::start(
|
||||||
client_config, spec, net_settings, Path::new(&conf.path())
|
client_config, spec, net_settings, Path::new(&conf.path()), Arc::new(Miner::default()),
|
||||||
).unwrap_or_else(|e| die_with_error("Client", e));
|
).unwrap_or_else(|e| die_with_error("Client", e));
|
||||||
|
|
||||||
panic_handler.forward_from(&service);
|
panic_handler.forward_from(&service);
|
||||||
|
@ -20,7 +20,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use die::*;
|
use die::*;
|
||||||
use ethsync::EthSync;
|
use ethsync::EthSync;
|
||||||
use ethminer::{Miner, ExternalMiner};
|
use ethcore::miner::{Miner, ExternalMiner};
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use util::RotatingLogger;
|
use util::RotatingLogger;
|
||||||
use util::keys::store::AccountService;
|
use util::keys::store::AccountService;
|
||||||
|
@ -18,7 +18,6 @@ ethcore-util = { path = "../util" }
|
|||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
ethash = { path = "../ethash" }
|
ethash = { path = "../ethash" }
|
||||||
ethsync = { path = "../sync" }
|
ethsync = { path = "../sync" }
|
||||||
ethminer = { path = "../miner" }
|
|
||||||
ethjson = { path = "../json" }
|
ethjson = { path = "../json" }
|
||||||
ethcore-devtools = { path = "../devtools" }
|
ethcore-devtools = { path = "../devtools" }
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
@ -34,4 +33,4 @@ syntex = "^0.32.0"
|
|||||||
[features]
|
[features]
|
||||||
default = ["serde_codegen"]
|
default = ["serde_codegen"]
|
||||||
nightly = ["serde_macros"]
|
nightly = ["serde_macros"]
|
||||||
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev", "ethminer/dev"]
|
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev"]
|
||||||
|
@ -29,7 +29,6 @@ extern crate jsonrpc_http_server;
|
|||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate ethsync;
|
extern crate ethsync;
|
||||||
extern crate ethminer;
|
|
||||||
extern crate transient_hashmap;
|
extern crate transient_hashmap;
|
||||||
extern crate json_ipc_server as ipc;
|
extern crate json_ipc_server as ipc;
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ extern crate ethash;
|
|||||||
use std::sync::{Arc, Weak, Mutex};
|
use std::sync::{Arc, Weak, Mutex};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use ethsync::{SyncProvider, SyncState};
|
use ethsync::{SyncProvider, SyncState};
|
||||||
use ethminer::{MinerService, ExternalMinerService};
|
use ethcore::miner::{MinerService, ExternalMinerService};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
use util::rlp::{encode, decode, UntrustedRlp, View};
|
use util::rlp::{encode, decode, UntrustedRlp, View};
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::AccountProvider;
|
||||||
use ethcore::client::{BlockChainClient, BlockID, TransactionID, UncleID};
|
use ethcore::client::{MiningBlockChainClient, BlockID, TransactionID, UncleID};
|
||||||
use ethcore::block::IsBlock;
|
use ethcore::block::IsBlock;
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
use ethcore::ethereum::Ethash;
|
use ethcore::ethereum::Ethash;
|
||||||
@ -42,7 +42,7 @@ use serde;
|
|||||||
|
|
||||||
/// Eth rpc implementation.
|
/// Eth rpc implementation.
|
||||||
pub struct EthClient<C, S, A, M, EM> where
|
pub struct EthClient<C, S, A, M, EM> where
|
||||||
C: BlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
S: SyncProvider,
|
S: SyncProvider,
|
||||||
A: AccountProvider,
|
A: AccountProvider,
|
||||||
M: MinerService,
|
M: MinerService,
|
||||||
@ -57,7 +57,7 @@ pub struct EthClient<C, S, A, M, EM> where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S, A, M, EM> EthClient<C, S, A, M, EM> where
|
impl<C, S, A, M, EM> EthClient<C, S, A, M, EM> where
|
||||||
C: BlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
S: SyncProvider,
|
S: SyncProvider,
|
||||||
A: AccountProvider,
|
A: AccountProvider,
|
||||||
M: MinerService,
|
M: MinerService,
|
||||||
@ -222,7 +222,7 @@ fn make_unsupported_err() -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
|
impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
|
||||||
C: BlockChainClient + 'static,
|
C: MiningBlockChainClient + 'static,
|
||||||
S: SyncProvider + 'static,
|
S: SyncProvider + 'static,
|
||||||
A: AccountProvider + 'static,
|
A: AccountProvider + 'static,
|
||||||
M: MinerService + 'static,
|
M: MinerService + 'static,
|
||||||
|
@ -21,7 +21,7 @@ use std::sync::{Arc, Weak, Mutex};
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use ethcore::filter::Filter as EthcoreFilter;
|
use ethcore::filter::Filter as EthcoreFilter;
|
||||||
use ethcore::client::{BlockChainClient, BlockID};
|
use ethcore::client::{BlockChainClient, BlockID};
|
||||||
use v1::traits::EthFilter;
|
use v1::traits::EthFilter;
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::AccountProvider;
|
||||||
use v1::helpers::{SigningQueue, ConfirmationsQueue};
|
use v1::helpers::{SigningQueue, ConfirmationsQueue};
|
||||||
@ -62,7 +62,7 @@ impl EthSigning for EthSigningQueueClient {
|
|||||||
|
|
||||||
/// Implementation of functions that require signing when no trusted signer is used.
|
/// Implementation of functions that require signing when no trusted signer is used.
|
||||||
pub struct EthSigningUnsafeClient<C, A, M> where
|
pub struct EthSigningUnsafeClient<C, A, M> where
|
||||||
C: BlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
A: AccountProvider,
|
A: AccountProvider,
|
||||||
M: MinerService {
|
M: MinerService {
|
||||||
client: Weak<C>,
|
client: Weak<C>,
|
||||||
@ -71,7 +71,7 @@ pub struct EthSigningUnsafeClient<C, A, M> where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C, A, M> EthSigningUnsafeClient<C, A, M> where
|
impl<C, A, M> EthSigningUnsafeClient<C, A, M> where
|
||||||
C: BlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
A: AccountProvider,
|
A: AccountProvider,
|
||||||
M: MinerService {
|
M: MinerService {
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ impl<C, A, M> EthSigningUnsafeClient<C, A, M> where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C, A, M> EthSigning for EthSigningUnsafeClient<C, A, M> where
|
impl<C, A, M> EthSigning for EthSigningUnsafeClient<C, A, M> where
|
||||||
C: BlockChainClient + 'static,
|
C: MiningBlockChainClient + 'static,
|
||||||
A: AccountProvider + 'static,
|
A: AccountProvider + 'static,
|
||||||
M: MinerService + 'static {
|
M: MinerService + 'static {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ use std::sync::{Arc, Weak};
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use v1::traits::Ethcore;
|
use v1::traits::Ethcore;
|
||||||
use v1::types::Bytes;
|
use v1::types::Bytes;
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ pub use self::rpc::RpcClient;
|
|||||||
|
|
||||||
use v1::types::TransactionRequest;
|
use v1::types::TransactionRequest;
|
||||||
use std::sync::Weak;
|
use std::sync::Weak;
|
||||||
use ethminer::{AccountDetails, MinerService};
|
use ethcore::miner::{AccountDetails, MinerService};
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
use ethcore::transaction::{Action, SignedTransaction, Transaction};
|
use ethcore::transaction::{Action, SignedTransaction, Transaction};
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::rlp::encode;
|
use util::rlp::encode;
|
||||||
@ -62,7 +62,7 @@ use util::bytes::ToPretty;
|
|||||||
use jsonrpc_core::{Error, to_value, Value};
|
use jsonrpc_core::{Error, to_value, Value};
|
||||||
|
|
||||||
fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error>
|
fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error>
|
||||||
where C: BlockChainClient, M: MinerService {
|
where C: MiningBlockChainClient, M: MinerService {
|
||||||
let hash = signed_transaction.hash();
|
let hash = signed_transaction.hash();
|
||||||
|
|
||||||
let import = miner.import_own_transaction(client, signed_transaction, |a: &Address| {
|
let import = miner.import_own_transaction(client, signed_transaction, |a: &Address| {
|
||||||
@ -76,7 +76,7 @@ fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedT
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sign_and_dispatch<C, M>(client: &Weak<C>, miner: &Weak<M>, request: TransactionRequest, secret: H256) -> Result<Value, Error>
|
fn sign_and_dispatch<C, M>(client: &Weak<C>, miner: &Weak<M>, request: TransactionRequest, secret: H256) -> Result<Value, Error>
|
||||||
where C: BlockChainClient, M: MinerService {
|
where C: MiningBlockChainClient, M: MinerService {
|
||||||
let client = take_weak!(client);
|
let client = take_weak!(client);
|
||||||
let miner = take_weak!(miner);
|
let miner = take_weak!(miner);
|
||||||
|
|
||||||
|
@ -22,19 +22,19 @@ use v1::types::TransactionRequest;
|
|||||||
use v1::impls::sign_and_dispatch;
|
use v1::impls::sign_and_dispatch;
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::AccountProvider;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
|
|
||||||
/// Account management (personal) rpc implementation.
|
/// Account management (personal) rpc implementation.
|
||||||
pub struct PersonalClient<A, C, M>
|
pub struct PersonalClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
accounts: Weak<A>,
|
accounts: Weak<A>,
|
||||||
client: Weak<C>,
|
client: Weak<C>,
|
||||||
miner: Weak<M>,
|
miner: Weak<M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, C, M> PersonalClient<A, C, M>
|
impl<A, C, M> PersonalClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
/// Creates new PersonalClient
|
/// Creates new PersonalClient
|
||||||
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>) -> Self {
|
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>) -> Self {
|
||||||
PersonalClient {
|
PersonalClient {
|
||||||
@ -46,7 +46,7 @@ impl<A, C, M> PersonalClient<A, C, M>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A: 'static, C: 'static, M: 'static> Personal for PersonalClient<A, C, M>
|
impl<A: 'static, C: 'static, M: 'static> Personal for PersonalClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
fn accounts(&self, _: Params) -> Result<Value, Error> {
|
fn accounts(&self, _: Params) -> Result<Value, Error> {
|
||||||
let store = take_weak!(self.accounts);
|
let store = take_weak!(self.accounts);
|
||||||
match store.accounts() {
|
match store.accounts() {
|
||||||
|
@ -24,12 +24,12 @@ use v1::impls::sign_and_dispatch;
|
|||||||
use v1::helpers::{SigningQueue, ConfirmationsQueue};
|
use v1::helpers::{SigningQueue, ConfirmationsQueue};
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::AccountProvider;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::MiningBlockChainClient;
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
|
|
||||||
/// Transactions confirmation (personal) rpc implementation.
|
/// Transactions confirmation (personal) rpc implementation.
|
||||||
pub struct SignerClient<A, C, M>
|
pub struct SignerClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
queue: Weak<ConfirmationsQueue>,
|
queue: Weak<ConfirmationsQueue>,
|
||||||
accounts: Weak<A>,
|
accounts: Weak<A>,
|
||||||
client: Weak<C>,
|
client: Weak<C>,
|
||||||
@ -37,7 +37,7 @@ pub struct SignerClient<A, C, M>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A: 'static, C: 'static, M: 'static> SignerClient<A, C, M>
|
impl<A: 'static, C: 'static, M: 'static> SignerClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
|
|
||||||
/// Create new instance of signer client.
|
/// Create new instance of signer client.
|
||||||
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>, queue: &Arc<ConfirmationsQueue>) -> Self {
|
pub fn new(store: &Arc<A>, client: &Arc<C>, miner: &Arc<M>, queue: &Arc<ConfirmationsQueue>) -> Self {
|
||||||
@ -51,7 +51,7 @@ impl<A: 'static, C: 'static, M: 'static> SignerClient<A, C, M>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A: 'static, C: 'static, M: 'static> PersonalSigner for SignerClient<A, C, M>
|
impl<A: 'static, C: 'static, M: 'static> PersonalSigner for SignerClient<A, C, M>
|
||||||
where A: AccountProvider, C: BlockChainClient, M: MinerService {
|
where A: AccountProvider, C: MiningBlockChainClient, M: MinerService {
|
||||||
|
|
||||||
fn transactions_to_confirm(&self, _params: Params) -> Result<Value, Error> {
|
fn transactions_to_confirm(&self, _params: Params) -> Result<Value, Error> {
|
||||||
let queue = take_weak!(self.queue);
|
let queue = take_weak!(self.queue);
|
||||||
|
@ -19,13 +19,14 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use ethcore::client::{MiningBlockChainClient, BlockChainClient, Client, ClientConfig};
|
||||||
use ethcore::ids::BlockID;
|
use ethcore::ids::BlockID;
|
||||||
use ethcore::client::{Client, BlockChainClient, ClientConfig};
|
|
||||||
use ethcore::spec::{Genesis, Spec};
|
use ethcore::spec::{Genesis, Spec};
|
||||||
use ethcore::block::Block;
|
use ethcore::block::Block;
|
||||||
use ethcore::views::BlockView;
|
use ethcore::views::BlockView;
|
||||||
use ethcore::ethereum;
|
use ethcore::ethereum;
|
||||||
use ethminer::{Miner, MinerService, ExternalMiner};
|
use ethcore::transaction::{Transaction, Action};
|
||||||
|
use ethcore::miner::{MinerService, ExternalMiner, Miner};
|
||||||
use devtools::RandomTempPath;
|
use devtools::RandomTempPath;
|
||||||
use util::Hashable;
|
use util::Hashable;
|
||||||
use util::io::IoChannel;
|
use util::io::IoChannel;
|
||||||
@ -68,8 +69,8 @@ fn make_spec(chain: &BlockChain) -> Spec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct EthTester {
|
struct EthTester {
|
||||||
_miner: Arc<MinerService>,
|
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
|
_miner: Arc<MinerService>,
|
||||||
accounts: Arc<TestAccountProvider>,
|
accounts: Arc<TestAccountProvider>,
|
||||||
handler: IoHandler,
|
handler: IoHandler,
|
||||||
}
|
}
|
||||||
@ -96,10 +97,10 @@ impl EthTester {
|
|||||||
where F: Fn() -> Spec {
|
where F: Fn() -> Spec {
|
||||||
|
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(ClientConfig::default(), spec_provider(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
|
||||||
let sync_provider = sync_provider();
|
|
||||||
let account_provider = account_provider();
|
let account_provider = account_provider();
|
||||||
let miner_service = miner_service(spec_provider(), account_provider.clone());
|
let miner_service = miner_service(spec_provider(), account_provider.clone());
|
||||||
|
let client = Client::new(ClientConfig::default(), spec_provider(), dir.as_path(), miner_service.clone(), IoChannel::disconnected()).unwrap();
|
||||||
|
let sync_provider = sync_provider();
|
||||||
let external_miner = Arc::new(ExternalMiner::default());
|
let external_miner = Arc::new(ExternalMiner::default());
|
||||||
|
|
||||||
let eth_client = EthClient::new(
|
let eth_client = EthClient::new(
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
use util::{Address, H256, Bytes, U256, FixedHash, Uint};
|
use util::{Address, H256, Bytes, U256, FixedHash, Uint};
|
||||||
use util::standard::*;
|
use util::standard::*;
|
||||||
use ethcore::error::{Error, ExecutionError};
|
use ethcore::error::{Error, ExecutionError};
|
||||||
use ethcore::client::{BlockChainClient, Executed};
|
use ethcore::client::{MiningBlockChainClient, Executed};
|
||||||
use ethcore::block::{ClosedBlock, IsBlock};
|
use ethcore::block::{ClosedBlock, IsBlock};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use ethcore::receipt::Receipt;
|
use ethcore::receipt::Receipt;
|
||||||
use ethminer::{MinerService, MinerStatus, AccountDetails, TransactionImportResult};
|
use ethcore::miner::{MinerService, MinerStatus, AccountDetails, TransactionImportResult};
|
||||||
|
|
||||||
/// Test miner service.
|
/// Test miner service.
|
||||||
pub struct TestMinerService {
|
pub struct TestMinerService {
|
||||||
@ -132,7 +132,7 @@ impl MinerService for TestMinerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Imports transactions to transaction queue.
|
/// Imports transactions to transaction queue.
|
||||||
fn import_own_transaction<T>(&self, chain: &BlockChainClient, transaction: SignedTransaction, _fetch_account: T) ->
|
fn import_own_transaction<T>(&self, chain: &MiningBlockChainClient, transaction: SignedTransaction, _fetch_account: T) ->
|
||||||
Result<TransactionImportResult, Error>
|
Result<TransactionImportResult, Error>
|
||||||
where T: Fn(&Address) -> AccountDetails {
|
where T: Fn(&Address) -> AccountDetails {
|
||||||
|
|
||||||
@ -154,21 +154,21 @@ impl MinerService for TestMinerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all transactions from the queue and restart mining operation.
|
/// Removes all transactions from the queue and restart mining operation.
|
||||||
fn clear_and_reset(&self, _chain: &BlockChainClient) {
|
fn clear_and_reset(&self, _chain: &MiningBlockChainClient) {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when blocks are imported to chain, updates transactions queue.
|
/// Called when blocks are imported to chain, updates transactions queue.
|
||||||
fn chain_new_blocks(&self, _chain: &BlockChainClient, _imported: &[H256], _invalid: &[H256], _enacted: &[H256], _retracted: &[H256]) {
|
fn chain_new_blocks(&self, _chain: &MiningBlockChainClient, _imported: &[H256], _invalid: &[H256], _enacted: &[H256], _retracted: &[H256]) {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// New chain head event. Restart mining operation.
|
/// New chain head event. Restart mining operation.
|
||||||
fn update_sealing(&self, _chain: &BlockChainClient) {
|
fn update_sealing(&self, _chain: &MiningBlockChainClient) {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_sealing_work<F, T>(&self, _chain: &BlockChainClient, _f: F) -> Option<T> where F: FnOnce(&ClosedBlock) -> T {
|
fn map_sealing_work<F, T>(&self, _chain: &MiningBlockChainClient, _f: F) -> Option<T> where F: FnOnce(&ClosedBlock) -> T {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,29 +194,29 @@ impl MinerService for TestMinerService {
|
|||||||
|
|
||||||
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
/// Submit `seal` as a valid solution for the header of `pow_hash`.
|
||||||
/// Will check the seal, but not actually insert the block into the chain.
|
/// Will check the seal, but not actually insert the block into the chain.
|
||||||
fn submit_seal(&self, _chain: &BlockChainClient, _pow_hash: H256, _seal: Vec<Bytes>) -> Result<(), Error> {
|
fn submit_seal(&self, _chain: &MiningBlockChainClient, _pow_hash: H256, _seal: Vec<Bytes>) -> Result<(), Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, _chain: &BlockChainClient, address: &Address) -> U256 {
|
fn balance(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||||
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
|
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
fn call(&self, _chain: &MiningBlockChainClient, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_at(&self, _chain: &BlockChainClient, address: &Address, position: &H256) -> H256 {
|
fn storage_at(&self, _chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256 {
|
||||||
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(H256::default, |b| b.block().fields().state.storage_at(address, position).clone())
|
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(H256::default, |b| b.block().fields().state.storage_at(address, position).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonce(&self, _chain: &BlockChainClient, address: &Address) -> U256 {
|
fn nonce(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||||
// we assume all transactions are in a pending block, ignoring the
|
// we assume all transactions are in a pending block, ignoring the
|
||||||
// reality of gas limits.
|
// reality of gas limits.
|
||||||
self.last_nonce(address).unwrap_or(U256::zero())
|
self.last_nonce(address).unwrap_or(U256::zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(&self, _chain: &BlockChainClient, address: &Address) -> Option<Bytes> {
|
fn code(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes> {
|
||||||
self.latest_closed_block.lock().unwrap().as_ref().map_or(None, |b| b.block().fields().state.code(address).clone())
|
self.latest_closed_block.lock().unwrap().as_ref().map_or(None, |b| b.block().fields().state.code(address).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, Transaction
|
|||||||
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
|
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
|
||||||
use ethcore::receipt::LocalizedReceipt;
|
use ethcore::receipt::LocalizedReceipt;
|
||||||
use ethcore::transaction::{Transaction, Action};
|
use ethcore::transaction::{Transaction, Action};
|
||||||
use ethminer::{ExternalMiner, MinerService};
|
use ethcore::miner::{ExternalMiner, MinerService};
|
||||||
use ethsync::SyncState;
|
use ethsync::SyncState;
|
||||||
use v1::{Eth, EthClient, EthSigning, EthSigningUnsafeClient};
|
use v1::{Eth, EthClient, EthSigning, EthSigningUnsafeClient};
|
||||||
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService};
|
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService};
|
||||||
|
@ -18,7 +18,7 @@ use std::sync::Arc;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use v1::{Ethcore, EthcoreClient};
|
use v1::{Ethcore, EthcoreClient};
|
||||||
use ethminer::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use v1::tests::helpers::TestMinerService;
|
use v1::tests::helpers::TestMinerService;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
|
@ -11,7 +11,6 @@ authors = ["Ethcore <admin@ethcore.io"]
|
|||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
clippy = { version = "0.0.69", optional = true}
|
clippy = { version = "0.0.69", optional = true}
|
||||||
ethminer = { path = "../miner" }
|
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
time = "0.1.34"
|
time = "0.1.34"
|
||||||
@ -20,4 +19,4 @@ heapsize = "0.3"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethminer/dev"]
|
dev = ["clippy", "ethcore/dev", "ethcore-util/dev"]
|
||||||
|
@ -97,7 +97,6 @@ use ethcore::client::{BlockChainClient, BlockStatus, BlockID, BlockChainInfo};
|
|||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use ethcore::block::Block;
|
use ethcore::block::Block;
|
||||||
use ethminer::{Miner, MinerService, AccountDetails};
|
|
||||||
use io::SyncIo;
|
use io::SyncIo;
|
||||||
use time;
|
use time;
|
||||||
use super::SyncConfig;
|
use super::SyncConfig;
|
||||||
@ -241,15 +240,13 @@ pub struct ChainSync {
|
|||||||
imported_this_round: Option<usize>,
|
imported_this_round: Option<usize>,
|
||||||
/// Network ID
|
/// Network ID
|
||||||
network_id: U256,
|
network_id: U256,
|
||||||
/// Miner
|
|
||||||
miner: Arc<Miner>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RlpResponseResult = Result<Option<(PacketId, RlpStream)>, PacketDecodeError>;
|
type RlpResponseResult = Result<Option<(PacketId, RlpStream)>, PacketDecodeError>;
|
||||||
|
|
||||||
impl ChainSync {
|
impl ChainSync {
|
||||||
/// Create a new instance of syncing strategy.
|
/// Create a new instance of syncing strategy.
|
||||||
pub fn new(config: SyncConfig, miner: Arc<Miner>, chain: &BlockChainClient) -> ChainSync {
|
pub fn new(config: SyncConfig, chain: &BlockChainClient) -> ChainSync {
|
||||||
let chain = chain.chain_info();
|
let chain = chain.chain_info();
|
||||||
let mut sync = ChainSync {
|
let mut sync = ChainSync {
|
||||||
state: SyncState::ChainHead,
|
state: SyncState::ChainHead,
|
||||||
@ -265,7 +262,6 @@ impl ChainSync {
|
|||||||
imported_this_round: None,
|
imported_this_round: None,
|
||||||
_max_download_ahead_blocks: max(MAX_HEADERS_TO_REQUEST, config.max_download_ahead_blocks),
|
_max_download_ahead_blocks: max(MAX_HEADERS_TO_REQUEST, config.max_download_ahead_blocks),
|
||||||
network_id: config.network_id,
|
network_id: config.network_id,
|
||||||
miner: miner,
|
|
||||||
};
|
};
|
||||||
sync.reset();
|
sync.reset();
|
||||||
sync
|
sync
|
||||||
@ -898,12 +894,7 @@ impl ChainSync {
|
|||||||
let tx: SignedTransaction = try!(r.val_at(i));
|
let tx: SignedTransaction = try!(r.val_at(i));
|
||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
}
|
}
|
||||||
let chain = io.chain();
|
let _ = io.chain().import_transactions(transactions);
|
||||||
let fetch_account = |a: &Address| AccountDetails {
|
|
||||||
nonce: chain.latest_nonce(a),
|
|
||||||
balance: chain.latest_balance(a),
|
|
||||||
};
|
|
||||||
let _ = self.miner.import_transactions(transactions, fetch_account);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1226,7 +1217,7 @@ impl ChainSync {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut transactions = self.miner.all_transactions();
|
let mut transactions = io.chain().all_transactions();
|
||||||
if transactions.is_empty() {
|
if transactions.is_empty() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1276,11 +1267,9 @@ impl ChainSync {
|
|||||||
self.check_resume(io);
|
self.check_resume(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// called when block is imported to chain, updates transactions queue and propagates the blocks
|
/// called when block is imported to chain, updates transactions queue and propagates the blocks
|
||||||
pub fn chain_new_blocks(&mut self, io: &mut SyncIo, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256]) {
|
pub fn chain_new_blocks(&mut self, io: &mut SyncIo, _imported: &[H256], invalid: &[H256], _enacted: &[H256], _retracted: &[H256]) {
|
||||||
if io.is_chain_queue_empty() {
|
if io.is_chain_queue_empty() {
|
||||||
// Notify miner
|
|
||||||
self.miner.chain_new_blocks(io.chain(), imported, invalid, enacted, retracted);
|
|
||||||
// Propagate latests blocks
|
// Propagate latests blocks
|
||||||
self.propagate_latest_blocks(io);
|
self.propagate_latest_blocks(io);
|
||||||
}
|
}
|
||||||
@ -1289,10 +1278,6 @@ impl ChainSync {
|
|||||||
self.restart_on_bad_block(io);
|
self.restart_on_bad_block(io);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chain_new_head(&mut self, io: &mut SyncIo) {
|
|
||||||
self.miner.update_sealing(io.chain());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -1305,8 +1290,7 @@ mod tests {
|
|||||||
use ethcore::views::BlockView;
|
use ethcore::views::BlockView;
|
||||||
use ethcore::header::*;
|
use ethcore::header::*;
|
||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::spec::Spec;
|
use ethcore::miner::MinerService;
|
||||||
use ethminer::{Miner, MinerService};
|
|
||||||
|
|
||||||
fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes {
|
fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes {
|
||||||
let mut header = Header::new();
|
let mut header = Header::new();
|
||||||
@ -1480,7 +1464,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dummy_sync_with_peer(peer_latest_hash: H256, client: &BlockChainClient) -> ChainSync {
|
fn dummy_sync_with_peer(peer_latest_hash: H256, client: &BlockChainClient) -> ChainSync {
|
||||||
let mut sync = ChainSync::new(SyncConfig::default(), Miner::new(false, Spec::new_test()), client);
|
let mut sync = ChainSync::new(SyncConfig::default(), client);
|
||||||
sync.peers.insert(0,
|
sync.peers.insert(0,
|
||||||
PeerInfo {
|
PeerInfo {
|
||||||
protocol_version: 0,
|
protocol_version: 0,
|
||||||
@ -1711,9 +1695,10 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let mut queue = VecDeque::new();
|
let mut queue = VecDeque::new();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
io.chain.miner.chain_new_blocks(io.chain, &[], &[], &[], &good_blocks);
|
||||||
sync.chain_new_blocks(&mut io, &[], &[], &[], &good_blocks);
|
sync.chain_new_blocks(&mut io, &[], &[], &[], &good_blocks);
|
||||||
assert_eq!(sync.miner.status().transactions_in_future_queue, 0);
|
assert_eq!(io.chain.miner.status().transactions_in_future_queue, 0);
|
||||||
assert_eq!(sync.miner.status().transactions_in_pending_queue, 1);
|
assert_eq!(io.chain.miner.status().transactions_in_pending_queue, 1);
|
||||||
}
|
}
|
||||||
// We need to update nonce status (because we say that the block has been imported)
|
// We need to update nonce status (because we say that the block has been imported)
|
||||||
for h in &[good_blocks[0]] {
|
for h in &[good_blocks[0]] {
|
||||||
@ -1724,11 +1709,12 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let mut queue = VecDeque::new();
|
let mut queue = VecDeque::new();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
io.chain.miner.chain_new_blocks(io.chain, &[], &[], &good_blocks, &retracted_blocks);
|
||||||
sync.chain_new_blocks(&mut io, &[], &[], &good_blocks, &retracted_blocks);
|
sync.chain_new_blocks(&mut io, &[], &[], &good_blocks, &retracted_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// then
|
// then
|
||||||
let status = sync.miner.status();
|
let status = client.miner.status();
|
||||||
assert_eq!(status.transactions_in_pending_queue, 1);
|
assert_eq!(status.transactions_in_pending_queue, 1);
|
||||||
assert_eq!(status.transactions_in_future_queue, 0);
|
assert_eq!(status.transactions_in_future_queue, 0);
|
||||||
}
|
}
|
||||||
@ -1750,12 +1736,12 @@ mod tests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
sync.chain_new_blocks(&mut io, &[], &[], &[], &good_blocks);
|
sync.chain_new_blocks(&mut io, &[], &[], &[], &good_blocks);
|
||||||
assert_eq!(sync.miner.status().transactions_in_future_queue, 0);
|
assert_eq!(io.chain.miner.status().transactions_in_future_queue, 0);
|
||||||
assert_eq!(sync.miner.status().transactions_in_pending_queue, 0);
|
assert_eq!(io.chain.miner.status().transactions_in_pending_queue, 0);
|
||||||
sync.chain_new_blocks(&mut io, &[], &[], &good_blocks, &retracted_blocks);
|
sync.chain_new_blocks(&mut io, &[], &[], &good_blocks, &retracted_blocks);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
let status = sync.miner.status();
|
let status = io.chain.miner.status();
|
||||||
assert_eq!(status.transactions_in_pending_queue, 0);
|
assert_eq!(status.transactions_in_pending_queue, 0);
|
||||||
assert_eq!(status.transactions_in_future_queue, 0);
|
assert_eq!(status.transactions_in_future_queue, 0);
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use ethcore::client::BlockChainClient;
|
|
||||||
use util::{NetworkContext, PeerId, PacketId,};
|
use util::{NetworkContext, PeerId, PacketId,};
|
||||||
use util::error::UtilError;
|
use util::error::UtilError;
|
||||||
use ethcore::service::SyncMessage;
|
use ethcore::service::SyncMessage;
|
||||||
|
use ethcore::client::BlockChainClient;
|
||||||
|
|
||||||
/// IO interface for the syning handler.
|
/// IO interface for the syning handler.
|
||||||
/// Provides peer connection management and an interface to the blockchain client.
|
/// Provides peer connection management and an interface to the blockchain client.
|
||||||
|
@ -32,21 +32,20 @@
|
|||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_util as util;
|
||||||
//! extern crate ethcore;
|
//! extern crate ethcore;
|
||||||
//! extern crate ethsync;
|
//! extern crate ethsync;
|
||||||
//! extern crate ethminer;
|
|
||||||
//! use std::env;
|
//! use std::env;
|
||||||
//! use std::sync::Arc;
|
//! use std::sync::Arc;
|
||||||
//! use util::network::{NetworkService, NetworkConfiguration};
|
//! use util::network::{NetworkService, NetworkConfiguration};
|
||||||
//! use ethcore::client::{Client, ClientConfig};
|
//! use ethcore::client::{Client, ClientConfig};
|
||||||
//! use ethsync::{EthSync, SyncConfig};
|
//! use ethsync::{EthSync, SyncConfig};
|
||||||
//! use ethminer::Miner;
|
|
||||||
//! use ethcore::ethereum;
|
//! use ethcore::ethereum;
|
||||||
|
//! use ethcore::miner::Miner;
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let mut service = NetworkService::start(NetworkConfiguration::new()).unwrap();
|
//! let mut service = NetworkService::start(NetworkConfiguration::new()).unwrap();
|
||||||
//! let dir = env::temp_dir();
|
//! let dir = env::temp_dir();
|
||||||
//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, service.io().channel()).unwrap();
|
//! let client = Client::new(ClientConfig::default(), ethereum::new_frontier(), &dir, Arc::new(Miner::default()), service.io().channel()).unwrap();
|
||||||
//! let miner = Miner::new(false, ethereum::new_frontier());
|
//! let miner = Miner::new(false, ethereum::new_frontier());
|
||||||
//! EthSync::register(&mut service, SyncConfig::default(), client, miner);
|
//! EthSync::register(&mut service, SyncConfig::default(), client);
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
@ -55,7 +54,6 @@ extern crate log;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate ethminer;
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
@ -69,7 +67,6 @@ use util::TimerToken;
|
|||||||
use util::{U256, ONE_U256};
|
use util::{U256, ONE_U256};
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use ethcore::service::SyncMessage;
|
use ethcore::service::SyncMessage;
|
||||||
use ethminer::Miner;
|
|
||||||
use io::NetSyncIo;
|
use io::NetSyncIo;
|
||||||
use chain::ChainSync;
|
use chain::ChainSync;
|
||||||
|
|
||||||
@ -115,8 +112,8 @@ pub use self::chain::{SyncStatus, SyncState};
|
|||||||
|
|
||||||
impl EthSync {
|
impl EthSync {
|
||||||
/// Creates and register protocol with the network service
|
/// Creates and register protocol with the network service
|
||||||
pub fn register(service: &mut NetworkService<SyncMessage>, config: SyncConfig, chain: Arc<Client>, miner: Arc<Miner>) -> Arc<EthSync> {
|
pub fn register(service: &mut NetworkService<SyncMessage>, config: SyncConfig, chain: Arc<Client>) -> Arc<EthSync> {
|
||||||
let sync = ChainSync::new(config, miner, chain.deref());
|
let sync = ChainSync::new(config, chain.deref());
|
||||||
let sync = Arc::new(EthSync {
|
let sync = Arc::new(EthSync {
|
||||||
chain: chain,
|
chain: chain,
|
||||||
sync: RwLock::new(sync),
|
sync: RwLock::new(sync),
|
||||||
@ -171,10 +168,6 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
|||||||
let mut sync_io = NetSyncIo::new(io, self.chain.deref());
|
let mut sync_io = NetSyncIo::new(io, self.chain.deref());
|
||||||
self.sync.write().unwrap().chain_new_blocks(&mut sync_io, imported, invalid, enacted, retracted);
|
self.sync.write().unwrap().chain_new_blocks(&mut sync_io, imported, invalid, enacted, retracted);
|
||||||
},
|
},
|
||||||
SyncMessage::NewChainHead => {
|
|
||||||
let mut sync_io = NetSyncIo::new(io, self.chain.deref());
|
|
||||||
self.sync.write().unwrap().chain_new_head(&mut sync_io);
|
|
||||||
},
|
|
||||||
_ => {/* Ignore other messages */},
|
_ => {/* Ignore other messages */},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::client::{TestBlockChainClient, BlockChainClient};
|
use ethcore::client::{TestBlockChainClient, BlockChainClient};
|
||||||
use ethcore::spec::Spec;
|
|
||||||
use io::SyncIo;
|
use io::SyncIo;
|
||||||
use chain::ChainSync;
|
use chain::ChainSync;
|
||||||
use ethminer::Miner;
|
|
||||||
use ::SyncConfig;
|
use ::SyncConfig;
|
||||||
|
|
||||||
pub struct TestIo<'p> {
|
pub struct TestIo<'p> {
|
||||||
@ -93,7 +91,7 @@ impl TestNet {
|
|||||||
};
|
};
|
||||||
for _ in 0..n {
|
for _ in 0..n {
|
||||||
let chain = TestBlockChainClient::new();
|
let chain = TestBlockChainClient::new();
|
||||||
let sync = ChainSync::new(SyncConfig::default(), Miner::new(false, Spec::new_test()), &chain);
|
let sync = ChainSync::new(SyncConfig::default(), &chain);
|
||||||
net.peers.push(TestPeer {
|
net.peers.push(TestPeer {
|
||||||
sync: sync,
|
sync: sync,
|
||||||
chain: chain,
|
chain: chain,
|
||||||
|
Loading…
Reference in New Issue
Block a user