Skip undesired nodes from stem and head iterators

This commit is contained in:
Prathamesh Musale 2022-12-15 16:02:15 +05:30 committed by prathamesh0
parent 2a194a9488
commit 8e4d67fcd1

View File

@ -17,6 +17,7 @@
package eth package eth
import ( import (
"bytes"
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
@ -932,6 +933,11 @@ func (b *Backend) getSliceStem(headPath []byte, t state.Trie, response *GetSlice
it, timeTaken := getIteratorAtPath(t, startPath) it, timeTaken := getIteratorAtPath(t, startPath)
metaData.trieLoadingTime += timeTaken metaData.trieLoadingTime += timeTaken
// Skip if iterator not at required path (might happen if node not present at given path)
if !bytes.Equal(it.Path(), startPath) {
continue
}
sliceNodeMetrics, err := fillSliceNodeData(b.EthDB, b.StateDatabase.TrieDB(), response.TrieNodes.Stem, response.Leaves, it, storage) sliceNodeMetrics, err := fillSliceNodeData(b.EthDB, b.StateDatabase.TrieDB(), response.TrieNodes.Stem, response.Leaves, it, storage)
if err != nil { if err != nil {
return err return err
@ -956,6 +962,11 @@ func (b *Backend) getSliceHead(headPath []byte, t state.Trie, response *GetSlice
it, timeTaken := getIteratorAtPath(t, headPath) it, timeTaken := getIteratorAtPath(t, headPath)
metaData.trieLoadingTime += timeTaken metaData.trieLoadingTime += timeTaken
// Skip if iterator not at required path (might happen if node not present at given path)
if !bytes.Equal(it.Path(), headPath) {
return nil
}
sliceNodeMetrics, err := fillSliceNodeData(b.EthDB, b.StateDatabase.TrieDB(), response.TrieNodes.Head, response.Leaves, it, storage) sliceNodeMetrics, err := fillSliceNodeData(b.EthDB, b.StateDatabase.TrieDB(), response.TrieNodes.Head, response.Leaves, it, storage)
if err != nil { if err != nil {
return err return err