/
start.go
348 lines (288 loc) · 11.2 KB
/
start.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package server
// DONTCOVER
import (
"os"
"runtime/pprof"
"github.com/evoblockchain/evochain/libs/tendermint/consensus"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/store/mpt"
"github.com/evoblockchain/evochain/libs/tendermint/rpc/client"
"github.com/gogo/protobuf/jsonpb"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/baseapp"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/client/context"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/client/lcd"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/codec"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/store/iavl"
"github.com/evoblockchain/evochain/libs/cosmos-sdk/x/auth/types"
"github.com/evoblockchain/evochain/libs/system"
"github.com/evoblockchain/evochain/libs/tendermint/libs/cli"
"github.com/evoblockchain/evochain/libs/tendermint/libs/log"
"github.com/evoblockchain/evochain/libs/tendermint/mempool"
"github.com/evoblockchain/evochain/libs/tendermint/node"
"github.com/evoblockchain/evochain/libs/tendermint/p2p"
"github.com/evoblockchain/evochain/libs/tendermint/proxy"
"github.com/evoblockchain/evochain/libs/tendermint/rpc/client/local"
"github.com/evoblockchain/evochain/libs/tendermint/state"
"github.com/spf13/cobra"
"github.com/spf13/viper"
tmiavl "github.com/evoblockchain/evochain/libs/iavl"
abci "github.com/evoblockchain/evochain/libs/tendermint/abci/types"
bcv0 "github.com/evoblockchain/evochain/libs/tendermint/blockchain/v0"
tcmd "github.com/evoblockchain/evochain/libs/tendermint/cmd/tendermint/commands"
tmos "github.com/evoblockchain/evochain/libs/tendermint/libs/os"
pvm "github.com/evoblockchain/evochain/libs/tendermint/privval"
tmtypes "github.com/evoblockchain/evochain/libs/tendermint/types"
)
// Tendermint full-node start flags
const (
flagAddress = "address"
flagTraceStore = "trace-store"
flagCPUProfile = "cpu-profile"
FlagMinGasPrices = "minimum-gas-prices"
FlagHaltHeight = "halt-height"
FlagHaltTime = "halt-time"
FlagInterBlockCache = "inter-block-cache"
FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades"
FlagTrace = "trace"
FlagPruning = "pruning"
FlagPruningKeepRecent = "pruning-keep-recent"
FlagPruningKeepEvery = "pruning-keep-every"
FlagPruningInterval = "pruning-interval"
FlagLocalRpcPort = "local-rpc-port"
FlagPortMonitor = "netstat"
FlagEvmImportPath = "evm-import-path"
FlagEvmImportMode = "evm-import-mode"
FlagGoroutineNum = "goroutine-num"
FlagPruningMaxWsNum = "pruning-max-worldstate-num"
FlagExportKeystore = "export-keystore"
FlagLogServerUrl = "log-server"
FlagActiveViewChange = "active-view-change"
FlagCommitGapHeight = "commit-gap-height"
FlagBlockPartSizeBytes = "block-part-size"
FlagFastSyncGap = "fastsync-gap"
)
// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
func StartCmd(ctx *Context,
cdc *codec.CodecProxy,
registry jsonpb.AnyResolver,
appCreator AppCreator,
appStop AppStop,
registerRoutesFn func(restServer *lcd.RestServer),
registerAppFlagFn func(cmd *cobra.Command),
appPreRun func(ctx *Context, cmd *cobra.Command) error,
subFunc func(logger log.Logger) log.Subscriber,
) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Run the full node",
Long: `Run the full node application with Tendermint in or out of process. By
default, the application will run with Tendermint in process.
Pruning options can be provided via the '--pruning' flag or alternatively with '--pruning-keep-recent',
'pruning-keep-every', and 'pruning-interval' together.
For '--pruning' the options are as follows:
default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals
nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node)
everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals
custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval'
Node halting configurations exist in the form of two flags: '--halt-height' and '--halt-time'. During
the ABCI Commit phase, the node will check if the current block height is greater than or equal to
the halt-height or if the current block time is greater than or equal to the halt-time. If so, the
node will attempt to gracefully shutdown and the block will not be committed. In addition, the node
will not be able to commit subsequent blocks.
For profiling and benchmarking purposes, CPU profiling can be enabled via the '--cpu-profile' flag
which accepts a path for the resulting pprof file.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
// app pre run
if err := appPreRun(ctx, cmd); err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx.Logger.Info("Starting ABCI with Tendermint")
sub := subFunc(ctx.Logger)
log.SetSubscriber(sub)
setPID(ctx)
_, err := startInProcess(ctx, cdc, registry, appCreator, appStop, registerRoutesFn)
if err != nil {
tmos.Exit(err.Error())
}
return nil
},
}
RegisterServerFlags(cmd)
registerAppFlagFn(cmd)
// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
cmd.AddCommand(nodeModeCmd(ctx))
return cmd
}
func startInProcess(ctx *Context, cdc *codec.CodecProxy, registry jsonpb.AnyResolver, appCreator AppCreator, appStop AppStop,
registerRoutesFn func(restServer *lcd.RestServer)) (*node.Node, error) {
cfg := ctx.Config
home := cfg.RootDir
//startInProcess hooker
callHooker(FlagHookstartInProcess, ctx)
traceWriterFile := viper.GetString(flagTraceStore)
db, err := openDB(home)
if err != nil {
return nil, err
}
traceWriter, err := openTraceWriter(traceWriterFile)
if err != nil {
return nil, err
}
app := appCreator(ctx.Logger, db, traceWriter)
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return nil, err
}
// create & start tendermint node
tmNode, err := node.NewNode(
cfg,
pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()),
nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,
node.DefaultMetricsProvider(cfg.Instrumentation),
ctx.Logger.With("module", "node"),
)
if err != nil {
return nil, err
}
app.SetOption(abci.RequestSetOption{
Key: "CheckChainID",
Value: tmNode.ConsensusState().GetState().ChainID,
})
if clientSetter, ok := app.(interface {
SetTmClient(client client.Client)
}); ok {
clientSetter.SetTmClient(local.New(tmNode))
}
ctx.Logger.Info("startInProcess",
"ConsensusStateChainID", tmNode.ConsensusState().GetState().ChainID,
"GenesisDocChainID", tmNode.GenesisDoc().ChainID,
)
if err := tmNode.Start(); err != nil {
return nil, err
}
var cpuProfileCleanup func()
if cpuProfile := viper.GetString(flagCPUProfile); cpuProfile != "" {
f, err := os.Create(cpuProfile)
if err != nil {
return nil, err
}
ctx.Logger.Info("starting CPU profiler", "profile", cpuProfile)
if err := pprof.StartCPUProfile(f); err != nil {
return nil, err
}
cpuProfileCleanup = func() {
ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile)
pprof.StopCPUProfile()
f.Close()
}
}
TrapSignal(func() {
if tmNode.IsRunning() {
_ = tmNode.Stop()
}
appStop(app)
if cpuProfileCleanup != nil {
cpuProfileCleanup()
}
ctx.Logger.Info("exiting...")
})
if registerRoutesFn != nil {
go lcd.StartRestServer(cdc, registry, registerRoutesFn, tmNode, viper.GetString(FlagListenAddr))
}
baseapp.SetGlobalMempool(tmNode.Mempool(), cfg.Mempool.SortTxByGp, cfg.Mempool.EnablePendingPool)
if cfg.Mempool.EnablePendingPool {
cliCtx := context.NewCLIContext().WithProxy(cdc)
cliCtx.Client = local.New(tmNode)
cliCtx.TrustNode = true
accRetriever := types.NewAccountRetriever(cliCtx)
tmNode.Mempool().SetAccountRetriever(accRetriever)
}
if parser, ok := app.(mempool.TxInfoParser); ok {
tmNode.Mempool().SetTxInfoParser(parser)
}
// run forever (the node will not be returned)
select {}
}
func StartRestWithNode(ctx *Context, cdc *codec.CodecProxy, blockStoreDir string,
registry jsonpb.AnyResolver, appCreator AppCreator,
registerRoutesFn func(restServer *lcd.RestServer)) (*node.Node, error) {
cfg := ctx.Config
home := cfg.RootDir
////startInProcess hooker
//callHooker(FlagHookstartInProcess, ctx)
traceWriterFile := viper.GetString(flagTraceStore)
db, err := openDB(home)
if err != nil {
return nil, err
}
traceWriter, err := openTraceWriter(traceWriterFile)
if err != nil {
return nil, err
}
app := appCreator(ctx.Logger, db, traceWriter)
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return nil, err
}
// create & start tendermint node
tmNode, err := node.NewLRPNode(
cfg,
pvm.LoadFilePVEmptyState(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()),
nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,
blockStoreDir,
ctx.Logger.With("module", "node"),
)
if err != nil {
return nil, err
}
app.SetOption(abci.RequestSetOption{
Key: "CheckChainID",
Value: tmNode.ConsensusState().GetState().ChainID,
})
if registerRoutesFn != nil {
go lcd.StartRestServer(cdc, registry, registerRoutesFn, tmNode, viper.GetString(FlagListenAddr))
}
// run forever (the node will not be returned)
//select {}
return tmNode, nil
}
// Use SetExternalPackageValue to set external package config value.
func SetExternalPackageValue(cmd *cobra.Command) {
iavl.IavlCacheSize = viper.GetInt(iavl.FlagIavlCacheSize)
tmiavl.IavlCacheInitRatio = viper.GetFloat64(tmiavl.FlagIavlCacheInitRatio)
tmiavl.OutputModules, _ = cmd.Flags().GetStringToInt(tmiavl.FlagOutputModules)
tmiavl.CommitIntervalHeight = viper.GetInt64(tmiavl.FlagIavlCommitIntervalHeight)
tmiavl.MinCommitItemCount = viper.GetInt64(tmiavl.FlagIavlMinCommitItemCount)
tmiavl.HeightOrphansCacheSize = viper.GetInt(tmiavl.FlagIavlHeightOrphansCacheSize)
tmiavl.MaxCommittedHeightNum = viper.GetInt(tmiavl.FlagIavlMaxCommittedHeightNum)
tmiavl.EnableAsyncCommit = viper.GetBool(tmiavl.FlagIavlEnableAsyncCommit)
if viper.GetBool(tmiavl.FlagIavlDiscardFastStorage) {
tmiavl.SetEnableFastStorage(false)
}
system.EnableGid = viper.GetBool(system.FlagEnableGid)
state.ApplyBlockPprofTime = viper.GetInt(state.FlagApplyBlockPprofTime)
state.HomeDir = viper.GetString(cli.HomeFlag)
abci.SetDisableABCIQueryMutex(viper.GetBool(abci.FlagDisableABCIQueryMutex))
abci.SetDisableCheckTx(viper.GetBool(abci.FlagDisableCheckTx))
tmtypes.DownloadDelta = viper.GetBool(tmtypes.FlagDownloadDDS)
tmtypes.UploadDelta = viper.GetBool(tmtypes.FlagUploadDDS)
tmtypes.FastQuery = viper.GetBool(tmtypes.FlagFastQuery)
tmtypes.DeltaVersion = viper.GetInt(tmtypes.FlagDeltaVersion)
tmtypes.BlockCompressType = viper.GetInt(tmtypes.FlagBlockCompressType)
tmtypes.BlockCompressFlag = viper.GetInt(tmtypes.FlagBlockCompressFlag)
tmtypes.BlockCompressThreshold = viper.GetInt(tmtypes.FlagBlockCompressThreshold)
mpt.TrieCommitGap = viper.GetInt64(FlagCommitGapHeight)
bcv0.MaxIntervalForFastSync = viper.GetInt64(FlagFastSyncGap)
consensus.SetActiveVC(viper.GetBool(FlagActiveViewChange))
}