Browse Source

bool param to enum

cl-refactor
arkpar 10 years ago
parent
commit
07b45657f7
  1. 11
      libethcore/Common.h
  2. 4
      libethereum/BlockChain.cpp
  3. 2
      libethereum/BlockChain.h
  4. 14
      libethereum/State.cpp
  5. 6
      libethereum/State.h
  6. 2
      mix/MixClient.cpp

11
libethcore/Common.h

@ -96,5 +96,16 @@ enum class ImportResult
BadChain
};
struct ImportRequirements
{
using value = unsigned;
enum
{
ValidNonce = 1,
DontHave = 2,
Default = ValidNonce
};
};
}
}

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, bool _checkNonce)
pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db, Aversion _force, ImportRequirements::value _ir)
{
//@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.
// Get total difficulty increase and update state, checking it.
State s(_db); //, bi.coinbaseAddress
auto tdIncrease = s.enactOn(&_block, bi, *this, _checkNonce);
auto tdIncrease = s.enactOn(&_block, bi, *this, _ir);
BlockLogBlooms blb;
BlockReceipts br;

2
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<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks, bool _checkNonce = true);
std::pair<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks, ImportRequirements::value _ir = ImportRequirements::Default);
/// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 const& _hash) const;

14
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 _checkNonce)
bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, ImportRequirements::value _ir)
{
bool ret = false;
// BLOCK
@ -337,7 +337,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, bool
for (auto it = chain.rbegin(); it != chain.rend(); ++it)
{
auto b = _bc.block(*it);
enact(&b, _bc, _checkNonce);
enact(&b, _bc, _ir);
cleanup(true);
}
}
@ -355,7 +355,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, bool
return ret;
}
u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, bool _checkNonce)
u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, ImportRequirements::value _ir)
{
#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, BlockInfo(), _checkNonce);
sync(_bc, _bi.parentHash, BlockInfo(), _ir);
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, _checkNonce);
auto ret = enact(_block, _bc, _ir);
#if ETH_TIMED_ENACTMENTS
enactment = t.elapsed();
@ -538,11 +538,11 @@ TransactionReceipts State::sync(BlockChain const& _bc, TransactionQueue& _tq, Ga
return ret;
}
u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce)
u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirements::value _ir)
{
// m_currentBlock is assumed to be prepopulated and reset.
BlockInfo bi(_block, _checkNonce ? CheckEverything : IgnoreNonce);
BlockInfo bi(_block, ((_ir & (ImportRequirements::ValidNonce | ImportRequirements::DontHave)) == ImportRequirements::ValidNonce) ? CheckEverything : IgnoreNonce);
#if !ETH_RELEASE
assert(m_previousBlock.hash() == bi.parentHash);

6
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 _checkNonce = true);
bool sync(BlockChain const& _bc, h256 _blockHash, BlockInfo const& _bi = BlockInfo(), ImportRequirements::value _ir = ImportRequirements::Default);
/// Execute all transactions within a given block.
/// @returns the additional total difficulty.
u256 enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, bool _checkNonce);
u256 enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const& _bc, ImportRequirements::value _ir = ImportRequirements::Default);
/// 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
@ -338,7 +338,7 @@ private:
/// Execute the given block, assuming it corresponds to m_currentBlock.
/// Throws on failure.
u256 enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce = true);
u256 enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirements::value _ir = ImportRequirements::Default);
/// Finalise the block, applying the earned rewards.
void applyRewards(std::vector<BlockInfo> const& _uncleBlockHeaders);

2
mix/MixClient.cpp

@ -251,7 +251,7 @@ void MixClient::mine()
WriteGuard l(x_state);
m_state.commitToMine(bc());
m_state.completeMine();
bc().import(m_state.blockData(), m_stateDB, Aversion::AvoidOldBlocks, false);
bc().import(m_state.blockData(), m_stateDB, Aversion::AvoidOldBlocks, ImportRequirements::ValidNonce | ImportRequirements::DontHave);
m_state.sync(bc());
m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };

Loading…
Cancel
Save