Browse Source

replaced Aversion with ImportRequirements

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

6
libethcore/Common.h

@ -101,9 +101,9 @@ struct ImportRequirements
using value = unsigned; using value = unsigned;
enum enum
{ {
ValidNonce = 1, ValidNonce = 1, ///< Validate Nonce
DontHave = 2, DontHave = 2, ///< Avoid old blocks
Default = ValidNonce Default = ValidNonce | DontHave
}; };
}; };

10
libethereum/BlockChain.cpp

@ -240,7 +240,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
return; return;
} }
lastHash = bi.hash(); lastHash = bi.hash();
import(b, s.db(), Aversion::ImportOldBlocks); import(b, s.db(), ImportRequirements::Default);
} }
catch (...) catch (...)
{ {
@ -334,11 +334,11 @@ tuple<h256s, h256s, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st
return make_tuple(fresh, dead, _bq.doneDrain(badBlocks)); return make_tuple(fresh, dead, _bq.doneDrain(badBlocks));
} }
pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, Aversion _force) noexcept pair<h256s, h256> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir) noexcept
{ {
try try
{ {
return import(_block, _stateDB, _force); return import(_block, _stateDB, _ir);
} }
catch (...) catch (...)
{ {
@ -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, ImportRequirements::value _ir) pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db, ImportRequirements::value _ir)
{ {
//@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.
@ -386,7 +386,7 @@ pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db,
#endif #endif
// Check block doesn't already exist first! // Check block doesn't already exist first!
if (isKnown(bi.hash()) && _force == Aversion::AvoidOldBlocks) if (isKnown(bi.hash()) && (_ir & ImportRequirements::DontHave))
{ {
clog(BlockChainNote) << bi.hash() << ": Not new."; clog(BlockChainNote) << bi.hash() << ": Not new.";
BOOST_THROW_EXCEPTION(AlreadyHaveBlock()); BOOST_THROW_EXCEPTION(AlreadyHaveBlock());

10
libethereum/BlockChain.h

@ -80,12 +80,6 @@ enum {
using ProgressCallback = std::function<void(unsigned, unsigned)>; using ProgressCallback = std::function<void(unsigned, unsigned)>;
enum class Aversion
{
AvoidOldBlocks,
ImportOldBlocks
};
/** /**
* @brief Implements the blockchain database. All data this gives is disk-backed. * @brief Implements the blockchain database. All data this gives is disk-backed.
* @threadsafe * @threadsafe
@ -108,11 +102,11 @@ public:
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// Attempt to import the given block directly into the CanonBlockChain and sync with the state 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> attemptImport(bytes const& _block, OverlayDB const& _stateDB, Aversion _force = Aversion::AvoidOldBlocks) noexcept; std::pair<h256s, h256> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default) noexcept;
/// 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, ImportRequirements::value _ir = ImportRequirements::Default); std::pair<h256s, h256> import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Default);
/// 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;

2
libethereum/State.cpp

@ -542,7 +542,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement
{ {
// m_currentBlock is assumed to be prepopulated and reset. // m_currentBlock is assumed to be prepopulated and reset.
BlockInfo bi(_block, ((_ir & (ImportRequirements::ValidNonce | ImportRequirements::DontHave)) == ImportRequirements::ValidNonce) ? CheckEverything : IgnoreNonce); BlockInfo bi(_block, (_ir & ImportRequirements::ValidNonce) ? CheckEverything : IgnoreNonce);
#if !ETH_RELEASE #if !ETH_RELEASE
assert(m_previousBlock.hash() == bi.parentHash); assert(m_previousBlock.hash() == bi.parentHash);

2
mix/MixClient.cpp

@ -251,7 +251,7 @@ void MixClient::mine()
WriteGuard l(x_state); WriteGuard l(x_state);
m_state.commitToMine(bc()); m_state.commitToMine(bc());
m_state.completeMine(); m_state.completeMine();
bc().import(m_state.blockData(), m_stateDB, Aversion::AvoidOldBlocks, ImportRequirements::ValidNonce | ImportRequirements::DontHave); bc().import(m_state.blockData(), m_stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce);
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