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