From 5185e6a6efb95336a16d65fa496d12eee8a91a85 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 1 Feb 2014 17:37:34 +0000 Subject: [PATCH] Changed genesis block to reflect root of empty trie as null. --- libethereum/BlockInfo.cpp | 2 +- libethereum/TrieDB.cpp | 3 +++ libethereum/TrieDB.h | 4 +++- test/main.cpp | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libethereum/BlockInfo.cpp b/libethereum/BlockInfo.cpp index 3f818596d..78059c42f 100644 --- a/libethereum/BlockInfo.cpp +++ b/libethereum/BlockInfo.cpp @@ -42,7 +42,7 @@ bytes BlockInfo::createGenesisBlock() { RLPStream block(3); auto sha3EmptyList = sha3(RLPEmptyList); - block.appendList(9) << h256() << sha3EmptyList << h160() << sha3(RLPNull) << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << (uint)0; + block.appendList(9) << h256() << sha3EmptyList << h160() << h256() << sha3EmptyList << c_genesisDifficulty << (uint)0 << string() << (uint)0; block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); return block.out(); diff --git a/libethereum/TrieDB.cpp b/libethereum/TrieDB.cpp index d41d22434..48838474d 100644 --- a/libethereum/TrieDB.cpp +++ b/libethereum/TrieDB.cpp @@ -26,4 +26,7 @@ using namespace eth; namespace eth { + +const h256 c_shaNull = sha3(""); + } diff --git a/libethereum/TrieDB.h b/libethereum/TrieDB.h index c9d983cfb..2448cf8a9 100644 --- a/libethereum/TrieDB.h +++ b/libethereum/TrieDB.h @@ -94,6 +94,8 @@ private: #pragma warning(disable:4100) // disable warnings so it compiles #endif +extern const h256 c_shaNull; + /** * @brief Merkle Patricia Tree "Trie": a modifed base-16 Radix tree. * This version uses an LDB backend @@ -111,7 +113,7 @@ public: void init(); void setRoot(h256 _root) { m_root = _root; } - h256 root() const { return m_root; } + 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. void debugPrint() {} diff --git a/test/main.cpp b/test/main.cpp index 90b784cf8..cf0ce9280 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -35,11 +35,11 @@ using namespace eth; int main(int argc, char** argv) { - /*RLPStream s; + RLPStream s; BlockInfo::genesis().fillStream(s, false); std::cout << RLP(s.out()) << std::endl; std::cout << asHex(s.out()) << std::endl; - std::cout << sha3(s.out()) << std::endl;*/ + std::cout << sha3(s.out()) << std::endl; // hexPrefixTest(); // rlpTest();