Implement getSlice API #206

Merged
prathamesh0 merged 21 commits from pm-get-slice into v4 2022-12-19 08:42:23 +00:00
Showing only changes of commit 865b965669 - Show all commits

View File

@ -892,12 +892,15 @@ func (b *Backend) GetSlice(path string, depth int, root common.Hash, storage boo
response := new(GetSliceResponse) response := new(GetSliceResponse)
response.init(path, depth, root) response.init(path, depth, root)
t, _ := b.StateDatabase.OpenTrie(root)
headPath := common.FromHex(path)
// Metadata fields // Metadata fields
metaData := metaDataFields{} metaData := metaDataFields{}
startTime := makeTimestamp()
t, _ := b.StateDatabase.OpenTrie(root)
metaData.trieLoadingTime = makeTimestamp() - startTime
headPath := common.FromHex(path)
// Get Stem nodes // Get Stem nodes
err := b.getSliceStem(headPath, t, response, &metaData, storage) err := b.getSliceStem(headPath, t, response, &metaData, storage)
if err != nil { if err != nil {
@ -944,8 +947,9 @@ func (b *Backend) getSliceStem(headPath []byte, t state.Trie, response *GetSlice
} }
// Update metadata // Update metadata
if (sliceNodeMetrics.pathLen - len(headPath)) > metaData.maxDepth { depthReached := sliceNodeMetrics.pathLen - len(headPath)
metaData.maxDepth = sliceNodeMetrics.pathLen if depthReached > metaData.maxDepth {
metaData.maxDepth = depthReached
} }
if sliceNodeMetrics.isLeaf { if sliceNodeMetrics.isLeaf {
metaData.leafCount++ metaData.leafCount++
@ -973,8 +977,9 @@ func (b *Backend) getSliceHead(headPath []byte, t state.Trie, response *GetSlice
} }
// Update metadata // Update metadata
if (sliceNodeMetrics.pathLen - len(headPath)) > metaData.maxDepth { depthReached := sliceNodeMetrics.pathLen - len(headPath)
metaData.maxDepth = sliceNodeMetrics.pathLen if depthReached > metaData.maxDepth {
metaData.maxDepth = depthReached
} }
if sliceNodeMetrics.isLeaf { if sliceNodeMetrics.isLeaf {
metaData.leafCount++ metaData.leafCount++
@ -1013,8 +1018,9 @@ func (b *Backend) getSliceTrie(headPath []byte, t state.Trie, response *GetSlice
} }
// Update metadata // Update metadata
if (sliceNodeMetrics.pathLen - len(headPath)) > metaData.maxDepth { depthReached := sliceNodeMetrics.pathLen - len(headPath)
metaData.maxDepth = sliceNodeMetrics.pathLen if depthReached > metaData.maxDepth {
metaData.maxDepth = depthReached
} }
if sliceNodeMetrics.isLeaf { if sliceNodeMetrics.isLeaf {
metaData.leafCount++ metaData.leafCount++