Skip to content

Commit

Permalink
all: use rawdb.HasLegacyNode() to check for node existance instead of…
Browse files Browse the repository at this point in the history
… check for length
  • Loading branch information
Francesco4203 committed Sep 25, 2024
1 parent 76030b9 commit f6bea7f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions cmd/ronin/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f6bea7f

Please sign in to comment.