Browse Source

types: privVal.Sign returns an error

pull/658/head
Ethan Buchman 7 years ago
parent
commit
90c0267bc1
4 changed files with 23 additions and 15 deletions
  1. +7
    -7
      consensus/byzantine_test.go
  2. +10
    -6
      types/priv_validator.go
  3. +1
    -1
      types/proposal_test.go
  4. +5
    -1
      types/vote_set_test.go

+ 7
- 7
consensus/byzantine_test.go View File

@ -275,30 +275,30 @@ func (privVal *ByzantinePrivValidator) GetAddress() []byte {
return privVal.Address
}
func (privVal *ByzantinePrivValidator) SignVote(chainID string, vote *types.Vote) error {
func (privVal *ByzantinePrivValidator) SignVote(chainID string, vote *types.Vote) (err error) {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
// Sign
vote.Signature = privVal.Sign(types.SignBytes(chainID, vote))
return nil
vote.Signature, err = privVal.Sign(types.SignBytes(chainID, vote))
return err
}
func (privVal *ByzantinePrivValidator) SignProposal(chainID string, proposal *types.Proposal) error {
func (privVal *ByzantinePrivValidator) SignProposal(chainID string, proposal *types.Proposal) (err error) {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
// Sign
proposal.Signature = privVal.Sign(types.SignBytes(chainID, proposal))
proposal.Signature, err = privVal.Sign(types.SignBytes(chainID, proposal))
return nil
}
func (privVal *ByzantinePrivValidator) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error {
func (privVal *ByzantinePrivValidator) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) (err error) {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
// Sign
heartbeat.Signature = privVal.Sign(types.SignBytes(chainID, heartbeat))
heartbeat.Signature, err = privVal.Sign(types.SignBytes(chainID, heartbeat))
return nil
}


+ 10
- 6
types/priv_validator.go View File

@ -59,7 +59,7 @@ type PrivValidator struct {
// Currently, the only callers are SignVote and SignProposal
type Signer interface {
PubKey() crypto.PubKey
Sign(msg []byte) crypto.Signature
Sign(msg []byte) (crypto.Signature, error)
}
// Implements Signer
@ -72,8 +72,8 @@ func NewDefaultSigner(priv crypto.PrivKey) *DefaultSigner {
}
// Implements Signer
func (ds *DefaultSigner) Sign(msg []byte) crypto.Signature {
return ds.priv.Sign(msg)
func (ds *DefaultSigner) Sign(msg []byte) (crypto.Signature, error) {
return ds.priv.Sign(msg), nil
}
// Implements Signer
@ -238,7 +238,10 @@ func (privVal *PrivValidator) signBytesHRS(height, round int, step int8, signByt
}
// Sign
sig = privVal.Sign(signBytes)
sig, err := privVal.Sign(signBytes)
if err != nil {
return sig, err
}
// Persist height/round/step
privVal.LastHeight = height
@ -255,8 +258,9 @@ func (privVal *PrivValidator) signBytesHRS(height, round int, step int8, signByt
func (privVal *PrivValidator) SignHeartbeat(chainID string, heartbeat *Heartbeat) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
heartbeat.Signature = privVal.Sign(SignBytes(chainID, heartbeat))
return nil
var err error
heartbeat.Signature, err = privVal.Sign(SignBytes(chainID, heartbeat))
return err
}
func (privVal *PrivValidator) String() string {


+ 1
- 1
types/proposal_test.go View File

@ -37,7 +37,7 @@ func BenchmarkProposalSign(b *testing.B) {
func BenchmarkProposalVerifySignature(b *testing.B) {
signBytes := SignBytes("test_chain_id", testProposal)
privVal := GenPrivValidator()
signature := privVal.Sign(signBytes)
signature, _ := privVal.Sign(signBytes)
pubKey := privVal.PubKey
for i := 0; i < b.N; i++ {


+ 5
- 1
types/vote_set_test.go View File

@ -60,7 +60,11 @@ func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
}
func signAddVote(privVal *PrivValidator, vote *Vote, voteSet *VoteSet) (bool, error) {
vote.Signature = privVal.Sign(SignBytes(voteSet.ChainID(), vote))
var err error
vote.Signature, err = privVal.Sign(SignBytes(voteSet.ChainID(), vote))
if err != nil {
return false, err
}
added, err := voteSet.AddVote(vote)
return added, err
}


Loading…
Cancel
Save