diff --git a/glide.lock b/glide.lock index 42712c232..a1a29b9db 100644 --- a/glide.lock +++ b/glide.lock @@ -90,9 +90,9 @@ imports: - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 0ca2c6fdb0706001ca4c4b9b80c9f428e8cf39da + version: 3e1dba7ab762bb689123eec30c468967f077a6a4 - name: github.com/tendermint/go-data - version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 + version: 9fbf0684fefc4fad580992394a0bcf47c1b3d77e - name: github.com/tendermint/go-db version: 9643f60bc2578693844aacf380a7c32e4c029fee - name: github.com/tendermint/go-events diff --git a/types/priv_validator.go b/types/priv_validator.go index c200dff3c..8752e430d 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -11,8 +11,6 @@ import ( . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" - - "github.com/tendermint/ed25519" ) const ( @@ -81,22 +79,15 @@ func (privVal *PrivValidator) SetSigner(s Signer) { // Generates a new validator with private key. func GenPrivValidator() *PrivValidator { - privKeyBytes := new([64]byte) - copy(privKeyBytes[:32], crypto.CRandBytes(32)) - pubKeyBytes := ed25519.MakePublicKey(privKeyBytes) - pubKey := crypto.PubKeyEd25519(*pubKeyBytes) - privKey := crypto.PrivKeyEd25519(*privKeyBytes) + privKey := crypto.WrapPrivKey(crypto.GenPrivKeyEd25519()) + pubKey := privKey.PubKey() return &PrivValidator{ - Address: pubKey.Address(), - PubKey: pubKey, - PrivKey: privKey, - LastHeight: 0, - LastRound: 0, - LastStep: stepNone, - LastSignature: nil, - LastSignBytes: nil, - filePath: "", - Signer: NewDefaultSigner(privKey), + Address: pubKey.Address(), + PubKey: pubKey, + PrivKey: privKey, + LastStep: stepNone, + filePath: "", + Signer: NewDefaultSigner(privKey), } } @@ -158,7 +149,7 @@ func (privVal *PrivValidator) Reset() { privVal.LastHeight = 0 privVal.LastRound = 0 privVal.LastStep = 0 - privVal.LastSignature = nil + privVal.LastSignature = crypto.Signature{} privVal.LastSignBytes = nil privVal.Save() } @@ -191,23 +182,24 @@ func (privVal *PrivValidator) SignProposal(chainID string, proposal *Proposal) e // check if there's a regression. Else sign and write the hrs+signature to disk func (privVal *PrivValidator) signBytesHRS(height, round int, step int8, signBytes []byte) (crypto.Signature, error) { + sig := crypto.Signature{} // If height regression, err if privVal.LastHeight > height { - return nil, errors.New("Height regression") + return sig, errors.New("Height regression") } // More cases for when the height matches if privVal.LastHeight == height { // If round regression, err if privVal.LastRound > round { - return nil, errors.New("Round regression") + return sig, errors.New("Round regression") } // If step regression, err if privVal.LastRound == round { if privVal.LastStep > step { - return nil, errors.New("Step regression") + return sig, errors.New("Step regression") } else if privVal.LastStep == step { if privVal.LastSignBytes != nil { - if privVal.LastSignature == nil { + if privVal.LastSignature.Empty() { PanicSanity("privVal: LastSignature is nil but LastSignBytes is not!") } // so we dont sign a conflicting vote or proposal @@ -218,23 +210,23 @@ func (privVal *PrivValidator) signBytesHRS(height, round int, step int8, signByt return privVal.LastSignature, nil } } - return nil, errors.New("Step regression") + return sig, errors.New("Step regression") } } } // Sign - signature := privVal.Sign(signBytes) + sig = privVal.Sign(signBytes) // Persist height/round/step privVal.LastHeight = height privVal.LastRound = round privVal.LastStep = step - privVal.LastSignature = signature + privVal.LastSignature = sig privVal.LastSignBytes = signBytes privVal.save() - return signature, nil + return sig, nil } diff --git a/types/validator_set_test.go b/types/validator_set_test.go index bc7fef798..b918b8d5f 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -9,10 +9,10 @@ import ( "github.com/tendermint/go-crypto" ) -func randPubKey() crypto.PubKeyEd25519 { +func randPubKey() crypto.PubKey { var pubKey [32]byte copy(pubKey[:], cmn.RandBytes(32)) - return crypto.PubKeyEd25519(pubKey) + return crypto.WrapPubKey(crypto.PubKeyEd25519(pubKey)) } func randValidator_() *Validator { @@ -194,7 +194,7 @@ func BenchmarkValidatorSetCopy(b *testing.B) { vset := NewValidatorSet([]*Validator{}) for i := 0; i < 1000; i++ { privKey := crypto.GenPrivKeyEd25519() - pubKey := privKey.PubKey().(crypto.PubKeyEd25519) + pubKey := privKey.PubKey() val := NewValidator(pubKey, 0) if !vset.Add(val) { panic("Failed to add validator")