/
init.go
99 lines (87 loc) · 2.68 KB
/
init.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package commands
import (
"context"
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/lily/commands/util"
"github.com/filecoin-project/lily/config"
lotusbuild "github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/node/repo"
)
var initFlags struct {
repo string
config string
importSnapshot string
backfillTipsetKeyRange int
}
var InitCmd = &cli.Command{
Name: "init",
Usage: "Initialise a lily repository.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Usage: "Specify path where lily should store chain state.",
EnvVars: []string{"LILY_REPO"},
Value: "~/.lily",
Destination: &initFlags.repo,
},
&cli.StringFlag{
Name: "config",
Usage: "Specify path of config file to use.",
EnvVars: []string{"LILY_CONFIG"},
Destination: &initFlags.config,
},
&cli.StringFlag{
Name: "import-snapshot",
Usage: "Import chain state from a given chain export file or url.",
EnvVars: []string{"LILY_SNAPSHOT"},
Destination: &initFlags.importSnapshot,
},
&cli.IntFlag{
Name: "backfill-tipsetkey-range",
Usage: "Determine the extent of backfilling from the head.",
EnvVars: []string{"LILY_BACKFILL_TIPSETKEY_RANGE"},
Value: 3600,
Destination: &initFlags.backfillTipsetKeyRange,
},
},
Action: func(c *cli.Context) error {
lotuslog.SetupLogLevels()
ctx := context.Background()
{
dir, err := homedir.Expand(initFlags.repo)
if err != nil {
log.Warnw("could not expand repo location", "error", err)
} else {
log.Infof("lotus repo: %s", dir)
}
}
r, err := repo.NewFS(initFlags.repo)
if err != nil {
return fmt.Errorf("opening fs repo: %w", err)
}
if initFlags.config != "" {
if err := config.EnsureExists(initFlags.config); err != nil {
return fmt.Errorf("ensuring config is present at %q: %w", initFlags.config, err)
}
r.SetConfigPath(initFlags.config)
}
err = r.Init(repo.FullNode)
if err != nil && err != repo.ErrRepoExists {
return fmt.Errorf("repo init error: %w", err)
}
if err := paramfetch.GetParams(lcli.ReqContext(c), lotusbuild.ParametersJSON(), lotusbuild.SrsJSON(), 0); err != nil {
return fmt.Errorf("fetching proof parameters: %w", err)
}
if initFlags.importSnapshot != "" {
if err := util.ImportChain(ctx, r, initFlags.importSnapshot, true, initFlags.backfillTipsetKeyRange); err != nil {
return err
}
}
return nil
},
}