rename of the trait
This commit is contained in:
parent
8e252d5f1b
commit
a845e08bc6
@ -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, ExtendedBlockChainClient, 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};
|
||||||
@ -722,7 +722,7 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> ExtendedBlockChainClient for Client<V> where V: Verifier {
|
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>)
|
fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec<SignedTransaction>)
|
||||||
-> (Option<ClosedBlock>, HashSet<H256>) {
|
-> (Option<ClosedBlock>, HashSet<H256>) {
|
||||||
let engine = self.engine.deref().deref();
|
let engine = self.engine.deref().deref();
|
||||||
|
@ -185,7 +185,7 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extended client interface used for mining
|
/// Extended client interface used for mining
|
||||||
pub trait ExtendedBlockChainClient : BlockChainClient {
|
pub trait MiningBlockChainClient : BlockChainClient {
|
||||||
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
/// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error.
|
||||||
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
|
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
|
||||||
|
|
||||||
|
@ -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, ExtendedBlockChainClient, 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;
|
||||||
@ -235,7 +235,7 @@ impl TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtendedBlockChainClient for TestBlockChainClient {
|
impl MiningBlockChainClient for TestBlockChainClient {
|
||||||
fn try_seal(&self, block: LockedBlock, _seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
fn try_seal(&self, block: LockedBlock, _seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
||||||
Err(block)
|
Err(block)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use std::sync::atomic::AtomicBool;
|
|||||||
use util::*;
|
use util::*;
|
||||||
use util::keys::store::{AccountService, AccountProvider};
|
use util::keys::store::{AccountService, AccountProvider};
|
||||||
use views::{BlockView, HeaderView};
|
use views::{BlockView, HeaderView};
|
||||||
use client::{ExtendedBlockChainClient, BlockID};
|
use client::{MiningBlockChainClient, BlockID};
|
||||||
use block::{ClosedBlock, IsBlock};
|
use block::{ClosedBlock, IsBlock};
|
||||||
use error::*;
|
use error::*;
|
||||||
use client::{Executive, Executed, EnvInfo, TransactOptions};
|
use client::{Executive, Executed, EnvInfo, TransactOptions};
|
||||||
@ -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: &ExtendedBlockChainClient) {
|
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();
|
||||||
@ -206,14 +206,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: &ExtendedBlockChainClient) {
|
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: &ExtendedBlockChainClient) -> 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);
|
||||||
@ -237,7 +237,7 @@ const SEALING_TIMEOUT_IN_BLOCKS : u64 = 5;
|
|||||||
|
|
||||||
impl MinerService for Miner {
|
impl MinerService for Miner {
|
||||||
|
|
||||||
fn clear_and_reset(&self, chain: &ExtendedBlockChainClient) {
|
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);
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&self, chain: &ExtendedBlockChainClient, 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) => {
|
||||||
@ -288,7 +288,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn balance(&self, chain: &ExtendedBlockChainClient, 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),
|
||||||
@ -296,7 +296,7 @@ impl MinerService for Miner {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_at(&self, chain: &ExtendedBlockChainClient, 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),
|
||||||
@ -304,12 +304,12 @@ impl MinerService for Miner {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nonce(&self, chain: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, 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))
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ impl MinerService for Miner {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn import_own_transaction<T>(&self, chain: &ExtendedBlockChainClient, 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();
|
||||||
@ -470,7 +470,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: &ExtendedBlockChainClient) {
|
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();
|
||||||
@ -490,7 +490,7 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_sealing_work<F, T>(&self, chain: &ExtendedBlockChainClient, 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");
|
||||||
@ -500,7 +500,7 @@ impl MinerService for Miner {
|
|||||||
ret.map(f)
|
ret.map(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_seal(&self, chain: &ExtendedBlockChainClient, 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(_) => {
|
||||||
@ -523,8 +523,8 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chain_new_blocks(&self, chain: &ExtendedBlockChainClient, _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: &ExtendedBlockChainClient, 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.
|
||||||
|
@ -52,7 +52,7 @@ 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 client::{ExtendedBlockChainClient, Executed};
|
use client::{MiningBlockChainClient, Executed};
|
||||||
use block::ClosedBlock;
|
use block::ClosedBlock;
|
||||||
use receipt::Receipt;
|
use receipt::Receipt;
|
||||||
use error::{Error, ExecutionError};
|
use error::{Error, ExecutionError};
|
||||||
@ -100,7 +100,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: &ExtendedBlockChainClient, 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;
|
||||||
|
|
||||||
@ -108,20 +108,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: &ExtendedBlockChainClient);
|
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: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient);
|
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: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, 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.
|
||||||
@ -146,19 +146,19 @@ pub trait MinerService : Send + Sync {
|
|||||||
fn sensible_gas_limit(&self) -> U256 { x!(21000) }
|
fn sensible_gas_limit(&self) -> U256 { x!(21000) }
|
||||||
|
|
||||||
/// Latest account balance in pending state.
|
/// Latest account balance in pending state.
|
||||||
fn balance(&self, chain: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, 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: &ExtendedBlockChainClient, address: &Address) -> Option<Bytes>;
|
fn code(&self, chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mining status
|
/// Mining status
|
||||||
|
Loading…
Reference in New Issue
Block a user