From 92cbfb1cb39e00f3bfab9994fba6bf175d448110 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Fri, 30 Jun 2023 19:42:07 +0200 Subject: [PATCH] change consensus proto and client --- consensus/consensusclient/client.go | 11 +- consensus/consensusclient/client_test.go | 15 +- .../mock_consensusclient.go | 7 +- consensus/consensusproto/consensus.pb.go | 837 +++++++++++++++--- consensus/consensusproto/consensus_drpc.pb.go | 14 +- .../consensusproto/protos/consensus.proto | 35 +- 6 files changed, 779 insertions(+), 140 deletions(-) diff --git a/consensus/consensusclient/client.go b/consensus/consensusclient/client.go index cd3c411a..ff5882a7 100644 --- a/consensus/consensusclient/client.go +++ b/consensus/consensusclient/client.go @@ -30,7 +30,7 @@ func New() Service { // Watcher watches new events by specified logId type Watcher interface { - AddConsensusRecords(recs []*consensusproto.Record) + AddConsensusRecords(recs []*consensusproto.RawRecordWithId) AddConsensusError(err error) } @@ -38,7 +38,7 @@ type Service interface { // AddLog adds new log to consensus servers AddLog(ctx context.Context, clog *consensusproto.Log) (err error) // AddRecord adds new record to consensus servers - AddRecord(ctx context.Context, logId []byte, clog *consensusproto.Record) (err error) + AddRecord(ctx context.Context, logId []byte, clog *consensusproto.RawRecord) (record *consensusproto.RawRecordWithId, err error) // Watch starts watching to given logId and calls watcher when any relative event received Watch(logId []byte, w Watcher) (err error) // UnWatch stops watching given logId and removes watcher @@ -97,9 +97,9 @@ func (s *service) AddLog(ctx context.Context, clog *consensusproto.Log) (err err }) } -func (s *service) AddRecord(ctx context.Context, logId []byte, clog *consensusproto.Record) (err error) { - return s.doClient(ctx, func(cl consensusproto.DRPCConsensusClient) error { - if _, err = cl.RecordAdd(ctx, &consensusproto.RecordAddRequest{ +func (s *service) AddRecord(ctx context.Context, logId []byte, clog *consensusproto.RawRecord) (record *consensusproto.RawRecordWithId, err error) { + err = s.doClient(ctx, func(cl consensusproto.DRPCConsensusClient) error { + if record, err = cl.RecordAdd(ctx, &consensusproto.RecordAddRequest{ LogId: logId, Record: clog, }); err != nil { @@ -107,6 +107,7 @@ func (s *service) AddRecord(ctx context.Context, logId []byte, clog *consensuspr } return nil }) + return } func (s *service) Watch(logId []byte, w Watcher) (err error) { diff --git a/consensus/consensusclient/client_test.go b/consensus/consensusclient/client_test.go index a212a635..fd21695c 100644 --- a/consensus/consensusclient/client_test.go +++ b/consensus/consensusclient/client_test.go @@ -11,6 +11,7 @@ import ( "github.com/anyproto/any-sync/nodeconf" "github.com/anyproto/any-sync/nodeconf/mock_nodeconf" "github.com/anyproto/any-sync/testutil/accounttest" + "github.com/anyproto/any-sync/util/cidutil" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -118,7 +119,9 @@ func TestService_AddLog(t *testing.T) { func TestService_AddRecord(t *testing.T) { fx := newFixture(t).run(t) defer fx.Finish() - assert.NoError(t, fx.AddRecord(ctx, []byte{'1'}, &consensusproto.Record{})) + rec, err := fx.AddRecord(ctx, []byte{'1'}, &consensusproto.RawRecord{}) + require.NoError(t, err) + assert.NotEmpty(t, rec) } var ctx = context.Background() @@ -186,13 +189,15 @@ func (t *testServer) LogAdd(ctx context.Context, req *consensusproto.LogAddReque return &consensusproto.Ok{}, nil } -func (t *testServer) RecordAdd(ctx context.Context, req *consensusproto.RecordAddRequest) (*consensusproto.Ok, error) { +func (t *testServer) RecordAdd(ctx context.Context, req *consensusproto.RecordAddRequest) (*consensusproto.RawRecordWithId, error) { if t.addRecord != nil { if err := t.addRecord(ctx, req); err != nil { return nil, err } } - return &consensusproto.Ok{}, nil + data, _ := req.Record.Marshal() + id, _ := cidutil.NewCidFromBytes(data) + return &consensusproto.RawRecordWithId{Id: id, Payload: data}, nil } func (t *testServer) LogWatch(stream consensusproto.DRPCConsensus_LogWatchStream) error { @@ -215,13 +220,13 @@ func (t *testServer) waitStream(test *testing.T) consensusproto.DRPCConsensus_Lo } type testWatcher struct { - recs [][]*consensusproto.Record + recs [][]*consensusproto.RawRecordWithId err error ready chan struct{} once sync.Once } -func (t *testWatcher) AddConsensusRecords(recs []*consensusproto.Record) { +func (t *testWatcher) AddConsensusRecords(recs []*consensusproto.RawRecordWithId) { t.recs = append(t.recs, recs) t.once.Do(func() { close(t.ready) diff --git a/consensus/consensusclient/mock_consensusclient/mock_consensusclient.go b/consensus/consensusclient/mock_consensusclient/mock_consensusclient.go index f97c1c4f..95087515 100644 --- a/consensus/consensusclient/mock_consensusclient/mock_consensusclient.go +++ b/consensus/consensusclient/mock_consensusclient/mock_consensusclient.go @@ -52,11 +52,12 @@ func (mr *MockServiceMockRecorder) AddLog(arg0, arg1 interface{}) *gomock.Call { } // AddRecord mocks base method. -func (m *MockService) AddRecord(arg0 context.Context, arg1 []byte, arg2 *consensusproto.Record) error { +func (m *MockService) AddRecord(arg0 context.Context, arg1 []byte, arg2 *consensusproto.RawRecord) (*consensusproto.RawRecordWithId, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddRecord", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 + ret0, _ := ret[0].(*consensusproto.RawRecordWithId) + ret1, _ := ret[1].(error) + return ret0, ret1 } // AddRecord indicates an expected call of AddRecord. diff --git a/consensus/consensusproto/consensus.pb.go b/consensus/consensusproto/consensus.pb.go index 19361350..4e81e61c 100644 --- a/consensus/consensusproto/consensus.pb.go +++ b/consensus/consensusproto/consensus.pb.go @@ -57,8 +57,9 @@ func (ErrCodes) EnumDescriptor() ([]byte, []int) { } type Log struct { - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Records []*Record `protobuf:"bytes,2,rep,name=records,proto3" json:"records,omitempty"` + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` + Records []*RawRecordWithId `protobuf:"bytes,3,rep,name=records,proto3" json:"records,omitempty"` } func (m *Log) Reset() { *m = Log{} } @@ -101,25 +102,155 @@ func (m *Log) GetId() []byte { return nil } -func (m *Log) GetRecords() []*Record { +func (m *Log) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +func (m *Log) GetRecords() []*RawRecordWithId { if m != nil { return m.Records } return nil } +// RawRecord is a proto message containing the payload in bytes, signature of the account who added it and signature of the acceptor +type RawRecord struct { + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + AcceptorIdentity []byte `protobuf:"bytes,3,opt,name=acceptorIdentity,proto3" json:"acceptorIdentity,omitempty"` + AcceptorSignature []byte `protobuf:"bytes,4,opt,name=acceptorSignature,proto3" json:"acceptorSignature,omitempty"` +} + +func (m *RawRecord) Reset() { *m = RawRecord{} } +func (m *RawRecord) String() string { return proto.CompactTextString(m) } +func (*RawRecord) ProtoMessage() {} +func (*RawRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_b8d7f1c16b400059, []int{1} +} +func (m *RawRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RawRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RawRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RawRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_RawRecord.Merge(m, src) +} +func (m *RawRecord) XXX_Size() int { + return m.Size() +} +func (m *RawRecord) XXX_DiscardUnknown() { + xxx_messageInfo_RawRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_RawRecord proto.InternalMessageInfo + +func (m *RawRecord) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +func (m *RawRecord) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func (m *RawRecord) GetAcceptorIdentity() []byte { + if m != nil { + return m.AcceptorIdentity + } + return nil +} + +func (m *RawRecord) GetAcceptorSignature() []byte { + if m != nil { + return m.AcceptorSignature + } + return nil +} + +// RawRecordWithId is a raw record and the id for convenience +type RawRecordWithId struct { + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *RawRecordWithId) Reset() { *m = RawRecordWithId{} } +func (m *RawRecordWithId) String() string { return proto.CompactTextString(m) } +func (*RawRecordWithId) ProtoMessage() {} +func (*RawRecordWithId) Descriptor() ([]byte, []int) { + return fileDescriptor_b8d7f1c16b400059, []int{2} +} +func (m *RawRecordWithId) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RawRecordWithId) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RawRecordWithId.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RawRecordWithId) XXX_Merge(src proto.Message) { + xxx_messageInfo_RawRecordWithId.Merge(m, src) +} +func (m *RawRecordWithId) XXX_Size() int { + return m.Size() +} +func (m *RawRecordWithId) XXX_DiscardUnknown() { + xxx_messageInfo_RawRecordWithId.DiscardUnknown(m) +} + +var xxx_messageInfo_RawRecordWithId proto.InternalMessageInfo + +func (m *RawRecordWithId) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +func (m *RawRecordWithId) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +// Record is a record containing a data type Record struct { - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - PrevId []byte `protobuf:"bytes,2,opt,name=prevId,proto3" json:"prevId,omitempty"` - Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"` - CreatedUnix uint64 `protobuf:"varint,4,opt,name=createdUnix,proto3" json:"createdUnix,omitempty"` + PrevId string `protobuf:"bytes,1,opt,name=prevId,proto3" json:"prevId,omitempty"` + Identity []byte `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + Timestamp int64 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` } func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{1} + return fileDescriptor_b8d7f1c16b400059, []int{3} } func (m *Record) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -148,30 +279,30 @@ func (m *Record) XXX_DiscardUnknown() { var xxx_messageInfo_Record proto.InternalMessageInfo -func (m *Record) GetId() []byte { - if m != nil { - return m.Id - } - return nil -} - -func (m *Record) GetPrevId() []byte { +func (m *Record) GetPrevId() string { if m != nil { return m.PrevId } - return nil + return "" } -func (m *Record) GetPayload() []byte { +func (m *Record) GetIdentity() []byte { if m != nil { - return m.Payload + return m.Identity } return nil } -func (m *Record) GetCreatedUnix() uint64 { +func (m *Record) GetData() []byte { if m != nil { - return m.CreatedUnix + return m.Data + } + return nil +} + +func (m *Record) GetTimestamp() int64 { + if m != nil { + return m.Timestamp } return 0 } @@ -183,7 +314,7 @@ func (m *Ok) Reset() { *m = Ok{} } func (m *Ok) String() string { return proto.CompactTextString(m) } func (*Ok) ProtoMessage() {} func (*Ok) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{2} + return fileDescriptor_b8d7f1c16b400059, []int{4} } func (m *Ok) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -220,7 +351,7 @@ func (m *LogAddRequest) Reset() { *m = LogAddRequest{} } func (m *LogAddRequest) String() string { return proto.CompactTextString(m) } func (*LogAddRequest) ProtoMessage() {} func (*LogAddRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{3} + return fileDescriptor_b8d7f1c16b400059, []int{5} } func (m *LogAddRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -257,15 +388,15 @@ func (m *LogAddRequest) GetLog() *Log { } type RecordAddRequest struct { - LogId []byte `protobuf:"bytes,1,opt,name=logId,proto3" json:"logId,omitempty"` - Record *Record `protobuf:"bytes,2,opt,name=record,proto3" json:"record,omitempty"` + LogId []byte `protobuf:"bytes,1,opt,name=logId,proto3" json:"logId,omitempty"` + Record *RawRecord `protobuf:"bytes,2,opt,name=record,proto3" json:"record,omitempty"` } func (m *RecordAddRequest) Reset() { *m = RecordAddRequest{} } func (m *RecordAddRequest) String() string { return proto.CompactTextString(m) } func (*RecordAddRequest) ProtoMessage() {} func (*RecordAddRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{4} + return fileDescriptor_b8d7f1c16b400059, []int{6} } func (m *RecordAddRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -301,7 +432,7 @@ func (m *RecordAddRequest) GetLogId() []byte { return nil } -func (m *RecordAddRequest) GetRecord() *Record { +func (m *RecordAddRequest) GetRecord() *RawRecord { if m != nil { return m.Record } @@ -317,7 +448,7 @@ func (m *LogWatchRequest) Reset() { *m = LogWatchRequest{} } func (m *LogWatchRequest) String() string { return proto.CompactTextString(m) } func (*LogWatchRequest) ProtoMessage() {} func (*LogWatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{5} + return fileDescriptor_b8d7f1c16b400059, []int{7} } func (m *LogWatchRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -361,16 +492,16 @@ func (m *LogWatchRequest) GetUnwatchIds() [][]byte { } type LogWatchEvent struct { - LogId []byte `protobuf:"bytes,1,opt,name=logId,proto3" json:"logId,omitempty"` - Records []*Record `protobuf:"bytes,2,rep,name=records,proto3" json:"records,omitempty"` - Error *Err `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` + LogId []byte `protobuf:"bytes,1,opt,name=logId,proto3" json:"logId,omitempty"` + Records []*RawRecordWithId `protobuf:"bytes,2,rep,name=records,proto3" json:"records,omitempty"` + Error *Err `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` } func (m *LogWatchEvent) Reset() { *m = LogWatchEvent{} } func (m *LogWatchEvent) String() string { return proto.CompactTextString(m) } func (*LogWatchEvent) ProtoMessage() {} func (*LogWatchEvent) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{6} + return fileDescriptor_b8d7f1c16b400059, []int{8} } func (m *LogWatchEvent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -406,7 +537,7 @@ func (m *LogWatchEvent) GetLogId() []byte { return nil } -func (m *LogWatchEvent) GetRecords() []*Record { +func (m *LogWatchEvent) GetRecords() []*RawRecordWithId { if m != nil { return m.Records } @@ -428,7 +559,7 @@ func (m *Err) Reset() { *m = Err{} } func (m *Err) String() string { return proto.CompactTextString(m) } func (*Err) ProtoMessage() {} func (*Err) Descriptor() ([]byte, []int) { - return fileDescriptor_b8d7f1c16b400059, []int{7} + return fileDescriptor_b8d7f1c16b400059, []int{9} } func (m *Err) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -467,6 +598,8 @@ func (m *Err) GetError() ErrCodes { func init() { proto.RegisterEnum("consensusProto.ErrCodes", ErrCodes_name, ErrCodes_value) proto.RegisterType((*Log)(nil), "consensusProto.Log") + proto.RegisterType((*RawRecord)(nil), "consensusProto.RawRecord") + proto.RegisterType((*RawRecordWithId)(nil), "consensusProto.RawRecordWithId") proto.RegisterType((*Record)(nil), "consensusProto.Record") proto.RegisterType((*Ok)(nil), "consensusProto.Ok") proto.RegisterType((*LogAddRequest)(nil), "consensusProto.LogAddRequest") @@ -481,39 +614,46 @@ func init() { } var fileDescriptor_b8d7f1c16b400059 = []byte{ - // 511 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xcd, 0xda, 0x6d, 0x9a, 0x4c, 0xda, 0xd4, 0x1a, 0x50, 0x65, 0x45, 0xaa, 0xb1, 0x2c, 0x21, - 0x05, 0x0e, 0x69, 0x65, 0x04, 0x17, 0x4e, 0x25, 0x32, 0x28, 0x92, 0x69, 0x90, 0xa5, 0x0a, 0xc4, - 0x89, 0xe0, 0xdd, 0x18, 0xab, 0x96, 0x37, 0xec, 0x3a, 0x25, 0x5c, 0xf9, 0x02, 0x3e, 0x8b, 0x63, - 0x8f, 0x48, 0x5c, 0x50, 0xf2, 0x0b, 0x7c, 0x00, 0xf2, 0x3a, 0x4e, 0x4d, 0x71, 0x84, 0xb8, 0xd8, - 0x7e, 0xef, 0xcd, 0xcc, 0xbe, 0x9d, 0x19, 0xc3, 0x49, 0xc8, 0x53, 0xc9, 0x52, 0x39, 0x97, 0x37, - 0x5f, 0x33, 0xc1, 0x33, 0x7e, 0xa2, 0x9e, 0x15, 0x76, 0xa0, 0x08, 0xec, 0x6e, 0x88, 0x57, 0x39, - 0x76, 0x5e, 0x80, 0xee, 0xf3, 0x08, 0xbb, 0xa0, 0xc5, 0xd4, 0x24, 0x36, 0xe9, 0xef, 0x07, 0x5a, - 0x4c, 0xf1, 0x14, 0xf6, 0x04, 0x0b, 0xb9, 0xa0, 0xd2, 0xd4, 0x6c, 0xbd, 0xdf, 0x71, 0x8f, 0x06, - 0x7f, 0x26, 0x0e, 0x02, 0x25, 0x07, 0x65, 0x98, 0x93, 0x40, 0xb3, 0xa0, 0xfe, 0xaa, 0x75, 0x04, - 0xcd, 0x99, 0x60, 0x57, 0x23, 0x6a, 0x6a, 0x8a, 0x5b, 0x23, 0x34, 0x61, 0x6f, 0x36, 0xf9, 0x9c, - 0xf0, 0x09, 0x35, 0x75, 0x25, 0x94, 0x10, 0x6d, 0xe8, 0x84, 0x82, 0x4d, 0x32, 0x46, 0x2f, 0xd2, - 0x78, 0x61, 0xee, 0xd8, 0xa4, 0xbf, 0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x73, 0x9e, 0x3d, 0xe7, 0xf3, - 0x94, 0x1a, 0x1a, 0x22, 0x74, 0x0b, 0xc3, 0x43, 0x9e, 0x4e, 0x93, 0x38, 0xcc, 0x0c, 0x1d, 0x0d, - 0xe8, 0x78, 0x79, 0xe1, 0xf1, 0x74, 0x2a, 0x59, 0x66, 0xfc, 0xd2, 0xdd, 0x1f, 0x04, 0xda, 0xc3, - 0xd2, 0x04, 0x3e, 0x85, 0x66, 0xb1, 0x0c, 0x78, 0x5c, 0x33, 0xf8, 0x9b, 0x49, 0xf7, 0xf0, 0xb6, - 0x3c, 0xbe, 0xc4, 0x33, 0x68, 0x6f, 0x36, 0x02, 0xed, 0xfa, 0xe6, 0xfd, 0xa3, 0xc4, 0x39, 0xb4, - 0xca, 0x51, 0xe1, 0xbd, 0x1a, 0x07, 0xd5, 0xa5, 0xe8, 0x1d, 0x6f, 0x0b, 0x50, 0x53, 0xee, 0x93, - 0x53, 0xf2, 0xcc, 0xfd, 0xb6, 0xb4, 0xc8, 0xf5, 0xd2, 0x22, 0x3f, 0x97, 0x16, 0xf9, 0xba, 0xb2, - 0x1a, 0xd7, 0x2b, 0xab, 0xf1, 0x7d, 0x65, 0x35, 0xde, 0x9a, 0xdb, 0x7e, 0xfa, 0xf7, 0x4d, 0xf5, - 0x7a, 0xf4, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xc1, 0x7f, 0xa3, 0x95, 0x17, 0x04, 0x00, 0x00, + // 618 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xce, 0xda, 0x6d, 0x1a, 0x4f, 0x7e, 0x4d, 0xfd, 0x1b, 0x10, 0x32, 0x11, 0x75, 0x23, 0x4b, + 0x48, 0xa5, 0x42, 0x29, 0x04, 0x81, 0x84, 0x7a, 0x82, 0x2a, 0x48, 0x91, 0x42, 0x8b, 0x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, 0xe5, 0xad, 0x33, 0xef, 0x7b, 0xf8, 0xa1, 0xaa, 0xff, 0x1e, 0xfd, 0x0e, 0x00, 0x00, + 0xff, 0xff, 0xbc, 0x83, 0xcb, 0xc1, 0x32, 0x05, 0x00, 0x00, } func (m *Log) Marshal() (dAtA []byte, err error) { @@ -547,9 +687,16 @@ func (m *Log) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintConsensus(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } + if len(m.Payload) > 0 { + i -= len(m.Payload) + copy(dAtA[i:], m.Payload) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Payload))) + i-- + dAtA[i] = 0x12 + } if len(m.Id) > 0 { i -= len(m.Id) copy(dAtA[i:], m.Id) @@ -560,6 +707,94 @@ func (m *Log) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *RawRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RawRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RawRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AcceptorSignature) > 0 { + i -= len(m.AcceptorSignature) + copy(dAtA[i:], m.AcceptorSignature) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.AcceptorSignature))) + i-- + dAtA[i] = 0x22 + } + if len(m.AcceptorIdentity) > 0 { + i -= len(m.AcceptorIdentity) + copy(dAtA[i:], m.AcceptorIdentity) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.AcceptorIdentity))) + i-- + dAtA[i] = 0x1a + } + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x12 + } + if len(m.Payload) > 0 { + i -= len(m.Payload) + copy(dAtA[i:], m.Payload) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Payload))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RawRecordWithId) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RawRecordWithId) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RawRecordWithId) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0x12 + } + if len(m.Payload) > 0 { + i -= len(m.Payload) + copy(dAtA[i:], m.Payload) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Payload))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *Record) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -580,30 +815,30 @@ func (m *Record) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.CreatedUnix != 0 { - i = encodeVarintConsensus(dAtA, i, uint64(m.CreatedUnix)) + if m.Timestamp != 0 { + i = encodeVarintConsensus(dAtA, i, uint64(m.Timestamp)) i-- dAtA[i] = 0x20 } - if len(m.Payload) > 0 { - i -= len(m.Payload) - copy(dAtA[i:], m.Payload) - i = encodeVarintConsensus(dAtA, i, uint64(len(m.Payload))) + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Data))) i-- dAtA[i] = 0x1a } + if len(m.Identity) > 0 { + i -= len(m.Identity) + copy(dAtA[i:], m.Identity) + i = encodeVarintConsensus(dAtA, i, uint64(len(m.Identity))) + i-- + dAtA[i] = 0x12 + } if len(m.PrevId) > 0 { i -= len(m.PrevId) copy(dAtA[i:], m.PrevId) i = encodeVarintConsensus(dAtA, i, uint64(len(m.PrevId))) i-- - dAtA[i] = 0x12 - } - if len(m.Id) > 0 { - i -= len(m.Id) - copy(dAtA[i:], m.Id) - i = encodeVarintConsensus(dAtA, i, uint64(len(m.Id))) - i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -855,6 +1090,10 @@ func (m *Log) Size() (n int) { if l > 0 { n += 1 + l + sovConsensus(uint64(l)) } + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } if len(m.Records) > 0 { for _, e := range m.Records { l = e.Size() @@ -864,26 +1103,68 @@ func (m *Log) Size() (n int) { return n } +func (m *RawRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + l = len(m.AcceptorIdentity) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + l = len(m.AcceptorSignature) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + return n +} + +func (m *RawRecordWithId) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + l = len(m.Id) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + return n +} + func (m *Record) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Id) - if l > 0 { - n += 1 + l + sovConsensus(uint64(l)) - } l = len(m.PrevId) if l > 0 { n += 1 + l + sovConsensus(uint64(l)) } - l = len(m.Payload) + l = len(m.Identity) if l > 0 { n += 1 + l + sovConsensus(uint64(l)) } - if m.CreatedUnix != 0 { - n += 1 + sovConsensus(uint64(m.CreatedUnix)) + l = len(m.Data) + if l > 0 { + n += 1 + l + sovConsensus(uint64(l)) + } + if m.Timestamp != 0 { + n += 1 + sovConsensus(uint64(m.Timestamp)) } return n } @@ -1053,6 +1334,40 @@ func (m *Log) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) + if m.Payload == nil { + m.Payload = []byte{} + } + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Records", wireType) } @@ -1081,7 +1396,7 @@ func (m *Log) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Records = append(m.Records, &Record{}) + m.Records = append(m.Records, &RawRecordWithId{}) if err := m.Records[len(m.Records)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1107,6 +1422,308 @@ func (m *Log) Unmarshal(dAtA []byte) error { } return nil } +func (m *RawRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RawRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RawRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) + if m.Payload == nil { + m.Payload = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AcceptorIdentity", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AcceptorIdentity = append(m.AcceptorIdentity[:0], dAtA[iNdEx:postIndex]...) + if m.AcceptorIdentity == nil { + m.AcceptorIdentity = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AcceptorSignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AcceptorSignature = append(m.AcceptorSignature[:0], dAtA[iNdEx:postIndex]...) + if m.AcceptorSignature == nil { + m.AcceptorSignature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConsensus(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConsensus + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RawRecordWithId) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RawRecordWithId: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RawRecordWithId: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) + if m.Payload == nil { + m.Payload = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConsensus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthConsensus + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthConsensus + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipConsensus(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConsensus + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Record) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1138,9 +1755,9 @@ func (m *Record) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PrevId", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConsensus @@ -1150,29 +1767,27 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthConsensus } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthConsensus } if postIndex > l { return io.ErrUnexpectedEOF } - m.Id = append(m.Id[:0], dAtA[iNdEx:postIndex]...) - if m.Id == nil { - m.Id = []byte{} - } + m.PrevId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrevId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Identity", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1199,14 +1814,14 @@ func (m *Record) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PrevId = append(m.PrevId[:0], dAtA[iNdEx:postIndex]...) - if m.PrevId == nil { - m.PrevId = []byte{} + m.Identity = append(m.Identity[:0], dAtA[iNdEx:postIndex]...) + if m.Identity == nil { + m.Identity = []byte{} } iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1233,16 +1848,16 @@ func (m *Record) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) - if m.Payload == nil { - m.Payload = []byte{} + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} } iNdEx = postIndex case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CreatedUnix", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) } - m.CreatedUnix = 0 + m.Timestamp = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConsensus @@ -1252,7 +1867,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CreatedUnix |= uint64(b&0x7F) << shift + m.Timestamp |= int64(b&0x7F) << shift if b < 0x80 { break } @@ -1507,7 +2122,7 @@ func (m *RecordAddRequest) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Record == nil { - m.Record = &Record{} + m.Record = &RawRecord{} } if err := m.Record.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1740,7 +2355,7 @@ func (m *LogWatchEvent) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Records = append(m.Records, &Record{}) + m.Records = append(m.Records, &RawRecordWithId{}) if err := m.Records[len(m.Records)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/consensus/consensusproto/consensus_drpc.pb.go b/consensus/consensusproto/consensus_drpc.pb.go index be8927c6..b0b00dad 100644 --- a/consensus/consensusproto/consensus_drpc.pb.go +++ b/consensus/consensusproto/consensus_drpc.pb.go @@ -41,7 +41,7 @@ type DRPCConsensusClient interface { DRPCConn() drpc.Conn LogAdd(ctx context.Context, in *LogAddRequest) (*Ok, error) - RecordAdd(ctx context.Context, in *RecordAddRequest) (*Ok, error) + RecordAdd(ctx context.Context, in *RecordAddRequest) (*RawRecordWithId, error) LogWatch(ctx context.Context) (DRPCConsensus_LogWatchClient, error) } @@ -64,8 +64,8 @@ func (c *drpcConsensusClient) LogAdd(ctx context.Context, in *LogAddRequest) (*O return out, nil } -func (c *drpcConsensusClient) RecordAdd(ctx context.Context, in *RecordAddRequest) (*Ok, error) { - out := new(Ok) +func (c *drpcConsensusClient) RecordAdd(ctx context.Context, in *RecordAddRequest) (*RawRecordWithId, error) { + out := new(RawRecordWithId) err := c.cc.Invoke(ctx, "/consensusProto.Consensus/RecordAdd", drpcEncoding_File_consensus_consensusproto_protos_consensus_proto{}, in, out) if err != nil { return nil, err @@ -114,7 +114,7 @@ func (x *drpcConsensus_LogWatchClient) RecvMsg(m *LogWatchEvent) error { type DRPCConsensusServer interface { LogAdd(context.Context, *LogAddRequest) (*Ok, error) - RecordAdd(context.Context, *RecordAddRequest) (*Ok, error) + RecordAdd(context.Context, *RecordAddRequest) (*RawRecordWithId, error) LogWatch(DRPCConsensus_LogWatchStream) error } @@ -124,7 +124,7 @@ func (s *DRPCConsensusUnimplementedServer) LogAdd(context.Context, *LogAddReques return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } -func (s *DRPCConsensusUnimplementedServer) RecordAdd(context.Context, *RecordAddRequest) (*Ok, error) { +func (s *DRPCConsensusUnimplementedServer) RecordAdd(context.Context, *RecordAddRequest) (*RawRecordWithId, error) { return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } @@ -191,14 +191,14 @@ func (x *drpcConsensus_LogAddStream) SendAndClose(m *Ok) error { type DRPCConsensus_RecordAddStream interface { drpc.Stream - SendAndClose(*Ok) error + SendAndClose(*RawRecordWithId) error } type drpcConsensus_RecordAddStream struct { drpc.Stream } -func (x *drpcConsensus_RecordAddStream) SendAndClose(m *Ok) error { +func (x *drpcConsensus_RecordAddStream) SendAndClose(m *RawRecordWithId) error { if err := x.MsgSend(m, drpcEncoding_File_consensus_consensusproto_protos_consensus_proto{}); err != nil { return err } diff --git a/consensus/consensusproto/protos/consensus.proto b/consensus/consensusproto/protos/consensus.proto index 6be8103c..55918519 100644 --- a/consensus/consensusproto/protos/consensus.proto +++ b/consensus/consensusproto/protos/consensus.proto @@ -14,21 +14,38 @@ enum ErrCodes { message Log { bytes id = 1; - repeated Record records = 2; + bytes payload = 2; + repeated RawRecordWithId records = 3; } -message Record { - bytes id = 1; - bytes prevId = 2; - bytes payload = 3; - uint64 createdUnix = 4; +// RawRecord is a proto message containing the payload in bytes, signature of the account who added it and signature of the acceptor +message RawRecord { + bytes payload = 1; + bytes signature = 2; + bytes acceptorIdentity = 3; + bytes acceptorSignature = 4; } +// RawRecordWithId is a raw record and the id for convenience +message RawRecordWithId { + bytes payload = 1; + string id = 2; +} + +// Record is a record containing a data +message Record { + string prevId = 1; + bytes identity = 2; + bytes data = 3; + int64 timestamp = 4; +} + + service Consensus { // AddLog adds new log to consensus rpc LogAdd(LogAddRequest) returns (Ok); // AddRecord adds new record to log - rpc RecordAdd(RecordAddRequest) returns (Ok); + rpc RecordAdd(RecordAddRequest) returns (RawRecordWithId); // WatchLog fetches log and subscribes for a changes rpc LogWatch(stream LogWatchRequest) returns (stream LogWatchEvent); } @@ -41,7 +58,7 @@ message LogAddRequest { message RecordAddRequest { bytes logId = 1; - Record record = 2; + RawRecord record = 2; } message LogWatchRequest { @@ -51,7 +68,7 @@ message LogWatchRequest { message LogWatchEvent { bytes logId = 1; - repeated Record records = 2; + repeated RawRecordWithId records = 2; Err error = 3; }