eth_getwork implemented.
This commit is contained in:
parent
2c32b0fc1c
commit
ffc5c2ea7b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -203,6 +203,7 @@ name = "ethcore-rpc"
|
||||
version = "0.9.99"
|
||||
dependencies = [
|
||||
"clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethash 0.9.99",
|
||||
"ethcore 0.9.99",
|
||||
"ethcore-util 0.9.99",
|
||||
"ethsync 0.9.99",
|
||||
|
@ -172,7 +172,8 @@ fn get_data_size(block_number: u64) -> usize {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_seedhash(block_number: u64) -> H256 {
|
||||
/// Given the `block_number`, determine the seed hash for Ethash.
|
||||
pub fn get_seedhash(block_number: u64) -> H256 {
|
||||
let epochs = block_number / ETHASH_EPOCH_LENGTH;
|
||||
let mut ret: H256 = [0u8; 32];
|
||||
for _ in 0..epochs {
|
||||
|
@ -24,7 +24,7 @@ mod compute;
|
||||
|
||||
use std::mem;
|
||||
use compute::Light;
|
||||
pub use compute::{quick_get_difficulty, H256, ProofOfWork, ETHASH_EPOCH_LENGTH};
|
||||
pub use compute::{get_seedhash, quick_get_difficulty, H256, ProofOfWork, ETHASH_EPOCH_LENGTH};
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@ -35,7 +35,7 @@ struct LightCache {
|
||||
prev: Option<Arc<Light>>,
|
||||
}
|
||||
|
||||
/// Lighy/Full cache manager
|
||||
/// Light/Full cache manager.
|
||||
pub struct EthashManager {
|
||||
cache: Mutex<LightCache>,
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ pub struct Client {
|
||||
panic_handler: Arc<PanicHandler>,
|
||||
|
||||
// for sealing...
|
||||
_sealing_block: Mutex<Option<ClosedBlock>>,
|
||||
sealing_block: Mutex<Option<ClosedBlock>>,
|
||||
}
|
||||
|
||||
const HISTORY: u64 = 1000;
|
||||
@ -232,7 +232,7 @@ impl Client {
|
||||
report: RwLock::new(Default::default()),
|
||||
import_lock: Mutex::new(()),
|
||||
panic_handler: panic_handler,
|
||||
_sealing_block: Mutex::new(None),
|
||||
sealing_block: Mutex::new(None),
|
||||
}))
|
||||
}
|
||||
|
||||
@ -417,9 +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 CHAIN HEAD: #{}: {}", self.chain.read().unwrap().best_block_number(), h);
|
||||
|
||||
info!("Preparing to seal.");
|
||||
info!("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(),
|
||||
@ -430,8 +428,11 @@ impl Client {
|
||||
);
|
||||
let b = b.close();
|
||||
info!("Sealed: 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);
|
||||
}
|
||||
|
||||
/// Grab the `ClosedBlock` that we want to be sealed. Comes as a mutex that you have to lock.
|
||||
pub fn sealing_block(&self) -> &Mutex<Option<ClosedBlock>> { &self.sealing_block }
|
||||
}
|
||||
|
||||
// TODO: need MinerService MinerIoHandler
|
||||
|
@ -241,10 +241,16 @@ impl Ethash {
|
||||
target
|
||||
}
|
||||
|
||||
fn boundary_to_difficulty(boundary: &H256) -> U256 {
|
||||
/// Convert an Ethash boundary to its original difficulty. Basically just `f(x) = 2^256 / x`.
|
||||
pub fn boundary_to_difficulty(boundary: &H256) -> U256 {
|
||||
U256::from((U512::one() << 256) / x!(U256::from(boundary.as_slice())))
|
||||
}
|
||||
|
||||
/// Convert an Ethash difficulty to the target boundary. Basically just `f(x) = 2^256 / x`.
|
||||
pub fn difficulty_to_boundary(difficulty: &U256) -> H256 {
|
||||
x!(U256::from((U512::one() << 256) / x!(difficulty)))
|
||||
}
|
||||
|
||||
fn to_ethash(hash: H256) -> EH256 {
|
||||
unsafe { mem::transmute(hash) }
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ jsonrpc-core = "1.2"
|
||||
jsonrpc-http-server = "2.1"
|
||||
ethcore-util = { path = "../util" }
|
||||
ethcore = { path = "../ethcore" }
|
||||
ethash = { path = "../ethash" }
|
||||
ethsync = { path = "../sync" }
|
||||
clippy = { version = "0.0.44", optional = true }
|
||||
rustc-serialize = "0.3"
|
||||
|
@ -22,7 +22,11 @@ use util::hash::*;
|
||||
use util::uint::*;
|
||||
use util::sha3::*;
|
||||
use ethcore::client::*;
|
||||
use ethcore::block::{IsBlock};
|
||||
use ethcore::views::*;
|
||||
extern crate ethash;
|
||||
use self::ethash::get_seedhash;
|
||||
use ethcore::ethereum::Ethash;
|
||||
use ethcore::ethereum::denominations::shannon;
|
||||
use v1::traits::{Eth, EthFilter};
|
||||
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, OptionalValue, Index, Filter, Log};
|
||||
@ -209,6 +213,29 @@ impl Eth for EthClient {
|
||||
to_value(&logs)
|
||||
})
|
||||
}
|
||||
|
||||
fn work(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => {
|
||||
let c = take_weak!(self.client);
|
||||
let u = c.sealing_block().lock().unwrap();
|
||||
match *u {
|
||||
Some(ref b) => {
|
||||
let current_hash = b.hash();
|
||||
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
|
||||
let seed_hash = get_seedhash(b.block().header().number());
|
||||
to_value(&(current_hash, seed_hash, target))
|
||||
}
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
},
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
|
||||
// fn submit_work(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
// fn submit_hashrate(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
}
|
||||
|
||||
/// Eth filter rpc implementation.
|
||||
|
@ -69,5 +69,5 @@ pub fn contents(name: &str) -> Result<Bytes, UtilError> {
|
||||
|
||||
/// Get the standard version string for this software.
|
||||
pub fn version() -> String {
|
||||
format!("Parity//{}-{}-{}/{}-{}-{}/rustc{}", env!("CARGO_PKG_VERSION"), short_sha(), commit_date().replace("-", ""), Target::arch(), Target::os(), Target::env(), rustc_version::version())
|
||||
format!("Parity//v{}-{}-{}/{}-{}-{}/rustc{}", env!("CARGO_PKG_VERSION"), short_sha(), commit_date().replace("-", ""), Target::arch(), Target::os(), Target::env(), rustc_version::version())
|
||||
}
|
@ -1124,6 +1124,33 @@ impl From<U512> for U256 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a U256> for U512 {
|
||||
fn from(value: &'a U256) -> U512 {
|
||||
let U256(ref arr) = *value;
|
||||
let mut ret = [0; 8];
|
||||
ret[0] = arr[0];
|
||||
ret[1] = arr[1];
|
||||
ret[2] = arr[2];
|
||||
ret[3] = arr[3];
|
||||
U512(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a U512> for U256 {
|
||||
fn from(value: &'a U512) -> U256 {
|
||||
let U512(ref arr) = *value;
|
||||
if arr[4] | arr[5] | arr[6] | arr[7] != 0 {
|
||||
panic!("Overflow");
|
||||
}
|
||||
let mut ret = [0; 4];
|
||||
ret[0] = arr[0];
|
||||
ret[1] = arr[1];
|
||||
ret[2] = arr[2];
|
||||
ret[3] = arr[3];
|
||||
U256(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<U256> for U128 {
|
||||
fn from(value: U256) -> U128 {
|
||||
let U256(ref arr) = value;
|
||||
|
Loading…
Reference in New Issue
Block a user