|
|
@ -28,17 +28,6 @@ func ReadPreimage(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WritePreimages writes the provided set of preimages to the database.
|
|
|
|
|
|
|
|
func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) { |
|
|
|
|
|
|
|
for hash, preimage := range preimages { |
|
|
|
|
|
|
|
if err := db.Put(preimageKey(hash), preimage); err != nil { |
|
|
|
|
|
|
|
log.Crit("Failed to store trie preimage", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
preimageCounter.Inc(int64(len(preimages))) |
|
|
|
|
|
|
|
preimageHitCounter.Inc(int64(len(preimages))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReadCode retrieves the contract code of the provided code hash.
|
|
|
|
// ReadCode retrieves the contract code of the provided code hash.
|
|
|
|
func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
// Try with the prefixed code scheme first, if not then try with legacy
|
|
|
|
// Try with the prefixed code scheme first, if not then try with legacy
|
|
|
@ -47,7 +36,7 @@ func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
if len(data) != 0 { |
|
|
|
if len(data) != 0 { |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
data, _ = db.Get(hash[:]) |
|
|
|
data, _ = db.Get(hash.Bytes()) |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -59,6 +48,24 @@ func ReadCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
return data |
|
|
|
return data |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReadTrieNode retrieves the trie node of the provided hash.
|
|
|
|
|
|
|
|
func ReadTrieNode(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
|
|
|
|
data, _ := db.Get(hash.Bytes()) |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HasCode checks if the contract code corresponding to the
|
|
|
|
|
|
|
|
// provided code hash is present in the db.
|
|
|
|
|
|
|
|
func HasCode(db ethdb.KeyValueReader, hash common.Hash) bool { |
|
|
|
|
|
|
|
// Try with the prefixed code scheme first, if not then try with legacy
|
|
|
|
|
|
|
|
// scheme.
|
|
|
|
|
|
|
|
if ok := HasCodeWithPrefix(db, hash); ok { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ok, _ := db.Has(hash.Bytes()) |
|
|
|
|
|
|
|
return ok |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// HasCodeWithPrefix checks if the contract code corresponding to the
|
|
|
|
// HasCodeWithPrefix checks if the contract code corresponding to the
|
|
|
|
// provided code hash is present in the db. This function will only check
|
|
|
|
// provided code hash is present in the db. This function will only check
|
|
|
|
// presence using the prefix-scheme.
|
|
|
|
// presence using the prefix-scheme.
|
|
|
@ -67,30 +74,28 @@ func HasCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) bool { |
|
|
|
return ok |
|
|
|
return ok |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteCode writes the provided contract code database.
|
|
|
|
// HasTrieNode checks if the trie node with the provided hash is present in db.
|
|
|
|
func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte) { |
|
|
|
func HasTrieNode(db ethdb.KeyValueReader, hash common.Hash) bool { |
|
|
|
if err := db.Put(codeKey(hash), code); err != nil { |
|
|
|
ok, _ := db.Has(hash.Bytes()) |
|
|
|
log.Crit("Failed to store contract code", "err", err) |
|
|
|
return ok |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeleteCode deletes the specified contract code from the database.
|
|
|
|
// WritePreimages writes the provided set of preimages to the database.
|
|
|
|
func DeleteCode(db ethdb.KeyValueWriter, hash common.Hash) { |
|
|
|
func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) { |
|
|
|
if err := db.Delete(codeKey(hash)); err != nil { |
|
|
|
for hash, preimage := range preimages { |
|
|
|
log.Crit("Failed to delete contract code", "err", err) |
|
|
|
if err := db.Put(preimageKey(hash), preimage); err != nil { |
|
|
|
|
|
|
|
log.Crit("Failed to store trie preimage", "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
preimageCounter.Inc(int64(len(preimages))) |
|
|
|
// ReadTrieNode retrieves the trie node of the provided hash.
|
|
|
|
preimageHitCounter.Inc(int64(len(preimages))) |
|
|
|
func ReadTrieNode(db ethdb.KeyValueReader, hash common.Hash) []byte { |
|
|
|
|
|
|
|
data, _ := db.Get(hash.Bytes()) |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// HasTrieNode checks if the trie node with the provided hash is present in db.
|
|
|
|
// WriteCode writes the provided contract code database.
|
|
|
|
func HasTrieNode(db ethdb.KeyValueReader, hash common.Hash) bool { |
|
|
|
func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte) { |
|
|
|
ok, _ := db.Has(hash.Bytes()) |
|
|
|
if err := db.Put(codeKey(hash), code); err != nil { |
|
|
|
return ok |
|
|
|
log.Crit("Failed to store contract code", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteTrieNode writes the provided trie node database.
|
|
|
|
// WriteTrieNode writes the provided trie node database.
|
|
|
@ -100,6 +105,13 @@ func WriteTrieNode(db ethdb.KeyValueWriter, hash common.Hash, node []byte) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteCode deletes the specified contract code from the database.
|
|
|
|
|
|
|
|
func DeleteCode(db ethdb.KeyValueWriter, hash common.Hash) { |
|
|
|
|
|
|
|
if err := db.Delete(codeKey(hash)); err != nil { |
|
|
|
|
|
|
|
log.Crit("Failed to delete contract code", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeleteTrieNode deletes the specified trie node from the database.
|
|
|
|
// DeleteTrieNode deletes the specified trie node from the database.
|
|
|
|
func DeleteTrieNode(db ethdb.KeyValueWriter, hash common.Hash) { |
|
|
|
func DeleteTrieNode(db ethdb.KeyValueWriter, hash common.Hash) { |
|
|
|
if err := db.Delete(hash.Bytes()); err != nil { |
|
|
|
if err := db.Delete(hash.Bytes()); err != nil { |
|
|
|