From e798766a27a0825f5e5deb460d755d2bf8813f96 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 18 Oct 2018 18:02:20 -0400 Subject: [PATCH] types: remove Version from CanonicalXxx (#2666) --- docs/spec/blockchain/encoding.md | 1 - types/canonical.go | 10 ++------ types/vote_test.go | 42 +++++++++++++++----------------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/docs/spec/blockchain/encoding.md b/docs/spec/blockchain/encoding.md index ed92739d0..5657784dc 100644 --- a/docs/spec/blockchain/encoding.md +++ b/docs/spec/blockchain/encoding.md @@ -307,7 +307,6 @@ We call this encoding the SignBytes. For instance, SignBytes for a vote is the A ```go type CanonicalVote struct { - Version uint64 `binary:"fixed64"` Height int64 `binary:"fixed64"` Round int64 `binary:"fixed64"` VoteType byte diff --git a/types/canonical.go b/types/canonical.go index 8a33debda..c40f35dd3 100644 --- a/types/canonical.go +++ b/types/canonical.go @@ -23,7 +23,6 @@ type CanonicalPartSetHeader struct { } type CanonicalProposal struct { - Version uint64 `binary:"fixed64"` Height int64 `binary:"fixed64"` Round int64 `binary:"fixed64"` Type SignedMsgType // type alias for byte @@ -35,7 +34,6 @@ type CanonicalProposal struct { } type CanonicalVote struct { - Version uint64 `binary:"fixed64"` Height int64 `binary:"fixed64"` Round int64 `binary:"fixed64"` Type SignedMsgType // type alias for byte @@ -45,9 +43,8 @@ type CanonicalVote struct { } type CanonicalHeartbeat struct { - Version uint64 `binary:"fixed64"` - Height int64 `binary:"fixed64"` - Round int `binary:"fixed64"` + Height int64 `binary:"fixed64"` + Round int `binary:"fixed64"` Type byte Sequence int `binary:"fixed64"` ValidatorAddress Address @@ -74,7 +71,6 @@ func CanonicalizePartSetHeader(psh PartSetHeader) CanonicalPartSetHeader { func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal { return CanonicalProposal{ - Version: 0, // TODO Height: proposal.Height, Round: int64(proposal.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int) Type: ProposalType, @@ -88,7 +84,6 @@ func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal func CanonicalizeVote(chainID string, vote *Vote) CanonicalVote { return CanonicalVote{ - Version: 0, // TODO Height: vote.Height, Round: int64(vote.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int) Type: vote.Type, @@ -100,7 +95,6 @@ func CanonicalizeVote(chainID string, vote *Vote) CanonicalVote { func CanonicalizeHeartbeat(chainID string, heartbeat *Heartbeat) CanonicalHeartbeat { return CanonicalHeartbeat{ - Version: 0, // TODO Height: heartbeat.Height, Round: heartbeat.Round, Type: byte(HeartbeatType), diff --git a/types/vote_test.go b/types/vote_test.go index 282953f46..066df4964 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -54,8 +54,7 @@ func TestVoteSignable(t *testing.T) { } func TestVoteSignableTestVectors(t *testing.T) { - voteWithVersion := CanonicalizeVote("", &Vote{Height: 1, Round: 1}) - voteWithVersion.Version = 123 + vote := CanonicalizeVote("", &Vote{Height: 1, Round: 1}) tests := []struct { canonicalVote CanonicalVote @@ -64,20 +63,20 @@ func TestVoteSignableTestVectors(t *testing.T) { { CanonicalizeVote("", &Vote{}), // NOTE: Height and Round are skipped here. This case needs to be considered while parsing. - []byte{0xb, 0x2a, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, + []byte{0xb, 0x22, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, }, // with proper (fixed size) height and round (PreCommit): { CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrecommitType}), []byte{ 0x1f, // total length - 0x11, // (field_number << 3) | wire_type (version is missing) + 0x9, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height - 0x19, // (field_number << 3) | wire_type + 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round - 0x20, // (field_number << 3) | wire_type + 0x18, // (field_number << 3) | wire_type 0x2, // PrecommitType - 0x2a, // (field_number << 3) | wire_type + 0x22, // (field_number << 3) | wire_type // remaining fields (timestamp): 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, }, @@ -86,29 +85,26 @@ func TestVoteSignableTestVectors(t *testing.T) { CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrevoteType}), []byte{ 0x1f, // total length - 0x11, // (field_number << 3) | wire_type (version is missing) + 0x9, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height - 0x19, // (field_number << 3) | wire_type + 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round - 0x20, // (field_number << 3) | wire_type + 0x18, // (field_number << 3) | wire_type 0x1, // PrevoteType - 0x2a, // (field_number << 3) | wire_type + 0x22, // (field_number << 3) | wire_type // remaining fields (timestamp): 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, }, - // containing version (empty type) { - voteWithVersion, + vote, []byte{ - 0x26, // total length - 0x9, // (field_number << 3) | wire_type - 0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // version (123) - 0x11, // (field_number << 3) | wire_type + 0x1d, // total length + 0x9, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height - 0x19, // (field_number << 3) | wire_type + 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round // remaining fields (timestamp): - 0x2a, + 0x22, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, }, // containing non-empty chain_id: @@ -116,14 +112,14 @@ func TestVoteSignableTestVectors(t *testing.T) { CanonicalizeVote("test_chain_id", &Vote{Height: 1, Round: 1}), []byte{ 0x2c, // total length - 0x11, // (field_number << 3) | wire_type + 0x9, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height - 0x19, // (field_number << 3) | wire_type + 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round // remaining fields: - 0x2a, // (field_number << 3) | wire_type + 0x22, // (field_number << 3) | wire_type 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff, // timestamp - 0x3a, // (field_number << 3) | wire_type + 0x32, // (field_number << 3) | wire_type 0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID }, }