Browse Source

Paranoia logging.

cl-refactor
Gav Wood 11 years ago
parent
commit
e3febfbd3b
  1. 2
      libethcore/Log.cpp
  2. 13
      libethcore/TrieDB.cpp
  3. 17
      libethcore/TrieDB.h

2
libethcore/Log.cpp

@ -27,7 +27,7 @@ using namespace std;
using namespace eth;
// Logging
int eth::g_logVerbosity = 7;
int eth::g_logVerbosity = 5;
map<type_info const*, bool> eth::g_logOverride;
ThreadLocalLogName eth::t_logThreadName("main");

13
libethcore/TrieDB.cpp

@ -54,7 +54,9 @@ void BasicMap::insert(h256 _h, bytesConstRef _v)
{
m_over[_h] = _v.toString();
m_refCount[_h]++;
#if ETH_PARANOIA
tdebug << "INST" << _h.abridged() << "=>" << m_refCount[_h];
#endif
}
bool BasicMap::kill(h256 _h)
@ -63,6 +65,7 @@ bool BasicMap::kill(h256 _h)
{
if (m_refCount[_h] > 0)
--m_refCount[_h];
#if ETH_PARANOIA
else
{
// If we get to this point, then there was probably a node in the level DB which we need to remove and which we have previously
@ -78,6 +81,10 @@ bool BasicMap::kill(h256 _h)
tdebug << "NOKILL" << _h.abridged();
return false;
}
#else
return true;
}
#endif
}
void BasicMap::purge()
@ -142,16 +149,18 @@ bool Overlay::exists(h256 _h) const
void Overlay::kill(h256 _h)
{
#if ETH_PARANOIA
if (!BasicMap::kill(_h))
{
#if ETH_PARANOIA
std::string ret;
if (m_db)
m_db->Get(m_readOptions, ldb::Slice((char const*)_h.data(), 32), &ret);
if (ret.empty())
cnote << "Decreasing DB node ref count below zero with no DB node. Probably have a corrupt Trie." << _h.abridged();
#endif
}
#else
BasicMap::kill(_h)
#endif
}
}

17
libethcore/TrieDB.h

@ -225,13 +225,17 @@ public:
}
if (!(rlp.isList() && (rlp.itemCount() == 2 || rlp.itemCount() == 17)))
{
#if ETH_PARANOIA
cwarn << "BIG FAT ERROR. STATE TRIE CORRUPTED!!!!!";
cdebug << b.rlp.size() << toHex(b.rlp);
cdebug << rlp;
auto c = rlp.itemCount();
cdebug << c;
throw InvalidTrie();
assert(rlp.isList() && (rlp.itemCount() == 2 || rlp.itemCount() == 17));
#else
m_that = nullptr;
return;
#endif
}
if (rlp.itemCount() == 2)
{
@ -451,7 +455,9 @@ template <class DB> void GenericTrieDB<DB>::init()
template <class DB> void GenericTrieDB<DB>::insert(bytesConstRef _key, bytesConstRef _value)
{
// tdebug << "Insert" << toHex(_key.cropped(0, 4)) << "=>" << toHex(_value);
#if ETH_PARANOIA
tdebug << "Insert" << toHex(_key.cropped(0, 4)) << "=>" << toHex(_value);
#endif
std::string rv = node(m_root);
assert(rv.size());
@ -503,7 +509,9 @@ template <class DB> std::string GenericTrieDB<DB>::atAux(RLP const& _here, Nibbl
template <class DB> bytes GenericTrieDB<DB>::mergeAt(RLP const& _orig, NibbleSlice _k, bytesConstRef _v, bool _inline)
{
#if ETH_PARANOIA
tdebug << "mergeAt " << _orig << _k << sha3(_orig.data()).abridged();
#endif
// The caller will make sure that the bytes are inserted properly.
// - This might mean inserting an entry into m_over
@ -570,7 +578,10 @@ template <class DB> bytes GenericTrieDB<DB>::mergeAt(RLP const& _orig, NibbleSli
template <class DB> void GenericTrieDB<DB>::mergeAtAux(RLPStream& _out, RLP const& _orig, NibbleSlice _k, bytesConstRef _v)
{
#if ETH_PARANOIA
tdebug << "mergeAtAux " << _orig << _k << sha3(_orig.data()).abridged() << ((_orig.isData() && _orig.size() <= 32) ? _orig.toHash<h256>().abridged() : std::string());
#endif
RLP r = _orig;
std::string s;
// _orig is always a segment of a node's RLP - removing it alone is pointless. However, if may be a hash, in which case we deref and we know it is removable.
@ -588,7 +599,9 @@ template <class DB> void GenericTrieDB<DB>::mergeAtAux(RLPStream& _out, RLP cons
template <class DB> void GenericTrieDB<DB>::remove(bytesConstRef _key)
{
#if ETH_PARANOIA
tdebug << "Remove" << toHex(_key.cropped(0, 4).toBytes());
#endif
std::string rv = node(m_root);
bytes b = deleteAt(RLP(rv), NibbleSlice(_key));

Loading…
Cancel
Save