@@ -25,9 +25,24 @@ import (
2525// ReadPreimage retrieves a single preimage of the provided hash.
2626func ReadPreimage (db ctxcdb.KeyValueReader , hash common.Hash ) []byte {
2727 data , _ := db .Get (preimageKey (hash ))
28+ if len (data ) == 0 {
29+ preimageMissCounter .Inc (1 )
30+ } else {
31+ preimageHitsCounter .Inc (1 )
32+ }
2833 return data
2934}
3035
36+ // WritePreimages writes the provided set of preimages to the database.
37+ func WritePreimages (db ctxcdb.KeyValueWriter , preimages map [common.Hash ][]byte ) {
38+ for hash , preimage := range preimages {
39+ if err := db .Put (preimageKey (hash ), preimage ); err != nil {
40+ log .Crit ("Failed to store trie preimage" , "err" , err )
41+ }
42+ }
43+ preimageCounter .Inc (int64 (len (preimages )))
44+ }
45+
3146// ReadCode retrieves the contract code of the provided code hash.
3247func ReadCode (db ctxcdb.KeyValueReader , hash common.Hash ) []byte {
3348 // Try with the prefixed code scheme first, if not then try with legacy
@@ -80,17 +95,6 @@ func HasTrieNode(db ctxcdb.KeyValueReader, hash common.Hash) bool {
8095 return ok
8196}
8297
83- // WritePreimages writes the provided set of preimages to the database.
84- func WritePreimages (db ctxcdb.KeyValueWriter , preimages map [common.Hash ][]byte ) {
85- for hash , preimage := range preimages {
86- if err := db .Put (preimageKey (hash ), preimage ); err != nil {
87- log .Crit ("Failed to store trie preimage" , "err" , err )
88- }
89- }
90- preimageCounter .Inc (int64 (len (preimages )))
91- preimageHitCounter .Inc (int64 (len (preimages )))
92- }
93-
9498// WriteCode writes the provided contract code database.
9599func WriteCode (db ctxcdb.KeyValueWriter , hash common.Hash , code []byte ) {
96100 if err := db .Put (codeKey (hash ), code ); err != nil {
0 commit comments