Browse Source

Fix mining deadlocks.

Cleanups and additional diagnostics for the BadRoot problems.
cl-refactor
Gav Wood 10 years ago
parent
commit
cb009c7640
  1. 2
      libdevcore/Exceptions.h
  2. 2
      libdevcore/TrieDB.h
  3. 2
      libethcore/EthashSealEngine.cpp
  4. 2
      libethcore/Miner.h
  5. 2
      libethcore/Sealer.h
  6. 7
      libethereum/BlockChain.cpp
  7. 4
      libethereum/Client.cpp
  8. 2
      libethereum/Client.h

2
libdevcore/Exceptions.h

@ -56,7 +56,7 @@ DEV_SIMPLE_EXCEPTION(BadHexCharacter);
DEV_SIMPLE_EXCEPTION(NoNetworking);
DEV_SIMPLE_EXCEPTION(NoUPnPDevice);
DEV_SIMPLE_EXCEPTION(RootNotFound);
DEV_SIMPLE_EXCEPTION(BadRoot);
struct BadRoot: virtual Exception { public: BadRoot(h256 const& _root): Exception("BadRoot " + _root.hex()), root(_root) {} h256 root; };
DEV_SIMPLE_EXCEPTION(FileError);
DEV_SIMPLE_EXCEPTION(Overflow);
DEV_SIMPLE_EXCEPTION(FailedInvariant);

2
libdevcore/TrieDB.h

@ -96,7 +96,7 @@ public:
/// True if the trie is initialised but empty (i.e. that the DB contains the root node which is empty).
bool isEmpty() const { return m_root == c_shaNull && node(m_root).size(); }
h256 const& root() const { if (node(m_root).empty()) BOOST_THROW_EXCEPTION(BadRoot()); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly.
h256 const& root() const { if (node(m_root).empty()) BOOST_THROW_EXCEPTION(BadRoot(m_root)); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly.
std::string at(bytes const& _key) const { return at(&_key); }
std::string at(bytesConstRef _key) const;

2
libethcore/EthashSealEngine.cpp

@ -63,7 +63,7 @@ void EthashSealEngine::onSealGenerated(std::function<void(bytes const&)> const&
{
m_farm.onSolutionFound([=](EthashProofOfWork::Solution const& sol)
{
cdebug << m_farm.work().seedHash << m_farm.work().headerHash << sol.nonce << EthashAux::eval(m_farm.work().seedHash, m_farm.work().headerHash, sol.nonce).value;
// cdebug << m_farm.work().seedHash << m_farm.work().headerHash << sol.nonce << EthashAux::eval(m_farm.work().seedHash, m_farm.work().headerHash, sol.nonce).value;
m_sealing.m_mixHash = sol.mixHash;
m_sealing.m_nonce = sol.nonce;
RLPStream ret;

2
libethcore/Miner.h

@ -58,6 +58,8 @@ public:
using Solution = typename PoW::Solution;
using Miner = GenericMiner<PoW>;
virtual ~GenericFarmFace() {}
/**
* @brief Called from a Miner to note a WorkPackage has a solution.
* @param _p The solution.

2
libethcore/Sealer.h

@ -38,6 +38,8 @@ class BlockInfo;
class SealEngineFace
{
public:
virtual ~SealEngineFace() {}
virtual std::string name() const = 0;
virtual unsigned revision() const = 0;
virtual unsigned sealFields() const = 0;

7
libethereum/BlockChain.cpp

@ -586,9 +586,11 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
#endif
}
#if ETH_CATCH
catch (BadRoot&)
catch (BadRoot& ex)
{
cwarn << "BadRoot error. Retrying import later.";
cwarn << "*** BadRoot error! Trying to import" << _block.info.hash() << "needed root" << ex.root;
cwarn << _block.info;
// Attempt in import later.
BOOST_THROW_EXCEPTION(FutureTime());
}
catch (Exception& ex)
@ -1245,6 +1247,7 @@ State BlockChain::genesisState(OverlayDB const& _db)
dev::eth::commit(m_genesisState, ret.m_state); // bit horrible. maybe consider a better way of constructing it?
ret.m_state.db()->commit(); // have to use this db() since it's the one that has been altered with the above commit.
ret.m_previousBlock = BlockInfo(&m_genesisBlock);
ret.resetCurrent();
return ret;
}

4
libethereum/Client.cpp

@ -586,7 +586,7 @@ void Client::onNewBlocks(h256s const& _blocks, h256Hash& io_changed)
appendFromBlock(h, BlockPolarity::Live, io_changed);
}
void Client::restartMining()
void Client::resyncStateFromChain()
{
// RESTART MINING
@ -639,7 +639,7 @@ void Client::onChainChanged(ImportRoute const& _ir)
m_tq.dropGood(t);
}
onNewBlocks(_ir.liveBlocks, changeds);
restartMining();
resyncStateFromChain();
noteChanged(changeds);
}

2
libethereum/Client.h

@ -250,7 +250,7 @@ protected:
void onNewBlocks(h256s const& _blocks, h256Hash& io_changed);
/// Called after processing blocks by onChainChanged(_ir)
void restartMining();
void resyncStateFromChain();
/// Magically called when the chain has changed. An import route is provided.
/// Called by either submitWork() or in our main thread through syncBlockQueue().

Loading…
Cancel
Save