Browse Source

non breaking signbytes (#5008)

* test-vectors for backwards compatibility:

 - copy & paste test-vectors from v0.33.5 to ensure
 backwards compatibility for vote's SignBytes

* WIP: everything besides time seems to match :-/

* almost

* Found the culprit: field nums weren't consecutive ints ...

* fix order of partset header too

* this last votes-related test can easily be fixed

* some minor changes and fix last failing test

* move proto types back to stdtime, fix various linting

* use libs/protoio

* remvoe commented code

* add comments

* fix tests

* uncomment testscases

* dont ignore error panic

* fix signable test

* fix happy path testing

* fix comment

Co-authored-by: Marko Baricevic <marbar3778@yahoo.com>
pull/5010/head
Ismail Khoffi 5 years ago
committed by GitHub
parent
commit
4774a8ec61
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 362 additions and 270 deletions
  1. +12
    -12
      abci/types/types.pb.go
  2. +5
    -2
      consensus/state_test.go
  3. +5
    -1
      consensus/types/height_vote_set_test.go
  4. +5
    -5
      privval/file.go
  5. +21
    -8
      privval/file_test.go
  6. +1
    -1
      proto/consensus/walmsgs.pb.go
  7. +1
    -1
      proto/state/types.pb.go
  8. +162
    -180
      proto/types/canonical.pb.go
  9. +10
    -10
      proto/types/canonical.proto
  10. +1
    -1
      proto/types/evidence.pb.go
  11. +11
    -9
      proto/types/types.pb.go
  12. +4
    -1
      proto/types/types.proto
  13. +1
    -1
      scripts/protocgen.sh
  14. +1
    -0
      types/block.go
  15. +20
    -12
      types/canonical.go
  16. +39
    -0
      types/canonical_test.go
  17. +5
    -5
      types/proposal.go
  18. +8
    -5
      types/proposal_test.go
  19. +3
    -3
      types/vote.go
  20. +47
    -13
      types/vote_test.go

+ 12
- 12
abci/types/types.pb.go View File

@ -8,11 +8,11 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/timestamp"
keys "github.com/tendermint/tendermint/proto/crypto/keys"
merkle "github.com/tendermint/tendermint/proto/crypto/merkle"
types "github.com/tendermint/tendermint/proto/types"
types1 "github.com/tendermint/tendermint/proto/types"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@ -720,7 +720,7 @@ func (m *RequestQuery) GetProve() bool {
type RequestBeginBlock struct {
Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
Header types.Header `protobuf:"bytes,2,opt,name=header,proto3" json:"header"`
Header types1.Header `protobuf:"bytes,2,opt,name=header,proto3" json:"header"`
LastCommitInfo LastCommitInfo `protobuf:"bytes,3,opt,name=last_commit_info,json=lastCommitInfo,proto3" json:"last_commit_info"`
ByzantineValidators []Evidence `protobuf:"bytes,4,rep,name=byzantine_validators,json=byzantineValidators,proto3" json:"byzantine_validators"`
}
@ -765,11 +765,11 @@ func (m *RequestBeginBlock) GetHash() []byte {
return nil
}
func (m *RequestBeginBlock) GetHeader() types.Header {
func (m *RequestBeginBlock) GetHeader() types1.Header {
if m != nil {
return m.Header
}
return types.Header{}
return types1.Header{}
}
func (m *RequestBeginBlock) GetLastCommitInfo() LastCommitInfo {
@ -2417,9 +2417,9 @@ func (m *ResponseApplySnapshotChunk) GetRejectSenders() []string {
// ConsensusParams contains all consensus-relevant parameters
// that can be adjusted by the abci app
type ConsensusParams struct {
Block *BlockParams `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"`
Evidence *types.EvidenceParams `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence,omitempty"`
Validator *types.ValidatorParams `protobuf:"bytes,3,opt,name=validator,proto3" json:"validator,omitempty"`
Block *BlockParams `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"`
Evidence *types1.EvidenceParams `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence,omitempty"`
Validator *types1.ValidatorParams `protobuf:"bytes,3,opt,name=validator,proto3" json:"validator,omitempty"`
}
func (m *ConsensusParams) Reset() { *m = ConsensusParams{} }
@ -2462,14 +2462,14 @@ func (m *ConsensusParams) GetBlock() *BlockParams {
return nil
}
func (m *ConsensusParams) GetEvidence() *types.EvidenceParams {
func (m *ConsensusParams) GetEvidence() *types1.EvidenceParams {
if m != nil {
return m.Evidence
}
return nil
}
func (m *ConsensusParams) GetValidator() *types.ValidatorParams {
func (m *ConsensusParams) GetValidator() *types1.ValidatorParams {
if m != nil {
return m.Validator
}
@ -13148,7 +13148,7 @@ func (m *ConsensusParams) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.Evidence == nil {
m.Evidence = &types.EvidenceParams{}
m.Evidence = &types1.EvidenceParams{}
}
if err := m.Evidence.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
@ -13184,7 +13184,7 @@ func (m *ConsensusParams) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF
}
if m.Validator == nil {
m.Validator = &types.ValidatorParams{}
m.Validator = &types1.ValidatorParams{}
}
if err := m.Validator.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err


+ 5
- 2
consensus/state_test.go View File

@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/abci/example/counter"
cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmrand "github.com/tendermint/tendermint/libs/rand"
@ -1802,7 +1803,9 @@ func TestStateOutputVoteStats(t *testing.T) {
// create dummy peer
peer := p2pmock.NewPeer(nil)
vote := signVote(vss[1], tmproto.PrecommitType, []byte("test"), types.PartSetHeader{})
randBytes := tmrand.Bytes(tmhash.Size)
vote := signVote(vss[1], tmproto.PrecommitType, randBytes, types.PartSetHeader{})
voteMessage := &VoteMessage{vote}
cs.handleMsg(msgInfo{voteMessage, peer.ID()})
@ -1816,7 +1819,7 @@ func TestStateOutputVoteStats(t *testing.T) {
// sending the vote for the bigger height
incrementHeight(vss[1])
vote = signVote(vss[1], tmproto.PrecommitType, []byte("test"), types.PartSetHeader{})
vote = signVote(vss[1], tmproto.PrecommitType, randBytes, types.PartSetHeader{})
cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID()})


+ 5
- 1
consensus/types/height_vote_set_test.go View File

@ -6,6 +6,8 @@ import (
"testing"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/types"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
@ -60,6 +62,8 @@ func makeVoteHR(t *testing.T, height int64, valIndex, round int32, privVals []ty
panic(err)
}
randBytes := tmrand.Bytes(tmhash.Size)
vote := &types.Vote{
ValidatorAddress: pubKey.Address(),
ValidatorIndex: valIndex,
@ -67,7 +71,7 @@ func makeVoteHR(t *testing.T, height int64, valIndex, round int32, privVals []ty
Round: round,
Timestamp: tmtime.Now(),
Type: tmproto.PrecommitType,
BlockID: types.BlockID{Hash: []byte("fakehash"), PartsHeader: types.PartSetHeader{}},
BlockID: types.BlockID{Hash: randBytes, PartsHeader: types.PartSetHeader{}},
}
chainID := config.ChainID()


+ 5
- 5
privval/file.go View File

@ -14,6 +14,7 @@ import (
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/libs/protoio"
"github.com/tendermint/tendermint/libs/tempfile"
tmproto "github.com/tendermint/tendermint/proto/types"
"github.com/tendermint/tendermint/types"
@ -397,15 +398,14 @@ func (pv *FilePV) saveSigned(height int64, round int32, step int8,
// returns true if the only difference in the votes is their timestamp.
func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) {
var lastVote, newVote tmproto.CanonicalVote
if err := proto.Unmarshal(lastSignBytes, &lastVote); err != nil {
if err := protoio.UnmarshalDelimited(lastSignBytes, &lastVote); err != nil {
panic(fmt.Sprintf("LastSignBytes cannot be unmarshalled into vote: %v", err))
}
if err := proto.Unmarshal(newSignBytes, &newVote); err != nil {
if err := protoio.UnmarshalDelimited(newSignBytes, &newVote); err != nil {
panic(fmt.Sprintf("signBytes cannot be unmarshalled into vote: %v", err))
}
lastTime := lastVote.Timestamp
// set the times to the same value and check equality
now := tmtime.Now()
lastVote.Timestamp = now
@ -418,10 +418,10 @@ func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.T
// returns true if the only difference in the proposals is their timestamp
func checkProposalsOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) {
var lastProposal, newProposal tmproto.CanonicalProposal
if err := proto.Unmarshal(lastSignBytes, &lastProposal); err != nil {
if err := protoio.UnmarshalDelimited(lastSignBytes, &lastProposal); err != nil {
panic(fmt.Sprintf("LastSignBytes cannot be unmarshalled into proposal: %v", err))
}
if err := proto.Unmarshal(newSignBytes, &newProposal); err != nil {
if err := protoio.UnmarshalDelimited(newSignBytes, &newProposal); err != nil {
panic(fmt.Sprintf("signBytes cannot be unmarshalled into proposal: %v", err))
}


+ 21
- 8
privval/file_test.go View File

@ -12,7 +12,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
tmjson "github.com/tendermint/tendermint/libs/json"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/types"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
@ -53,7 +55,8 @@ func TestResetValidator(t *testing.T) {
// test vote
height, round := int64(10), int32(1)
voteType := tmproto.PrevoteType
blockID := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
randBytes := tmrand.Bytes(tmhash.Size)
blockID := types.BlockID{Hash: randBytes, PartsHeader: types.PartSetHeader{}}
vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID)
err = privVal.SignVote("mychainid", vote.ToProto())
assert.NoError(t, err, "expected no error signing vote")
@ -163,8 +166,13 @@ func TestSignVote(t *testing.T) {
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
block2 := types.BlockID{Hash: []byte{3, 2, 1}, PartsHeader: types.PartSetHeader{}}
randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)
block1 := types.BlockID{Hash: randbytes,
PartsHeader: types.PartSetHeader{Total: 5, Hash: randbytes}}
block2 := types.BlockID{Hash: randbytes2,
PartsHeader: types.PartSetHeader{Total: 10, Hash: randbytes2}}
height, round := int64(10), int32(1)
voteType := tmproto.PrevoteType
@ -211,8 +219,13 @@ func TestSignProposal(t *testing.T) {
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{Total: 5, Hash: []byte{1, 2, 3}}}
block2 := types.BlockID{Hash: []byte{3, 2, 1}, PartsHeader: types.PartSetHeader{Total: 10, Hash: []byte{3, 2, 1}}}
randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)
block1 := types.BlockID{Hash: randbytes,
PartsHeader: types.PartSetHeader{Total: 5, Hash: randbytes}}
block2 := types.BlockID{Hash: randbytes2,
PartsHeader: types.PartSetHeader{Total: 10, Hash: randbytes2}}
height, round := int64(10), int32(1)
// sign a proposal for first time
@ -253,8 +266,8 @@ func TestDifferByTimestamp(t *testing.T) {
require.Nil(t, err)
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{Total: 5, Hash: []byte{1, 2, 3}}}
randbytes := tmrand.Bytes(tmhash.Size)
block1 := types.BlockID{Hash: randbytes, PartsHeader: types.PartSetHeader{Total: 5, Hash: randbytes}}
height, round := int64(10), int32(1)
chainID := "mychainid"
@ -284,7 +297,7 @@ func TestDifferByTimestamp(t *testing.T) {
// test vote
{
voteType := tmproto.PrevoteType
blockID := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
blockID := types.BlockID{Hash: randbytes, PartsHeader: types.PartSetHeader{}}
vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID)
v := vote.ToProto()
err := privVal.SignVote("mychainid", v)


+ 1
- 1
proto/consensus/walmsgs.pb.go View File

@ -7,9 +7,9 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/duration"
_ "github.com/golang/protobuf/ptypes/timestamp"
types "github.com/tendermint/tendermint/proto/types"
io "io"
math "math"


+ 1
- 1
proto/state/types.pb.go View File

@ -7,8 +7,8 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/timestamp"
types "github.com/tendermint/tendermint/abci/types"
types1 "github.com/tendermint/tendermint/proto/types"
version "github.com/tendermint/tendermint/proto/version"


+ 162
- 180
proto/types/canonical.pb.go View File

@ -4,11 +4,12 @@
package types
import (
encoding_binary "encoding/binary"
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/timestamp"
io "io"
math "math"
math_bits "math/bits"
@ -80,8 +81,8 @@ func (m *CanonicalBlockID) GetPartsHeader() CanonicalPartSetHeader {
}
type CanonicalPartSetHeader struct {
Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
Total uint32 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"`
Total uint32 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
}
func (m *CanonicalPartSetHeader) Reset() { *m = CanonicalPartSetHeader{} }
@ -117,28 +118,28 @@ func (m *CanonicalPartSetHeader) XXX_DiscardUnknown() {
var xxx_messageInfo_CanonicalPartSetHeader proto.InternalMessageInfo
func (m *CanonicalPartSetHeader) GetHash() []byte {
func (m *CanonicalPartSetHeader) GetTotal() uint32 {
if m != nil {
return m.Hash
return m.Total
}
return nil
return 0
}
func (m *CanonicalPartSetHeader) GetTotal() uint32 {
func (m *CanonicalPartSetHeader) GetHash() []byte {
if m != nil {
return m.Total
return m.Hash
}
return 0
return nil
}
type CanonicalProposal struct {
Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.proto.types.SignedMsgType" json:"type,omitempty"`
Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty" binary:" fixed64 "`
Round int64 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty" binary:" fixed64 "`
POLRound int64 `protobuf:"varint,4,opt,name=pol_round,json=polRound,proto3" json:"pol_round,omitempty"`
BlockID CanonicalBlockID `protobuf:"bytes,5,opt,name=block_id,json=blockId,proto3" json:"block_id"`
Timestamp time.Time `protobuf:"bytes,6,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
ChainID string `protobuf:"bytes,7,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.proto.types.SignedMsgType" json:"type,omitempty"`
Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"`
Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"`
POLRound int64 `protobuf:"varint,4,opt,name=pol_round,json=polRound,proto3" json:"pol_round,omitempty"`
BlockID *CanonicalBlockID `protobuf:"bytes,5,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"`
Timestamp time.Time `protobuf:"bytes,6,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
ChainID string `protobuf:"bytes,7,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
}
func (m *CanonicalProposal) Reset() { *m = CanonicalProposal{} }
@ -202,11 +203,11 @@ func (m *CanonicalProposal) GetPOLRound() int64 {
return 0
}
func (m *CanonicalProposal) GetBlockID() CanonicalBlockID {
func (m *CanonicalProposal) GetBlockID() *CanonicalBlockID {
if m != nil {
return m.BlockID
}
return CanonicalBlockID{}
return nil
}
func (m *CanonicalProposal) GetTimestamp() time.Time {
@ -224,12 +225,12 @@ func (m *CanonicalProposal) GetChainID() string {
}
type CanonicalVote struct {
Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.proto.types.SignedMsgType" json:"type,omitempty"`
Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty" binary:" fixed64 "`
Round int64 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty" binary:" fixed64 "`
BlockID CanonicalBlockID `protobuf:"bytes,5,opt,name=block_id,json=blockId,proto3" json:"block_id"`
Timestamp time.Time `protobuf:"bytes,6,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
ChainID string `protobuf:"bytes,7,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.proto.types.SignedMsgType" json:"type,omitempty"`
Height int64 `protobuf:"fixed64,2,opt,name=height,proto3" json:"height,omitempty"`
Round int64 `protobuf:"fixed64,3,opt,name=round,proto3" json:"round,omitempty"`
BlockID *CanonicalBlockID `protobuf:"bytes,4,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"`
Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
ChainID string `protobuf:"bytes,6,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
}
func (m *CanonicalVote) Reset() { *m = CanonicalVote{} }
@ -286,11 +287,11 @@ func (m *CanonicalVote) GetRound() int64 {
return 0
}
func (m *CanonicalVote) GetBlockID() CanonicalBlockID {
func (m *CanonicalVote) GetBlockID() *CanonicalBlockID {
if m != nil {
return m.BlockID
}
return CanonicalBlockID{}
return nil
}
func (m *CanonicalVote) GetTimestamp() time.Time {
@ -317,39 +318,38 @@ func init() {
func init() { proto.RegisterFile("proto/types/canonical.proto", fileDescriptor_3f9b1d584b46f180) }
var fileDescriptor_3f9b1d584b46f180 = []byte{
// 506 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0x4d, 0x8b, 0xd3, 0x40,
0x18, 0x6e, 0xb6, 0x5f, 0xe9, 0xb4, 0xeb, 0xc7, 0x20, 0x35, 0x54, 0x48, 0x42, 0xc0, 0xa5, 0xc2,
0x32, 0x81, 0x55, 0x04, 0x3d, 0x66, 0x45, 0x2c, 0x28, 0x2e, 0xd9, 0xa2, 0xe0, 0xa5, 0x4c, 0x92,
0xd9, 0x64, 0x30, 0xcd, 0x84, 0x64, 0x0a, 0xf6, 0xe4, 0x5f, 0xd8, 0xab, 0xff, 0x68, 0x8f, 0x3d,
0x7a, 0xaa, 0x92, 0xde, 0x3c, 0xfa, 0x0b, 0x64, 0x66, 0xfa, 0x75, 0xa8, 0x7a, 0xd5, 0x4b, 0x79,
0xe7, 0x99, 0xe7, 0x79, 0xde, 0xa7, 0xef, 0xbc, 0x04, 0x3c, 0xc8, 0x0b, 0xc6, 0x99, 0xcb, 0xe7,
0x39, 0x29, 0xdd, 0x10, 0x67, 0x2c, 0xa3, 0x21, 0x4e, 0x91, 0x44, 0x61, 0x9f, 0x93, 0x2c, 0x22,
0xc5, 0x94, 0x66, 0x5c, 0x21, 0x48, 0xf2, 0x06, 0x27, 0x3c, 0xa1,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x05, 0x00, 0x00,
0xff, 0xff, 0x79, 0xf8, 0x2b, 0x08, 0xb5, 0x04, 0x00, 0x00,
// 493 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x53, 0x41, 0x8b, 0xd3, 0x40,
0x14, 0x6e, 0xba, 0x69, 0x9b, 0x4e, 0xbb, 0xb2, 0x0e, 0x52, 0x43, 0x85, 0xa4, 0x14, 0x5c, 0x22,
0xc8, 0x04, 0xd6, 0x93, 0xd7, 0xac, 0x88, 0x05, 0xc5, 0x32, 0xbb, 0x28, 0x78, 0x29, 0xd3, 0x64,
0x4c, 0x06, 0xd3, 0x4c, 0x48, 0xa6, 0x87, 0x9e, 0xfc, 0x0b, 0xfb, 0x6b, 0xfc, 0x0d, 0x7b, 0xdc,
0xa3, 0xa7, 0x2a, 0x29, 0xfe, 0x0f, 0x99, 0x99, 0xb6, 0xe9, 0x61, 0x8b, 0x07, 0xc5, 0x4b, 0x78,
0xef, 0x7b, 0xef, 0x7d, 0xef, 0xcb, 0xf7, 0x18, 0xf0, 0x24, 0x2f, 0xb8, 0xe0, 0xbe, 0x58, 0xe5,
0xb4, 0xf4, 0x43, 0x92, 0xf1, 0x8c, 0x85, 0x24, 0x45, 0x0a, 0x85, 0x03, 0x41, 0xb3, 0x88, 0x16,
0x0b, 0x96, 0x09, 0x8d, 0x20, 0xd5, 0x37, 0x3c, 0x17, 0x09, 0x2b, 0xa2, 0x59, 0x4e, 0x0a, 0xb1,
0xf2, 0x35, 0x41, 0xcc, 0x63, 0x5e, 0x47, 0xba, 0x7b, 0xf8, 0xf8, 0x90, 0x5c, 0x7d, 0xb7, 0x05,
0x37, 0xe6, 0x3c, 0x4e, 0xa9, 0x9e, 0x9d, 0x2f, 0x3f, 0xfb, 0x82, 0x2d, 0x68, 0x29, 0xc8, 0x22,
0xd7, 0x0d, 0xe3, 0xaf, 0xe0, 0xec, 0x72, 0x27, 0x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 0xbb, 0x9d, 0x6d, 0x82, 0x3b, 0x8a, 0x66, 0x12, 0xc1, 0x00, 0x74, 0xf7, 0x37, 0xb5, 0xdb,
0x8a, 0x72, 0x88, 0xf4, 0xd5, 0xd1, 0xee, 0xea, 0xe8, 0x7a, 0xd7, 0x11, 0x58, 0xf2, 0x02, 0x37,
0x3f, 0x5c, 0x03, 0xd7, 0x63, 0xf0, 0x1c, 0x58, 0x61, 0x42, 0x58, 0x26, 0x55, 0x75, 0x46, 0x86,
0xd7, 0xd5, 0xbb, 0x2e, 0x25, 0x26, 0x77, 0xa9, 0xe2, 0x24, 0x1a, 0x7f, 0x6b, 0x82, 0xd3, 0xbd,
0xac, 0x0f, 0x5c, 0xd0, 0xff, 0xe7, 0xf1, 0xa1, 0x71, 0xe6, 0xbf, 0x37, 0xae, 0xf5, 0xf7, 0xc6,
0xb5, 0x8f, 0x1b, 0x17, 0xbc, 0xbe, 0xad, 0x1c, 0xe3, 0xae, 0x72, 0x8c, 0x9f, 0x95, 0x63, 0xdc,
0x6c, 0x9c, 0xc6, 0xdd, 0xc6, 0x69, 0x7c, 0xdf, 0x38, 0x8d, 0x4f, 0xcf, 0x63, 0x26, 0x92, 0xe5,
0x1c, 0x85, 0x7c, 0xe1, 0xd7, 0xff, 0x73, 0x18, 0x1e, 0x3c, 0xed, 0x79, 0x5b, 0x25, 0x2f, 0x7e,
0x07, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xd1, 0x62, 0xe9, 0x4d, 0x04, 0x00, 0x00,
}
func (m *CanonicalBlockID) Marshal() (dAtA []byte, err error) {
@ -412,17 +412,17 @@ func (m *CanonicalPartSetHeader) MarshalToSizedBuffer(dAtA []byte) (int, error)
_ = i
var l int
_ = l
if m.Total != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Total))
i--
dAtA[i] = 0x10
}
if len(m.Hash) > 0 {
i -= len(m.Hash)
copy(dAtA[i:], m.Hash)
i = encodeVarintCanonical(dAtA, i, uint64(len(m.Hash)))
i--
dAtA[i] = 0xa
dAtA[i] = 0x12
}
if m.Total != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Total))
i--
dAtA[i] = 0x8
}
return len(dAtA) - i, nil
}
@ -462,30 +462,34 @@ func (m *CanonicalProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i = encodeVarintCanonical(dAtA, i, uint64(n2))
i--
dAtA[i] = 0x32
{
size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
if m.BlockID != nil {
{
size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintCanonical(dAtA, i, uint64(size))
}
i -= size
i = encodeVarintCanonical(dAtA, i, uint64(size))
i--
dAtA[i] = 0x2a
}
i--
dAtA[i] = 0x2a
if m.POLRound != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.POLRound))
i--
dAtA[i] = 0x20
}
if m.Round != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Round))
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Round))
i--
dAtA[i] = 0x18
dAtA[i] = 0x19
}
if m.Height != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Height))
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Height))
i--
dAtA[i] = 0x10
dAtA[i] = 0x11
}
if m.Type != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Type))
@ -520,7 +524,7 @@ func (m *CanonicalVote) MarshalToSizedBuffer(dAtA []byte) (int, error) {
copy(dAtA[i:], m.ChainID)
i = encodeVarintCanonical(dAtA, i, uint64(len(m.ChainID)))
i--
dAtA[i] = 0x3a
dAtA[i] = 0x32
}
n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):])
if err4 != nil {
@ -529,26 +533,30 @@ func (m *CanonicalVote) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i -= n4
i = encodeVarintCanonical(dAtA, i, uint64(n4))
i--
dAtA[i] = 0x32
{
size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
dAtA[i] = 0x2a
if m.BlockID != nil {
{
size, err := m.BlockID.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintCanonical(dAtA, i, uint64(size))
}
i -= size
i = encodeVarintCanonical(dAtA, i, uint64(size))
i--
dAtA[i] = 0x22
}
i--
dAtA[i] = 0x2a
if m.Round != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Round))
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Round))
i--
dAtA[i] = 0x18
dAtA[i] = 0x19
}
if m.Height != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Height))
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Height))
i--
dAtA[i] = 0x10
dAtA[i] = 0x11
}
if m.Type != 0 {
i = encodeVarintCanonical(dAtA, i, uint64(m.Type))
@ -590,13 +598,13 @@ func (m *CanonicalPartSetHeader) Size() (n int) {
}
var l int
_ = l
if m.Total != 0 {
n += 1 + sovCanonical(uint64(m.Total))
}
l = len(m.Hash)
if l > 0 {
n += 1 + l + sovCanonical(uint64(l))
}
if m.Total != 0 {
n += 1 + sovCanonical(uint64(m.Total))
}
return n
}
@ -610,16 +618,18 @@ func (m *CanonicalProposal) Size() (n int) {
n += 1 + sovCanonical(uint64(m.Type))
}
if m.Height != 0 {
n += 1 + sovCanonical(uint64(m.Height))
n += 9
}
if m.Round != 0 {
n += 1 + sovCanonical(uint64(m.Round))
n += 9
}
if m.POLRound != 0 {
n += 1 + sovCanonical(uint64(m.POLRound))
}
l = m.BlockID.Size()
n += 1 + l + sovCanonical(uint64(l))
if m.BlockID != nil {
l = m.BlockID.Size()
n += 1 + l + sovCanonical(uint64(l))
}
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp)
n += 1 + l + sovCanonical(uint64(l))
l = len(m.ChainID)
@ -639,13 +649,15 @@ func (m *CanonicalVote) Size() (n int) {
n += 1 + sovCanonical(uint64(m.Type))
}
if m.Height != 0 {
n += 1 + sovCanonical(uint64(m.Height))
n += 9
}
if m.Round != 0 {
n += 1 + sovCanonical(uint64(m.Round))
n += 9
}
if m.BlockID != nil {
l = m.BlockID.Size()
n += 1 + l + sovCanonical(uint64(l))
}
l = m.BlockID.Size()
n += 1 + l + sovCanonical(uint64(l))
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp)
n += 1 + l + sovCanonical(uint64(l))
l = len(m.ChainID)
@ -811,6 +823,25 @@ func (m *CanonicalPartSetHeader) Unmarshal(dAtA []byte) error {
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType)
}
m.Total = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Total |= uint32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
}
@ -844,25 +875,6 @@ func (m *CanonicalPartSetHeader) Unmarshal(dAtA []byte) error {
m.Hash = []byte{}
}
iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType)
}
m.Total = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Total |= uint32(b&0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipCanonical(dAtA[iNdEx:])
@ -936,43 +948,25 @@ func (m *CanonicalProposal) Unmarshal(dAtA []byte) error {
}
}
case 2:
if wireType != 0 {
if wireType != 1 {
return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType)
}
m.Height = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Height |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
if (iNdEx + 8) > l {
return io.ErrUnexpectedEOF
}
m.Height = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:]))
iNdEx += 8
case 3:
if wireType != 0 {
if wireType != 1 {
return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType)
}
m.Round = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Round |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
if (iNdEx + 8) > l {
return io.ErrUnexpectedEOF
}
m.Round = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:]))
iNdEx += 8
case 4:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field POLRound", wireType)
@ -1021,6 +1015,9 @@ func (m *CanonicalProposal) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.BlockID == nil {
m.BlockID = &CanonicalBlockID{}
}
if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -1163,44 +1160,26 @@ func (m *CanonicalVote) Unmarshal(dAtA []byte) error {
}
}
case 2:
if wireType != 0 {
if wireType != 1 {
return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType)
}
m.Height = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Height |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
if (iNdEx + 8) > l {
return io.ErrUnexpectedEOF
}
m.Height = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:]))
iNdEx += 8
case 3:
if wireType != 0 {
if wireType != 1 {
return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType)
}
m.Round = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowCanonical
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Round |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
if (iNdEx + 8) > l {
return io.ErrUnexpectedEOF
}
case 5:
m.Round = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:]))
iNdEx += 8
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BlockID", wireType)
}
@ -1229,11 +1208,14 @@ func (m *CanonicalVote) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.BlockID == nil {
m.BlockID = &CanonicalBlockID{}
}
if err := m.BlockID.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 6:
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType)
}
@ -1266,7 +1248,7 @@ func (m *CanonicalVote) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 7:
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType)
}


