-
Notifications
You must be signed in to change notification settings - Fork 901
/
header.go
72 lines (57 loc) · 1.54 KB
/
header.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
68
69
70
71
72
package main
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/spf13/cobra"
"github.com/celestiaorg/go-header/store"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/nodebuilder"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
)
func init() {
headerCmd.AddCommand(headerStoreInit)
}
var headerCmd = &cobra.Command{
Use: "header [subcommand]",
Short: "Collection of header module related utilities",
}
var headerStoreInit = &cobra.Command{
Use: "store-init [node-type] [network] [height]",
Short: `Forcefully initialize header store head to be of the given height. Requires the node being stopped.
Custom store path is not supported yet.`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 3 {
return errors.New("not enough arguments")
}
tp := node.ParseType(args[0])
if !tp.IsValid() {
return errors.New("invalid node-type")
}
network := args[1]
height, err := strconv.Atoi(args[2])
if err != nil {
return fmt.Errorf("invalid height: %w", err)
}
s, err := nodebuilder.OpenStore(fmt.Sprintf("~/.celestia-%s-%s", strings.ToLower(tp.String()),
strings.ToLower(network)), nil)
if err != nil {
return err
}
ds, err := s.Datastore()
if err != nil {
return err
}
hstore, err := store.NewStore[*header.ExtendedHeader](ds)
if err != nil {
return err
}
newHead, err := hstore.GetByHeight(cmd.Context(), uint64(height))
if err != nil {
return err
}
return hstore.Init(cmd.Context(), newHead)
},
}