func (pv *FridayFilePV) signVote(chainID string, vote *types.Vote) error {
	height, round, step := vote.Height, vote.Round, voteToStep(vote)

	sameHRS, existSignState, err := pv.SignState.CheckHRS(height, round, step)
	if err != nil {
		return err
	}

	signBytes := vote.SignBytes(chainID)

	// We might crash before writing to the wal,
	// causing us to try to re-sign for the same HRS.
	// If signbytes are the same, use the last signature.
	// If they only differ by timestamp, use last timestamp and signature
	// Otherwise, return error
	if sameHRS {
		if bytes.Equal(signBytes, existSignState.SignBytes) {
			vote.Signature = existSignState.Signature
		} else if timestamp, ok := checkVotesOnlyDifferByTimestamp(existSignState.SignBytes, signBytes); ok {
			vote.Timestamp = timestamp
			vote.Signature = existSignState.Signature
		} else {
			err = fmt.Errorf("conflicting data")
		}
		return err
	}

	// It passed the checks. Sign the vote
	sig, err := pv.Key.PrivKey.Sign(signBytes)
	if err != nil {
		return err
	}
	pv.saveSigned(height, round, step, signBytes, sig)
	vote.Signature = sig
	return nil
}
// signVote checks if the vote is good to sign and sets the vote signature.
// It may need to set the timestamp as well if the vote is otherwise the same as
// a previously signed vote (ie. we crashed after signing but before the vote hit the WAL).
signVote checks if the vote is good to sign and sets the vote signature.
It may need to set the timestamp as well if the vote is otherwise the same as
a previously signed vote .
// signVote checks if the vote is good to sign and sets the vote signature . // It may need to set the timestamp as well if the vote is otherwise the same as // a previously signed vote ( ie . we crashed after signing but before the vote hit the WAL ) .
func (pv *FridayFilePV) signVote(chainID string, vote *types.Vote) error {
	height, round, step := vote.Height, vote.Round, voteToStep(vote)
	sameHRS, existSignState, err := pv.SignState.CheckHRS(height, round, step)
	if err != nil {
		return err
	}
	signBytes := vote.SignBytes(chainID)
	if sameHRS {
		if bytes.Equal(signBytes, existSignState.SignBytes) {
			vote.Signature = existSignState.Signature
		} else if timestamp, ok := checkVotesOnlyDifferByTimestamp(existSignState.SignBytes, signBytes); ok {
			vote.Timestamp = timestamp
			vote.Signature = existSignState.Signature
		} else {
			err = fmt.Errorf("conflicting data")
		}
		return err
	}
	sig, err := pv.Key.PrivKey.Sign(signBytes)
	if err != nil {
		return err
	}
	pv.saveSigned(height, round, step, signBytes, sig)
	vote.Signature = sig
	return nil
}
func ( pv * FridayFilePV ) signVote ( chainID string , vote * types . Vote ) error { height , round , step := vote . Height , vote . Round , voteToStep ( vote ) sameHRS , existSignState , err := pv . SignState . CheckHRS ( height , round , step ) if err != nil { return err } signBytes := vote . SignBytes ( chainID ) if sameHRS { if bytes . Equal ( signBytes , existSignState . SignBytes ) { vote . Signature = existSignState . Signature } else if timestamp , ok := checkVotesOnlyDifferByTimestamp ( existSignState . SignBytes , signBytes ) ; ok { vote . Timestamp = timestamp vote . Signature = existSignState . Signature } else { err = fmt . Errorf ( " " ) } return err } sig , err := pv . Key . PrivKey . Sign ( signBytes ) if err != nil { return err } pv . saveSigned ( height , round , step , signBytes , sig ) vote . Signature = sig return nil }
signVote checks if the vote is good to sign and sets the vote signature.
signVote checks if the vote is good to sign and sets the vote signature .
// We might crash before writing to the wal, // causing us to try to re-sign for the same HRS. // If signbytes are the same, use the last signature. // If they only differ by timestamp, use last timestamp and signature // Otherwise, return error // It passed the checks. Sign the vote