From 62992fe47b7e134e11e6c82a0768aa5402240f7d Mon Sep 17 00:00:00 2001 From: Francesco4203 Date: Thu, 26 Sep 2024 00:24:18 +0700 Subject: [PATCH] all: use rawdb.HasLegacyNode() to check for node existance instead of check for length --- cmd/ronin/snapshot.go | 6 ++---- core/state/pruner/pruner.go | 4 ++-- trie/sync.go | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/ronin/snapshot.go b/cmd/ronin/snapshot.go index 2a6a97f36..acb24361c 100644 --- a/cmd/ronin/snapshot.go +++ b/cmd/ronin/snapshot.go @@ -394,8 +394,7 @@ func traverseRawState(ctx *cli.Context) error { if node != (common.Hash{}) { // Check the present for non-empty hash node(embedded node doesn't // have their own hash). - blob := rawdb.ReadLegacyTrieNode(chaindb, node) - if len(blob) == 0 { + if !rawdb.HasLegacyTrieNode(chaindb, node) { log.Error("Missing trie node(account)", "hash", node) return errors.New("missing account") } @@ -423,8 +422,7 @@ func traverseRawState(ctx *cli.Context) error { // Check the present for non-empty hash node(embedded node doesn't // have their own hash). if node != (common.Hash{}) { - blob := rawdb.ReadLegacyTrieNode(chaindb, node) - if len(blob) == 0 { + if !rawdb.HasLegacyTrieNode(chaindb, node) { log.Error("Missing trie node(storage)", "hash", node) return errors.New("missing storage") } diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index 34497569d..a383990be 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -265,7 +265,7 @@ func (p *Pruner) Prune(root common.Hash) error { // Ensure the root is really present. The weak assumption // is the presence of root can indicate the presence of the // entire trie. - if blob := rawdb.ReadLegacyTrieNode(p.db, root); len(blob) == 0 { + if !rawdb.HasLegacyTrieNode(p.db, root) { // The special case is for clique based networks(rinkeby, goerli // and some other private networks), it's possible that two // consecutive blocks will have same root. In this case snapshot @@ -279,7 +279,7 @@ func (p *Pruner) Prune(root common.Hash) error { // as the pruning target. var found bool for i := len(layers) - 2; i >= 2; i-- { - if blob := rawdb.ReadLegacyTrieNode(p.db, layers[i].Root()); len(blob) != 0 { + if !rawdb.HasLegacyTrieNode(p.db, layers[i].Root()) { root = layers[i].Root() found = true log.Info("Selecting middle-layer as the pruning target", "root", root, "depth", i) diff --git a/trie/sync.go b/trie/sync.go index a406d281e..d68ea8567 100644 --- a/trie/sync.go +++ b/trie/sync.go @@ -195,8 +195,7 @@ func (s *Sync) AddSubTrie(root common.Hash, path []byte, parent common.Hash, par // If database says yes, then at least the trie node is present // and we hold the assumption that it's NOT legacy contract code. owner, inner := ResolvePath(path) - blob := rawdb.ReadTrieNode(s.database, owner, inner, root, s.scheme) - if len(blob) > 0 { + if rawdb.HasTrieNode(s.database, owner, inner, root, s.scheme) { return } // False positive, bump fault meter