Skip to content

Commit 99d375e

Browse files
konradkonradulope
authored andcommitted
Change chain init roles
This changes the `validator` role to create a configuration for a network exposed validator. The previous setting, where `--role validator` set the parameters for an isolated validator behind a `sentry` mode can now be configured by using `--role isolated-validator`. This is now more in line with the setup used in https://github.com/shutter-network/snapshot-keyper which means less configuration changes are needed during the setup. It also allows for a simpler local docker compose test setup.
1 parent c888682 commit 99d375e

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

rolling-shutter/cmd/chain/init.go

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ import (
2323
"github.com/tendermint/tendermint/p2p"
2424
"github.com/tendermint/tendermint/privval"
2525
"github.com/tendermint/tendermint/types"
26+
"golang.org/x/exp/slices"
2627

2728
"github.com/shutter-network/rolling-shutter/rolling-shutter/app"
2829
)
2930

30-
const VALIDATOR = "validator"
31+
const (
32+
VALIDATOR = "validator"
33+
ISOLATEDVALIDATOR = "isolated-validator"
34+
SENTRY = "sentry"
35+
SEED = "seed"
36+
)
3137

3238
type Config struct {
3339
RootDir string `mapstructure:"root"`
@@ -65,7 +71,7 @@ func initCmd() *cobra.Command {
6571
cmd.PersistentFlags().Float64("blocktime", 1.0, "block time in seconds")
6672
cmd.PersistentFlags().StringSlice("genesis-keyper", nil, "genesis keyper address")
6773
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)")
6975
cmd.PersistentFlags().Uint64("initial-eon", 0, "initial eon")
7076
return cmd
7177
}
@@ -95,7 +101,7 @@ func getArgFromViper[T interface{}](getter func(string) T, name string, required
95101
func initFiles(_ *cobra.Command, config *Config, _ []string) error {
96102
keypers := []common.Address{}
97103

98-
if config.Role == VALIDATOR {
104+
if slices.Contains([]string{VALIDATOR, ISOLATEDVALIDATOR}, config.Role) {
99105
for _, a := range config.GenesisKeyper {
100106
if !common.IsHexAddress(a) {
101107
return errors.Errorf("--genesis-keyper argument '%s' is not an address", a)
@@ -133,13 +139,17 @@ func initFiles(_ *cobra.Command, config *Config, _ []string) error {
133139

134140
// set up according to the network role: https://docs.tendermint.com/v0.34/tendermint-core/validators.html
135141
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
137147
tendermintCfg.P2P.PexReactor = false
138148
tendermintCfg.P2P.AddrBookStrict = false
139-
case "sentry":
149+
case SENTRY: // even though "sentry" nodes are documented, there is no special mode
140150
tendermintCfg.P2P.PexReactor = true
141151
tendermintCfg.P2P.AddrBookStrict = false
142-
case "seed":
152+
case SEED:
143153
tendermintCfg.P2P.PexReactor = true
144154
tendermintCfg.P2P.AddrBookStrict = false
145155
default:
@@ -170,24 +180,25 @@ func adjustPort(address string, keyperIndex int) (string, error) {
170180

171181
func initFilesWithConfig(tendermintConfig *cfg.Config, config *Config, appState app.GenesisAppState) error {
172182
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+
}
191202

192203
validatorPubKeyPath := filepath.Join(tendermintConfig.RootDir, "config", "priv_validator_pubkey.hex")
193204
validatorPublicKeyHex := hex.EncodeToString(pv.Key.PubKey.Bytes())
@@ -227,7 +238,7 @@ func initFilesWithConfig(tendermintConfig *cfg.Config, config *Config, appState
227238
}
228239
log.Info().Str("path", genFile).Msg("Generated genesis file")
229240
}
230-
241+
231242
nodeKeyFile := tendermintConfig.NodeKeyFile()
232243
if tmos.FileExists(nodeKeyFile) {
233244
log.Info().Str("path", nodeKeyFile).Msg("Found node key")

rolling-shutter/docs/rolling-shutter_chain_init.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rolling-shutter chain init [flags]
1616
--index int keyper index
1717
--initial-eon uint initial eon
1818
--listen-address string tendermint RPC listen address (default "tcp://127.0.0.1:26657")
19-
--role string tendermint node role (validator, sentry, seed) (default "validator")
19+
--role string tendermint node role (validator, isolated-validator, sentry, seed) (default "validator")
2020
--root string root directory
2121
```
2222

rolling-shutter/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ require (
4242
go.opentelemetry.io/otel/trace v1.14.0
4343
go.opentelemetry.io/proto/otlp v0.19.0
4444
golang.org/x/crypto v0.12.0
45+
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
4546
golang.org/x/sync v0.3.0
4647
google.golang.org/protobuf v1.30.0
4748
gotest.tools v2.2.0+incompatible
@@ -215,7 +216,6 @@ require (
215216
go.uber.org/fx v1.20.0 // indirect
216217
go.uber.org/multierr v1.11.0 // indirect
217218
go.uber.org/zap v1.25.0 // indirect
218-
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
219219
golang.org/x/mod v0.12.0 // indirect
220220
golang.org/x/net v0.14.0 // indirect
221221
golang.org/x/sys v0.11.0 // indirect

0 commit comments

Comments
 (0)