From ae304a5b5837d0dccc1a6a2557a6025dec90b1f4 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 +++++++++--- go.mod | 6 +++--- go.sum | 6 ++++++ trie/verkle.go | 7 +++++-- 4 files changed, 23 insertions(+), 8 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/go.mod b/go.mod index de558afcb61e..2bb6b2042bef 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/fatih/color v1.7.0 github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff - github.com/gballet/go-verkle v0.0.0-20210428140941-bf04335d54d3 // indirect + github.com/gballet/go-verkle v0.0.0-20210428140941-bf04335d54d3 github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect github.com/go-stack/stack v1.8.0 @@ -39,7 +39,7 @@ require ( github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29 github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/holiman/bloomfilter/v2 v2.0.3 - github.com/holiman/uint256 v1.1.1 + github.com/holiman/uint256 v1.2.0 github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 github.com/influxdata/influxdb v1.8.3 github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 @@ -63,7 +63,7 @@ require ( github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 - golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 + golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 golang.org/x/text v0.3.4 golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce diff --git a/go.sum b/go.sum index 7a7799b0763a..d58b5b6a1c52 100644 --- a/go.sum +++ b/go.sum @@ -225,10 +225,14 @@ github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:i github.com/herumi/bls-eth-go-binary v0.0.0-20210302070600-dfaa902c7773/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/herumi/bls-eth-go-binary v0.0.0-20210311024029-2939a1bfdec2 h1:WYYASILSlSdBFLQRysRQFuRW7VHxyNDbmYaGo3T2PkA= github.com/herumi/bls-eth-go-binary v0.0.0-20210311024029-2939a1bfdec2/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= +github.com/herumi/bls-eth-go-binary v0.0.0-20210504084019-f04b979e5fef h1:6fj3Xe89H1RELigndAInkWKsbYegsEcLdiSpSo4InUA= +github.com/herumi/bls-eth-go-binary v0.0.0-20210504084019-f04b979e5fef/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw= github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= +github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= +github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 h1:bcAj8KroPf552TScjFPIakjH2/tdIrIH8F+cc4v4SRo= @@ -529,6 +533,8 @@ golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 h1:EjgCl+fVlIaPJSori0ikSz3uV0DOHKWOJFpv1sAAhBM= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 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