From 062eaa2043ca5e539068492ed2324d4cf6554a09 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 7 Feb 2022 06:37:54 +0000 Subject: [PATCH 1/4] implement core/state: implement GetCodeSize for VerkleDB --- core/state/database.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/state/database.go b/core/state/database.go index ee7d2c9a37a0..673193ca9724 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -270,7 +270,17 @@ func (db *VerkleDB) ContractCode(addrHash, codeHash common.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. func (db *VerkleDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, error) { - panic("need to merge #31 for this to work") + // TODO disgusting hack, do this the proper way (reading code size from the account fields) + if code := db.codeCache.Get(nil, codeHash.Bytes()); len(code) > 0 { + return len(code), nil + } + code := rawdb.ReadCode(db.db.DiskDB(), codeHash) + if len(code) > 0 { + db.codeCache.Set(codeHash.Bytes(), code) + db.codeSizeCache.Add(codeHash, len(code)) + return len(code), nil + } + return 0, errors.New("not found") } // TrieDB retrieves the low level trie database used for data storage. From bacc438346867893c80a0c48f7ad092d1e5e0eb1 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 7 Feb 2022 06:44:29 +0000 Subject: [PATCH 2/4] fix --- core/state/database.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/state/database.go b/core/state/database.go index 673193ca9724..a74d439c042b 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -270,7 +270,6 @@ func (db *VerkleDB) ContractCode(addrHash, codeHash common.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. func (db *VerkleDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, error) { - // TODO disgusting hack, do this the proper way (reading code size from the account fields) if code := db.codeCache.Get(nil, codeHash.Bytes()); len(code) > 0 { return len(code), nil } @@ -279,8 +278,9 @@ func (db *VerkleDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, error db.codeCache.Set(codeHash.Bytes(), code) db.codeSizeCache.Add(codeHash, len(code)) return len(code), nil + } else { + return 0 } - return 0, errors.New("not found") } // TrieDB retrieves the low level trie database used for data storage. From f187ed82b0fd94e59e2e559fcf572664bdfa95ca Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 7 Feb 2022 06:45:29 +0000 Subject: [PATCH 3/4] fix --- core/state/database.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/state/database.go b/core/state/database.go index a74d439c042b..8aa5f81d2d70 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -278,9 +278,8 @@ func (db *VerkleDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, error db.codeCache.Set(codeHash.Bytes(), code) db.codeSizeCache.Add(codeHash, len(code)) return len(code), nil - } else { - return 0 } + return 0 } // TrieDB retrieves the low level trie database used for data storage. From c1432d2d0f3ab6af84c7d31e14be792752f110a6 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 7 Feb 2022 06:57:28 +0000 Subject: [PATCH 4/4] fix --- core/state/database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/state/database.go b/core/state/database.go index 8aa5f81d2d70..f29e85474745 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -279,7 +279,7 @@ func (db *VerkleDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, error db.codeSizeCache.Add(codeHash, len(code)) return len(code), nil } - return 0 + return 0, nil } // TrieDB retrieves the low level trie database used for data storage.