eth_getwork implemented.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -144,9 +144,9 @@ impl Engine for Ethash {
|
||||
}
|
||||
|
||||
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty(
|
||||
&Ethash::to_ethash(header.bare_hash()),
|
||||
header.nonce().low_u64(),
|
||||
&Ethash::to_ethash(header.mix_hash()))));
|
||||
&Ethash::to_ethash(header.bare_hash()),
|
||||
header.nonce().low_u64(),
|
||||
&Ethash::to_ethash(header.mix_hash()) )));
|
||||
if difficulty < header.difficulty {
|
||||
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty })));
|
||||
}
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user