From 6216b33775ee961ad3beabe54426961d95f1bbfa Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 10 Apr 2015 16:55:59 +0200 Subject: [PATCH] Allow mining without pow check --- libethereum/BlockChain.cpp | 4 ++-- libethereum/BlockChain.h | 2 +- libethereum/State.cpp | 10 +++++----- libethereum/State.h | 4 ++-- mix/MixClient.cpp | 3 +-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index cb2d26eff..4df91e3d1 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -347,7 +347,7 @@ pair BlockChain::attemptImport(bytes const& _block, OverlayDB const } } -pair BlockChain::import(bytes const& _block, OverlayDB const& _db, Aversion _force) +pair BlockChain::import(bytes const& _block, OverlayDB const& _db, Aversion _force, bool _checkNonce) { //@tidy This is a behemoth of a method - could do to be split into a few smaller ones. @@ -432,7 +432,7 @@ pair BlockChain::import(bytes const& _block, OverlayDB const& _db, // Check transactions are valid and that they result in a state equivalent to our state_root. // Get total difficulty increase and update state, checking it. State s(_db); //, bi.coinbaseAddress - auto tdIncrease = s.enactOn(&_block, bi, *this); + auto tdIncrease = s.enactOn(&_block, bi, *this, _checkNonce); BlockLogBlooms blb; BlockReceipts br; diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 765e00b03..635399494 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -112,7 +112,7 @@ public: /// Import block into disk-backed DB /// @returns the block hashes of any blocks that came into/went out of the canonical block chain. - std::pair import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks); + std::pair import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks, bool _checkNonce = true); /// Returns true if the given block is known (though not necessarily a part of the canon chain). bool isKnown(h256 const& _hash) const; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 5631ffe28..1a645ab67 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -274,7 +274,7 @@ bool State::sync(BlockChain const& _bc) return sync(_bc, _bc.currentHash()); } -bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi) +bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, bool _checkNonce) { bool ret = false; // BLOCK @@ -337,7 +337,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi) for (auto it = chain.rbegin(); it != chain.rend(); ++it) { auto b = _bc.block(*it); - enact(&b, _bc); + enact(&b, _bc, _checkNonce); cleanup(true); } } @@ -355,7 +355,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi) return ret; } -u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc) +u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, bool _checkNonce) { #if ETH_TIMED_ENACTMENTS boost::timer t; @@ -383,7 +383,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const t.restart(); #endif - sync(_bc, _bi.parentHash); + sync(_bc, _bi.parentHash, BlockInfo(), _checkNonce); resetCurrent(); #if ETH_TIMED_ENACTMENTS @@ -392,7 +392,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const #endif m_previousBlock = biParent; - auto ret = enact(_block, _bc); + auto ret = enact(_block, _bc, _checkNonce); #if ETH_TIMED_ENACTMENTS enactment = t.elapsed(); diff --git a/libethereum/State.h b/libethereum/State.h index 336c58b1a..e1699c256 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -306,11 +306,11 @@ public: bool sync(BlockChain const& _bc); /// Sync with the block chain, but rather than synching to the latest block, instead sync to the given block. - bool sync(BlockChain const& _bc, h256 _blockHash, BlockInfo const& _bi = BlockInfo()); + bool sync(BlockChain const& _bc, h256 _blockHash, BlockInfo const& _bi = BlockInfo(), bool _checkNonce = true); /// Execute all transactions within a given block. /// @returns the additional total difficulty. - u256 enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc); + u256 enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, bool _checkNonce); /// Returns back to a pristine state after having done a playback. /// @arg _fullCommit if true flush everything out to disk. If false, this effectively only validates diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index ff35a6d78..a68bfdf83 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -250,9 +250,8 @@ void MixClient::mine() { WriteGuard l(x_state); m_state.commitToMine(bc()); - while (!m_state.mine(100, true).completed) {} m_state.completeMine(); - bc().import(m_state.blockData(), m_stateDB); + bc().import(m_state.blockData(), m_stateDB, Aversion::AvoidOldBlocks, false); m_state.sync(bc()); m_startState = m_state; h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };