github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/admin/commands/storage/read_range_cluster_blocks.go (about) 1 package storage 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/dgraph-io/badger/v2" 8 "github.com/rs/zerolog/log" 9 10 "github.com/onflow/flow-go/admin" 11 "github.com/onflow/flow-go/admin/commands" 12 "github.com/onflow/flow-go/cmd/util/cmd/read-light-block" 13 "github.com/onflow/flow-go/model/flow" 14 storage "github.com/onflow/flow-go/storage/badger" 15 ) 16 17 var _ commands.AdminCommand = (*ReadRangeClusterBlocksCommand)(nil) 18 19 // 10001 instead of 10000, because 10000 won't allow a range from 10000 to 20000, 20 // which is easier to type than [10001, 20000] 21 const Max_Range_Cluster_Block_Limit = uint64(10001) 22 23 type ReadRangeClusterBlocksCommand struct { 24 db *badger.DB 25 headers *storage.Headers 26 payloads *storage.ClusterPayloads 27 } 28 29 func NewReadRangeClusterBlocksCommand(db *badger.DB, headers *storage.Headers, payloads *storage.ClusterPayloads) commands.AdminCommand { 30 return &ReadRangeClusterBlocksCommand{ 31 db: db, 32 headers: headers, 33 payloads: payloads, 34 } 35 } 36 37 func (c *ReadRangeClusterBlocksCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { 38 chainID, err := parseString(req, "chain-id") 39 if err != nil { 40 return nil, err 41 } 42 43 reqData, err := parseHeightRangeRequestData(req) 44 if err != nil { 45 return nil, err 46 } 47 48 log.Info().Str("module", "admin-tool").Msgf("read range cluster blocks, data: %v", reqData) 49 50 if reqData.Range() > Max_Range_Cluster_Block_Limit { 51 return nil, admin.NewInvalidAdminReqErrorf("getting for more than %v blocks at a time might have an impact to node's performance and is not allowed", Max_Range_Cluster_Block_Limit) 52 } 53 54 clusterBlocks := storage.NewClusterBlocks( 55 c.db, flow.ChainID(chainID), c.headers, c.payloads, 56 ) 57 58 lights, err := read.ReadClusterLightBlockByHeightRange(clusterBlocks, reqData.startHeight, reqData.endHeight) 59 if err != nil { 60 return nil, fmt.Errorf("could not get with chainID id %v: %w", chainID, err) 61 } 62 return commands.ConvertToInterfaceList(lights) 63 } 64 65 func (c *ReadRangeClusterBlocksCommand) Validator(req *admin.CommandRequest) error { 66 return nil 67 }