diff --git a/libethereum/TrieDB.cpp b/libethereum/TrieDB.cpp index 48838474d..306c2cfc8 100644 --- a/libethereum/TrieDB.cpp +++ b/libethereum/TrieDB.cpp @@ -27,6 +27,6 @@ using namespace eth; namespace eth { -const h256 c_shaNull = sha3(""); +const h256 c_shaNull = sha3(rlp("")); } diff --git a/libethereum/TrieDB.h b/libethereum/TrieDB.h index 2448cf8a9..0a30fcfda 100644 --- a/libethereum/TrieDB.h +++ b/libethereum/TrieDB.h @@ -105,15 +105,15 @@ class GenericTrieDB { public: GenericTrieDB(DB* _db): m_db(_db) {} - GenericTrieDB(DB* _db, h256 _root): m_root(_root), m_db(_db) {} + GenericTrieDB(DB* _db, h256 _root) { open(_db, _root); } ~GenericTrieDB() {} - void open(DB* _db, h256 _root) { m_root = _root; m_db = _db; } + void open(DB* _db, h256 _root) { setRoot(_root); m_db = _db; assert(node(m_root).size()); } void init(); - void setRoot(h256 _root) { m_root = _root; } + void setRoot(h256 _root) { m_root = _root == h256() ? c_shaNull : _root; /*std::cout << "Setting root to " << _root << " (patched to " << m_root << ")" << std::endl;*/ assert(node(m_root).size()); } - h256 root() const { return m_root == c_shaNull ? h256() : m_root; } // patch the root in the case of the empty trie. TODO: handle this properly. + h256 root() const { assert(node(m_root).size()); h256 ret = (m_root == c_shaNull ? h256() : m_root); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return ret; } // patch the root in the case of the empty trie. TODO: handle this properly. void debugPrint() {} @@ -396,11 +396,14 @@ namespace eth template void GenericTrieDB::init() { m_root = insertNode(&RLPNull); +// std::cout << "Initialised root to " << m_root << std::endl; + assert(node(m_root).size()); } template void GenericTrieDB::insert(bytesConstRef _key, bytesConstRef _value) { std::string rv = node(m_root); + assert(rv.size()); bytes b = mergeAt(RLP(rv), NibbleSlice(_key), _value); // mergeAt won't attempt to delete the node is it's less than 32 bytes