forked from froghub-io/filecoin-sealer-recover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (78 loc) · 2.12 KB
/
main.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
package main
import (
"context"
"github.com/filecoin-project/go-address"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/froghub-io/filecoin-sealer-recover/recovery"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
"os"
)
func main() {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
app := &cli.App{
Name: "sealer-recovery",
Usage: "Filecoin sealer recovery",
Version: BuildVersion,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "miner",
Usage: "Filecoin miner. Such as: f01000",
Required: true,
},
&cli.IntSliceFlag{
Name: "sector",
Usage: "Sector number to be recovered. Such as: --sector=0 --sector=1 ... ",
Required: true,
},
&cli.UintFlag{
Name: "parallel",
Usage: "Number of parallel P1",
Value: 1,
},
&cli.StringFlag{
Name: "sealing-result",
Value: "~/sector",
Usage: "Recover sector result path",
},
&cli.StringFlag{
Name: "sealing-temp",
Value: "~/temp",
Usage: "Temporarily generated during sector recovery",
},
},
Action: func(cctx *cli.Context) error {
log.Info("Start sealer recovery!")
ctx := cliutil.DaemonContext(cctx)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
maddr, err := address.NewFromString(cctx.String("miner"))
if err != nil {
return xerrors.Errorf("Getting NewFromString err:", err)
}
actorID, err := address.IDFromAddress(maddr)
if err != nil {
return xerrors.Errorf("Getting IDFromAddress err:", err)
}
fullapi, closer, err := cliutil.GetFullNodeAPI(cctx)
if err != nil {
return xerrors.Errorf("Getting FullNodeAPI err:", err)
}
defer closer()
if err = recovery.RecoverSealedFile(ctx, fullapi, maddr, actorID, cctx.IntSlice("sector"), cctx.Uint("parallel"), cctx.String("sealing-result"), cctx.String("sealing-temp")); err != nil {
return err
}
log.Info("Complete recovery sealed!")
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Warnf("%+v", err)
return
}
}
// BuildVersion is the local build version
const BuildVersion = "1.0.0"