-
Notifications
You must be signed in to change notification settings - Fork 179
/
start_okchain.go
193 lines (171 loc) · 5.47 KB
/
start_okchain.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
package server
import (
"bufio"
"errors"
"fmt"
"os"
"path/filepath"
"reflect"
"strconv"
"github.com/okex/exchain/libs/cosmos-sdk/client/flags"
cmn "github.com/okex/exchain/libs/tendermint/libs/os"
"github.com/spf13/cobra"
)
// exchain full-node start flags
const (
FlagListenAddr = "rest.laddr"
FlagUlockKey = "rest.unlock_key"
FlagUlockKeyHome = "rest.unlock_key_home"
FlagRestPathPrefix = "rest.path_prefix"
FlagCORS = "cors"
FlagMaxOpenConnections = "max-open"
FlagHookstartInProcess = "startInProcess"
FlagWebsocket = "wsport"
FlagWsMaxConnections = "ws.max_connections"
FlagWsSubChannelLength = "ws.sub_channel_length"
)
//module hook
type fnHookstartInProcess func(ctx *Context) error
type serverHookTable struct {
hookTable map[string]interface{}
}
var gSrvHookTable = serverHookTable{make(map[string]interface{})}
func InstallHookEx(flag string, hooker fnHookstartInProcess) {
gSrvHookTable.hookTable[flag] = hooker
}
//call hooker function
func callHooker(flag string, args ...interface{}) error {
params := make([]interface{}, 0)
switch flag {
case FlagHookstartInProcess:
{
//none hook func, return nil
function, ok := gSrvHookTable.hookTable[FlagHookstartInProcess]
if !ok {
return nil
}
params = append(params, args...)
if len(params) != 1 {
return errors.New("too many or less parameter called, want 1")
}
//param type check
p1, ok := params[0].(*Context)
if !ok {
return errors.New("wrong param 1 type. want *Context, got" + reflect.TypeOf(params[0]).String())
}
//get hook function and call it
caller := function.(fnHookstartInProcess)
return caller(p1)
}
default:
break
}
return nil
}
//end of hook
func setPID(ctx *Context) {
pid := os.Getpid()
f, err := os.OpenFile(filepath.Join(ctx.Config.RootDir, "config", "pid"), os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
cmn.Exit(err.Error())
}
defer f.Close()
writer := bufio.NewWriter(f)
_, err = writer.WriteString(strconv.Itoa(pid))
if err != nil {
fmt.Println(err.Error())
}
writer.Flush()
}
// StopCmd stop the node gracefully
// Tendermint.
func StopCmd(ctx *Context) *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop the node gracefully",
RunE: func(cmd *cobra.Command, args []string) error {
f, err := os.Open(filepath.Join(ctx.Config.RootDir, "config", "pid"))
if err != nil {
errStr := fmt.Sprintf("%s Please finish the process of exchaind through kill -2 pid to stop gracefully", err.Error())
cmn.Exit(errStr)
}
defer f.Close()
in := bufio.NewScanner(f)
in.Scan()
pid, err := strconv.Atoi(in.Text())
if err != nil {
errStr := fmt.Sprintf("%s Please finish the process of exchaind through kill -2 pid to stop gracefully", err.Error())
cmn.Exit(errStr)
}
process, err := os.FindProcess(pid)
if err != nil {
cmn.Exit(err.Error())
}
err = process.Signal(os.Interrupt)
if err != nil {
cmn.Exit(err.Error())
}
fmt.Println("pid", pid, "has been sent SIGINT")
return nil
},
}
return cmd
}
var sem *nodeSemaphore
type nodeSemaphore struct {
done chan struct{}
}
func Stop() {
sem.done <- struct{}{}
}
// registerRestServerFlags registers the flags required for rest server
func registerRestServerFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(FlagListenAddr, "tcp://0.0.0.0:26659", "EVM RPC and cosmos-sdk REST API listen address.")
cmd.Flags().String(FlagUlockKey, "", "Select the keys to unlock on the RPC server")
cmd.Flags().String(FlagUlockKeyHome, os.ExpandEnv("$HOME/.exchaincli"), "The keybase home path")
cmd.Flags().String(FlagRestPathPrefix, "exchain", "Path prefix for registering rest api route.")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)")
cmd.Flags().String(FlagCORS, "", "Set the rest-server domains that can make CORS requests (* for all)")
cmd.Flags().Int(FlagMaxOpenConnections, 1000, "The number of maximum open connections of rest-server")
cmd.Flags().String(FlagWebsocket, "8546", "websocket port to listen to")
cmd.Flags().Int(FlagWsMaxConnections, 20000, "the max capacity number of websocket client connections")
cmd.Flags().Int(FlagWsSubChannelLength, 100, "the length of subscription channel")
cmd.Flags().String(flags.FlagChainID, "", "Chain ID of tendermint node for web3")
cmd.Flags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block) for web3")
return cmd
}
func nodeModeCmd(ctx *Context) *cobra.Command {
cmd := &cobra.Command{
Use: "node-mode",
Short: "exchaind start --node-mode help info",
Long: `There are three node modes that can be set when the exchaind start
set --node-mode=rpc to manage the following flags:
--disable-checktx-mutex=true
--disable-query-mutex=true
--enable-bloom-filter=true
--fast-lru=10000
--fast-query=true
--iavl-enable-async-commit=true
--max-open=20000
--mempool.enable_pending_pool=true
--cors=*
set --node-mode=validator to manage the following flags:
--disable-checktx-mutex=true
--disable-query-mutex=true
--enable-dynamic-gp=false
--iavl-enable-async-commit=true
--iavl-cache-size=10000000
--pruning=everything
set --node-mode=archive to manage the following flags:
--pruning=nothing
--disable-checktx-mutex=true
--disable-query-mutex=true
--enable-bloom-filter=true
--iavl-enable-async-commit=true
--max-open=20000
--cors=*`,
Run: func(cmd *cobra.Command, args []string) {
},
}
return cmd
}