Browse Source

Allow mining without pow check

cl-refactor
arkpar 10 years ago
parent
commit
6216b33775
  1. 4
      libethereum/BlockChain.cpp
  2. 2
      libethereum/BlockChain.h
  3. 10
      libethereum/State.cpp
  4. 4
      libethereum/State.h
  5. 3
      mix/MixClient.cpp

4
libethereum/BlockChain.cpp

@ -347,7 +347,7 @@ pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const
} }
} }
pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db, Aversion _force) pair<h256s, h256> 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. //@tidy This is a behemoth of a method - could do to be split into a few smaller ones.
@ -432,7 +432,7 @@ pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db,
// Check transactions are valid and that they result in a state equivalent to our state_root. // 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. // Get total difficulty increase and update state, checking it.
State s(_db); //, bi.coinbaseAddress State s(_db); //, bi.coinbaseAddress
auto tdIncrease = s.enactOn(&_block, bi, *this); auto tdIncrease = s.enactOn(&_block, bi, *this, _checkNonce);
BlockLogBlooms blb; BlockLogBlooms blb;
BlockReceipts br; BlockReceipts br;

2
libethereum/BlockChain.h

@ -112,7 +112,7 @@ public:
/// Import block into disk-backed DB /// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
std::pair<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks); std::pair<h256s, h256> 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). /// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 const& _hash) const; bool isKnown(h256 const& _hash) const;

10
libethereum/State.cpp

@ -274,7 +274,7 @@ bool State::sync(BlockChain const& _bc)
return sync(_bc, _bc.currentHash()); 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; bool ret = false;
// BLOCK // 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) for (auto it = chain.rbegin(); it != chain.rend(); ++it)
{ {
auto b = _bc.block(*it); auto b = _bc.block(*it);
enact(&b, _bc); enact(&b, _bc, _checkNonce);
cleanup(true); cleanup(true);
} }
} }
@ -355,7 +355,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi)
return ret; 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 #if ETH_TIMED_ENACTMENTS
boost::timer t; boost::timer t;
@ -383,7 +383,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const
t.restart(); t.restart();
#endif #endif
sync(_bc, _bi.parentHash); sync(_bc, _bi.parentHash, BlockInfo(), _checkNonce);
resetCurrent(); resetCurrent();
#if ETH_TIMED_ENACTMENTS #if ETH_TIMED_ENACTMENTS
@ -392,7 +392,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const
#endif #endif
m_previousBlock = biParent; m_previousBlock = biParent;
auto ret = enact(_block, _bc); auto ret = enact(_block, _bc, _checkNonce);
#if ETH_TIMED_ENACTMENTS #if ETH_TIMED_ENACTMENTS
enactment = t.elapsed(); enactment = t.elapsed();

4
libethereum/State.h

@ -306,11 +306,11 @@ public:
bool sync(BlockChain const& _bc); bool sync(BlockChain const& _bc);
/// Sync with the block chain, but rather than synching to the latest block, instead sync to the given block. /// 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. /// Execute all transactions within a given block.
/// @returns the additional total difficulty. /// @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. /// 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 /// @arg _fullCommit if true flush everything out to disk. If false, this effectively only validates

3
mix/MixClient.cpp

@ -250,9 +250,8 @@ void MixClient::mine()
{ {
WriteGuard l(x_state); WriteGuard l(x_state);
m_state.commitToMine(bc()); m_state.commitToMine(bc());
while (!m_state.mine(100, true).completed) {}
m_state.completeMine(); 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_state.sync(bc());
m_startState = m_state; m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };

Loading…
Cancel
Save