Hashrate now reported correctly.
This commit is contained in:
parent
2266d74c2a
commit
5ccb172e73
@ -417,7 +417,7 @@ impl Client {
|
|||||||
/// New chain head event.
|
/// New chain head event.
|
||||||
pub fn new_chain_head(&self) {
|
pub fn new_chain_head(&self) {
|
||||||
let h = self.chain.read().unwrap().best_block_hash();
|
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(
|
let b = OpenBlock::new(
|
||||||
self.engine.deref().deref(),
|
self.engine.deref().deref(),
|
||||||
self.state_db.lock().unwrap().clone(),
|
self.state_db.lock().unwrap().clone(),
|
||||||
@ -427,7 +427,7 @@ impl Client {
|
|||||||
b"Parity".to_vec()
|
b"Parity".to_vec()
|
||||||
);
|
);
|
||||||
let b = b.close();
|
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);
|
*self.sealing_block.lock().unwrap() = Some(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Eth rpc implementation.
|
//! Eth rpc implementation.
|
||||||
use std::sync::{Arc, Weak};
|
|
||||||
use ethsync::{EthSync, SyncState};
|
use ethsync::{EthSync, SyncState};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
|
use util::standard::{RwLock, HashMap, Arc, Weak};
|
||||||
use util::rlp::encode;
|
use util::rlp::encode;
|
||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::block::{IsBlock};
|
use ethcore::block::{IsBlock};
|
||||||
@ -34,7 +34,8 @@ use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncIn
|
|||||||
/// Eth rpc implementation.
|
/// Eth rpc implementation.
|
||||||
pub struct EthClient {
|
pub struct EthClient {
|
||||||
client: Weak<Client>,
|
client: Weak<Client>,
|
||||||
sync: Weak<EthSync>
|
sync: Weak<EthSync>,
|
||||||
|
hashrates: RwLock<HashMap<H256, u64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthClient {
|
impl EthClient {
|
||||||
@ -42,7 +43,8 @@ impl EthClient {
|
|||||||
pub fn new(client: &Arc<Client>, sync: &Arc<EthSync>) -> Self {
|
pub fn new(client: &Arc<Client>, sync: &Arc<EthSync>) -> Self {
|
||||||
EthClient {
|
EthClient {
|
||||||
client: Arc::downgrade(client),
|
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
|
// TODO: return real hashrate once we have mining
|
||||||
fn hashrate(&self, params: Params) -> Result<Value, Error> {
|
fn hashrate(&self, params: Params) -> Result<Value, Error> {
|
||||||
match params {
|
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())
|
_ => Err(Error::invalid_params())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +217,6 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn work(&self, params: Params) -> Result<Value, Error> {
|
fn work(&self, params: Params) -> Result<Value, Error> {
|
||||||
println!("Work wanted: {:?}", params);
|
|
||||||
match params {
|
match params {
|
||||||
Params::None => {
|
Params::None => {
|
||||||
let c = take_weak!(self.client);
|
let c = take_weak!(self.client);
|
||||||
@ -235,6 +236,7 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn submit_work(&self, params: Params) -> Result<Value, Error> {
|
fn submit_work(&self, params: Params) -> Result<Value, Error> {
|
||||||
|
// TODO: println! should be debug!
|
||||||
println!("Work submission: {:?}", params);
|
println!("Work submission: {:?}", params);
|
||||||
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
|
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
|
||||||
let c = take_weak!(self.client);
|
let c = take_weak!(self.client);
|
||||||
@ -244,9 +246,9 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn submit_hashrate(&self, params: Params) -> Result<Value, Error> {
|
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)| {
|
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)
|
to_value(&true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user