-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathread_range_cluster_blocks.go
More file actions
70 lines (56 loc) · 2.11 KB
/
Copy pathread_range_cluster_blocks.go
File metadata and controls
70 lines (56 loc) · 2.11 KB
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
68
69
70
package storage
import (
"context"
"fmt"
"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"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/storage"
"github.com/onflow/flow-go/storage/store"
)
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 storage.DB
payloads *store.ClusterPayloads
}
func NewReadRangeClusterBlocksCommand(db storage.DB, payloads *store.ClusterPayloads) commands.AdminCommand {
return &ReadRangeClusterBlocksCommand{
db: db,
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)
}
clusterHeaders, err := store.NewClusterHeaders(metrics.NewNoopCollector(), c.db, flow.ChainID(chainID))
if err != nil {
return nil, err
}
clusterBlocks := store.NewClusterBlocks(
c.db, flow.ChainID(chainID), clusterHeaders, 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
}