core, trie: use db.has over db.get where possible #24117 (#1078)

This commit is contained in:
Daniel Liu 2025-08-20 14:51:32 +08:00 committed by GitHub
parent e6f85271a3
commit a75fa97f56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -156,8 +156,7 @@ func (s *Sync) AddSubTrie(root common.Hash, path []byte, parent common.Hash, cal
} }
// If database says this is a duplicate, then at least the trie node is // If database says this is a duplicate, then at least the trie node is
// present, and we hold the assumption that it's NOT legacy contract code. // present, and we hold the assumption that it's NOT legacy contract code.
blob := rawdb.ReadTrieNode(s.database, root) if rawdb.HasTrieNode(s.database, root) {
if len(blob) > 0 {
return return
} }
// Assemble the new sub-trie sync request // Assemble the new sub-trie sync request
@ -194,7 +193,7 @@ func (s *Sync) AddCodeEntry(hash common.Hash, path []byte, parent common.Hash) {
// sync is expected to run with a fresh new node. Even there // sync is expected to run with a fresh new node. Even there
// exists the code with legacy format, fetch and store with // exists the code with legacy format, fetch and store with
// new scheme anyway. // new scheme anyway.
if blob := rawdb.ReadCodeWithPrefix(s.database, hash); len(blob) > 0 { if rawdb.HasCodeWithPrefix(s.database, hash) {
return return
} }
// Assemble the new sub-trie sync request // Assemble the new sub-trie sync request
@ -402,7 +401,7 @@ func (s *Sync) children(req *request, object node) ([]*request, error) {
} }
// If database says duplicate, then at least the trie node is present // If database says duplicate, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code. // and we hold the assumption that it's NOT legacy contract code.
if blob := rawdb.ReadTrieNode(s.database, hash); len(blob) > 0 { if rawdb.HasTrieNode(s.database, hash) {
continue continue
} }
// Locally unknown Node, schedule for retrieval // Locally unknown Node, schedule for retrieval