-
Notifications
You must be signed in to change notification settings - Fork 170
/
cmd.go
88 lines (67 loc) · 2.04 KB
/
cmd.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
package read
import (
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
list_accounts "github.com/onflow/flow-go/cmd/util/cmd/read-execution-state/list-accounts"
list_tries "github.com/onflow/flow-go/cmd/util/cmd/read-execution-state/list-tries"
list_wals "github.com/onflow/flow-go/cmd/util/cmd/read-execution-state/list-wals"
"github.com/onflow/flow-go/ledger/common/pathfinder"
"github.com/onflow/flow-go/ledger/complete"
"github.com/onflow/flow-go/ledger/complete/mtrie"
"github.com/onflow/flow-go/ledger/complete/wal"
"github.com/onflow/flow-go/module/metrics"
)
var (
flagExecutionStateDir string
)
var Cmd = &cobra.Command{
Use: "read-execution-state",
Short: "Reads Execution State and will allow (one day) queries against it",
Run: run,
}
func init() {
Cmd.PersistentFlags().StringVar(&flagExecutionStateDir, "execution-state-dir", "",
"Execution Node state dir (where WAL logs are written")
_ = Cmd.MarkPersistentFlagRequired("execution-state-dir")
addSubcommands()
}
func addSubcommands() {
Cmd.AddCommand(list_tries.Init(loadExecutionState))
Cmd.AddCommand(list_accounts.Init(loadExecutionState))
Cmd.AddCommand(list_wals.Init())
}
func loadExecutionState() *mtrie.Forest {
w, err := wal.NewDiskWAL(
zerolog.Nop(),
nil,
metrics.NewNoopCollector(),
flagExecutionStateDir,
complete.DefaultCacheSize,
pathfinder.PathByteSize,
wal.SegmentSize,
)
if err != nil {
log.Fatal().Err(err).Msg("error while creating WAL")
}
defer func() {
<-w.Done()
}()
forest, err := mtrie.NewForest(complete.DefaultCacheSize, metrics.NewNoopCollector(), nil)
if err != nil {
log.Fatal().Err(err).Msg("error while creating mForest")
}
err = w.ReplayOnForest(forest)
if err != nil {
log.Fatal().Err(err).Msg("error while replaying execution state")
}
return forest
}
func run(*cobra.Command, []string) {
log.Info().Msg("reading")
startTime := time.Now()
_ = loadExecutionState()
duration := time.Since(startTime)
log.Info().Float64("total_time_s", duration.Seconds()).Msg("finished")
}