erigon-pulse/cmd/restapi/apis/intermediate_data_len_api.go
Alex Sharov daa359c363
Mgr schedule iterator (#566)
* db based version of PrefixByCumulativeWitnessSize

* db based version of PrefixByCumulativeWitnessSize

* retain all in Trie by default

* fix WitnessLen logic in calcTrie roots

* Rename IntermediateTrieWitnessLenBucket to IntermediateWitnessLenBucket

* handle corner cases in WL

* Use correct incarnation for IH bucket

* use name WitnessSize

* save progress towards db-only witness estimation

* results from trie and from db are still different

* less recursion

* correct incarnation in CumulativeSearch

* reuse results from previous Tick, separate concepts of parent and startKey

* experiment: if not including trie structure to WitnessSize will reduce cumulative error

* tool to generate all IH and tool to calculate assessment of cumulative error

* tool to generate all IH

* Calculate totalWitnessSize based on DB data - then schedule will not overrun state during MGR cycle

* better stats

* Calculate totalWitnessSize based on DB data - then schedule will not overrun state during MGR cycle

* Calculate totalWitnessSize based on DB data - then schedule will not overrun state during MGR cycle

* calculate ticks size distribution

* estimate cumulative error

* fix linter

* resetIH from scratch if needed

* cleanup

* fix test

* fix test
2020-05-28 12:33:05 +01:00

65 lines
1.5 KiB
Go

package apis
import (
"context"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
)
func RegisterIntermediateDataLenAPI(router *gin.RouterGroup, e *Env) error {
router.GET("/", e.FindIntermediateDataLen)
return nil
}
func (e *Env) FindIntermediateDataLen(c *gin.Context) {
results, err := findIntermediateDataLenByPrefix(c.Query("prefix"), e.DB)
if err != nil {
c.Error(err) //nolint:errcheck
return
}
c.JSON(http.StatusOK, results)
}
type IntermediateDataLenResponse struct {
Prefix string `json:"prefix"`
Value string `json:"value"`
}
func findIntermediateDataLenByPrefix(prefixS string, remoteDB ethdb.KV) ([]*IntermediateDataLenResponse, error) {
var results []*IntermediateDataLenResponse
prefix := common.FromHex(prefixS)
if err := remoteDB.View(context.TODO(), func(tx ethdb.Tx) error {
interBucket := tx.Bucket(dbutils.IntermediateWitnessSizeBucket)
c := interBucket.Cursor().Prefix(prefix)
for k, v, err := c.First(); k != nil || err != nil; k, v, err = c.Next() {
if err != nil {
return err
}
results = append(results, &IntermediateDataLenResponse{
Prefix: fmt.Sprintf("%x\n", k),
Value: fmt.Sprintf("%x\n", v),
})
if len(results) > 50 {
results = append(results, &IntermediateDataLenResponse{
Prefix: "too much results",
})
return nil
}
}
return nil
}); err != nil {
return nil, err
}
return results, nil
}