Browse Source

cmd: add support for --key (#5612)

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
pull/5639/head
Marko 4 years ago
committed by GitHub
parent
commit
bf35cc6443
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 169 additions and 31 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +10
    -1
      cmd/tendermint/commands/gen_validator.go
  3. +24
    -2
      cmd/tendermint/commands/init.go
  4. +7
    -1
      cmd/tendermint/commands/reset_priv_validator.go
  5. +9
    -1
      cmd/tendermint/commands/testnet.go
  6. +8
    -2
      consensus/common_test.go
  7. +4
    -1
      consensus/wal_generator.go
  8. +6
    -1
      node/node.go
  9. +3
    -1
      node/node_test.go
  10. +17
    -6
      privval/file.go
  11. +14
    -7
      privval/file_test.go
  12. +2
    -1
      rpc/client/evidence_test.go
  13. +4
    -1
      rpc/test/helpers.go
  14. +5
    -1
      test/e2e/app/main.go
  15. +3
    -0
      test/e2e/generator/generate.go
  16. +1
    -0
      test/e2e/networks/single.toml
  17. +4
    -0
      test/e2e/pkg/manifest.go
  18. +22
    -4
      test/e2e/pkg/testnet.go
  19. +7
    -0
      test/e2e/runner/setup.go
  20. +4
    -1
      test/maverick/consensus/wal_generator.go
  21. +13
    -0
      test/maverick/main.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -24,6 +24,8 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
### IMPROVEMENTS
- [privval] \#5603 Add `--key` to `init`, `gen_validator`, `testnet` & `unsafe_reset_priv_validator` for use in generating `secp256k1` keys.
### BUG FIXES
- [types] \#5523 Change json naming of `PartSetHeader` within `BlockID` from `parts` to `part_set_header` (@marbar3778)

+ 10
- 1
cmd/tendermint/commands/gen_validator.go View File

@ -7,6 +7,7 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types"
)
// GenValidatorCmd allows the generation of a keypair for a
@ -17,8 +18,16 @@ var GenValidatorCmd = &cobra.Command{
Run: genValidator,
}
func init() {
GenValidatorCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
func genValidator(cmd *cobra.Command, args []string) {
pv := privval.GenFilePV("", "")
pv, err := privval.GenFilePV("", "", keyType)
if err != nil {
panic(err)
}
jsbz, err := tmjson.Marshal(pv)
if err != nil {
panic(err)


+ 24
- 2
cmd/tendermint/commands/init.go View File

@ -10,6 +10,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -21,6 +22,15 @@ var InitFilesCmd = &cobra.Command{
RunE: initFiles,
}
var (
keyType string
)
func init() {
InitFilesCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
func initFiles(cmd *cobra.Command, args []string) error {
return initFilesWithConfig(config)
}
@ -29,13 +39,19 @@ func initFilesWithConfig(config *cfg.Config) error {
// private validator
privValKeyFile := config.PrivValidatorKeyFile()
privValStateFile := config.PrivValidatorStateFile()
var pv *privval.FilePV
var (
pv *privval.FilePV
err error
)
if tmos.FileExists(privValKeyFile) {
pv = privval.LoadFilePV(privValKeyFile, privValStateFile)
logger.Info("Found private validator", "keyFile", privValKeyFile,
"stateFile", privValStateFile)
} else {
pv = privval.GenFilePV(privValKeyFile, privValStateFile)
pv, err = privval.GenFilePV(privValKeyFile, privValStateFile, keyType)
if err != nil {
return err
}
pv.Save()
logger.Info("Generated private validator", "keyFile", privValKeyFile,
"stateFile", privValStateFile)
@ -56,11 +72,17 @@ func initFilesWithConfig(config *cfg.Config) error {
if tmos.FileExists(genFile) {
logger.Info("Found genesis file", "path", genFile)
} else {
genDoc := types.GenesisDoc{
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
GenesisTime: tmtime.Now(),
ConsensusParams: types.DefaultConsensusParams(),
}
if keyType == "secp256k1" {
genDoc.ConsensusParams.Validator = tmproto.ValidatorParams{
PubKeyTypes: []string{types.ABCIPubKeyTypeSecp256k1},
}
}
pubKey, err := pv.GetPubKey()
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)


+ 7
- 1
cmd/tendermint/commands/reset_priv_validator.go View File

@ -8,6 +8,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types"
)
// ResetAllCmd removes the database of this Tendermint core
@ -22,6 +23,8 @@ var keepAddrBook bool
func init() {
ResetAllCmd.Flags().BoolVar(&keepAddrBook, "keep-addr-book", false, "keep the address book intact")
ResetPrivValidatorCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
// ResetPrivValidatorCmd resets the private validator files.
@ -71,7 +74,10 @@ func resetFilePV(privValKeyFile, privValStateFile string, logger log.Logger) {
logger.Info("Reset private validator file to genesis state", "keyFile", privValKeyFile,
"stateFile", privValStateFile)
} else {
pv := privval.GenFilePV(privValKeyFile, privValStateFile)
pv, err := privval.GenFilePV(privValKeyFile, privValStateFile, keyType)
if err != nil {
panic(err)
}
pv.Save()
logger.Info("Generated private validator file", "keyFile", privValKeyFile,
"stateFile", privValStateFile)


+ 9
- 1
cmd/tendermint/commands/testnet.go View File

@ -15,6 +15,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -74,6 +75,8 @@ func init() {
"P2P Port")
TestnetFilesCmd.Flags().BoolVar(&randomMonikers, "random-monikers", false,
"randomize the moniker for each generated node")
TestnetFilesCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
// TestnetFilesCmd allows initialisation of files for a Tendermint testnet.
@ -180,10 +183,15 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
// Generate genesis doc from generated validators
genDoc := &types.GenesisDoc{
ChainID: "chain-" + tmrand.Str(6),
ConsensusParams: types.DefaultConsensusParams(),
GenesisTime: tmtime.Now(),
InitialHeight: initialHeight,
Validators: genVals,
ConsensusParams: types.DefaultConsensusParams(),
}
if keyType == "secp256k1" {
genDoc.ConsensusParams.Validator = tmproto.ValidatorParams{
PubKeyTypes: []string{types.ABCIPubKeyTypeSecp256k1},
}
}
// Write genesis file.


+ 8
- 2
consensus/common_test.go View File

@ -414,7 +414,10 @@ func loadPrivValidator(config *cfg.Config) *privval.FilePV {
privValidatorKeyFile := config.PrivValidatorKeyFile()
ensureDir(filepath.Dir(privValidatorKeyFile), 0700)
privValidatorStateFile := config.PrivValidatorStateFile()
privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
privValidator, err := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
if err != nil {
panic(err)
}
privValidator.Reset()
return privValidator
}
@ -739,7 +742,10 @@ func randConsensusNetWithPeers(
panic(err)
}
privVal = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
if err != nil {
panic(err)
}
}
app := appFunc(path.Join(config.DBDir(), fmt.Sprintf("%s_%d", testName, i)))


+ 4
- 1
consensus/wal_generator.go View File

@ -40,7 +40,10 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
// NOTE: we don't do handshake so need to set state.Version.Consensus.App directly.
privValidatorKeyFile := config.PrivValidatorKeyFile()
privValidatorStateFile := config.PrivValidatorStateFile()
privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
privValidator, err := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
if err != nil {
return err
}
genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
if err != nil {
return fmt.Errorf("failed to read genesis file: %w", err)


+ 6
- 1
node/node.go View File

@ -92,8 +92,13 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
return nil, fmt.Errorf("failed to load or gen node key %s: %w", config.NodeKeyFile(), err)
}
pval, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
if err != nil {
return nil, err
}
return NewNode(config,
privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()),
pval,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config),


+ 3
- 1
node/node_test.go View File

@ -384,9 +384,11 @@ func TestNodeNewNodeCustomReactors(t *testing.T) {
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
require.NoError(t, err)
pval, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
require.NoError(t, err)
n, err := NewNode(config,
privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()),
pval,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config),


+ 17
- 6
privval/file.go View File

@ -11,6 +11,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"
@ -170,8 +171,15 @@ func NewFilePV(privKey crypto.PrivKey, keyFilePath, stateFilePath string) *FileP
// GenFilePV generates a new validator with randomly generated private key
// and sets the filePaths, but does not call Save().
func GenFilePV(keyFilePath, stateFilePath string) *FilePV {
return NewFilePV(ed25519.GenPrivKey(), keyFilePath, stateFilePath)
func GenFilePV(keyFilePath, stateFilePath, keyType string) (*FilePV, error) {
switch keyType {
case types.ABCIPubKeyTypeSecp256k1:
return NewFilePV(secp256k1.GenPrivKey(), keyFilePath, stateFilePath), nil
case "", types.ABCIPubKeyTypeEd25519:
return NewFilePV(ed25519.GenPrivKey(), keyFilePath, stateFilePath), nil
default:
return nil, fmt.Errorf("key type: %s is not supported", keyType)
}
}
// LoadFilePV loads a FilePV from the filePaths. The FilePV handles double
@ -227,15 +235,18 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV {
// LoadOrGenFilePV loads a FilePV from the given filePaths
// or else generates a new one and saves it to the filePaths.
func LoadOrGenFilePV(keyFilePath, stateFilePath string) *FilePV {
var pv *FilePV
func LoadOrGenFilePV(keyFilePath, stateFilePath string) (*FilePV, error) {
var (
pv *FilePV
err error
)
if tmos.FileExists(keyFilePath) {
pv = LoadFilePV(keyFilePath, stateFilePath)
} else {
pv = GenFilePV(keyFilePath, stateFilePath)
pv, err = GenFilePV(keyFilePath, stateFilePath, "")
pv.Save()
}
return pv
return pv, err
}
// GetAddress returns the address of the validator.


+ 14
- 7
privval/file_test.go View File

@ -28,7 +28,8 @@ func TestGenLoadValidator(t *testing.T) {
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
require.NoError(t, err)
height := int64(100)
privVal.LastSignState.Height = height
@ -46,7 +47,8 @@ func TestResetValidator(t *testing.T) {
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
require.NoError(t, err)
emptyState := FilePVLastSignState{filePath: tempStateFile.Name()}
// new priv val has empty state
@ -86,9 +88,11 @@ func TestLoadOrGenValidator(t *testing.T) {
t.Error(err)
}
privVal := LoadOrGenFilePV(tempKeyFilePath, tempStateFilePath)
privVal, err := LoadOrGenFilePV(tempKeyFilePath, tempStateFilePath)
require.NoError(t, err)
addr := privVal.GetAddress()
privVal = LoadOrGenFilePV(tempKeyFilePath, tempStateFilePath)
privVal, err = LoadOrGenFilePV(tempKeyFilePath, tempStateFilePath)
require.NoError(t, err)
assert.Equal(addr, privVal.GetAddress(), "expected privval addr to be the same")
}
@ -164,7 +168,8 @@ func TestSignVote(t *testing.T) {
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
require.NoError(t, err)
randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)
@ -217,7 +222,8 @@ func TestSignProposal(t *testing.T) {
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
require.NoError(t, err)
randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)
@ -265,7 +271,8 @@ func TestDifferByTimestamp(t *testing.T) {
tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
privVal, err := GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), "")
require.NoError(t, err)
randbytes := tmrand.Bytes(tmhash.Size)
block1 := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{Total: 5, Hash: randbytes}}
height, round := int64(10), int32(1)


+ 2
- 1
rpc/client/evidence_test.go View File

@ -116,8 +116,9 @@ func TestBroadcastEvidence_DuplicateVoteEvidence(t *testing.T) {
var (
config = rpctest.GetConfig()
chainID = config.ChainID()
pv = privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
)
pv, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
require.NoError(t, err)
for i, c := range GetClients() {
correct, fakes := makeEvidences(t, pv, chainID)


+ 4
- 1
rpc/test/helpers.go View File

@ -161,7 +161,10 @@ func NewTendermint(app abci.Application, opts *Options) *nm.Node {
}
pvKeyFile := config.PrivValidatorKeyFile()
pvKeyStateFile := config.PrivValidatorStateFile()
pv := privval.LoadOrGenFilePV(pvKeyFile, pvKeyStateFile)
pv, err := privval.LoadOrGenFilePV(pvKeyFile, pvKeyStateFile)
if err != nil {
panic(err)
}
papp := proxy.NewLocalClientCreator(app)
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
if err != nil {


+ 5
- 1
test/e2e/app/main.go View File

@ -115,8 +115,12 @@ func startNode(cfg *Config) error {
return fmt.Errorf("failed to setup config: %w", err)
}
pval, err := privval.LoadOrGenFilePV(tmcfg.PrivValidatorKeyFile(), tmcfg.PrivValidatorStateFile())
if err != nil {
return err
}
n, err := node.NewNode(tmcfg,
privval.LoadOrGenFilePV(tmcfg.PrivValidatorKeyFile(), tmcfg.PrivValidatorStateFile()),
pval,
nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(tmcfg),


+ 3
- 0
test/e2e/generator/generate.go View File

@ -8,6 +8,7 @@ import (
"strings"
e2e "github.com/tendermint/tendermint/test/e2e/pkg"
"github.com/tendermint/tendermint/types"
)
var (
@ -22,6 +23,7 @@ var (
map[string]string{"initial01": "a", "initial02": "b", "initial03": "c"},
},
"validators": {"genesis", "initchain"},
"keyType": {types.ABCIPubKeyTypeEd25519, types.ABCIPubKeyTypeSecp256k1},
}
// The following specify randomly chosen values for testnet nodes.
@ -74,6 +76,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
Validators: &map[string]int64{},
ValidatorUpdates: map[string]map[string]int64{},
Nodes: map[string]*e2e.ManifestNode{},
KeyType: opt["keyType"].(string),
}
var numSeeds, numValidators, numFulls int


+ 1
- 0
test/e2e/networks/single.toml View File

@ -1 +1,2 @@
[node.validator]

+ 4
- 0
test/e2e/pkg/manifest.go View File

@ -46,6 +46,10 @@ type Manifest struct {
// Nodes specifies the network nodes. At least one node must be given.
Nodes map[string]*ManifestNode `toml:"node"`
// KeyType sets the curve that will be used by validators.
// Options are ed25519 & secp256k1
KeyType string `toml:"key_type"`
}
// ManifestNode represents a node in a testnet manifest.


+ 22
- 4
test/e2e/pkg/testnet.go View File

@ -14,8 +14,10 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
mcs "github.com/tendermint/tendermint/test/maverick/consensus"
"github.com/tendermint/tendermint/types"
)
const (
@ -57,6 +59,7 @@ type Testnet struct {
Validators map[*Node]int64
ValidatorUpdates map[int64]map[*Node]int64
Nodes []*Node
KeyType string
}
// Node represents a Tendermint node in a testnet.
@ -118,6 +121,10 @@ func LoadTestnet(file string) (*Testnet, error) {
Validators: map[*Node]int64{},
ValidatorUpdates: map[int64]map[*Node]int64{},
Nodes: []*Node{},
KeyType: "ed25519",
}
if len(manifest.KeyType) != 0 {
testnet.KeyType = manifest.KeyType
}
if manifest.InitialHeight > 0 {
testnet.InitialHeight = manifest.InitialHeight
@ -135,7 +142,7 @@ func LoadTestnet(file string) (*Testnet, error) {
node := &Node{
Name: name,
Testnet: testnet,
Key: keyGen.Generate(),
Key: keyGen.Generate(manifest.KeyType),
IP: ipGen.Next(),
ProxyPort: proxyPortGen.Next(),
Mode: ModeValidator,
@ -263,6 +270,11 @@ func (t Testnet) Validate() error {
if len(t.Nodes) == 0 {
return errors.New("network has no nodes")
}
switch t.KeyType {
case "", types.ABCIPubKeyTypeEd25519, types.ABCIPubKeyTypeSecp256k1:
default:
return errors.New("unsupported KeyType")
}
for _, node := range t.Nodes {
if err := node.Validate(t); err != nil {
return fmt.Errorf("invalid node %q: %w", node.Name, err)
@ -466,15 +478,21 @@ func newKeyGenerator(seed int64) *keyGenerator {
}
}
func (g *keyGenerator) Generate() crypto.PrivKey {
func (g *keyGenerator) Generate(keyType string) crypto.PrivKey {
seed := make([]byte, ed25519.SeedSize)
_, err := io.ReadFull(g.random, seed)
if err != nil {
panic(err) // this shouldn't happen
}
return ed25519.GenPrivKeyFromSecret(seed)
switch keyType {
case "secp256k1":
return secp256k1.GenPrivKeySecp256k1(seed)
case "", "ed25519":
return ed25519.GenPrivKeyFromSecret(seed)
default:
panic("KeyType not supported") // should not make it this far
}
}
// portGenerator generates local Docker proxy ports for each node.


+ 7
- 0
test/e2e/runner/setup.go View File

@ -191,6 +191,13 @@ func MakeGenesis(testnet *e2e.Testnet) (types.GenesisDoc, error) {
ConsensusParams: types.DefaultConsensusParams(),
InitialHeight: testnet.InitialHeight,
}
switch testnet.KeyType {
case "", types.ABCIPubKeyTypeEd25519, types.ABCIPubKeyTypeSecp256k1:
genesis.ConsensusParams.Validator.PubKeyTypes =
append(genesis.ConsensusParams.Validator.PubKeyTypes, types.ABCIPubKeyTypeSecp256k1)
default:
return genesis, errors.New("unsupported KeyType")
}
for validator, power := range testnet.Validators {
genesis.Validators = append(genesis.Validators, types.GenesisValidator{
Name: validator.Name,


+ 4
- 1
test/maverick/consensus/wal_generator.go View File

@ -41,7 +41,10 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
// NOTE: we don't do handshake so need to set state.Version.Consensus.App directly.
privValidatorKeyFile := config.PrivValidatorKeyFile()
privValidatorStateFile := config.PrivValidatorStateFile()
privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
privValidator, err := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
if err != nil {
return err
}
genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
if err != nil {
return fmt.Errorf("failed to read genesis file: %w", err)


+ 13
- 0
test/maverick/main.go View File

@ -17,6 +17,7 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
cs "github.com/tendermint/tendermint/test/maverick/consensus"
nd "github.com/tendermint/tendermint/test/maverick/node"
"github.com/tendermint/tendermint/types"
@ -156,12 +157,19 @@ func startNode(config *cfg.Config, logger log.Logger, misbehaviorFlag string) er
select {}
}
var keyType string
var InitFilesCmd = &cobra.Command{
Use: "init",
Short: "Initialize Tendermint",
RunE: initFiles,
}
func init() {
InitFilesCmd.Flags().StringVar(&keyType, "key", types.ABCIPubKeyTypeEd25519,
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
func initFiles(cmd *cobra.Command, args []string) error {
return initFilesWithConfig(config)
}
@ -202,6 +210,11 @@ func initFilesWithConfig(config *cfg.Config) error {
GenesisTime: tmtime.Now(),
ConsensusParams: types.DefaultConsensusParams(),
}
if keyType == "secp256k1" {
genDoc.ConsensusParams.Validator = tmproto.ValidatorParams{
PubKeyTypes: []string{types.ABCIPubKeyTypeSecp256k1},
}
}
pubKey, err := pv.GetPubKey()
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)


Loading…
Cancel
Save