-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
mismatches.go
54 lines (42 loc) · 1.04 KB
/
mismatches.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
package main
import (
"fmt"
"github.com/urfave/cli/v2"
lcli "github.com/filecoin-project/lotus/cli"
)
var mismatchesCmd = &cli.Command{
Name: "mismatches",
Description: "Walk up the chain, recomputing state, and reporting any mismatches",
Action: func(cctx *cli.Context) error {
srv, err := lcli.GetFullNodeServices(cctx)
if err != nil {
return err
}
defer srv.Close() //nolint:errcheck
api := srv.FullNodeAPI()
ctx := lcli.ReqContext(cctx)
checkTs, err := api.ChainHead(ctx)
if err != nil {
return err
}
for checkTs.Height() != 0 {
if checkTs.Height()%10000 == 0 {
fmt.Println("Reached height ", checkTs.Height())
}
execTsk := checkTs.Parents()
execTs, err := api.ChainGetTipSet(ctx, execTsk)
if err != nil {
return err
}
st, err := api.StateCompute(ctx, execTs.Height(), nil, execTsk)
if err != nil {
return err
}
if st.Root != checkTs.ParentState() {
fmt.Println("consensus mismatch found at height ", execTs.Height())
}
checkTs = execTs
}
return nil
},
}