From dfc65d2fcea8c139dd1c4cd7cfc23846c112f85b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 1 Mar 2015 23:14:54 +0100 Subject: [PATCH] Fixes for FatTrie. --- libdevcrypto/OverlayDB.cpp | 11 ++++++++++- libdevcrypto/TrieDB.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libdevcrypto/OverlayDB.cpp b/libdevcrypto/OverlayDB.cpp index 4f237becb..d34dd1906 100644 --- a/libdevcrypto/OverlayDB.cpp +++ b/libdevcrypto/OverlayDB.cpp @@ -53,7 +53,14 @@ void OverlayDB::commit() m_db->Put(m_writeOptions, ldb::Slice((char const*)i.first.data(), i.first.size), ldb::Slice(i.second.data(), i.second.size())); } if (m_auxKey && m_aux.count(m_auxKey)) + { m_db->Put(m_writeOptions, m_auxKey.ref(), bytesConstRef(&m_aux[m_auxKey])); + cdebug << "Committing aux: " << m_auxKey; + m_aux.erase(m_auxKey); + cdebug << "Discarding " << keysOf(m_aux); + } + m_auxKey = h256(); + m_aux.clear(); m_over.clear(); m_refCount.clear(); } @@ -65,7 +72,9 @@ bytes OverlayDB::lookupAux(h256 _h) const if (!ret.empty()) return ret; std::string v; - m_db->Get(m_readOptions, _h.ref(), &v); + m_db->Get(m_readOptions, aux(_h).ref(), &v); + if (v.empty()) + cwarn << "Aux not found: " << _h; return asBytes(v); } diff --git a/libdevcrypto/TrieDB.h b/libdevcrypto/TrieDB.h index f32170cd4..e00e03f44 100644 --- a/libdevcrypto/TrieDB.h +++ b/libdevcrypto/TrieDB.h @@ -408,7 +408,7 @@ public: Super::setRoot(h256(Super::db()->lookupAux(m_secure.root()))); } - h256 root() const { const_cast(this)->syncRoot(); return m_secure.root(); } + h256 root() const { return m_secure.root(); } void insert(bytesConstRef _key, bytesConstRef _value) { Super::insert(_key, _value); m_secure.insert(_key, _value); syncRoot(); } void remove(bytesConstRef _key) { Super::remove(_key); m_secure.remove(_key); syncRoot(); }