@@ -25,9 +25,24 @@ import (
25
25
// ReadPreimage retrieves a single preimage of the provided hash.
26
26
func ReadPreimage (db ctxcdb.KeyValueReader , hash common.Hash ) []byte {
27
27
data , _ := db .Get (preimageKey (hash ))
28
+ if len (data ) == 0 {
29
+ preimageMissCounter .Inc (1 )
30
+ } else {
31
+ preimageHitsCounter .Inc (1 )
32
+ }
28
33
return data
29
34
}
30
35
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
+
31
46
// ReadCode retrieves the contract code of the provided code hash.
32
47
func ReadCode (db ctxcdb.KeyValueReader , hash common.Hash ) []byte {
33
48
// 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 {
80
95
return ok
81
96
}
82
97
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
-
94
98
// WriteCode writes the provided contract code database.
95
99
func WriteCode (db ctxcdb.KeyValueWriter , hash common.Hash , code []byte ) {
96
100
if err := db .Put (codeKey (hash ), code ); err != nil {
0 commit comments