+ 10
- 10
proto/types/canonical.proto View File

@ -13,25 +13,25 @@ message CanonicalBlockID {
}
message CanonicalPartSetHeader {
bytes hash = 1;
uint32 total = 2;
uint32 total = 1;
bytes hash = 2;
}
message CanonicalProposal {
SignedMsgType type = 1; // type alias for byte
int64 height = 2 [(gogoproto.moretags) = "binary:\" fixed64 \""];
int64 round = 3 [(gogoproto.moretags) = "binary:\" fixed64 \""];
sfixed64 height = 2; // canonicalization requires fixed size encoding here
sfixed64 round = 3; // canonicalization requires fixed size encoding here
int64 pol_round = 4 [(gogoproto.customname) = "POLRound"];
CanonicalBlockID block_id = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"];
CanonicalBlockID block_id = 5 [(gogoproto.customname) = "BlockID"];
google.protobuf.Timestamp timestamp = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
string chain_id = 7 [(gogoproto.customname) = "ChainID"];
}
message CanonicalVote {
SignedMsgType type = 1; // type alias for byte
int64 height = 2 [(gogoproto.moretags) = "binary:\" fixed64 \""];
int64 round = 3 [(gogoproto.moretags) = "binary:\" fixed64 \""];
CanonicalBlockID block_id = 5 [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"];
google.protobuf.Timestamp timestamp = 6 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
string chain_id = 7 [(gogoproto.customname) = "ChainID"];
sfixed64 height = 2; // canonicalization requires fixed size encoding here
sfixed64 round = 3; // canonicalization requires fixed size encoding here
CanonicalBlockID block_id = 4 [(gogoproto.customname) = "BlockID"];
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
string chain_id = 6 [(gogoproto.customname) = "ChainID"];
}

+ 1
- 1
proto/types/evidence.pb.go View File

@ -7,8 +7,8 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/timestamp"
keys "github.com/tendermint/tendermint/proto/crypto/keys"
io "io"
math "math"


+ 11
- 9
proto/types/types.pb.go View File

@ -7,8 +7,8 @@ import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
_ "github.com/golang/protobuf/ptypes/timestamp"
merkle "github.com/tendermint/tendermint/proto/crypto/merkle"
bits "github.com/tendermint/tendermint/proto/libs/bits"
version "github.com/tendermint/tendermint/proto/version"
@ -67,23 +67,25 @@ type SignedMsgType int32
const (
SIGNED_MSG_TYPE_UNKNOWN SignedMsgType = 0
PrevoteType SignedMsgType = 1
PrecommitType SignedMsgType = 2
ProposalType SignedMsgType = 3
// Votes
PrevoteType SignedMsgType = 1
PrecommitType SignedMsgType = 2
// Proposals
ProposalType SignedMsgType = 32
)
var SignedMsgType_name = map[int32]string{
0: "SIGNED_MSG_TYPE_UNKNOWN",
1: "PREVOTE_TYPE",
2: "PRECOMMIT_TYPE",
3: "PROPOSAL_TYPE",
0: "SIGNED_MSG_TYPE_UNKNOWN",
1: "PREVOTE_TYPE",
2: "PRECOMMIT_TYPE",
32: "PROPOSAL_TYPE",
}
var SignedMsgType_value = map[string]int32{
"SIGNED_MSG_TYPE_UNKNOWN": 0,
"PREVOTE_TYPE": 1,
"PRECOMMIT_TYPE": 2,
"PROPOSAL_TYPE": 3,
"PROPOSAL_TYPE": 32,
}
func (x SignedMsgType) String() string {


+ 4
- 1
proto/types/types.proto View File

@ -26,9 +26,12 @@ enum SignedMsgType {
option (gogoproto.goproto_enum_prefix) = false;
SIGNED_MSG_TYPE_UNKNOWN = 0;
// Votes
PREVOTE_TYPE = 1 [(gogoproto.enumvalue_customname) = "PrevoteType"];
PRECOMMIT_TYPE = 2 [(gogoproto.enumvalue_customname) = "PrecommitType"];
PROPOSAL_TYPE = 3 [(gogoproto.enumvalue_customname) = "ProposalType"];
// Proposals
PROPOSAL_TYPE = 32 [(gogoproto.enumvalue_customname) = "ProposalType"];
}
// PartsetHeader


+ 1
- 1
scripts/protocgen.sh View File

@ -6,6 +6,6 @@ proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xarg
for dir in $proto_dirs; do
protoc \
-I. \
--gogofaster_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,plugins=grpc,paths=source_relative:. \
--gogofaster_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,plugins=grpc,paths=source_relative:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

+ 1
- 0
types/block.go View File

@ -1306,6 +1306,7 @@ func BlockIDFromProto(bID *tmproto.BlockID) (*BlockID, error) {
if bID == nil {
return nil, errors.New("nil BlockID")
}
blockID := new(BlockID)
ph, err := PartSetHeaderFromProto(&bID.PartsHeader)
if err != nil {


+ 20
- 12
types/canonical.go View File

@ -15,25 +15,33 @@ const TimeFormat = time.RFC3339Nano
//-----------------------------------
// Canonicalize the structs
func CanonicalizeBlockID(blockID tmproto.BlockID) tmproto.CanonicalBlockID {
return tmproto.CanonicalBlockID{
Hash: blockID.Hash,
PartsHeader: CanonicalizePartSetHeader(blockID.PartsHeader),
func CanonicalizeBlockID(bid tmproto.BlockID) *tmproto.CanonicalBlockID {
rbid, err := BlockIDFromProto(&bid)
if err != nil {
panic(err)
}
var cbid *tmproto.CanonicalBlockID
if rbid == nil || rbid.IsZero() {
cbid = nil
} else {
cbid = &tmproto.CanonicalBlockID{
Hash: bid.Hash,
PartsHeader: CanonicalizePartSetHeader(bid.PartsHeader),
}
}
return cbid
}
func CanonicalizePartSetHeader(psh tmproto.PartSetHeader) tmproto.CanonicalPartSetHeader {
return tmproto.CanonicalPartSetHeader{
Hash: psh.Hash,
Total: psh.Total,
}
return tmproto.CanonicalPartSetHeader(psh)
}
func CanonicalizeProposal(chainID string, proposal *tmproto.Proposal) tmproto.CanonicalProposal {
return tmproto.CanonicalProposal{
Type: tmproto.ProposalType,
Height: proposal.Height,
Round: int64(proposal.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
Height: proposal.Height, // encoded as sfixed64
Round: int64(proposal.Round), // encoded as sfixed64
POLRound: int64(proposal.PolRound),
BlockID: CanonicalizeBlockID(proposal.BlockID),
Timestamp: proposal.Timestamp,
@ -44,8 +52,8 @@ func CanonicalizeProposal(chainID string, proposal *tmproto.Proposal) tmproto.Ca
func CanonicalizeVote(chainID string, vote *tmproto.Vote) tmproto.CanonicalVote {
return tmproto.CanonicalVote{
Type: vote.Type,
Height: vote.Height,
Round: int64(vote.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
Height: vote.Height, // encoded as sfixed64
Round: int64(vote.Round), // encoded as sfixed64
BlockID: CanonicalizeBlockID(vote.BlockID),
Timestamp: vote.Timestamp,
ChainID: chainID,


+ 39
- 0
types/canonical_test.go View File

@ -0,0 +1,39 @@
package types
import (
"reflect"
"testing"
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/types"
)
func TestCanonicalizeBlockID(t *testing.T) {
randhash := tmrand.Bytes(tmhash.Size)
block1 := tmproto.BlockID{Hash: randhash,
PartsHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
block2 := tmproto.BlockID{Hash: randhash,
PartsHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}}
cblock1 := tmproto.CanonicalBlockID{Hash: randhash,
PartsHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}}
cblock2 := tmproto.CanonicalBlockID{Hash: randhash,
PartsHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}}
tests := []struct {
name string
args tmproto.BlockID
want *tmproto.CanonicalBlockID
}{
{"first", block1, &cblock1},
{"second", block2, &cblock2},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := CanonicalizeBlockID(tt.args); !reflect.DeepEqual(got, tt.want) {
t.Errorf("CanonicalizeBlockID() = %v, want %v", got, tt.want)
}
})
}
}

+ 5
- 5
types/proposal.go View File

@ -5,9 +5,8 @@ import (
"fmt"
"time"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/libs/bytes"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/protoio"
tmproto "github.com/tendermint/tendermint/proto/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -87,17 +86,18 @@ func (p *Proposal) String() string {
p.Round,
p.BlockID,
p.POLRound,
bytes.Fingerprint(p.Signature),
tmbytes.Fingerprint(p.Signature),
CanonicalTime(p.Timestamp))
}
// ProposalSignBytes returns the Proposal bytes for signing
func ProposalSignBytes(chainID string, p *tmproto.Proposal) []byte {
pb := CanonicalizeProposal(chainID, p)
bz, err := proto.Marshal(&pb)
bz, err := protoio.MarshalDelimited(&pb)
if err != nil {
panic(err)
}
return bz
}


+ 8
- 5
types/proposal_test.go View File

@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/protoio"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/types"
)
@ -25,9 +26,10 @@ func init() {
panic(err)
}
testProposal = &Proposal{
Height: 12345,
Round: 23456,
BlockID: BlockID{[]byte{1, 2, 3}, PartSetHeader{111, []byte("blockparts")}},
Height: 12345,
Round: 23456,
BlockID: BlockID{Hash: []byte("--June_15_2020_amino_was_removed"),
PartsHeader: PartSetHeader{Total: 111, Hash: []byte("--June_15_2020_amino_was_removed")}},
POLRound: -1,
Timestamp: stamp,
}
@ -38,14 +40,15 @@ func TestProposalSignable(t *testing.T) {
chainID := "test_chain_id"
signBytes := ProposalSignBytes(chainID, pbp)
pb := CanonicalizeProposal(chainID, pbp)
expected, err := proto.Marshal(&pb)
expected, err := protoio.MarshalDelimited(&pb)
require.NoError(t, err)
require.Equal(t, expected, signBytes, "Got unexpected sign bytes for Proposal")
}
func TestProposalString(t *testing.T) {
str := testProposal.String()
expected := `Proposal{12345/23456 (010203:111:626C6F636B70, -1) 000000000000 @ 2018-02-11T07:09:22.765Z}`
expected := `Proposal{12345/23456 (2D2D4A756E655F31355F323032305F616D696E6F5F7761735F72656D6F766564:111:2D2D4A756E65, -1) 000000000000 @ 2018-02-11T07:09:22.765Z}` //nolint:lll // ignore line length for tests
if str != expected {
t.Errorf("got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str)
}


+ 3
- 3
types/vote.go View File

@ -6,10 +6,9 @@ import (
"fmt"
"time"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/protoio"
tmproto "github.com/tendermint/tendermint/proto/types"
)
@ -87,10 +86,11 @@ func (vote *Vote) CommitSig() CommitSig {
// If any error arises this will panic
func VoteSignBytes(chainID string, vote *tmproto.Vote) []byte {
pb := CanonicalizeVote(chainID, vote)
bz, err := proto.Marshal(&pb)
bz, err := protoio.MarshalDelimited(&pb)
if err != nil {
panic(err)
}
return bz
}


+ 47
- 13
types/vote_test.go View File

@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/protoio"
tmproto "github.com/tendermint/tendermint/proto/types"
)
@ -51,8 +52,7 @@ func TestVoteSignable(t *testing.T) {
v := vote.ToProto()
signBytes := VoteSignBytes("test_chain_id", v)
pb := CanonicalizeVote("test_chain_id", v)
expected, err := proto.Marshal(&pb)
expected, err := protoio.MarshalDelimited(&pb)
require.NoError(t, err)
require.Equal(t, expected, signBytes, "Got unexpected sign bytes for Vote.")
@ -68,38 +68,72 @@ func TestVoteSignBytesTestVectors(t *testing.T) {
0: {
"", &Vote{},
// NOTE: Height and Round are skipped here. This case needs to be considered while parsing.
[]byte{0x2a, 0x2, 0x12, 0x0, 0x32, 0xb, 0x8, 0x80, 0x92, 0xb8,
0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
[]byte{0xd, 0x2a, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// with proper (fixed size) height and round (PreCommit):
1: {
"", &Vote{Height: 1, Round: 1, Type: tmproto.PrecommitType},
[]byte{0x8, 0x2, 0x10, 0x1, 0x18, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x32,
[]byte{
0x21, // length
0x8, // (field_number << 3) | wire_type
0x2, // PrecommitType
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
0x2a, // (field_number << 3) | wire_type
// remaining fields (timestamp):
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// with proper (fixed size) height and round (PreVote):
2: {
"", &Vote{Height: 1, Round: 1, Type: tmproto.PrevoteType},
[]byte{0x8, 0x1, 0x10, 0x1, 0x18, 0x1, 0x2a, 0x2, 0x12, 0x0,
0x32, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
[]byte{
0x21, // length
0x8, // (field_number << 3) | wire_type
0x1, // PrevoteType
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
0x2a, // (field_number << 3) | wire_type
// remaining fields (timestamp):
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
3: {
"", &Vote{Height: 1, Round: 1},
[]byte{0x10, 0x1, 0x18, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x32, 0xb,
0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
[]byte{
0x1f, // length
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
// remaining fields (timestamp):
0x2a,
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// containing non-empty chain_id:
4: {
"test_chain_id", &Vote{Height: 1, Round: 1},
[]byte{0x10, 0x1, 0x18, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x32, 0xb, 0x8,
0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x3a, 0xd,
0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64},
[]byte{
0x2e, // length
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
// remaining fields:
0x2a, // (field_number << 3) | wire_type
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, // timestamp
// (field_number << 3) | wire_type
0x32,
0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID
},
}
for i, tc := range tests {
v := tc.vote.ToProto()
got := VoteSignBytes(tc.chainID, v)
require.Equal(t, tc.want, got, "test case #%v: got unexpected sign bytes for Vote.", i)
assert.Equal(t, len(tc.want), len(got), "test case #%v: got unexpected sign bytes length for Vote.", i)
assert.Equal(t, tc.want, got, "test case #%v: got unexpected sign bytes for Vote.", i)
}
}


Loading…
Cancel
Save