Browse Source

Fix for mining, possibly.

cl-refactor
Gav Wood 10 years ago
parent
commit
53da2881e9
  1. 9
      libethereum/Client.cpp
  2. 42
      libethereum/State.h
  3. 2
      mix/MixClient.cpp

9
libethereum/Client.cpp

@ -205,20 +205,11 @@ void Client::startedWorking()
// TODO: currently it contains keys for *all* blocks. Make it remove old ones.
cdebug << "startedWorking()";
cdebug << m_bc.number() << m_bc.currentHash();
cdebug << "Pre:" << m_preMine.info();
cdebug << "Post:" << m_postMine.info();
cdebug << "Pre:" << m_preMine.info().headerHash(WithoutNonce) << "; Post:" << m_postMine.info().headerHash(WithoutNonce);
ETH_WRITE_GUARDED(x_preMine)
m_preMine.sync(m_bc);
ETH_WRITE_GUARDED(x_postMine)
ETH_READ_GUARDED(x_preMine)
m_postMine = m_preMine;
cdebug << "Pre:" << m_preMine.info();
cdebug << "Post:" << m_postMine.info();
cdebug << "Pre:" << m_preMine.info().headerHash(WithoutNonce) << "; Post:" << m_postMine.info().headerHash(WithoutNonce);
}
void Client::doneWorking()

42
libethereum/State.h

@ -161,15 +161,18 @@ public:
/// This may be called multiple times and without issue.
void commitToMine(BlockChain const& _bc);
/// @returns true iff commitToMine() has been called without any subsequest transactions added &c.
bool isCommittedToMine() const { return m_committedToMine; }
/// Pass in a solution to the proof-of-work.
/// @returns true iff the given nonce is a proof-of-work for this State's block.
/// @returns true iff we were previously committed to mining.
template <class PoW>
bool completeMine(typename PoW::Solution const& _result)
{
PoW::assignResult(_result, m_currentBlock);
if (!m_committedToMine)
return false;
// if (!m_pow.verify(m_currentBlock))
// return false;
PoW::assignResult(_result, m_currentBlock);
cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << PoW::verify(m_currentBlock);
@ -178,24 +181,6 @@ public:
return true;
}
/** Commit to DB and build the final block if the previous call to mine()'s result is completion.
* Typically looks like:
* @code
* while (notYetMined)
* {
* // lock
* commitToMine(_blockChain); // will call uncommitToMine if a repeat.
* // unlock
* MineInfo info;
* for (info.completed = false; !info.completed; info = mine()) {}
* }
* // lock
* completeMine();
* // unlock
* @endcode
*/
void completeMine();
/// Get the complete current block, including valid nonce.
/// Only valid after mine() returns true.
bytes const& blockData() const { return m_currentBytes; }
@ -327,6 +312,19 @@ public:
void resetCurrent();
private:
/** Commit to DB and build the final block if the previous call to mine()'s result is completion.
* Typically looks like:
* @code
* while (notYetMined)
* {
* // lock
* commitToMine(_blockChain); // will call uncommitToMine if a repeat.
* completeMine();
* // unlock
* @endcode
*/
void completeMine();
/// Undo the changes to the state for committing to mine.
void uncommitToMine();

2
mix/MixClient.cpp

@ -250,7 +250,7 @@ void MixClient::mine()
{
WriteGuard l(x_state);
m_state.commitToMine(bc());
m_state.completeMine();
m_state.completeMine<Ethash>(Ethash::Solution());
bc().import(m_state.blockData(), m_stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce);
/*
GenericFarm<ProofOfWork> f;

Loading…
Cancel
Save