diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 38bb3747..0d817215 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -289,17 +289,17 @@ func (privVal *ByzantinePrivValidator) GetPubKey() crypto.PubKey { } func (privVal *ByzantinePrivValidator) SignVote(chainID string, vote *types.Vote) (err error) { - vote.Signature, err = privVal.Sign(types.SignBytes(chainID, vote)) + vote.Signature, err = privVal.Sign(vote.SignBytes(chainID)) return err } func (privVal *ByzantinePrivValidator) SignProposal(chainID string, proposal *types.Proposal) (err error) { - proposal.Signature, _ = privVal.Sign(types.SignBytes(chainID, proposal)) + proposal.Signature, _ = privVal.Sign(proposal.SignBytes(chainID)) return nil } func (privVal *ByzantinePrivValidator) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) (err error) { - heartbeat.Signature, _ = privVal.Sign(types.SignBytes(chainID, heartbeat)) + heartbeat.Signature, _ = privVal.Sign(heartbeat.SignBytes(chainID)) return nil } diff --git a/consensus/state.go b/consensus/state.go index 62d1c925..30bd56f1 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1269,7 +1269,7 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error { } // Verify signature - if !cs.Validators.GetProposer().PubKey.VerifyBytes(types.SignBytes(cs.state.ChainID, proposal), proposal.Signature) { + if !cs.Validators.GetProposer().PubKey.VerifyBytes(proposal.SignBytes(cs.state.ChainID), proposal.Signature) { return ErrInvalidProposalSignature } diff --git a/lite/helpers.go b/lite/helpers.go index d985882d..7df77027 100644 --- a/lite/helpers.go +++ b/lite/helpers.go @@ -102,7 +102,7 @@ func makeVote(header *types.Header, vals *types.ValidatorSet, key crypto.PrivKey BlockID: types.BlockID{Hash: header.Hash()}, } // Sign it - signBytes := types.SignBytes(header.ChainID, vote) + signBytes := vote.SignBytes(header.ChainID) vote.Signature = key.Sign(signBytes) return vote } diff --git a/types/heartbeat_test.go b/types/heartbeat_test.go index 67bc93b4..055f26f7 100644 --- a/types/heartbeat_test.go +++ b/types/heartbeat_test.go @@ -25,11 +25,11 @@ func TestHeartbeatString(t *testing.T) { require.Contains(t, nilHb.String(), "nil", "expecting a string and no panic") hb := &Heartbeat{ValidatorIndex: 1, Height: 11, Round: 2} - require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) }") + require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) {}}") var key crypto.PrivKeyEd25519 hb.Signature = key.Sign([]byte("Tendermint")) - require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) /FF41E371B9BF.../}") + require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) {/FF41E371B9BF.../}}") } /* TODO WIRE make json work diff --git a/types/priv_validator/priv_validator_test.go b/types/priv_validator/priv_validator_test.go index 664d59cf..120a0c86 100644 --- a/types/priv_validator/priv_validator_test.go +++ b/types/priv_validator/priv_validator_test.go @@ -211,7 +211,7 @@ func TestDifferByTimestamp(t *testing.T) { proposal := newProposal(height, round, block1) err := privVal.SignProposal(chainID, proposal) assert.NoError(t, err, "expected no error signing proposal") - signBytes := types.SignBytes(chainID, proposal) + signBytes := proposal.SignBytes(chainID) sig := proposal.Signature timeStamp := clipToMS(proposal.Timestamp) @@ -222,7 +222,7 @@ func TestDifferByTimestamp(t *testing.T) { assert.NoError(t, err, "expected no error on signing same proposal") assert.Equal(t, timeStamp, proposal.Timestamp) - assert.Equal(t, signBytes, types.SignBytes(chainID, proposal)) + assert.Equal(t, signBytes, proposal.SignBytes(chainID)) assert.Equal(t, sig, proposal.Signature) } @@ -237,7 +237,7 @@ func TestDifferByTimestamp(t *testing.T) { err = privVal.SignVote("mychainid", vote) assert.NoError(t, err, "expected no error signing vote") - signBytes := types.SignBytes(chainID, vote) + signBytes := vote.SignBytes(chainID) sig := vote.Signature timeStamp := clipToMS(vote.Timestamp) @@ -248,7 +248,7 @@ func TestDifferByTimestamp(t *testing.T) { assert.NoError(t, err, "expected no error on signing same vote") assert.Equal(t, timeStamp, vote.Timestamp) - assert.Equal(t, signBytes, types.SignBytes(chainID, vote)) + assert.Equal(t, signBytes, vote.SignBytes(chainID)) assert.Equal(t, sig, vote.Signature) } } diff --git a/types/priv_validator/sign_info.go b/types/priv_validator/sign_info.go index 60113c57..746131a9 100644 --- a/types/priv_validator/sign_info.go +++ b/types/priv_validator/sign_info.go @@ -112,7 +112,7 @@ func (info *LastSignedInfo) Reset() { // Else it returns an error. func (lsi *LastSignedInfo) SignVote(signer types.Signer, chainID string, vote *types.Vote) error { height, round, step := vote.Height, vote.Round, voteToStep(vote) - signBytes := types.SignBytes(chainID, vote) + signBytes := vote.SignBytes(chainID) sameHRS, err := lsi.Verify(height, round, step) if err != nil { @@ -151,7 +151,7 @@ func (lsi *LastSignedInfo) SignVote(signer types.Signer, chainID string, vote *t // Else it returns an error. func (lsi *LastSignedInfo) SignProposal(signer types.Signer, chainID string, proposal *types.Proposal) error { height, round, step := proposal.Height, proposal.Round, stepPropose - signBytes := types.SignBytes(chainID, proposal) + signBytes := proposal.SignBytes(chainID) sameHRS, err := lsi.Verify(height, round, step) if err != nil { diff --git a/types/priv_validator/unencrypted.go b/types/priv_validator/unencrypted.go index 3ef38eec..10a304d9 100644 --- a/types/priv_validator/unencrypted.go +++ b/types/priv_validator/unencrypted.go @@ -61,6 +61,6 @@ func (upv *PrivValidatorUnencrypted) SignProposal(chainID string, proposal *type func (upv *PrivValidatorUnencrypted) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error { var err error - heartbeat.Signature, err = upv.PrivKey.Sign(types.SignBytes(chainID, heartbeat)) + heartbeat.Signature, err = upv.PrivKey.Sign(heartbeat.SignBytes(chainID)) return err }