@@ -3,7 +3,6 @@ package chain
3
3
// This has been copied from tendermint's own init command
4
4
5
5
import (
6
- "context"
7
6
"encoding/hex"
8
7
"fmt"
9
8
"os"
@@ -19,10 +18,9 @@ import (
19
18
"github.com/spf13/viper"
20
19
"github.com/tendermint/go-amino"
21
20
cfg "github.com/tendermint/tendermint/config"
22
- tmlog "github.com/tendermint/tendermint/libs/log"
23
21
tmos "github.com/tendermint/tendermint/libs/os"
24
22
tmrand "github.com/tendermint/tendermint/libs/rand"
25
- tmtime "github.com/tendermint/tendermint/libs/time "
23
+ "github.com/tendermint/tendermint/p2p "
26
24
"github.com/tendermint/tendermint/privval"
27
25
"github.com/tendermint/tendermint/types"
28
26
@@ -107,7 +105,7 @@ func initFiles(_ *cobra.Command, config *Config, _ []string) error {
107
105
}
108
106
109
107
tendermintCfg := cfg .DefaultConfig ()
110
- tendermintCfg .LogLevel = tmlog . LogLevelError
108
+ tendermintCfg .BaseConfig . LogLevel = "error"
111
109
tendermintCfg .RPC .ListenAddress = config .ListenAddress
112
110
113
111
scaleToBlockTime (tendermintCfg , config .BlockTime )
@@ -126,7 +124,6 @@ func initFiles(_ *cobra.Command, config *Config, _ []string) error {
126
124
tendermintCfg .P2P .ListenAddress = p2pAddress
127
125
128
126
tendermintCfg .P2P .AllowDuplicateIP = true
129
- tendermintCfg .Mode = cfg .ModeValidator
130
127
131
128
tendermintCfg .SetRoot (config .RootDir )
132
129
if err := tendermintCfg .ValidateBasic (); err != nil {
@@ -138,25 +135,19 @@ func initFiles(_ *cobra.Command, config *Config, _ []string) error {
138
135
switch config .Role {
139
136
case VALIDATOR :
140
137
tendermintCfg .P2P .PexReactor = false
141
- tendermintCfg .Mode = cfg .ModeValidator
142
138
tendermintCfg .P2P .AddrBookStrict = false
143
- case "sentry" : // even though "sentry" nodes are documented, there is no special mode
139
+ case "sentry" :
144
140
tendermintCfg .P2P .PexReactor = true
145
- tendermintCfg .Mode = cfg .ModeFull
146
141
tendermintCfg .P2P .AddrBookStrict = false
147
142
case "seed" :
148
143
tendermintCfg .P2P .PexReactor = true
149
- tendermintCfg .Mode = cfg .ModeSeed
150
144
tendermintCfg .P2P .AddrBookStrict = false
151
145
default :
152
146
return errors .Errorf ("illegal value for --role: %s" , config .Role )
153
147
}
154
148
// EnsureRoot also write the config file but with the default config. We want our own, so
155
149
// let's overwrite it.
156
- err = cfg .WriteConfigFile (config .RootDir , tendermintCfg )
157
- if err != nil {
158
- return err
159
- }
150
+ cfg .WriteConfigFile (config .RootDir + "/config/config.toml" , tendermintCfg )
160
151
appState := app .NewGenesisAppState (keypers , (2 * len (keypers )+ 2 )/ 3 , config .InitialEon )
161
152
162
153
return initFilesWithConfig (tendermintCfg , config , appState )
@@ -179,80 +170,73 @@ func adjustPort(address string, keyperIndex int) (string, error) {
179
170
180
171
func initFilesWithConfig (tendermintConfig * cfg.Config , config * Config , appState app.GenesisAppState ) error {
181
172
var err error
182
- if config .Role == VALIDATOR {
183
- // private validator
184
- privValKeyFile := tendermintConfig .PrivValidator .KeyFile ()
185
- privValStateFile := tendermintConfig .PrivValidator .StateFile ()
186
- var pv * privval.FilePV
187
- if tmos .FileExists (privValKeyFile ) {
188
- pv , err = privval .LoadFilePV (privValKeyFile , privValStateFile )
189
- if err != nil {
190
- return err
191
- }
192
- log .Info ().
193
- Str ("privValKeyFile" , privValKeyFile ).
194
- Str ("stateFile" , privValStateFile ).
195
- Msg ("Found private validator" )
196
- } else {
197
- pv , err = privval .GenFilePV (privValKeyFile , privValStateFile , types .ABCIPubKeyTypeEd25519 )
198
- if err != nil {
199
- return err
200
- }
201
- pv .Save ()
202
- log .Info ().
203
- Str ("privValKeyFile" , privValKeyFile ).
204
- Str ("stateFile" , privValStateFile ).
205
- Msg ("Generated private validator" )
206
- }
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
+ }
191
+
192
+ validatorPubKeyPath := filepath .Join (tendermintConfig .RootDir , "config" , "priv_validator_pubkey.hex" )
193
+ validatorPublicKeyHex := hex .EncodeToString (pv .Key .PubKey .Bytes ())
194
+ err = os .WriteFile (validatorPubKeyPath , []byte (validatorPublicKeyHex ), 0o644 )
195
+ if err != nil {
196
+ return errors .Wrapf (err , "Could not write to %s" , validatorPubKeyPath )
197
+ }
198
+ log .Info ().Str ("path" , validatorPubKeyPath ).Str ("validatorPublicKey" , validatorPublicKeyHex ).Msg ("Saved private validator publickey" )
207
199
208
- validatorPubKeyPath := filepath .Join (tendermintConfig .RootDir , "config" , "priv_validator_pubkey.hex" )
209
- validatorPublicKeyHex := hex .EncodeToString (pv .Key .PubKey .Bytes ())
210
- err = os .WriteFile (validatorPubKeyPath , []byte (validatorPublicKeyHex ), 0o644 )
200
+ // genesis file
201
+ genFile := tendermintConfig .GenesisFile ()
202
+ if tmos .FileExists (genFile ) {
203
+ log .Info ().Str ("path" , genFile ).Msg ("Found genesis file" )
204
+ } else {
205
+ appStateBytes , err := amino .NewCodec ().MarshalJSONIndent (appState , "" , " " )
211
206
if err != nil {
212
- return errors . Wrapf ( err , "Could not write to %s" , validatorPubKeyPath )
207
+ return err
213
208
}
214
- log .Info ().Str ("path" , validatorPubKeyPath ).Str ("validatorPublicKey" , validatorPublicKeyHex ).Msg ("Saved private validator publickey" )
215
-
216
- // genesis file
217
- genFile := tendermintConfig .GenesisFile ()
218
- if tmos .FileExists (genFile ) {
219
- log .Info ().Str ("path" , genFile ).Msg ("Found genesis file" )
220
- } else {
221
- appStateBytes , err := amino .NewCodec ().MarshalJSONIndent (appState , "" , " " )
222
- if err != nil {
223
- return err
224
- }
225
- genDoc := types.GenesisDoc {
226
- ChainID : fmt .Sprintf ("shutter-test-chain-%v" , tmrand .Str (6 )),
227
- GenesisTime : tmtime .Now (),
228
- ConsensusParams : types .DefaultConsensusParams (),
229
- AppState : appStateBytes ,
230
- }
231
- pubKey , err := pv .GetPubKey (context .Background ())
232
- if err != nil {
233
- return errors .Wrap (err , "can't get pubkey" )
234
- }
235
- genDoc .Validators = []types.GenesisValidator {{
236
- Address : pubKey .Address (),
237
- PubKey : pubKey ,
238
- Power : 10 ,
239
- }}
209
+ genDoc := types.GenesisDoc {
210
+ ChainID : fmt .Sprintf ("shutter-test-chain-%v" , tmrand .Str (6 )),
211
+ GenesisTime : time .Now (),
212
+ ConsensusParams : types .DefaultConsensusParams (),
213
+ AppState : appStateBytes ,
214
+ }
215
+ pubKey , err := pv .GetPubKey ()
216
+ if err != nil {
217
+ return errors .Wrap (err , "can't get pubkey" )
218
+ }
219
+ genDoc .Validators = []types.GenesisValidator {{
220
+ Address : pubKey .Address (),
221
+ PubKey : pubKey ,
222
+ Power : 10 ,
223
+ }}
240
224
241
- if err := genDoc .SaveAs (genFile ); err != nil {
242
- return err
243
- }
244
- log .Info ().Str ("path" , genFile ).Msg ("Generated genesis file" )
225
+ if err := genDoc .SaveAs (genFile ); err != nil {
226
+ return err
245
227
}
228
+ log .Info ().Str ("path" , genFile ).Msg ("Generated genesis file" )
246
229
}
247
230
248
231
nodeKeyFile := tendermintConfig .NodeKeyFile ()
249
232
if tmos .FileExists (nodeKeyFile ) {
250
233
log .Info ().Str ("path" , nodeKeyFile ).Msg ("Found node key" )
251
234
} else {
252
- nodeid , err := tendermintConfig . LoadOrGenNodeKeyID ( )
235
+ nodeKey , err := p2p . LoadOrGenNodeKey ( nodeKeyFile )
253
236
if err != nil {
254
237
return err
255
238
}
239
+ nodeid := nodeKey .ID ()
256
240
idpath := nodeKeyFile + ".id"
257
241
err = os .WriteFile (idpath , []byte (nodeid ), 0o644 )
258
242
if err != nil {
0 commit comments