Merge remote-tracking branch 'origin/master' into bettermining

This commit is contained in:
Gav Wood 2016-03-24 23:10:54 +01:00
commit d50c9f9fac
5 changed files with 37 additions and 23 deletions

View File

@ -16,6 +16,7 @@
//! Test client. //! Test client.
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;
@ -55,6 +56,8 @@ pub struct TestBlockChainClient {
pub execution_result: RwLock<Option<Executed>>, pub execution_result: RwLock<Option<Executed>>,
/// Transaction receipts. /// Transaction receipts.
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>, pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
/// Block queue size.
pub queue_size: AtomicUsize,
} }
#[derive(Clone)] #[derive(Clone)]
@ -91,6 +94,7 @@ impl TestBlockChainClient {
code: RwLock::new(HashMap::new()), code: RwLock::new(HashMap::new()),
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),
}; };
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();
@ -122,6 +126,11 @@ impl TestBlockChainClient {
self.storage.write().unwrap().insert((address, position), value); self.storage.write().unwrap().insert((address, position), value);
} }
/// Set block queue size for testing
pub fn set_queue_size(&self, size: usize) {
self.queue_size.store(size, AtomicOrder::Relaxed);
}
/// Add blocks to test client. /// Add blocks to test client.
pub fn add_blocks(&self, count: usize, with: EachBlockWith) { pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
let len = self.numbers.read().unwrap().len(); let len = self.numbers.read().unwrap().len();
@ -384,7 +393,7 @@ impl BlockChainClient for TestBlockChainClient {
fn queue_info(&self) -> BlockQueueInfo { fn queue_info(&self) -> BlockQueueInfo {
BlockQueueInfo { BlockQueueInfo {
verified_queue_size: 0, verified_queue_size: self.queue_size.load(AtomicOrder::Relaxed),
unverified_queue_size: 0, unverified_queue_size: 0,
verifying_queue_size: 0, verifying_queue_size: 0,
max_queue_size: 0, max_queue_size: 0,

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PARITY_DEB_URL=https://github.com/ethcore/parity/releases/download/v1.0.0-rc1/parity_linux_1.0.0.rc1-0_amd64.deb PARITY_DEB_URL=https://github.com/ethcore/parity/releases/download/v1.0.0/parity_linux_1.0.0-0_amd64.deb
function run_installer() function run_installer()
@ -435,13 +435,8 @@ function run_installer()
echo echo
info "Installing parity" info "Installing parity"
if [[ $isEth == true ]] brew reinstall parity
then brew linkapps parity
brew reinstall parity
else
brew install parity
brew linkapps parity
fi
echo echo
} }

View File

@ -215,18 +215,18 @@ impl MinerService for Miner {
} }
fn update_sealing(&self, chain: &BlockChainClient) { fn update_sealing(&self, chain: &BlockChainClient) {
let should_disable_sealing = { 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 last_request = self.sealing_block_last_request.lock().unwrap(); let last_request = *self.sealing_block_last_request.lock().unwrap();
let is_greater = current_no > *last_request; let should_disable_sealing = current_no > last_request && current_no - last_request > SEALING_TIMEOUT_IN_BLOCKS;
is_greater && current_no - *last_request > SEALING_TIMEOUT_IN_BLOCKS
};
if should_disable_sealing { if should_disable_sealing {
self.sealing_enabled.store(false, atomic::Ordering::Relaxed); trace!(target: "miner", "Miner sleeping (current {}, last {})", current_no, last_request);
self.sealing_work.lock().unwrap().reset(); self.sealing_enabled.store(false, atomic::Ordering::Relaxed);
} else if self.sealing_enabled.load(atomic::Ordering::Relaxed) { self.sealing_work.lock().unwrap().reset();
self.prepare_sealing(chain); } else if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
self.prepare_sealing(chain);
}
} }
} }
@ -236,7 +236,12 @@ impl MinerService for Miner {
self.sealing_enabled.store(true, atomic::Ordering::Relaxed); self.sealing_enabled.store(true, atomic::Ordering::Relaxed);
self.prepare_sealing(chain); self.prepare_sealing(chain);
} }
*self.sealing_block_last_request.lock().unwrap() = chain.chain_info().best_block_number; let mut sealing_block_last_request = self.sealing_block_last_request.lock().unwrap();
let best_number = chain.chain_info().best_block_number;
if *sealing_block_last_request != best_number {
trace!(target: "miner", "Miner received request (was {}, now {}) - waking up.", *sealing_block_last_request, best_number);
*sealing_block_last_request = best_number;
}
self.sealing_work.lock().unwrap().use_last_ref().map(f) self.sealing_work.lock().unwrap().use_last_ref().map(f)
} }

View File

@ -197,6 +197,8 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
} }
} }
const MAX_QUEUE_SIZE_TO_MINE_ON: usize = 4; // because uncles go back 6.
impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
where C: BlockChainClient + 'static, where C: BlockChainClient + 'static,
S: SyncProvider + 'static, S: SyncProvider + 'static,
@ -400,8 +402,10 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
let client = take_weak!(self.client); let client = take_weak!(self.client);
// check if we're still syncing and return empty strings in that case // check if we're still syncing and return empty strings in that case
{ {
let sync = take_weak!(self.sync); //TODO: check if initial sync is complete here
if sync.status().state != SyncState::Idle && client.queue_info().is_empty() { //let sync = take_weak!(self.sync);
if /*sync.status().state != SyncState::Idle ||*/ client.queue_info().total_queue_size() > MAX_QUEUE_SIZE_TO_MINE_ON {
trace!(target: "miner", "Syncing. Cannot give any work.");
return to_value(&(String::new(), String::new(), String::new())); return to_value(&(String::new(), String::new(), String::new()));
} }
} }

View File

@ -476,7 +476,8 @@ fn rpc_eth_compile_serpent() {
#[test] #[test]
fn returns_no_work_if_cant_mine() { fn returns_no_work_if_cant_mine() {
let eth_tester = EthTester::default(); let mut eth_tester = EthTester::default();
eth_tester.client.set_queue_size(10);
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#; let response = r#"{"jsonrpc":"2.0","result":["","",""],"id":1}"#;