From 82104c93293097a41c32023d9b14e7bd06b46149 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Tue, 12 Jun 2018 23:49:16 -0700 Subject: [PATCH 1/8] almost --- types/proto3/block.proto | 44 ++++++++++++++++++++++++++++++ types/proto3_test.go | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 types/proto3/block.proto create mode 100644 types/proto3_test.go diff --git a/types/proto3/block.proto b/types/proto3/block.proto new file mode 100644 index 000000000..d1c5cb928 --- /dev/null +++ b/types/proto3/block.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package proto3; + + +message PartSetHeader { + sint32 Total = 1; + bytes Hash = 2; +} + +message BlockID { + bytes Hash = 1; + PartSetHeader PartsHeader = 2; +} + +message Header { + // basic block info + string ChainID = 1; + sint64 Height = 2; + Timestamp Time = 3; + sint64 NumTxs = 4; + + // prev block info + BlockID LastBlockID = 5; + sint64 TotalTxs = 6; + + // hashes of block data + bytes LastCommitHash = 7; // commit from validators from the last block + bytes DataHash = 8; // transactions + + // hashes from the app output from the prev block + bytes ValidatorsHash = 9; // validators for the current block + bytes ConsensusHash = 10; // consensus params for current block + bytes AppHash = 11; // state after txs from the previous block + bytes LastResultsHash = 12; // root hash of all results from the txs from the previous block + + // consensus info + bytes EvidenceHash = 13; // evidence included in the block +} + +message Timestamp { + sint64 seconds = 1; + sint32 nanos = 2; +} diff --git a/types/proto3_test.go b/types/proto3_test.go new file mode 100644 index 000000000..244551fe2 --- /dev/null +++ b/types/proto3_test.go @@ -0,0 +1,59 @@ +package types + +import ( + "testing" + "github.com/tendermint/tendermint/types/proto3" + "github.com/stretchr/testify/assert" + "github.com/golang/protobuf/proto" + "time" +) + +func TestProto3Compatibility(t *testing.T) { + // TODO(ismail): table tests instead... + tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006") + assert.NoError(t, err) + + pbHeader := proto3.Header{ + ChainID: "cosmos", + Height:150, + Time: &proto3.Timestamp{Seconds:tm.Unix(), Nanos:int32(tm.Nanosecond())}, + NumTxs: 7, + LastBlockID: &proto3.BlockID{ + Hash: []byte("some serious hashing"), + PartsHeader:&proto3.PartSetHeader{ + Total: 8, + Hash: []byte("some more serious hashing"), + }, + }, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + + } + // TODO(ismail): add another test where parts are missing (to see if default values are treated equiv.) + aminoHeader := Header{ + ChainID: "cosmos", + Height:150, + Time: tm, + NumTxs: 7, + LastBlockID: BlockID{ + Hash: []byte("some serious hashing"), + PartsHeader: PartSetHeader{ + Total: 8, + Hash: []byte("some more serious hashing"), + }, + }, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + } + ab, err := cdc.MarshalBinaryBare(aminoHeader) + assert.NoError(t, err, "unexpected error") + + pb, err := proto.Marshal(&pbHeader) + assert.NoError(t, err, "unexpected error") + // This works: + assert.Equal(t, ab, pb, "encoding doesn't match") +} From 99fa7f8132366c2c42f941c9886151cd97622a7a Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 13 Jun 2018 00:43:06 -0700 Subject: [PATCH 2/8] everything works with https://github.com/tendermint/go-amino/pull/178 --- types/proto3/block.proto | 4 ++-- types/proto3_test.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/types/proto3/block.proto b/types/proto3/block.proto index d1c5cb928..771bc828b 100644 --- a/types/proto3/block.proto +++ b/types/proto3/block.proto @@ -39,6 +39,6 @@ message Header { } message Timestamp { - sint64 seconds = 1; - sint32 nanos = 2; + sfixed64 seconds = 1; + sfixed32 nanos = 2; } diff --git a/types/proto3_test.go b/types/proto3_test.go index 244551fe2..bffe1cf75 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -12,11 +12,12 @@ func TestProto3Compatibility(t *testing.T) { // TODO(ismail): table tests instead... tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006") assert.NoError(t, err) - + seconds := tm.Unix() + nanos := int32(tm.Nanosecond()) pbHeader := proto3.Header{ ChainID: "cosmos", Height:150, - Time: &proto3.Timestamp{Seconds:tm.Unix(), Nanos:int32(tm.Nanosecond())}, + Time: &proto3.Timestamp{Seconds:seconds, Nanos:nanos}, NumTxs: 7, LastBlockID: &proto3.BlockID{ Hash: []byte("some serious hashing"), From 0cd82fa166ed0f91a7cc7e62f4815f714595101a Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 13 Jun 2018 01:11:21 -0700 Subject: [PATCH 3/8] add empty struct examples --- types/proto3_test.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/types/proto3_test.go b/types/proto3_test.go index bffe1cf75..e06341821 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -9,7 +9,6 @@ import ( ) func TestProto3Compatibility(t *testing.T) { - // TODO(ismail): table tests instead... tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006") assert.NoError(t, err) seconds := tm.Unix() @@ -32,7 +31,6 @@ func TestProto3Compatibility(t *testing.T) { ValidatorsHash:[]byte("validators hash"), } - // TODO(ismail): add another test where parts are missing (to see if default values are treated equiv.) aminoHeader := Header{ ChainID: "cosmos", Height:150, @@ -57,4 +55,37 @@ func TestProto3Compatibility(t *testing.T) { assert.NoError(t, err, "unexpected error") // This works: assert.Equal(t, ab, pb, "encoding doesn't match") + + emptyLastBlockPb := proto3.Header{ + ChainID: "cosmos", + Height:150, + Time: &proto3.Timestamp{Seconds:seconds, Nanos:nanos}, + NumTxs: 7, + LastBlockID: &proto3.BlockID{ + PartsHeader: &proto3.PartSetHeader{}, + }, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + + } + emptyLastBlockAm := Header{ + ChainID: "cosmos", + Height:150, + Time: tm, + NumTxs: 7, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + } + + ab, err = cdc.MarshalBinaryBare(emptyLastBlockAm) + assert.NoError(t, err, "unexpected error") + + pb, err = proto.Marshal(&emptyLastBlockPb) + assert.NoError(t, err, "unexpected error") + // This works: + assert.Equal(t, ab, pb, "encoding doesn't match") } From 3c38a25bbbfc0c1ffa52c4f3bdc9290da2f92c08 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 13 Jun 2018 12:08:59 -0700 Subject: [PATCH 4/8] add empty struct examples --- types/proto3/block.pb.go | 257 +++++++++++++++++++++++++++++++++++++++ types/proto3_test.go | 1 + 2 files changed, 258 insertions(+) create mode 100644 types/proto3/block.pb.go diff --git a/types/proto3/block.pb.go b/types/proto3/block.pb.go new file mode 100644 index 000000000..96d5d34f8 --- /dev/null +++ b/types/proto3/block.pb.go @@ -0,0 +1,257 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: block.proto + +/* +Package proto3 is a generated protocol buffer package. + +It is generated from these files: + block.proto + +It has these top-level messages: + PartSetHeader + BlockID + Header + Timestamp +*/ +package proto3 + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type PartSetHeader struct { + Total int32 `protobuf:"zigzag32,1,opt,name=Total" json:"Total,omitempty"` + Hash []byte `protobuf:"bytes,2,opt,name=Hash,proto3" json:"Hash,omitempty"` +} + +func (m *PartSetHeader) Reset() { *m = PartSetHeader{} } +func (m *PartSetHeader) String() string { return proto.CompactTextString(m) } +func (*PartSetHeader) ProtoMessage() {} +func (*PartSetHeader) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +func (m *PartSetHeader) GetTotal() int32 { + if m != nil { + return m.Total + } + return 0 +} + +func (m *PartSetHeader) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +type BlockID struct { + Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` + PartsHeader *PartSetHeader `protobuf:"bytes,2,opt,name=PartsHeader" json:"PartsHeader,omitempty"` +} + +func (m *BlockID) Reset() { *m = BlockID{} } +func (m *BlockID) String() string { return proto.CompactTextString(m) } +func (*BlockID) ProtoMessage() {} +func (*BlockID) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *BlockID) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *BlockID) GetPartsHeader() *PartSetHeader { + if m != nil { + return m.PartsHeader + } + return nil +} + +type Header struct { + // basic block info + ChainID string `protobuf:"bytes,1,opt,name=ChainID" json:"ChainID,omitempty"` + Height int64 `protobuf:"zigzag64,2,opt,name=Height" json:"Height,omitempty"` + Time *Timestamp `protobuf:"bytes,3,opt,name=Time" json:"Time,omitempty"` + NumTxs int64 `protobuf:"zigzag64,4,opt,name=NumTxs" json:"NumTxs,omitempty"` + // prev block info + LastBlockID *BlockID `protobuf:"bytes,5,opt,name=LastBlockID" json:"LastBlockID,omitempty"` + TotalTxs int64 `protobuf:"zigzag64,6,opt,name=TotalTxs" json:"TotalTxs,omitempty"` + // hashes of block data + LastCommitHash []byte `protobuf:"bytes,7,opt,name=LastCommitHash,proto3" json:"LastCommitHash,omitempty"` + DataHash []byte `protobuf:"bytes,8,opt,name=DataHash,proto3" json:"DataHash,omitempty"` + // hashes from the app output from the prev block + ValidatorsHash []byte `protobuf:"bytes,9,opt,name=ValidatorsHash,proto3" json:"ValidatorsHash,omitempty"` + ConsensusHash []byte `protobuf:"bytes,10,opt,name=ConsensusHash,proto3" json:"ConsensusHash,omitempty"` + AppHash []byte `protobuf:"bytes,11,opt,name=AppHash,proto3" json:"AppHash,omitempty"` + LastResultsHash []byte `protobuf:"bytes,12,opt,name=LastResultsHash,proto3" json:"LastResultsHash,omitempty"` + // consensus info + EvidenceHash []byte `protobuf:"bytes,13,opt,name=EvidenceHash,proto3" json:"EvidenceHash,omitempty"` +} + +func (m *Header) Reset() { *m = Header{} } +func (m *Header) String() string { return proto.CompactTextString(m) } +func (*Header) ProtoMessage() {} +func (*Header) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *Header) GetChainID() string { + if m != nil { + return m.ChainID + } + return "" +} + +func (m *Header) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Header) GetTime() *Timestamp { + if m != nil { + return m.Time + } + return nil +} + +func (m *Header) GetNumTxs() int64 { + if m != nil { + return m.NumTxs + } + return 0 +} + +func (m *Header) GetLastBlockID() *BlockID { + if m != nil { + return m.LastBlockID + } + return nil +} + +func (m *Header) GetTotalTxs() int64 { + if m != nil { + return m.TotalTxs + } + return 0 +} + +func (m *Header) GetLastCommitHash() []byte { + if m != nil { + return m.LastCommitHash + } + return nil +} + +func (m *Header) GetDataHash() []byte { + if m != nil { + return m.DataHash + } + return nil +} + +func (m *Header) GetValidatorsHash() []byte { + if m != nil { + return m.ValidatorsHash + } + return nil +} + +func (m *Header) GetConsensusHash() []byte { + if m != nil { + return m.ConsensusHash + } + return nil +} + +func (m *Header) GetAppHash() []byte { + if m != nil { + return m.AppHash + } + return nil +} + +func (m *Header) GetLastResultsHash() []byte { + if m != nil { + return m.LastResultsHash + } + return nil +} + +func (m *Header) GetEvidenceHash() []byte { + if m != nil { + return m.EvidenceHash + } + return nil +} + +type Timestamp struct { + Seconds int64 `protobuf:"fixed64,1,opt,name=seconds" json:"seconds,omitempty"` + Nanos int32 `protobuf:"fixed32,2,opt,name=nanos" json:"nanos,omitempty"` +} + +func (m *Timestamp) Reset() { *m = Timestamp{} } +func (m *Timestamp) String() string { return proto.CompactTextString(m) } +func (*Timestamp) ProtoMessage() {} +func (*Timestamp) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func (m *Timestamp) GetSeconds() int64 { + if m != nil { + return m.Seconds + } + return 0 +} + +func (m *Timestamp) GetNanos() int32 { + if m != nil { + return m.Nanos + } + return 0 +} + +func init() { + proto.RegisterType((*PartSetHeader)(nil), "proto3.PartSetHeader") + proto.RegisterType((*BlockID)(nil), "proto3.BlockID") + proto.RegisterType((*Header)(nil), "proto3.Header") + proto.RegisterType((*Timestamp)(nil), "proto3.Timestamp") +} + +func init() { proto.RegisterFile("block.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 372 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x4f, 0x6b, 0xe3, 0x30, + 0x10, 0xc5, 0xf1, 0xe6, 0xff, 0x38, 0xd9, 0x6c, 0x86, 0xdd, 0xc5, 0xf4, 0x14, 0x4c, 0x5b, 0x72, + 0x0a, 0xb4, 0x39, 0x94, 0xd2, 0x53, 0x9b, 0x14, 0x12, 0x28, 0xa5, 0xa8, 0x21, 0x77, 0x25, 0x16, + 0x8d, 0xa9, 0x2d, 0x19, 0x4b, 0x29, 0xfd, 0x7c, 0xfd, 0x64, 0x45, 0x23, 0xdb, 0x8d, 0x73, 0x4a, + 0xde, 0x9b, 0x37, 0xbf, 0x91, 0x47, 0x02, 0x7f, 0x9b, 0xa8, 0xdd, 0xfb, 0x34, 0xcb, 0x95, 0x51, + 0xd8, 0xa6, 0x9f, 0x59, 0x78, 0x0b, 0x83, 0x17, 0x9e, 0x9b, 0x57, 0x61, 0x96, 0x82, 0x47, 0x22, + 0xc7, 0xbf, 0xd0, 0x5a, 0x2b, 0xc3, 0x93, 0xc0, 0x1b, 0x7b, 0x93, 0x11, 0x73, 0x02, 0x11, 0x9a, + 0x4b, 0xae, 0xf7, 0xc1, 0xaf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c4, 0x09, 0x0c, 0xed, 0xa9, + 0x98, 0xd0, 0x87, 0xc4, 0x38, 0x42, 0x9f, 0x12, 0xa7, 0x36, 0x86, 0xd0, 0x7f, 0xfc, 0x88, 0x23, + 0x21, 0x77, 0x82, 0x62, 0x03, 0x8a, 0xd5, 0xbc, 0xf0, 0x0e, 0x7a, 0xd5, 0xce, 0xed, 0x50, 0x2d, + 0x76, 0x4a, 0x46, 0x9a, 0xae, 0xf1, 0x0f, 0x2b, 0xa5, 0x7d, 0x6d, 0x92, 0x4b, 0xa5, 0xe9, 0x16, + 0x87, 0xcc, 0x89, 0x6d, 0xf1, 0x38, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x74, 0x2f, 0xbd, + 0xb2, 0x02, 0x00, 0x00, +} diff --git a/types/proto3_test.go b/types/proto3_test.go index e06341821..0ab14ea3a 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -61,6 +61,7 @@ func TestProto3Compatibility(t *testing.T) { Height:150, Time: &proto3.Timestamp{Seconds:seconds, Nanos:nanos}, NumTxs: 7, + // TODO(ismail): as Jae suggested, we'll add a flag to make this obsolete: LastBlockID: &proto3.BlockID{ PartsHeader: &proto3.PartSetHeader{}, }, From d665c79cc9463779f40cbce6ea2cc522003ad5c2 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 20 Jun 2018 15:15:05 -0700 Subject: [PATCH 5/8] WIP: more empty struct examples --- types/proto3_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/proto3_test.go b/types/proto3_test.go index 0ab14ea3a..ba5fe4902 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -89,4 +89,13 @@ func TestProto3Compatibility(t *testing.T) { assert.NoError(t, err, "unexpected error") // This works: assert.Equal(t, ab, pb, "encoding doesn't match") + + pb, err = proto.Marshal(&proto3.Header{}) + assert.NoError(t, err, "unexpected error") + t.Log(pb) + + pb, err = proto.Marshal(&proto3.Timestamp{}) + assert.NoError(t, err, "unexpected error") + t.Log(pb) + } From 2744682e77c7bb035a8dc53ab4e8c0daf590b540 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 18 Jul 2018 15:53:53 +0200 Subject: [PATCH 6/8] update to latest amino (pre) release v0.11.1 - also reformat code and order imports --- Gopkg.toml | 2 +- types/proto3_test.go | 66 ++++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Gopkg.toml b/Gopkg.toml index 19fa68944..09ba364cc 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -63,7 +63,7 @@ [[constraint]] name = "github.com/tendermint/go-amino" - version = "=0.10.1" + version = "=v0.11.1" [[constraint]] name = "google.golang.org/grpc" diff --git a/types/proto3_test.go b/types/proto3_test.go index ba5fe4902..c19296cad 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -2,10 +2,12 @@ package types import ( "testing" - "github.com/tendermint/tendermint/types/proto3" - "github.com/stretchr/testify/assert" - "github.com/golang/protobuf/proto" "time" + + "github.com/golang/protobuf/proto" + "github.com/stretchr/testify/assert" + + "github.com/tendermint/tendermint/types/proto3" ) func TestProto3Compatibility(t *testing.T) { @@ -15,38 +17,37 @@ func TestProto3Compatibility(t *testing.T) { nanos := int32(tm.Nanosecond()) pbHeader := proto3.Header{ ChainID: "cosmos", - Height:150, - Time: &proto3.Timestamp{Seconds:seconds, Nanos:nanos}, - NumTxs: 7, + Height: 150, + Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos}, + NumTxs: 7, LastBlockID: &proto3.BlockID{ Hash: []byte("some serious hashing"), - PartsHeader:&proto3.PartSetHeader{ + PartsHeader: &proto3.PartSetHeader{ Total: 8, - Hash: []byte("some more serious hashing"), + Hash: []byte("some more serious hashing"), }, }, - TotalTxs: 100, + TotalTxs: 100, LastCommitHash: []byte("commit hash"), - DataHash: []byte("data hash"), - ValidatorsHash:[]byte("validators hash"), - + DataHash: []byte("data hash"), + ValidatorsHash: []byte("validators hash"), } aminoHeader := Header{ ChainID: "cosmos", - Height:150, - Time: tm, - NumTxs: 7, + Height: 150, + Time: tm, + NumTxs: 7, LastBlockID: BlockID{ Hash: []byte("some serious hashing"), PartsHeader: PartSetHeader{ Total: 8, - Hash: []byte("some more serious hashing"), + Hash: []byte("some more serious hashing"), }, }, - TotalTxs: 100, + TotalTxs: 100, LastCommitHash: []byte("commit hash"), - DataHash: []byte("data hash"), - ValidatorsHash:[]byte("validators hash"), + DataHash: []byte("data hash"), + ValidatorsHash: []byte("validators hash"), } ab, err := cdc.MarshalBinaryBare(aminoHeader) assert.NoError(t, err, "unexpected error") @@ -58,28 +59,27 @@ func TestProto3Compatibility(t *testing.T) { emptyLastBlockPb := proto3.Header{ ChainID: "cosmos", - Height:150, - Time: &proto3.Timestamp{Seconds:seconds, Nanos:nanos}, - NumTxs: 7, + Height: 150, + Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos}, + NumTxs: 7, // TODO(ismail): as Jae suggested, we'll add a flag to make this obsolete: LastBlockID: &proto3.BlockID{ PartsHeader: &proto3.PartSetHeader{}, }, - TotalTxs: 100, + TotalTxs: 100, LastCommitHash: []byte("commit hash"), - DataHash: []byte("data hash"), - ValidatorsHash:[]byte("validators hash"), - + DataHash: []byte("data hash"), + ValidatorsHash: []byte("validators hash"), } emptyLastBlockAm := Header{ - ChainID: "cosmos", - Height:150, - Time: tm, - NumTxs: 7, - TotalTxs: 100, + ChainID: "cosmos", + Height: 150, + Time: tm, + NumTxs: 7, + TotalTxs: 100, LastCommitHash: []byte("commit hash"), - DataHash: []byte("data hash"), - ValidatorsHash:[]byte("validators hash"), + DataHash: []byte("data hash"), + ValidatorsHash: []byte("validators hash"), } ab, err = cdc.MarshalBinaryBare(emptyLastBlockAm) From a81ca93139ab5e9947cf9e681742cf7c60dbaf97 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 18 Jul 2018 16:37:15 +0200 Subject: [PATCH 7/8] update to new (timestamp & empty structs) encoding in amino - timestamps no longer have fixed length encoding - --- types/proto3/block.pb.go | 54 ++++++++++++++++++++-------------------- types/proto3/block.proto | 4 +-- types/proto3_test.go | 7 +++--- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/types/proto3/block.pb.go b/types/proto3/block.pb.go index 96d5d34f8..3e6aa5f9b 100644 --- a/types/proto3/block.pb.go +++ b/types/proto3/block.pb.go @@ -196,8 +196,8 @@ func (m *Header) GetEvidenceHash() []byte { } type Timestamp struct { - Seconds int64 `protobuf:"fixed64,1,opt,name=seconds" json:"seconds,omitempty"` - Nanos int32 `protobuf:"fixed32,2,opt,name=nanos" json:"nanos,omitempty"` + Seconds int64 `protobuf:"varint,1,opt,name=seconds" json:"seconds,omitempty"` + Nanos int32 `protobuf:"varint,2,opt,name=nanos" json:"nanos,omitempty"` } func (m *Timestamp) Reset() { *m = Timestamp{} } @@ -229,29 +229,29 @@ func init() { func init() { proto.RegisterFile("block.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 372 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x4f, 0x6b, 0xe3, 0x30, - 0x10, 0xc5, 0xf1, 0xe6, 0xff, 0x38, 0xd9, 0x6c, 0x86, 0xdd, 0xc5, 0xf4, 0x14, 0x4c, 0x5b, 0x72, - 0x0a, 0xb4, 0x39, 0x94, 0xd2, 0x53, 0x9b, 0x14, 0x12, 0x28, 0xa5, 0xa8, 0x21, 0x77, 0x25, 0x16, - 0x8d, 0xa9, 0x2d, 0x19, 0x4b, 0x29, 0xfd, 0x7c, 0xfd, 0x64, 0x45, 0x23, 0xdb, 0x8d, 0x73, 0x4a, - 0xde, 0x9b, 0x37, 0xbf, 0x91, 0x47, 0x02, 0x7f, 0x9b, 0xa8, 0xdd, 0xfb, 0x34, 0xcb, 0x95, 0x51, - 0xd8, 0xa6, 0x9f, 0x59, 0x78, 0x0b, 0x83, 0x17, 0x9e, 0x9b, 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xa2, 0xe7, 0x18, 0x75, 0x17, 0xcf, 0x61, 0x30, 0x57, 0x52, 0x0b, 0xa9, 0x0f, 0x2e, 0x06, 0x14, - 0xab, 0x9b, 0x76, 0xa3, 0xf7, 0x59, 0x46, 0x75, 0x9f, 0xea, 0xa5, 0xc4, 0x09, 0x0c, 0xed, 0xa9, - 0x98, 0xd0, 0x87, 0xc4, 0x38, 0x42, 0x9f, 0x12, 0xa7, 0x36, 0x86, 0xd0, 0x7f, 0xfc, 0x88, 0x23, - 0x21, 0x77, 0x82, 0x62, 0x03, 0x8a, 0xd5, 0xbc, 0xf0, 0x0e, 0x7a, 0xd5, 0xce, 0xed, 0x50, 0x2d, - 0x76, 0x4a, 0x46, 0x9a, 0xae, 0xf1, 0x0f, 0x2b, 0xa5, 0x7d, 0x6d, 0x92, 0x4b, 0xa5, 0xe9, 0x16, - 0x87, 0xcc, 0x89, 0x6d, 0xf1, 0x38, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x74, 0x2f, 0xbd, - 0xb2, 0x02, 0x00, 0x00, + // 371 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x5f, 0x4b, 0xeb, 0x40, + 0x10, 0xc5, 0xc9, 0xed, 0xff, 0x49, 0x7b, 0x4b, 0x87, 0x7b, 0x25, 0xf8, 0x54, 0x82, 0x4a, 0x9f, + 0x0a, 0xda, 0x07, 0x11, 0x9f, 0xb4, 0x15, 0x5a, 0x10, 0x91, 0xb5, 0xf4, 0x7d, 0xdb, 0x2c, 0x36, + 0x98, 0xec, 0x86, 0xec, 0x56, 0xfc, 0x7c, 0x7e, 0x32, 0xd9, 0xd9, 0x24, 0x36, 0x7d, 0x6a, 0xcf, + 0x99, 0x33, 0xbf, 0xd9, 0xcc, 0x2e, 0xf8, 0xdb, 0x44, 0xed, 0x3e, 0xa6, 0x59, 0xae, 0x8c, 0xc2, + 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 0x96, 0xb1, 0xe1, 0x49, 0x1c, 0x71, 0xa3, 0x72, 0x4d, 0x89, + 0x9e, 0x63, 0xd4, 0x5d, 0xbc, 0x80, 0xc1, 0x5c, 0x49, 0x2d, 0xa4, 0x3e, 0xb8, 0x18, 0x50, 0xac, + 0x6e, 0xda, 0x8d, 0x3e, 0x64, 0x19, 0xd5, 0x7d, 0xaa, 0x97, 0x12, 0x27, 0x30, 0xb4, 0xa7, 0x62, + 0x42, 0x1f, 0x12, 0xe3, 0x08, 0x7d, 0x4a, 0x9c, 0xda, 0x18, 0x42, 0xff, 0xe9, 0x33, 0x8e, 0x84, + 0xdc, 0x09, 0x8a, 0x0d, 0x28, 0x56, 0xf3, 0xc2, 0x7b, 0xe8, 0x55, 0x3b, 0xb7, 0x43, 0xb5, 0xd8, + 0x29, 0x19, 0x69, 0xba, 0xc6, 0x06, 0x2b, 0xa5, 0x7d, 0x6d, 0x92, 0x4b, 0xa5, 0xe9, 0x16, 0x5b, + 0xcc, 0x89, 0x6d, 0xf1, 0x38, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x31, 0x7d, 0xc7, 0x97, 0xb2, + 0x02, 0x00, 0x00, } diff --git a/types/proto3/block.proto b/types/proto3/block.proto index 771bc828b..639e4cb10 100644 --- a/types/proto3/block.proto +++ b/types/proto3/block.proto @@ -39,6 +39,6 @@ message Header { } message Timestamp { - sfixed64 seconds = 1; - sfixed32 nanos = 2; + int64 seconds = 1; + int32 nanos = 2; } diff --git a/types/proto3_test.go b/types/proto3_test.go index c19296cad..c5a6676dc 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -62,10 +62,6 @@ func TestProto3Compatibility(t *testing.T) { Height: 150, Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos}, NumTxs: 7, - // TODO(ismail): as Jae suggested, we'll add a flag to make this obsolete: - LastBlockID: &proto3.BlockID{ - PartsHeader: &proto3.PartSetHeader{}, - }, TotalTxs: 100, LastCommitHash: []byte("commit hash"), DataHash: []byte("data hash"), @@ -93,6 +89,9 @@ func TestProto3Compatibility(t *testing.T) { pb, err = proto.Marshal(&proto3.Header{}) assert.NoError(t, err, "unexpected error") t.Log(pb) + ab, err = cdc.MarshalBinaryBare(Header{}) + assert.NoError(t, err, "unexpected error") + t.Log(ab) pb, err = proto.Marshal(&proto3.Timestamp{}) assert.NoError(t, err, "unexpected error") From 96818af9d593dd7bc0db26dad6bd82c943b17bdc Mon Sep 17 00:00:00 2001 From: Liamsi Date: Wed, 18 Jul 2018 19:06:38 +0200 Subject: [PATCH 8/8] fix protos to make all tests pass, document differences --- types/proto3/block.pb.go | 58 +++++++++++++++++++++------------------- types/proto3/block.proto | 8 ++++-- types/proto3_test.go | 15 +++++++++++ 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/types/proto3/block.pb.go b/types/proto3/block.pb.go index 3e6aa5f9b..805828f82 100644 --- a/types/proto3/block.pb.go +++ b/types/proto3/block.pb.go @@ -195,9 +195,13 @@ func (m *Header) GetEvidenceHash() []byte { return nil } +// Timestamp wraps how amino encodes time. Note that this is different from the protobuf well-known type +// protobuf/timestamp.proto in the sense that there seconds and nanos are varint encoded. See: +// https://github.com/google/protobuf/blob/d2980062c859649523d5fd51d6b55ab310e47482/src/google/protobuf/timestamp.proto#L123-L135 +// Also nanos do not get skipped if they are zero in amino. type Timestamp struct { - Seconds int64 `protobuf:"varint,1,opt,name=seconds" json:"seconds,omitempty"` - Nanos int32 `protobuf:"varint,2,opt,name=nanos" json:"nanos,omitempty"` + Seconds int64 `protobuf:"fixed64,1,opt,name=seconds" json:"seconds,omitempty"` + Nanos int32 `protobuf:"fixed32,2,opt,name=nanos" json:"nanos,omitempty"` } func (m *Timestamp) Reset() { *m = Timestamp{} } @@ -229,29 +233,29 @@ func init() { func init() { proto.RegisterFile("block.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 371 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0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x1b, 0x95, 0xe3, - 0xac, 0xa7, 0x0d, 0x4f, 0x33, 0x46, 0x65, 0xdb, 0xfe, 0x72, 0x48, 0xd7, 0x5f, 0x3a, 0x68, 0xba, - 0x76, 0xa7, 0xf0, 0x1a, 0xfc, 0x67, 0xae, 0x4d, 0xf1, 0x5d, 0x41, 0x8b, 0x28, 0xc3, 0x92, 0x52, - 0xd8, 0xec, 0x38, 0x83, 0xe7, 0xd0, 0xa5, 0x1d, 0x59, 0x58, 0x9b, 0x60, 0x95, 0xc6, 0x2b, 0xf8, - 0x6b, 0xa3, 0x73, 0x95, 0xa6, 0xb1, 0xa1, 0x0d, 0x75, 0x68, 0x43, 0x27, 0xae, 0x65, 0x2c, 0xb8, - 0xe1, 0x94, 0xe8, 0x52, 0xa2, 0xd2, 0x96, 0xb1, 0xe1, 0x49, 0x1c, 0x71, 0xa3, 0x72, 0x4d, 0x89, - 0x9e, 0x63, 0xd4, 0x5d, 0xbc, 0x80, 0xc1, 0x5c, 0x49, 0x2d, 0xa4, 0x3e, 0xb8, 0x18, 0x50, 0xac, - 0x6e, 0xda, 0x8d, 0x3e, 0x64, 0x19, 0xd5, 0x7d, 0xaa, 0x97, 0x12, 0x27, 0x30, 0xb4, 0xa7, 0x62, - 0x42, 0x1f, 0x12, 0xe3, 0x08, 0x7d, 0x4a, 0x9c, 0xda, 0x18, 0x42, 0xff, 0xe9, 0x33, 0x8e, 0x84, - 0xdc, 0x09, 0x8a, 0x0d, 0x28, 0x56, 0xf3, 0xc2, 0x7b, 0xe8, 0x55, 0x3b, 0xb7, 0x43, 0xb5, 0xd8, - 0x29, 0x19, 0x69, 0xba, 0xc6, 0x06, 0x2b, 0xa5, 0x7d, 0x6d, 0x92, 0x4b, 0xa5, 0xe9, 0x16, 0x5b, - 0xcc, 0x89, 0x6d, 0xf1, 0x38, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x31, 0x7d, 0xc7, 0x97, 0xb2, - 0x02, 0x00, 0x00, + // 372 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x4f, 0x6b, 0xe3, 0x30, + 0x10, 0xc5, 0xf1, 0xe6, 0xff, 0x38, 0xd9, 0x6c, 0x86, 0xdd, 0xc5, 0xf4, 0x14, 0x4c, 0x5b, 0x72, + 0x0a, 0xb4, 0x39, 0x94, 0xd2, 0x53, 0x9b, 0x14, 0x12, 0x28, 0xa5, 0xa8, 0x21, 0x77, 0x25, 0x16, + 0x8d, 0xa9, 0x2d, 0x19, 0x4b, 0x29, 0xfd, 0x7c, 0xfd, 0x64, 0x45, 0x23, 0xdb, 0x8d, 0x73, 0x4a, + 0xde, 0x9b, 0x37, 0xbf, 0x91, 0x47, 0x02, 0x7f, 0x9b, 0xa8, 0xdd, 0xfb, 0x34, 0xcb, 0x95, 0x51, + 0xd8, 0xa6, 0x9f, 0x59, 0x78, 0x0b, 0x83, 0x17, 0x9e, 0x9b, 0x57, 0x61, 0x96, 0x82, 0x47, 0x22, + 0xc7, 0xbf, 0xd0, 0x5a, 0x2b, 0xc3, 0x93, 0xc0, 0x1b, 0x7b, 0x93, 0x11, 0x73, 0x02, 0x11, 0x9a, + 0x4b, 0xae, 0xf7, 0xc1, 0xaf, 0xb1, 0x37, 0xe9, 0x33, 0xfa, 0x1f, 0x6e, 0xa0, 0xf3, 0x60, 0x89, + 0xab, 0x45, 0x55, 0xf6, 0x7e, 0xca, 0x78, 0x03, 0xbe, 0x25, 0x6b, 0xc7, 0xa5, 0x4e, 0xff, 0xfa, + 0x9f, 0x1b, 0x3f, 0x9b, 0xd6, 0x86, 0xb2, 0xe3, 0x64, 0xf8, 0xd5, 0x80, 0x76, 0x71, 0x98, 0x00, + 0x3a, 0xf3, 0x3d, 0x8f, 0xe5, 0x6a, 0x41, 0xe8, 0x1e, 0x2b, 0x25, 0xfe, 0xb7, 0x99, 0xf8, 0x6d, + 0x6f, 0x08, 0x8c, 0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xff, 0x6b, 0x74, 0x2f, 0xbd, + 0xb2, 0x02, 0x00, 0x00, } diff --git a/types/proto3/block.proto b/types/proto3/block.proto index 639e4cb10..bc3cf8749 100644 --- a/types/proto3/block.proto +++ b/types/proto3/block.proto @@ -38,7 +38,11 @@ message Header { bytes EvidenceHash = 13; // evidence included in the block } +// Timestamp wraps how amino encodes time. Note that this is different from the protobuf well-known type +// protobuf/timestamp.proto in the sense that there seconds and nanos are varint encoded. See: +// https://github.com/google/protobuf/blob/d2980062c859649523d5fd51d6b55ab310e47482/src/google/protobuf/timestamp.proto#L123-L135 +// Also nanos do not get skipped if they are zero in amino. message Timestamp { - int64 seconds = 1; - int32 nanos = 2; + sfixed64 seconds = 1; + sfixed32 nanos = 2; } diff --git a/types/proto3_test.go b/types/proto3_test.go index c5a6676dc..19a624a65 100644 --- a/types/proto3_test.go +++ b/types/proto3_test.go @@ -13,8 +13,13 @@ import ( func TestProto3Compatibility(t *testing.T) { tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006") assert.NoError(t, err) + // add some nanos, otherwise protobuf will skip over this while amino (still) won't! + tm = tm.Add(50000 * time.Nanosecond) seconds := tm.Unix() nanos := int32(tm.Nanosecond()) + t.Log("seconds", seconds) + t.Log("nanos", nanos) + pbHeader := proto3.Header{ ChainID: "cosmos", Height: 150, @@ -62,6 +67,11 @@ func TestProto3Compatibility(t *testing.T) { Height: 150, Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos}, NumTxs: 7, + // This is not fully skipped in amino (yet) although it is empty: + LastBlockID: &proto3.BlockID{ + PartsHeader: &proto3.PartSetHeader{ + }, + }, TotalTxs: 100, LastCommitHash: []byte("commit hash"), DataHash: []byte("data hash"), @@ -89,6 +99,8 @@ func TestProto3Compatibility(t *testing.T) { pb, err = proto.Marshal(&proto3.Header{}) assert.NoError(t, err, "unexpected error") t.Log(pb) + + // While in protobuf Header{} encodes to an empty byte slice it does not in amino: ab, err = cdc.MarshalBinaryBare(Header{}) assert.NoError(t, err, "unexpected error") t.Log(ab) @@ -97,4 +109,7 @@ func TestProto3Compatibility(t *testing.T) { assert.NoError(t, err, "unexpected error") t.Log(pb) + ab, err = cdc.MarshalBinaryBare(time.Time{}) + assert.NoError(t, err, "unexpected error") + t.Log(ab) }