Hashrate now reported correctly.

This commit is contained in:
Gav Wood 2016-03-01 01:52:22 +01:00
parent 2266d74c2a
commit 5ccb172e73
2 changed files with 11 additions and 9 deletions

View File

@ -417,7 +417,7 @@ impl Client {
/// New chain head event.
pub fn new_chain_head(&self) {
let h = self.chain.read().unwrap().best_block_hash();
info!("New best block: #{}: {}", self.chain.read().unwrap().best_block_number(), h);
debug!("New best block: #{}: {}", self.chain.read().unwrap().best_block_number(), h);
let b = OpenBlock::new(
self.engine.deref().deref(),
self.state_db.lock().unwrap().clone(),
@ -427,7 +427,7 @@ impl Client {
b"Parity".to_vec()
);
let b = b.close();
info!("Sealed: hash={}, diff={}, number={}", b.hash(), b.block().header().difficulty(), b.block().header().number());
debug!("Sealing: hash={}, diff={}, number={}", b.hash(), b.block().header().difficulty(), b.block().header().number());
*self.sealing_block.lock().unwrap() = Some(b);
}

View File

@ -15,12 +15,12 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Eth rpc implementation.
use std::sync::{Arc, Weak};
use ethsync::{EthSync, SyncState};
use jsonrpc_core::*;
use util::hash::*;
use util::uint::*;
use util::sha3::*;
use util::standard::{RwLock, HashMap, Arc, Weak};
use util::rlp::encode;
use ethcore::client::*;
use ethcore::block::{IsBlock};
@ -34,7 +34,8 @@ use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncIn
/// Eth rpc implementation.
pub struct EthClient {
client: Weak<Client>,
sync: Weak<EthSync>
sync: Weak<EthSync>,
hashrates: RwLock<HashMap<H256, u64>>,
}
impl EthClient {
@ -42,7 +43,8 @@ impl EthClient {
pub fn new(client: &Arc<Client>, sync: &Arc<EthSync>) -> Self {
EthClient {
client: Arc::downgrade(client),
sync: Arc::downgrade(sync)
sync: Arc::downgrade(sync),
hashrates: RwLock::new(HashMap::new()),
}
}
@ -137,7 +139,7 @@ impl Eth for EthClient {
// TODO: return real hashrate once we have mining
fn hashrate(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => to_value(&U256::zero()),
Params::None => to_value(&self.hashrates.read().unwrap().iter().fold(0u64, |sum, (_, v)| sum + v)),
_ => Err(Error::invalid_params())
}
}
@ -215,7 +217,6 @@ impl Eth for EthClient {
}
fn work(&self, params: Params) -> Result<Value, Error> {
println!("Work wanted: {:?}", params);
match params {
Params::None => {
let c = take_weak!(self.client);
@ -235,6 +236,7 @@ impl Eth for EthClient {
}
fn submit_work(&self, params: Params) -> Result<Value, Error> {
// TODO: println! should be debug!
println!("Work submission: {:?}", params);
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
let c = take_weak!(self.client);
@ -244,9 +246,9 @@ impl Eth for EthClient {
}
fn submit_hashrate(&self, params: Params) -> Result<Value, Error> {
println!("Hashrate submission: {:?}", params);
// TODO: Index should be U256.
from_params::<(Index, H256)>(params).and_then(|(rate, id)| {
println!("Miner {} reports a hash rate of {} H/s", id, rate.value());
self.hashrates.write().unwrap().insert(id, rate.value() as u64);
to_value(&true)
})
}