diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index e48b58283..4655240e3 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1718,7 +1718,7 @@ void Main::on_blocks_currentItemChanged() s << "
Seed hash: " << info.seedHash() << "" << "
"; s << "
Mix hash: " << info.mixHash << "" << "
"; s << "
Nonce: " << info.nonce << "" << "
"; - s << "
Hash w/o nonce: " << info.headerHash(WithoutNonce) << "" << "
"; + s << "
Hash w/o nonce: " << info.headerHash(WithoutProof) << "" << "
"; s << "
Difficulty: " << info.difficulty << "" << "
"; if (info.number) { @@ -1749,7 +1749,7 @@ void Main::on_blocks_currentItemChanged() s << line << "Seed hash: " << uncle.seedHash() << "" << ""; s << line << "Mix hash: " << uncle.mixHash << "" << ""; s << line << "Nonce: " << uncle.nonce << "" << ""; - s << line << "Hash w/o nonce: " << uncle.headerHash(WithoutNonce) << "" << ""; + s << line << "Hash w/o nonce: " << uncle.headerHash(WithoutProof) << "" << ""; s << line << "Difficulty: " << uncle.difficulty << "" << ""; auto e = EthashAux::eval(uncle); s << line << "Proof-of-Work: " << e.value << " <= " << (h256)u256((bigint(1) << 256) / uncle.difficulty) << " (mixhash: " << e.mixHash.abridged() << ")" << ""; diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index ff28132b1..5c6112743 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -254,17 +254,17 @@ public: bi.difficulty = u256(m); auto boundary = bi.boundary(); m = boost::to_lower_copy(string(argv[++i])); - bi.nonce = h64(m); - auto r = EthashAux::eval(seedHash, powHash, bi.nonce); + bi.proof.nonce = h64(m); + auto r = EthashAux::eval(seedHash, powHash, bi.proof.nonce); bool valid = r.value < boundary; cout << (valid ? "VALID :-)" : "INVALID :-(") << endl; cout << r.value << (valid ? " < " : " >= ") << boundary << endl; cout << " where " << boundary << " = 2^256 / " << bi.difficulty << endl; - cout << " and " << r.value << " = ethash(" << powHash << ", " << bi.nonce << ")" << endl; + cout << " and " << r.value << " = ethash(" << powHash << ", " << bi.proof.nonce << ")" << endl; cout << " with seed as " << seedHash << endl; if (valid) cout << "(mixHash = " << r.mixHash << ")" << endl; - cout << "SHA3( light(seed) ) = " << sha3(EthashAux::light(bi.seedHash())->data()) << endl; + cout << "SHA3( light(seed) ) = " << sha3(EthashAux::light(bi.proofCache())->data()) << endl; exit(0); } catch (...) @@ -382,7 +382,7 @@ private: { BlockInfo bi; bi.number = _n; - cout << "Initializing DAG for epoch beginning #" << (bi.number / 30000 * 30000) << " (seedhash " << bi.seedHash().abridged() << "). This will take a while." << endl; + cout << "Initializing DAG for epoch beginning #" << (bi.number / 30000 * 30000) << " (seedhash " << bi.proofCache().abridged() << "). This will take a while." << endl; Ethash::prep(bi); exit(0); } diff --git a/exp/main.cpp b/exp/main.cpp index 88608f8cf..9884bd0e1 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -197,7 +197,7 @@ int main() bool completed = false; f.onSolutionFound([&](ProofOfWork::Solution sol) { - ProofOfWork::assignResult(sol, bi); + bi.proof = sol; return completed = true; }); f.setWork(bi); diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index fec5b4678..c7acd9091 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -26,7 +26,6 @@ #include #include #include "EthashAux.h" -#include "ProofOfWork.h" #include "Exceptions.h" #include "BlockInfo.h" using namespace std; @@ -57,22 +56,21 @@ void BlockInfo::clear() gasUsed = 0; timestamp = 0; extraData.clear(); - mixHash = h256(); - nonce = Nonce(); - m_hash = m_seedHash = h256(); + proof = ProofOfWork::Solution(); + m_proofCache = ProofOfWork::HeaderCache(); + m_hash = h256(); } -h256 const& BlockInfo::seedHash() const +ProofOfWork::HeaderCache const& BlockInfo::proofCache() const { - if (!m_seedHash) - m_seedHash = EthashAux::seedHash((unsigned)number); - return m_seedHash; + ProofOfWork::ensureHeaderCacheValid(m_proofCache, *this); + return m_proofCache; } h256 const& BlockInfo::hash() const { if (!m_hash) - m_hash = headerHash(WithNonce); + m_hash = headerHash(WithProof); return m_hash; } @@ -90,20 +88,20 @@ BlockInfo BlockInfo::fromHeader(bytesConstRef _header, Strictness _s, h256 const return ret; } -h256 BlockInfo::headerHash(IncludeNonce _n) const +h256 BlockInfo::headerHash(IncludeProof _n) const { RLPStream s; streamRLP(s, _n); return sha3(s.out()); } -void BlockInfo::streamRLP(RLPStream& _s, IncludeNonce _n) const +void BlockInfo::streamRLP(RLPStream& _s, IncludeProof _n) const { - _s.appendList(_n == WithNonce ? 15 : 13) + _s.appendList(_n == WithProof ? 13 + ProofOfWork::Solution::Fields : 13) << parentHash << sha3Uncles << coinbaseAddress << stateRoot << transactionsRoot << receiptsRoot << logBloom << difficulty << number << gasLimit << gasUsed << timestamp << extraData; - if (_n == WithNonce) - _s << mixHash << nonce; + if (_n == WithProof) + proof.streamRLP(_s); } h256 BlockInfo::headerHash(bytesConstRef _block) @@ -116,12 +114,12 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const m_hash = _h; if (_h) assert(_h == dev::sha3(_header.data())); - m_seedHash = h256(); + m_proofCache = ProofOfWork::HeaderCache(); int field = 0; try { - if (_header.itemCount() != 15) + if (_header.itemCount() != 13 + ProofOfWork::Solution::Fields) BOOST_THROW_EXCEPTION(InvalidBlockHeaderItemCount()); parentHash = _header[field = 0].toHash(RLP::VeryStrict); sha3Uncles = _header[field = 1].toHash(RLP::VeryStrict); @@ -136,8 +134,7 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const gasUsed = _header[field = 10].toInt(); timestamp = _header[field = 11].toInt(); extraData = _header[field = 12].toBytes(); - mixHash = _header[field = 13].toHash(RLP::VeryStrict); - nonce = _header[field = 14].toHash(RLP::VeryStrict); + proof.populateFromRLP(_header, field = 13); } catch (Exception const& _e) { @@ -152,22 +149,18 @@ void BlockInfo::populateFromHeader(RLP const& _header, Strictness _s, h256 const if (_s == CheckEverything && parentHash && !ProofOfWork::verify(*this)) { InvalidBlockNonce ex; - ex << errinfo_hash256(headerHash(WithoutNonce)); - ex << errinfo_nonce(nonce); + ProofOfWork::composeException(ex, *this); + ex << errinfo_hash256(headerHash(WithoutProof)); ex << errinfo_difficulty(difficulty); - ex << errinfo_seedHash(seedHash()); ex << errinfo_target(boundary()); - ex << errinfo_mixHash(mixHash); - Ethash::Result er = EthashAux::eval(seedHash(), headerHash(WithoutNonce), nonce); - ex << errinfo_ethashResult(make_tuple(er.value, er.mixHash)); BOOST_THROW_EXCEPTION(ex); } else if (_s == QuickNonce && parentHash && !ProofOfWork::preVerify(*this)) { InvalidBlockNonce ex; - ex << errinfo_hash256(headerHash(WithoutNonce)); - ex << errinfo_nonce(nonce); + ex << errinfo_hash256(headerHash(WithoutProof)); ex << errinfo_difficulty(difficulty); + ProofOfWork::composeExceptionPre(ex, *this); BOOST_THROW_EXCEPTION(ex); } diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 79c12ebb4..b77c47c6b 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -24,16 +24,17 @@ #include #include #include "Common.h" +#include "ProofOfWork.h" namespace dev { namespace eth { -enum IncludeNonce +enum IncludeProof { - WithoutNonce = 0, - WithNonce = 1 + WithoutProof = 0, + WithProof = 1 }; enum Strictness @@ -82,8 +83,7 @@ public: u256 gasUsed; u256 timestamp = Invalid256; bytes extraData; - h256 mixHash; - Nonce nonce; + typename ProofOfWork::Solution proof; BlockInfo(); explicit BlockInfo(bytes const& _block, Strictness _s = IgnoreNonce, h256 const& _h = h256()): BlockInfo(&_block, _s, _h) {} @@ -112,14 +112,13 @@ public: gasUsed == _cmp.gasUsed && timestamp == _cmp.timestamp && extraData == _cmp.extraData && - mixHash == _cmp.mixHash && - nonce == _cmp.nonce; + proof == _cmp.proof; } bool operator!=(BlockInfo const& _cmp) const { return !operator==(_cmp); } void clear(); - void noteDirty() const { m_hash = m_seedHash = m_boundary = h256(); } + void noteDirty() const { m_hash = m_boundary = h256(); m_proofCache = ProofOfWork::HeaderCache(); } void populateFromHeader(RLP const& _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()); void populate(bytesConstRef _block, Strictness _s = IgnoreNonce, h256 const& _h = h256()); @@ -130,16 +129,17 @@ public: u256 calculateDifficulty(BlockInfo const& _parent) const; u256 selectGasLimit(BlockInfo const& _parent) const; - h256 const& seedHash() const; + ProofOfWork::HeaderCache const& proofCache() const; h256 const& hash() const; h256 const& boundary() const; /// sha3 of the header only. - h256 headerHash(IncludeNonce _n) const; - void streamRLP(RLPStream& _s, IncludeNonce _n) const; + h256 headerHash(IncludeProof _n) const; + void streamRLP(RLPStream& _s, IncludeProof _n) const; private: - mutable h256 m_seedHash; + + mutable ProofOfWork::HeaderCache m_proofCache; mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. mutable h256 m_boundary; ///< 2^256 / difficulty }; @@ -148,7 +148,7 @@ inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi) { _out << _bi.hash() << " " << _bi.parentHash << " " << _bi.sha3Uncles << " " << _bi.coinbaseAddress << " " << _bi.stateRoot << " " << _bi.transactionsRoot << " " << _bi.receiptsRoot << " " << _bi.logBloom << " " << _bi.difficulty << " " << _bi.number << " " << _bi.gasLimit << " " << - _bi.gasUsed << " " << _bi.timestamp << " " << _bi.mixHash << " " << _bi.nonce << " (" << _bi.seedHash() << ")"; + _bi.gasUsed << " " << _bi.timestamp; return _out; } diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index 618703e22..41cd1bba8 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -26,6 +26,7 @@ #include #include "Exceptions.h" #include "ProofOfWork.h" +#include "BlockInfo.h" using namespace std; using namespace dev; using namespace dev::eth; @@ -112,9 +113,9 @@ std::string formatBalance(bigint const& _b) static void badBlockInfo(BlockInfo const& _bi, string const& _err) { - string const c_line = EthReset EthOnMaroon + string(80, ' '); + string const c_line = EthReset EthOnMaroon + string(80, ' ') + EthReset; string const c_border = EthReset EthOnMaroon + string(2, ' ') + EthReset EthMaroonBold; - string const c_space = c_border + string(76, ' ') + c_border; + string const c_space = c_border + string(76, ' ') + c_border + EthReset; stringstream ss; ss << c_line << endl; ss << c_space << endl; diff --git a/libethcore/Common.h b/libethcore/Common.h index 296f0d01d..1e0cdc3b1 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -189,6 +189,7 @@ struct TransactionSkeleton Address to; u256 value; bytes data; + u256 nonce = UndefinedU256; u256 gas = UndefinedU256; u256 gasPrice = UndefinedU256; u256 nonce = UndefinedU256; diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 9be76926d..6a4a1445f 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -46,6 +46,7 @@ #endif #include "BlockInfo.h" #include "EthashAux.h" +#include "Exceptions.h" using namespace std; using namespace std::chrono; @@ -56,6 +57,26 @@ namespace eth const Ethash::WorkPackage Ethash::NullWorkPackage = Ethash::WorkPackage(); +void Ethash::ensureHeaderCacheValid(HeaderCache& io_out, BlockInfo const& _h) +{ + if (!io_out) + io_out = EthashAux::seedHash((unsigned)_h.number); +} + +void Ethash::composeException(Exception& _ex, BlockInfo& _bi) +{ + _ex << errinfo_nonce(_bi.proof.nonce); + _ex << errinfo_mixHash(_bi.proof.mixHash); + _ex << errinfo_seedHash(_bi.proofCache()); + Ethash::Result er = EthashAux::eval(_bi.proofCache(), _bi.headerHash(WithoutProof), _bi.proof.nonce); + _ex << errinfo_ethashResult(make_tuple(er.value, er.mixHash)); +} + +void Ethash::composeExceptionPre(Exception& _ex, BlockInfo& _bi) +{ + _ex << errinfo_nonce(_bi.proof.nonce); +} + std::string Ethash::name() { return "Ethash"; @@ -66,12 +87,23 @@ unsigned Ethash::revision() return ETHASH_REVISION; } +void Ethash::Solution::populateFromRLP(RLP const& _header, int& _field) +{ + mixHash = _header[_field].toHash(RLP::VeryStrict); + nonce = _header[++_field].toHash(RLP::VeryStrict); +} + +void Ethash::Solution::streamRLP(RLPStream& io_rlp) const +{ + io_rlp << mixHash << nonce; +} + Ethash::WorkPackage Ethash::package(BlockInfo const& _bi) { WorkPackage ret; ret.boundary = _bi.boundary(); - ret.headerHash = _bi.headerHash(WithoutNonce); - ret.seedHash = _bi.seedHash(); + ret.headerHash = _bi.headerHash(WithoutProof); + ret.seedHash = _bi.proofCache(); return ret; } @@ -84,7 +116,7 @@ void Ethash::ensurePrecomputed(unsigned _number) void Ethash::prep(BlockInfo const& _header, std::function const& _f) { - EthashAux::full(_header.seedHash(), true, _f); + EthashAux::full(_header.proofCache(), true, _f); } bool Ethash::preVerify(BlockInfo const& _header) @@ -95,9 +127,9 @@ bool Ethash::preVerify(BlockInfo const& _header) h256 boundary = u256((bigint(1) << 256) / _header.difficulty); bool ret = !!ethash_quick_check_difficulty( - (ethash_h256_t const*)_header.headerHash(WithoutNonce).data(), - (uint64_t)(u64)_header.nonce, - (ethash_h256_t const*)_header.mixHash.data(), + (ethash_h256_t const*)_header.headerHash(WithoutProof).data(), + (uint64_t)(u64)_header.proof.nonce, + (ethash_h256_t const*)_header.proof.mixHash.data(), (ethash_h256_t const*)boundary.data()); return ret; @@ -115,7 +147,7 @@ bool Ethash::verify(BlockInfo const& _header) #endif auto result = EthashAux::eval(_header); - bool slow = result.value <= _header.boundary() && result.mixHash == _header.mixHash; + bool slow = result.value <= _header.boundary() && result.mixHash == _header.proof.mixHash; // cdebug << (slow ? "VERIFY" : "VERYBAD"); // cdebug << result.value.hex() << _header.boundary().hex(); @@ -125,9 +157,9 @@ bool Ethash::verify(BlockInfo const& _header) if (!pre && slow) { cwarn << "WARNING: evaluated result gives true whereas ethash_quick_check_difficulty gives false."; - cwarn << "headerHash:" << _header.headerHash(WithoutNonce); - cwarn << "nonce:" << _header.nonce; - cwarn << "mixHash:" << _header.mixHash; + cwarn << "headerHash:" << _header.headerHash(WithoutProof); + cwarn << "nonce:" << _header.proof.nonce; + cwarn << "mixHash:" << _header.proof.mixHash; cwarn << "difficulty:" << _header.difficulty; cwarn << "boundary:" << _header.boundary(); cwarn << "result.value:" << result.value; diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 7ffd887d0..5640152f0 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -28,16 +28,20 @@ #include #include #include "Common.h" -#include "BlockInfo.h" #include "Miner.h" class ethash_cl_miner; namespace dev { + +class RLP; +class RLPStream; + namespace eth { +class BlockInfo; class EthashCLHook; class Ethash @@ -45,8 +49,17 @@ class Ethash public: using Miner = GenericMiner; + using HeaderCache = h256; + static void ensureHeaderCacheValid(HeaderCache& io_out, BlockInfo const& _h); + static void composeException(Exception& _ex, BlockInfo& _bi); + static void composeExceptionPre(Exception& _ex, BlockInfo& _bi); + struct Solution { + bool operator==(Solution const& _v) const { return nonce == _v.nonce && mixHash == _v.mixHash; } + void populateFromRLP(RLP const& io_rlp, int& io_field); + void streamRLP(RLPStream& io_rlp) const; + static const unsigned Fields = 2; Nonce nonce; h256 mixHash; }; @@ -78,7 +91,6 @@ public: static bool verify(BlockInfo const& _header); static bool preVerify(BlockInfo const& _header); static WorkPackage package(BlockInfo const& _header); - static void assignResult(Solution const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; } class CPUMiner: public Miner, Worker { diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index efb6066f7..db01f3c49 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -200,6 +200,11 @@ EthashAux::FullType EthashAux::full(h256 const& _seedHash, bool _createIfMissing return ret; } +Ethash::Result EthashAux::eval(BlockInfo const& _header) +{ + return eval(_header, _header.proof.nonce); +} + #define DEV_IF_THROWS(X) try { X; } catch (...) unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing) @@ -252,7 +257,7 @@ Ethash::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonc Ethash::Result EthashAux::eval(BlockInfo const& _header, Nonce const& _nonce) { - return eval(_header.seedHash(), _header.headerHash(WithoutNonce), _nonce); + return eval(_header.proofCache(), _header.headerHash(WithoutProof), _nonce); } Ethash::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) diff --git a/libethcore/EthashAux.h b/libethcore/EthashAux.h index d5bd60d44..be07f579c 100644 --- a/libethcore/EthashAux.h +++ b/libethcore/EthashAux.h @@ -78,7 +78,7 @@ public: /// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result or empty pointer if not existing and _createIfMissing is false. static FullType full(h256 const& _seedHash, bool _createIfMissing = false, std::function const& _f = std::function()); - static Ethash::Result eval(BlockInfo const& _header) { return eval(_header, _header.nonce); } + static Ethash::Result eval(BlockInfo const& _header); static Ethash::Result eval(BlockInfo const& _header, Nonce const& _nonce); static Ethash::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce); diff --git a/libethcore/ProofOfWork.h b/libethcore/ProofOfWork.h index 764207aef..7b4298047 100644 --- a/libethcore/ProofOfWork.h +++ b/libethcore/ProofOfWork.h @@ -38,7 +38,6 @@ namespace eth * typename Solution * typename CPUMiner * typename GPUMiner - * void assignResult(BlockInfo&, Result) * and a few others. TODO */ using ProofOfWork = Ethash; diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 768ed223f..aaafe7ce9 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -575,8 +575,8 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& #endif StructuredLogger::chainReceivedNewBlock( - _block.info.headerHash(WithoutNonce).abridged(), - _block.info.nonce.abridged(), + _block.info.headerHash(WithoutProof).abridged(), + _block.info.proof.nonce.abridged(), currentHash().abridged(), "", // TODO: remote id ?? _block.info.parentHash.abridged() @@ -666,8 +666,8 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& clog(BlockChainNote) << " Imported and best" << td << " (#" << _block.info.number << "). Has" << (details(_block.info.parentHash).children.size() - 1) << "siblings. Route:" << route; StructuredLogger::chainNewHead( - _block.info.headerHash(WithoutNonce).abridged(), - _block.info.nonce.abridged(), + _block.info.headerHash(WithoutProof).abridged(), + _block.info.proof.nonce.abridged(), currentHash().abridged(), _block.info.parentHash.abridged() ); diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index f95a3880e..690fb60ee 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -101,7 +101,7 @@ void BlockQueue::verifierBody() swap(work, m_unverified.front()); m_unverified.pop_front(); BlockInfo bi; - bi.mixHash = work.hash; + bi.proof.mixHash = work.hash; bi.parentHash = work.parentHash; m_verifying.emplace_back(move(bi)); } @@ -121,7 +121,7 @@ void BlockQueue::verifierBody() m_readySet.erase(work.hash); m_knownBad.insert(work.hash); for (auto it = m_verifying.begin(); it != m_verifying.end(); ++it) - if (it->verified.info.mixHash == work.hash) + if (it->verified.info.proof.mixHash == work.hash) { m_verifying.erase(it); goto OK1; @@ -136,7 +136,7 @@ void BlockQueue::verifierBody() { WriteGuard l2(m_lock); unique_lock l(m_verification); - if (!m_verifying.empty() && m_verifying.front().verified.info.mixHash == work.hash) + if (!m_verifying.empty() && m_verifying.front().verified.info.proof.mixHash == work.hash) { // we're next! m_verifying.pop_front(); @@ -154,7 +154,7 @@ void BlockQueue::verifierBody() else { for (auto& i: m_verifying) - if (i.verified.info.mixHash == work.hash) + if (i.verified.info.proof.mixHash == work.hash) { i = move(res); goto OK; @@ -323,9 +323,9 @@ void BlockQueue::updateBad_WITH_LOCK(h256 const& _bad) std::deque oldVerifying; swap(m_verifying, oldVerifying); for (auto& b: oldVerifying) - if (m_knownBad.count(b.verified.info.parentHash) || m_knownBad.count(b.verified.info.mixHash)) + if (m_knownBad.count(b.verified.info.parentHash) || m_knownBad.count(b.verified.info.proof.mixHash)) { - h256 const& h = b.blockData.size() != 0 ? b.verified.info.hash() : b.verified.info.mixHash; + h256 const& h = b.blockData.size() != 0 ? b.verified.info.hash() : b.verified.info.proof.mixHash; m_knownBad.insert(h); m_readySet.erase(h); collectUnknownBad_WITH_BOTH_LOCKS(h); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 10d637509..bf55a50ff 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -837,7 +837,7 @@ bool State::amIJustParanoid(BlockChain const& _bc) // Compile block: RLPStream block; block.appendList(3); - m_currentBlock.streamRLP(block, WithNonce); + m_currentBlock.streamRLP(block, WithProof); block.appendRaw(m_currentTxs); block.appendRaw(m_currentUncles); @@ -902,7 +902,7 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData) if (!excluded.count(u)) // ignore any uncles/mainline blocks that we know about. { BlockInfo ubi(_bc.block(u)); - ubi.streamRLP(unclesData, WithNonce); + ubi.streamRLP(unclesData, WithProof); ++unclesCount; uncleBlockHeaders.push_back(ubi); if (unclesCount == 2) @@ -970,7 +970,7 @@ void State::completeMine() // Compile block: RLPStream ret; ret.appendList(3); - m_currentBlock.streamRLP(ret, WithNonce); + m_currentBlock.streamRLP(ret, WithProof); ret.appendRaw(m_currentTxs); ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); @@ -978,7 +978,7 @@ void State::completeMine() cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash << ")"; StructuredLogger::minedNewBlock( m_currentBlock.hash().abridged(), - m_currentBlock.nonce.abridged(), + m_currentBlock.proof.nonce.abridged(), "", //TODO: chain head hash here ?? m_currentBlock.parentHash.abridged() ); diff --git a/libethereum/State.h b/libethereum/State.h index ef8a3251a..0555b6dcd 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -169,11 +169,11 @@ public: if (!m_committedToMine) return false; - PoW::assignResult(_result, m_currentBlock); + m_currentBlock.proof = _result; if (!PoW::verify(m_currentBlock)) return false; - cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce) << m_currentBlock.nonce << m_currentBlock.difficulty << PoW::verify(m_currentBlock); + cnote << "Completed" << m_currentBlock.headerHash(WithoutProof) << m_currentBlock.proof.nonce << m_currentBlock.difficulty << PoW::verify(m_currentBlock); completeMine(); diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 96312f625..f7c09ebc2 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -99,11 +99,12 @@ Json::Value toJson(dev::eth::BlockInfo const& _bi) res["gasLimit"] = toJS(_bi.gasLimit); res["timestamp"] = toJS(_bi.timestamp); res["extraData"] = toJS(_bi.extraData); - res["nonce"] = toJS(_bi.nonce); res["logsBloom"] = toJS(_bi.logBloom); - - res["seedHash"] = toJS(_bi.seedHash()); res["target"] = toJS(_bi.boundary()); + + // TODO: move into ProofOfWork. + res["nonce"] = toJS(_bi.proof.nonce); + res["seedHash"] = toJS(_bi.proofCache()); } return res; } diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 8373c7c51..ea4686601 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -49,7 +49,6 @@ namespace struct MixPow //dummy POW { typedef int Solution; - static void assignResult(int, BlockInfo const&) {} static bool verify(BlockInfo const&) { return true; } }; diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index f49ed1e09..b43c4db51 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -81,7 +81,7 @@ void mine(BlockInfo& _bi) bool completed = false; f.onSolutionFound([&](ProofOfWork::Solution sol) { - ProofOfWork::assignResult(sol, _bi); + _bi.proof = sol; return completed = true; }); f.setWork(_bi);