@@ -23,11 +23,17 @@ import (
23
23
"github.com/tendermint/tendermint/p2p"
24
24
"github.com/tendermint/tendermint/privval"
25
25
"github.com/tendermint/tendermint/types"
26
+ "golang.org/x/exp/slices"
26
27
27
28
"github.com/shutter-network/rolling-shutter/rolling-shutter/app"
28
29
)
29
30
30
- const VALIDATOR = "validator"
31
+ const (
32
+ VALIDATOR = "validator"
33
+ ISOLATEDVALIDATOR = "isolated-validator"
34
+ SENTRY = "sentry"
35
+ SEED = "seed"
36
+ )
31
37
32
38
type Config struct {
33
39
RootDir string `mapstructure:"root"`
@@ -65,7 +71,7 @@ func initCmd() *cobra.Command {
65
71
cmd .PersistentFlags ().Float64 ("blocktime" , 1.0 , "block time in seconds" )
66
72
cmd .PersistentFlags ().StringSlice ("genesis-keyper" , nil , "genesis keyper address" )
67
73
cmd .PersistentFlags ().String ("listen-address" , "tcp://127.0.0.1:26657" , "tendermint RPC listen address" )
68
- cmd .PersistentFlags ().String ("role" , "validator" , "tendermint node role (validator, sentry, seed)" )
74
+ cmd .PersistentFlags ().String ("role" , "validator" , "tendermint node role (validator, isolated-validator, sentry, seed)" )
69
75
cmd .PersistentFlags ().Uint64 ("initial-eon" , 0 , "initial eon" )
70
76
return cmd
71
77
}
@@ -95,7 +101,7 @@ func getArgFromViper[T interface{}](getter func(string) T, name string, required
95
101
func initFiles (_ * cobra.Command , config * Config , _ []string ) error {
96
102
keypers := []common.Address {}
97
103
98
- if config . Role == VALIDATOR {
104
+ if slices . Contains ([] string { VALIDATOR , ISOLATEDVALIDATOR }, config . Role ) {
99
105
for _ , a := range config .GenesisKeyper {
100
106
if ! common .IsHexAddress (a ) {
101
107
return errors .Errorf ("--genesis-keyper argument '%s' is not an address" , a )
@@ -133,13 +139,17 @@ func initFiles(_ *cobra.Command, config *Config, _ []string) error {
133
139
134
140
// set up according to the network role: https://docs.tendermint.com/v0.34/tendermint-core/validators.html
135
141
switch config .Role {
136
- case VALIDATOR :
142
+ case VALIDATOR : // standard validator mode, network exposed
143
+ tendermintCfg .P2P .PexReactor = true
144
+ tendermintCfg .Mode = cfg .ModeValidator
145
+ tendermintCfg .P2P .AddrBookStrict = true
146
+ case ISOLATEDVALIDATOR : // validator mode behind a sentry node
137
147
tendermintCfg .P2P .PexReactor = false
138
148
tendermintCfg .P2P .AddrBookStrict = false
139
- case "sentry" :
149
+ case SENTRY : // even though "sentry" nodes are documented, there is no special mode
140
150
tendermintCfg .P2P .PexReactor = true
141
151
tendermintCfg .P2P .AddrBookStrict = false
142
- case "seed" :
152
+ case SEED :
143
153
tendermintCfg .P2P .PexReactor = true
144
154
tendermintCfg .P2P .AddrBookStrict = false
145
155
default :
@@ -170,24 +180,25 @@ func adjustPort(address string, keyperIndex int) (string, error) {
170
180
171
181
func initFilesWithConfig (tendermintConfig * cfg.Config , config * Config , appState app.GenesisAppState ) error {
172
182
var err error
173
- // private validator
174
- privValKeyFile := tendermintConfig .PrivValidatorKeyFile ()
175
- privValStateFile := tendermintConfig .PrivValidatorStateFile ()
176
- var pv * privval.FilePV
177
- if tmos .FileExists (privValKeyFile ) {
178
- pv = privval .LoadFilePV (privValKeyFile , privValStateFile )
179
- log .Info ().
180
- Str ("privValKeyFile" , privValKeyFile ).
181
- Str ("stateFile" , privValStateFile ).
182
- Msg ("Found private validator" )
183
- } else {
184
- pv = privval .GenFilePV (privValKeyFile , privValStateFile )
185
- pv .Save ()
186
- log .Info ().
187
- Str ("privValKeyFile" , privValKeyFile ).
188
- Str ("stateFile" , privValStateFile ).
189
- Msg ("Generated private validator" )
190
- }
183
+ if slices .Contains ([]string {VALIDATOR , ISOLATEDVALIDATOR }, config .Role ) {
184
+ // private validator
185
+ privValKeyFile := tendermintConfig .PrivValidatorKeyFile ()
186
+ privValStateFile := tendermintConfig .PrivValidatorStateFile ()
187
+ var pv * privval.FilePV
188
+ if tmos .FileExists (privValKeyFile ) {
189
+ pv = privval .LoadFilePV (privValKeyFile , privValStateFile )
190
+ log .Info ().
191
+ Str ("privValKeyFile" , privValKeyFile ).
192
+ Str ("stateFile" , privValStateFile ).
193
+ Msg ("Found private validator" )
194
+ } else {
195
+ pv = privval .GenFilePV (privValKeyFile , privValStateFile )
196
+ pv .Save ()
197
+ log .Info ().
198
+ Str ("privValKeyFile" , privValKeyFile ).
199
+ Str ("stateFile" , privValStateFile ).
200
+ Msg ("Generated private validator" )
201
+ }
191
202
192
203
validatorPubKeyPath := filepath .Join (tendermintConfig .RootDir , "config" , "priv_validator_pubkey.hex" )
193
204
validatorPublicKeyHex := hex .EncodeToString (pv .Key .PubKey .Bytes ())
@@ -227,7 +238,7 @@ func initFilesWithConfig(tendermintConfig *cfg.Config, config *Config, appState
227
238
}
228
239
log .Info ().Str ("path" , genFile ).Msg ("Generated genesis file" )
229
240
}
230
-
241
+
231
242
nodeKeyFile := tendermintConfig .NodeKeyFile ()
232
243
if tmos .FileExists (nodeKeyFile ) {
233
244
log .Info ().Str ("path" , nodeKeyFile ).Msg ("Found node key" )
0 commit comments