mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-13 03:24:28 +00:00
cmd: add support for --key (#5612)
Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user