From 93cf056199adcf94633f7fd653b65847569093d1 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 31 May 2021 16:08:09 +0200 Subject: [PATCH] Fix statedb unit tests (#14) * debug code * Fix more unit tests * remove traces * Go back to the full range --- core/state/database.go | 12 +++++++++--- trie/verkle.go | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/state/database.go b/core/state/database.go index e7a6bf774c1e..9513fabc6dc5 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -232,10 +232,16 @@ func (db *VerkleDB) OpenStorageTrie(accTrie Trie, addrHash, root common.Hash) (T // CopyTrie returns an independent copy of the given trie. func (db *VerkleDB) CopyTrie(tr Trie) Trie { t, ok := tr.(*trie.VerkleTrie) - if !ok { - panic("invalid tree type != VerkleTrie") + if ok { + return t.Copy(db.db) } - return t.Copy(db.db) + + s, ok := tr.(*trie.VerkleStorageAdapter) + if ok { + return s.Copy(db.db) + } + + panic("invalid tree type != VerkleTrie") } // ContractCode retrieves a particular contract's code. diff --git a/trie/verkle.go b/trie/verkle.go index 1686087a3aeb..1c388cf0159f 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -159,13 +159,16 @@ func (adapter *VerkleStorageAdapter) TryUpdate(key, value []byte) error { // TryDelete removes any existing value for key from the trie. If a node was not // found in the database, a trie.MissingNodeError is returned. func (adapter *VerkleStorageAdapter) TryDelete(key []byte) error { - return adapter.trie.root.Delete(key) + return adapter.trie.root.Delete(adapter.key2Storage(key)) } // Hash returns the root hash of the trie. It does not write to the database and // can be used even if the trie doesn't have one. func (adapter *VerkleStorageAdapter) Hash() common.Hash { - return adapter.trie.Hash() + // Return an empty hash for the moment. + // XXX this could be the wrong value, but at this stage I don't + // want to send the signal that this account has no storage. + return common.Hash{} } // Commit writes all nodes to the trie's memory database, tracking the internal