mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
test/e2e: fix secp failures (#5649)
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
func RandVal(i int) types.ValidatorUpdate {
|
func RandVal(i int) types.ValidatorUpdate {
|
||||||
pubkey := tmrand.Bytes(32)
|
pubkey := tmrand.Bytes(32)
|
||||||
power := tmrand.Uint16() + 1
|
power := tmrand.Uint16() + 1
|
||||||
v := types.Ed25519ValidatorUpdate(pubkey, int64(power))
|
v := types.UpdateValidator(pubkey, int64(power), "")
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update
|
// update
|
||||||
return app.updateValidator(types.Ed25519ValidatorUpdate(pubkey, power))
|
return app.updateValidator(types.UpdateValidator(pubkey, power, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add, update, or remove a validator
|
// add, update, or remove a validator
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func InitChain(client abcicli.Client) error {
|
|||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
pubkey := tmrand.Bytes(33)
|
pubkey := tmrand.Bytes(33)
|
||||||
power := tmrand.Int()
|
power := tmrand.Int()
|
||||||
vals[i] = types.Ed25519ValidatorUpdate(pubkey, int64(power))
|
vals[i] = types.UpdateValidator(pubkey, int64(power), "")
|
||||||
}
|
}
|
||||||
_, err := client.InitChainSync(types.RequestInitChain{
|
_, err := client.InitChainSync(types.RequestInitChain{
|
||||||
Validators: vals,
|
Validators: vals,
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
fmt "fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
|
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
|
||||||
)
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
|
|
||||||
const (
|
|
||||||
PubKeyEd25519 = "ed25519"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
|
func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
|
||||||
pke := ed25519.PubKey(pk)
|
pke := ed25519.PubKey(pk)
|
||||||
|
|
||||||
pkp, err := cryptoenc.PubKeyToProto(pke)
|
pkp, err := cryptoenc.PubKeyToProto(pke)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -22,3 +22,23 @@ func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
|
|||||||
Power: power,
|
Power: power,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateValidator(pk []byte, power int64, keyType string) ValidatorUpdate {
|
||||||
|
switch keyType {
|
||||||
|
case "", ed25519.KeyType:
|
||||||
|
return Ed25519ValidatorUpdate(pk, power)
|
||||||
|
case secp256k1.KeyType:
|
||||||
|
pke := secp256k1.PubKey(pk)
|
||||||
|
pkp, err := cryptoenc.PubKeyToProto(pke)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ValidatorUpdate{
|
||||||
|
// Address:
|
||||||
|
PubKey: pkp,
|
||||||
|
Power: power,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("key type %s not supported", keyType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) {
|
|||||||
return pk, nil
|
return pk, nil
|
||||||
case *pc.PublicKey_Secp256K1:
|
case *pc.PublicKey_Secp256K1:
|
||||||
if len(k.Secp256K1) != secp256k1.PubKeySize {
|
if len(k.Secp256K1) != secp256k1.PubKeySize {
|
||||||
return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d",
|
return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d",
|
||||||
len(k.Secp256K1), secp256k1.PubKeySize)
|
len(k.Secp256K1), secp256k1.PubKeySize)
|
||||||
}
|
}
|
||||||
pk := make(secp256k1.PubKey, secp256k1.PubKeySize)
|
pk := make(secp256k1.PubKey, secp256k1.PubKeySize)
|
||||||
|
|||||||
@@ -193,13 +193,15 @@ func (app *Application) validatorUpdates(height uint64) (abci.ValidatorUpdates,
|
|||||||
if len(updates) == 0 {
|
if len(updates) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
valUpdates := abci.ValidatorUpdates{}
|
valUpdates := abci.ValidatorUpdates{}
|
||||||
for keyString, power := range updates {
|
for keyString, power := range updates {
|
||||||
|
|
||||||
keyBytes, err := base64.StdEncoding.DecodeString(keyString)
|
keyBytes, err := base64.StdEncoding.DecodeString(keyString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid base64 pubkey value %q: %w", keyString, err)
|
return nil, fmt.Errorf("invalid base64 pubkey value %q: %w", keyString, err)
|
||||||
}
|
}
|
||||||
valUpdates = append(valUpdates, abci.Ed25519ValidatorUpdate(keyBytes, int64(power)))
|
valUpdates = append(valUpdates, abci.UpdateValidator(keyBytes, int64(power), app.cfg.KeyType))
|
||||||
}
|
}
|
||||||
return valUpdates, nil
|
return valUpdates, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Config struct {
|
|||||||
PrivValKey string `toml:"privval_key"`
|
PrivValKey string `toml:"privval_key"`
|
||||||
PrivValState string `toml:"privval_state"`
|
PrivValState string `toml:"privval_state"`
|
||||||
Misbehaviors map[string]string `toml:"misbehaviors"`
|
Misbehaviors map[string]string `toml:"misbehaviors"`
|
||||||
|
KeyType string `toml:"key_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig loads the configuration from disk.
|
// LoadConfig loads the configuration from disk.
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ type Node struct {
|
|||||||
Name string
|
Name string
|
||||||
Testnet *Testnet
|
Testnet *Testnet
|
||||||
Mode Mode
|
Mode Mode
|
||||||
Key crypto.PrivKey
|
PrivvalKey crypto.PrivKey
|
||||||
|
NodeKey crypto.PrivKey
|
||||||
IP net.IP
|
IP net.IP
|
||||||
ProxyPort uint32
|
ProxyPort uint32
|
||||||
StartAt int64
|
StartAt int64
|
||||||
@@ -135,7 +136,8 @@ func LoadTestnet(file string) (*Testnet, error) {
|
|||||||
node := &Node{
|
node := &Node{
|
||||||
Name: name,
|
Name: name,
|
||||||
Testnet: testnet,
|
Testnet: testnet,
|
||||||
Key: keyGen.Generate(),
|
PrivvalKey: keyGen.Generate(manifest.KeyType),
|
||||||
|
NodeKey: keyGen.Generate("ed25519"),
|
||||||
IP: ipGen.Next(),
|
IP: ipGen.Next(),
|
||||||
ProxyPort: proxyPortGen.Next(),
|
ProxyPort: proxyPortGen.Next(),
|
||||||
Mode: ModeValidator,
|
Mode: ModeValidator,
|
||||||
@@ -435,7 +437,7 @@ func (n Node) AddressP2P(withID bool) string {
|
|||||||
}
|
}
|
||||||
addr := fmt.Sprintf("%v:26656", ip)
|
addr := fmt.Sprintf("%v:26656", ip)
|
||||||
if withID {
|
if withID {
|
||||||
addr = fmt.Sprintf("%x@%v", n.Key.PubKey().Address().Bytes(), addr)
|
addr = fmt.Sprintf("%x@%v", n.NodeKey.PubKey().Address().Bytes(), addr)
|
||||||
}
|
}
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,12 +96,12 @@ func Setup(testnet *e2e.Testnet) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = (&p2p.NodeKey{PrivKey: node.Key}).SaveAs(filepath.Join(nodeDir, "config", "node_key.json"))
|
err = (&p2p.NodeKey{PrivKey: node.NodeKey}).SaveAs(filepath.Join(nodeDir, "config", "node_key.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
(privval.NewFilePV(node.Key,
|
(privval.NewFilePV(node.PrivvalKey,
|
||||||
filepath.Join(nodeDir, PrivvalKeyFile),
|
filepath.Join(nodeDir, PrivvalKeyFile),
|
||||||
filepath.Join(nodeDir, PrivvalStateFile),
|
filepath.Join(nodeDir, PrivvalStateFile),
|
||||||
)).Save()
|
)).Save()
|
||||||
@@ -194,8 +194,8 @@ func MakeGenesis(testnet *e2e.Testnet) (types.GenesisDoc, error) {
|
|||||||
for validator, power := range testnet.Validators {
|
for validator, power := range testnet.Validators {
|
||||||
genesis.Validators = append(genesis.Validators, types.GenesisValidator{
|
genesis.Validators = append(genesis.Validators, types.GenesisValidator{
|
||||||
Name: validator.Name,
|
Name: validator.Name,
|
||||||
Address: validator.Key.PubKey().Address(),
|
Address: validator.PrivvalKey.PubKey().Address(),
|
||||||
PubKey: validator.Key.PubKey(),
|
PubKey: validator.PrivvalKey.PubKey(),
|
||||||
Power: power,
|
Power: power,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -317,6 +317,7 @@ func MakeAppConfig(node *e2e.Node) ([]byte, error) {
|
|||||||
"persist_interval": node.PersistInterval,
|
"persist_interval": node.PersistInterval,
|
||||||
"snapshot_interval": node.SnapshotInterval,
|
"snapshot_interval": node.SnapshotInterval,
|
||||||
"retain_blocks": node.RetainBlocks,
|
"retain_blocks": node.RetainBlocks,
|
||||||
|
"key_type": node.PrivvalKey.Type(),
|
||||||
}
|
}
|
||||||
switch node.ABCIProtocol {
|
switch node.ABCIProtocol {
|
||||||
case e2e.ProtocolUNIX:
|
case e2e.ProtocolUNIX:
|
||||||
@@ -359,7 +360,7 @@ func MakeAppConfig(node *e2e.Node) ([]byte, error) {
|
|||||||
for height, validators := range node.Testnet.ValidatorUpdates {
|
for height, validators := range node.Testnet.ValidatorUpdates {
|
||||||
updateVals := map[string]int64{}
|
updateVals := map[string]int64{}
|
||||||
for node, power := range validators {
|
for node, power := range validators {
|
||||||
updateVals[base64.StdEncoding.EncodeToString(node.Key.PubKey().Bytes())] = power
|
updateVals[base64.StdEncoding.EncodeToString(node.PrivvalKey.PubKey().Bytes())] = power
|
||||||
}
|
}
|
||||||
validatorUpdates[fmt.Sprintf("%v", height)] = updateVals
|
validatorUpdates[fmt.Sprintf("%v", height)] = updateVals
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestEvidence_Misbehavior(t *testing.T) {
|
|||||||
for _, evidence := range block.Evidence.Evidence {
|
for _, evidence := range block.Evidence.Evidence {
|
||||||
switch evidence := evidence.(type) {
|
switch evidence := evidence.(type) {
|
||||||
case *types.DuplicateVoteEvidence:
|
case *types.DuplicateVoteEvidence:
|
||||||
if bytes.Equal(evidence.VoteA.ValidatorAddress, node.Key.PubKey().Address()) {
|
if bytes.Equal(evidence.VoteA.ValidatorAddress, node.PrivvalKey.PubKey().Address()) {
|
||||||
nodeEvidence = evidence
|
nodeEvidence = evidence
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func TestValidator_Propose(t *testing.T) {
|
|||||||
if node.Mode != e2e.ModeValidator {
|
if node.Mode != e2e.ModeValidator {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
address := node.Key.PubKey().Address()
|
address := node.PrivvalKey.PubKey().Address()
|
||||||
valSchedule := newValidatorSchedule(*node.Testnet)
|
valSchedule := newValidatorSchedule(*node.Testnet)
|
||||||
|
|
||||||
expectCount := 0
|
expectCount := 0
|
||||||
@@ -90,7 +90,7 @@ func TestValidator_Sign(t *testing.T) {
|
|||||||
if node.Mode != e2e.ModeValidator {
|
if node.Mode != e2e.ModeValidator {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
address := node.Key.PubKey().Address()
|
address := node.PrivvalKey.PubKey().Address()
|
||||||
valSchedule := newValidatorSchedule(*node.Testnet)
|
valSchedule := newValidatorSchedule(*node.Testnet)
|
||||||
|
|
||||||
expectCount := 0
|
expectCount := 0
|
||||||
@@ -160,7 +160,7 @@ func (s *validatorSchedule) Increment(heights int64) {
|
|||||||
func makeVals(valMap map[*e2e.Node]int64) []*types.Validator {
|
func makeVals(valMap map[*e2e.Node]int64) []*types.Validator {
|
||||||
vals := make([]*types.Validator, 0, len(valMap))
|
vals := make([]*types.Validator, 0, len(valMap))
|
||||||
for node, power := range valMap {
|
for node, power := range valMap {
|
||||||
vals = append(vals, types.NewValidator(node.Key.PubKey(), power))
|
vals = append(vals, types.NewValidator(node.PrivvalKey.PubKey(), power))
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user