Browse Source

Avoid mining invalid blocks. Actually allow external mining.

cl-refactor
Gav Wood 10 years ago
parent
commit
2513561a33
  1. 2
      libethcore/BlockInfo.cpp
  2. 9
      libethcore/Ethash.cpp
  3. 2
      libethcore/Ethash.h
  4. 1
      libethereum/Client.cpp
  5. 6
      libethereum/State.cpp

2
libethcore/BlockInfo.cpp

@ -176,7 +176,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const
}
clog(BlockInfoDiagnosticsChannel) << "Expected uncle hash:" << toString(sha3(root[2].data()));
if (m_sha3Uncles != sha3(root[2].data()))
BOOST_THROW_EXCEPTION(InvalidUnclesHash());
BOOST_THROW_EXCEPTION(InvalidUnclesHash() << Hash256RequirementError(sha3(root[2].data()), m_sha3Uncles));
}
void BlockInfo::populateFromParent(BlockInfo const& _parent)

9
libethcore/Ethash.cpp

@ -177,15 +177,22 @@ StringHashMap Ethash::BlockHeaderRaw::jsInfo() const
return { { "nonce", toJS(m_nonce) }, { "seedHash", toJS(seedHash()) }, { "mixHash", toJS(m_mixHash) } };
}
void Ethash::manuallySetWork(SealEngineFace* _engine, BlockHeader const& _work)
{
// set m_sealing to the current problem.
if (EthashSealEngine* e = dynamic_cast<EthashSealEngine*>(_engine))
e->m_sealing = _work;
}
void Ethash::manuallySubmitWork(SealEngineFace* _engine, h256 const& _mixHash, Nonce _nonce)
{
if (EthashSealEngine* e = dynamic_cast<EthashSealEngine*>(_engine))
{
// Go via the farm since the handler function object is stored as a local within the Farm's lambda.
// Has the side effect of stopping local workers, which is good, as long as it only does it for
// valid submissions.
static_cast<GenericFarmFace<EthashProofOfWork>&>(e->m_farm).submitProof(EthashProofOfWork::Solution{_nonce, _mixHash}, nullptr);
}
}
bool Ethash::isWorking(SealEngineFace* _engine)

2
libethcore/Ethash.h

@ -99,6 +99,8 @@ public:
};
using BlockHeader = BlockHeaderPolished<BlockHeaderRaw>;
static void manuallySetWork(SealEngineFace* _engine, BlockHeader const& _work);
// TODO: Move elsewhere (EthashAux?)
static void ensurePrecomputed(unsigned _number);
};

1
libethereum/Client.cpp

@ -924,6 +924,7 @@ std::tuple<h256, h256, h256> EthashClient::getEthashWork()
// otherwise, set this to true so that it gets prepped next time.
m_remoteWorking = true;
Ethash::BlockHeader bh = Ethash::BlockHeader(m_miningInfo);
Ethash::manuallySetWork(m_sealEngine.get(), bh);
return std::tuple<h256, h256, h256>(bh.hashWithout(), bh.seedHash(), bh.boundary());
}

6
libethereum/State.cpp

@ -906,8 +906,12 @@ bool State::sealBlock(bytesConstRef _header)
if (!m_committedToMine)
return false;
// Check that this header is indeed for this block.
if (BlockInfo(_header, CheckNothing, h256{}, HeaderData).hashWithout() != m_currentBlock.hashWithout())
return false;
// Looks good!
clog(StateDetail) << "Sealing block!";
// Got it!
// Compile block:
RLPStream ret;

Loading…
Cancel
Save