Browse Source

Fixes for reimporting.

cl-refactor
Gav Wood 10 years ago
parent
commit
4e4fc4d11c
  1. 14
      libethereum/BlockChain.cpp
  2. 4
      libethereum/BlockChain.h
  3. 8
      libethereum/State.cpp

14
libethereum/BlockChain.cpp

@ -218,7 +218,11 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
m_lastLastHashes.clear(); m_lastLastHashes.clear();
m_lastBlockHash = genesisHash(); m_lastBlockHash = genesisHash();
h256 lastHash = genesisHash(); m_details[m_lastBlockHash].totalDifficulty = c_genesisDifficulty;
m_extrasDB->Put(m_writeOptions, toSlice(m_lastBlockHash, ExtraDetails), (ldb::Slice)dev::ref(m_details[m_lastBlockHash].rlp()));
h256 lastHash = m_lastBlockHash;
boost::timer t; boost::timer t;
for (unsigned d = 1; d < originalNumber; ++d) for (unsigned d = 1; d < originalNumber; ++d)
{ {
@ -240,7 +244,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
return; return;
} }
lastHash = bi.hash(); lastHash = bi.hash();
import(b, s.db(), ImportRequirements::Default); import(b, s.db(), 0);
} }
catch (...) catch (...)
{ {
@ -408,12 +412,12 @@ ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, Import
// Check it's not crazy // Check it's not crazy
if (bi.timestamp > (u256)time(0)) if (bi.timestamp > (u256)time(0))
{ {
clog(BlockChainNote) << bi.hash() << ": Future time " << bi.timestamp << " (now at " << time(0) << ")"; clog(BlockChainChat) << bi.hash() << ": Future time " << bi.timestamp << " (now at " << time(0) << ")";
// Block has a timestamp in the future. This is no good. // Block has a timestamp in the future. This is no good.
BOOST_THROW_EXCEPTION(FutureTime()); BOOST_THROW_EXCEPTION(FutureTime());
} }
clog(BlockChainNote) << "Attempting import of " << bi.hash().abridged() << "..."; clog(BlockChainChat) << "Attempting import of " << bi.hash().abridged() << "...";
#if ETH_TIMED_IMPORTS #if ETH_TIMED_IMPORTS
preliminaryChecks = t.elapsed(); preliminaryChecks = t.elapsed();
@ -609,7 +613,7 @@ ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, Import
} }
else else
{ {
clog(BlockChainNote) << " Imported but not best (oTD:" << details(last).totalDifficulty << " > TD:" << td << ")"; clog(BlockChainChat) << " Imported but not best (oTD:" << details(last).totalDifficulty << " > TD:" << td << ")";
} }
#if ETH_TIMED_IMPORTS #if ETH_TIMED_IMPORTS

4
libethereum/BlockChain.h

@ -56,8 +56,8 @@ struct AlreadyHaveBlock: virtual Exception {};
struct UnknownParent: virtual Exception {}; struct UnknownParent: virtual Exception {};
struct FutureTime: virtual Exception {}; struct FutureTime: virtual Exception {};
struct BlockChainChat: public LogChannel { static const char* name() { return "-B-"; } static const int verbosity = 7; }; struct BlockChainChat: public LogChannel { static const char* name() { return "-B-"; } static const int verbosity = 5; };
struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 4; }; struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 3; };
struct BlockChainWarn: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 1; }; struct BlockChainWarn: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 1; };
struct BlockChainDebug: public LogChannel { static const char* name() { return "#B#"; } static const int verbosity = 0; }; struct BlockChainDebug: public LogChannel { static const char* name() { return "#B#"; } static const int verbosity = 0; };

8
libethereum/State.cpp

@ -663,7 +663,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement
uncle.verifyParent(uncleParent); uncle.verifyParent(uncleParent);
nonces.insert(uncle.nonce); nonces.insert(uncle.nonce);
tdIncrease += uncle.difficulty; // tdIncrease += uncle.difficulty;
rewarded.push_back(uncle); rewarded.push_back(uncle);
} }
@ -704,15 +704,15 @@ void State::cleanup(bool _fullCommit)
paranoia("immediately before database commit", true); paranoia("immediately before database commit", true);
// Commit the new trie to disk. // Commit the new trie to disk.
cnote << "Committing to disk: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); clog(StateTrace) << "Committing to disk: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash())));
m_db.commit(); m_db.commit();
cnote << "Committed: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); clog(StateTrace) << "Committed: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash())));
paranoia("immediately after database commit", true); paranoia("immediately after database commit", true);
m_previousBlock = m_currentBlock; m_previousBlock = m_currentBlock;
m_currentBlock.populateFromParent(m_previousBlock); m_currentBlock.populateFromParent(m_previousBlock);
cdebug << "finalising enactment. current -> previous, hash is" << m_previousBlock.hash().abridged(); clog(StateTrace) << "finalising enactment. current -> previous, hash is" << m_previousBlock.hash().abridged();
} }
else else
m_db.rollback(); m_db.rollback();

Loading…
Cancel
Save