This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/
fastibd.go
161 lines (156 loc) · 3.84 KB
/
fastibd.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"github.com/Qitmeer/qitmeer/common/roughtime"
_ "github.com/Qitmeer/qitmeer/database/ffldb"
_ "github.com/Qitmeer/qitmeer/services/common"
"github.com/urfave/cli/v2"
"os"
"runtime"
"runtime/debug"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
debug.SetGCPercent(20)
if err := fastIBD(); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}
func fastIBD() error {
cfg := &Config{}
node := &Node{}
app := &cli.App{
Name: "FastIBD",
Version: "V0.0.1",
Compiled: roughtime.Now(),
Authors: []*cli.Author{
&cli.Author{
Name: "Qitmeer",
},
},
Copyright: "(c) 2020 Qitmeer",
Usage: "Fast Initial Block Download",
Commands: []*cli.Command{
&cli.Command{
Name: "export",
Aliases: []string{"e"},
Category: "IBD",
Usage: "Export all blocks from database",
Description: "Export all blocks from database",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "Path to output data",
Value: defaultHomeDir,
Destination: &cfg.OutputPath,
},
&cli.StringFlag{
Name: "endpoint",
Aliases: []string{"e"},
Usage: "End point for output data",
Destination: &cfg.EndPoint,
},
&cli.BoolFlag{
Name: "byid",
Aliases: []string{"i"},
Usage: "Export by block id",
Destination: &cfg.ByID,
},
},
Before: func(c *cli.Context) error {
return node.init(cfg)
},
After: func(c *cli.Context) error {
return node.exit()
},
Action: func(c *cli.Context) error {
return node.Export()
},
},
&cli.Command{
Name: "import",
Aliases: []string{"i"},
Category: "IBD",
Usage: "Import all blocks from database",
Description: "Import all blocks from database",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "Path to input data",
Value: defaultHomeDir,
Destination: &cfg.InputPath,
},
},
Before: func(c *cli.Context) error {
return node.init(cfg)
},
After: func(c *cli.Context) error {
return node.exit()
},
Action: func(c *cli.Context) error {
return node.Import()
},
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "appdata",
Aliases: []string{"A"},
Usage: "Path to application home directory",
Value: defaultHomeDir,
Destination: &cfg.HomeDir,
},
&cli.StringFlag{
Name: "datadir",
Aliases: []string{"b"},
Usage: "Directory to store data",
Value: defaultDataDir,
Destination: &cfg.DataDir,
},
&cli.BoolFlag{
Name: "testnet",
Usage: "Use the test network",
Value: false,
Destination: &cfg.TestNet,
},
&cli.BoolFlag{
Name: "mixnet",
Usage: "Use the test mix pow network",
Value: false,
Destination: &cfg.MixNet,
},
&cli.BoolFlag{
Name: "privnet",
Usage: "Use the private network",
Value: false,
Destination: &cfg.PrivNet,
},
&cli.StringFlag{
Name: "dbtype",
Usage: "Database backend to use for the Block Chain",
Value: defaultDbType,
Destination: &cfg.DbType,
},
&cli.StringFlag{
Name: "dagtype",
Aliases: []string{"G"},
Usage: "DAG type {phantom,conflux,spectre}",
Value: defaultDAGType,
Destination: &cfg.DAGType,
},
&cli.BoolFlag{
Name: "disablebar",
Usage: "Hide progress bar",
Value: false,
Destination: &cfg.DisableBar,
},
},
EnableBashCompletion: true,
Action: func(c *cli.Context) error {
return cli.ShowAppHelp(c)
},
}
return app.Run(os.Args)
}