Browse Source

types: remove Version from CanonicalXxx (#2666)

pull/2675/head
Ethan Buchman 6 years ago
committed by GitHub
parent
commit
e798766a27
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 32 deletions
  1. +0
    -1
      docs/spec/blockchain/encoding.md
  2. +2
    -8
      types/canonical.go
  3. +19
    -23
      types/vote_test.go

+ 0
- 1
docs/spec/blockchain/encoding.md View File

@ -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


+ 2
- 8
types/canonical.go View File

@ -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),


+ 19
- 23
types/vote_test.go View File

@ -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
},
}


Loading…
Cancel
Save