Implement getSlice
API
#206
@ -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++
|
||||||
|
Loading…
Reference in New Issue
Block a user