-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
111 lines (91 loc) · 2.38 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/proxy"
cfg "github.com/cometbft/cometbft/config"
cmtflags "github.com/cometbft/cometbft/libs/cli/flags"
cmtlog "github.com/cometbft/cometbft/libs/log"
"github.com/dgraph-io/badger/v4"
nm "github.com/meterio/supernova/node"
"github.com/meterio/supernova/types"
"github.com/spf13/viper"
)
var homeDir string
func init() {
flag.StringVar(&homeDir, "cmt-home", "", "Path to the CometBFT config directory (if empty, uses $HOME/.cometbft)")
}
var (
logger = cmtlog.NewTMLogger(
cmtlog.NewSyncWriter(os.Stdout),
).With("module", "priv_val")
)
func main() {
flag.Parse()
if homeDir == "" {
homeDir = os.ExpandEnv("$HOME/.supernova")
}
config := cfg.DefaultConfig()
config.SetRoot(homeDir)
viper.SetConfigFile(fmt.Sprintf("%s/%s", homeDir, "config/config.toml"))
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Reading config: %v", err)
}
if err := viper.Unmarshal(config); err != nil {
log.Fatalf("Decoding config: %v", err)
}
if err := config.ValidateBasic(); err != nil {
log.Fatalf("Invalid configuration data: %v", err)
}
dbPath := filepath.Join(homeDir, "badger")
db, err := badger.Open(badger.DefaultOptions(dbPath))
if err != nil {
log.Fatalf("Opening database: %v", err)
}
defer func() {
if err := db.Close(); err != nil {
log.Printf("Closing database: %v", err)
}
}()
app := NewKVStoreApplication(db)
pv := privval.LoadFilePV(
config.PrivValidatorKeyFile(),
config.PrivValidatorStateFile(),
)
nodeKey, err := types.LoadNodeKey(config.NodeKeyFile())
if err != nil {
log.Fatalf("failed to load node's key: %v %v", config.NodeKeyFile(), err)
}
logger := cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout))
logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel)
if err != nil {
log.Fatalf("failed to parse log level: %v", err)
}
// config.LogLevel = "debug" // default is info
node := nm.NewNode(
config,
pv,
nodeKey,
proxy.NewLocalClientCreator(app),
nm.DefaultGenesisDocProviderFunc(config),
cfg.DefaultDBProvider,
logger,
)
if err != nil {
log.Fatalf("Creating node: %v", err)
}
node.Start()
defer func() {
node.Stop()
// node.Wait()
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
}