diff --git a/docs/spec/blockchain/encoding.md b/docs/spec/blockchain/encoding.md index aa184210..94b167f8 100644 --- a/docs/spec/blockchain/encoding.md +++ b/docs/spec/blockchain/encoding.md @@ -268,7 +268,7 @@ We call this encoding the CanonicalSignBytes. For instance, CanonicalSignBytes f like: ```json -{"chain_id":"my-chain-id","vote":{"block_id":{"hash":DEADBEEF,"parts":{"hash":BEEFDEAD,"total":3}},"height":3,"round":2,"timestamp":1234567890, "type":2} +{"chain_id":"my-chain-id","vote":{"block_id":{"hash":DEADBEEF,"parts":{"hash":BEEFDEAD,"total":3}},"height":3,"round":2, "type":2} ``` Note how the fields within each level are sorted. diff --git a/privval/priv_validator.go b/privval/priv_validator.go index 2bb5ef32..4c33fdb1 100644 --- a/privval/priv_validator.go +++ b/privval/priv_validator.go @@ -207,14 +207,10 @@ func (pv *FilePV) signVote(chainID string, vote *types.Vote) error { // 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, pv.LastSignBytes) { vote.Signature = pv.LastSignature - } else if timestamp, ok := checkVotesOnlyDifferByTimestamp(pv.LastSignBytes, signBytes); ok { - vote.Timestamp = timestamp - vote.Signature = pv.LastSignature } else { err = fmt.Errorf("Conflicting data") } @@ -292,32 +288,6 @@ func (pv *FilePV) String() string { //------------------------------------- -// returns the timestamp from the lastSignBytes. -// returns true if the only difference in the votes is their timestamp. -func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) { - var lastVote, newVote types.CanonicalJSONVote - if err := cdc.UnmarshalJSON(lastSignBytes, &lastVote); err != nil { - panic(fmt.Sprintf("LastSignBytes cannot be unmarshalled into vote: %v", err)) - } - if err := cdc.UnmarshalJSON(newSignBytes, &newVote); err != nil { - panic(fmt.Sprintf("signBytes cannot be unmarshalled into vote: %v", err)) - } - - lastTime, err := time.Parse(types.TimeFormat, lastVote.Timestamp) - if err != nil { - panic(err) - } - - // set the times to the same value and check equality - now := types.CanonicalTime(time.Now()) - lastVote.Timestamp = now - newVote.Timestamp = now - lastVoteBytes, _ := cdc.MarshalJSON(lastVote) - newVoteBytes, _ := cdc.MarshalJSON(newVote) - - return lastTime, bytes.Equal(newVoteBytes, lastVoteBytes) -} - // returns the timestamp from the lastSignBytes. // returns true if the only difference in the proposals is their timestamp func checkProposalsOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) { diff --git a/privval/priv_validator_test.go b/privval/priv_validator_test.go index c7212d59..189829bc 100644 --- a/privval/priv_validator_test.go +++ b/privval/priv_validator_test.go @@ -207,7 +207,6 @@ func TestDifferByTimestamp(t *testing.T) { signBytes := vote.SignBytes(chainID) sig := vote.Signature - timeStamp := clipToMS(vote.Timestamp) // manipulate the timestamp. should get changed back vote.Timestamp = vote.Timestamp.Add(time.Millisecond) @@ -216,7 +215,6 @@ func TestDifferByTimestamp(t *testing.T) { err = privVal.SignVote("mychainid", vote) assert.NoError(t, err, "expected no error on signing same vote") - assert.Equal(t, timeStamp, vote.Timestamp) assert.Equal(t, signBytes, vote.SignBytes(chainID)) assert.Equal(t, sig, vote.Signature) } diff --git a/types/canonical_json.go b/types/canonical_json.go index 95ade9c6..1d2671fb 100644 --- a/types/canonical_json.go +++ b/types/canonical_json.go @@ -34,13 +34,12 @@ type CanonicalJSONProposal struct { } type CanonicalJSONVote struct { - ChainID string `json:"@chain_id"` - Type string `json:"@type"` - BlockID CanonicalJSONBlockID `json:"block_id"` - Height int64 `json:"height"` - Round int `json:"round"` - Timestamp string `json:"timestamp"` - VoteType byte `json:"type"` + ChainID string `json:"@chain_id"` + Type string `json:"@type"` + BlockID CanonicalJSONBlockID `json:"block_id"` + Height int64 `json:"height"` + Round int `json:"round"` + VoteType byte `json:"type"` } type CanonicalJSONHeartbeat struct { @@ -85,13 +84,12 @@ func CanonicalProposal(chainID string, proposal *Proposal) CanonicalJSONProposal func CanonicalVote(chainID string, vote *Vote) CanonicalJSONVote { return CanonicalJSONVote{ - ChainID: chainID, - Type: "vote", - BlockID: CanonicalBlockID(vote.BlockID), - Height: vote.Height, - Round: vote.Round, - Timestamp: CanonicalTime(vote.Timestamp), - VoteType: vote.Type, + ChainID: chainID, + Type: "vote", + BlockID: CanonicalBlockID(vote.BlockID), + Height: vote.Height, + Round: vote.Round, + VoteType: vote.Type, } } diff --git a/types/vote_test.go b/types/vote_test.go index 263d2c35..36225953 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -43,7 +43,7 @@ func TestVoteSignable(t *testing.T) { signBytes := vote.SignBytes("test_chain_id") signStr := string(signBytes) - expected := `{"@chain_id":"test_chain_id","@type":"vote","block_id":{"hash":"68617368","parts":{"hash":"70617274735F68617368","total":1000000}},"height":12345,"round":2,"timestamp":"2017-12-25T03:00:01.234Z","type":2}` + expected := `{"@chain_id":"test_chain_id","@type":"vote","block_id":{"hash":"68617368","parts":{"hash":"70617274735F68617368","total":1000000}},"height":12345,"round":2,"type":2}` if signStr != expected { // NOTE: when this fails, you probably want to fix up consensus/replay_test too t.Errorf("Got unexpected sign string for Vote. Expected:\n%v\nGot:\n%v", expected, signStr)