From 8e4d67fcd1f32b23af00cf5b52753e1a52f8c603 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Thu, 15 Dec 2022 16:02:15 +0530 Subject: [PATCH] Skip undesired nodes from stem and head iterators --- pkg/eth/backend.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index 6f7e9385..a3eb6ea8 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -17,6 +17,7 @@ package eth import ( + "bytes" "context" "database/sql" "errors" @@ -932,6 +933,11 @@ func (b *Backend) getSliceStem(headPath []byte, t state.Trie, response *GetSlice it, timeTaken := getIteratorAtPath(t, startPath) 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) if err != nil { return err @@ -956,6 +962,11 @@ func (b *Backend) getSliceHead(headPath []byte, t state.Trie, response *GetSlice it, timeTaken := getIteratorAtPath(t, headPath) 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) if err != nil { return err