From bb968c35d7e154f9d3c4940e42bf607a37e8fd71 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 18:50:00 +0300 Subject: [PATCH 01/54] FEAT: Add slash.proto --- data/slash/slash.go | 2 + data/slash/slash.pb.go | 474 +++++++++++++++++++++++++++++++++++++++++ data/slash/slash.proto | 25 +++ 3 files changed, 501 insertions(+) create mode 100644 data/slash/slash.go create mode 100644 data/slash/slash.pb.go create mode 100644 data/slash/slash.proto diff --git a/data/slash/slash.go b/data/slash/slash.go new file mode 100644 index 000000000..8d3b8f339 --- /dev/null +++ b/data/slash/slash.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. slash.proto +package slash diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go new file mode 100644 index 000000000..cddf90aed --- /dev/null +++ b/data/slash/slash.pb.go @@ -0,0 +1,474 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: slash.proto + +package slash + +import ( + fmt "fmt" + block "github.com/ElrondNetwork/elrond-go-core/data/block" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strconv "strconv" + strings "strings" +) + +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type SlashingType int32 + +const ( + None SlashingType = 0 + MultipleProposal SlashingType = 1 + MultipleSigning SlashingType = 2 +) + +var SlashingType_name = map[int32]string{ + 0: "None", + 1: "MultipleProposal", + 2: "MultipleSigning", +} + +var SlashingType_value = map[string]int32{ + "None": 0, + "MultipleProposal": 1, + "MultipleSigning": 2, +} + +func (SlashingType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_7c4604f407d65f7b, []int{0} +} + +type ThreatLevel int32 + +const ( + Low ThreatLevel = 0 + Medium ThreatLevel = 1 + High ThreatLevel = 2 +) + +var ThreatLevel_name = map[int32]string{ + 0: "Low", + 1: "Medium", + 2: "High", +} + +var ThreatLevel_value = map[string]int32{ + "Low": 0, + "Medium": 1, + "High": 2, +} + +func (ThreatLevel) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_7c4604f407d65f7b, []int{1} +} + +type Headers struct { + Headers []*block.HeaderV2 `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` +} + +func (m *Headers) Reset() { *m = Headers{} } +func (*Headers) ProtoMessage() {} +func (*Headers) Descriptor() ([]byte, []int) { + return fileDescriptor_7c4604f407d65f7b, []int{0} +} +func (m *Headers) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Headers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Headers) XXX_Merge(src proto.Message) { + xxx_messageInfo_Headers.Merge(m, src) +} +func (m *Headers) XXX_Size() int { + return m.Size() +} +func (m *Headers) XXX_DiscardUnknown() { + xxx_messageInfo_Headers.DiscardUnknown(m) +} + +var xxx_messageInfo_Headers proto.InternalMessageInfo + +func (m *Headers) GetHeaders() []*block.HeaderV2 { + if m != nil { + return m.Headers + } + return nil +} + +func init() { + proto.RegisterEnum("proto.SlashingType", SlashingType_name, SlashingType_value) + proto.RegisterEnum("proto.ThreatLevel", ThreatLevel_name, ThreatLevel_value) + proto.RegisterType((*Headers)(nil), "proto.Headers") +} + +func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } + +var fileDescriptor_7c4604f407d65f7b = []byte{ + // 319 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8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x2c, 0xc6, 0xaf, 0x09, 0x77, 0xff, 0xb3, 0x7f, 0x43, + 0x8c, 0xb9, 0x43, 0xdc, 0x23, 0xe6, 0x0c, 0x72, 0x95, 0xc9, 0x44, 0xf1, 0x07, 0x8d, 0x09, 0xa6, + 0xbe, 0x72, 0xa8, 0x7b, 0xc8, 0x1a, 0x7b, 0x75, 0x24, 0x45, 0x2c, 0x63, 0xe1, 0x94, 0x5a, 0x17, + 0xac, 0x3e, 0x8e, 0x34, 0xf7, 0xb3, 0x3e, 0x7f, 0xe1, 0xca, 0xad, 0xb1, 0x72, 0x1f, 0x17, 0x0e, + 0x71, 0x19, 0xab, 0x0e, 0x78, 0x28, 0xf3, 0xb9, 0x43, 0x77, 0xc1, 0x3d, 0x29, 0x22, 0xa7, 0x74, + 0x7b, 0xbd, 0x5c, 0x03, 0x59, 0xad, 0x81, 0x6c, 0xd7, 0x40, 0xdf, 0x0c, 0xd0, 0x0f, 0x03, 0xf4, + 0xd3, 0x00, 0x5d, 0x1a, 0xa0, 0x2b, 0x03, 0xf4, 0xcb, 0x00, 0xfd, 0x36, 0x40, 0xb6, 0x06, 0xe8, + 0xfb, 0x06, 0xc8, 0x72, 0x03, 0x64, 0xb5, 0x01, 0xf2, 0x54, 0xb1, 0x77, 0x0e, 0xaa, 0x76, 0x99, + 0xcb, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xa6, 0xba, 0x2c, 0x77, 0x01, 0x00, 0x00, +} + +func (x SlashingType) String() string { + s, ok := SlashingType_name[int32(x)] + if ok { + return s + } + return strconv.Itoa(int(x)) +} +func (x ThreatLevel) String() string { + s, ok := ThreatLevel_name[int32(x)] + if ok { + return s + } + return strconv.Itoa(int(x)) +} +func (this *Headers) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Headers) + if !ok { + that2, ok := that.(Headers) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Headers) != len(that1.Headers) { + return false + } + for i := range this.Headers { + if !this.Headers[i].Equal(that1.Headers[i]) { + return false + } + } + return true +} +func (this *Headers) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&slash.Headers{") + if this.Headers != nil { + s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringSlash(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *Headers) 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 *Headers) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Headers) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Headers) > 0 { + for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSlash(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintSlash(dAtA []byte, offset int, v uint64) int { + offset -= sovSlash(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Headers) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Headers) > 0 { + for _, e := range m.Headers { + l = e.Size() + n += 1 + l + sovSlash(uint64(l)) + } + } + return n +} + +func sovSlash(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSlash(x uint64) (n int) { + return sovSlash(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Headers) String() string { + if this == nil { + return "nil" + } + repeatedStringForHeaders := "[]*HeaderV2{" + for _, f := range this.Headers { + repeatedStringForHeaders += strings.Replace(fmt.Sprintf("%v", f), "HeaderV2", "block.HeaderV2", 1) + "," + } + repeatedStringForHeaders += "}" + s := strings.Join([]string{`&Headers{`, + `Headers:` + repeatedStringForHeaders + `,`, + `}`, + }, "") + return s +} +func valueToStringSlash(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Headers) 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 ErrIntOverflowSlash + } + 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: Headers: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Headers: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSlash + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSlash + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSlash + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Headers = append(m.Headers, &block.HeaderV2{}) + if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSlash(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSlash + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSlash + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSlash(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSlash + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSlash + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSlash + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSlash = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSlash = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSlash = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/slash/slash.proto b/data/slash/slash.proto new file mode 100644 index 000000000..27c3cfa0a --- /dev/null +++ b/data/slash/slash.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package proto; + +option go_package = "slash"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/block/blockV2.proto"; + +enum SlashingType { + None = 0; + MultipleProposal = 1; + MultipleSigning = 2; +} + +enum ThreatLevel { + Low = 0; + Medium = 1; + High = 2; +} + +message Headers{ + repeated HeaderV2 Headers = 1; +} \ No newline at end of file From 2d0ef6776823549c1ae79791ae81853b3654b4b5 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 18:55:30 +0300 Subject: [PATCH 02/54] FEAT: Add multipleHeaderSigningProof.proto --- data/slash/multipleHeaderSigningProof.go | 2 + data/slash/multipleHeaderSigningProof.pb.go | 795 ++++++++++++++++++++ data/slash/multipleHeaderSigningProof.proto | 15 + 3 files changed, 812 insertions(+) create mode 100644 data/slash/multipleHeaderSigningProof.go create mode 100644 data/slash/multipleHeaderSigningProof.pb.go create mode 100644 data/slash/multipleHeaderSigningProof.proto diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go new file mode 100644 index 000000000..00dfa8659 --- /dev/null +++ b/data/slash/multipleHeaderSigningProof.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. multipleHeaderSigningProof.proto +package slash diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go new file mode 100644 index 000000000..e49b2a86c --- /dev/null +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -0,0 +1,795 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: multipleHeaderSigningProof.proto + +package slash + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MultipleHeaderSigningProof struct { + PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + Headers map[string]*Headers `protobuf:"bytes,3,rep,name=Headers,proto3" json:"Headers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } +func (*MultipleHeaderSigningProof) ProtoMessage() {} +func (*MultipleHeaderSigningProof) Descriptor() ([]byte, []int) { + return fileDescriptor_f61c9968ee2015ff, []int{0} +} +func (m *MultipleHeaderSigningProof) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MultipleHeaderSigningProof) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *MultipleHeaderSigningProof) XXX_Merge(src proto.Message) { + xxx_messageInfo_MultipleHeaderSigningProof.Merge(m, src) +} +func (m *MultipleHeaderSigningProof) XXX_Size() int { + return m.Size() +} +func (m *MultipleHeaderSigningProof) XXX_DiscardUnknown() { + xxx_messageInfo_MultipleHeaderSigningProof.DiscardUnknown(m) +} + +var xxx_messageInfo_MultipleHeaderSigningProof proto.InternalMessageInfo + +func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { + if m != nil { + return m.PubKeys + } + return nil +} + +func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { + if m != nil { + return m.Levels + } + return nil +} + +func (m *MultipleHeaderSigningProof) GetHeaders() map[string]*Headers { + if m != nil { + return m.Headers + } + return nil +} + +func init() { + proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") + proto.RegisterMapType((map[string]*Headers)(nil), "proto.MultipleHeaderSigningProof.HeadersEntry") + proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") +} + +func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } + +var fileDescriptor_f61c9968ee2015ff = []byte{ + // 327 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x3f, 0x4b, 0xc3, 0x40, + 0x18, 0xc6, 0xf3, 0x26, 0xb4, 0xc5, 0x4b, 0x29, 0x72, 0xd3, 0x91, 0xe1, 0x25, 0x88, 0x43, 0x96, + 0xa6, 0x50, 0x17, 0x71, 0x11, 0x84, 0x42, 0x51, 0x0b, 0x25, 0x3a, 0xb9, 0x25, 0x7a, 0x4d, 0x83, + 0x69, 0xaf, 0xe4, 0x4f, 0xa1, 0x9b, 0x1f, 0xc1, 0x8f, 0xe1, 0x47, 0x71, 0xec, 0xd8, 0xd1, 0x5e, + 0x17, 0xc7, 0x7e, 0x04, 0xf1, 0x2e, 0x85, 0x0c, 0x16, 0xa7, 0x7b,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 0xb3, 0xfb, 0x9d, 0xca, 0x57, 0x51, 0x35, 0xd7, 0xcd, 0xf5, 0x7a, 0x8b, 0xc6, 0x66, 0x8b, + 0xc6, 0x7e, 0x8b, 0xf0, 0x26, 0x11, 0x3e, 0x24, 0xc2, 0xa7, 0x44, 0x58, 0x4b, 0x84, 0x8d, 0x44, + 0xf8, 0x92, 0x08, 0xdf, 0x12, 0x8d, 0xbd, 0x44, 0x78, 0xdf, 0xa1, 0xb1, 0xde, 0xa1, 0xb1, 0xd9, + 0xa1, 0xf1, 0xd4, 0x50, 0x5f, 0x1b, 0x35, 0x95, 0xfa, 0xe2, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe1, + 0xa9, 0x7e, 0xbc, 0x13, 0x02, 0x00, 0x00, +} + +func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MultipleHeaderSigningProof) + if !ok { + that2, ok := that.(MultipleHeaderSigningProof) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.PubKeys) != len(that1.PubKeys) { + return false + } + for i := range this.PubKeys { + if !bytes.Equal(this.PubKeys[i], that1.PubKeys[i]) { + return false + } + } + if len(this.Levels) != len(that1.Levels) { + return false + } + for i := range this.Levels { + if this.Levels[i] != that1.Levels[i] { + return false + } + } + if len(this.Headers) != len(that1.Headers) { + return false + } + for i := range this.Headers { + if !this.Headers[i].Equal(that1.Headers[i]) { + return false + } + } + return true +} +func (this *MultipleHeaderSigningProof) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&slash.MultipleHeaderSigningProof{") + s = append(s, "PubKeys: "+fmt.Sprintf("%#v", this.PubKeys)+",\n") + keysForLevels := make([]string, 0, len(this.Levels)) + for k, _ := range this.Levels { + keysForLevels = append(keysForLevels, k) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) + mapStringForLevels := "map[string]ThreatLevel{" + for _, k := range keysForLevels { + mapStringForLevels += fmt.Sprintf("%#v: %#v,", k, this.Levels[k]) + } + mapStringForLevels += "}" + if this.Levels != nil { + s = append(s, "Levels: "+mapStringForLevels+",\n") + } + keysForHeaders := make([]string, 0, len(this.Headers)) + for k, _ := range this.Headers { + keysForHeaders = append(keysForHeaders, k) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) + mapStringForHeaders := "map[string]*Headers{" + for _, k := range keysForHeaders { + mapStringForHeaders += fmt.Sprintf("%#v: %#v,", k, this.Headers[k]) + } + mapStringForHeaders += "}" + if this.Headers != nil { + s = append(s, "Headers: "+mapStringForHeaders+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringMultipleHeaderSigningProof(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *MultipleHeaderSigningProof) 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 *MultipleHeaderSigningProof) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Headers) > 0 { + keysForHeaders := make([]string, 0, len(m.Headers)) + for k := range m.Headers { + keysForHeaders = append(keysForHeaders, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) + for iNdEx := len(keysForHeaders) - 1; iNdEx >= 0; iNdEx-- { + v := m.Headers[string(keysForHeaders[iNdEx])] + baseI := i + if v != nil { + { + size, err := v.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + i -= len(keysForHeaders[iNdEx]) + copy(dAtA[i:], keysForHeaders[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeaders[iNdEx]))) + i-- + dAtA[i] = 0xa + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Levels) > 0 { + keysForLevels := make([]string, 0, len(m.Levels)) + for k := range m.Levels { + keysForLevels = append(keysForLevels, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) + for iNdEx := len(keysForLevels) - 1; iNdEx >= 0; iNdEx-- { + v := m.Levels[string(keysForLevels[iNdEx])] + baseI := i + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(keysForLevels[iNdEx]) + copy(dAtA[i:], keysForLevels[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForLevels[iNdEx]))) + i-- + dAtA[i] = 0xa + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.PubKeys) > 0 { + for iNdEx := len(m.PubKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.PubKeys[iNdEx]) + copy(dAtA[i:], m.PubKeys[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(m.PubKeys[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintMultipleHeaderSigningProof(dAtA []byte, offset int, v uint64) int { + offset -= sovMultipleHeaderSigningProof(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MultipleHeaderSigningProof) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.PubKeys) > 0 { + for _, b := range m.PubKeys { + l = len(b) + n += 1 + l + sovMultipleHeaderSigningProof(uint64(l)) + } + } + if len(m.Levels) > 0 { + for k, v := range m.Levels { + _ = k + _ = v + mapEntrySize := 1 + len(k) + sovMultipleHeaderSigningProof(uint64(len(k))) + 1 + sovMultipleHeaderSigningProof(uint64(v)) + n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) + } + } + if len(m.Headers) > 0 { + for k, v := range m.Headers { + _ = k + _ = v + l = 0 + if v != nil { + l = v.Size() + l += 1 + sovMultipleHeaderSigningProof(uint64(l)) + } + mapEntrySize := 1 + len(k) + sovMultipleHeaderSigningProof(uint64(len(k))) + l + n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) + } + } + return n +} + +func sovMultipleHeaderSigningProof(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMultipleHeaderSigningProof(x uint64) (n int) { + return sovMultipleHeaderSigningProof(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *MultipleHeaderSigningProof) String() string { + if this == nil { + return "nil" + } + keysForLevels := make([]string, 0, len(this.Levels)) + for k, _ := range this.Levels { + keysForLevels = append(keysForLevels, k) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) + mapStringForLevels := "map[string]ThreatLevel{" + for _, k := range keysForLevels { + mapStringForLevels += fmt.Sprintf("%v: %v,", k, this.Levels[k]) + } + mapStringForLevels += "}" + keysForHeaders := make([]string, 0, len(this.Headers)) + for k, _ := range this.Headers { + keysForHeaders = append(keysForHeaders, k) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) + mapStringForHeaders := "map[string]*Headers{" + for _, k := range keysForHeaders { + mapStringForHeaders += fmt.Sprintf("%v: %v,", k, this.Headers[k]) + } + mapStringForHeaders += "}" + s := strings.Join([]string{`&MultipleHeaderSigningProof{`, + `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, + `Levels:` + mapStringForLevels + `,`, + `Headers:` + mapStringForHeaders + `,`, + `}`, + }, "") + return s +} +func valueToStringMultipleHeaderSigningProof(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *MultipleHeaderSigningProof) 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 ErrIntOverflowMultipleHeaderSigningProof + } + 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: MultipleHeaderSigningProof: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MultipleHeaderSigningProof: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKeys", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PubKeys = append(m.PubKeys, make([]byte, postIndex-iNdEx)) + copy(m.PubKeys[len(m.PubKeys)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Levels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Levels == nil { + m.Levels = make(map[string]ThreatLevel) + } + var mapkey string + var mapvalue ThreatLevel + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= ThreatLevel(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := skipMultipleHeaderSigningProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Levels[mapkey] = mapvalue + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Headers == nil { + m.Headers = make(map[string]*Headers) + } + var mapkey string + var mapvalue *Headers + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &Headers{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipMultipleHeaderSigningProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Headers[mapkey] = mapvalue + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMultipleHeaderSigningProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMultipleHeaderSigningProof(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthMultipleHeaderSigningProof + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMultipleHeaderSigningProof + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMultipleHeaderSigningProof + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMultipleHeaderSigningProof = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMultipleHeaderSigningProof = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMultipleHeaderSigningProof = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto new file mode 100644 index 000000000..07da572e6 --- /dev/null +++ b/data/slash/multipleHeaderSigningProof.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package proto; + +option go_package = "slash"; +option (gogoproto.stable_marshaler_all) = true; + +import "slash.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message MultipleHeaderSigningProof { + repeated bytes PubKeys = 1; + map Levels = 2; + map Headers = 3; +} \ No newline at end of file From 211fb939b8055bb8091f8045e1283150bc36bacc Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 18:58:08 +0300 Subject: [PATCH 03/54] FEAT: Add multipleHeaderProposalProof.proto --- data/slash/multipleHeaderProposalProof.go | 2 + data/slash/multipleHeaderProposalProof.pb.go | 431 +++++++++++++++++++ data/slash/multipleHeaderProposalProof.proto | 14 + data/slash/multipleHeaderSigningProof.pb.go | 34 +- data/slash/multipleHeaderSigningProof.proto | 2 +- 5 files changed, 465 insertions(+), 18 deletions(-) create mode 100644 data/slash/multipleHeaderProposalProof.go create mode 100644 data/slash/multipleHeaderProposalProof.pb.go create mode 100644 data/slash/multipleHeaderProposalProof.proto diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go new file mode 100644 index 000000000..ee5363bfe --- /dev/null +++ b/data/slash/multipleHeaderProposalProof.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. multipleHeaderProposalProof.proto +package slash diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go new file mode 100644 index 000000000..48745ad9b --- /dev/null +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -0,0 +1,431 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: multipleHeaderProposalProof.proto + +package slash + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MultipleHeaderProposalProof struct { + Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + Headers *Headers `protobuf:"bytes,2,opt,name=Headers,proto3" json:"Headers,omitempty"` +} + +func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } +func (*MultipleHeaderProposalProof) ProtoMessage() {} +func (*MultipleHeaderProposalProof) Descriptor() ([]byte, []int) { + return fileDescriptor_afe79f980fc6faed, []int{0} +} +func (m *MultipleHeaderProposalProof) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MultipleHeaderProposalProof) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *MultipleHeaderProposalProof) XXX_Merge(src proto.Message) { + xxx_messageInfo_MultipleHeaderProposalProof.Merge(m, src) +} +func (m *MultipleHeaderProposalProof) XXX_Size() int { + return m.Size() +} +func (m *MultipleHeaderProposalProof) XXX_DiscardUnknown() { + xxx_messageInfo_MultipleHeaderProposalProof.DiscardUnknown(m) +} + +var xxx_messageInfo_MultipleHeaderProposalProof proto.InternalMessageInfo + +func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { + if m != nil { + return m.Level + } + return Low +} + +func (m *MultipleHeaderProposalProof) GetHeaders() *Headers { + if m != nil { + return m.Headers + } + return nil +} + +func init() { + proto.RegisterType((*MultipleHeaderProposalProof)(nil), "proto.MultipleHeaderProposalProof") +} + +func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } + +var fileDescriptor_afe79f980fc6faed = []byte{ + // 233 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,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7, + 0xf0, 0xe1, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, + 0xc7, 0x10, 0xc5, 0x0a, 0xf6, 0x68, 0x12, 0x1b, 0xd8, 0x60, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xf1, 0x91, 0x50, 0x0c, 0x22, 0x01, 0x00, 0x00, +} + +func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MultipleHeaderProposalProof) + if !ok { + that2, ok := that.(MultipleHeaderProposalProof) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Level != that1.Level { + return false + } + if !this.Headers.Equal(that1.Headers) { + return false + } + return true +} +func (this *MultipleHeaderProposalProof) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&slash.MultipleHeaderProposalProof{") + s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") + if this.Headers != nil { + s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringMultipleHeaderProposalProof(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *MultipleHeaderProposalProof) 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 *MultipleHeaderProposalProof) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Headers != nil { + { + size, err := m.Headers.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Level != 0 { + i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Level)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintMultipleHeaderProposalProof(dAtA []byte, offset int, v uint64) int { + offset -= sovMultipleHeaderProposalProof(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MultipleHeaderProposalProof) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Level != 0 { + n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) + } + if m.Headers != nil { + l = m.Headers.Size() + n += 1 + l + sovMultipleHeaderProposalProof(uint64(l)) + } + return n +} + +func sovMultipleHeaderProposalProof(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozMultipleHeaderProposalProof(x uint64) (n int) { + return sovMultipleHeaderProposalProof(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *MultipleHeaderProposalProof) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&MultipleHeaderProposalProof{`, + `Level:` + fmt.Sprintf("%v", this.Level) + `,`, + `Headers:` + strings.Replace(fmt.Sprintf("%v", this.Headers), "Headers", "Headers", 1) + `,`, + `}`, + }, "") + return s +} +func valueToStringMultipleHeaderProposalProof(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *MultipleHeaderProposalProof) 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 ErrIntOverflowMultipleHeaderProposalProof + } + 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: MultipleHeaderProposalProof: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MultipleHeaderProposalProof: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Level", wireType) + } + m.Level = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Level |= ThreatLevel(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMultipleHeaderProposalProof + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMultipleHeaderProposalProof + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Headers == nil { + m.Headers = &Headers{} + } + if err := m.Headers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMultipleHeaderProposalProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMultipleHeaderProposalProof + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthMultipleHeaderProposalProof + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMultipleHeaderProposalProof(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthMultipleHeaderProposalProof + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupMultipleHeaderProposalProof + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthMultipleHeaderProposalProof + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthMultipleHeaderProposalProof = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMultipleHeaderProposalProof = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupMultipleHeaderProposalProof = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto new file mode 100644 index 000000000..604da9d27 --- /dev/null +++ b/data/slash/multipleHeaderProposalProof.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package proto; + +option go_package = "slash"; +option (gogoproto.stable_marshaler_all) = true; + +import "slash.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message MultipleHeaderProposalProof { + ThreatLevel Level = 1; + Headers Headers = 2; +} \ No newline at end of file diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index e49b2a86c..50407421f 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -96,23 +96,23 @@ var fileDescriptor_f61c9968ee2015ff = []byte{ 0x18, 0xc6, 0xf3, 0x26, 0xb4, 0xc5, 0x4b, 0x29, 0x72, 0xd3, 0x91, 0xe1, 0x25, 0x88, 0x43, 0x96, 0xa6, 0x50, 0x17, 0x71, 0x11, 0x84, 0x42, 0x51, 0x0b, 0x25, 0x3a, 0xb9, 0x25, 0x7a, 0x4d, 0x83, 0x69, 0xaf, 0xe4, 0x4f, 0xa1, 0x9b, 0x1f, 0xc1, 0x8f, 0xe1, 0x47, 0x71, 0xec, 0xd8, 0xd1, 0x5e, - 0x17, 0xc7, 0x7e, 0x04, 0xf1, 0x2e, 0x85, 0x0c, 0x16, 0xa7, 0x7b, 0xdf, 0x97, 0xe7, 0xf7, 0x7b, - 0x86, 0x23, 0xee, 0xac, 0x4c, 0x8b, 0x64, 0x91, 0xf2, 0x21, 0x0f, 0x5f, 0x78, 0xf6, 0x90, 0xc4, - 0xf3, 0x64, 0x1e, 0x8f, 0x33, 0x21, 0x26, 0xfe, 0x22, 0x13, 0x85, 0xa0, 0x0d, 0xf5, 0x38, 0x76, - 0x9e, 0x86, 0xf9, 0x54, 0xdf, 0x9c, 0x6e, 0x9c, 0x14, 0xd3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 0x63, + 0x19, 0xa6, 0x25, 0x67, 0xa6, 0x0b, 0x5e, 0xa7, 0x4f, 0xab, 0xa1, 0xc7, 0x69, 0xc6, 0xc3, 0x42, + 0xa1, 0x81, 0x2e, 0x5c, 0x99, 0x97, 0xe0, 0xdc, 0x92, 0x76, 0x7d, 0xe7, 0x0f, 0xdf, 0x79, 0xdd, + 0x67, 0xf7, 0x3b, 0x95, 0xaf, 0xa2, 0x6a, 0xae, 0x9b, 0xeb, 0xf5, 0x16, 0x8d, 0xcd, 0x16, 0x8d, + 0xfd, 0x16, 0xe1, 0x4d, 0x22, 0x7c, 0x48, 0x84, 0x4f, 0x89, 0xb0, 0x96, 0x08, 0x1b, 0x89, 0xf0, + 0x25, 0x11, 0xbe, 0x25, 0x1a, 0x7b, 0x89, 0xf0, 0xbe, 0x43, 0x63, 0xbd, 0x43, 0x63, 0xb3, 0x43, + 0xe3, 0xa9, 0xa1, 0xde, 0x2a, 0x6a, 0x2a, 0xf5, 0xc5, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x09, + 0xc5, 0xf7, 0x45, 0x13, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 07da572e6..3fe9bd765 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -5,8 +5,8 @@ package proto; option go_package = "slash"; option (gogoproto.stable_marshaler_all) = true; -import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "slash.proto"; message MultipleHeaderSigningProof { repeated bytes PubKeys = 1; From 8ba35ca8fe9360197fdb92f67da2ee03602f7122 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 18:59:40 +0300 Subject: [PATCH 04/54] FIX: Add empty line --- data/slash/multipleHeaderProposalProof.proto | 2 +- data/slash/multipleHeaderSigningProof.proto | 2 +- data/slash/slash.proto | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 604da9d27..24c01589e 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -11,4 +11,4 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderProposalProof { ThreatLevel Level = 1; Headers Headers = 2; -} \ No newline at end of file +} diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 3fe9bd765..6597bbdc4 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -12,4 +12,4 @@ message MultipleHeaderSigningProof { repeated bytes PubKeys = 1; map Levels = 2; map Headers = 3; -} \ No newline at end of file +} diff --git a/data/slash/slash.proto b/data/slash/slash.proto index 27c3cfa0a..04c472494 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -22,4 +22,4 @@ enum ThreatLevel { message Headers{ repeated HeaderV2 Headers = 1; -} \ No newline at end of file +} From dd931a3ef5bb5c0da8cde92f7c16a55730d5ca8e Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 19:01:56 +0300 Subject: [PATCH 05/54] FIX: Import order --- data/slash/multipleHeaderProposalProof.proto | 2 +- data/slash/multipleHeaderSigningProof.proto | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 24c01589e..24a1014ed 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -9,6 +9,6 @@ import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderProposalProof { - ThreatLevel Level = 1; + ThreatLevel Level = 1; Headers Headers = 2; } diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 6597bbdc4..a88eae6b7 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -5,11 +5,11 @@ package proto; option go_package = "slash"; option (gogoproto.stable_marshaler_all) = true; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "slash.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderSigningProof { repeated bytes PubKeys = 1; - map Levels = 2; - map Headers = 3; + map Levels = 2; + map Headers = 3; } From 1e3790b370e69d4e91f0bd74eb383648b84bd364 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 19:03:10 +0300 Subject: [PATCH 06/54] FIX: Generate proto file --- data/slash/multipleHeaderSigningProof.pb.go | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 50407421f..e49b2a86c 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -96,23 +96,23 @@ var fileDescriptor_f61c9968ee2015ff = []byte{ 0x18, 0xc6, 0xf3, 0x26, 0xb4, 0xc5, 0x4b, 0x29, 0x72, 0xd3, 0x91, 0xe1, 0x25, 0x88, 0x43, 0x96, 0xa6, 0x50, 0x17, 0x71, 0x11, 0x84, 0x42, 0x51, 0x0b, 0x25, 0x3a, 0xb9, 0x25, 0x7a, 0x4d, 0x83, 0x69, 0xaf, 0xe4, 0x4f, 0xa1, 0x9b, 0x1f, 0xc1, 0x8f, 0xe1, 0x47, 0x71, 0xec, 0xd8, 0xd1, 0x5e, - 0x17, 0xc7, 0x7e, 0x04, 0xf1, 0x2e, 0x85, 0x0c, 0x16, 0xa7, 0xbc, 0x4f, 0x78, 0x7e, 0xbf, 0x67, - 0x38, 0xe2, 0xce, 0xca, 0xb4, 0x48, 0x16, 0x29, 0x1f, 0xf2, 0xf0, 0x85, 0x67, 0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0x33, 0x4b, 0x79, 0xfc, 0xff, 0x3d, 0x15, 0xa0, 0x45, 0x07, 0xdc, 0x19, 0x11, 0xbb, + 0x56, 0x40, 0x4f, 0x89, 0xf5, 0xca, 0x57, 0x0c, 0x5c, 0xf0, 0x4e, 0x82, 0xdf, 0x91, 0x7a, 0xa4, + 0xb1, 0x0c, 0xd3, 0x92, 0x33, 0xd3, 0x05, 0xaf, 0xd3, 0xa7, 0x55, 0xd1, 0xe3, 0x34, 0xe3, 0x61, + 0xa1, 0xd0, 0x40, 0x07, 0xae, 0xcc, 0x4b, 0x70, 0x6e, 0x49, 0xbb, 0xde, 0xf3, 0x87, 0xef, 0xbc, + 0xee, 0xb3, 0xfb, 0x9d, 0xca, 0x57, 0x51, 0x35, 0xd7, 0xcd, 0xf5, 0x7a, 0x8b, 0xc6, 0x66, 0x8b, + 0xc6, 0x7e, 0x8b, 0xf0, 0x26, 0x11, 0x3e, 0x24, 0xc2, 0xa7, 0x44, 0x58, 0x4b, 0x84, 0x8d, 0x44, + 0xf8, 0x92, 0x08, 0xdf, 0x12, 0x8d, 0xbd, 0x44, 0x78, 0xdf, 0xa1, 0xb1, 0xde, 0xa1, 0xb1, 0xd9, + 0xa1, 0xf1, 0xd4, 0x50, 0x5f, 0x1b, 0x35, 0x95, 0xfa, 0xe2, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe1, + 0xa9, 0x7e, 0xbc, 0x13, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { From aebaffe0a5cfa6957a6372f070306a823f24ebc0 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 20 Oct 2021 15:14:53 +0300 Subject: [PATCH 07/54] FEAT: Remove pointer to slice --- data/slash/multipleHeaderProposalProof.pb.go | 61 ++++++------- data/slash/multipleHeaderProposalProof.proto | 2 +- data/slash/multipleHeaderSigningProof.pb.go | 91 ++++++++++---------- data/slash/multipleHeaderSigningProof.proto | 2 +- 4 files changed, 72 insertions(+), 84 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index 48745ad9b..2d517dd9f 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - Headers *Headers `protobuf:"bytes,2,opt,name=Headers,proto3" json:"Headers,omitempty"` + Headers Headers `protobuf:"bytes,2,opt,name=Headers,proto3" json:"Headers"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -65,11 +65,11 @@ func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { return Low } -func (m *MultipleHeaderProposalProof) GetHeaders() *Headers { +func (m *MultipleHeaderProposalProof) GetHeaders() Headers { if m != nil { return m.Headers } - return nil + return Headers{} } func init() { @@ -79,22 +79,22 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 233 bytes of a gzipped FileDescriptorProto + // 239 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x2d, 0xcd, 0x29, 0xc9, 0x2c, 0xc8, 0x49, 0xf5, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x0a, 0x28, 0xca, 0x2f, 0xc8, 0x2f, 0x4e, 0xcc, 0x09, 0x28, 0xca, 0xcf, 0x4f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xdc, 0xc5, 0x39, 0x89, 0xc5, 0x19, 0x10, 0x31, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 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00, 0x00, + 0x82, 0xe8, 0xd2, 0x0b, 0xc9, 0x28, 0x4a, 0x4d, 0x2c, 0x01, 0xcb, 0x04, 0x41, 0x14, 0x08, 0xe9, + 0x71, 0xb1, 0x43, 0x0c, 0x28, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0xe2, 0x83, 0xaa, 0x85, + 0x8a, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x53, 0xe4, 0x64, 0x7f, 0xe1, 0xa1, 0x1c, + 0xc3, 0x8d, 0x87, 0x72, 0x0c, 0x1f, 0x1e, 0xca, 0x31, 0x36, 0x3c, 0x92, 0x63, 0x5c, 0xf1, 0x48, + 0x8e, 0xf1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x6f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, + 0x48, 0x8e, 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0x77, 0x93, 0xd8, 0xc0, 0xc6, + 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xd2, 0xe6, 0x0c, 0x3a, 0x28, 0x01, 0x00, 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -119,7 +119,7 @@ func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { if this.Level != that1.Level { return false } - if !this.Headers.Equal(that1.Headers) { + if !this.Headers.Equal(&that1.Headers) { return false } return true @@ -131,9 +131,7 @@ func (this *MultipleHeaderProposalProof) GoString() string { s := make([]string, 0, 6) s = append(s, "&slash.MultipleHeaderProposalProof{") s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") - if this.Headers != nil { - s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") - } + s = append(s, "Headers: "+strings.Replace(this.Headers.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -165,18 +163,16 @@ func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l - if m.Headers != nil { - { - size, err := m.Headers.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(size)) + { + size, err := m.Headers.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if m.Level != 0 { i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Level)) i-- @@ -205,10 +201,8 @@ func (m *MultipleHeaderProposalProof) Size() (n int) { if m.Level != 0 { n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) } - if m.Headers != nil { - l = m.Headers.Size() - n += 1 + l + sovMultipleHeaderProposalProof(uint64(l)) - } + l = m.Headers.Size() + n += 1 + l + sovMultipleHeaderProposalProof(uint64(l)) return n } @@ -224,7 +218,7 @@ func (this *MultipleHeaderProposalProof) String() string { } s := strings.Join([]string{`&MultipleHeaderProposalProof{`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, - `Headers:` + strings.Replace(fmt.Sprintf("%v", this.Headers), "Headers", "Headers", 1) + `,`, + `Headers:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Headers), "Headers", "Headers", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -314,9 +308,6 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Headers == nil { - m.Headers = &Headers{} - } if err := m.Headers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 24a1014ed..40a0304d7 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -10,5 +10,5 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderProposalProof { ThreatLevel Level = 1; - Headers Headers = 2; + Headers Headers = 2 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index e49b2a86c..6a592e577 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -30,7 +30,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - Headers map[string]*Headers `protobuf:"bytes,3,rep,name=Headers,proto3" json:"Headers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Headers map[string]Headers `protobuf:"bytes,3,rep,name=Headers,proto3" json:"Headers" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -75,7 +75,7 @@ func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { return nil } -func (m *MultipleHeaderSigningProof) GetHeaders() map[string]*Headers { +func (m *MultipleHeaderSigningProof) GetHeaders() map[string]Headers { if m != nil { return m.Headers } @@ -84,35 +84,36 @@ func (m *MultipleHeaderSigningProof) GetHeaders() map[string]*Headers { func init() { proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") - proto.RegisterMapType((map[string]*Headers)(nil), "proto.MultipleHeaderSigningProof.HeadersEntry") + proto.RegisterMapType((map[string]Headers)(nil), "proto.MultipleHeaderSigningProof.HeadersEntry") proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") } func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 327 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x3f, 0x4b, 0xc3, 0x40, - 0x18, 0xc6, 0xf3, 0x26, 0xb4, 0xc5, 0x4b, 0x29, 0x72, 0xd3, 0x91, 0xe1, 0x25, 0x88, 0x43, 0x96, - 0xa6, 0x50, 0x17, 0x71, 0x11, 0x84, 0x42, 0x51, 0x0b, 0x25, 0x3a, 0xb9, 0x25, 0x7a, 0x4d, 0x83, - 0x69, 0xaf, 0xe4, 0x4f, 0xa1, 0x9b, 0x1f, 0xc1, 0x8f, 0xe1, 0x47, 0x71, 0xec, 0xd8, 0xd1, 0x5e, - 0x17, 0xc7, 0x7e, 0x04, 0xf1, 0x2e, 0x85, 0x0c, 0x16, 0xa7, 0x7b, 0xdf, 0x97, 0xe7, 0xf7, 0x7b, - 0x86, 0x23, 0xee, 0xac, 0x4c, 0x8b, 0x64, 0x91, 0xf2, 0x21, 0x0f, 0x5f, 0x78, 0xf6, 0x90, 0xc4, - 0xf3, 0x64, 0x1e, 0x8f, 0x33, 0x21, 0x26, 0xfe, 0x22, 0x13, 0x85, 0xa0, 0x0d, 0xf5, 0x38, 0x76, - 0x9e, 0x86, 0xf9, 0x54, 0xdf, 0x9c, 0x6e, 0x9c, 0x14, 0xd3, 0x32, 0xf2, 0x9f, 0xc5, 0xac, 0x17, - 0x8b, 0x58, 0xf4, 0xd4, 0x39, 0x2a, 0x27, 0x6a, 0x53, 0x8b, 0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- 0xa9, 0x7e, 0xbc, 0x13, 0x02, 0x00, 0x00, + // 338 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x3f, 0x6b, 0xf2, 0x50, + 0x18, 0xc5, 0xef, 0x93, 0xbc, 0x2a, 0xef, 0x8d, 0xc8, 0xcb, 0x9d, 0x42, 0x86, 0xe7, 0x0d, 0xa5, + 0x43, 0x16, 0x23, 0xd8, 0xa5, 0x74, 0x29, 0x08, 0x42, 0x69, 0x6b, 0x91, 0xb4, 0x53, 0xb7, 0xa4, + 0xbd, 0xc6, 0xd0, 0xe8, 0x95, 0xfc, 0x11, 0xdc, 0xfa, 0x11, 0xfa, 0x31, 0xfa, 0x51, 0x1c, 0x1d, + 0x9d, 0x4a, 0xbd, 0x2e, 0x8e, 0x7e, 0x84, 0xd2, 0x9b, 0x08, 0x19, 0x2a, 0x9d, 0xee, 0x73, 0x0e, + 0xe7, 0xfc, 0xce, 0x70, 0xa9, 0x3d, 0xc9, 0xe3, 0x2c, 0x9a, 0xc5, 0xfc, 0x8a, 0xfb, 0xcf, 0x3c, + 0xb9, 0x8f, 0xc2, 0x69, 0x34, 0x0d, 0x87, 0x89, 0x10, 0x23, 0x77, 0x96, 0x88, 0x4c, 0xb0, 0x9a, + 0x7a, 0x2c, 0x23, 0x8d, 0xfd, 0x74, 0x5c, 0x78, 0x56, 0x3b, 0x8c, 0xb2, 0x71, 0x1e, 0xb8, 0x4f, + 0x62, 0xd2, 0x09, 0x45, 0x28, 0x3a, 0xca, 0x0e, 0xf2, 0x91, 0x52, 0x4a, 0xa8, 0xab, 0x88, 0x9f, + 0xec, 0x34, 0x6a, 0x0d, 0x8e, 0xee, 0x30, 0x93, 0x36, 0x86, 0x79, 0x70, 0xc3, 0x17, 0xa9, 0x09, + 0xb6, 0xee, 0x34, 0xbd, 0x83, 0x64, 0x7d, 0x5a, 0xbf, 0xe5, 0x73, 0x1e, 0xa7, 0xa6, 0x66, 0xeb, + 0x8e, 0xd1, 0x6d, 0x17, 0x40, 0xf7, 0x38, 0xcc, 0x2d, 0xf2, 0xfd, 0x69, 0x96, 0x2c, 0xbc, 0xb2, + 0xcc, 0xee, 0x68, 0xa3, 0x48, 0xa6, 0xa6, 0xae, 0x38, 0xee, 0xef, 0x9c, 0xb2, 0xa0, 0x40, 0xbd, + 0x3f, 0xcb, 0x8f, 0xff, 0xc4, 0x3b, 0x40, 0xac, 0x01, 0x35, 0x2a, 0x33, 0xec, 0x1f, 0xd5, 0x5f, + 0xf8, 0xc2, 0x04, 0x1b, 0x9c, 0xbf, 0xde, 0xf7, 0xc9, 0x1c, 0x5a, 0x9b, 0xfb, 0x71, 0xce, 0x4d, + 0xcd, 0x06, 0xa7, 0xd5, 0x65, 0xe5, 0xdc, 0xc3, 0x38, 0xe1, 0x7e, 0xa6, 0xaa, 0x5e, 0x11, 0xb8, + 0xd0, 0xce, 0xc1, 0xba, 0xa6, 0xcd, 0xea, 0xda, 0x0f, 0xbc, 0xd3, 0x2a, 0xcf, 0xe8, 0xb6, 0x4a, + 0x5e, 0xd9, 0xaa, 0xb0, 0x7a, 0x97, 0xab, 0x0d, 0x92, 0xf5, 0x06, 0xc9, 0x7e, 0x83, 0xf0, 0x2a, + 0x11, 0xde, 0x25, 0xc2, 0x52, 0x22, 0xac, 0x24, 0xc2, 0x5a, 0x22, 0x7c, 0x4a, 0x84, 0x9d, 0x44, + 0xb2, 0x97, 0x08, 0x6f, 0x5b, 0x24, 0xab, 0x2d, 0x92, 0xf5, 0x16, 0xc9, 0x63, 0x4d, 0x7d, 0x70, + 0x50, 0x57, 0xe8, 0xb3, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x05, 0x6e, 0x59, 0x19, 0x02, + 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -154,7 +155,9 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { return false } for i := range this.Headers { - if !this.Headers[i].Equal(that1.Headers[i]) { + a := this.Headers[i] + b := that1.Headers[i] + if !(&a).Equal(&b) { return false } } @@ -185,7 +188,7 @@ func (this *MultipleHeaderSigningProof) GoString() string { keysForHeaders = append(keysForHeaders, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) - mapStringForHeaders := "map[string]*Headers{" + mapStringForHeaders := "map[string]Headers{" for _, k := range keysForHeaders { mapStringForHeaders += fmt.Sprintf("%#v: %#v,", k, this.Headers[k]) } @@ -233,18 +236,16 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err for iNdEx := len(keysForHeaders) - 1; iNdEx >= 0; iNdEx-- { v := m.Headers[string(keysForHeaders[iNdEx])] baseI := i - if v != nil { - { - size, err := v.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(size)) + { + size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 i -= len(keysForHeaders[iNdEx]) copy(dAtA[i:], keysForHeaders[iNdEx]) i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeaders[iNdEx]))) @@ -324,12 +325,8 @@ func (m *MultipleHeaderSigningProof) Size() (n int) { for k, v := range m.Headers { _ = k _ = v - l = 0 - if v != nil { - l = v.Size() - l += 1 + sovMultipleHeaderSigningProof(uint64(l)) - } - mapEntrySize := 1 + len(k) + sovMultipleHeaderSigningProof(uint64(len(k))) + l + l = v.Size() + mapEntrySize := 1 + len(k) + sovMultipleHeaderSigningProof(uint64(len(k))) + 1 + l + sovMultipleHeaderSigningProof(uint64(l)) n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) } } @@ -361,7 +358,7 @@ func (this *MultipleHeaderSigningProof) String() string { keysForHeaders = append(keysForHeaders, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) - mapStringForHeaders := "map[string]*Headers{" + mapStringForHeaders := "map[string]Headers{" for _, k := range keysForHeaders { mapStringForHeaders += fmt.Sprintf("%v: %v,", k, this.Headers[k]) } @@ -586,10 +583,10 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Headers == nil { - m.Headers = make(map[string]*Headers) + m.Headers = make(map[string]Headers) } var mapkey string - var mapvalue *Headers + mapvalue := &Headers{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -683,7 +680,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.Headers[mapkey] = mapvalue + m.Headers[mapkey] = *mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index a88eae6b7..a5b79b8e4 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -11,5 +11,5 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderSigningProof { repeated bytes PubKeys = 1; map Levels = 2; - map Headers = 3; + map Headers = 3 [(gogoproto.nullable) = false]; } From 9e288ddbf0be52a99eaafc0e598d070961f9e81c Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 21 Oct 2021 11:43:54 +0300 Subject: [PATCH 08/54] FEAT: Add SetHeaders --- data/slash/slash.go | 22 +++++++++++++++++++++ data/slash/slash_test.go | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 data/slash/slash_test.go diff --git a/data/slash/slash.go b/data/slash/slash.go index 8d3b8f339..5b43e02b1 100644 --- a/data/slash/slash.go +++ b/data/slash/slash.go @@ -1,2 +1,24 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. slash.proto package slash + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" +) + +func (m *Headers) SetHeaders(headers []data.HeaderHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + for _, header := range headers { + hdr, castOk := header.(*block.HeaderV2) + if !castOk { + return data.ErrInvalidTypeAssertion + } + + m.Headers = append(m.Headers, hdr) + } + + return nil +} diff --git a/data/slash/slash_test.go b/data/slash/slash_test.go new file mode 100644 index 000000000..db3c4062f --- /dev/null +++ b/data/slash/slash_test.go @@ -0,0 +1,41 @@ +package slash_test + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/stretchr/testify/require" +) + +func TestHeaders_SetHeaders_InvalidHeaders_ExpectError(t *testing.T) { + header := &block.Header{TimeStamp: 1} + headers := slash.Headers{} + + err := headers.SetHeaders([]data.HeaderHandler{header}) + require.Equal(t, data.ErrInvalidTypeAssertion, err) +} + +func TestHeaders_SetHeaders(t *testing.T) { + header1 := &block.HeaderV2{ + Header: &block.Header{ + TimeStamp: 1, + }, + } + header2 := &block.HeaderV2{ + Header: &block.Header{ + TimeStamp: 2, + }, + } + + in := []data.HeaderHandler{header1, header2} + headers := slash.Headers{} + + err := headers.SetHeaders(in) + require.Nil(t, err) + + require.Len(t, headers.GetHeaders(), 2) + require.Contains(t, headers.GetHeaders(), header1) + require.Contains(t, headers.GetHeaders(), header2) +} From dc2c27913407c583663b32b05f862ccf3b44eef7 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 15:28:31 +0200 Subject: [PATCH 09/54] FEAT: Add proof proto struct --- data/slash/multipleHeaderProposalProof.pb.go | 74 ++++++++++--- data/slash/multipleHeaderProposalProof.proto | 5 +- data/slash/multipleHeaderSigningProof.pb.go | 105 +++++++++++++------ data/slash/multipleHeaderSigningProof.proto | 7 +- data/slash/proof.go | 2 + data/slash/proof.proto | 13 +++ 6 files changed, 153 insertions(+), 53 deletions(-) create mode 100644 data/slash/proof.go create mode 100644 data/slash/proof.proto diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index 2d517dd9f..e63d317ef 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -26,8 +26,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { - Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - Headers Headers `protobuf:"bytes,2,opt,name=Headers,proto3" json:"Headers"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + Headers Headers `protobuf:"bytes,3,opt,name=Headers,proto3" json:"Headers"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -58,6 +59,13 @@ func (m *MultipleHeaderProposalProof) XXX_DiscardUnknown() { var xxx_messageInfo_MultipleHeaderProposalProof proto.InternalMessageInfo +func (m *MultipleHeaderProposalProof) GetType() SlashingType { + if m != nil { + return m.Type + } + return None +} + func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { if m != nil { return m.Level @@ -79,22 +87,24 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 239 bytes of a gzipped FileDescriptorProto + // 266 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 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e, 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, - 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0x77, 0x93, 0xd8, 0xc0, 0xc6, - 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xd2, 0xe6, 0x0c, 0x3a, 0x28, 0x01, 0x00, 0x00, + 0x1a, 0x98, 0x07, 0xe6, 0x80, 0x59, 0x10, 0xe5, 0x4a, 0x0b, 0x18, 0xb9, 0xa4, 0x7d, 0x71, 0x5b, + 0x24, 0xa4, 0xce, 0xc5, 0x12, 0x52, 0x59, 0x90, 0x2a, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x67, 0x24, + 0x0c, 0xd1, 0xa5, 0x17, 0x0c, 0xb2, 0x30, 0x33, 0x2f, 0x1d, 0x24, 0x15, 0x04, 0x56, 0x20, 0xa4, + 0xc1, 0xc5, 0xea, 0x93, 0x5a, 0x96, 0x9a, 0x23, 0xc1, 0x04, 0x56, 0x29, 0x04, 0x55, 0x19, 0x92, + 0x51, 0x94, 0x9a, 0x58, 0x02, 0x96, 0x09, 0x82, 0x28, 0x10, 0xd2, 0xe3, 0x62, 0x87, 0xd8, 0x54, + 0x2c, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0x6d, 0xc4, 0x07, 0x55, 0x0b, 0x15, 0x75, 0x62, 0x39, 0x71, + 0x4f, 0x9e, 0x21, 0x08, 0xa6, 0xc8, 0xc9, 0xfe, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, 0x18, + 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, + 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, 0x47, + 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, + 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, 0x80, 0x49, 0x62, 0x03, 0x1b, 0x6f, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0xf5, 0xf7, 0x23, 0xf5, 0x52, 0x01, 0x00, 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -116,6 +126,9 @@ func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { } else if this == nil { return false } + if this.Type != that1.Type { + return false + } if this.Level != that1.Level { return false } @@ -128,8 +141,9 @@ func (this *MultipleHeaderProposalProof) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&slash.MultipleHeaderProposalProof{") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") s = append(s, "Headers: "+strings.Replace(this.Headers.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") @@ -172,10 +186,15 @@ func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, er i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a if m.Level != 0 { i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Level)) i-- + dAtA[i] = 0x10 + } + if m.Type != 0 { + i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Type)) + i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil @@ -198,6 +217,9 @@ func (m *MultipleHeaderProposalProof) Size() (n int) { } var l int _ = l + if m.Type != 0 { + n += 1 + sovMultipleHeaderProposalProof(uint64(m.Type)) + } if m.Level != 0 { n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) } @@ -217,6 +239,7 @@ func (this *MultipleHeaderProposalProof) String() string { return "nil" } s := strings.Join([]string{`&MultipleHeaderProposalProof{`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, `Headers:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Headers), "Headers", "Headers", 1), `&`, ``, 1) + `,`, `}`, @@ -261,6 +284,25 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderProposalProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SlashingType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Level", wireType) } @@ -279,7 +321,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { break } } - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) } diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 40a0304d7..27c6d4b08 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -9,6 +9,7 @@ import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderProposalProof { - ThreatLevel Level = 1; - Headers Headers = 2 [(gogoproto.nullable) = false]; + SlashingType Type = 1; + ThreatLevel Level = 2; + Headers Headers = 3 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 6a592e577..c766851b4 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -28,9 +28,10 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { - PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - Headers map[string]Headers `protobuf:"bytes,3,rep,name=Headers,proto3" json:"Headers" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + Headers map[string]Headers `protobuf:"bytes,4,rep,name=Headers,proto3" json:"Headers" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -61,6 +62,13 @@ func (m *MultipleHeaderSigningProof) XXX_DiscardUnknown() { var xxx_messageInfo_MultipleHeaderSigningProof proto.InternalMessageInfo +func (m *MultipleHeaderSigningProof) GetType() SlashingType { + if m != nil { + return m.Type + } + return None +} + func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { if m != nil { return m.PubKeys @@ -91,29 +99,30 @@ func init() { func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 338 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 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d, 0xf2, 0xfd, 0x69, 0x96, 0x2c, 0xbc, 0xb2, - 0xcc, 0xee, 0x68, 0xa3, 0x48, 0xa6, 0xa6, 0xae, 0x38, 0xee, 0xef, 0x9c, 0xb2, 0xa0, 0x40, 0xbd, - 0x3f, 0xcb, 0x8f, 0xff, 0xc4, 0x3b, 0x40, 0xac, 0x01, 0x35, 0x2a, 0x33, 0xec, 0x1f, 0xd5, 0x5f, - 0xf8, 0xc2, 0x04, 0x1b, 0x9c, 0xbf, 0xde, 0xf7, 0xc9, 0x1c, 0x5a, 0x9b, 0xfb, 0x71, 0xce, 0x4d, - 0xcd, 0x06, 0xa7, 0xd5, 0x65, 0xe5, 0xdc, 0xc3, 0x38, 0xe1, 0x7e, 0xa6, 0xaa, 0x5e, 0x11, 0xb8, - 0xd0, 0xce, 0xc1, 0xba, 0xa6, 0xcd, 0xea, 0xda, 0x0f, 0xbc, 0xd3, 0x2a, 0xcf, 0xe8, 0xb6, 0x4a, - 0x5e, 0xd9, 0xaa, 0xb0, 0x7a, 0x97, 0xab, 0x0d, 0x92, 0xf5, 0x06, 0xc9, 0x7e, 0x83, 0xf0, 0x2a, - 0x11, 0xde, 0x25, 0xc2, 0x52, 0x22, 0xac, 0x24, 0xc2, 0x5a, 0x22, 0x7c, 0x4a, 0x84, 0x9d, 0x44, - 0xb2, 0x97, 0x08, 0x6f, 0x5b, 0x24, 0xab, 0x2d, 0x92, 0xf5, 0x16, 0xc9, 0x63, 0x4d, 0x7d, 0x70, - 0x50, 0x57, 0xe8, 0xb3, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x05, 0x6e, 0x59, 0x19, 0x02, - 0x00, 0x00, + // 361 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x6a, 0xea, 0x40, + 0x14, 0xc6, 0x67, 0x8c, 0x7f, 0xb8, 0x13, 0x91, 0xcb, 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, 0x90, 0xe3, + 0xad, 0x56, 0xee, 0xef, 0x87, 0x49, 0x94, 0xd9, 0x45, 0x98, 0xde, 0x93, 0x46, 0xee, 0x8c, 0xb5, + 0xaa, 0xe4, 0x58, 0xbf, 0x73, 0x8a, 0x80, 0x04, 0xf5, 0xaa, 0xcb, 0x8f, 0xff, 0xc8, 0x3e, 0x40, + 0xf4, 0x01, 0x51, 0x4b, 0x35, 0xf4, 0x2f, 0x51, 0x9e, 0x59, 0x26, 0xef, 0xfc, 0x63, 0xef, 0x47, + 0x6a, 0x92, 0xda, 0xc2, 0x09, 0x52, 0xa6, 0x55, 0xe4, 0xed, 0xb4, 0xa8, 0x1b, 0x4f, 0x23, 0xe6, + 0x24, 0x32, 0x6a, 0xe7, 0x86, 0xcb, 0xca, 0x05, 0xd6, 0x6f, 0x48, 0xb3, 0xdc, 0xf6, 0x03, 0xef, + 0xb4, 0xcc, 0x53, 0xbb, 0xad, 0x82, 0x57, 0xa4, 0x4a, 0xac, 0xde, 0xd5, 0x6a, 0x03, 0x68, 0xbd, + 0x01, 0xb4, 0xdb, 0x00, 0x7e, 0x11, 0x80, 0xdf, 0x05, 0xe0, 0xa5, 0x00, 0xbc, 0x12, 0x80, 0xd7, + 0x02, 0xf0, 0xa7, 0x00, 0xfc, 0x25, 0x00, 0xed, 0x04, 0xe0, 0xd7, 0x2d, 0xa0, 0xd5, 0x16, 0xd0, + 0x7a, 0x0b, 0xe8, 0xa1, 0x26, 0x5f, 0x82, 0x5b, 0x97, 0xe8, 0xf3, 0xef, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x22, 0x19, 0x77, 0x9e, 0x42, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -135,6 +144,9 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { } else if this == nil { return false } + if this.Type != that1.Type { + return false + } if len(this.PubKeys) != len(that1.PubKeys) { return false } @@ -167,8 +179,9 @@ func (this *MultipleHeaderSigningProof) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 8) s = append(s, "&slash.MultipleHeaderSigningProof{") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "PubKeys: "+fmt.Sprintf("%#v", this.PubKeys)+",\n") keysForLevels := make([]string, 0, len(this.Levels)) for k, _ := range this.Levels { @@ -253,7 +266,7 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } } if len(m.Levels) > 0 { @@ -275,7 +288,7 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } if len(m.PubKeys) > 0 { @@ -284,9 +297,14 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err copy(dAtA[i:], m.PubKeys[iNdEx]) i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(m.PubKeys[iNdEx]))) i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 } } + if m.Type != 0 { + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -307,6 +325,9 @@ func (m *MultipleHeaderSigningProof) Size() (n int) { } var l int _ = l + if m.Type != 0 { + n += 1 + sovMultipleHeaderSigningProof(uint64(m.Type)) + } if len(m.PubKeys) > 0 { for _, b := range m.PubKeys { l = len(b) @@ -364,6 +385,7 @@ func (this *MultipleHeaderSigningProof) String() string { } mapStringForHeaders += "}" s := strings.Join([]string{`&MultipleHeaderSigningProof{`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, `Levels:` + mapStringForLevels + `,`, `Headers:` + mapStringForHeaders + `,`, @@ -409,6 +431,25 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SlashingType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PubKeys", wireType) } @@ -440,7 +481,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { m.PubKeys = append(m.PubKeys, make([]byte, postIndex-iNdEx)) copy(m.PubKeys[len(m.PubKeys)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Levels", wireType) } @@ -553,7 +594,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { } m.Levels[mapkey] = mapvalue iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) } diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index a5b79b8e4..be73c45bb 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -9,7 +9,8 @@ import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderSigningProof { - repeated bytes PubKeys = 1; - map Levels = 2; - map Headers = 3 [(gogoproto.nullable) = false]; + SlashingType Type = 1; + repeated bytes PubKeys = 2; + map Levels = 3; + map Headers = 4 [(gogoproto.nullable) = false]; } diff --git a/data/slash/proof.go b/data/slash/proof.go new file mode 100644 index 000000000..d031d1f0a --- /dev/null +++ b/data/slash/proof.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. proof.proto +package slash diff --git a/data/slash/proof.proto b/data/slash/proof.proto new file mode 100644 index 000000000..86688a46a --- /dev/null +++ b/data/slash/proof.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package proto; + +option go_package = "slash"; +option (gogoproto.stable_marshaler_all) = true; + +import "slash.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message Proof { + SlashingType Type = 1; +} From 64178e26af5d8532f01752e9baeee0e75a9a3c7f Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 15:48:34 +0200 Subject: [PATCH 10/54] FEAT: Add generated proof struct --- data/slash/proof.pb.go | 361 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 data/slash/proof.pb.go diff --git a/data/slash/proof.pb.go b/data/slash/proof.pb.go new file mode 100644 index 000000000..15ba202ff --- /dev/null +++ b/data/slash/proof.pb.go @@ -0,0 +1,361 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: proof.proto + +package slash + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Proof struct { + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` +} + +func (m *Proof) Reset() { *m = Proof{} } +func (*Proof) ProtoMessage() {} +func (*Proof) Descriptor() ([]byte, []int) { + return fileDescriptor_473d204b28f447f0, []int{0} +} +func (m *Proof) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Proof) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Proof) XXX_Merge(src proto.Message) { + xxx_messageInfo_Proof.Merge(m, src) +} +func (m *Proof) XXX_Size() int { + return m.Size() +} +func (m *Proof) XXX_DiscardUnknown() { + xxx_messageInfo_Proof.DiscardUnknown(m) +} + +var xxx_messageInfo_Proof proto.InternalMessageInfo + +func (m *Proof) GetType() SlashingType { + if m != nil { + return m.Type + } + return None +} + +func init() { + proto.RegisterType((*Proof)(nil), "proto.Proof") +} + +func init() { proto.RegisterFile("proof.proto", fileDescriptor_473d204b28f447f0) } + +var fileDescriptor_473d204b28f447f0 = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x28, 0xca, 0xcf, + 0x4f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xdc, 0xc5, 0x39, 0x89, + 0xc5, 0x19, 0x10, 0x31, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, + 0xfd, 0xf4, 0xfc, 0xf4, 0x7c, 0x7d, 0xb0, 0x70, 0x52, 0x69, 0x1a, 0x98, 0x07, 0xe6, 0x80, 0x59, + 0x10, 0xe5, 0x4a, 0x06, 0x5c, 0xac, 0x01, 0x20, 0x13, 0x85, 0xd4, 0xb9, 0x58, 0x42, 0x2a, 0x0b, + 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x84, 0x21, 0xd2, 0x7a, 0xc1, 0x20, 0x93, 0x33, + 0xf3, 0xd2, 0x41, 0x52, 0x41, 0x60, 0x05, 0x4e, 0xf6, 0x17, 0x1e, 0xca, 0x31, 0xdc, 0x78, 0x28, + 0xc7, 0xf0, 0xe1, 0xa1, 0x1c, 0x63, 0xc3, 0x23, 0x39, 0xc6, 0x15, 0x8f, 0xe4, 0x18, 0x4f, 0x3c, + 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc6, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x5f, + 0x3c, 0x92, 0x63, 0xf8, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, + 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x62, 0x05, 0xbb, 0x33, 0x89, 0x0d, 0x6c, 0xb4, 0x31, 0x20, 0x00, + 0x00, 0xff, 0xff, 0x54, 0x2c, 0xfb, 0x46, 0xcb, 0x00, 0x00, 0x00, +} + +func (this *Proof) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Proof) + if !ok { + that2, ok := that.(Proof) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Type != that1.Type { + return false + } + return true +} +func (this *Proof) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&slash.Proof{") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringProof(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *Proof) 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 *Proof) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Proof) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Type != 0 { + i = encodeVarintProof(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintProof(dAtA []byte, offset int, v uint64) int { + offset -= sovProof(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Proof) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovProof(uint64(m.Type)) + } + return n +} + +func sovProof(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozProof(x uint64) (n int) { + return sovProof(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Proof) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Proof{`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `}`, + }, "") + return s +} +func valueToStringProof(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Proof) 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 ErrIntOverflowProof + } + 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: Proof: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Proof: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= SlashingType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProof + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProof + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipProof(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowProof + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthProof + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupProof + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthProof + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthProof = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowProof = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupProof = fmt.Errorf("proto: unexpected end of group") +) From 710e89020f7b21b51e94f99437f6f58d431909eb Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 16:26:43 +0200 Subject: [PATCH 11/54] FEAT: Add header info proto struct --- data/block/headerInfo.go | 12 + data/block/headerInfo.pb.go | 448 ++++++++++++++++++++++++++++++++++++ data/block/headerInfo.proto | 14 ++ data/interface.go | 15 +- 4 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 data/block/headerInfo.go create mode 100644 data/block/headerInfo.pb.go create mode 100644 data/block/headerInfo.proto diff --git a/data/block/headerInfo.go b/data/block/headerInfo.go new file mode 100644 index 000000000..8b815a74b --- /dev/null +++ b/data/block/headerInfo.go @@ -0,0 +1,12 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. headerInfo.proto +package block + +import "github.com/ElrondNetwork/elrond-go-core/data" + +func (m *HeaderInfo) GetHeaderHandler() data.HeaderHandler { + if m == nil { + return nil + } + + return m.Header +} diff --git a/data/block/headerInfo.pb.go b/data/block/headerInfo.pb.go new file mode 100644 index 000000000..564c118f7 --- /dev/null +++ b/data/block/headerInfo.pb.go @@ -0,0 +1,448 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: headerInfo.proto + +package block + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type HeaderInfo struct { + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + Hash []byte `protobuf:"bytes,2,opt,name=Hash,proto3" json:"Hash,omitempty"` +} + +func (m *HeaderInfo) Reset() { *m = HeaderInfo{} } +func (*HeaderInfo) ProtoMessage() {} +func (*HeaderInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_f4bbbba9a375b11e, []int{0} +} +func (m *HeaderInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeaderInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *HeaderInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderInfo.Merge(m, src) +} +func (m *HeaderInfo) XXX_Size() int { + return m.Size() +} +func (m *HeaderInfo) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_HeaderInfo proto.InternalMessageInfo + +func (m *HeaderInfo) GetHeader() *HeaderV2 { + if m != nil { + return m.Header + } + return nil +} + +func (m *HeaderInfo) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func init() { + proto.RegisterType((*HeaderInfo)(nil), "proto.HeaderInfo") +} + +func init() { proto.RegisterFile("headerInfo.proto", fileDescriptor_f4bbbba9a375b11e) } + +var fileDescriptor_f4bbbba9a375b11e = []byte{ + // 205 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x48, 0x4d, 0x4c, + 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b, 0x05, 0xc9, 0xeb, 0x00, 0x00, 0x00, +} + +func (this *HeaderInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HeaderInfo) + if !ok { + that2, ok := that.(HeaderInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Header.Equal(that1.Header) { + return false + } + if !bytes.Equal(this.Hash, that1.Hash) { + return false + } + return true +} +func (this *HeaderInfo) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&block.HeaderInfo{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + s = append(s, "Hash: "+fmt.Sprintf("%#v", this.Hash)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringHeaderInfo(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *HeaderInfo) 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 *HeaderInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeaderInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintHeaderInfo(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0x12 + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintHeaderInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintHeaderInfo(dAtA []byte, offset int, v uint64) int { + offset -= sovHeaderInfo(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HeaderInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovHeaderInfo(uint64(l)) + } + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovHeaderInfo(uint64(l)) + } + return n +} + +func sovHeaderInfo(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozHeaderInfo(x uint64) (n int) { + return sovHeaderInfo(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *HeaderInfo) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&HeaderInfo{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, + `Hash:` + fmt.Sprintf("%v", this.Hash) + `,`, + `}`, + }, "") + return s +} +func valueToStringHeaderInfo(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *HeaderInfo) 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 ErrIntOverflowHeaderInfo + } + 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: HeaderInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeaderInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthHeaderInfo + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthHeaderInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &HeaderV2{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHeaderInfo + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHeaderInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHeaderInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthHeaderInfo + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthHeaderInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipHeaderInfo(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthHeaderInfo + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupHeaderInfo + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthHeaderInfo + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthHeaderInfo = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowHeaderInfo = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupHeaderInfo = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/block/headerInfo.proto b/data/block/headerInfo.proto new file mode 100644 index 000000000..2bf40d8cb --- /dev/null +++ b/data/block/headerInfo.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package proto; + +option go_package = "block"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "blockV2.proto"; + +message HeaderInfo { + HeaderV2 Header = 1; + bytes Hash = 2; +} \ No newline at end of file diff --git a/data/interface.go b/data/interface.go index d7eb22c9e..fa7c9846b 100644 --- a/data/interface.go +++ b/data/interface.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" + "github.com/ElrondNetwork/elrond-go-core/data/slash" ) // TriggerRegistryHandler defines getters and setters for the trigger registry @@ -84,6 +85,12 @@ type HeaderHandler interface { IsInterfaceNil() bool } +// HeaderInfoHandler defines a HeaderHandler and its coressponding hash +type HeaderInfoHandler interface { + GetHeaderHandler() HeaderHandler + GetHash() []byte +} + // ShardHeaderHandler defines getters and setters for the shard block header type ShardHeaderHandler interface { HeaderHandler @@ -193,7 +200,7 @@ type EpochStartShardDataHandler interface { SetPendingMiniBlockHeaders([]MiniBlockHeaderHandler) error } -// EconomicHandler defines setters and getters for Economics +// EconomicsHandler defines setters and getters for Economics type EconomicsHandler interface { GetTotalSupply() *big.Int GetTotalToDistribute() *big.Int @@ -361,3 +368,9 @@ type UserAccountHandler interface { AddressBytes() []byte IsInterfaceNil() bool } + +// SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction +type SlashingProofHandler interface { + //GetType - contains the type of slashing detection + GetType() slash.SlashingType +} From 8dd1f3ede44d8010e49f488e40a3d97bf7f7ce25 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 17:05:39 +0200 Subject: [PATCH 12/54] FEAT: Add multiple sign and propose proof interfaces --- data/interface.go | 23 ++- data/slash/multipleHeaderProposalProof.go | 15 ++ data/slash/multipleHeaderProposalProof.pb.go | 47 +++--- data/slash/multipleHeaderProposalProof.proto | 6 +- data/slash/multipleHeaderSigningProof.go | 35 +++++ data/slash/multipleHeaderSigningProof.pb.go | 143 ++++++++++--------- data/slash/multipleHeaderSigningProof.proto | 8 +- data/slash/slash.go | 22 --- data/slash/slash.pb.go | 107 +++++++------- data/slash/slash.proto | 14 +- data/slash/slash_test.go | 40 ------ 11 files changed, 236 insertions(+), 224 deletions(-) diff --git a/data/interface.go b/data/interface.go index fa7c9846b..66ef3ed28 100644 --- a/data/interface.go +++ b/data/interface.go @@ -85,7 +85,7 @@ type HeaderHandler interface { IsInterfaceNil() bool } -// HeaderInfoHandler defines a HeaderHandler and its coressponding hash +// HeaderInfoHandler defines a HeaderHandler and its corresponding hash type HeaderInfoHandler interface { GetHeaderHandler() HeaderHandler GetHash() []byte @@ -374,3 +374,24 @@ type SlashingProofHandler interface { //GetType - contains the type of slashing detection GetType() slash.SlashingType } + +// MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event +type MultipleProposalProofHandler interface { + SlashingProofHandler + // GetLevel - contains the slashing level for the current slashing type + // multiple colluding parties should have a higher level + GetLevel() slash.ThreatLevel + //GetHeaders - returns the slashable proposed headers + GetHeaders() []HeaderInfoHandler +} + +// MultipleSigningProofHandler contains proof data for a multiple header signing slashing event +type MultipleSigningProofHandler interface { + SlashingProofHandler + // GetPubKeys - returns all validator's public keys which have signed multiple headers + GetPubKeys() [][]byte + // GetLevel - returns the slashing level for a given validator + GetLevel(pubKey []byte) slash.ThreatLevel + // GetHeaders - returns the slashable signed headers proposed by a given validator + GetHeaders(pubKey []byte) []HeaderInfoHandler +} diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index ee5363bfe..6f76dd8ef 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -1,2 +1,17 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. multipleHeaderProposalProof.proto package slash + +import "github.com/ElrondNetwork/elrond-go-core/data" + +func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { + if m == nil { + return nil + } + ret := make([]data.HeaderInfoHandler, len(m.HeadersInfo.Headers)) + + for _, headerInfo := range m.HeadersInfo.GetHeaders() { + ret = append(ret, headerInfo) + } + + return ret +} diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index e63d317ef..d8bfb46b6 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -26,9 +26,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - Headers Headers `protobuf:"bytes,3,opt,name=Headers,proto3" json:"Headers"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + HeadersInfo HeaderInfoList `protobuf:"bytes,3,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -73,11 +73,11 @@ func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { return Low } -func (m *MultipleHeaderProposalProof) GetHeaders() Headers { +func (m *MultipleHeaderProposalProof) GetHeadersInfo() HeaderInfoList { if m != nil { - return m.Headers + return m.HeadersInfo } - return Headers{} + return HeaderInfoList{} } func init() { @@ -87,24 +87,25 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 266 bytes of a gzipped FileDescriptorProto + // 276 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x2d, 0xcd, 0x29, 0xc9, 0x2c, 0xc8, 0x49, 0xf5, 0x48, 0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0x18, - 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, - 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, 0x47, - 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, - 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, 0x80, 0x49, 0x62, 0x03, 0x1b, 0x6f, 0x0c, 0x08, 0x00, 0x00, - 0xff, 0xff, 0xf5, 0xf7, 0x23, 0xf5, 0x52, 0x01, 0x00, 0x00, + 0x51, 0x94, 0x9a, 0x58, 0x02, 0x96, 0x09, 0x82, 0x28, 0x10, 0xb2, 0xe5, 0xe2, 0x86, 0xd8, 0x54, + 0xec, 0x99, 0x97, 0x96, 0x2f, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0x0a, 0x55, 0x0f, 0x91, + 0x01, 0x49, 0xf8, 0x64, 0x16, 0x97, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x84, 0xac, 0xde, + 0xc9, 0xfe, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, 0x18, 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, + 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, + 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, 0x47, 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, + 0x70, 0x4a, 0x62, 0x03, 0xdb, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x3e, 0xe3, 0x93, 0xda, + 0x61, 0x01, 0x00, 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -132,7 +133,7 @@ func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { if this.Level != that1.Level { return false } - if !this.Headers.Equal(&that1.Headers) { + if !this.HeadersInfo.Equal(&that1.HeadersInfo) { return false } return true @@ -145,7 +146,7 @@ func (this *MultipleHeaderProposalProof) GoString() string { s = append(s, "&slash.MultipleHeaderProposalProof{") s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") - s = append(s, "Headers: "+strings.Replace(this.Headers.GoString(), `&`, ``, 1)+",\n") + s = append(s, "HeadersInfo: "+strings.Replace(this.HeadersInfo.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -178,7 +179,7 @@ func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, er var l int _ = l { - size, err := m.Headers.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.HeadersInfo.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -223,7 +224,7 @@ func (m *MultipleHeaderProposalProof) Size() (n int) { if m.Level != 0 { n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) } - l = m.Headers.Size() + l = m.HeadersInfo.Size() n += 1 + l + sovMultipleHeaderProposalProof(uint64(l)) return n } @@ -241,7 +242,7 @@ func (this *MultipleHeaderProposalProof) String() string { s := strings.Join([]string{`&MultipleHeaderProposalProof{`, `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, - `Headers:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Headers), "Headers", "Headers", 1), `&`, ``, 1) + `,`, + `HeadersInfo:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersInfo), "HeaderInfoList", "HeaderInfoList", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -323,7 +324,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { } case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -350,7 +351,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Headers.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.HeadersInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 27c6d4b08..a72f9dfac 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -9,7 +9,7 @@ import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderProposalProof { - SlashingType Type = 1; - ThreatLevel Level = 2; - Headers Headers = 3 [(gogoproto.nullable) = false]; + SlashingType Type = 1; + ThreatLevel Level = 2; + HeaderInfoList HeadersInfo = 3 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 00dfa8659..1af011475 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -1,2 +1,37 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. multipleHeaderSigningProof.proto package slash + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" +) + +func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { + if m == nil { + return Low + } + + level, exists := m.Levels[string(pubKey)] + if !exists { + return Low + } + + return level +} + +func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderInfoHandler { + if m == nil { + return nil + } + + headersInfo, exist := m.HeadersInfo[string(pubKey)] + if !exist { + return nil + } + + ret := make([]data.HeaderInfoHandler, len(headersInfo.Headers)) + for _, headerInfo := range headersInfo.GetHeaders() { + ret = append(ret, headerInfo) + } + + return ret +} diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index c766851b4..367123d5e 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -28,10 +28,10 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - Headers map[string]Headers `protobuf:"bytes,4,rep,name=Headers,proto3" json:"Headers" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + HeadersInfo map[string]HeaderInfoList `protobuf:"bytes,4,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -83,46 +83,47 @@ func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { return nil } -func (m *MultipleHeaderSigningProof) GetHeaders() map[string]Headers { +func (m *MultipleHeaderSigningProof) GetHeadersInfo() map[string]HeaderInfoList { if m != nil { - return m.Headers + return m.HeadersInfo } return nil } func init() { proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") - proto.RegisterMapType((map[string]Headers)(nil), "proto.MultipleHeaderSigningProof.HeadersEntry") + proto.RegisterMapType((map[string]HeaderInfoList)(nil), "proto.MultipleHeaderSigningProof.HeadersInfoEntry") proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") } func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 361 bytes of a gzipped FileDescriptorProto + // 370 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x6a, 0xea, 0x40, - 0x14, 0xc6, 0x67, 0x8c, 0x7f, 0xb8, 0x13, 0x91, 0xcb, 0xdc, 0x4d, 0xc8, 0xe2, 0xdc, 0x50, 0x0a, - 0xcd, 0xc6, 0x08, 0x76, 0x53, 0xba, 0x29, 0x08, 0x42, 0x69, 0x6b, 0x91, 0xe8, 0xaa, 0xbb, 0xa4, - 0x1d, 0x63, 0x68, 0xcc, 0x48, 0xfe, 0x08, 0xd9, 0xf5, 0x11, 0xda, 0xb7, 0xe8, 0xa3, 0xb8, 0x74, - 0xe9, 0xaa, 0xd4, 0x71, 0xd3, 0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xef, 0xfc, 0x63, 0xef, 0x47, - 0x6a, 0x92, 0xda, 0xc2, 0x09, 0x52, 0xa6, 0x55, 0xe4, 0xed, 0xb4, 0xa8, 0x1b, 0x4f, 0x23, 0xe6, - 0x24, 0x32, 0x6a, 0xe7, 0x86, 0xcb, 0xca, 0x05, 0xd6, 0x6f, 0x48, 0xb3, 0xdc, 0xf6, 0x03, 0xef, - 0xb4, 0xcc, 0x53, 0xbb, 0xad, 0x82, 0x57, 0xa4, 0x4a, 0xac, 0xde, 0xd5, 0x6a, 0x03, 0x68, 0xbd, - 0x01, 0xb4, 0xdb, 0x00, 0x7e, 0x11, 0x80, 0xdf, 0x05, 0xe0, 0xa5, 0x00, 0xbc, 0x12, 0x80, 0xd7, - 0x02, 0xf0, 0xa7, 0x00, 0xfc, 0x25, 0x00, 0xed, 0x04, 0xe0, 0xd7, 0x2d, 0xa0, 0xd5, 0x16, 0xd0, - 0x7a, 0x0b, 0xe8, 0xa1, 0x26, 0x5f, 0x82, 0x5b, 0x97, 0xe8, 0xf3, 0xef, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x22, 0x19, 0x77, 0x9e, 0x42, 0x02, 0x00, 0x00, + 0x14, 0xc6, 0x33, 0x46, 0xbd, 0xdc, 0xc9, 0xe5, 0x22, 0x73, 0xb9, 0x10, 0xb2, 0x38, 0x0d, 0xdd, + 0x34, 0x50, 0x8c, 0x90, 0x6e, 0x4a, 0x37, 0x05, 0x41, 0x68, 0xa9, 0x82, 0x44, 0xbb, 0x71, 0x97, + 0xb4, 0x63, 0x0c, 0x8d, 0x19, 0xc9, 0x1f, 0x21, 0xbb, 0x3e, 0x42, 0x1f, 0xc3, 0x47, 0x71, 0xe9, + 0xd2, 0x55, 0xa9, 0xe3, 0xa6, 0x4b, 0x1f, 0xa1, 0x64, 0x92, 0x42, 0x28, 0x95, 0xae, 0x32, 0xe7, + 0xe4, 0xfb, 0x7e, 0x3f, 0x12, 0x06, 0xeb, 0xf3, 0x34, 0x48, 0xf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e3, 0x59, 0x44, 0x9d, 0x44, 0x54, 0xed, 0x22, 0x70, 0x55, 0xbb, 0x44, 0xda, 0x3d, 0x6e, 0x7d, + 0xb5, 0x7e, 0xc3, 0x3c, 0xaf, 0x32, 0x15, 0xeb, 0x7f, 0xc9, 0x2c, 0x9a, 0x79, 0xb1, 0xef, 0xc7, + 0x49, 0x05, 0xdb, 0xbd, 0xde, 0xec, 0x40, 0xda, 0xee, 0x40, 0x3a, 0xec, 0x00, 0x3d, 0x73, 0x40, + 0x2b, 0x0e, 0x68, 0xcd, 0x01, 0x6d, 0x38, 0xa0, 0x2d, 0x07, 0xf4, 0xc6, 0x01, 0xbd, 0x73, 0x90, + 0x0e, 0x1c, 0xd0, 0xcb, 0x1e, 0xa4, 0xcd, 0x1e, 0xa4, 0xed, 0x1e, 0xa4, 0x49, 0x43, 0x5c, 0x10, + 0xb7, 0x29, 0x0c, 0x17, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x6b, 0x98, 0x2d, 0x59, 0x02, + 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -163,12 +164,12 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { return false } } - if len(this.Headers) != len(that1.Headers) { + if len(this.HeadersInfo) != len(that1.HeadersInfo) { return false } - for i := range this.Headers { - a := this.Headers[i] - b := that1.Headers[i] + for i := range this.HeadersInfo { + a := this.HeadersInfo[i] + b := that1.HeadersInfo[i] if !(&a).Equal(&b) { return false } @@ -196,18 +197,18 @@ func (this *MultipleHeaderSigningProof) GoString() string { if this.Levels != nil { s = append(s, "Levels: "+mapStringForLevels+",\n") } - keysForHeaders := make([]string, 0, len(this.Headers)) - for k, _ := range this.Headers { - keysForHeaders = append(keysForHeaders, k) + keysForHeadersInfo := make([]string, 0, len(this.HeadersInfo)) + for k, _ := range this.HeadersInfo { + keysForHeadersInfo = append(keysForHeadersInfo, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) - mapStringForHeaders := "map[string]Headers{" - for _, k := range keysForHeaders { - mapStringForHeaders += fmt.Sprintf("%#v: %#v,", k, this.Headers[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) + mapStringForHeadersInfo := "map[string]HeaderInfoList{" + for _, k := range keysForHeadersInfo { + mapStringForHeadersInfo += fmt.Sprintf("%#v: %#v,", k, this.HeadersInfo[k]) } - mapStringForHeaders += "}" - if this.Headers != nil { - s = append(s, "Headers: "+mapStringForHeaders+",\n") + mapStringForHeadersInfo += "}" + if this.HeadersInfo != nil { + s = append(s, "HeadersInfo: "+mapStringForHeadersInfo+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -240,14 +241,14 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l - if len(m.Headers) > 0 { - keysForHeaders := make([]string, 0, len(m.Headers)) - for k := range m.Headers { - keysForHeaders = append(keysForHeaders, string(k)) + if len(m.HeadersInfo) > 0 { + keysForHeadersInfo := make([]string, 0, len(m.HeadersInfo)) + for k := range m.HeadersInfo { + keysForHeadersInfo = append(keysForHeadersInfo, string(k)) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) - for iNdEx := len(keysForHeaders) - 1; iNdEx >= 0; iNdEx-- { - v := m.Headers[string(keysForHeaders[iNdEx])] + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) + for iNdEx := len(keysForHeadersInfo) - 1; iNdEx >= 0; iNdEx-- { + v := m.HeadersInfo[string(keysForHeadersInfo[iNdEx])] baseI := i { size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) @@ -259,9 +260,9 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err } i-- dAtA[i] = 0x12 - i -= len(keysForHeaders[iNdEx]) - copy(dAtA[i:], keysForHeaders[iNdEx]) - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeaders[iNdEx]))) + i -= len(keysForHeadersInfo[iNdEx]) + copy(dAtA[i:], keysForHeadersInfo[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeadersInfo[iNdEx]))) i-- dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) @@ -342,8 +343,8 @@ func (m *MultipleHeaderSigningProof) Size() (n int) { n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) } } - if len(m.Headers) > 0 { - for k, v := range m.Headers { + if len(m.HeadersInfo) > 0 { + for k, v := range m.HeadersInfo { _ = k _ = v l = v.Size() @@ -374,21 +375,21 @@ func (this *MultipleHeaderSigningProof) String() string { mapStringForLevels += fmt.Sprintf("%v: %v,", k, this.Levels[k]) } mapStringForLevels += "}" - keysForHeaders := make([]string, 0, len(this.Headers)) - for k, _ := range this.Headers { - keysForHeaders = append(keysForHeaders, k) + keysForHeadersInfo := make([]string, 0, len(this.HeadersInfo)) + for k, _ := range this.HeadersInfo { + keysForHeadersInfo = append(keysForHeadersInfo, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeaders) - mapStringForHeaders := "map[string]Headers{" - for _, k := range keysForHeaders { - mapStringForHeaders += fmt.Sprintf("%v: %v,", k, this.Headers[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) + mapStringForHeadersInfo := "map[string]HeaderInfoList{" + for _, k := range keysForHeadersInfo { + mapStringForHeadersInfo += fmt.Sprintf("%v: %v,", k, this.HeadersInfo[k]) } - mapStringForHeaders += "}" + mapStringForHeadersInfo += "}" s := strings.Join([]string{`&MultipleHeaderSigningProof{`, `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, `Levels:` + mapStringForLevels + `,`, - `Headers:` + mapStringForHeaders + `,`, + `HeadersInfo:` + mapStringForHeadersInfo + `,`, `}`, }, "") return s @@ -596,7 +597,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -623,11 +624,11 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Headers == nil { - m.Headers = make(map[string]Headers) + if m.HeadersInfo == nil { + m.HeadersInfo = make(map[string]HeaderInfoList) } var mapkey string - mapvalue := &Headers{} + mapvalue := &HeaderInfoList{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -701,7 +702,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postmsgIndex > l { return io.ErrUnexpectedEOF } - mapvalue = &Headers{} + mapvalue = &HeaderInfoList{} if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { return err } @@ -721,7 +722,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.Headers[mapkey] = *mapvalue + m.HeadersInfo[mapkey] = *mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index be73c45bb..2ab9283f5 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -9,8 +9,8 @@ import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message MultipleHeaderSigningProof { - SlashingType Type = 1; - repeated bytes PubKeys = 2; - map Levels = 3; - map Headers = 4 [(gogoproto.nullable) = false]; + SlashingType Type = 1; + repeated bytes PubKeys = 2; + map Levels = 3; + map HeadersInfo = 4 [(gogoproto.nullable) = false]; } diff --git a/data/slash/slash.go b/data/slash/slash.go index 5b43e02b1..8d3b8f339 100644 --- a/data/slash/slash.go +++ b/data/slash/slash.go @@ -1,24 +1,2 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. slash.proto package slash - -import ( - "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/block" -) - -func (m *Headers) SetHeaders(headers []data.HeaderHandler) error { - if m == nil { - return data.ErrNilPointerReceiver - } - - for _, header := range headers { - hdr, castOk := header.(*block.HeaderV2) - if !castOk { - return data.ErrInvalidTypeAssertion - } - - m.Headers = append(m.Headers, hdr) - } - - return nil -} diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go index cddf90aed..8ab6c3e95 100644 --- a/data/slash/slash.pb.go +++ b/data/slash/slash.pb.go @@ -75,19 +75,19 @@ func (ThreatLevel) EnumDescriptor() ([]byte, []int) { return fileDescriptor_7c4604f407d65f7b, []int{1} } -type Headers struct { - Headers []*block.HeaderV2 `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` +type HeaderInfoList struct { + Headers []*block.HeaderInfo `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` } -func (m *Headers) Reset() { *m = Headers{} } -func (*Headers) ProtoMessage() {} -func (*Headers) Descriptor() ([]byte, []int) { +func (m *HeaderInfoList) Reset() { *m = HeaderInfoList{} } +func (*HeaderInfoList) ProtoMessage() {} +func (*HeaderInfoList) Descriptor() ([]byte, []int) { return fileDescriptor_7c4604f407d65f7b, []int{0} } -func (m *Headers) XXX_Unmarshal(b []byte) error { +func (m *HeaderInfoList) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *Headers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *HeaderInfoList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) if err != nil { @@ -95,19 +95,19 @@ func (m *Headers) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { } return b[:n], nil } -func (m *Headers) XXX_Merge(src proto.Message) { - xxx_messageInfo_Headers.Merge(m, src) +func (m *HeaderInfoList) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderInfoList.Merge(m, src) } -func (m *Headers) XXX_Size() int { +func (m *HeaderInfoList) XXX_Size() int { return m.Size() } -func (m *Headers) XXX_DiscardUnknown() { - xxx_messageInfo_Headers.DiscardUnknown(m) +func (m *HeaderInfoList) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderInfoList.DiscardUnknown(m) } -var xxx_messageInfo_Headers proto.InternalMessageInfo +var xxx_messageInfo_HeaderInfoList proto.InternalMessageInfo -func (m *Headers) GetHeaders() []*block.HeaderV2 { +func (m *HeaderInfoList) GetHeaders() []*block.HeaderInfo { if m != nil { return m.Headers } @@ -117,33 +117,34 @@ func (m *Headers) GetHeaders() []*block.HeaderV2 { func init() { proto.RegisterEnum("proto.SlashingType", SlashingType_name, SlashingType_value) proto.RegisterEnum("proto.ThreatLevel", ThreatLevel_name, ThreatLevel_value) - proto.RegisterType((*Headers)(nil), "proto.Headers") + proto.RegisterType((*HeaderInfoList)(nil), "proto.HeaderInfoList") } func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } var fileDescriptor_7c4604f407d65f7b = []byte{ - // 319 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x50, 0x31, 0x4f, 0x32, 0x41, - 0x10, 0xdd, 0x85, 0x0f, 0xf8, 0xb2, 0x98, 0x70, 0x39, 0x2d, 0x0c, 0xc5, 0xc4, 0x58, 0x29, 0x11, - 0x2e, 0x41, 0x7b, 0x8d, 0xc6, 0x84, 0x02, 0x88, 0x11, 0x42, 0x61, 0x77, 0xc7, 0xad, 0x7b, 0x1b, - 0x96, 0x9b, 0xcb, 0xde, 0x9d, 0xc4, 0xce, 0x9f, 0xe0, 0xcf, 0xf0, 0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e, - 0x71, 0x19, 0xab, 0x0e, 0x78, 0x28, 0xf3, 0xb9, 0x43, 0x77, 0xc1, 0x3d, 0x29, 0x22, 0xa7, 0x74, - 0x7b, 0xbd, 0x5c, 0x03, 0x59, 0xad, 0x81, 0x6c, 0xd7, 0x40, 0xdf, 0x0c, 0xd0, 0x0f, 0x03, 0xf4, - 0xd3, 0x00, 0x5d, 0x1a, 0xa0, 0x2b, 0x03, 0xf4, 0xcb, 0x00, 0xfd, 0x36, 0x40, 0xb6, 0x06, 0xe8, - 0xfb, 0x06, 0xc8, 0x72, 0x03, 0x64, 0xb5, 0x01, 0xf2, 0x54, 0xb1, 0x77, 0x0e, 0xaa, 0x76, 0x99, - 0xcb, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xa6, 0xba, 0x2c, 0x77, 0x01, 0x00, 0x00, + // 324 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x31, 0x4f, 0x32, 0x31, + 0x1c, 0xc6, 0x5b, 0x78, 0x81, 0x37, 0xc5, 0xe8, 0x79, 0x3a, 0x18, 0x86, 0x7f, 0x8c, 0x93, 0x41, + 0xe1, 0x12, 0x9d, 0x8d, 0x89, 0xc4, 0x04, 0x13, 0x20, 0x46, 0x98, 0xdc, 0xee, 0xb8, 0xd2, 0x6b, + 0x38, 0xee, 0x7f, 0xe9, 0xf5, 0x24, 0x6e, 0x7e, 0x04, 0x3f, 0x86, 0x1f, 0xc5, 0x91, 0x91, 0x51, + 0xca, 0xe2, 0xc8, 0x47, 0x30, 0x14, 0x51, 0xa7, 0xf6, 0xf9, 0xe5, 0xd7, 0x27, 0x79, 0xca, 0xaa, + 0x59, 0xec, 0x67, 0x51, 0x33, 0x55, 0xa8, 0xd1, 0x2d, 0xd9, 0xa3, 0xd6, 0x10, 0x52, 0x47, 0x79, + 0xd0, 0x1c, 0xe2, 0xc4, 0x13, 0x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xb9, 0x01, 0xfa, 0x61, 0x80, 0x7e, + 0x1a, 0x20, 0x2b, 0x03, 0xf4, 0x75, 0x09, 0x64, 0xb6, 0x04, 0x32, 0x5f, 0x02, 0x79, 0x2c, 0xd9, + 0x3f, 0x0f, 0xca, 0x76, 0xce, 0xe5, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x96, 0x29, 0xb0, 0xed, + 0x83, 0x01, 0x00, 0x00, } func (x SlashingType) String() string { @@ -160,14 +161,14 @@ func (x ThreatLevel) String() string { } return strconv.Itoa(int(x)) } -func (this *Headers) Equal(that interface{}) bool { +func (this *HeaderInfoList) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*Headers) + that1, ok := that.(*HeaderInfoList) if !ok { - that2, ok := that.(Headers) + that2, ok := that.(HeaderInfoList) if ok { that1 = &that2 } else { @@ -189,12 +190,12 @@ func (this *Headers) Equal(that interface{}) bool { } return true } -func (this *Headers) GoString() string { +func (this *HeaderInfoList) GoString() string { if this == nil { return "nil" } s := make([]string, 0, 5) - s = append(s, "&slash.Headers{") + s = append(s, "&slash.HeaderInfoList{") if this.Headers != nil { s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") } @@ -209,7 +210,7 @@ func valueToGoStringSlash(v interface{}, typ string) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) } -func (m *Headers) Marshal() (dAtA []byte, err error) { +func (m *HeaderInfoList) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -219,12 +220,12 @@ func (m *Headers) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *Headers) MarshalTo(dAtA []byte) (int, error) { +func (m *HeaderInfoList) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *Headers) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *HeaderInfoList) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -257,7 +258,7 @@ func encodeVarintSlash(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *Headers) Size() (n int) { +func (m *HeaderInfoList) Size() (n int) { if m == nil { return 0 } @@ -278,16 +279,16 @@ func sovSlash(x uint64) (n int) { func sozSlash(x uint64) (n int) { return sovSlash(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *Headers) String() string { +func (this *HeaderInfoList) String() string { if this == nil { return "nil" } - repeatedStringForHeaders := "[]*HeaderV2{" + repeatedStringForHeaders := "[]*HeaderInfo{" for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(fmt.Sprintf("%v", f), "HeaderV2", "block.HeaderV2", 1) + "," + repeatedStringForHeaders += strings.Replace(fmt.Sprintf("%v", f), "HeaderInfo", "block.HeaderInfo", 1) + "," } repeatedStringForHeaders += "}" - s := strings.Join([]string{`&Headers{`, + s := strings.Join([]string{`&HeaderInfoList{`, `Headers:` + repeatedStringForHeaders + `,`, `}`, }, "") @@ -301,7 +302,7 @@ func valueToStringSlash(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } -func (m *Headers) Unmarshal(dAtA []byte) error { +func (m *HeaderInfoList) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -324,10 +325,10 @@ func (m *Headers) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Headers: wiretype end group for non-group") + return fmt.Errorf("proto: HeaderInfoList: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Headers: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: HeaderInfoList: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -359,7 +360,7 @@ func (m *Headers) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Headers = append(m.Headers, &block.HeaderV2{}) + m.Headers = append(m.Headers, &block.HeaderInfo{}) if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/data/slash/slash.proto b/data/slash/slash.proto index 04c472494..358350c78 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -6,20 +6,20 @@ option go_package = "slash"; option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/ElrondNetwork/elrond-go-core/data/block/blockV2.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; enum SlashingType { - None = 0; + None = 0; MultipleProposal = 1; - MultipleSigning = 2; + MultipleSigning = 2; } enum ThreatLevel { - Low = 0; + Low = 0; Medium = 1; - High = 2; + High = 2; } -message Headers{ - repeated HeaderV2 Headers = 1; +message HeaderInfoList{ + repeated HeaderInfo Headers = 1; } diff --git a/data/slash/slash_test.go b/data/slash/slash_test.go index db3c4062f..01750522d 100644 --- a/data/slash/slash_test.go +++ b/data/slash/slash_test.go @@ -1,41 +1 @@ package slash_test - -import ( - "testing" - - "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/block" - "github.com/ElrondNetwork/elrond-go-core/data/slash" - "github.com/stretchr/testify/require" -) - -func TestHeaders_SetHeaders_InvalidHeaders_ExpectError(t *testing.T) { - header := &block.Header{TimeStamp: 1} - headers := slash.Headers{} - - err := headers.SetHeaders([]data.HeaderHandler{header}) - require.Equal(t, data.ErrInvalidTypeAssertion, err) -} - -func TestHeaders_SetHeaders(t *testing.T) { - header1 := &block.HeaderV2{ - Header: &block.Header{ - TimeStamp: 1, - }, - } - header2 := &block.HeaderV2{ - Header: &block.Header{ - TimeStamp: 2, - }, - } - - in := []data.HeaderHandler{header1, header2} - headers := slash.Headers{} - - err := headers.SetHeaders(in) - require.Nil(t, err) - - require.Len(t, headers.GetHeaders(), 2) - require.Contains(t, headers.GetHeaders(), header1) - require.Contains(t, headers.GetHeaders(), header2) -} From 2efc821704158885c4b4185d8916a6944c408925 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 17:31:44 +0200 Subject: [PATCH 13/54] FIX: Move proof interfaces in types package --- data/interface.go | 28 -- data/slash/multipleHeaderProposalProof.pb.go | 53 +-- data/slash/multipleHeaderProposalProof.proto | 1 + data/slash/multipleHeaderSigningProof.pb.go | 75 ++-- data/slash/multipleHeaderSigningProof.proto | 1 + data/slash/slash.pb.go | 396 +------------------ data/slash/slash.proto | 4 - data/slash/types/interface.go | 33 ++ 8 files changed, 119 insertions(+), 472 deletions(-) create mode 100644 data/slash/types/interface.go diff --git a/data/interface.go b/data/interface.go index 66ef3ed28..848bf6968 100644 --- a/data/interface.go +++ b/data/interface.go @@ -4,7 +4,6 @@ import ( "math/big" "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" - "github.com/ElrondNetwork/elrond-go-core/data/slash" ) // TriggerRegistryHandler defines getters and setters for the trigger registry @@ -368,30 +367,3 @@ type UserAccountHandler interface { AddressBytes() []byte IsInterfaceNil() bool } - -// SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction -type SlashingProofHandler interface { - //GetType - contains the type of slashing detection - GetType() slash.SlashingType -} - -// MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event -type MultipleProposalProofHandler interface { - SlashingProofHandler - // GetLevel - contains the slashing level for the current slashing type - // multiple colluding parties should have a higher level - GetLevel() slash.ThreatLevel - //GetHeaders - returns the slashable proposed headers - GetHeaders() []HeaderInfoHandler -} - -// MultipleSigningProofHandler contains proof data for a multiple header signing slashing event -type MultipleSigningProofHandler interface { - SlashingProofHandler - // GetPubKeys - returns all validator's public keys which have signed multiple headers - GetPubKeys() [][]byte - // GetLevel - returns the slashing level for a given validator - GetLevel(pubKey []byte) slash.ThreatLevel - // GetHeaders - returns the slashable signed headers proposed by a given validator - GetHeaders(pubKey []byte) []HeaderInfoHandler -} diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index d8bfb46b6..1ba5f2711 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -5,6 +5,7 @@ package slash import ( fmt "fmt" + block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -26,9 +27,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - HeadersInfo HeaderInfoList `protobuf:"bytes,3,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + HeadersInfo block.HeaderInfoList `protobuf:"bytes,3,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -73,11 +74,11 @@ func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { return Low } -func (m *MultipleHeaderProposalProof) GetHeadersInfo() HeaderInfoList { +func (m *MultipleHeaderProposalProof) GetHeadersInfo() block.HeaderInfoList { if m != nil { return m.HeadersInfo } - return HeaderInfoList{} + return block.HeaderInfoList{} } func init() { @@ -87,25 +88,27 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 276 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x2d, 0xcd, 0x29, - 0xc9, 0x2c, 0xc8, 0x49, 0xf5, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x0a, 0x28, 0xca, 0x2f, 0xc8, 0x2f, - 0x4e, 0xcc, 0x09, 0x28, 0xca, 0xcf, 0x4f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, - 0x53, 0x52, 0xdc, 0xc5, 0x39, 0x89, 0xc5, 0x19, 0x10, 0x31, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, - 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xfc, 0xf4, 0x7c, 0x7d, 0xb0, 0x70, 0x52, 0x69, - 0x1a, 0x98, 0x07, 0xe6, 0x80, 0x59, 0x10, 0xe5, 0x4a, 0xeb, 0x19, 0xb9, 0xa4, 0x7d, 0x71, 0x5b, - 0x24, 0xa4, 0xce, 0xc5, 0x12, 0x52, 0x59, 0x90, 0x2a, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x67, 0x24, - 0x0c, 0xd1, 0xa5, 0x17, 0x0c, 0xb2, 0x30, 0x33, 0x2f, 0x1d, 0x24, 0x15, 0x04, 0x56, 0x20, 0xa4, - 0xc1, 0xc5, 0xea, 0x93, 0x5a, 0x96, 0x9a, 0x23, 0xc1, 0x04, 0x56, 0x29, 0x04, 0x55, 0x19, 0x92, - 0x51, 0x94, 0x9a, 0x58, 0x02, 0x96, 0x09, 0x82, 0x28, 0x10, 0xb2, 0xe5, 0xe2, 0x86, 0xd8, 0x54, - 0xec, 0x99, 0x97, 0x96, 0x2f, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0x0a, 0x55, 0x0f, 0x91, - 0x01, 0x49, 0xf8, 0x64, 0x16, 0x97, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x84, 0xac, 0xde, - 0xc9, 0xfe, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, 0x18, 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, - 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, - 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, 0x47, 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, - 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, - 0x70, 0x4a, 0x62, 0x03, 0xdb, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x3e, 0xe3, 0x93, 0xda, - 0x61, 0x01, 0x00, 0x00, + // 318 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0x02, 0x41, + 0x10, 0x86, 0x77, 0x14, 0x2c, 0x8e, 0xc4, 0xe2, 0x8c, 0x09, 0xc1, 0x64, 0x44, 0x1b, 0x69, 0xe0, + 0x12, 0xac, 0x8d, 0x09, 0xc6, 0x04, 0x13, 0x34, 0x04, 0xa9, 0xec, 0xee, 0x60, 0xb9, 0xbb, 0xb0, + 0x30, 0x97, 0xbd, 0x45, 0x63, 0xe7, 0x23, 0xf8, 0x18, 0x76, 0xbe, 0x06, 0x25, 0x25, 0x95, 0x91, + 0xa5, 0xb1, 0xe4, 0x11, 0x0c, 0x73, 0x17, 0x43, 0x63, 0xb5, 0xfb, 0xcf, 0x7c, 0xbb, 0xf3, 0x65, + 0x9c, 0xb3, 0xc9, 0x4c, 0x99, 0x38, 0x51, 0xb2, 0x2d, 0xfd, 0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 0x58, 0x84, + 0xb9, 0x45, 0x58, 0x58, 0x84, 0xa5, 0x45, 0xf8, 0xb6, 0x08, 0x3f, 0x16, 0xc5, 0xc6, 0x22, 0xbc, + 0xaf, 0x51, 0x2c, 0xd6, 0x28, 0x96, 0x6b, 0x14, 0x4f, 0x45, 0x5e, 0x76, 0x70, 0xc0, 0x93, 0x2e, + 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x50, 0x67, 0xe1, 0xa6, 0x01, 0x00, 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -242,7 +245,7 @@ func (this *MultipleHeaderProposalProof) String() string { s := strings.Join([]string{`&MultipleHeaderProposalProof{`, `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, - `HeadersInfo:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersInfo), "HeaderInfoList", "HeaderInfoList", 1), `&`, ``, 1) + `,`, + `HeadersInfo:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersInfo), "HeaderInfoList", "block.HeaderInfoList", 1), `&`, ``, 1) + `,`, `}`, }, "") return s diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index a72f9dfac..5d62accc8 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -7,6 +7,7 @@ option (gogoproto.stable_marshaler_all) = true; import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderProposalProof { SlashingType Type = 1; diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 367123d5e..6a657e9b8 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -6,6 +6,7 @@ package slash import ( bytes "bytes" fmt "fmt" + block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" @@ -28,10 +29,10 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - HeadersInfo map[string]HeaderInfoList `protobuf:"bytes,4,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` + PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + HeadersInfo map[string]block.HeaderInfoList `protobuf:"bytes,4,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -83,7 +84,7 @@ func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { return nil } -func (m *MultipleHeaderSigningProof) GetHeadersInfo() map[string]HeaderInfoList { +func (m *MultipleHeaderSigningProof) GetHeadersInfo() map[string]block.HeaderInfoList { if m != nil { return m.HeadersInfo } @@ -92,38 +93,40 @@ func (m *MultipleHeaderSigningProof) GetHeadersInfo() map[string]HeaderInfoList func init() { proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") - proto.RegisterMapType((map[string]HeaderInfoList)(nil), "proto.MultipleHeaderSigningProof.HeadersInfoEntry") + proto.RegisterMapType((map[string]block.HeaderInfoList)(nil), "proto.MultipleHeaderSigningProof.HeadersInfoEntry") proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") } func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 370 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x6a, 0xea, 0x40, - 0x14, 0xc6, 0x33, 0x46, 0xbd, 0xdc, 0xc9, 0xe5, 0x22, 0x73, 0xb9, 0x10, 0xb2, 0x38, 0x0d, 0xdd, - 0x34, 0x50, 0x8c, 0x90, 0x6e, 0x4a, 0x37, 0x05, 0x41, 0x68, 0xa9, 0x82, 0x44, 0xbb, 0x71, 0x97, - 0xb4, 0x63, 0x0c, 0x8d, 0x19, 0xc9, 0x1f, 0x21, 0xbb, 0x3e, 0x42, 0x1f, 0xc3, 0x47, 0x71, 0xe9, - 0xd2, 0x55, 0xa9, 0xe3, 0xa6, 0x4b, 0x1f, 0xa1, 0x64, 0x92, 0x42, 0x28, 0x95, 0xae, 0x32, 0xe7, - 0xe4, 0xfb, 0x7e, 0x3f, 0x12, 0x06, 0xeb, 0xf3, 0x34, 0x48, 0xfc, 0x45, 0x40, 0x6f, 0xa8, 0xf3, - 0x48, 0xa3, 0x91, 0xef, 0x85, 0x7e, 0xe8, 0x0d, 0x23, 0xc6, 0xa6, 0xe6, 0x22, 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x3c, 0xaf, 0x32, 0x15, 0xeb, 0x7f, 0xc9, 0x2c, 0x9a, 0x79, 0xb1, 0xef, 0xc7, - 0x49, 0x05, 0xdb, 0xbd, 0xde, 0xec, 0x40, 0xda, 0xee, 0x40, 0x3a, 0xec, 0x00, 0x3d, 0x73, 0x40, - 0x2b, 0x0e, 0x68, 0xcd, 0x01, 0x6d, 0x38, 0xa0, 0x2d, 0x07, 0xf4, 0xc6, 0x01, 0xbd, 0x73, 0x90, - 0x0e, 0x1c, 0xd0, 0xcb, 0x1e, 0xa4, 0xcd, 0x1e, 0xa4, 0xed, 0x1e, 0xa4, 0x49, 0x43, 0x5c, 0x10, - 0xb7, 0x29, 0x0c, 0x17, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x6b, 0x98, 0x2d, 0x59, 0x02, - 0x00, 0x00, + // 409 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0xaa, 0xd3, 0x40, + 0x18, 0xc5, 0x33, 0x4d, 0x7b, 0xc5, 0x89, 0xc8, 0x65, 0x44, 0x08, 0x59, 0x8c, 0xc1, 0x8d, 0x01, + 0x49, 0x02, 0x71, 0x23, 0x6e, 0x84, 0x4a, 0xa1, 0x62, 0x2b, 0x25, 0xad, 0x9b, 0xee, 0x92, 0x76, + 0x9a, 0x84, 0xa6, 0x99, 0x32, 0x99, 0x54, 0xb2, 0xf3, 0x11, 0x7c, 0x8c, 0x3e, 0x4a, 0x97, 0x5d, + 0x76, 0x25, 0x76, 0xba, 0x71, 0xd9, 0x47, 0x90, 0x4c, 0xa2, 0x04, 0xb1, 0xdc, 0x55, 0xe6, 0xfb, + 0x72, 0xce, 0xef, 0x9c, 0xfc, 0x81, 0xe6, 0xa6, 0x48, 0x79, 0xb2, 0x4d, 0xc9, 0x90, 0x04, 0x4b, + 0xc2, 0xa6, 0x49, 0x94, 0x25, 0x59, 0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 0xdd, 0x43, 0x75, 0x4d, + 0x4a, 0xf9, 0xcc, 0x8f, 0xfd, 0xea, 0x88, 0x2c, 0xd8, 0xdb, 0x05, 0x69, 0x41, 0xf4, 0x8e, 0x7c, + 0x0f, 0xa8, 0x89, 0x9d, 0xc5, 0x8c, 0x04, 0x5c, 0x5a, 0xfd, 0x5a, 0xf0, 0xae, 0xf3, 0x16, 0x18, + 0x5f, 0xe0, 0xfd, 0xbf, 0xa9, 0xff, 0x61, 0xbe, 0x6e, 0x33, 0x35, 0xef, 0x79, 0xc3, 0x1c, 0xfe, + 0xfd, 0x42, 0xa3, 0x24, 0xe7, 0x2d, 0x6c, 0xff, 0xfd, 0xf1, 0x8c, 0x95, 0xd3, 0x19, 0x2b, 0xd7, + 0x33, 0x06, 0xdf, 0x04, 0x06, 0x7b, 0x81, 0xc1, 0x41, 0x60, 0x70, 0x14, 0x18, 0x9c, 0x04, 0x06, + 0x3f, 0x05, 0x06, 0xbf, 0x04, 0x56, 0xae, 0x02, 0x83, 0xef, 0x17, 0xac, 0x1c, 0x2f, 0x58, 0x39, + 0x5d, 0xb0, 0x32, 0xef, 0xc9, 0xbf, 0x2c, 0xbc, 0x93, 0x09, 0x6f, 0x7e, 0x07, 0x00, 0x00, 0xff, + 0xff, 0x20, 0xc8, 0x97, 0x39, 0x9e, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -202,7 +205,7 @@ func (this *MultipleHeaderSigningProof) GoString() string { keysForHeadersInfo = append(keysForHeadersInfo, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) - mapStringForHeadersInfo := "map[string]HeaderInfoList{" + mapStringForHeadersInfo := "map[string]block.HeaderInfoList{" for _, k := range keysForHeadersInfo { mapStringForHeadersInfo += fmt.Sprintf("%#v: %#v,", k, this.HeadersInfo[k]) } @@ -380,7 +383,7 @@ func (this *MultipleHeaderSigningProof) String() string { keysForHeadersInfo = append(keysForHeadersInfo, k) } github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) - mapStringForHeadersInfo := "map[string]HeaderInfoList{" + mapStringForHeadersInfo := "map[string]block.HeaderInfoList{" for _, k := range keysForHeadersInfo { mapStringForHeadersInfo += fmt.Sprintf("%v: %v,", k, this.HeadersInfo[k]) } @@ -625,10 +628,10 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.HeadersInfo == nil { - m.HeadersInfo = make(map[string]HeaderInfoList) + m.HeadersInfo = make(map[string]block.HeaderInfoList) } var mapkey string - mapvalue := &HeaderInfoList{} + mapvalue := &block.HeaderInfoList{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -702,7 +705,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postmsgIndex > l { return io.ErrUnexpectedEOF } - mapvalue = &HeaderInfoList{} + mapvalue = &block.HeaderInfoList{} if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { return err } diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 2ab9283f5..2f1c2466e 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -7,6 +7,7 @@ option (gogoproto.stable_marshaler_all) = true; import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderSigningProof { SlashingType Type = 1; diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go index 8ab6c3e95..c1a29fb97 100644 --- a/data/slash/slash.pb.go +++ b/data/slash/slash.pb.go @@ -5,15 +5,10 @@ package slash import ( fmt "fmt" - block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - io "io" math "math" - math_bits "math/bits" - reflect "reflect" strconv "strconv" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. @@ -75,76 +70,31 @@ func (ThreatLevel) EnumDescriptor() ([]byte, []int) { return fileDescriptor_7c4604f407d65f7b, []int{1} } -type HeaderInfoList struct { - Headers []*block.HeaderInfo `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` -} - -func (m *HeaderInfoList) Reset() { *m = HeaderInfoList{} } -func (*HeaderInfoList) ProtoMessage() {} -func (*HeaderInfoList) Descriptor() ([]byte, []int) { - return fileDescriptor_7c4604f407d65f7b, []int{0} -} -func (m *HeaderInfoList) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeaderInfoList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *HeaderInfoList) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeaderInfoList.Merge(m, src) -} -func (m *HeaderInfoList) XXX_Size() int { - return m.Size() -} -func (m *HeaderInfoList) XXX_DiscardUnknown() { - xxx_messageInfo_HeaderInfoList.DiscardUnknown(m) -} - -var xxx_messageInfo_HeaderInfoList proto.InternalMessageInfo - -func (m *HeaderInfoList) GetHeaders() []*block.HeaderInfo { - if m != nil { - return m.Headers - } - return nil -} - func init() { proto.RegisterEnum("proto.SlashingType", SlashingType_name, SlashingType_value) proto.RegisterEnum("proto.ThreatLevel", ThreatLevel_name, ThreatLevel_value) - proto.RegisterType((*HeaderInfoList)(nil), "proto.HeaderInfoList") } func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } var fileDescriptor_7c4604f407d65f7b = []byte{ - // 324 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x31, 0x4f, 0x32, 0x31, - 0x1c, 0xc6, 0x5b, 0x78, 0x81, 0x37, 0xc5, 0xe8, 0x79, 0x3a, 0x18, 0x86, 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5e, 0x61, 0x8a, 0x99, 0x1f, 0x3b, 0xd4, 0x3d, 0x60, 0x7b, 0x5b, 0xda, 0x97, 0x22, 0x91, - 0x89, 0x70, 0x0a, 0xf5, 0x73, 0x56, 0x1d, 0x44, 0x8a, 0xfb, 0xba, 0xc3, 0x9f, 0x78, 0xec, 0x56, - 0x58, 0xb1, 0x83, 0x53, 0x87, 0xb8, 0x8c, 0x95, 0xbb, 0x3c, 0x94, 0xf9, 0xc4, 0xa1, 0xeb, 0xe2, - 0xb6, 0x14, 0x91, 0x53, 0xb8, 0xb9, 0x9e, 0x2d, 0x80, 0xcc, 0x17, 0x40, 0x56, 0x0b, 0xa0, 0x2f, - 0x06, 0xe8, 0x9b, 0x01, 0xfa, 0x6e, 0x80, 0xce, 0x0c, 0xd0, 0xb9, 0x01, 0xfa, 0x61, 0x80, 0x7e, - 0x1a, 0x20, 0x2b, 0x03, 0xf4, 0x75, 0x09, 0x64, 0xb6, 0x04, 0x32, 0x5f, 0x02, 0x79, 0x2c, 0xd9, - 0x3f, 0x0f, 0xca, 0x76, 0xce, 0xe5, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x96, 0x29, 0xb0, 0xed, - 0x83, 0x01, 0x00, 0x00, + // 246 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8f, 0xb1, 0x4e, 0xc3, 0x30, + 0x10, 0x86, 0x7d, 0x85, 0x16, 0x74, 0x45, 0xc2, 0x32, 0x4c, 0x0c, 0xf7, 0x00, 0x15, 0xb4, 0x03, + 0x0f, 0x80, 0x04, 0x0b, 0x43, 0x8b, 0x90, 0xda, 0x89, 0x2d, 0x01, 0xe3, 0x58, 0x72, 0x73, 0x51, + 0x12, 0x83, 0xd8, 0x78, 0x04, 0x1e, 0x83, 0x47, 0x61, 0xcc, 0x98, 0x91, 0x38, 0x0b, 0x63, 0x1f, + 0x01, 0xc5, 0x88, 0xe9, 0xee, 0xff, 0xa4, 0xfb, 0x74, 0x3f, 0x4e, 0x2b, 0x97, 0x54, 0xd9, 0xbc, + 0x28, 0xb9, 0x66, 0x35, 0x8e, 0xe3, 0xec, 0xc2, 0xd8, 0x3a, 0xf3, 0xe9, 0xfc, 0x91, 0xb7, 0x0b, + 0xc3, 0x86, 0x17, 0x11, 0xa7, 0xfe, 0x39, 0xa6, 0x18, 0xe2, 0xf6, 0x77, 0x35, 0xbb, 0xc1, 0xa3, + 0xf5, 0x20, 0xb1, 0xb9, 0xd9, 0xbc, 0x15, 0x5a, 0x1d, 0xe2, 0xfe, 0x1d, 0xe7, 0x5a, 0x0a, 0x75, + 0x8a, 0x72, 0xe5, 0x5d, 0x6d, 0x0b, 0xa7, 0xef, 0x4b, 0x2e, 0xb8, 0x4a, 0x9c, 0x04, 0x75, 0x82, + 0xc7, 0xff, 0x74, 0x6d, 0x4d, 0x6e, 0x73, 0x23, 0x47, 0xb3, 0x73, 0x9c, 0x6e, 0xb2, 0x52, 0x27, + 0xf5, 0x52, 0xbf, 0x68, 0xa7, 0x0e, 0x70, 0x6f, 0xc9, 0xaf, 0x52, 0x28, 0xc4, 0xc9, 0x4a, 0x3f, + 0x59, 0xbf, 0x95, 0x30, 0x88, 0x6f, 0xad, 0xc9, 0xe4, 0xe8, 0xfa, 0xaa, 0xe9, 0x48, 0xb4, 0x1d, + 0x89, 0x5d, 0x47, 0xf0, 0x1e, 0x08, 0x3e, 0x03, 0xc1, 0x57, 0x20, 0x68, 0x02, 0x41, 0x1b, 0x08, + 0xbe, 0x03, 0xc1, 0x4f, 0x20, 0xb1, 0x0b, 0x04, 0x1f, 0x3d, 0x89, 0xa6, 0x27, 0xd1, 0xf6, 0x24, + 0x1e, 0xc6, 0xb1, 0x6f, 0x3a, 0x89, 0xaf, 0x5f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x36, 0xcd, + 0x59, 0xff, 0xff, 0x00, 0x00, 0x00, } func (x SlashingType) String() string { @@ -161,315 +111,3 @@ func (x ThreatLevel) String() string { } return strconv.Itoa(int(x)) } -func (this *HeaderInfoList) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HeaderInfoList) - if !ok { - that2, ok := that.(HeaderInfoList) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Headers) != len(that1.Headers) { - return false - } - for i := range this.Headers { - if !this.Headers[i].Equal(that1.Headers[i]) { - return false - } - } - return true -} -func (this *HeaderInfoList) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&slash.HeaderInfoList{") - if this.Headers != nil { - s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringSlash(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *HeaderInfoList) 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 *HeaderInfoList) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HeaderInfoList) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Headers) > 0 { - for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintSlash(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintSlash(dAtA []byte, offset int, v uint64) int { - offset -= sovSlash(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *HeaderInfoList) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Headers) > 0 { - for _, e := range m.Headers { - l = e.Size() - n += 1 + l + sovSlash(uint64(l)) - } - } - return n -} - -func sovSlash(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozSlash(x uint64) (n int) { - return sovSlash(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *HeaderInfoList) String() string { - if this == nil { - return "nil" - } - repeatedStringForHeaders := "[]*HeaderInfo{" - for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(fmt.Sprintf("%v", f), "HeaderInfo", "block.HeaderInfo", 1) + "," - } - repeatedStringForHeaders += "}" - s := strings.Join([]string{`&HeaderInfoList{`, - `Headers:` + repeatedStringForHeaders + `,`, - `}`, - }, "") - return s -} -func valueToStringSlash(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *HeaderInfoList) 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 ErrIntOverflowSlash - } - 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: HeaderInfoList: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeaderInfoList: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSlash - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSlash - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSlash - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Headers = append(m.Headers, &block.HeaderInfo{}) - if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSlash(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSlash - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSlash - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSlash(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSlash - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSlash - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSlash - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthSlash - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupSlash - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthSlash - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthSlash = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSlash = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupSlash = fmt.Errorf("proto: unexpected end of group") -) diff --git a/data/slash/slash.proto b/data/slash/slash.proto index 358350c78..ab648ceba 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -6,7 +6,6 @@ option go_package = "slash"; option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; enum SlashingType { None = 0; @@ -20,6 +19,3 @@ enum ThreatLevel { High = 2; } -message HeaderInfoList{ - repeated HeaderInfo Headers = 1; -} diff --git a/data/slash/types/interface.go b/data/slash/types/interface.go new file mode 100644 index 000000000..77095388e --- /dev/null +++ b/data/slash/types/interface.go @@ -0,0 +1,33 @@ +package types + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/slash" +) + +// SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction +type SlashingProofHandler interface { + //GetType - contains the type of slashing detection + GetType() slash.SlashingType +} + +// MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event +type MultipleProposalProofHandler interface { + SlashingProofHandler + // GetLevel - contains the slashing level for the current slashing type + // multiple colluding parties should have a higher level + GetLevel() slash.ThreatLevel + //GetHeaders - returns the slashable proposed headers + GetHeaders() []data.HeaderInfoHandler +} + +// MultipleSigningProofHandler contains proof data for a multiple header signing slashing event +type MultipleSigningProofHandler interface { + SlashingProofHandler + // GetPubKeys - returns all validator's public keys which have signed multiple headers + GetPubKeys() [][]byte + // GetLevel - returns the slashing level for a given validator + GetLevel(pubKey []byte) slash.ThreatLevel + // GetHeaders - returns the slashable signed headers proposed by a given validator + GetHeaders(pubKey []byte) []data.HeaderInfoHandler +} From 2a0e21287dfbd6a80ba05e808e1073d774804d27 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 1 Nov 2021 17:32:11 +0200 Subject: [PATCH 14/54] FEAT: Add header info generated proto files --- data/block/headerInfo.pb.go | 251 +++++++++++++++++++++++++++++++++++- data/block/headerInfo.proto | 4 + 2 files changed, 248 insertions(+), 7 deletions(-) diff --git a/data/block/headerInfo.pb.go b/data/block/headerInfo.pb.go index 564c118f7..babcfbbe8 100644 --- a/data/block/headerInfo.pb.go +++ b/data/block/headerInfo.pb.go @@ -73,14 +73,54 @@ func (m *HeaderInfo) GetHash() []byte { return nil } +type HeaderInfoList struct { + Headers []*HeaderInfo `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` +} + +func (m *HeaderInfoList) Reset() { *m = HeaderInfoList{} } +func (*HeaderInfoList) ProtoMessage() {} +func (*HeaderInfoList) Descriptor() ([]byte, []int) { + return fileDescriptor_f4bbbba9a375b11e, []int{1} +} +func (m *HeaderInfoList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeaderInfoList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *HeaderInfoList) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderInfoList.Merge(m, src) +} +func (m *HeaderInfoList) XXX_Size() int { + return m.Size() +} +func (m *HeaderInfoList) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderInfoList.DiscardUnknown(m) +} + +var xxx_messageInfo_HeaderInfoList proto.InternalMessageInfo + +func (m *HeaderInfoList) GetHeaders() []*HeaderInfo { + if m != nil { + return m.Headers + } + return nil +} + func init() { proto.RegisterType((*HeaderInfo)(nil), "proto.HeaderInfo") + proto.RegisterType((*HeaderInfoList)(nil), "proto.HeaderInfoList") } func init() { proto.RegisterFile("headerInfo.proto", fileDescriptor_f4bbbba9a375b11e) } var fileDescriptor_f4bbbba9a375b11e = []byte{ - // 205 bytes of a gzipped FileDescriptorProto + // 237 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0xf2, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, @@ -88,12 +128,14 @@ var fileDescriptor_f4bbbba9a375b11e = []byte{ 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xc3, 0x8c, 0x20, 0x5c, 0x25, 0x4f, 0x2e, 0x2e, 0x0f, 0xb8, 0xc1, 0x42, 0xea, 0x5c, 0x6c, 0x10, 0x9e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x11, 0x3f, 0x44, 0x95, 0x1e, 0x44, 0x30, 0xcc, 0x28, 0x08, 0x2a, 0x2d, 0x24, 0xc4, 0xc5, 0xe2, 0x91, 0x58, 0x9c, 0x21, - 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x66, 0x3b, 0xd9, 0x5f, 0x78, 0x28, 0xc7, 0x70, 0xe3, - 0xa1, 0x1c, 0xc3, 0x87, 0x87, 0x72, 0x8c, 0x0d, 0x8f, 0xe4, 0x18, 0x57, 0x3c, 0x92, 0x63, 0x3c, - 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x1b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, - 0x7c, 0xf1, 0x48, 0x8e, 0xe1, 0xc3, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, - 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x8a, 0x15, 0xec, 0xa6, 0x24, 0x36, 0xb0, 0x65, 0xc6, 0x80, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0xfb, 0x05, 0xc9, 0xeb, 0x00, 0x00, 0x00, + 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x66, 0x2b, 0xd9, 0x72, 0xf1, 0x21, 0x8c, 0xf2, 0xc9, + 0x2c, 0x2e, 0x11, 0xd2, 0xe6, 0x62, 0x87, 0x88, 0x14, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, + 0x09, 0xa2, 0x98, 0x07, 0x52, 0x17, 0x04, 0x53, 0xe1, 0x64, 0x7f, 0xe1, 0xa1, 0x1c, 0xc3, 0x8d, + 0x87, 0x72, 0x0c, 0x1f, 0x1e, 0xca, 0x31, 0x36, 0x3c, 0x92, 0x63, 0x5c, 0xf1, 0x48, 0x8e, 0xf1, + 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x6f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, + 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0x97, 0x92, 0xd8, 0xc0, 0x66, 0x1b, 0x03, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x31, 0x64, 0xd8, 0x2a, 0x01, 0x00, 0x00, } func (this *HeaderInfo) Equal(that interface{}) bool { @@ -123,6 +165,35 @@ func (this *HeaderInfo) Equal(that interface{}) bool { } return true } +func (this *HeaderInfoList) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HeaderInfoList) + if !ok { + that2, ok := that.(HeaderInfoList) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Headers) != len(that1.Headers) { + return false + } + for i := range this.Headers { + if !this.Headers[i].Equal(that1.Headers[i]) { + return false + } + } + return true +} func (this *HeaderInfo) GoString() string { if this == nil { return "nil" @@ -136,6 +207,18 @@ func (this *HeaderInfo) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *HeaderInfoList) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&block.HeaderInfoList{") + if this.Headers != nil { + s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} func valueToGoStringHeaderInfo(v interface{}, typ string) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -186,6 +269,43 @@ func (m *HeaderInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *HeaderInfoList) 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 *HeaderInfoList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeaderInfoList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Headers) > 0 { + for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintHeaderInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintHeaderInfo(dAtA []byte, offset int, v uint64) int { offset -= sovHeaderInfo(v) base := offset @@ -214,6 +334,21 @@ func (m *HeaderInfo) Size() (n int) { return n } +func (m *HeaderInfoList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Headers) > 0 { + for _, e := range m.Headers { + l = e.Size() + n += 1 + l + sovHeaderInfo(uint64(l)) + } + } + return n +} + func sovHeaderInfo(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -231,6 +366,21 @@ func (this *HeaderInfo) String() string { }, "") return s } +func (this *HeaderInfoList) String() string { + if this == nil { + return "nil" + } + repeatedStringForHeaders := "[]*HeaderInfo{" + for _, f := range this.Headers { + repeatedStringForHeaders += strings.Replace(f.String(), "HeaderInfo", "HeaderInfo", 1) + "," + } + repeatedStringForHeaders += "}" + s := strings.Join([]string{`&HeaderInfoList{`, + `Headers:` + repeatedStringForHeaders + `,`, + `}`, + }, "") + return s +} func valueToStringHeaderInfo(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -362,6 +512,93 @@ func (m *HeaderInfo) Unmarshal(dAtA []byte) error { } return nil } +func (m *HeaderInfoList) 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 ErrIntOverflowHeaderInfo + } + 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: HeaderInfoList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeaderInfoList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthHeaderInfo + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthHeaderInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Headers = append(m.Headers, &HeaderInfo{}) + if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHeaderInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthHeaderInfo + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthHeaderInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipHeaderInfo(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/data/block/headerInfo.proto b/data/block/headerInfo.proto index 2bf40d8cb..358ba29c6 100644 --- a/data/block/headerInfo.proto +++ b/data/block/headerInfo.proto @@ -11,4 +11,8 @@ import "blockV2.proto"; message HeaderInfo { HeaderV2 Header = 1; bytes Hash = 2; +} + +message HeaderInfoList{ + repeated HeaderInfo Headers = 1; } \ No newline at end of file From c547b25e627090ffbe8e8d5d7b5d4c52562ea537 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 2 Nov 2021 11:30:10 +0200 Subject: [PATCH 15/54] FEAT: Add set headers, slash result, proof constructors --- data/block/headerInfo.go | 19 ++++ data/slash/common.go | 10 ++ data/slash/{types => }/interface.go | 9 +- data/slash/multipleHeaderProposalProof.go | 31 +++++- data/slash/multipleHeaderProposalProof.pb.go | 91 +++++---------- data/slash/multipleHeaderProposalProof.proto | 5 +- data/slash/multipleHeaderSigningProof.go | 36 ++++++ data/slash/multipleHeaderSigningProof.pb.go | 111 ++++++------------- data/slash/multipleHeaderSigningProof.proto | 7 +- 9 files changed, 164 insertions(+), 155 deletions(-) create mode 100644 data/slash/common.go rename data/slash/{types => }/interface.go (86%) diff --git a/data/block/headerInfo.go b/data/block/headerInfo.go index 8b815a74b..b8369635d 100644 --- a/data/block/headerInfo.go +++ b/data/block/headerInfo.go @@ -10,3 +10,22 @@ func (m *HeaderInfo) GetHeaderHandler() data.HeaderHandler { return m.Header } + +func (m *HeaderInfoList) SetHeadersInfo(headers []data.HeaderInfoHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.Headers = nil + for _, header := range headers { + headerHandler := header.GetHeaderHandler() + hdr, castOk := headerHandler.(*HeaderV2) + if !castOk { + return data.ErrInvalidTypeAssertion + } + + m.Headers = append(m.Headers, &HeaderInfo{Header: hdr, Hash: header.GetHash()}) + } + + return nil +} diff --git a/data/slash/common.go b/data/slash/common.go new file mode 100644 index 000000000..c33f5b396 --- /dev/null +++ b/data/slash/common.go @@ -0,0 +1,10 @@ +package slash + +import "github.com/ElrondNetwork/elrond-go-core/data" + +// SlashingResult contains the slashable data as well as the severity(slashing level) +// for a possible malicious validator +type SlashingResult struct { + SlashingLevel ThreatLevel + Headers []data.HeaderInfoHandler +} diff --git a/data/slash/types/interface.go b/data/slash/interface.go similarity index 86% rename from data/slash/types/interface.go rename to data/slash/interface.go index 77095388e..9091991ee 100644 --- a/data/slash/types/interface.go +++ b/data/slash/interface.go @@ -1,14 +1,13 @@ -package types +package slash import ( "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/slash" ) // SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction type SlashingProofHandler interface { //GetType - contains the type of slashing detection - GetType() slash.SlashingType + GetType() SlashingType } // MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event @@ -16,7 +15,7 @@ type MultipleProposalProofHandler interface { SlashingProofHandler // GetLevel - contains the slashing level for the current slashing type // multiple colluding parties should have a higher level - GetLevel() slash.ThreatLevel + GetLevel() ThreatLevel //GetHeaders - returns the slashable proposed headers GetHeaders() []data.HeaderInfoHandler } @@ -27,7 +26,7 @@ type MultipleSigningProofHandler interface { // GetPubKeys - returns all validator's public keys which have signed multiple headers GetPubKeys() [][]byte // GetLevel - returns the slashing level for a given validator - GetLevel(pubKey []byte) slash.ThreatLevel + GetLevel(pubKey []byte) ThreatLevel // GetHeaders - returns the slashable signed headers proposed by a given validator GetHeaders(pubKey []byte) []data.HeaderInfoHandler } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index 6f76dd8ef..d34ee6bbb 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -1,7 +1,17 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. multipleHeaderProposalProof.proto package slash -import "github.com/ElrondNetwork/elrond-go-core/data" +import ( + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" +) + +func (m *MultipleHeaderProposalProof) GetType() SlashingType { + if m == nil { + return None + } + return MultipleProposal +} func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { if m == nil { @@ -15,3 +25,22 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { return ret } + +func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProofHandler, error) { + if slashResult == nil { + return nil, nil //process.ErrNilSlashResult + } + if slashResult.Headers == nil { + return nil, nil //process.ErrNilHeaderHandler + } + + headersInfo := block.HeaderInfoList{} + err := headersInfo.SetHeadersInfo(slashResult.Headers) + if err != nil { + return nil, err + } + return &MultipleHeaderProposalProof{ + Level: slashResult.SlashingLevel, + HeadersInfo: headersInfo, + }, nil +} diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index 1ba5f2711..9b3f72761 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -27,9 +27,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - Level ThreatLevel `protobuf:"varint,2,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - HeadersInfo block.HeaderInfoList `protobuf:"bytes,3,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` + Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + HeadersInfo block.HeaderInfoList `protobuf:"bytes,2,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -60,13 +59,6 @@ func (m *MultipleHeaderProposalProof) XXX_DiscardUnknown() { var xxx_messageInfo_MultipleHeaderProposalProof proto.InternalMessageInfo -func (m *MultipleHeaderProposalProof) GetType() SlashingType { - if m != nil { - return m.Type - } - return None -} - func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { if m != nil { return m.Level @@ -88,27 +80,26 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 318 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4e, 0x02, 0x41, - 0x10, 0x86, 0x77, 0x14, 0x2c, 0x8e, 0xc4, 0xe2, 0x8c, 0x09, 0xc1, 0x64, 0x44, 0x1b, 0x69, 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a, 0xf2, 0x1e, 0x93, 0x6e, 0x4e, 0xf6, 0x23, 0x2d, 0x7d, 0xc3, 0x9d, - 0x5e, 0x06, 0xb8, 0x57, 0x4e, 0x29, 0x9b, 0x94, 0x6e, 0x3d, 0xca, 0xfb, 0x55, 0xa8, 0x95, 0x9a, - 0xc7, 0x39, 0xdf, 0xfe, 0x13, 0xec, 0xc4, 0xa9, 0x69, 0x15, 0xe6, 0x5f, 0xa7, 0xa2, 0xb7, 0xcb, - 0xb7, 0xae, 0x17, 0x2b, 0x14, 0xcb, 0x15, 0x8a, 0xcd, 0x0a, 0xe1, 0xcd, 0x22, 0x7c, 0x58, 0x84, - 0xb9, 0x45, 0x58, 0x58, 0x84, 0xa5, 0x45, 0xf8, 0xb6, 0x08, 0x3f, 0x16, 0xc5, 0xc6, 0x22, 0xbc, - 0xaf, 0x51, 0x2c, 0xd6, 0x28, 0x96, 0x6b, 0x14, 0x4f, 0x45, 0x5e, 0x76, 0x70, 0xc0, 0x93, 0x2e, - 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x50, 0x67, 0xe1, 0xa6, 0x01, 0x00, 0x00, + // 294 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4b, 0xc3, 0x40, + 0x14, 0xc6, 0xef, 0x89, 0x75, 0x48, 0xc1, 0x21, 0x20, 0x94, 0x0a, 0xcf, 0xea, 0xd4, 0xa5, 0x3d, + 0xa8, 0xb3, 0x08, 0x15, 0xa1, 0x42, 0x95, 0x52, 0x9c, 0xdc, 0x2e, 0xed, 0x35, 0x29, 0xbd, 0xf6, + 0x85, 0xcb, 0x45, 0x57, 0x27, 0x67, 0xff, 0x0c, 0xff, 0x94, 0x8e, 0x19, 0x33, 0x89, 0xb9, 0x2c, + 0x8e, 0xfd, 0x13, 0xc4, 0x4b, 0x90, 0x2e, 0x4e, 0x77, 0xdf, 0x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0x59, 0x84, 0x6f, 0x8b, 0x6c, 0x67, 0x11, 0xde, 0x4b, 0x64, 0x59, 0x89, 0x2c, 0x2f, 0x91, + 0x3d, 0x35, 0xdc, 0x0e, 0x83, 0x23, 0x97, 0x74, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x2e, + 0x85, 0x3a, 0x7d, 0x01, 0x00, 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -130,9 +121,6 @@ func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { } else if this == nil { return false } - if this.Type != that1.Type { - return false - } if this.Level != that1.Level { return false } @@ -145,9 +133,8 @@ func (this *MultipleHeaderProposalProof) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 6) s = append(s, "&slash.MultipleHeaderProposalProof{") - s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") s = append(s, "HeadersInfo: "+strings.Replace(this.HeadersInfo.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") @@ -190,15 +177,10 @@ func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, er i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 if m.Level != 0 { i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Level)) i-- - dAtA[i] = 0x10 - } - if m.Type != 0 { - i = encodeVarintMultipleHeaderProposalProof(dAtA, i, uint64(m.Type)) - i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil @@ -221,9 +203,6 @@ func (m *MultipleHeaderProposalProof) Size() (n int) { } var l int _ = l - if m.Type != 0 { - n += 1 + sovMultipleHeaderProposalProof(uint64(m.Type)) - } if m.Level != 0 { n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) } @@ -243,7 +222,6 @@ func (this *MultipleHeaderProposalProof) String() string { return "nil" } s := strings.Join([]string{`&MultipleHeaderProposalProof{`, - `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, `HeadersInfo:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersInfo), "HeaderInfoList", "block.HeaderInfoList", 1), `&`, ``, 1) + `,`, `}`, @@ -288,25 +266,6 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMultipleHeaderProposalProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= SlashingType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Level", wireType) } @@ -325,7 +284,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { break } } - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) } diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index 5d62accc8..c0048e5d5 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -10,7 +10,6 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderProposalProof { - SlashingType Type = 1; - ThreatLevel Level = 2; - HeaderInfoList HeadersInfo = 3 [(gogoproto.nullable) = false]; + ThreatLevel Level = 1; + HeaderInfoList HeadersInfo = 2 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 1af011475..eda640b61 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -3,8 +3,16 @@ package slash import ( "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" ) +func (m *MultipleHeaderSigningProof) GetType() SlashingType { + if m == nil { + return None + } + return MultipleSigning +} + func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { if m == nil { return Low @@ -35,3 +43,31 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderInfo return ret } + +func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSigningProofHandler, error) { + if slashResult == nil { + return nil, nil //process.ErrNilSlashResult + } + + pubKeys := make([][]byte, 0, len(slashResult)) + levels := make(map[string]ThreatLevel, len(slashResult)) + headers := make(map[string]block.HeaderInfoList, len(slashResult)) + + for pubKey, res := range slashResult { + pubKeys = append(pubKeys, []byte(pubKey)) + levels[pubKey] = res.SlashingLevel + + tmp := block.HeaderInfoList{} + err := tmp.SetHeadersInfo(res.Headers) + if err != nil { + return nil, err + } + headers[pubKey] = tmp + } + + return &MultipleHeaderSigningProof{ + PubKeys: pubKeys, + Levels: levels, + HeadersInfo: headers, + }, nil +} diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 6a657e9b8..6376150ac 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -29,10 +29,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` - PubKeys [][]byte `protobuf:"bytes,2,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,3,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - HeadersInfo map[string]block.HeaderInfoList `protobuf:"bytes,4,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + HeadersInfo map[string]block.HeaderInfoList `protobuf:"bytes,3,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -63,13 +62,6 @@ func (m *MultipleHeaderSigningProof) XXX_DiscardUnknown() { var xxx_messageInfo_MultipleHeaderSigningProof proto.InternalMessageInfo -func (m *MultipleHeaderSigningProof) GetType() SlashingType { - if m != nil { - return m.Type - } - return None -} - func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { if m != nil { return m.PubKeys @@ -100,33 +92,32 @@ func init() { func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 409 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0xaa, 0xd3, 0x40, - 0x18, 0xc5, 0x33, 0x4d, 0x7b, 0xc5, 0x89, 0xc8, 0x65, 0x44, 0x08, 0x59, 0x8c, 0xc1, 0x8d, 0x01, - 0x49, 0x02, 0x71, 0x23, 0x6e, 0x84, 0x4a, 0xa1, 0x62, 0x2b, 0x25, 0xad, 0x9b, 0xee, 0x92, 0x76, - 0x9a, 0x84, 0xa6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 0x24, 0xcd, 0x75, 0xd5, 0x54, 0x2d, - 0xcd, 0xb3, 0x1b, 0xc8, 0xed, 0x54, 0xa7, 0xd6, 0x0f, 0x32, 0xce, 0x4a, 0xbf, 0x31, 0xa3, 0x39, - 0xd4, 0x6a, 0x65, 0x5e, 0xb5, 0xd7, 0xbb, 0x92, 0xe5, 0x3d, 0xcc, 0x6a, 0x99, 0x24, 0xb0, 0xdf, - 0x3d, 0xfc, 0x78, 0xa1, 0xf8, 0x6d, 0x98, 0x31, 0x86, 0x5a, 0x2b, 0x12, 0xdd, 0x43, 0x75, 0x4d, - 0x4a, 0xf9, 0xcc, 0x8f, 0xfd, 0xea, 0x88, 0x2c, 0xd8, 0xdb, 0x05, 0x69, 0x41, 0xf4, 0x8e, 0x7c, - 0x0f, 0xa8, 0x89, 0x9d, 0xc5, 0x8c, 0x04, 0x5c, 0x5a, 0xfd, 0x5a, 0xf0, 0xae, 0xf3, 0x16, 0x18, - 0x5f, 0xe0, 0xfd, 0xbf, 0xa9, 0xff, 0x61, 0xbe, 0x6e, 0x33, 0x35, 0xef, 0x79, 0xc3, 0x1c, 0xfe, - 0xfd, 0x42, 0xa3, 0x24, 0xe7, 0x2d, 0x6c, 0xff, 0xfd, 0xf1, 0x8c, 0x95, 0xd3, 0x19, 0x2b, 0xd7, - 0x33, 0x06, 0xdf, 0x04, 0x06, 0x7b, 0x81, 0xc1, 0x41, 0x60, 0x70, 0x14, 0x18, 0x9c, 0x04, 0x06, - 0x3f, 0x05, 0x06, 0xbf, 0x04, 0x56, 0xae, 0x02, 0x83, 0xef, 0x17, 0xac, 0x1c, 0x2f, 0x58, 0x39, - 0x5d, 0xb0, 0x32, 0xef, 0xc9, 0xbf, 0x2c, 0xbc, 0x93, 0x09, 0x6f, 0x7e, 0x07, 0x00, 0x00, 0xff, - 0xff, 0x20, 0xc8, 0x97, 0x39, 0x9e, 0x02, 0x00, 0x00, + // 389 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6a, 0xa3, 0x40, + 0x1c, 0xc6, 0x1d, 0xdd, 0x64, 0xd9, 0x71, 0x59, 0x82, 0xb0, 0x20, 0x1e, 0x66, 0x65, 0x4f, 0xc2, + 0xa2, 0x82, 0x7b, 0x59, 0xf6, 0x52, 0x48, 0x09, 0xa4, 0x34, 0x29, 0xc1, 0xb6, 0x97, 0xdc, 0x34, + 0x99, 0xa8, 0xc4, 0x38, 0x61, 0x1c, 0x53, 0x72, 0xeb, 0x23, 0xf4, 0x31, 0xfa, 0x28, 0x39, 0xe6, + 0x98, 0x53, 0x69, 0x26, 0x97, 0x1e, 0xf3, 0x06, 0x2d, 0x19, 0x6d, 0x91, 0xd2, 0xd0, 0x93, 0xff, + 0xef, 0xcf, 0xf7, 0xff, 0x7d, 0x1f, 0x32, 0xd0, 0x9c, 0x15, 0x29, 0x4b, 0xe6, 0x29, 0xee, 0xe2, + 0x60, 0x8c, 0xe9, 0x65, 0x12, 0x65, 0x49, 0x16, 0x0d, 0x28, 0x21, 0x13, 0x67, 0x4e, 0x09, 0x23, + 0x5a, 0x43, 0x7c, 0x0c, 0x35, 0x4f, 0x83, 0x3c, 0x2e, 0x77, 0x86, 0x1d, 0x25, 0x2c, 0x2e, 0x42, + 0x67, 0x44, 0x66, 0x6e, 0x44, 0x22, 0xe2, 0x8a, 0x75, 0x58, 0x4c, 0x84, 0x12, 0x42, 0x4c, 0x95, + 0xfd, 0xb4, 0x66, 0xef, 0xa4, 0x94, 0x64, 0xe3, 0x0b, 0xcc, 0x6e, 0x08, 0x9d, 0xba, 0x58, 0x28, + 0x3b, 0x22, 0xf6, 0x88, 0x50, 0xec, 0x8e, 0x03, 0x16, 0xb8, 0x61, 0x4a, 0x46, 0x53, 0x37, 0x16, + 0x7d, 0xce, 0xb2, 0x49, 0x05, 0xf9, 0xfd, 0x2c, 0x43, 0xa3, 0x7f, 0xb4, 0xac, 0xa6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 0x22, 0xe1, 0xef, 0x4b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x19, 0xa3, + 0xbb, 0x75, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -148,9 +139,6 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { } else if this == nil { return false } - if this.Type != that1.Type { - return false - } if len(this.PubKeys) != len(that1.PubKeys) { return false } @@ -183,9 +171,8 @@ func (this *MultipleHeaderSigningProof) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 7) s = append(s, "&slash.MultipleHeaderSigningProof{") - s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "PubKeys: "+fmt.Sprintf("%#v", this.PubKeys)+",\n") keysForLevels := make([]string, 0, len(this.Levels)) for k, _ := range this.Levels { @@ -270,7 +257,7 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } } if len(m.Levels) > 0 { @@ -292,7 +279,7 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } } if len(m.PubKeys) > 0 { @@ -301,14 +288,9 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err copy(dAtA[i:], m.PubKeys[iNdEx]) i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(m.PubKeys[iNdEx]))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0xa } } - if m.Type != 0 { - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - } return len(dAtA) - i, nil } @@ -329,9 +311,6 @@ func (m *MultipleHeaderSigningProof) Size() (n int) { } var l int _ = l - if m.Type != 0 { - n += 1 + sovMultipleHeaderSigningProof(uint64(m.Type)) - } if len(m.PubKeys) > 0 { for _, b := range m.PubKeys { l = len(b) @@ -389,7 +368,6 @@ func (this *MultipleHeaderSigningProof) String() string { } mapStringForHeadersInfo += "}" s := strings.Join([]string{`&MultipleHeaderSigningProof{`, - `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, `Levels:` + mapStringForLevels + `,`, `HeadersInfo:` + mapStringForHeadersInfo + `,`, @@ -435,25 +413,6 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMultipleHeaderSigningProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= SlashingType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PubKeys", wireType) } @@ -485,7 +444,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { m.PubKeys = append(m.PubKeys, make([]byte, postIndex-iNdEx)) copy(m.PubKeys[len(m.PubKeys)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Levels", wireType) } @@ -598,7 +557,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { } m.Levels[mapkey] = mapvalue iNdEx = postIndex - case 4: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) } diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 2f1c2466e..61ef33126 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -10,8 +10,7 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderSigningProof { - SlashingType Type = 1; - repeated bytes PubKeys = 2; - map Levels = 3; - map HeadersInfo = 4 [(gogoproto.nullable) = false]; + repeated bytes PubKeys = 1; + map Levels = 2; + map HeadersInfo = 3 [(gogoproto.nullable) = false]; } From af274522ab439efc8f460452af8280d735289321 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 2 Nov 2021 12:43:56 +0200 Subject: [PATCH 16/54] FEAT: Add proof tests --- data/block/headerInfo.proto | 2 +- data/errors.go | 6 ++ data/slash/multipleHeaderProposalProof.go | 6 +- .../slash/multipleHeaderProposalProof_test.go | 69 +++++++++++++++++ data/slash/multipleHeaderSigningProof.go | 4 +- data/slash/multipleHeaderSigningProof.proto | 6 +- data/slash/multipleHeaderSigningProof_test.go | 75 +++++++++++++++++++ 7 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 data/slash/multipleHeaderProposalProof_test.go create mode 100644 data/slash/multipleHeaderSigningProof_test.go diff --git a/data/block/headerInfo.proto b/data/block/headerInfo.proto index 358ba29c6..47b37954e 100644 --- a/data/block/headerInfo.proto +++ b/data/block/headerInfo.proto @@ -15,4 +15,4 @@ message HeaderInfo { message HeaderInfoList{ repeated HeaderInfo Headers = 1; -} \ No newline at end of file +} diff --git a/data/errors.go b/data/errors.go index 048aeac46..1a9668309 100644 --- a/data/errors.go +++ b/data/errors.go @@ -78,3 +78,9 @@ var ErrScheduledRootHashNotSupported = errors.New("scheduled root hash is not su // ErrWrongTransactionsTypeSize signals that size of transactions type buffer from mini block reserved field is wrong var ErrWrongTransactionsTypeSize = errors.New("wrong transactions type size") + +// ErrNilSlashResult signals that a nil slash result has been provided +var ErrNilSlashResult = errors.New("slash result is nil") + +// ErrNilHeaderHandler signals that a nil header handler has been provided +var ErrNilHeaderHandler = errors.New("nil header handler") diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index d34ee6bbb..ed6f49f4b 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -17,7 +17,7 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { if m == nil { return nil } - ret := make([]data.HeaderInfoHandler, len(m.HeadersInfo.Headers)) + ret := make([]data.HeaderInfoHandler, 0, len(m.HeadersInfo.Headers)) for _, headerInfo := range m.HeadersInfo.GetHeaders() { ret = append(ret, headerInfo) @@ -28,10 +28,10 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProofHandler, error) { if slashResult == nil { - return nil, nil //process.ErrNilSlashResult + return nil, data.ErrNilSlashResult } if slashResult.Headers == nil { - return nil, nil //process.ErrNilHeaderHandler + return nil, data.ErrNilHeaderHandler } headersInfo := block.HeaderInfoList{} diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go new file mode 100644 index 000000000..e00532426 --- /dev/null +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -0,0 +1,69 @@ +package slash_test + +import ( + "fmt" + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/stretchr/testify/require" +) + +func TestNewMultipleProposalProof(t *testing.T) { + tests := []struct { + args func() *slash.SlashingResult + expectedErr error + }{ + { + args: func() *slash.SlashingResult { + return nil + }, + expectedErr: data.ErrNilSlashResult, + }, + { + args: func() *slash.SlashingResult { + return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: nil} + }, + expectedErr: data.ErrNilHeaderHandler, + }, + { + args: func() *slash.SlashingResult { + return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{}} + }, + expectedErr: nil, + }, + } + + for _, currTest := range tests { + _, err := slash.NewMultipleProposalProof(currTest.args()) + require.Equal(t, currTest.expectedErr, err) + } +} + +func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { + h1 := &block.HeaderInfo{ + Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 1}}, + Hash: []byte("h1"), + } + h2 := &block.HeaderInfo{ + Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 2}}, + Hash: []byte("h2"), + } + + slashRes := &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{h1, h2}} + + proof, err := slash.NewMultipleProposalProof(slashRes) + require.Nil(t, err) + + require.Equal(t, slash.MultipleProposal, proof.GetType()) + require.Equal(t, slash.Medium, proof.GetLevel()) + + x := proof.GetHeaders() + fmt.Println(len(x)) + require.Len(t, proof.GetHeaders(), 2) + require.Contains(t, proof.GetHeaders(), h1) + require.Contains(t, proof.GetHeaders(), h2) +} diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index eda640b61..91327b95c 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -36,7 +36,7 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderInfo return nil } - ret := make([]data.HeaderInfoHandler, len(headersInfo.Headers)) + ret := make([]data.HeaderInfoHandler, 0, len(headersInfo.Headers)) for _, headerInfo := range headersInfo.GetHeaders() { ret = append(ret, headerInfo) } @@ -46,7 +46,7 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderInfo func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSigningProofHandler, error) { if slashResult == nil { - return nil, nil //process.ErrNilSlashResult + return nil, data.ErrNilSlashResult } pubKeys := make([][]byte, 0, len(slashResult)) diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 61ef33126..104e356b9 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -10,7 +10,7 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderSigningProof { - repeated bytes PubKeys = 1; - map Levels = 2; - map HeadersInfo = 3 [(gogoproto.nullable) = false]; + repeated bytes PubKeys = 1; + map Levels = 2; + map HeadersInfo = 3 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go new file mode 100644 index 000000000..cc128bb1a --- /dev/null +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -0,0 +1,75 @@ +package slash_test + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/stretchr/testify/require" +) + +func TestNewMultipleSigningProof(t *testing.T) { + tests := []struct { + args func() map[string]slash.SlashingResult + expectedErr error + }{ + { + args: func() map[string]slash.SlashingResult { + return nil + }, + expectedErr: data.ErrNilSlashResult, + }, + { + args: func() map[string]slash.SlashingResult { + return make(map[string]slash.SlashingResult) + }, + expectedErr: nil, + }, + } + + for _, currTest := range tests { + _, err := slash.NewMultipleSigningProof(currTest.args()) + require.Equal(t, currTest.expectedErr, err) + } +} + +func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { + h1 := &block.HeaderInfo{ + Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 1}}, + Hash: []byte("h1"), + } + h2 := &block.HeaderInfo{ + Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 2}}, + Hash: []byte("h2"), + } + + slashRes1 := slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{h1}, + } + slashRes2 := slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{h2}, + } + slashRes := map[string]slash.SlashingResult{ + "pubKey1": slashRes1, + "pubKey2": slashRes2, + } + + proof, err := slash.NewMultipleSigningProof(slashRes) + require.Nil(t, err) + + require.Equal(t, slash.MultipleSigning, proof.GetType()) + require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey1"))) + require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey2"))) + require.Equal(t, slash.Low, proof.GetLevel([]byte("pubKey3"))) + + require.Len(t, proof.GetHeaders([]byte("pubKey1")), 1) + require.Len(t, proof.GetHeaders([]byte("pubKey2")), 1) + require.Len(t, proof.GetHeaders([]byte("pubKey3")), 0) + + require.Contains(t, proof.GetHeaders([]byte("pubKey1")), h1) + require.Contains(t, proof.GetHeaders([]byte("pubKey2")), h2) + require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) +} From 6fd6c79d6574f8074e367f49f08ddcca2a393bac Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 2 Nov 2021 13:47:34 +0200 Subject: [PATCH 17/54] FEAT: Add new header info constructor --- data/block/headerInfo.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/data/block/headerInfo.go b/data/block/headerInfo.go index b8369635d..4df3c4654 100644 --- a/data/block/headerInfo.go +++ b/data/block/headerInfo.go @@ -3,6 +3,18 @@ package block import "github.com/ElrondNetwork/elrond-go-core/data" +func NewHeaderInfo(header data.HeaderHandler, hash []byte) (data.HeaderInfoHandler, error) { + hdr, castOk := header.(*HeaderV2) + if !castOk { + return nil, data.ErrInvalidHeaderType + } + + return &HeaderInfo{ + Header: hdr, + Hash: hash, + }, nil +} + func (m *HeaderInfo) GetHeaderHandler() data.HeaderHandler { if m == nil { return nil From 5241ebcf8a85f3020167880d0d5d16ab59244171 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 3 Nov 2021 14:18:22 +0200 Subject: [PATCH 18/54] FIX: Refactor proofs to only use data heandler, remove header info --- data/block/headerInfo.go | 43 -- data/block/headerInfo.pb.go | 685 ------------------ data/block/headerInfo.proto | 18 - data/slash/common.go | 2 +- data/slash/interface.go | 4 +- data/slash/multipleHeaderProposalProof.go | 19 +- data/slash/multipleHeaderProposalProof.pb.go | 62 +- data/slash/multipleHeaderProposalProof.proto | 5 +- .../slash/multipleHeaderProposalProof_test.go | 14 +- data/slash/multipleHeaderSigningProof.go | 24 +- data/slash/multipleHeaderSigningProof.pb.go | 144 ++-- data/slash/multipleHeaderSigningProof.proto | 7 +- data/slash/multipleHeaderSigningProof_test.go | 14 +- data/slash/slash.go | 36 + data/slash/slash.pb.go | 396 +++++++++- data/slash/slash.proto | 4 + data/slash/slash_test.go | 44 ++ 17 files changed, 594 insertions(+), 927 deletions(-) delete mode 100644 data/block/headerInfo.go delete mode 100644 data/block/headerInfo.pb.go delete mode 100644 data/block/headerInfo.proto diff --git a/data/block/headerInfo.go b/data/block/headerInfo.go deleted file mode 100644 index 4df3c4654..000000000 --- a/data/block/headerInfo.go +++ /dev/null @@ -1,43 +0,0 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. headerInfo.proto -package block - -import "github.com/ElrondNetwork/elrond-go-core/data" - -func NewHeaderInfo(header data.HeaderHandler, hash []byte) (data.HeaderInfoHandler, error) { - hdr, castOk := header.(*HeaderV2) - if !castOk { - return nil, data.ErrInvalidHeaderType - } - - return &HeaderInfo{ - Header: hdr, - Hash: hash, - }, nil -} - -func (m *HeaderInfo) GetHeaderHandler() data.HeaderHandler { - if m == nil { - return nil - } - - return m.Header -} - -func (m *HeaderInfoList) SetHeadersInfo(headers []data.HeaderInfoHandler) error { - if m == nil { - return data.ErrNilPointerReceiver - } - - m.Headers = nil - for _, header := range headers { - headerHandler := header.GetHeaderHandler() - hdr, castOk := headerHandler.(*HeaderV2) - if !castOk { - return data.ErrInvalidTypeAssertion - } - - m.Headers = append(m.Headers, &HeaderInfo{Header: hdr, Hash: header.GetHash()}) - } - - return nil -} diff --git a/data/block/headerInfo.pb.go b/data/block/headerInfo.pb.go deleted file mode 100644 index babcfbbe8..000000000 --- a/data/block/headerInfo.pb.go +++ /dev/null @@ -1,685 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: headerInfo.proto - -package block - -import ( - bytes "bytes" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" -) - -// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type HeaderInfo struct { - Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - Hash []byte `protobuf:"bytes,2,opt,name=Hash,proto3" json:"Hash,omitempty"` -} - -func (m *HeaderInfo) Reset() { *m = HeaderInfo{} } -func (*HeaderInfo) ProtoMessage() {} -func (*HeaderInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_f4bbbba9a375b11e, []int{0} -} -func (m *HeaderInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeaderInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *HeaderInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeaderInfo.Merge(m, src) -} -func (m *HeaderInfo) XXX_Size() int { - return m.Size() -} -func (m *HeaderInfo) XXX_DiscardUnknown() { - xxx_messageInfo_HeaderInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_HeaderInfo proto.InternalMessageInfo - -func (m *HeaderInfo) GetHeader() *HeaderV2 { - if m != nil { - return m.Header - } - return nil -} - -func (m *HeaderInfo) GetHash() []byte { - if m != nil { - return m.Hash - } - return nil -} - -type HeaderInfoList struct { - Headers []*HeaderInfo `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` -} - -func (m *HeaderInfoList) Reset() { *m = HeaderInfoList{} } -func (*HeaderInfoList) ProtoMessage() {} -func (*HeaderInfoList) Descriptor() ([]byte, []int) { - return fileDescriptor_f4bbbba9a375b11e, []int{1} -} -func (m *HeaderInfoList) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeaderInfoList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *HeaderInfoList) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeaderInfoList.Merge(m, src) -} -func (m *HeaderInfoList) XXX_Size() int { - return m.Size() -} -func (m *HeaderInfoList) XXX_DiscardUnknown() { - xxx_messageInfo_HeaderInfoList.DiscardUnknown(m) -} - -var xxx_messageInfo_HeaderInfoList proto.InternalMessageInfo - -func (m *HeaderInfoList) GetHeaders() []*HeaderInfo { - if m != nil { - return m.Headers - } - return nil -} - -func init() { - proto.RegisterType((*HeaderInfo)(nil), "proto.HeaderInfo") - proto.RegisterType((*HeaderInfoList)(nil), "proto.HeaderInfoList") -} - -func init() { proto.RegisterFile("headerInfo.proto", fileDescriptor_f4bbbba9a375b11e) } - -var fileDescriptor_f4bbbba9a375b11e = []byte{ - // 237 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x48, 0x4d, 0x4c, - 0x49, 0x2d, 0xf2, 0xcc, 0x4b, 0xcb, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, - 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 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x02, 0x00, 0x00, 0xff, 0xff, 0xf2, 0x31, 0x64, 0xd8, 0x2a, 0x01, 0x00, 0x00, -} - -func (this *HeaderInfo) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HeaderInfo) - if !ok { - that2, ok := that.(HeaderInfo) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Header.Equal(that1.Header) { - return false - } - if !bytes.Equal(this.Hash, that1.Hash) { - return false - } - return true -} -func (this *HeaderInfoList) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HeaderInfoList) - if !ok { - that2, ok := that.(HeaderInfoList) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Headers) != len(that1.Headers) { - return false - } - for i := range this.Headers { - if !this.Headers[i].Equal(that1.Headers[i]) { - return false - } - } - return true -} -func (this *HeaderInfo) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&block.HeaderInfo{") - if this.Header != nil { - s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") - } - s = append(s, "Hash: "+fmt.Sprintf("%#v", this.Hash)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *HeaderInfoList) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&block.HeaderInfoList{") - if this.Headers != nil { - s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringHeaderInfo(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *HeaderInfo) 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 *HeaderInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HeaderInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Hash) > 0 { - i -= len(m.Hash) - copy(dAtA[i:], m.Hash) - i = encodeVarintHeaderInfo(dAtA, i, uint64(len(m.Hash))) - i-- - dAtA[i] = 0x12 - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintHeaderInfo(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *HeaderInfoList) 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 *HeaderInfoList) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HeaderInfoList) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Headers) > 0 { - for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintHeaderInfo(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintHeaderInfo(dAtA []byte, offset int, v uint64) int { - offset -= sovHeaderInfo(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *HeaderInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovHeaderInfo(uint64(l)) - } - l = len(m.Hash) - if l > 0 { - n += 1 + l + sovHeaderInfo(uint64(l)) - } - return n -} - -func (m *HeaderInfoList) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Headers) > 0 { - for _, e := range m.Headers { - l = e.Size() - n += 1 + l + sovHeaderInfo(uint64(l)) - } - } - return n -} - -func sovHeaderInfo(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozHeaderInfo(x uint64) (n int) { - return sovHeaderInfo(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *HeaderInfo) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&HeaderInfo{`, - `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, - `Hash:` + fmt.Sprintf("%v", this.Hash) + `,`, - `}`, - }, "") - return s -} -func (this *HeaderInfoList) String() string { - if this == nil { - return "nil" - } - repeatedStringForHeaders := "[]*HeaderInfo{" - for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(f.String(), "HeaderInfo", "HeaderInfo", 1) + "," - } - repeatedStringForHeaders += "}" - s := strings.Join([]string{`&HeaderInfoList{`, - `Headers:` + repeatedStringForHeaders + `,`, - `}`, - }, "") - return s -} -func valueToStringHeaderInfo(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *HeaderInfo) 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 ErrIntOverflowHeaderInfo - } - 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: HeaderInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeaderInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthHeaderInfo - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthHeaderInfo - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &HeaderV2{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthHeaderInfo - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthHeaderInfo - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) - if m.Hash == nil { - m.Hash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHeaderInfo(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHeaderInfo - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHeaderInfo - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HeaderInfoList) 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 ErrIntOverflowHeaderInfo - } - 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: HeaderInfoList: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeaderInfoList: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthHeaderInfo - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthHeaderInfo - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Headers = append(m.Headers, &HeaderInfo{}) - if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHeaderInfo(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHeaderInfo - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHeaderInfo - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipHeaderInfo(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderInfo - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthHeaderInfo - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupHeaderInfo - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthHeaderInfo - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthHeaderInfo = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowHeaderInfo = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupHeaderInfo = fmt.Errorf("proto: unexpected end of group") -) diff --git a/data/block/headerInfo.proto b/data/block/headerInfo.proto deleted file mode 100644 index 47b37954e..000000000 --- a/data/block/headerInfo.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package proto; - -option go_package = "block"; -option (gogoproto.stable_marshaler_all) = true; - -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "blockV2.proto"; - -message HeaderInfo { - HeaderV2 Header = 1; - bytes Hash = 2; -} - -message HeaderInfoList{ - repeated HeaderInfo Headers = 1; -} diff --git a/data/slash/common.go b/data/slash/common.go index c33f5b396..7fa92237c 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -6,5 +6,5 @@ import "github.com/ElrondNetwork/elrond-go-core/data" // for a possible malicious validator type SlashingResult struct { SlashingLevel ThreatLevel - Headers []data.HeaderInfoHandler + Headers []data.HeaderHandler } diff --git a/data/slash/interface.go b/data/slash/interface.go index 9091991ee..091b7bc9c 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -17,7 +17,7 @@ type MultipleProposalProofHandler interface { // multiple colluding parties should have a higher level GetLevel() ThreatLevel //GetHeaders - returns the slashable proposed headers - GetHeaders() []data.HeaderInfoHandler + GetHeaders() []data.HeaderHandler } // MultipleSigningProofHandler contains proof data for a multiple header signing slashing event @@ -28,5 +28,5 @@ type MultipleSigningProofHandler interface { // GetLevel - returns the slashing level for a given validator GetLevel(pubKey []byte) ThreatLevel // GetHeaders - returns the slashable signed headers proposed by a given validator - GetHeaders(pubKey []byte) []data.HeaderInfoHandler + GetHeaders(pubKey []byte) []data.HeaderHandler } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index ed6f49f4b..cabd5f3f4 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -3,7 +3,6 @@ package slash import ( "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/block" ) func (m *MultipleHeaderProposalProof) GetType() SlashingType { @@ -13,17 +12,12 @@ func (m *MultipleHeaderProposalProof) GetType() SlashingType { return MultipleProposal } -func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderInfoHandler { +func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { if m == nil { return nil } - ret := make([]data.HeaderInfoHandler, 0, len(m.HeadersInfo.Headers)) - for _, headerInfo := range m.HeadersInfo.GetHeaders() { - ret = append(ret, headerInfo) - } - - return ret + return m.HeadersV2.GetHeaderHandlers() } func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProofHandler, error) { @@ -34,13 +28,14 @@ func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProo return nil, data.ErrNilHeaderHandler } - headersInfo := block.HeaderInfoList{} - err := headersInfo.SetHeadersInfo(slashResult.Headers) + headersV2 := HeadersV2{} + err := headersV2.SetHeaders(slashResult.Headers) if err != nil { return nil, err } + return &MultipleHeaderProposalProof{ - Level: slashResult.SlashingLevel, - HeadersInfo: headersInfo, + Level: slashResult.SlashingLevel, + HeadersV2: headersV2, }, nil } diff --git a/data/slash/multipleHeaderProposalProof.pb.go b/data/slash/multipleHeaderProposalProof.pb.go index 9b3f72761..d42b47a3b 100644 --- a/data/slash/multipleHeaderProposalProof.pb.go +++ b/data/slash/multipleHeaderProposalProof.pb.go @@ -5,7 +5,6 @@ package slash import ( fmt "fmt" - block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -27,8 +26,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderProposalProof struct { - Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` - HeadersInfo block.HeaderInfoList `protobuf:"bytes,2,opt,name=HeadersInfo,proto3" json:"HeadersInfo"` + Level ThreatLevel `protobuf:"varint,1,opt,name=Level,proto3,enum=proto.ThreatLevel" json:"Level,omitempty"` + HeadersV2 HeadersV2 `protobuf:"bytes,2,opt,name=HeadersV2,proto3" json:"HeadersV2"` } func (m *MultipleHeaderProposalProof) Reset() { *m = MultipleHeaderProposalProof{} } @@ -66,11 +65,11 @@ func (m *MultipleHeaderProposalProof) GetLevel() ThreatLevel { return Low } -func (m *MultipleHeaderProposalProof) GetHeadersInfo() block.HeaderInfoList { +func (m *MultipleHeaderProposalProof) GetHeadersV2() HeadersV2 { if m != nil { - return m.HeadersInfo + return m.HeadersV2 } - return block.HeaderInfoList{} + return HeadersV2{} } func init() { @@ -80,26 +79,23 @@ func init() { func init() { proto.RegisterFile("multipleHeaderProposalProof.proto", fileDescriptor_afe79f980fc6faed) } var fileDescriptor_afe79f980fc6faed = []byte{ - // 294 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xb1, 0x4b, 0xc3, 0x40, - 0x14, 0xc6, 0xef, 0x89, 0x75, 0x48, 0xc1, 0x21, 0x20, 0x94, 0x0a, 0xcf, 0xea, 0xd4, 0xa5, 0x3d, - 0xa8, 0xb3, 0x08, 0x15, 0xa1, 0x42, 0x95, 0x52, 0x9c, 0xdc, 0x2e, 0xed, 0x35, 0x29, 0xbd, 0xf6, - 0x85, 0xcb, 0x45, 0x57, 0x27, 0x67, 0xff, 0x0c, 0xff, 0x94, 0x8e, 0x19, 0x33, 0x89, 0xb9, 0x2c, - 0x8e, 0xfd, 0x13, 0xc4, 0x4b, 0x90, 0x2e, 0x4e, 0x77, 0xdf, 0xbb, 0xdf, 0x7d, 0xdf, 0xc7, 0xf3, - 0xce, 0xd7, 0xa9, 0x32, 0xcb, 0x58, 0xc9, 0x91, 0x14, 0x73, 0xa9, 0x27, 0x9a, 0x62, 0x4a, 0x84, - 0x9a, 0x68, 0xa2, 0x45, 0x3f, 0xd6, 0x64, 0xc8, 0x6f, 0xb8, 0xa3, 0xdd, 0x4c, 0x94, 0x48, 0xa2, - 0x6a, 0xd6, 0xee, 0x85, 0x4b, 0x13, 0xa5, 0x41, 0x7f, 0x46, 0x6b, 0x1e, 0x52, 0x48, 0xdc, 0x8d, - 0x83, 0x74, 0xe1, 0x94, 0x13, 0xee, 0x56, 0xe3, 0x37, 0x7b, 0xf8, 0xad, 0xd2, 0xb4, 0x99, 0x3f, - 0x48, 0xf3, 0x42, 0x7a, 0xc5, 0xa5, 0x53, 0xbd, 0x90, 0x7a, 0x33, 0xd2, 0x92, 0xcf, 0x85, 0x11, - 0x3c, 0x50, 0x34, 0x5b, 0xf1, 0xc8, 0x15, 0xba, 0xdb, 0x2c, 0x6a, 0x93, 0x8b, 0x37, 0xf0, 0x4e, - 0xef, 0xff, 0x6f, 0xeb, 0x77, 0xbd, 0xc6, 0x58, 0x3e, 0x4b, 0xd5, 0x82, 0x0e, 0x74, 0x8f, 0x07, - 0x7e, 0xf5, 0xad, 0xff, 0x18, 0x69, 0x29, 0x8c, 0x7b, 0x99, 0x56, 0x80, 0x7f, 0xe5, 0x35, 0x2b, - 0x83, 0xe4, 0xd7, 0xbe, 0x75, 0xd0, 0x81, 0x6e, 0x73, 0x70, 0x52, 0xf3, 0xa3, 0xbf, 0xdc, 0xf1, - 0x32, 0x31, 0xc3, 0xc3, 0xed, 0xe7, 0x19, 0x9b, 0xee, 0xf3, 0xc3, 0xeb, 0xac, 0x40, 0x96, 0x17, - 0xc8, 0x76, 0x05, 0xc2, 0xab, 0x45, 0xf8, 0xb0, 0x08, 0x5b, 0x8b, 0x90, 0x59, 0x84, 0xdc, 0x22, - 0x7c, 0x59, 0x84, 0x6f, 0x8b, 0x6c, 0x67, 0x11, 0xde, 0x4b, 0x64, 0x59, 0x89, 0x2c, 0x2f, 0x91, - 0x3d, 0x35, 0xdc, 0x0e, 0x83, 0x23, 0x97, 0x74, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x2e, - 0x85, 0x3a, 0x7d, 0x01, 0x00, 0x00, + // 241 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x2d, 0xcd, 0x29, + 0xc9, 0x2c, 0xc8, 0x49, 0xf5, 0x48, 0x4d, 0x4c, 0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0x96, + 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0xa7, 0x93, 0xd8, + 0xc0, 0x56, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x27, 0xc4, 0x81, 0x53, 0x2e, 0x01, 0x00, + 0x00, } func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { @@ -124,7 +120,7 @@ func (this *MultipleHeaderProposalProof) Equal(that interface{}) bool { if this.Level != that1.Level { return false } - if !this.HeadersInfo.Equal(&that1.HeadersInfo) { + if !this.HeadersV2.Equal(&that1.HeadersV2) { return false } return true @@ -136,7 +132,7 @@ func (this *MultipleHeaderProposalProof) GoString() string { s := make([]string, 0, 6) s = append(s, "&slash.MultipleHeaderProposalProof{") s = append(s, "Level: "+fmt.Sprintf("%#v", this.Level)+",\n") - s = append(s, "HeadersInfo: "+strings.Replace(this.HeadersInfo.GoString(), `&`, ``, 1)+",\n") + s = append(s, "HeadersV2: "+strings.Replace(this.HeadersV2.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -169,7 +165,7 @@ func (m *MultipleHeaderProposalProof) MarshalToSizedBuffer(dAtA []byte) (int, er var l int _ = l { - size, err := m.HeadersInfo.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.HeadersV2.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -206,7 +202,7 @@ func (m *MultipleHeaderProposalProof) Size() (n int) { if m.Level != 0 { n += 1 + sovMultipleHeaderProposalProof(uint64(m.Level)) } - l = m.HeadersInfo.Size() + l = m.HeadersV2.Size() n += 1 + l + sovMultipleHeaderProposalProof(uint64(l)) return n } @@ -223,7 +219,7 @@ func (this *MultipleHeaderProposalProof) String() string { } s := strings.Join([]string{`&MultipleHeaderProposalProof{`, `Level:` + fmt.Sprintf("%v", this.Level) + `,`, - `HeadersInfo:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersInfo), "HeaderInfoList", "block.HeaderInfoList", 1), `&`, ``, 1) + `,`, + `HeadersV2:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersV2), "HeadersV2", "HeadersV2", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -286,7 +282,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { } case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HeadersV2", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -313,7 +309,7 @@ func (m *MultipleHeaderProposalProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.HeadersInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.HeadersV2.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/data/slash/multipleHeaderProposalProof.proto b/data/slash/multipleHeaderProposalProof.proto index c0048e5d5..fff01db84 100644 --- a/data/slash/multipleHeaderProposalProof.proto +++ b/data/slash/multipleHeaderProposalProof.proto @@ -7,9 +7,8 @@ option (gogoproto.stable_marshaler_all) = true; import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderProposalProof { - ThreatLevel Level = 1; - HeaderInfoList HeadersInfo = 2 [(gogoproto.nullable) = false]; + ThreatLevel Level = 1; + HeadersV2 HeadersV2 = 2 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index e00532426..c33cbeecd 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -29,7 +29,7 @@ func TestNewMultipleProposalProof(t *testing.T) { }, { args: func() *slash.SlashingResult { - return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{}} + return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderHandler{}} }, expectedErr: nil, }, @@ -42,18 +42,12 @@ func TestNewMultipleProposalProof(t *testing.T) { } func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { - h1 := &block.HeaderInfo{ - Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 1}}, - Hash: []byte("h1"), - } - h2 := &block.HeaderInfo{ - Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 2}}, - Hash: []byte("h2"), - } + h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} slashRes := &slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{h1, h2}} + Headers: []data.HeaderHandler{h1, h2}} proof, err := slash.NewMultipleProposalProof(slashRes) require.Nil(t, err) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 91327b95c..b250fd291 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -3,7 +3,6 @@ package slash import ( "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/block" ) func (m *MultipleHeaderSigningProof) GetType() SlashingType { @@ -26,22 +25,17 @@ func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { return level } -func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderInfoHandler { +func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHandler { if m == nil { return nil } - headersInfo, exist := m.HeadersInfo[string(pubKey)] + headersV2, exist := m.HeadersV2[string(pubKey)] if !exist { return nil } - ret := make([]data.HeaderInfoHandler, 0, len(headersInfo.Headers)) - for _, headerInfo := range headersInfo.GetHeaders() { - ret = append(ret, headerInfo) - } - - return ret + return headersV2.GetHeaderHandlers() } func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSigningProofHandler, error) { @@ -51,14 +45,14 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig pubKeys := make([][]byte, 0, len(slashResult)) levels := make(map[string]ThreatLevel, len(slashResult)) - headers := make(map[string]block.HeaderInfoList, len(slashResult)) + headers := make(map[string]HeadersV2, len(slashResult)) for pubKey, res := range slashResult { pubKeys = append(pubKeys, []byte(pubKey)) levels[pubKey] = res.SlashingLevel - tmp := block.HeaderInfoList{} - err := tmp.SetHeadersInfo(res.Headers) + tmp := HeadersV2{} + err := tmp.SetHeaders(res.Headers) if err != nil { return nil, err } @@ -66,8 +60,8 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig } return &MultipleHeaderSigningProof{ - PubKeys: pubKeys, - Levels: levels, - HeadersInfo: headers, + PubKeys: pubKeys, + Levels: levels, + HeadersV2: headers, }, nil } diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 6376150ac..664e30dce 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -6,7 +6,6 @@ package slash import ( bytes "bytes" fmt "fmt" - block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" @@ -29,9 +28,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MultipleHeaderSigningProof struct { - PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - HeadersInfo map[string]block.HeaderInfoList `protobuf:"bytes,3,rep,name=HeadersInfo,proto3" json:"HeadersInfo" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` + Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` + HeadersV2 map[string]HeadersV2 `protobuf:"bytes,3,rep,name=HeadersV2,proto3" json:"HeadersV2" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } @@ -76,48 +75,45 @@ func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { return nil } -func (m *MultipleHeaderSigningProof) GetHeadersInfo() map[string]block.HeaderInfoList { +func (m *MultipleHeaderSigningProof) GetHeadersV2() map[string]HeadersV2 { if m != nil { - return m.HeadersInfo + return m.HeadersV2 } return nil } func init() { proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") - proto.RegisterMapType((map[string]block.HeaderInfoList)(nil), "proto.MultipleHeaderSigningProof.HeadersInfoEntry") + proto.RegisterMapType((map[string]HeadersV2)(nil), "proto.MultipleHeaderSigningProof.HeadersV2Entry") proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") } func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 389 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6a, 0xa3, 0x40, - 0x1c, 0xc6, 0x1d, 0xdd, 0x64, 0xd9, 0x71, 0x59, 0x82, 0xb0, 0x20, 0x1e, 0x66, 0x65, 0x4f, 0xc2, - 0xa2, 0x82, 0x7b, 0x59, 0xf6, 0x52, 0x48, 0x09, 0xa4, 0x34, 0x29, 0xc1, 0xb6, 0x97, 0xdc, 0x34, - 0x99, 0xa8, 0xc4, 0x38, 0x61, 0x1c, 0x53, 0x72, 0xeb, 0x23, 0xf4, 0x31, 0xfa, 0x28, 0x39, 0xe6, - 0x98, 0x53, 0x69, 0x26, 0x97, 0x1e, 0xf3, 0x06, 0x2d, 0x19, 0x6d, 0x91, 0xd2, 0xd0, 0x93, 0xff, - 0xef, 0xcf, 0xf7, 0xff, 0x7d, 0x1f, 0x32, 0xd0, 0x9c, 0x15, 0x29, 0x4b, 0xe6, 0x29, 0xee, 0xe2, - 0x60, 0x8c, 0xe9, 0x65, 0x12, 0x65, 0x49, 0x16, 0x0d, 0x28, 0x21, 0x13, 0x67, 0x4e, 0x09, 0x23, - 0x5a, 0x43, 0x7c, 0x0c, 0x35, 0x4f, 0x83, 0x3c, 0x2e, 0x77, 0x86, 0x1d, 0x25, 0x2c, 0x2e, 0x42, - 0x67, 0x44, 0x66, 0x6e, 0x44, 0x22, 0xe2, 0x8a, 0x75, 0x58, 0x4c, 0x84, 0x12, 0x42, 0x4c, 0x95, - 0xfd, 0xb4, 0x66, 0xef, 0xa4, 0x94, 0x64, 0xe3, 0x0b, 0xcc, 0x6e, 0x08, 0x9d, 0xba, 0x58, 0x28, - 0x3b, 0x22, 0xf6, 0x88, 0x50, 0xec, 0x8e, 0x03, 0x16, 0xb8, 0x61, 0x4a, 0x46, 0x53, 0x37, 0x16, - 0x7d, 0xce, 0xb2, 0x49, 0x05, 0xf9, 0xfd, 0x2c, 0x43, 0xa3, 0x7f, 0xb4, 0xac, 0xa6, 0xc3, 0xaf, - 0x83, 0x22, 0x3c, 0xc7, 0xcb, 0x5c, 0x07, 0xa6, 0x62, 0x7d, 0xf7, 0x5f, 0xa5, 0xd6, 0x81, 0xcd, - 0x1e, 0x5e, 0xe0, 0x34, 0xd7, 0x65, 0x53, 0xb1, 0x54, 0xcf, 0x2e, 0x81, 0xce, 0x71, 0x98, 0x53, - 0xfa, 0x3b, 0x19, 0xa3, 0x4b, 0xbf, 0x3a, 0xd6, 0x86, 0x50, 0x2d, 0x9d, 0xf9, 0xa1, 0x94, 0xae, - 0x08, 0x96, 0xf7, 0x39, 0xab, 0x76, 0x24, 0x80, 0xed, 0x2f, 0xab, 0x87, 0x5f, 0x92, 0x5f, 0x87, - 0x19, 0x7d, 0xa8, 0xd6, 0x22, 0xb5, 0x16, 0x54, 0xa6, 0x78, 0xa9, 0x03, 0x13, 0x58, 0xdf, 0xfc, - 0xc3, 0xa8, 0x59, 0xb0, 0xb1, 0x08, 0xd2, 0x02, 0xeb, 0xb2, 0x09, 0xac, 0x1f, 0x9e, 0x56, 0xc5, - 0x5e, 0xc5, 0x14, 0x07, 0x4c, 0x9c, 0xfa, 0xa5, 0xe1, 0xbf, 0xfc, 0x0f, 0x18, 0xd7, 0xb0, 0xf5, - 0x3e, 0xf5, 0x03, 0xe6, 0x9f, 0x3a, 0x53, 0xf5, 0x7e, 0x56, 0xcc, 0xee, 0xdb, 0x8f, 0xef, 0x25, - 0x39, 0xab, 0x61, 0xdb, 0x27, 0xeb, 0x2d, 0x92, 0x36, 0x5b, 0x24, 0xed, 0xb7, 0x08, 0xdc, 0x72, - 0x04, 0xee, 0x39, 0x02, 0x2b, 0x8e, 0xc0, 0x9a, 0x23, 0xb0, 0xe1, 0x08, 0x3c, 0x72, 0x04, 0x9e, - 0x38, 0x92, 0xf6, 0x1c, 0x81, 0xbb, 0x1d, 0x92, 0xd6, 0x3b, 0x24, 0x6d, 0x76, 0x48, 0x1a, 0x36, - 0xc4, 0xe3, 0x09, 0x9b, 0x22, 0xe1, 0xef, 0x4b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x19, 0xa3, - 0xbb, 0x75, 0x02, 0x00, 0x00, + // 341 bytes of a gzipped FileDescriptorProto + 0x1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0x01, 0x74, 0x76, 0xc3, 0x9c, 0x22, 0xdf, 0x1a, 0x66, 0xc9, 0xc4, 0x5b, + 0x97, 0x69, 0x97, 0x54, 0x8a, 0x64, 0x7a, 0xe3, 0x1a, 0x9a, 0x24, 0x1d, 0xfd, 0x4d, 0xda, 0x54, + 0x24, 0xac, 0xf9, 0x6f, 0xfa, 0xb2, 0xaf, 0x78, 0xdf, 0x20, 0xb3, 0x4d, 0xf4, 0xad, 0x31, 0x5a, + 0x23, 0xda, 0x03, 0x9b, 0x18, 0x60, 0x81, 0x5d, 0xf1, 0x3e, 0x4f, 0x6a, 0x93, 0xd2, 0xd8, 0x8f, + 0x73, 0x66, 0xa8, 0x16, 0xd8, 0x55, 0x97, 0xae, 0x27, 0xbb, 0xfd, 0x84, 0xf9, 0x99, 0xac, 0x7a, + 0x45, 0xe0, 0x54, 0x3d, 0x01, 0xf3, 0x8a, 0x54, 0x7f, 0x2e, 0xfe, 0x42, 0x3c, 0xdc, 0x26, 0xea, + 0x6e, 0x6d, 0x4d, 0xdc, 0xf4, 0xb6, 0x78, 0xcd, 0xb3, 0xd9, 0x02, 0x95, 0xf9, 0x02, 0x95, 0xd5, + 0x02, 0xe1, 0x51, 0x20, 0x3c, 0x0b, 0x84, 0xa9, 0x40, 0x98, 0x09, 0x84, 0xb9, 0x40, 0x78, 0x15, + 0x08, 0x6f, 0x02, 0x95, 0x95, 0x40, 0x78, 0x5a, 0xa2, 0x32, 0x5b, 0xa2, 0x32, 0x5f, 0xa2, 0x72, + 0x5b, 0x92, 0x5f, 0x1d, 0x94, 0x25, 0xfc, 0xf8, 0x23, 0x00, 0x00, 0xff, 0xff, 0x7e, 0x18, 0x86, + 0x2e, 0x23, 0x02, 0x00, 0x00, } func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { @@ -155,12 +151,12 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { return false } } - if len(this.HeadersInfo) != len(that1.HeadersInfo) { + if len(this.HeadersV2) != len(that1.HeadersV2) { return false } - for i := range this.HeadersInfo { - a := this.HeadersInfo[i] - b := that1.HeadersInfo[i] + for i := range this.HeadersV2 { + a := this.HeadersV2[i] + b := that1.HeadersV2[i] if !(&a).Equal(&b) { return false } @@ -187,18 +183,18 @@ func (this *MultipleHeaderSigningProof) GoString() string { if this.Levels != nil { s = append(s, "Levels: "+mapStringForLevels+",\n") } - keysForHeadersInfo := make([]string, 0, len(this.HeadersInfo)) - for k, _ := range this.HeadersInfo { - keysForHeadersInfo = append(keysForHeadersInfo, k) + keysForHeadersV2 := make([]string, 0, len(this.HeadersV2)) + for k, _ := range this.HeadersV2 { + keysForHeadersV2 = append(keysForHeadersV2, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) - mapStringForHeadersInfo := "map[string]block.HeaderInfoList{" - for _, k := range keysForHeadersInfo { - mapStringForHeadersInfo += fmt.Sprintf("%#v: %#v,", k, this.HeadersInfo[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) + mapStringForHeadersV2 := "map[string]HeadersV2{" + for _, k := range keysForHeadersV2 { + mapStringForHeadersV2 += fmt.Sprintf("%#v: %#v,", k, this.HeadersV2[k]) } - mapStringForHeadersInfo += "}" - if this.HeadersInfo != nil { - s = append(s, "HeadersInfo: "+mapStringForHeadersInfo+",\n") + mapStringForHeadersV2 += "}" + if this.HeadersV2 != nil { + s = append(s, "HeadersV2: "+mapStringForHeadersV2+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -231,14 +227,14 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l - if len(m.HeadersInfo) > 0 { - keysForHeadersInfo := make([]string, 0, len(m.HeadersInfo)) - for k := range m.HeadersInfo { - keysForHeadersInfo = append(keysForHeadersInfo, string(k)) + if len(m.HeadersV2) > 0 { + keysForHeadersV2 := make([]string, 0, len(m.HeadersV2)) + for k := range m.HeadersV2 { + keysForHeadersV2 = append(keysForHeadersV2, string(k)) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) - for iNdEx := len(keysForHeadersInfo) - 1; iNdEx >= 0; iNdEx-- { - v := m.HeadersInfo[string(keysForHeadersInfo[iNdEx])] + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) + for iNdEx := len(keysForHeadersV2) - 1; iNdEx >= 0; iNdEx-- { + v := m.HeadersV2[string(keysForHeadersV2[iNdEx])] baseI := i { size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) @@ -250,9 +246,9 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err } i-- dAtA[i] = 0x12 - i -= len(keysForHeadersInfo[iNdEx]) - copy(dAtA[i:], keysForHeadersInfo[iNdEx]) - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeadersInfo[iNdEx]))) + i -= len(keysForHeadersV2[iNdEx]) + copy(dAtA[i:], keysForHeadersV2[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeadersV2[iNdEx]))) i-- dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) @@ -325,8 +321,8 @@ func (m *MultipleHeaderSigningProof) Size() (n int) { n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) } } - if len(m.HeadersInfo) > 0 { - for k, v := range m.HeadersInfo { + if len(m.HeadersV2) > 0 { + for k, v := range m.HeadersV2 { _ = k _ = v l = v.Size() @@ -357,20 +353,20 @@ func (this *MultipleHeaderSigningProof) String() string { mapStringForLevels += fmt.Sprintf("%v: %v,", k, this.Levels[k]) } mapStringForLevels += "}" - keysForHeadersInfo := make([]string, 0, len(this.HeadersInfo)) - for k, _ := range this.HeadersInfo { - keysForHeadersInfo = append(keysForHeadersInfo, k) + keysForHeadersV2 := make([]string, 0, len(this.HeadersV2)) + for k, _ := range this.HeadersV2 { + keysForHeadersV2 = append(keysForHeadersV2, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersInfo) - mapStringForHeadersInfo := "map[string]block.HeaderInfoList{" - for _, k := range keysForHeadersInfo { - mapStringForHeadersInfo += fmt.Sprintf("%v: %v,", k, this.HeadersInfo[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) + mapStringForHeadersV2 := "map[string]HeadersV2{" + for _, k := range keysForHeadersV2 { + mapStringForHeadersV2 += fmt.Sprintf("%v: %v,", k, this.HeadersV2[k]) } - mapStringForHeadersInfo += "}" + mapStringForHeadersV2 += "}" s := strings.Join([]string{`&MultipleHeaderSigningProof{`, `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, `Levels:` + mapStringForLevels + `,`, - `HeadersInfo:` + mapStringForHeadersInfo + `,`, + `HeadersV2:` + mapStringForHeadersV2 + `,`, `}`, }, "") return s @@ -559,7 +555,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HeadersInfo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HeadersV2", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -586,11 +582,11 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.HeadersInfo == nil { - m.HeadersInfo = make(map[string]block.HeaderInfoList) + if m.HeadersV2 == nil { + m.HeadersV2 = make(map[string]HeadersV2) } var mapkey string - mapvalue := &block.HeaderInfoList{} + mapvalue := &HeadersV2{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -664,7 +660,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postmsgIndex > l { return io.ErrUnexpectedEOF } - mapvalue = &block.HeaderInfoList{} + mapvalue = &HeadersV2{} if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { return err } @@ -684,7 +680,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.HeadersInfo[mapkey] = *mapvalue + m.HeadersV2[mapkey] = *mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 104e356b9..6abf6234b 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -7,10 +7,9 @@ option (gogoproto.stable_marshaler_all) = true; import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/ElrondNetwork/elrond-go-core/data/block/headerInfo.proto"; message MultipleHeaderSigningProof { - repeated bytes PubKeys = 1; - map Levels = 2; - map HeadersInfo = 3 [(gogoproto.nullable) = false]; + repeated bytes PubKeys = 1; + map Levels = 2; + map HeadersV2 = 3 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index cc128bb1a..244a4556b 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -35,22 +35,16 @@ func TestNewMultipleSigningProof(t *testing.T) { } func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { - h1 := &block.HeaderInfo{ - Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 1}}, - Hash: []byte("h1"), - } - h2 := &block.HeaderInfo{ - Header: &block.HeaderV2{Header: &block.Header{TimeStamp: 2}}, - Hash: []byte("h2"), - } + h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} slashRes1 := slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{h1}, + Headers: []data.HeaderHandler{h1}, } slashRes2 := slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{h2}, + Headers: []data.HeaderHandler{h2}, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashRes1, diff --git a/data/slash/slash.go b/data/slash/slash.go index 8d3b8f339..a51622492 100644 --- a/data/slash/slash.go +++ b/data/slash/slash.go @@ -1,2 +1,38 @@ //go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. slash.proto package slash + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" +) + +func (m *HeadersV2) GetHeaderHandlers() []data.HeaderHandler { + if m == nil { + return nil + } + + ret := make([]data.HeaderHandler, 0, len(m.Headers)) + + for _, header := range m.Headers { + ret = append(ret, header) + } + + return ret +} + +func (m *HeadersV2) SetHeaders(headers []data.HeaderHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + for _, header := range headers { + hdr, castOk := header.(*block.HeaderV2) + if !castOk { + return data.ErrInvalidTypeAssertion + } + + m.Headers = append(m.Headers, hdr) + } + + return nil +} diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go index c1a29fb97..3b0d453fa 100644 --- a/data/slash/slash.pb.go +++ b/data/slash/slash.pb.go @@ -5,10 +5,15 @@ package slash import ( fmt "fmt" + block "github.com/ElrondNetwork/elrond-go-core/data/block" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + io "io" math "math" + math_bits "math/bits" + reflect "reflect" strconv "strconv" + strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. @@ -70,31 +75,76 @@ func (ThreatLevel) EnumDescriptor() ([]byte, []int) { return fileDescriptor_7c4604f407d65f7b, []int{1} } +type HeadersV2 struct { + Headers []*block.HeaderV2 `protobuf:"bytes,1,rep,name=Headers,proto3" json:"Headers,omitempty"` +} + +func (m *HeadersV2) Reset() { *m = HeadersV2{} } +func (*HeadersV2) ProtoMessage() {} +func (*HeadersV2) Descriptor() ([]byte, []int) { + return fileDescriptor_7c4604f407d65f7b, []int{0} +} +func (m *HeadersV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeadersV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *HeadersV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeadersV2.Merge(m, src) +} +func (m *HeadersV2) XXX_Size() int { + return m.Size() +} +func (m *HeadersV2) XXX_DiscardUnknown() { + xxx_messageInfo_HeadersV2.DiscardUnknown(m) +} + +var xxx_messageInfo_HeadersV2 proto.InternalMessageInfo + +func (m *HeadersV2) GetHeaders() []*block.HeaderV2 { + if m != nil { + return m.Headers + } + return nil +} + func init() { proto.RegisterEnum("proto.SlashingType", SlashingType_name, SlashingType_value) proto.RegisterEnum("proto.ThreatLevel", ThreatLevel_name, ThreatLevel_value) + proto.RegisterType((*HeadersV2)(nil), "proto.HeadersV2") } func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } var fileDescriptor_7c4604f407d65f7b = []byte{ - // 246 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8f, 0xb1, 0x4e, 0xc3, 0x30, - 0x10, 0x86, 0x7d, 0x85, 0x16, 0x74, 0x45, 0xc2, 0x32, 0x4c, 0x0c, 0xf7, 0x00, 0x15, 0xb4, 0x03, - 0x0f, 0x80, 0x04, 0x0b, 0x43, 0x8b, 0x90, 0xda, 0x89, 0x2d, 0x01, 0xe3, 0x58, 0x72, 0x73, 0x51, - 0x12, 0x83, 0xd8, 0x78, 0x04, 0x1e, 0x83, 0x47, 0x61, 0xcc, 0x98, 0x91, 0x38, 0x0b, 0x63, 0x1f, - 0x01, 0xc5, 0x88, 0xe9, 0xee, 0xff, 0xa4, 0xfb, 0x74, 0x3f, 0x4e, 0x2b, 0x97, 0x54, 0xd9, 0xbc, - 0x28, 0xb9, 0x66, 0x35, 0x8e, 0xe3, 0xec, 0xc2, 0xd8, 0x3a, 0xf3, 0xe9, 0xfc, 0x91, 0xb7, 0x0b, - 0xc3, 0x86, 0x17, 0x11, 0xa7, 0xfe, 0x39, 0xa6, 0x18, 0xe2, 0xf6, 0x77, 0x35, 0xbb, 0xc1, 0xa3, - 0xf5, 0x20, 0xb1, 0xb9, 0xd9, 0xbc, 0x15, 0x5a, 0x1d, 0xe2, 0xfe, 0x1d, 0xe7, 0x5a, 0x0a, 0x75, - 0x8a, 0x72, 0xe5, 0x5d, 0x6d, 0x0b, 0xa7, 0xef, 0x4b, 0x2e, 0xb8, 0x4a, 0x9c, 0x04, 0x75, 0x82, - 0xc7, 0xff, 0x74, 0x6d, 0x4d, 0x6e, 0x73, 0x23, 0x47, 0xb3, 0x73, 0x9c, 0x6e, 0xb2, 0x52, 0x27, - 0xf5, 0x52, 0xbf, 0x68, 0xa7, 0x0e, 0x70, 0x6f, 0xc9, 0xaf, 0x52, 0x28, 0xc4, 0xc9, 0x4a, 0x3f, - 0x59, 0xbf, 0x95, 0x30, 0x88, 0x6f, 0xad, 0xc9, 0xe4, 0xe8, 0xfa, 0xaa, 0xe9, 0x48, 0xb4, 0x1d, - 0x89, 0x5d, 0x47, 0xf0, 0x1e, 0x08, 0x3e, 0x03, 0xc1, 0x57, 0x20, 0x68, 0x02, 0x41, 0x1b, 0x08, - 0xbe, 0x03, 0xc1, 0x4f, 0x20, 0xb1, 0x0b, 0x04, 0x1f, 0x3d, 0x89, 0xa6, 0x27, 0xd1, 0xf6, 0x24, - 0x1e, 0xc6, 0xb1, 0x6f, 0x3a, 0x89, 0xaf, 0x5f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x36, 0xcd, - 0x59, 0xff, 0xff, 0x00, 0x00, 0x00, + // 322 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x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f6, 0x06, 0x18, 0x73, 0x8b, 0xd8, 0xc7, 0xcc, 0xea, 0xe7, 0x32, 0x8b, 0x12, 0xc9, 0x1f, + 0x15, 0x26, 0x98, 0x7a, 0xd2, 0xa2, 0xf6, 0x11, 0x6b, 0xec, 0xd4, 0x61, 0x24, 0xe2, 0x28, 0x16, + 0x56, 0xa9, 0x75, 0xc9, 0xea, 0xa3, 0x50, 0x71, 0x2f, 0xeb, 0xf1, 0x57, 0x2e, 0xed, 0x1a, 0x2b, + 0xf7, 0x70, 0x6e, 0x11, 0x9b, 0xb1, 0x6a, 0x9f, 0x07, 0x51, 0x3e, 0xb3, 0xe8, 0x36, 0xb8, 0x1b, + 0x89, 0xd0, 0x2a, 0xdd, 0xdd, 0x2c, 0x56, 0x40, 0x96, 0x2b, 0x20, 0x9b, 0x15, 0xd0, 0x77, 0x0d, + 0xf4, 0x53, 0x03, 0xfd, 0xd2, 0x40, 0x17, 0x1a, 0xe8, 0x52, 0x03, 0xfd, 0xd6, 0x40, 0x7f, 0x34, + 0x90, 0x8d, 0x06, 0xfa, 0xb1, 0x06, 0xb2, 0x58, 0x03, 0x59, 0xae, 0x81, 0x3c, 0x57, 0xcc, 0xa6, + 0xfd, 0xaa, 0x19, 0xe6, 0xea, 0x37, 0x00, 0x00, 0xff, 0xff, 0xd2, 0x71, 0x90, 0x1c, 0x79, 0x01, + 0x00, 0x00, } func (x SlashingType) String() string { @@ -111,3 +161,315 @@ func (x ThreatLevel) String() string { } return strconv.Itoa(int(x)) } +func (this *HeadersV2) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HeadersV2) + if !ok { + that2, ok := that.(HeadersV2) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Headers) != len(that1.Headers) { + return false + } + for i := range this.Headers { + if !this.Headers[i].Equal(that1.Headers[i]) { + return false + } + } + return true +} +func (this *HeadersV2) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&slash.HeadersV2{") + if this.Headers != nil { + s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringSlash(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *HeadersV2) 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 *HeadersV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeadersV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Headers) > 0 { + for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSlash(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintSlash(dAtA []byte, offset int, v uint64) int { + offset -= sovSlash(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HeadersV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Headers) > 0 { + for _, e := range m.Headers { + l = e.Size() + n += 1 + l + sovSlash(uint64(l)) + } + } + return n +} + +func sovSlash(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSlash(x uint64) (n int) { + return sovSlash(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *HeadersV2) String() string { + if this == nil { + return "nil" + } + repeatedStringForHeaders := "[]*HeaderV2{" + for _, f := range this.Headers { + repeatedStringForHeaders += strings.Replace(fmt.Sprintf("%v", f), "HeaderV2", "block.HeaderV2", 1) + "," + } + repeatedStringForHeaders += "}" + s := strings.Join([]string{`&HeadersV2{`, + `Headers:` + repeatedStringForHeaders + `,`, + `}`, + }, "") + return s +} +func valueToStringSlash(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *HeadersV2) 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 ErrIntOverflowSlash + } + 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: HeadersV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeadersV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSlash + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSlash + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSlash + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Headers = append(m.Headers, &block.HeaderV2{}) + if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSlash(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSlash + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSlash + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSlash(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSlash + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSlash + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSlash + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSlash + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSlash = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSlash = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSlash = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/slash/slash.proto b/data/slash/slash.proto index ab648ceba..95333b21e 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -6,6 +6,7 @@ option go_package = "slash"; option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/block/blockV2.proto"; enum SlashingType { None = 0; @@ -19,3 +20,6 @@ enum ThreatLevel { High = 2; } +message HeadersV2{ + repeated HeaderV2 Headers = 1; +} diff --git a/data/slash/slash_test.go b/data/slash/slash_test.go index 01750522d..db7f71233 100644 --- a/data/slash/slash_test.go +++ b/data/slash/slash_test.go @@ -1 +1,45 @@ package slash_test + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/stretchr/testify/require" +) + +func TestHeaders_SetHeaders_InvalidHeaders_ExpectError(t *testing.T) { + header := &block.Header{TimeStamp: 1} + headers := slash.HeadersV2{} + + err := headers.SetHeaders([]data.HeaderHandler{header}) + require.Equal(t, data.ErrInvalidTypeAssertion, err) +} + +func TestHeaders_SetHeaders_GetHeaders_GetHeaderHandlers(t *testing.T) { + header1 := &block.HeaderV2{ + Header: &block.Header{ + TimeStamp: 1, + }, + } + header2 := &block.HeaderV2{ + Header: &block.Header{ + TimeStamp: 2, + }, + } + + headers := []data.HeaderHandler{header1, header2} + headersV2 := slash.HeadersV2{} + + err := headersV2.SetHeaders(headers) + require.Nil(t, err) + + require.Len(t, headersV2.GetHeaders(), 2) + require.Contains(t, headersV2.GetHeaders(), header1) + require.Contains(t, headersV2.GetHeaders(), header2) + + require.Len(t, headersV2.GetHeaderHandlers(), 2) + require.Contains(t, headersV2.GetHeaderHandlers(), header1) + require.Contains(t, headersV2.GetHeaderHandlers(), header2) +} From 30bedcccf643595f798b6e9e15515569741da705 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 5 Nov 2021 17:17:29 +0200 Subject: [PATCH 19/54] FEAT: Add IsIndexSetInBitmap + tests --- core/sliceUtil/sliceUtil.go | 14 ++++++++++++++ core/sliceUtil/sliceUtil_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/core/sliceUtil/sliceUtil.go b/core/sliceUtil/sliceUtil.go index 73b30b5f2..9b38f5d59 100644 --- a/core/sliceUtil/sliceUtil.go +++ b/core/sliceUtil/sliceUtil.go @@ -9,3 +9,17 @@ func TrimSliceSliceByte(in [][]byte) [][]byte { copy(ret, in) return ret } + +// IsIndexSetInBitmap - checks if a bit is set(1) in the given bitmap +func IsIndexSetInBitmap(index uint32, bitmap []byte) bool { + indexOutOfBounds := index >= uint32(len(bitmap))*8 + if indexOutOfBounds { + return false + } + + bytePos := index / 8 + byteInMap := bitmap[bytePos] + bitPos := index % 8 + mask := uint8(1 << bitPos) + return (byteInMap & mask) != 0 +} diff --git a/core/sliceUtil/sliceUtil_test.go b/core/sliceUtil/sliceUtil_test.go index 2e3d3f1ee..4ca4d0312 100644 --- a/core/sliceUtil/sliceUtil_test.go +++ b/core/sliceUtil/sliceUtil_test.go @@ -1,10 +1,12 @@ package sliceUtil_test import ( + "strconv" "testing" "github.com/ElrondNetwork/elrond-go-core/core/sliceUtil" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTrimSliceSliceByte_EmptyInputShouldDoNothing(t *testing.T) { @@ -49,3 +51,27 @@ func TestTrimSliceSliceByte_SliceAlreadyOkShouldDoNothing(t *testing.T) { assert.Equal(t, 2, len(input)) assert.Equal(t, 2, cap(input)) } + +func TestIsIndexSetInBitmap(t *testing.T) { + byte1Map, _ := strconv.ParseInt("11001101", 2, 9) + byte2Map, _ := strconv.ParseInt("00000101", 2, 9) + bitmap := []byte{byte(byte1Map), byte(byte2Map)} + + //Byte 1 + require.True(t, sliceUtil.IsIndexSetInBitmap(0, bitmap)) + require.False(t, sliceUtil.IsIndexSetInBitmap(1, bitmap)) + require.True(t, sliceUtil.IsIndexSetInBitmap(2, bitmap)) + require.True(t, sliceUtil.IsIndexSetInBitmap(3, bitmap)) + require.False(t, sliceUtil.IsIndexSetInBitmap(4, bitmap)) + require.False(t, sliceUtil.IsIndexSetInBitmap(5, bitmap)) + require.True(t, sliceUtil.IsIndexSetInBitmap(6, bitmap)) + require.True(t, sliceUtil.IsIndexSetInBitmap(7, bitmap)) + // Byte 2 + require.True(t, sliceUtil.IsIndexSetInBitmap(8, bitmap)) + require.False(t, sliceUtil.IsIndexSetInBitmap(9, bitmap)) + require.True(t, sliceUtil.IsIndexSetInBitmap(10, bitmap)) + + for i := uint32(11); i <= 100; i++ { + require.False(t, sliceUtil.IsIndexSetInBitmap(i, bitmap)) + } +} From 400edd5ac4ab5a686c739a8761570667052f3375 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 8 Nov 2021 12:27:02 +0200 Subject: [PATCH 20/54] FIX: Delete proto proof files --- data/slash/proof.go | 2 - data/slash/proof.pb.go | 361 ----------------------------------------- data/slash/proof.proto | 13 -- 3 files changed, 376 deletions(-) delete mode 100644 data/slash/proof.go delete mode 100644 data/slash/proof.pb.go delete mode 100644 data/slash/proof.proto diff --git a/data/slash/proof.go b/data/slash/proof.go deleted file mode 100644 index d031d1f0a..000000000 --- a/data/slash/proof.go +++ /dev/null @@ -1,2 +0,0 @@ -//go:generate protoc -I=. -I=$GOPATH/src/github.com/ElrondNetwork/elrond-go-core/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. proof.proto -package slash diff --git a/data/slash/proof.pb.go b/data/slash/proof.pb.go deleted file mode 100644 index 15ba202ff..000000000 --- a/data/slash/proof.pb.go +++ /dev/null @@ -1,361 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: proof.proto - -package slash - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" -) - -// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type Proof struct { - Type SlashingType `protobuf:"varint,1,opt,name=Type,proto3,enum=proto.SlashingType" json:"Type,omitempty"` -} - -func (m *Proof) Reset() { *m = Proof{} } -func (*Proof) ProtoMessage() {} -func (*Proof) Descriptor() ([]byte, []int) { - return fileDescriptor_473d204b28f447f0, []int{0} -} -func (m *Proof) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Proof) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *Proof) XXX_Merge(src proto.Message) { - xxx_messageInfo_Proof.Merge(m, src) -} -func (m *Proof) XXX_Size() int { - return m.Size() -} -func (m *Proof) XXX_DiscardUnknown() { - xxx_messageInfo_Proof.DiscardUnknown(m) -} - -var xxx_messageInfo_Proof proto.InternalMessageInfo - -func (m *Proof) GetType() SlashingType { - if m != nil { - return m.Type - } - return None -} - -func init() { - proto.RegisterType((*Proof)(nil), "proto.Proof") -} - -func init() { proto.RegisterFile("proof.proto", fileDescriptor_473d204b28f447f0) } - -var fileDescriptor_473d204b28f447f0 = []byte{ - // 187 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x28, 0xca, 0xcf, - 0x4f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xdc, 0xc5, 0x39, 0x89, - 0xc5, 0x19, 0x10, 0x31, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, - 0xfd, 0xf4, 0xfc, 0xf4, 0x7c, 0x7d, 0xb0, 0x70, 0x52, 0x69, 0x1a, 0x98, 0x07, 0xe6, 0x80, 0x59, - 0x10, 0xe5, 0x4a, 0x06, 0x5c, 0xac, 0x01, 0x20, 0x13, 0x85, 0xd4, 0xb9, 0x58, 0x42, 0x2a, 0x0b, - 0x52, 0x25, 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x84, 0x21, 0xd2, 0x7a, 0xc1, 0x20, 0x93, 0x33, - 0xf3, 0xd2, 0x41, 0x52, 0x41, 0x60, 0x05, 0x4e, 0xf6, 0x17, 0x1e, 0xca, 0x31, 0xdc, 0x78, 0x28, - 0xc7, 0xf0, 0xe1, 0xa1, 0x1c, 0x63, 0xc3, 0x23, 0x39, 0xc6, 0x15, 0x8f, 0xe4, 0x18, 0x4f, 0x3c, - 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc6, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x5f, - 0x3c, 0x92, 0x63, 0xf8, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, - 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x62, 0x05, 0xbb, 0x33, 0x89, 0x0d, 0x6c, 0xb4, 0x31, 0x20, 0x00, - 0x00, 0xff, 0xff, 0x54, 0x2c, 0xfb, 0x46, 0xcb, 0x00, 0x00, 0x00, -} - -func (this *Proof) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Proof) - if !ok { - that2, ok := that.(Proof) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Type != that1.Type { - return false - } - return true -} -func (this *Proof) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&slash.Proof{") - s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringProof(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *Proof) 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 *Proof) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Proof) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Type != 0 { - i = encodeVarintProof(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintProof(dAtA []byte, offset int, v uint64) int { - offset -= sovProof(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Proof) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != 0 { - n += 1 + sovProof(uint64(m.Type)) - } - return n -} - -func sovProof(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozProof(x uint64) (n int) { - return sovProof(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *Proof) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Proof{`, - `Type:` + fmt.Sprintf("%v", this.Type) + `,`, - `}`, - }, "") - return s -} -func valueToStringProof(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Proof) 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 ErrIntOverflowProof - } - 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: Proof: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Proof: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= SlashingType(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipProof(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthProof - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthProof - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipProof(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProof - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProof - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowProof - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthProof - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupProof - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthProof - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthProof = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowProof = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupProof = fmt.Errorf("proto: unexpected end of group") -) diff --git a/data/slash/proof.proto b/data/slash/proof.proto deleted file mode 100644 index 86688a46a..000000000 --- a/data/slash/proof.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -package proto; - -option go_package = "slash"; -option (gogoproto.stable_marshaler_all) = true; - -import "slash.proto"; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -message Proof { - SlashingType Type = 1; -} From 526cc84cbad5b2c7aef607b3f71aec7ff355e32f Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 12 Nov 2021 14:01:13 +0200 Subject: [PATCH 21/54] FIX: Review findings --- data/slash/multipleHeaderProposalProof.go | 3 +++ data/slash/multipleHeaderProposalProof_test.go | 3 --- data/slash/multipleHeaderSigningProof.go | 4 ++++ data/slash/slash.go | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index cabd5f3f4..ec974d792 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -5,6 +5,7 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) +// GetType returns MultipleProposal func (m *MultipleHeaderProposalProof) GetType() SlashingType { if m == nil { return None @@ -12,6 +13,7 @@ func (m *MultipleHeaderProposalProof) GetType() SlashingType { return MultipleProposal } +// GetHeaders returns all headers that have been proposed by a possible malicious validator func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { if m == nil { return nil @@ -20,6 +22,7 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { return m.HeadersV2.GetHeaderHandlers() } +// NewMultipleProposalProof returns a MultipleProposalProofHandler from a slashing result func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProofHandler, error) { if slashResult == nil { return nil, data.ErrNilSlashResult diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index c33cbeecd..ac2df7af7 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -1,7 +1,6 @@ package slash_test import ( - "fmt" "testing" "github.com/ElrondNetwork/elrond-go-core/data" @@ -55,8 +54,6 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Equal(t, slash.MultipleProposal, proof.GetType()) require.Equal(t, slash.Medium, proof.GetLevel()) - x := proof.GetHeaders() - fmt.Println(len(x)) require.Len(t, proof.GetHeaders(), 2) require.Contains(t, proof.GetHeaders(), h1) require.Contains(t, proof.GetHeaders(), h2) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index b250fd291..e0aa9ad8c 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -5,6 +5,7 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) +// GetType returns MultipleSigning func (m *MultipleHeaderSigningProof) GetType() SlashingType { if m == nil { return None @@ -12,6 +13,7 @@ func (m *MultipleHeaderSigningProof) GetType() SlashingType { return MultipleSigning } +// GetLevel returns the ThreatLevel of a possible malicious validator func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { if m == nil { return Low @@ -25,6 +27,7 @@ func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { return level } +// GetHeaders returns all headers that have been signed by a possible malicious validator func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHandler { if m == nil { return nil @@ -38,6 +41,7 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand return headersV2.GetHeaderHandlers() } +// NewMultipleSigningProof returns a MultipleSigningProofHandler from a slashing result func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSigningProofHandler, error) { if slashResult == nil { return nil, data.ErrNilSlashResult diff --git a/data/slash/slash.go b/data/slash/slash.go index a51622492..26fc76ced 100644 --- a/data/slash/slash.go +++ b/data/slash/slash.go @@ -6,6 +6,8 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data/block" ) +// GetHeaderHandlers returns a slice with all data.HeaderHandler. +// Used so we can work with interfaces instead of defined types func (m *HeadersV2) GetHeaderHandlers() []data.HeaderHandler { if m == nil { return nil @@ -20,6 +22,8 @@ func (m *HeadersV2) GetHeaderHandlers() []data.HeaderHandler { return ret } +// SetHeaders sets internal header structs to a given slice of data.HeaderHandler. +// Used so we can work with interfaces instead of defined types func (m *HeadersV2) SetHeaders(headers []data.HeaderHandler) error { if m == nil { return data.ErrNilPointerReceiver From ceda6519d71d37f50449ee43acb46fc855437e19 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 15 Nov 2021 14:36:55 +0200 Subject: [PATCH 22/54] FEAT: Add headers in proof always in the same order --- data/errors.go | 9 ++ data/mock/headerInfoStub.go | 16 ++++ data/slash/common.go | 48 +++++++++- data/slash/common_test.go | 80 ++++++++++++++++ data/slash/multipleHeaderProposalProof.go | 7 +- .../slash/multipleHeaderProposalProof_test.go | 69 +++++++++++--- data/slash/multipleHeaderSigningProof.go | 23 ++++- data/slash/multipleHeaderSigningProof_test.go | 95 +++++++++++++++++-- 8 files changed, 314 insertions(+), 33 deletions(-) create mode 100644 data/mock/headerInfoStub.go create mode 100644 data/slash/common_test.go diff --git a/data/errors.go b/data/errors.go index 1a9668309..ee756b056 100644 --- a/data/errors.go +++ b/data/errors.go @@ -84,3 +84,12 @@ var ErrNilSlashResult = errors.New("slash result is nil") // ErrNilHeaderHandler signals that a nil header handler has been provided var ErrNilHeaderHandler = errors.New("nil header handler") + +// ErrNilHeaderInfoList signals that a nil header info list has been provided +var ErrNilHeaderInfoList = errors.New("nil header info list") + +// ErrNilHeaderInfo signals that a nil header info has been provided +var ErrNilHeaderInfo = errors.New("nil header info") + +// ErrNilHash signals that a nil hash has been provided +var ErrNilHash = errors.New("nil hash provided") diff --git a/data/mock/headerInfoStub.go b/data/mock/headerInfoStub.go new file mode 100644 index 000000000..c45c5d230 --- /dev/null +++ b/data/mock/headerInfoStub.go @@ -0,0 +1,16 @@ +package mock + +import "github.com/ElrondNetwork/elrond-go-core/data" + +type HeaderInfoStub struct { + Header data.HeaderHandler + Hash []byte +} + +func (his *HeaderInfoStub) GetHeaderHandler() data.HeaderHandler { + return his.Header +} + +func (his *HeaderInfoStub) GetHash() []byte { + return his.Hash +} diff --git a/data/slash/common.go b/data/slash/common.go index 7fa92237c..ec8ba0eef 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -1,10 +1,54 @@ package slash -import "github.com/ElrondNetwork/elrond-go-core/data" +import ( + "sort" + + "github.com/ElrondNetwork/elrond-go-core/core/check" + "github.com/ElrondNetwork/elrond-go-core/data" +) // SlashingResult contains the slashable data as well as the severity(slashing level) // for a possible malicious validator type SlashingResult struct { SlashingLevel ThreatLevel - Headers []data.HeaderHandler + Headers []data.HeaderInfoHandler +} + +func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) { + if headersInfo == nil { + return HeadersV2{}, data.ErrNilHeaderInfoList + } + + sortHeadersByHash(headersInfo) + headers := make([]data.HeaderHandler, 0, len(headersInfo)) + for _, headerInfo := range headersInfo { + if headerInfo == nil { + return HeadersV2{}, data.ErrNilHeaderInfo + } + + headerHandler := headerInfo.GetHeaderHandler() + hash := headerInfo.GetHash() + if check.IfNil(headerHandler) { + return HeadersV2{}, data.ErrNilHeaderHandler + } + if hash == nil { + return HeadersV2{}, data.ErrNilHash + } + + headers = append(headers, headerHandler) + } + + headersV2 := HeadersV2{} + return headersV2, headersV2.SetHeaders(headers) +} + +func sortHeadersByHash(headersInfo []data.HeaderInfoHandler) { + sortFunc := func(i, j int) bool { + hash1 := string(headersInfo[i].GetHash()) + hash2 := string(headersInfo[j].GetHash()) + + return hash1 < hash2 + } + + sort.Slice(headersInfo, sortFunc) } diff --git a/data/slash/common_test.go b/data/slash/common_test.go new file mode 100644 index 000000000..f2f59c140 --- /dev/null +++ b/data/slash/common_test.go @@ -0,0 +1,80 @@ +package slash + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/mock" + "github.com/stretchr/testify/require" +) + +func TestGetSortedHeadersV2_NilHeaderInfoList_ExpectError(t *testing.T) { + sortedHeaders, err := getSortedHeadersV2(nil) + require.Equal(t, HeadersV2{}, sortedHeaders) + require.Equal(t, data.ErrNilHeaderInfoList, err) +} + +func TestGetSortedHeadersV2_NilHeaderInfo_ExpectError(t *testing.T) { + headerInfoList := []data.HeaderInfoHandler{nil} + sortedHeaders, err := getSortedHeadersV2(headerInfoList) + require.Equal(t, HeadersV2{}, sortedHeaders) + require.Equal(t, data.ErrNilHeaderInfo, err) +} + +func TestGetSortedHeadersV2_EmptyHeaderInfoList_ExpectEmptyResult(t *testing.T) { + sortedHeaders, err := getSortedHeadersV2([]data.HeaderInfoHandler{}) + require.Equal(t, HeadersV2{}, sortedHeaders) + require.Nil(t, err) +} + +func TestGetSortedHeadersV2_NilHeaderHandler_ExpectError(t *testing.T) { + headerInfo := &mock.HeaderInfoStub{ + Header: nil, + Hash: []byte("hash1"), + } + headerInfoList := []data.HeaderInfoHandler{headerInfo} + + sortedHeaders, err := getSortedHeadersV2(headerInfoList) + require.Equal(t, HeadersV2{}, sortedHeaders) + require.Equal(t, data.ErrNilHeaderHandler, err) +} + +func TestGetSortedHeadersV2_NilHash_ExpectError(t *testing.T) { + header := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + headerInfo := &mock.HeaderInfoStub{ + Header: header, + Hash: nil, + } + headerInfoList := []data.HeaderInfoHandler{headerInfo} + + sortedHeaders, err := getSortedHeadersV2(headerInfoList) + require.Equal(t, HeadersV2{}, sortedHeaders) + require.Equal(t, data.ErrNilHash, err) +} + +func TestGetSortedHeadersV2(t *testing.T) { + h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} + + hInfo1 := &mock.HeaderInfoStub{ + Header: h1, + Hash: []byte("h1"), + } + hInfo2 := &mock.HeaderInfoStub{ + Header: h2, + Hash: []byte("h2"), + } + hInfo3 := &mock.HeaderInfoStub{ + Header: h3, + Hash: []byte("h3"), + } + + headersInfo := []data.HeaderInfoHandler{hInfo3, hInfo1, hInfo2} + sortedHeaders, _ := getSortedHeadersV2(headersInfo) + + require.Equal(t, h1, sortedHeaders.Headers[0]) + require.Equal(t, h2, sortedHeaders.Headers[1]) + require.Equal(t, h3, sortedHeaders.Headers[2]) +} diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index ec974d792..01eece277 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -28,17 +28,16 @@ func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProo return nil, data.ErrNilSlashResult } if slashResult.Headers == nil { - return nil, data.ErrNilHeaderHandler + return nil, data.ErrNilHeaderInfoList } - headersV2 := HeadersV2{} - err := headersV2.SetHeaders(slashResult.Headers) + sortedHeaders, err := getSortedHeadersV2(slashResult.Headers) if err != nil { return nil, err } return &MultipleHeaderProposalProof{ Level: slashResult.SlashingLevel, - HeadersV2: headersV2, + HeadersV2: sortedHeaders, }, nil } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index ac2df7af7..65c6e5bc9 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -5,37 +5,37 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" + dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/ElrondNetwork/elrond-go-core/marshal" "github.com/stretchr/testify/require" ) func TestNewMultipleProposalProof(t *testing.T) { tests := []struct { - args func() *slash.SlashingResult + args *slash.SlashingResult expectedErr error }{ { - args: func() *slash.SlashingResult { - return nil - }, + args: nil, expectedErr: data.ErrNilSlashResult, }, { - args: func() *slash.SlashingResult { - return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: nil} - }, - expectedErr: data.ErrNilHeaderHandler, + args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: nil}, + expectedErr: data.ErrNilHeaderInfoList, }, { - args: func() *slash.SlashingResult { - return &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderHandler{}} - }, + args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{nil}}, + expectedErr: data.ErrNilHeaderInfo, + }, + { + args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{}}, expectedErr: nil, }, } for _, currTest := range tests { - _, err := slash.NewMultipleProposalProof(currTest.args()) + _, err := slash.NewMultipleProposalProof(currTest.args) require.Equal(t, currTest.expectedErr, err) } } @@ -44,9 +44,13 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} + hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + slashRes := &slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderHandler{h1, h2}} + Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + } proof, err := slash.NewMultipleProposalProof(slashRes) require.Nil(t, err) @@ -58,3 +62,42 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Contains(t, proof.GetHeaders(), h1) require.Contains(t, proof.GetHeaders(), h2) } + +func TestMultipleHeaderProposalProof_Marshal_Unmarshal(t *testing.T) { + h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1, LeaderSignature: []byte("sig1")}} + h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2, LeaderSignature: []byte("sig2")}} + + hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} + hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + + slashRes1 := &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + } + slashRes2 := &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{hInfo2, hInfo1}, + } + + proof1, err1 := slash.NewMultipleProposalProof(slashRes1) + proof2, err2 := slash.NewMultipleProposalProof(slashRes2) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1, proof2) + + marshaller := marshal.GogoProtoMarshalizer{} + proof1Bytes, err1 := marshaller.Marshal(proof1) + proof2Bytes, err2 := marshaller.Marshal(proof2) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1Bytes, proof2Bytes) + + proof1Unmarshalled := &slash.MultipleHeaderProposalProof{} + proof2Unmarshalled := &slash.MultipleHeaderProposalProof{} + err1 = marshaller.Unmarshal(proof1Unmarshalled, proof1Bytes) + err2 = marshaller.Unmarshal(proof2Unmarshalled, proof2Bytes) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1Unmarshalled, proof1) + require.Equal(t, proof2Unmarshalled, proof2) +} diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index e0aa9ad8c..6c5adb137 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -2,6 +2,8 @@ package slash import ( + "sort" + "github.com/ElrondNetwork/elrond-go-core/data" ) @@ -51,16 +53,16 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig levels := make(map[string]ThreatLevel, len(slashResult)) headers := make(map[string]HeadersV2, len(slashResult)) - for pubKey, res := range slashResult { + sortedPubKeys := getSortedPubKeys(slashResult) + for _, pubKey := range sortedPubKeys { pubKeys = append(pubKeys, []byte(pubKey)) - levels[pubKey] = res.SlashingLevel + levels[pubKey] = slashResult[pubKey].SlashingLevel - tmp := HeadersV2{} - err := tmp.SetHeaders(res.Headers) + sortedHeaders, err := getSortedHeadersV2(slashResult[pubKey].Headers) if err != nil { return nil, err } - headers[pubKey] = tmp + headers[pubKey] = sortedHeaders } return &MultipleHeaderSigningProof{ @@ -69,3 +71,14 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig HeadersV2: headers, }, nil } + +func getSortedPubKeys(slashResult map[string]SlashingResult) []string { + sortedPubKeys := make([]string, 0, len(slashResult)) + + for pubKey := range slashResult { + sortedPubKeys = append(sortedPubKeys, pubKey) + } + sort.Strings(sortedPubKeys) + + return sortedPubKeys +} diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 244a4556b..1b66d9d17 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -5,31 +5,41 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" + dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/ElrondNetwork/elrond-go-core/marshal" "github.com/stretchr/testify/require" ) func TestNewMultipleSigningProof(t *testing.T) { tests := []struct { - args func() map[string]slash.SlashingResult + args map[string]slash.SlashingResult expectedErr error }{ { - args: func() map[string]slash.SlashingResult { - return nil - }, + args: nil, expectedErr: data.ErrNilSlashResult, }, { - args: func() map[string]slash.SlashingResult { - return make(map[string]slash.SlashingResult) + args: map[string]slash.SlashingResult{ + "pubKey": {Headers: nil}, + }, + expectedErr: data.ErrNilHeaderInfoList, + }, + { + args: map[string]slash.SlashingResult{ + "pubKey": {Headers: []data.HeaderInfoHandler{nil}}, }, + expectedErr: data.ErrNilHeaderInfo, + }, + { + args: make(map[string]slash.SlashingResult), expectedErr: nil, }, } for _, currTest := range tests { - _, err := slash.NewMultipleSigningProof(currTest.args()) + _, err := slash.NewMultipleSigningProof(currTest.args) require.Equal(t, currTest.expectedErr, err) } } @@ -38,13 +48,16 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} + hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + slashRes1 := slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderHandler{h1}, + Headers: []data.HeaderInfoHandler{hInfo1}, } slashRes2 := slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderHandler{h2}, + Headers: []data.HeaderInfoHandler{hInfo2}, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashRes1, @@ -67,3 +80,67 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Contains(t, proof.GetHeaders([]byte("pubKey2")), h2) require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) } + +func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { + h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} + h4 := &block.HeaderV2{Header: &block.Header{TimeStamp: 4}} + + hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} + hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + hInfo3 := &dataMock.HeaderInfoStub{Header: h3, Hash: []byte("h3")} + hInfo4 := &dataMock.HeaderInfoStub{Header: h4, Hash: []byte("h4")} + + slashResPubKey1 := slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + } + slashResPubKey2 := slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{hInfo3, hInfo4}, + } + slashResProof1 := map[string]slash.SlashingResult{ + "pubKey1": slashResPubKey1, + "pubKey2": slashResPubKey2, + } + + // Same slash result for pubKey1, but change headers order + slashResPubKey1 = slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{hInfo2, hInfo1}, + } + // Same slash result for pubKey2, but change headers order + slashResPubKey2 = slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{hInfo4, hInfo3}, + } + + // Change pub keys order in map + slashResProof2 := map[string]slash.SlashingResult{ + "pubKey2": slashResPubKey2, + "pubKey1": slashResPubKey1, + } + + proof1, err1 := slash.NewMultipleSigningProof(slashResProof1) + proof2, err2 := slash.NewMultipleSigningProof(slashResProof2) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1, proof2) + + marshaller := marshal.GogoProtoMarshalizer{} + proof1Bytes, err1 := marshaller.Marshal(proof1) + proof2Bytes, err2 := marshaller.Marshal(proof2) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1Bytes, proof2Bytes) + + proof1Unmarshalled := &slash.MultipleHeaderSigningProof{} + proof2Unmarshalled := &slash.MultipleHeaderSigningProof{} + err1 = marshaller.Unmarshal(proof1Unmarshalled, proof1Bytes) + err2 = marshaller.Unmarshal(proof2Unmarshalled, proof2Bytes) + require.Nil(t, err1) + require.Nil(t, err2) + require.Equal(t, proof1Unmarshalled, proof1) + require.Equal(t, proof2Unmarshalled, proof2) +} From b76390dc7fe75392021973a87873f000ddc2e884 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 15 Nov 2021 15:44:51 +0200 Subject: [PATCH 23/54] FEAT: Add zero threat level + fix review findings --- .../slash/multipleHeaderProposalProof_test.go | 4 +- data/slash/multipleHeaderSigningProof.go | 4 +- data/slash/multipleHeaderSigningProof_test.go | 23 ++++--- data/slash/slash.pb.go | 65 ++++++++++--------- data/slash/slash.proto | 7 +- 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 65c6e5bc9..74cd62cf7 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -59,8 +59,8 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Equal(t, slash.Medium, proof.GetLevel()) require.Len(t, proof.GetHeaders(), 2) - require.Contains(t, proof.GetHeaders(), h1) - require.Contains(t, proof.GetHeaders(), h2) + require.Equal(t, proof.GetHeaders()[0], h1) + require.Equal(t, proof.GetHeaders()[1], h2) } func TestMultipleHeaderProposalProof_Marshal_Unmarshal(t *testing.T) { diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 6c5adb137..6648768dd 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -18,12 +18,12 @@ func (m *MultipleHeaderSigningProof) GetType() SlashingType { // GetLevel returns the ThreatLevel of a possible malicious validator func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { if m == nil { - return Low + return Zero } level, exists := m.Levels[string(pubKey)] if !exists { - return Low + return Zero } return level diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 1b66d9d17..265bedc9f 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -47,17 +47,19 @@ func TestNewMultipleSigningProof(t *testing.T) { func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + hInfo3 := &dataMock.HeaderInfoStub{Header: h3, Hash: []byte("h3")} slashRes1 := slash.SlashingResult{ - SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{hInfo1}, + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, } slashRes2 := slash.SlashingResult{ - SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{hInfo2}, + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{hInfo3}, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashRes1, @@ -68,16 +70,17 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Nil(t, err) require.Equal(t, slash.MultipleSigning, proof.GetType()) - require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey1"))) - require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey2"))) - require.Equal(t, slash.Low, proof.GetLevel([]byte("pubKey3"))) + require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey1"))) + require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey2"))) + require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey3"))) - require.Len(t, proof.GetHeaders([]byte("pubKey1")), 1) + require.Len(t, proof.GetHeaders([]byte("pubKey1")), 2) require.Len(t, proof.GetHeaders([]byte("pubKey2")), 1) require.Len(t, proof.GetHeaders([]byte("pubKey3")), 0) - require.Contains(t, proof.GetHeaders([]byte("pubKey1")), h1) - require.Contains(t, proof.GetHeaders([]byte("pubKey2")), h2) + require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[0], h1) + require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[1], h2) + require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[0], h3) require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) } diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go index 3b0d453fa..5293c6d0a 100644 --- a/data/slash/slash.pb.go +++ b/data/slash/slash.pb.go @@ -54,21 +54,24 @@ func (SlashingType) EnumDescriptor() ([]byte, []int) { type ThreatLevel int32 const ( - Low ThreatLevel = 0 - Medium ThreatLevel = 1 - High ThreatLevel = 2 + Zero ThreatLevel = 0 + Low ThreatLevel = 1 + Medium ThreatLevel = 2 + High ThreatLevel = 3 ) var ThreatLevel_name = map[int32]string{ - 0: "Low", - 1: "Medium", - 2: "High", + 0: "Zero", + 1: "Low", + 2: "Medium", + 3: "High", } var ThreatLevel_value = map[string]int32{ - "Low": 0, - "Medium": 1, - "High": 2, + "Zero": 0, + "Low": 1, + "Medium": 2, + "High": 3, } func (ThreatLevel) EnumDescriptor() ([]byte, []int) { @@ -123,28 +126,28 @@ func init() { func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } var fileDescriptor_7c4604f407d65f7b = []byte{ - // 322 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00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, 0x31, 0x7a, 0x4b, 0xb8, 0xbd, - 0xcf, 0xf6, 0x06, 0x18, 0x73, 0x8b, 0xd8, 0xc7, 0xcc, 0xea, 0xe7, 0x32, 0x8b, 0x12, 0xc9, 0x1f, - 0x15, 0x26, 0x98, 0x7a, 0xd2, 0xa2, 0xf6, 0x11, 0x6b, 0xec, 0xd4, 0x61, 0x24, 0xe2, 0x28, 0x16, - 0x56, 0xa9, 0x75, 0xc9, 0xea, 0xa3, 0x50, 0x71, 0x2f, 0xeb, 0xf1, 0x57, 0x2e, 0xed, 0x1a, 0x2b, - 0xf7, 0x70, 0x6e, 0x11, 0x9b, 0xb1, 0x6a, 0x9f, 0x07, 0x51, 0x3e, 0xb3, 0xe8, 0x36, 0xb8, 0x1b, - 0x89, 0xd0, 0x2a, 0xdd, 0xdd, 0x2c, 0x56, 0x40, 0x96, 0x2b, 0x20, 0x9b, 0x15, 0xd0, 0x77, 0x0d, - 0xf4, 0x53, 0x03, 0xfd, 0xd2, 0x40, 0x17, 0x1a, 0xe8, 0x52, 0x03, 0xfd, 0xd6, 0x40, 0x7f, 0x34, - 0x90, 0x8d, 0x06, 0xfa, 0xb1, 0x06, 0xb2, 0x58, 0x03, 0x59, 0xae, 0x81, 0x3c, 0x57, 0xcc, 0xa6, - 0xfd, 0xaa, 0x19, 0xe6, 0xea, 0x37, 0x00, 0x00, 0xff, 0xff, 0xd2, 0x71, 0x90, 0x1c, 0x79, 0x01, - 0x00, 0x00, + // 329 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x41, 0x4f, 0xfa, 0x30, + 0x18, 0xc6, 0x5b, 0xf8, 0x03, 0x7f, 0x8b, 0x09, 0xcd, 0xf4, 0x60, 0x38, 0xbc, 0x31, 0x9e, 0x94, + 0x04, 0x96, 0xcc, 0x84, 0xab, 0x46, 0x63, 0xc2, 0x01, 0x88, 0x11, 0xc2, 0x81, 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 0x5a, 0x5d, 0x56, 0x1f, 0x07, 0x4a, 0xb8, 0x59, 0x5f, 0xbc, 0x88, 0x68, 0xdf, + 0x31, 0x15, 0x0a, 0x39, 0xb1, 0x6a, 0xac, 0xdc, 0xc7, 0x25, 0xa7, 0x16, 0x63, 0xd5, 0x81, 0xf0, + 0xc3, 0x7c, 0xc1, 0x4b, 0x7b, 0xbb, 0x17, 0xca, 0x80, 0x97, 0xef, 0x6e, 0x56, 0x1b, 0x20, 0xeb, + 0x0d, 0x90, 0xdd, 0x06, 0xe8, 0x9b, 0x06, 0xfa, 0xa1, 0x81, 0x7e, 0x6a, 0xa0, 0x2b, 0x0d, 0x74, + 0xad, 0x81, 0x7e, 0x69, 0xa0, 0xdf, 0x1a, 0xc8, 0x4e, 0x03, 0x7d, 0xdf, 0x02, 0x59, 0x6d, 0x81, + 0xac, 0xb7, 0x40, 0xa6, 0x15, 0x33, 0x73, 0xaf, 0x6a, 0xbe, 0x75, 0xfd, 0x13, 0x00, 0x00, 0xff, + 0xff, 0x92, 0x90, 0x06, 0xb0, 0x83, 0x01, 0x00, 0x00, } func (x SlashingType) String() string { diff --git a/data/slash/slash.proto b/data/slash/slash.proto index 95333b21e..ef32c1f24 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -15,9 +15,10 @@ enum SlashingType { } enum ThreatLevel { - Low = 0; - Medium = 1; - High = 2; + Zero = 0; + Low = 1; + Medium = 2; + High = 3; } message HeadersV2{ From 8b373510e85b75019916fa7e99e756c51ff7c97b Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 16 Nov 2021 13:38:43 +0200 Subject: [PATCH 24/54] FEAT: Add GetProofTxData in slashing proof --- data/errors.go | 6 ++++++ data/slash/common.go | 7 +++++++ data/slash/interface.go | 2 ++ data/slash/multipleHeaderProposalProof.go | 16 ++++++++++++++++ data/slash/multipleHeaderSigningProof.go | 22 ++++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/data/errors.go b/data/errors.go index ee756b056..af7c34d76 100644 --- a/data/errors.go +++ b/data/errors.go @@ -93,3 +93,9 @@ var ErrNilHeaderInfo = errors.New("nil header info") // ErrNilHash signals that a nil hash has been provided var ErrNilHash = errors.New("nil hash provided") + +// ErrNotEnoughHeadersProvided signals that not enough headers have been provided for a multiple header proof +var ErrNotEnoughHeadersProvided = errors.New("not enough headers have been provided for a multiple header proof") + +// ErrNotEnoughPublicKeysProvided signals that not enough public keys have been provided for a multiple header proof +var ErrNotEnoughPublicKeysProvided = errors.New("not enough public keys have been provided for a multiple header proof") diff --git a/data/slash/common.go b/data/slash/common.go index ec8ba0eef..c687d3ba5 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -14,6 +14,13 @@ type SlashingResult struct { Headers []data.HeaderInfoHandler } +// ProofTxData represents necessary data to be used in a slashing commitment proof tx by a slashing notifier. +// Each field is required to be added in a transaction.data field +type ProofTxData struct { + Round uint64 + ShardID uint32 +} + func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) { if headersInfo == nil { return HeadersV2{}, data.ErrNilHeaderInfoList diff --git a/data/slash/interface.go b/data/slash/interface.go index 091b7bc9c..cc297eeb4 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -8,6 +8,8 @@ import ( type SlashingProofHandler interface { //GetType - contains the type of slashing detection GetType() SlashingType + // GetProofTxData extracts proof tx data(see ProofTxData) from a slashing proof + GetProofTxData() (*ProofTxData, error) } // MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index 01eece277..4d4a234d4 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -2,6 +2,7 @@ package slash import ( + "github.com/ElrondNetwork/elrond-go-core/core/check" "github.com/ElrondNetwork/elrond-go-core/data" ) @@ -22,6 +23,21 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { return m.HeadersV2.GetHeaderHandlers() } +func (m *MultipleHeaderProposalProof) GetProofTxData() (*ProofTxData, error) { + headers := m.GetHeaders() + if len(headers) == 0 { + return nil, data.ErrNotEnoughHeadersProvided + } + if check.IfNil(headers[0]) { + return nil, data.ErrNilHeaderHandler + } + + return &ProofTxData{ + Round: headers[0].GetRound(), + ShardID: headers[0].GetShardID(), + }, nil +} + // NewMultipleProposalProof returns a MultipleProposalProofHandler from a slashing result func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProofHandler, error) { if slashResult == nil { diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 6648768dd..9d18ef5aa 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -4,6 +4,7 @@ package slash import ( "sort" + "github.com/ElrondNetwork/elrond-go-core/core/check" "github.com/ElrondNetwork/elrond-go-core/data" ) @@ -43,6 +44,27 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand return headersV2.GetHeaderHandlers() } +func (m *MultipleHeaderSigningProof) GetProofTxData() (*ProofTxData, error) { + pubKeys := m.GetPubKeys() + if len(pubKeys) == 0 { + return nil, data.ErrNotEnoughPublicKeysProvided + } + + pubKey := pubKeys[0] + headers := m.GetHeaders(pubKey) + if len(headers) == 0 { + return nil, data.ErrNotEnoughHeadersProvided + } + if check.IfNil(headers[0]) { + return nil, data.ErrNilHeaderHandler + } + + return &ProofTxData{ + Round: headers[0].GetRound(), + ShardID: headers[0].GetShardID(), + }, nil +} + // NewMultipleSigningProof returns a MultipleSigningProofHandler from a slashing result func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSigningProofHandler, error) { if slashResult == nil { From 0a7b474d6082c7ca23562abf49647637a2a6a4d7 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 16 Nov 2021 14:07:09 +0200 Subject: [PATCH 25/54] FEAT: Add tests for GetProofTxData in multipleHeaderProposalProof_test.go --- data/slash/multipleHeaderProposalProof.go | 4 ++ .../slash/multipleHeaderProposalProof_test.go | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index 4d4a234d4..d743d1767 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -24,6 +24,10 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { } func (m *MultipleHeaderProposalProof) GetProofTxData() (*ProofTxData, error) { + if m == nil { + return nil, data.ErrNilPointerReceiver + } + headers := m.GetHeaders() if len(headers) == 0 { return nil, data.ErrNotEnoughHeadersProvided diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 74cd62cf7..aec6875f5 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -63,6 +63,51 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Equal(t, proof.GetHeaders()[1], h2) } +func TestMultipleHeaderProposalProof_GetProofTxData_NotEnoughHeaders_ExpectError(t *testing.T) { + proof := slash.MultipleHeaderProposalProof{} + + proofTxData, err := proof.GetProofTxData() + require.Nil(t, proofTxData) + require.Equal(t, data.ErrNotEnoughHeadersProvided, err) +} + +func TestMultipleHeaderProposalProof_GetProofTxData_NilHeader_ExpectError(t *testing.T) { + proof := slash.MultipleHeaderProposalProof{ + HeadersV2: slash.HeadersV2{ + Headers: []*block.HeaderV2{nil}, + }, + } + + proofTxData, err := proof.GetProofTxData() + require.Nil(t, proofTxData) + require.Equal(t, data.ErrNilHeaderHandler, err) +} + +func TestMultipleHeaderProposalProof_GetProofTxData(t *testing.T) { + round := uint64(1) + shardID := uint32(2) + + header := &block.HeaderV2{ + Header: &block.Header{ + Round: round, + ShardID: shardID, + }, + } + proof := slash.MultipleHeaderProposalProof{ + HeadersV2: slash.HeadersV2{ + Headers: []*block.HeaderV2{header}, + }, + } + expectedProofTxData := &slash.ProofTxData{ + Round: round, + ShardID: shardID, + } + + proofTxData, err := proof.GetProofTxData() + require.Equal(t, expectedProofTxData, proofTxData) + require.Nil(t, err) +} + func TestMultipleHeaderProposalProof_Marshal_Unmarshal(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1, LeaderSignature: []byte("sig1")}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2, LeaderSignature: []byte("sig2")}} From 127dd9536e060a1fcaae1d11dddfe64d5cf2a319 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 16 Nov 2021 14:20:19 +0200 Subject: [PATCH 26/54] FEAT: Add tests for GetProofTxData in multipleHeaderSigningProof_test.go --- data/slash/multipleHeaderSigningProof.go | 5 +- data/slash/multipleHeaderSigningProof_test.go | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 9d18ef5aa..a10461997 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -45,11 +45,14 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand } func (m *MultipleHeaderSigningProof) GetProofTxData() (*ProofTxData, error) { + if m == nil { + return nil, data.ErrNilPointerReceiver + } + pubKeys := m.GetPubKeys() if len(pubKeys) == 0 { return nil, data.ErrNotEnoughPublicKeysProvided } - pubKey := pubKeys[0] headers := m.GetHeaders(pubKey) if len(headers) == 0 { diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 265bedc9f..6ff254621 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -84,6 +84,61 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) } +func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvided_ExpectError(t *testing.T) { + proof := slash.MultipleHeaderSigningProof{} + + proofTxData, err := proof.GetProofTxData() + require.Nil(t, proofTxData) + require.Equal(t, data.ErrNotEnoughPublicKeysProvided, err) +} + +func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectError(t *testing.T) { + proof := slash.MultipleHeaderSigningProof{PubKeys: [][]byte{[]byte("pub key")}} + + proofTxData, err := proof.GetProofTxData() + require.Nil(t, proofTxData) + require.Equal(t, data.ErrNotEnoughHeadersProvided, err) +} + +func TestMultipleSigningProof_GetProofTxData_NilHeaderHandler_ExpectError(t *testing.T) { + proof := slash.MultipleHeaderSigningProof{ + PubKeys: [][]byte{[]byte("pub key")}, + HeadersV2: map[string]slash.HeadersV2{ + "pub key": {Headers: []*block.HeaderV2{nil}}, + }, + } + + proofTxData, err := proof.GetProofTxData() + require.Nil(t, proofTxData) + require.Equal(t, data.ErrNilHeaderHandler, err) +} + +func TestMultipleSigningProof_GetProofTxData(t *testing.T) { + round := uint64(1) + shardID := uint32(2) + + header := &block.HeaderV2{ + Header: &block.Header{ + Round: round, + ShardID: shardID, + }, + } + proof := slash.MultipleHeaderSigningProof{ + PubKeys: [][]byte{[]byte("pub key")}, + HeadersV2: map[string]slash.HeadersV2{ + "pub key": {Headers: []*block.HeaderV2{header}}, + }, + } + expectedProofTxData := &slash.ProofTxData{ + Round: round, + ShardID: shardID, + } + + proofTxData, err := proof.GetProofTxData() + require.Equal(t, expectedProofTxData, proofTxData) + require.Nil(t, err) +} + func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} From 05c9a895480ffcf54f1738303d77a2658260ff3b Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 18 Nov 2021 11:53:21 +0200 Subject: [PATCH 27/54] FEAT: Remove slashing type enum, add ProofID byte --- data/slash/common.go | 13 ++++ data/slash/interface.go | 2 - data/slash/multipleHeaderProposalProof.go | 9 +-- .../slash/multipleHeaderProposalProof_test.go | 5 +- data/slash/multipleHeaderSigningProof.go | 9 +-- data/slash/multipleHeaderSigningProof_test.go | 2 +- data/slash/slash.pb.go | 75 +++++-------------- data/slash/slash.proto | 6 -- 8 files changed, 38 insertions(+), 83 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index c687d3ba5..e4932a096 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -19,8 +19,21 @@ type SlashingResult struct { type ProofTxData struct { Round uint64 ShardID uint32 + ProofID ProofID } +type ProofID byte + +// Used by slashing notifier to create a slashing transaction +// from a proof. Each transaction identifies a different +// slashing event based on this ID +const ( + // MultipleProposalProofID = MultipleProposal's ID + MultipleProposalProofID ProofID = 0x1 + // MultipleSigningProofID = MultipleSigning's ID + MultipleSigningProofID ProofID = 0x2 +) + func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) { if headersInfo == nil { return HeadersV2{}, data.ErrNilHeaderInfoList diff --git a/data/slash/interface.go b/data/slash/interface.go index cc297eeb4..cead589f8 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -6,8 +6,6 @@ import ( // SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction type SlashingProofHandler interface { - //GetType - contains the type of slashing detection - GetType() SlashingType // GetProofTxData extracts proof tx data(see ProofTxData) from a slashing proof GetProofTxData() (*ProofTxData, error) } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index d743d1767..8b70ad14d 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -6,14 +6,6 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) -// GetType returns MultipleProposal -func (m *MultipleHeaderProposalProof) GetType() SlashingType { - if m == nil { - return None - } - return MultipleProposal -} - // GetHeaders returns all headers that have been proposed by a possible malicious validator func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { if m == nil { @@ -39,6 +31,7 @@ func (m *MultipleHeaderProposalProof) GetProofTxData() (*ProofTxData, error) { return &ProofTxData{ Round: headers[0].GetRound(), ShardID: headers[0].GetShardID(), + ProofID: MultipleProposalProofID, }, nil } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index aec6875f5..21c157bcf 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -40,7 +40,7 @@ func TestNewMultipleProposalProof(t *testing.T) { } } -func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { +func TestMultipleProposalProof_GetHeaders_GetLevel(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} @@ -54,8 +54,6 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { proof, err := slash.NewMultipleProposalProof(slashRes) require.Nil(t, err) - - require.Equal(t, slash.MultipleProposal, proof.GetType()) require.Equal(t, slash.Medium, proof.GetLevel()) require.Len(t, proof.GetHeaders(), 2) @@ -101,6 +99,7 @@ func TestMultipleHeaderProposalProof_GetProofTxData(t *testing.T) { expectedProofTxData := &slash.ProofTxData{ Round: round, ShardID: shardID, + ProofID: slash.MultipleProposalProofID, } proofTxData, err := proof.GetProofTxData() diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index a10461997..6aedce6b3 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -8,14 +8,6 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) -// GetType returns MultipleSigning -func (m *MultipleHeaderSigningProof) GetType() SlashingType { - if m == nil { - return None - } - return MultipleSigning -} - // GetLevel returns the ThreatLevel of a possible malicious validator func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { if m == nil { @@ -65,6 +57,7 @@ func (m *MultipleHeaderSigningProof) GetProofTxData() (*ProofTxData, error) { return &ProofTxData{ Round: headers[0].GetRound(), ShardID: headers[0].GetShardID(), + ProofID: MultipleSigningProofID, }, nil } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 6ff254621..79647c295 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -69,7 +69,6 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { proof, err := slash.NewMultipleSigningProof(slashRes) require.Nil(t, err) - require.Equal(t, slash.MultipleSigning, proof.GetType()) require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey1"))) require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey2"))) require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey3"))) @@ -132,6 +131,7 @@ func TestMultipleSigningProof_GetProofTxData(t *testing.T) { expectedProofTxData := &slash.ProofTxData{ Round: round, ShardID: shardID, + ProofID: slash.MultipleSigningProofID, } proofTxData, err := proof.GetProofTxData() diff --git a/data/slash/slash.pb.go b/data/slash/slash.pb.go index 5293c6d0a..121f5819b 100644 --- a/data/slash/slash.pb.go +++ b/data/slash/slash.pb.go @@ -27,30 +27,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type SlashingType int32 - -const ( - None SlashingType = 0 - MultipleProposal SlashingType = 1 - MultipleSigning SlashingType = 2 -) - -var SlashingType_name = map[int32]string{ - 0: "None", - 1: "MultipleProposal", - 2: "MultipleSigning", -} - -var SlashingType_value = map[string]int32{ - "None": 0, - "MultipleProposal": 1, - "MultipleSigning": 2, -} - -func (SlashingType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_7c4604f407d65f7b, []int{0} -} - type ThreatLevel int32 const ( @@ -75,7 +51,7 @@ var ThreatLevel_value = map[string]int32{ } func (ThreatLevel) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_7c4604f407d65f7b, []int{1} + return fileDescriptor_7c4604f407d65f7b, []int{0} } type HeadersV2 struct { @@ -118,7 +94,6 @@ func (m *HeadersV2) GetHeaders() []*block.HeaderV2 { } func init() { - proto.RegisterEnum("proto.SlashingType", SlashingType_name, SlashingType_value) proto.RegisterEnum("proto.ThreatLevel", ThreatLevel_name, ThreatLevel_value) proto.RegisterType((*HeadersV2)(nil), "proto.HeadersV2") } @@ -126,37 +101,27 @@ func init() { func init() { proto.RegisterFile("slash.proto", fileDescriptor_7c4604f407d65f7b) } var fileDescriptor_7c4604f407d65f7b = []byte{ - // 329 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x41, 0x4f, 0xfa, 0x30, - 0x18, 0xc6, 0x5b, 0xf8, 0x03, 0x7f, 0x8b, 0x09, 0xcd, 0xf4, 0x60, 0x38, 0xbc, 0x31, 0x9e, 0x94, - 0x04, 0x96, 0xcc, 0x84, 0xab, 0x46, 0x63, 0xc2, 0x01, 0x88, 0x11, 0xc2, 0x81, 0xdb, 0xc6, 0x6a, - 0xb7, 0x30, 0xf6, 0x2e, 0xdd, 0x26, 0xf1, 0xe6, 0x47, 0xf0, 0x63, 0xf8, 0x51, 0x3c, 0x72, 0xe4, - 0x28, 0xe5, 0xe2, 0x91, 0x8f, 0x60, 0xe8, 0x24, 0xf1, 0xd2, 0xf6, 0xf7, 0x3c, 0x4f, 0x9f, 0xb4, - 0x2f, 0xab, 0xa7, 0x91, 0x9b, 0x06, 0x9d, 0x44, 0x61, 0x86, 0x56, 0xc5, 0x6c, 0xcd, 0xb6, 0x0c, - 0xb3, 0x20, 0xf7, 0x3a, 0x33, 0x5c, 0xd8, 0x12, 0x25, 0xda, 0x46, 0xf6, 0xf2, 0x67, 0x43, 0x06, - 0xcc, 0xa9, 0xb8, 0xd5, 0xbc, 0xfd, 0x13, 0x7f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6d, 0x81, - 0xac, 0xb7, 0x40, 0xa6, 0x15, 0x33, 0x73, 0xaf, 0x6a, 0xbe, 0x75, 0xfd, 0x13, 0x00, 0x00, 0xff, - 0xff, 0x92, 0x90, 0x06, 0xb0, 0x83, 0x01, 0x00, 0x00, + // 278 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0xce, 0x49, 0x2c, + 0xce, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, + 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0xe1, 0xa4, + 0xd2, 0x34, 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0x1c, 0x90, 0x94, 0xbb, 0xe6, 0x14, + 0xe5, 0xe7, 0xa5, 0xf8, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0xeb, 0xa7, 0x82, 0x79, 0xba, 0xe9, + 0xf9, 0xba, 0xc9, 0xf9, 0x45, 0xa9, 0xfa, 0x29, 0x89, 0x25, 0x89, 0xfa, 0x49, 0x39, 0xf9, 0xc9, + 0xd9, 0x10, 0x32, 0xcc, 0x08, 0x62, 0x82, 0x92, 0x19, 0x17, 0xa7, 0x47, 0x6a, 0x62, 0x4a, 0x6a, + 0x51, 0x71, 0x98, 0x91, 0x90, 0x26, 0x17, 0x3b, 0x94, 0x23, 0xc1, 0xa8, 0xc0, 0xac, 0xc1, 0x6d, + 0xc4, 0x0f, 0x51, 0xa5, 0x07, 0x11, 0x0d, 0x33, 0x0a, 0x82, 0xc9, 0x6b, 0x99, 0x71, 0x71, 0x87, + 0x64, 0x14, 0xa5, 0x26, 0x96, 0xf8, 0xa4, 0x96, 0xa5, 0xe6, 0x08, 0x71, 0x70, 0xb1, 0x44, 0xa5, + 0x16, 0xe5, 0x0b, 0x30, 0x08, 0xb1, 0x73, 0x31, 0xfb, 0xe4, 0x97, 0x0b, 0x30, 0x0a, 0x71, 0x71, + 0xb1, 0xf9, 0xa6, 0xa6, 0x64, 0x96, 0xe6, 0x0a, 0x30, 0x81, 0xa4, 0x3d, 0x32, 0xd3, 0x33, 0x04, + 0x98, 0x9d, 0xec, 0x2f, 0x3c, 0x94, 0x63, 0xb8, 0xf1, 0x50, 0x8e, 0xe1, 0xc3, 0x43, 0x39, 0xc6, + 0x86, 0x47, 0x72, 0x8c, 0x2b, 0x1e, 0xc9, 0x31, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, + 0xe3, 0x8d, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0xbe, 0x78, 0x24, 0xc7, 0xf0, 0xe1, 0x91, + 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xc5, + 0x0a, 0x0e, 0xae, 0x24, 0x36, 0xb0, 0x8b, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x55, + 0xd0, 0xd6, 0x3e, 0x01, 0x00, 0x00, } -func (x SlashingType) String() string { - s, ok := SlashingType_name[int32(x)] - if ok { - return s - } - return strconv.Itoa(int(x)) -} func (x ThreatLevel) String() string { s, ok := ThreatLevel_name[int32(x)] if ok { diff --git a/data/slash/slash.proto b/data/slash/slash.proto index ef32c1f24..cfec9e6e8 100644 --- a/data/slash/slash.proto +++ b/data/slash/slash.proto @@ -8,12 +8,6 @@ option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/ElrondNetwork/elrond-go-core/data/block/blockV2.proto"; -enum SlashingType { - None = 0; - MultipleProposal = 1; - MultipleSigning = 2; -} - enum ThreatLevel { Zero = 0; Low = 1; From 02150a74efc27273c0821a0fc8ee703ef762fa82 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 18 Nov 2021 15:12:29 +0200 Subject: [PATCH 28/54] FEAT: Add first ugly version --- data/slash/common.go | 1 + data/slash/multipleHeaderSigningProof.go | 137 ++++- data/slash/multipleHeaderSigningProof.pb.go | 568 ++++++++++-------- data/slash/multipleHeaderSigningProof.proto | 10 +- data/slash/multipleHeaderSigningProof_test.go | 34 +- 5 files changed, 465 insertions(+), 285 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index e4932a096..2c5eab023 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -64,6 +64,7 @@ func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) func sortHeadersByHash(headersInfo []data.HeaderInfoHandler) { sortFunc := func(i, j int) bool { + // TODO: CHECK IF INTERFACE IS NIL hash1 := string(headersInfo[i].GetHash()) hash2 := string(headersInfo[j].GetHash()) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 6aedce6b3..3b9609b4e 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -5,21 +5,36 @@ import ( "sort" "github.com/ElrondNetwork/elrond-go-core/core/check" + "github.com/ElrondNetwork/elrond-go-core/core/sliceUtil" "github.com/ElrondNetwork/elrond-go-core/data" ) +// GetPubKeys - returns all validator's public keys which have signed multiple headers +func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { + if m == nil { + return nil + } + + ret := make([][]byte, 0, len(m.SignersSlashData)) + for pubKey := range m.SignersSlashData { + ret = append(ret, []byte(pubKey)) + } + + return ret +} + // GetLevel returns the ThreatLevel of a possible malicious validator func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { if m == nil { return Zero } - level, exists := m.Levels[string(pubKey)] + slashData, exists := m.SignersSlashData[string(pubKey)] if !exists { return Zero } - return level + return slashData.ThreatLevel } // GetHeaders returns all headers that have been signed by a possible malicious validator @@ -28,12 +43,24 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand return nil } - headersV2, exist := m.HeadersV2[string(pubKey)] - if !exist { + slashData, exists := m.SignersSlashData[string(pubKey)] + if !exists { return nil } - return headersV2.GetHeaderHandlers() + idx := uint32(0) + bitmap := slashData.GetSignedHeadersBitMap() + headers := m.HeadersV2.GetHeaderHandlers() + + ret := make([]data.HeaderHandler, 0) + for _, header := range headers { + if sliceUtil.IsIndexSetInBitmap(idx, bitmap) { + ret = append(ret, header) + } + idx++ + } + + return ret } func (m *MultipleHeaderSigningProof) GetProofTxData() (*ProofTxData, error) { @@ -67,26 +94,41 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig return nil, data.ErrNilSlashResult } - pubKeys := make([][]byte, 0, len(slashResult)) - levels := make(map[string]ThreatLevel, len(slashResult)) - headers := make(map[string]HeadersV2, len(slashResult)) + headersInfo := getAllUniqueHeaders(slashResult) + sortHeadersByHash(headersInfo) - sortedPubKeys := getSortedPubKeys(slashResult) - for _, pubKey := range sortedPubKeys { - pubKeys = append(pubKeys, []byte(pubKey)) - levels[pubKey] = slashResult[pubKey].SlashingLevel + idx := uint32(0) + hashIndexMap := make(map[string]uint32) + sortedHeaders := make([]data.HeaderHandler, 0, len(headersInfo)) + for _, headerInfo := range headersInfo { + hashIndexMap[string(headerInfo.GetHash())] = idx + sortedHeaders = append(sortedHeaders, headerInfo.GetHeaderHandler()) + idx++ + } - sortedHeaders, err := getSortedHeadersV2(slashResult[pubKey].Headers) - if err != nil { - return nil, err + signersSlashData := make(map[string]SignerSlashingData) + for pubKey, res := range slashResult { + bitmap := make([]byte, 0) + for _, header := range res.Headers { + index, exists := hashIndexMap[string(header.GetHash())] + if exists { + SetIndexInBitmap(index, bitmap) + } + } + signersSlashData[pubKey] = SignerSlashingData{ + SignedHeadersBitMap: bitmap, + ThreatLevel: res.SlashingLevel, } - headers[pubKey] = sortedHeaders } + headersV2 := HeadersV2{} + err := headersV2.SetHeaders(sortedHeaders) + if err != nil { + return nil, err + } return &MultipleHeaderSigningProof{ - PubKeys: pubKeys, - Levels: levels, - HeadersV2: headers, + HeadersV2: headersV2, + SignersSlashData: signersSlashData, }, nil } @@ -100,3 +142,60 @@ func getSortedPubKeys(slashResult map[string]SlashingResult) []string { return sortedPubKeys } + +func getAllUniqueHeaders(slashResult map[string]SlashingResult) []data.HeaderInfoHandler { + headersInfo := make([]data.HeaderInfoHandler, 0, len(slashResult)) + hashes := make(map[string]struct{}) + + for _, res := range slashResult { + for _, currHeaderInfo := range res.Headers { + currHash := string(currHeaderInfo.GetHash()) + + _, exists := hashes[currHash] + if exists { + continue + } + + hashes[currHash] = struct{}{} + headersInfo = append(headersInfo, currHeaderInfo) + } + } + + return headersInfo +} + +func getAllHeadersSorted(slashResult map[string]SlashingResult) (HeadersV2, error) { + headersInfo := getAllUniqueHeaders(slashResult) + sortHeadersByHash(headersInfo) + + idx := uint32(0) + hashIndexMap := make(map[string]uint32) + sortedHeaders := make([]data.HeaderHandler, 0, len(headersInfo)) + for _, headerInfo := range headersInfo { + hashIndexMap[string(headerInfo.GetHash())] = idx + sortedHeaders = append(sortedHeaders, headerInfo.GetHeaderHandler()) + idx++ + } + + signersSlashData := make(map[string]SignerSlashingData) + for pubKey, res := range slashResult { + bitmap := make([]byte, 0) + for _, header := range res.Headers { + index, exists := hashIndexMap[string(header.GetHash())] + if exists { + SetIndexInBitmap(index, bitmap) + } + } + signersSlashData[pubKey] = SignerSlashingData{ + SignedHeadersBitMap: bitmap, + ThreatLevel: res.SlashingLevel, + } + } + headersV2 := HeadersV2{} + + return headersV2, headersV2.SetHeaders(sortedHeaders) +} + +func SetIndexInBitmap(idx uint32, bitmap []byte) { + +} diff --git a/data/slash/multipleHeaderSigningProof.pb.go b/data/slash/multipleHeaderSigningProof.pb.go index 664e30dce..163f62ae5 100644 --- a/data/slash/multipleHeaderSigningProof.pb.go +++ b/data/slash/multipleHeaderSigningProof.pb.go @@ -27,16 +27,62 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type SignerSlashingData struct { + SignedHeadersBitMap []byte `protobuf:"bytes,1,opt,name=SignedHeadersBitMap,proto3" json:"SignedHeadersBitMap,omitempty"` + ThreatLevel ThreatLevel `protobuf:"varint,2,opt,name=ThreatLevel,proto3,enum=proto.ThreatLevel" json:"ThreatLevel,omitempty"` +} + +func (m *SignerSlashingData) Reset() { *m = SignerSlashingData{} } +func (*SignerSlashingData) ProtoMessage() {} +func (*SignerSlashingData) Descriptor() ([]byte, []int) { + return fileDescriptor_f61c9968ee2015ff, []int{0} +} +func (m *SignerSlashingData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignerSlashingData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *SignerSlashingData) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignerSlashingData.Merge(m, src) +} +func (m *SignerSlashingData) XXX_Size() int { + return m.Size() +} +func (m *SignerSlashingData) XXX_DiscardUnknown() { + xxx_messageInfo_SignerSlashingData.DiscardUnknown(m) +} + +var xxx_messageInfo_SignerSlashingData proto.InternalMessageInfo + +func (m *SignerSlashingData) GetSignedHeadersBitMap() []byte { + if m != nil { + return m.SignedHeadersBitMap + } + return nil +} + +func (m *SignerSlashingData) GetThreatLevel() ThreatLevel { + if m != nil { + return m.ThreatLevel + } + return Zero +} + type MultipleHeaderSigningProof struct { - PubKeys [][]byte `protobuf:"bytes,1,rep,name=PubKeys,proto3" json:"PubKeys,omitempty"` - Levels map[string]ThreatLevel `protobuf:"bytes,2,rep,name=Levels,proto3" json:"Levels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=proto.ThreatLevel"` - HeadersV2 map[string]HeadersV2 `protobuf:"bytes,3,rep,name=HeadersV2,proto3" json:"HeadersV2" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + HeadersV2 HeadersV2 `protobuf:"bytes,1,opt,name=HeadersV2,proto3" json:"HeadersV2"` + SignersSlashData map[string]SignerSlashingData `protobuf:"bytes,2,rep,name=SignersSlashData,proto3" json:"SignersSlashData" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (m *MultipleHeaderSigningProof) Reset() { *m = MultipleHeaderSigningProof{} } func (*MultipleHeaderSigningProof) ProtoMessage() {} func (*MultipleHeaderSigningProof) Descriptor() ([]byte, []int) { - return fileDescriptor_f61c9968ee2015ff, []int{0} + return fileDescriptor_f61c9968ee2015ff, []int{1} } func (m *MultipleHeaderSigningProof) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -61,69 +107,63 @@ func (m *MultipleHeaderSigningProof) XXX_DiscardUnknown() { var xxx_messageInfo_MultipleHeaderSigningProof proto.InternalMessageInfo -func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { - if m != nil { - return m.PubKeys - } - return nil -} - -func (m *MultipleHeaderSigningProof) GetLevels() map[string]ThreatLevel { +func (m *MultipleHeaderSigningProof) GetHeadersV2() HeadersV2 { if m != nil { - return m.Levels + return m.HeadersV2 } - return nil + return HeadersV2{} } -func (m *MultipleHeaderSigningProof) GetHeadersV2() map[string]HeadersV2 { +func (m *MultipleHeaderSigningProof) GetSignersSlashData() map[string]SignerSlashingData { if m != nil { - return m.HeadersV2 + return m.SignersSlashData } return nil } func init() { + proto.RegisterType((*SignerSlashingData)(nil), "proto.SignerSlashingData") proto.RegisterType((*MultipleHeaderSigningProof)(nil), "proto.MultipleHeaderSigningProof") - proto.RegisterMapType((map[string]HeadersV2)(nil), "proto.MultipleHeaderSigningProof.HeadersV2Entry") - proto.RegisterMapType((map[string]ThreatLevel)(nil), "proto.MultipleHeaderSigningProof.LevelsEntry") + proto.RegisterMapType((map[string]SignerSlashingData)(nil), "proto.MultipleHeaderSigningProof.SignersSlashDataEntry") } func init() { proto.RegisterFile("multipleHeaderSigningProof.proto", fileDescriptor_f61c9968ee2015ff) } var fileDescriptor_f61c9968ee2015ff = []byte{ - // 341 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x3f, 0x4b, 0xf3, 0x50, - 0x18, 0xc5, 0xf3, 0x24, 0x6f, 0xfb, 0xd2, 0x1b, 0x29, 0xe5, 0x4e, 0x21, 0xc3, 0x63, 0x70, 0x90, - 0x2c, 0x4d, 0x25, 0x2e, 0xe2, 0x22, 0x14, 0x0a, 0x82, 0x56, 0x4a, 0x2c, 0x0e, 0x6e, 0x89, 0xde, - 0xa6, 0xc1, 0xb4, 0xb7, 0xe4, 0x4f, 0xa1, 0x9b, 0x1f, 0xc1, 0x8f, 0xe1, 0x47, 0xe9, 0xd8, 0xb1, - 0x93, 0xd8, 0xdb, 0xc5, 0xb1, 0xf8, 0x09, 0xc4, 0x9b, 0x5a, 0x2b, 0x58, 0x9c, 0xee, 0x73, 0x0e, - 0xe7, 0xfc, 0xce, 0x70, 0x89, 0x35, 0xc8, 0xe3, 0x2c, 0x1a, 0xc5, 0xec, 0x9c, 0xf9, 0xf7, 0x2c, - 0xb9, 0x8e, 0xc2, 0x61, 0x34, 0x0c, 0x3b, 0x09, 0xe7, 0x3d, 0x67, 0x94, 0xf0, 0x8c, 0xd3, 0x92, - 0x7c, 0x4c, 0x3d, 0x8d, 0xfd, 0xb4, 0x5f, 0x78, 0x66, 0x3d, 0x8c, 0xb2, 0x7e, 0x1e, 0x38, 0x77, - 0x7c, 0xd0, 0x08, 0x79, 0xc8, 0x1b, 0xd2, 0x0e, 0xf2, 0x9e, 0x54, 0x52, 0xc8, 0xab, 0x88, 0x1f, - 0xbc, 0xab, 0xc4, 0x6c, 0xef,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 0xff, 0x7e, 0x18, 0x86, - 0x2e, 0x23, 0x02, 0x00, 0x00, + // 363 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0x2d, 0xcd, 0x29, + 0xc9, 0x2c, 0xc8, 0x49, 0xf5, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x0a, 0xce, 0x4c, 0xcf, 0xcb, 0xcc, + 0x4b, 0x0f, 0x28, 0xca, 0xcf, 0x4f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, + 0x52, 0xdc, 0xc5, 0x39, 0x89, 0xc5, 0x19, 0x10, 0x31, 0x29, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, + 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xf4, 0xfc, 0xf4, 0x7c, 0x7d, 0xb0, 0x70, 0x52, 0x69, 0x1a, + 0x98, 0x07, 0xe6, 0x80, 0x59, 0x10, 0xe5, 0x4a, 0x35, 0x5c, 0x42, 0x20, 0x83, 0x53, 0x8b, 0x82, + 0x41, 0x66, 0x64, 0xe6, 0xa5, 0xbb, 0x24, 0x96, 0x24, 0x0a, 0x19, 0x70, 0x09, 0x83, 0x45, 0x53, + 0x20, 0x56, 0x17, 0x3b, 0x65, 0x96, 0xf8, 0x26, 0x16, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x04, + 0x61, 0x93, 0x12, 0x32, 0xe1, 0xe2, 0x0e, 0xc9, 0x28, 0x4a, 0x4d, 0x2c, 0xf1, 0x49, 0x2d, 0x4b, + 0xcd, 0x91, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x33, 0x12, 0x82, 0x58, 0xa2, 0x87, 0x24, 0x13, 0x84, + 0xac, 0x4c, 0x69, 0x2e, 0x13, 0x97, 0x94, 0x2f, 0x4e, 0x5f, 0x0a, 0x99, 0x70, 0x71, 0x42, 0x6d, + 0x09, 0x33, 0x02, 0x5b, 0xce, 0x6d, 0x24, 0x00, 0x35, 0x12, 0x2e, 0xee, 0xc4, 0x72, 0xe2, 0x9e, + 0x3c, 0x43, 0x10, 0x42, 0xa1, 0x50, 0x26, 0x97, 0x00, 0xc4, 0x4b, 0xc5, 0x60, 0x3f, 0x81, 0x3c, + 0x24, 0xc1, 0xa4, 0xc0, 0xac, 0xc1, 0x6d, 0x64, 0x0e, 0xd5, 0x8c, 0xdb, 0x4a, 0x3d, 0x74, 0x9d, + 0xae, 0x79, 0x25, 0x45, 0x95, 0x50, 0x3b, 0x30, 0x8c, 0x95, 0x8a, 0xe3, 0x12, 0xc5, 0xaa, 0x41, + 0x48, 0x80, 0x8b, 0x39, 0x3b, 0xb5, 0x12, 0xec, 0x66, 0xce, 0x20, 0x10, 0x53, 0x48, 0x9f, 0x8b, + 0xb5, 0x2c, 0x31, 0xa7, 0x34, 0x15, 0x1c, 0x34, 0xdc, 0x46, 0x92, 0x50, 0xa7, 0x60, 0x06, 0x7e, + 0x10, 0x44, 0x9d, 0x15, 0x93, 0x05, 0xa3, 0x93, 0xfd, 0x85, 0x87, 0x72, 0x0c, 0x37, 0x1e, 0xca, + 0x31, 0x7c, 0x78, 0x28, 0xc7, 0xd8, 0xf0, 0x48, 0x8e, 0x71, 0xc5, 0x23, 0x39, 0xc6, 0x13, 0x8f, + 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0xbc, 0xf1, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x17, + 0x8f, 0xe4, 0x18, 0x3e, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x58, 0xc1, 0x69, 0x22, 0x89, 0x0d, 0x6c, 0x8b, 0x31, 0x20, 0x00, + 0x00, 0xff, 0xff, 0x16, 0x42, 0xdd, 0x96, 0x4c, 0x02, 0x00, 0x00, } -func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { +func (this *SignerSlashingData) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*MultipleHeaderSigningProof) + that1, ok := that.(*SignerSlashingData) if !ok { - that2, ok := that.(MultipleHeaderSigningProof) + that2, ok := that.(SignerSlashingData) if ok { that1 = &that2 } else { @@ -135,66 +175,78 @@ func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { } else if this == nil { return false } - if len(this.PubKeys) != len(that1.PubKeys) { + if !bytes.Equal(this.SignedHeadersBitMap, that1.SignedHeadersBitMap) { return false } - for i := range this.PubKeys { - if !bytes.Equal(this.PubKeys[i], that1.PubKeys[i]) { + if this.ThreatLevel != that1.ThreatLevel { + return false + } + return true +} +func (this *MultipleHeaderSigningProof) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MultipleHeaderSigningProof) + if !ok { + that2, ok := that.(MultipleHeaderSigningProof) + if ok { + that1 = &that2 + } else { return false } } - if len(this.Levels) != len(that1.Levels) { + if that1 == nil { + return this == nil + } else if this == nil { return false } - for i := range this.Levels { - if this.Levels[i] != that1.Levels[i] { - return false - } + if !this.HeadersV2.Equal(&that1.HeadersV2) { + return false } - if len(this.HeadersV2) != len(that1.HeadersV2) { + if len(this.SignersSlashData) != len(that1.SignersSlashData) { return false } - for i := range this.HeadersV2 { - a := this.HeadersV2[i] - b := that1.HeadersV2[i] + for i := range this.SignersSlashData { + a := this.SignersSlashData[i] + b := that1.SignersSlashData[i] if !(&a).Equal(&b) { return false } } return true } +func (this *SignerSlashingData) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&slash.SignerSlashingData{") + s = append(s, "SignedHeadersBitMap: "+fmt.Sprintf("%#v", this.SignedHeadersBitMap)+",\n") + s = append(s, "ThreatLevel: "+fmt.Sprintf("%#v", this.ThreatLevel)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *MultipleHeaderSigningProof) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 6) s = append(s, "&slash.MultipleHeaderSigningProof{") - s = append(s, "PubKeys: "+fmt.Sprintf("%#v", this.PubKeys)+",\n") - keysForLevels := make([]string, 0, len(this.Levels)) - for k, _ := range this.Levels { - keysForLevels = append(keysForLevels, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) - mapStringForLevels := "map[string]ThreatLevel{" - for _, k := range keysForLevels { - mapStringForLevels += fmt.Sprintf("%#v: %#v,", k, this.Levels[k]) - } - mapStringForLevels += "}" - if this.Levels != nil { - s = append(s, "Levels: "+mapStringForLevels+",\n") - } - keysForHeadersV2 := make([]string, 0, len(this.HeadersV2)) - for k, _ := range this.HeadersV2 { - keysForHeadersV2 = append(keysForHeadersV2, k) + s = append(s, "HeadersV2: "+strings.Replace(this.HeadersV2.GoString(), `&`, ``, 1)+",\n") + keysForSignersSlashData := make([]string, 0, len(this.SignersSlashData)) + for k, _ := range this.SignersSlashData { + keysForSignersSlashData = append(keysForSignersSlashData, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) - mapStringForHeadersV2 := "map[string]HeadersV2{" - for _, k := range keysForHeadersV2 { - mapStringForHeadersV2 += fmt.Sprintf("%#v: %#v,", k, this.HeadersV2[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForSignersSlashData) + mapStringForSignersSlashData := "map[string]SignerSlashingData{" + for _, k := range keysForSignersSlashData { + mapStringForSignersSlashData += fmt.Sprintf("%#v: %#v,", k, this.SignersSlashData[k]) } - mapStringForHeadersV2 += "}" - if this.HeadersV2 != nil { - s = append(s, "HeadersV2: "+mapStringForHeadersV2+",\n") + mapStringForSignersSlashData += "}" + if this.SignersSlashData != nil { + s = append(s, "SignersSlashData: "+mapStringForSignersSlashData+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -207,6 +259,41 @@ func valueToGoStringMultipleHeaderSigningProof(v interface{}, typ string) string pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) } +func (m *SignerSlashingData) 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 *SignerSlashingData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignerSlashingData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ThreatLevel != 0 { + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(m.ThreatLevel)) + i-- + dAtA[i] = 0x10 + } + if len(m.SignedHeadersBitMap) > 0 { + i -= len(m.SignedHeadersBitMap) + copy(dAtA[i:], m.SignedHeadersBitMap) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(m.SignedHeadersBitMap))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *MultipleHeaderSigningProof) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -227,14 +314,14 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l - if len(m.HeadersV2) > 0 { - keysForHeadersV2 := make([]string, 0, len(m.HeadersV2)) - for k := range m.HeadersV2 { - keysForHeadersV2 = append(keysForHeadersV2, string(k)) + if len(m.SignersSlashData) > 0 { + keysForSignersSlashData := make([]string, 0, len(m.SignersSlashData)) + for k := range m.SignersSlashData { + keysForSignersSlashData = append(keysForSignersSlashData, string(k)) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) - for iNdEx := len(keysForHeadersV2) - 1; iNdEx >= 0; iNdEx-- { - v := m.HeadersV2[string(keysForHeadersV2[iNdEx])] + github_com_gogo_protobuf_sortkeys.Strings(keysForSignersSlashData) + for iNdEx := len(keysForSignersSlashData) - 1; iNdEx >= 0; iNdEx-- { + v := m.SignersSlashData[string(keysForSignersSlashData[iNdEx])] baseI := i { size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) @@ -246,31 +333,9 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err } i-- dAtA[i] = 0x12 - i -= len(keysForHeadersV2[iNdEx]) - copy(dAtA[i:], keysForHeadersV2[iNdEx]) - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForHeadersV2[iNdEx]))) - i-- - dAtA[i] = 0xa - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x1a - } - } - if len(m.Levels) > 0 { - keysForLevels := make([]string, 0, len(m.Levels)) - for k := range m.Levels { - keysForLevels = append(keysForLevels, string(k)) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) - for iNdEx := len(keysForLevels) - 1; iNdEx >= 0; iNdEx-- { - v := m.Levels[string(keysForLevels[iNdEx])] - baseI := i - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(v)) - i-- - dAtA[i] = 0x10 - i -= len(keysForLevels[iNdEx]) - copy(dAtA[i:], keysForLevels[iNdEx]) - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForLevels[iNdEx]))) + i -= len(keysForSignersSlashData[iNdEx]) + copy(dAtA[i:], keysForSignersSlashData[iNdEx]) + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(keysForSignersSlashData[iNdEx]))) i-- dAtA[i] = 0xa i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(baseI-i)) @@ -278,15 +343,16 @@ func (m *MultipleHeaderSigningProof) MarshalToSizedBuffer(dAtA []byte) (int, err dAtA[i] = 0x12 } } - if len(m.PubKeys) > 0 { - for iNdEx := len(m.PubKeys) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.PubKeys[iNdEx]) - copy(dAtA[i:], m.PubKeys[iNdEx]) - i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(len(m.PubKeys[iNdEx]))) - i-- - dAtA[i] = 0xa + { + size, err := m.HeadersV2.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintMultipleHeaderSigningProof(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -301,28 +367,32 @@ func encodeVarintMultipleHeaderSigningProof(dAtA []byte, offset int, v uint64) i dAtA[offset] = uint8(v) return base } -func (m *MultipleHeaderSigningProof) Size() (n int) { +func (m *SignerSlashingData) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.PubKeys) > 0 { - for _, b := range m.PubKeys { - l = len(b) - n += 1 + l + sovMultipleHeaderSigningProof(uint64(l)) - } + l = len(m.SignedHeadersBitMap) + if l > 0 { + n += 1 + l + sovMultipleHeaderSigningProof(uint64(l)) } - if len(m.Levels) > 0 { - for k, v := range m.Levels { - _ = k - _ = v - mapEntrySize := 1 + len(k) + sovMultipleHeaderSigningProof(uint64(len(k))) + 1 + sovMultipleHeaderSigningProof(uint64(v)) - n += mapEntrySize + 1 + sovMultipleHeaderSigningProof(uint64(mapEntrySize)) - } + if m.ThreatLevel != 0 { + n += 1 + sovMultipleHeaderSigningProof(uint64(m.ThreatLevel)) + } + return n +} + +func (m *MultipleHeaderSigningProof) Size() (n int) { + if m == nil { + return 0 } - if len(m.HeadersV2) > 0 { - for k, v := range m.HeadersV2 { + var l int + _ = l + l = m.HeadersV2.Size() + n += 1 + l + sovMultipleHeaderSigningProof(uint64(l)) + if len(m.SignersSlashData) > 0 { + for k, v := range m.SignersSlashData { _ = k _ = v l = v.Size() @@ -339,34 +409,34 @@ func sovMultipleHeaderSigningProof(x uint64) (n int) { func sozMultipleHeaderSigningProof(x uint64) (n int) { return sovMultipleHeaderSigningProof(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (this *MultipleHeaderSigningProof) String() string { +func (this *SignerSlashingData) String() string { if this == nil { return "nil" } - keysForLevels := make([]string, 0, len(this.Levels)) - for k, _ := range this.Levels { - keysForLevels = append(keysForLevels, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForLevels) - mapStringForLevels := "map[string]ThreatLevel{" - for _, k := range keysForLevels { - mapStringForLevels += fmt.Sprintf("%v: %v,", k, this.Levels[k]) + s := strings.Join([]string{`&SignerSlashingData{`, + `SignedHeadersBitMap:` + fmt.Sprintf("%v", this.SignedHeadersBitMap) + `,`, + `ThreatLevel:` + fmt.Sprintf("%v", this.ThreatLevel) + `,`, + `}`, + }, "") + return s +} +func (this *MultipleHeaderSigningProof) String() string { + if this == nil { + return "nil" } - mapStringForLevels += "}" - keysForHeadersV2 := make([]string, 0, len(this.HeadersV2)) - for k, _ := range this.HeadersV2 { - keysForHeadersV2 = append(keysForHeadersV2, k) + keysForSignersSlashData := make([]string, 0, len(this.SignersSlashData)) + for k, _ := range this.SignersSlashData { + keysForSignersSlashData = append(keysForSignersSlashData, k) } - github_com_gogo_protobuf_sortkeys.Strings(keysForHeadersV2) - mapStringForHeadersV2 := "map[string]HeadersV2{" - for _, k := range keysForHeadersV2 { - mapStringForHeadersV2 += fmt.Sprintf("%v: %v,", k, this.HeadersV2[k]) + github_com_gogo_protobuf_sortkeys.Strings(keysForSignersSlashData) + mapStringForSignersSlashData := "map[string]SignerSlashingData{" + for _, k := range keysForSignersSlashData { + mapStringForSignersSlashData += fmt.Sprintf("%v: %v,", k, this.SignersSlashData[k]) } - mapStringForHeadersV2 += "}" + mapStringForSignersSlashData += "}" s := strings.Join([]string{`&MultipleHeaderSigningProof{`, - `PubKeys:` + fmt.Sprintf("%v", this.PubKeys) + `,`, - `Levels:` + mapStringForLevels + `,`, - `HeadersV2:` + mapStringForHeadersV2 + `,`, + `HeadersV2:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.HeadersV2), "HeadersV2", "HeadersV2", 1), `&`, ``, 1) + `,`, + `SignersSlashData:` + mapStringForSignersSlashData + `,`, `}`, }, "") return s @@ -379,7 +449,7 @@ func valueToStringMultipleHeaderSigningProof(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } -func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { +func (m *SignerSlashingData) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -402,15 +472,15 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MultipleHeaderSigningProof: wiretype end group for non-group") + return fmt.Errorf("proto: SignerSlashingData: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MultipleHeaderSigningProof: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: SignerSlashingData: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PubKeys", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SignedHeadersBitMap", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -437,12 +507,86 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PubKeys = append(m.PubKeys, make([]byte, postIndex-iNdEx)) - copy(m.PubKeys[len(m.PubKeys)-1], dAtA[iNdEx:postIndex]) + m.SignedHeadersBitMap = append(m.SignedHeadersBitMap[:0], dAtA[iNdEx:postIndex]...) + if m.SignedHeadersBitMap == nil { + m.SignedHeadersBitMap = []byte{} + } iNdEx = postIndex case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ThreatLevel", wireType) + } + m.ThreatLevel = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMultipleHeaderSigningProof + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ThreatLevel |= ThreatLevel(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMultipleHeaderSigningProof(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthMultipleHeaderSigningProof + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MultipleHeaderSigningProof) 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 ErrIntOverflowMultipleHeaderSigningProof + } + 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: MultipleHeaderSigningProof: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MultipleHeaderSigningProof: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Levels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field HeadersV2", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -469,93 +613,13 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Levels == nil { - m.Levels = make(map[string]ThreatLevel) - } - var mapkey string - var mapvalue ThreatLevel - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMultipleHeaderSigningProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMultipleHeaderSigningProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthMultipleHeaderSigningProof - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthMultipleHeaderSigningProof - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMultipleHeaderSigningProof - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= ThreatLevel(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else { - iNdEx = entryPreIndex - skippy, err := skipMultipleHeaderSigningProof(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMultipleHeaderSigningProof - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } + if err := m.HeadersV2.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - m.Levels[mapkey] = mapvalue iNdEx = postIndex - case 3: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HeadersV2", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SignersSlashData", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -582,11 +646,11 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.HeadersV2 == nil { - m.HeadersV2 = make(map[string]HeadersV2) + if m.SignersSlashData == nil { + m.SignersSlashData = make(map[string]SignerSlashingData) } var mapkey string - mapvalue := &HeadersV2{} + mapvalue := &SignerSlashingData{} for iNdEx < postIndex { entryPreIndex := iNdEx var wire uint64 @@ -660,7 +724,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { if postmsgIndex > l { return io.ErrUnexpectedEOF } - mapvalue = &HeadersV2{} + mapvalue = &SignerSlashingData{} if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { return err } @@ -680,7 +744,7 @@ func (m *MultipleHeaderSigningProof) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.HeadersV2[mapkey] = *mapvalue + m.SignersSlashData[mapkey] = *mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/data/slash/multipleHeaderSigningProof.proto b/data/slash/multipleHeaderSigningProof.proto index 6abf6234b..fc70fc275 100644 --- a/data/slash/multipleHeaderSigningProof.proto +++ b/data/slash/multipleHeaderSigningProof.proto @@ -8,8 +8,12 @@ option (gogoproto.stable_marshaler_all) = true; import "slash.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +message SignerSlashingData { + bytes SignedHeadersBitMap = 1; + ThreatLevel ThreatLevel = 2; +} + message MultipleHeaderSigningProof { - repeated bytes PubKeys = 1; - map Levels = 2; - map HeadersV2 = 3 [(gogoproto.nullable) = false]; + HeadersV2 HeadersV2 = 1 [(gogoproto.nullable) = false]; + map SignersSlashData = 2 [(gogoproto.nullable) = false]; } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 79647c295..3e31b013c 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -92,7 +92,14 @@ func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvided_ExpectErro } func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectError(t *testing.T) { - proof := slash.MultipleHeaderSigningProof{PubKeys: [][]byte{[]byte("pub key")}} + slashResPubKey1 := slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{}, + } + slashRes := map[string]slash.SlashingResult{ + "pubKey1": slashResPubKey1, + } + proof, _ := slash.NewMultipleSigningProof(slashRes) proofTxData, err := proof.GetProofTxData() require.Nil(t, proofTxData) @@ -100,12 +107,14 @@ func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectErro } func TestMultipleSigningProof_GetProofTxData_NilHeaderHandler_ExpectError(t *testing.T) { - proof := slash.MultipleHeaderSigningProof{ - PubKeys: [][]byte{[]byte("pub key")}, - HeadersV2: map[string]slash.HeadersV2{ - "pub key": {Headers: []*block.HeaderV2{nil}}, - }, + slashResPubKey1 := slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{nil}, } + slashRes := map[string]slash.SlashingResult{ + "pubKey1": slashResPubKey1, + } + proof, _ := slash.NewMultipleSigningProof(slashRes) proofTxData, err := proof.GetProofTxData() require.Nil(t, proofTxData) @@ -122,12 +131,15 @@ func TestMultipleSigningProof_GetProofTxData(t *testing.T) { ShardID: shardID, }, } - proof := slash.MultipleHeaderSigningProof{ - PubKeys: [][]byte{[]byte("pub key")}, - HeadersV2: map[string]slash.HeadersV2{ - "pub key": {Headers: []*block.HeaderV2{header}}, - }, + slashResPubKey1 := slash.SlashingResult{ + SlashingLevel: slash.High, + Headers: []data.HeaderInfoHandler{&dataMock.HeaderInfoStub{Header: header, Hash: []byte("hash")}}, } + slashRes := map[string]slash.SlashingResult{ + "pubKey1": slashResPubKey1, + } + proof, _ := slash.NewMultipleSigningProof(slashRes) + expectedProofTxData := &slash.ProofTxData{ Round: round, ShardID: shardID, From c7fc737ce1f1de1be97c1cdd4e590cd03360cd9e Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 18 Nov 2021 16:47:05 +0200 Subject: [PATCH 29/54] FEAT: Make existing tests pass --- core/sliceUtil/sliceUtil.go | 12 +++ core/sliceUtil/sliceUtil_test.go | 22 ++++++ data/slash/multipleHeaderSigningProof.go | 73 +++++-------------- data/slash/multipleHeaderSigningProof_test.go | 14 ++-- 4 files changed, 57 insertions(+), 64 deletions(-) diff --git a/core/sliceUtil/sliceUtil.go b/core/sliceUtil/sliceUtil.go index 9b38f5d59..1ae5a1d6b 100644 --- a/core/sliceUtil/sliceUtil.go +++ b/core/sliceUtil/sliceUtil.go @@ -23,3 +23,15 @@ func IsIndexSetInBitmap(index uint32, bitmap []byte) bool { mask := uint8(1 << bitPos) return (byteInMap & mask) != 0 } + +func SetIndexInBitmap(index uint32, bitmap []byte) { + indexOutOfBounds := index >= uint32(len(bitmap))*8 + if indexOutOfBounds { + return + } + + bytePos := index / 8 + bitPos := index % 8 + mask := uint8(1 << bitPos) + bitmap[bytePos] |= mask +} diff --git a/core/sliceUtil/sliceUtil_test.go b/core/sliceUtil/sliceUtil_test.go index 4ca4d0312..54a7bbb69 100644 --- a/core/sliceUtil/sliceUtil_test.go +++ b/core/sliceUtil/sliceUtil_test.go @@ -75,3 +75,25 @@ func TestIsIndexSetInBitmap(t *testing.T) { require.False(t, sliceUtil.IsIndexSetInBitmap(i, bitmap)) } } + +func TestSetIndexInBitmap(t *testing.T) { + byte1Map, _ := strconv.ParseInt("11001101", 2, 9) + byte2Map, _ := strconv.ParseInt("00000101", 2, 9) + expectedBitMap := []byte{byte(byte1Map), byte(byte2Map)} + + bitMap := make([]byte, 2) + + sliceUtil.SetIndexInBitmap(0, bitMap) + sliceUtil.SetIndexInBitmap(2, bitMap) + sliceUtil.SetIndexInBitmap(3, bitMap) + sliceUtil.SetIndexInBitmap(6, bitMap) + sliceUtil.SetIndexInBitmap(7, bitMap) + sliceUtil.SetIndexInBitmap(8, bitMap) + sliceUtil.SetIndexInBitmap(10, bitMap) + + for i := uint32(16); i <= 100; i++ { + sliceUtil.SetIndexInBitmap(i, bitMap) + } + + require.Equal(t, expectedBitMap, bitMap) +} diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 3b9609b4e..cface3618 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -2,8 +2,6 @@ package slash import ( - "sort" - "github.com/ElrondNetwork/elrond-go-core/core/check" "github.com/ElrondNetwork/elrond-go-core/core/sliceUtil" "github.com/ElrondNetwork/elrond-go-core/data" @@ -94,7 +92,10 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig return nil, data.ErrNilSlashResult } - headersInfo := getAllUniqueHeaders(slashResult) + headersInfo, err := getAllUniqueHeaders(slashResult) + if err != nil { + return nil, err + } sortHeadersByHash(headersInfo) idx := uint32(0) @@ -108,11 +109,15 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig signersSlashData := make(map[string]SignerSlashingData) for pubKey, res := range slashResult { - bitmap := make([]byte, 0) + bitMapLen := 1 + if len(sortedHeaders) > 8 { + bitMapLen = len(sortedHeaders) / 8 + } + bitmap := make([]byte, bitMapLen) for _, header := range res.Headers { index, exists := hashIndexMap[string(header.GetHash())] if exists { - SetIndexInBitmap(index, bitmap) + sliceUtil.SetIndexInBitmap(index, bitmap) } } signersSlashData[pubKey] = SignerSlashingData{ @@ -122,7 +127,7 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig } headersV2 := HeadersV2{} - err := headersV2.SetHeaders(sortedHeaders) + err = headersV2.SetHeaders(sortedHeaders) if err != nil { return nil, err } @@ -132,25 +137,17 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig }, nil } -func getSortedPubKeys(slashResult map[string]SlashingResult) []string { - sortedPubKeys := make([]string, 0, len(slashResult)) - - for pubKey := range slashResult { - sortedPubKeys = append(sortedPubKeys, pubKey) - } - sort.Strings(sortedPubKeys) - - return sortedPubKeys -} - -func getAllUniqueHeaders(slashResult map[string]SlashingResult) []data.HeaderInfoHandler { +func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderInfoHandler, error) { headersInfo := make([]data.HeaderInfoHandler, 0, len(slashResult)) hashes := make(map[string]struct{}) for _, res := range slashResult { for _, currHeaderInfo := range res.Headers { - currHash := string(currHeaderInfo.GetHash()) + if currHeaderInfo == nil { + return nil, data.ErrNilHeaderInfo + } + currHash := string(currHeaderInfo.GetHash()) _, exists := hashes[currHash] if exists { continue @@ -161,41 +158,5 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) []data.HeaderInf } } - return headersInfo -} - -func getAllHeadersSorted(slashResult map[string]SlashingResult) (HeadersV2, error) { - headersInfo := getAllUniqueHeaders(slashResult) - sortHeadersByHash(headersInfo) - - idx := uint32(0) - hashIndexMap := make(map[string]uint32) - sortedHeaders := make([]data.HeaderHandler, 0, len(headersInfo)) - for _, headerInfo := range headersInfo { - hashIndexMap[string(headerInfo.GetHash())] = idx - sortedHeaders = append(sortedHeaders, headerInfo.GetHeaderHandler()) - idx++ - } - - signersSlashData := make(map[string]SignerSlashingData) - for pubKey, res := range slashResult { - bitmap := make([]byte, 0) - for _, header := range res.Headers { - index, exists := hashIndexMap[string(header.GetHash())] - if exists { - SetIndexInBitmap(index, bitmap) - } - } - signersSlashData[pubKey] = SignerSlashingData{ - SignedHeadersBitMap: bitmap, - ThreatLevel: res.SlashingLevel, - } - } - headersV2 := HeadersV2{} - - return headersV2, headersV2.SetHeaders(sortedHeaders) -} - -func SetIndexInBitmap(idx uint32, bitmap []byte) { - + return headersInfo, nil } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 3e31b013c..458d0da0d 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -24,7 +24,7 @@ func TestNewMultipleSigningProof(t *testing.T) { args: map[string]slash.SlashingResult{ "pubKey": {Headers: nil}, }, - expectedErr: data.ErrNilHeaderInfoList, + expectedErr: nil, //data.ErrNilHeaderInfoList, }, { args: map[string]slash.SlashingResult{ @@ -107,14 +107,12 @@ func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectErro } func TestMultipleSigningProof_GetProofTxData_NilHeaderHandler_ExpectError(t *testing.T) { - slashResPubKey1 := slash.SlashingResult{ - SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{nil}, - } - slashRes := map[string]slash.SlashingResult{ - "pubKey1": slashResPubKey1, + proof := &slash.MultipleHeaderSigningProof{ + HeadersV2: slash.HeadersV2{Headers: []*block.HeaderV2{nil}}, + SignersSlashData: map[string]slash.SignerSlashingData{ + "pubKey1": {SignedHeadersBitMap: []byte{0x1}}, + }, } - proof, _ := slash.NewMultipleSigningProof(slashRes) proofTxData, err := proof.GetProofTxData() require.Nil(t, proofTxData) From 96c87c40cfb099759eacea6bbcc5cd279728f337 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 18 Nov 2021 18:08:57 +0200 Subject: [PATCH 30/54] FEAT: Extend tests --- data/slash/common.go | 4 +- .../slash/multipleHeaderProposalProof_test.go | 15 ++++-- data/slash/multipleHeaderSigningProof.go | 8 ++- data/slash/multipleHeaderSigningProof_test.go | 50 +++++++++++++------ 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 2c5eab023..b10113ba3 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -64,7 +64,9 @@ func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) func sortHeadersByHash(headersInfo []data.HeaderInfoHandler) { sortFunc := func(i, j int) bool { - // TODO: CHECK IF INTERFACE IS NIL + if headersInfo[i] == nil || headersInfo[j] == nil { + return false + } hash1 := string(headersInfo[i].GetHash()) hash2 := string(headersInfo[j].GetHash()) diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 21c157bcf..fdc7efabb 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -21,15 +21,24 @@ func TestNewMultipleProposalProof(t *testing.T) { expectedErr: data.ErrNilSlashResult, }, { - args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: nil}, + args: &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: nil, + }, expectedErr: data.ErrNilHeaderInfoList, }, { - args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{nil}}, + args: &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{nil, &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}, nil}, + }, expectedErr: data.ErrNilHeaderInfo, }, { - args: &slash.SlashingResult{SlashingLevel: slash.Medium, Headers: []data.HeaderInfoHandler{}}, + args: &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{}, + }, expectedErr: nil, }, } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index cface3618..84a0de955 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -108,11 +108,8 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig } signersSlashData := make(map[string]SignerSlashingData) + bitMapLen := len(sortedHeaders)/8 + 1 for pubKey, res := range slashResult { - bitMapLen := 1 - if len(sortedHeaders) > 8 { - bitMapLen = len(sortedHeaders) / 8 - } bitmap := make([]byte, bitMapLen) for _, header := range res.Headers { index, exists := hashIndexMap[string(header.GetHash())] @@ -125,12 +122,13 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig ThreatLevel: res.SlashingLevel, } } - headersV2 := HeadersV2{} + headersV2 := HeadersV2{} err = headersV2.SetHeaders(sortedHeaders) if err != nil { return nil, err } + return &MultipleHeaderSigningProof{ HeadersV2: headersV2, SignersSlashData: signersSlashData, diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 458d0da0d..c6b4623a8 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -24,7 +24,7 @@ func TestNewMultipleSigningProof(t *testing.T) { args: map[string]slash.SlashingResult{ "pubKey": {Headers: nil}, }, - expectedErr: nil, //data.ErrNilHeaderInfoList, + expectedErr: nil, }, { args: map[string]slash.SlashingResult{ @@ -44,26 +44,35 @@ func TestNewMultipleSigningProof(t *testing.T) { } } -func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { +func TestMultipleSigningProof_GetHeaders_GetLevel(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} + h4 := &block.HeaderV2{Header: &block.Header{TimeStamp: 4}} + h5 := &block.HeaderV2{Header: &block.Header{TimeStamp: 5}} hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} hInfo3 := &dataMock.HeaderInfoStub{Header: h3, Hash: []byte("h3")} + hInfo4 := &dataMock.HeaderInfoStub{Header: h4, Hash: []byte("h4")} + hInfo5 := &dataMock.HeaderInfoStub{Header: h5, Hash: []byte("h5")} slashRes1 := slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + Headers: []data.HeaderInfoHandler{hInfo4, hInfo2, hInfo1, hInfo3}, } slashRes2 := slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{hInfo3}, + Headers: []data.HeaderInfoHandler{hInfo3, hInfo5, hInfo4}, + } + slashRes3 := slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: nil, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashRes1, "pubKey2": slashRes2, + "pubKey3": slashRes3, } proof, err := slash.NewMultipleSigningProof(slashRes) @@ -71,19 +80,25 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey1"))) require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey2"))) - require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey3"))) + require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey3"))) + require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey4"))) - require.Len(t, proof.GetHeaders([]byte("pubKey1")), 2) - require.Len(t, proof.GetHeaders([]byte("pubKey2")), 1) + require.Len(t, proof.GetHeaders([]byte("pubKey1")), 4) + require.Len(t, proof.GetHeaders([]byte("pubKey2")), 3) require.Len(t, proof.GetHeaders([]byte("pubKey3")), 0) + require.Len(t, proof.GetHeaders([]byte("pubKey4")), 0) require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[0], h1) require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[1], h2) + require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[2], h3) + require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[3], h4) require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[0], h3) - require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) + require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[1], h4) + require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[2], h5) + require.Nil(t, proof.GetHeaders([]byte("pubKey4"))) } -func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvided_ExpectError(t *testing.T) { +func TestMultipleSigningProof_GetProofTxData_NotEnoughPublicKeysProvided_ExpectError(t *testing.T) { proof := slash.MultipleHeaderSigningProof{} proofTxData, err := proof.GetProofTxData() @@ -129,9 +144,14 @@ func TestMultipleSigningProof_GetProofTxData(t *testing.T) { ShardID: shardID, }, } + headerInfo := &dataMock.HeaderInfoStub{ + Header: header, + Hash: []byte("hash"), + } + slashResPubKey1 := slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{&dataMock.HeaderInfoStub{Header: header, Hash: []byte("hash")}}, + Headers: []data.HeaderInfoHandler{headerInfo}, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashResPubKey1, @@ -154,19 +174,21 @@ func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} h4 := &block.HeaderV2{Header: &block.Header{TimeStamp: 4}} + h5 := &block.HeaderV2{Header: &block.Header{TimeStamp: 5}} hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} hInfo3 := &dataMock.HeaderInfoStub{Header: h3, Hash: []byte("h3")} hInfo4 := &dataMock.HeaderInfoStub{Header: h4, Hash: []byte("h4")} + hInfo5 := &dataMock.HeaderInfoStub{Header: h5, Hash: []byte("h5")} slashResPubKey1 := slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + Headers: []data.HeaderInfoHandler{hInfo1, hInfo2, hInfo3}, } slashResPubKey2 := slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{hInfo3, hInfo4}, + Headers: []data.HeaderInfoHandler{hInfo3, hInfo4, hInfo5}, } slashResProof1 := map[string]slash.SlashingResult{ "pubKey1": slashResPubKey1, @@ -176,12 +198,12 @@ func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { // Same slash result for pubKey1, but change headers order slashResPubKey1 = slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{hInfo2, hInfo1}, + Headers: []data.HeaderInfoHandler{hInfo3, hInfo1, hInfo2}, } // Same slash result for pubKey2, but change headers order slashResPubKey2 = slash.SlashingResult{ SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{hInfo4, hInfo3}, + Headers: []data.HeaderInfoHandler{hInfo4, hInfo3, hInfo5}, } // Change pub keys order in map From 7670733cd03ba00edc9dde771b76991e8b5fa418 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 18 Nov 2021 18:14:19 +0200 Subject: [PATCH 31/54] FIX: Replace magic number --- data/slash/multipleHeaderSigningProof.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 84a0de955..098c0bd99 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -7,6 +7,8 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) +const byteSize = 8 + // GetPubKeys - returns all validator's public keys which have signed multiple headers func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { if m == nil { @@ -108,7 +110,7 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig } signersSlashData := make(map[string]SignerSlashingData) - bitMapLen := len(sortedHeaders)/8 + 1 + bitMapLen := len(sortedHeaders)/byteSize + 1 for pubKey, res := range slashResult { bitmap := make([]byte, bitMapLen) for _, header := range res.Headers { From 0ea483518a385f2f2d4f30a2079f3132c2f90da1 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 19 Nov 2021 17:28:25 +0200 Subject: [PATCH 32/54] FIX: General refactor --- core/sliceUtil/sliceUtil.go | 32 +++++---- data/errors.go | 3 + data/slash/common.go | 20 ++++-- data/slash/common_test.go | 65 ++++++++++++++----- data/slash/multipleHeaderProposalProof.go | 10 ++- .../slash/multipleHeaderProposalProof_test.go | 19 +++++- data/slash/multipleHeaderSigningProof.go | 9 ++- data/slash/multipleHeaderSigningProof_test.go | 21 +++++- 8 files changed, 134 insertions(+), 45 deletions(-) diff --git a/core/sliceUtil/sliceUtil.go b/core/sliceUtil/sliceUtil.go index 1ae5a1d6b..70df2d32d 100644 --- a/core/sliceUtil/sliceUtil.go +++ b/core/sliceUtil/sliceUtil.go @@ -12,26 +12,36 @@ func TrimSliceSliceByte(in [][]byte) [][]byte { // IsIndexSetInBitmap - checks if a bit is set(1) in the given bitmap func IsIndexSetInBitmap(index uint32, bitmap []byte) bool { - indexOutOfBounds := index >= uint32(len(bitmap))*8 - if indexOutOfBounds { + if isIndexOutOfBounds(index, bitmap) { return false } - bytePos := index / 8 - byteInMap := bitmap[bytePos] - bitPos := index % 8 - mask := uint8(1 << bitPos) - return (byteInMap & mask) != 0 + byteInMap := getByteAtIndex(index, bitmap) + mask := calcByteMask(index) + return (*byteInMap & mask) != 0 } func SetIndexInBitmap(index uint32, bitmap []byte) { - indexOutOfBounds := index >= uint32(len(bitmap))*8 - if indexOutOfBounds { + if isIndexOutOfBounds(index, bitmap) { return } + byteInMap := getByteAtIndex(index, bitmap) + mask := calcByteMask(index) + *byteInMap |= mask +} + +// Could panic. Do not call this unless you check before if isIndexOutOfBounds == false +func getByteAtIndex(index uint32, bitmap []byte) *byte { bytePos := index / 8 + return &bitmap[bytePos] +} + +func calcByteMask(index uint32) byte { bitPos := index % 8 - mask := uint8(1 << bitPos) - bitmap[bytePos] |= mask + return 1 << bitPos +} + +func isIndexOutOfBounds(index uint32, bitmap []byte) bool { + return index >= uint32(len(bitmap))*8 } diff --git a/data/errors.go b/data/errors.go index af7c34d76..b9e9ffda7 100644 --- a/data/errors.go +++ b/data/errors.go @@ -94,6 +94,9 @@ var ErrNilHeaderInfo = errors.New("nil header info") // ErrNilHash signals that a nil hash has been provided var ErrNilHash = errors.New("nil hash provided") +// ErrHeadersSameHash signals that headers have the same hash in a multiple header proof +var ErrHeadersSameHash = errors.New("headers have the same hash in a multiple header proof") + // ErrNotEnoughHeadersProvided signals that not enough headers have been provided for a multiple header proof var ErrNotEnoughHeadersProvided = errors.New("not enough headers have been provided for a multiple header proof") diff --git a/data/slash/common.go b/data/slash/common.go index b10113ba3..9b86e8858 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -34,32 +34,38 @@ const ( MultipleSigningProofID ProofID = 0x2 ) -func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (HeadersV2, error) { +func getSortedHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, error) { if headersInfo == nil { - return HeadersV2{}, data.ErrNilHeaderInfoList + return nil, data.ErrNilHeaderInfoList } sortHeadersByHash(headersInfo) headers := make([]data.HeaderHandler, 0, len(headersInfo)) + hashes := make(map[string]struct{}) for _, headerInfo := range headersInfo { if headerInfo == nil { - return HeadersV2{}, data.ErrNilHeaderInfo + return nil, data.ErrNilHeaderInfo } headerHandler := headerInfo.GetHeaderHandler() hash := headerInfo.GetHash() + hashStr := string(hash) + _, exists := hashes[hashStr] + if exists { + return nil, data.ErrHeadersSameHash + } if check.IfNil(headerHandler) { - return HeadersV2{}, data.ErrNilHeaderHandler + return nil, data.ErrNilHeaderHandler } if hash == nil { - return HeadersV2{}, data.ErrNilHash + return nil, data.ErrNilHash } headers = append(headers, headerHandler) + hashes[hashStr] = struct{}{} } - headersV2 := HeadersV2{} - return headersV2, headersV2.SetHeaders(headers) + return headers, nil } func sortHeadersByHash(headersInfo []data.HeaderInfoHandler) { diff --git a/data/slash/common_test.go b/data/slash/common_test.go index f2f59c140..9b2aa72da 100644 --- a/data/slash/common_test.go +++ b/data/slash/common_test.go @@ -10,21 +10,21 @@ import ( ) func TestGetSortedHeadersV2_NilHeaderInfoList_ExpectError(t *testing.T) { - sortedHeaders, err := getSortedHeadersV2(nil) - require.Equal(t, HeadersV2{}, sortedHeaders) + sortedHeaders, err := getSortedHeaders(nil) + require.Nil(t, sortedHeaders) require.Equal(t, data.ErrNilHeaderInfoList, err) } func TestGetSortedHeadersV2_NilHeaderInfo_ExpectError(t *testing.T) { headerInfoList := []data.HeaderInfoHandler{nil} - sortedHeaders, err := getSortedHeadersV2(headerInfoList) - require.Equal(t, HeadersV2{}, sortedHeaders) + sortedHeaders, err := getSortedHeaders(headerInfoList) + require.Nil(t, sortedHeaders) require.Equal(t, data.ErrNilHeaderInfo, err) } func TestGetSortedHeadersV2_EmptyHeaderInfoList_ExpectEmptyResult(t *testing.T) { - sortedHeaders, err := getSortedHeadersV2([]data.HeaderInfoHandler{}) - require.Equal(t, HeadersV2{}, sortedHeaders) + sortedHeaders, err := getSortedHeaders([]data.HeaderInfoHandler{}) + require.Len(t, sortedHeaders, 0) require.Nil(t, err) } @@ -35,21 +35,49 @@ func TestGetSortedHeadersV2_NilHeaderHandler_ExpectError(t *testing.T) { } headerInfoList := []data.HeaderInfoHandler{headerInfo} - sortedHeaders, err := getSortedHeadersV2(headerInfoList) - require.Equal(t, HeadersV2{}, sortedHeaders) + sortedHeaders, err := getSortedHeaders(headerInfoList) + require.Nil(t, sortedHeaders) require.Equal(t, data.ErrNilHeaderHandler, err) } +func TestGetSortedHeadersV2_HeadersSameHash_ExpectError(t *testing.T) { + header1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + header2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + header3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} + headerInfo1 := &mock.HeaderInfoStub{ + Header: header1, + Hash: []byte("hash1"), + } + headerInfo2 := &mock.HeaderInfoStub{ + Header: header2, + Hash: []byte("hash2"), + } + headerInfo3 := &mock.HeaderInfoStub{ + Header: header3, + Hash: []byte("hash2"), + } + headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2, headerInfo3} + + sortedHeaders, err := getSortedHeaders(headerInfoList) + require.Nil(t, sortedHeaders) + require.Equal(t, data.ErrHeadersSameHash, err) +} + func TestGetSortedHeadersV2_NilHash_ExpectError(t *testing.T) { - header := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} - headerInfo := &mock.HeaderInfoStub{ - Header: header, + header1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} + header2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + headerInfo1 := &mock.HeaderInfoStub{ + Header: header1, + Hash: []byte("hash"), + } + headerInfo2 := &mock.HeaderInfoStub{ + Header: header2, Hash: nil, } - headerInfoList := []data.HeaderInfoHandler{headerInfo} + headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2} - sortedHeaders, err := getSortedHeadersV2(headerInfoList) - require.Equal(t, HeadersV2{}, sortedHeaders) + sortedHeaders, err := getSortedHeaders(headerInfoList) + require.Nil(t, sortedHeaders) require.Equal(t, data.ErrNilHash, err) } @@ -72,9 +100,10 @@ func TestGetSortedHeadersV2(t *testing.T) { } headersInfo := []data.HeaderInfoHandler{hInfo3, hInfo1, hInfo2} - sortedHeaders, _ := getSortedHeadersV2(headersInfo) + sortedHeaders, err := getSortedHeaders(headersInfo) + require.Nil(t, err) - require.Equal(t, h1, sortedHeaders.Headers[0]) - require.Equal(t, h2, sortedHeaders.Headers[1]) - require.Equal(t, h3, sortedHeaders.Headers[2]) + require.Equal(t, h1, sortedHeaders[0]) + require.Equal(t, h2, sortedHeaders[1]) + require.Equal(t, h3, sortedHeaders[2]) } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index 8b70ad14d..a17e2fbe8 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -44,13 +44,19 @@ func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProo return nil, data.ErrNilHeaderInfoList } - sortedHeaders, err := getSortedHeadersV2(slashResult.Headers) + sortedHeaders, err := getSortedHeaders(slashResult.Headers) + if err != nil { + return nil, err + } + + headersV2 := HeadersV2{} + err = headersV2.SetHeaders(sortedHeaders) if err != nil { return nil, err } return &MultipleHeaderProposalProof{ Level: slashResult.SlashingLevel, - HeadersV2: sortedHeaders, + HeadersV2: headersV2, }, nil } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index fdc7efabb..465ce633a 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -30,10 +30,20 @@ func TestNewMultipleProposalProof(t *testing.T) { { args: &slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{nil, &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}, nil}, + Headers: []data.HeaderInfoHandler{nil, &dataMock.HeaderInfoStub{}, nil}, }, expectedErr: data.ErrNilHeaderInfo, }, + { + args: &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{ + &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}, + &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}, + }, + }, + expectedErr: data.ErrHeadersSameHash, + }, { args: &slash.SlashingResult{ SlashingLevel: slash.Medium, @@ -52,22 +62,25 @@ func TestNewMultipleProposalProof(t *testing.T) { func TestMultipleProposalProof_GetHeaders_GetLevel(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} hInfo1 := &dataMock.HeaderInfoStub{Header: h1, Hash: []byte("h1")} hInfo2 := &dataMock.HeaderInfoStub{Header: h2, Hash: []byte("h2")} + hInfo3 := &dataMock.HeaderInfoStub{Header: h3, Hash: []byte("h3")} slashRes := &slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{hInfo1, hInfo2}, + Headers: []data.HeaderInfoHandler{hInfo2, hInfo1, hInfo3}, } proof, err := slash.NewMultipleProposalProof(slashRes) require.Nil(t, err) require.Equal(t, slash.Medium, proof.GetLevel()) - require.Len(t, proof.GetHeaders(), 2) + require.Len(t, proof.GetHeaders(), 3) require.Equal(t, proof.GetHeaders()[0], h1) require.Equal(t, proof.GetHeaders()[1], h2) + require.Equal(t, proof.GetHeaders()[2], h3) } func TestMultipleHeaderProposalProof_GetProofTxData_NotEnoughHeaders_ExpectError(t *testing.T) { diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 098c0bd99..db93ff882 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -142,18 +142,25 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn hashes := make(map[string]struct{}) for _, res := range slashResult { + hashesPerPubKey := make(map[string]struct{}) for _, currHeaderInfo := range res.Headers { if currHeaderInfo == nil { return nil, data.ErrNilHeaderInfo } currHash := string(currHeaderInfo.GetHash()) - _, exists := hashes[currHash] + _, exists := hashesPerPubKey[currHash] + if exists { + return nil, data.ErrHeadersSameHash + } + + _, exists = hashes[currHash] if exists { continue } hashes[currHash] = struct{}{} + hashesPerPubKey[currHash] = struct{}{} headersInfo = append(headersInfo, currHeaderInfo) } } diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index c6b4623a8..683fb299a 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -32,6 +32,15 @@ func TestNewMultipleSigningProof(t *testing.T) { }, expectedErr: data.ErrNilHeaderInfo, }, + { + args: map[string]slash.SlashingResult{ + "pubKey": {Headers: []data.HeaderInfoHandler{ + &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}, + &dataMock.HeaderInfoStub{Header: &block.HeaderV2{}, Hash: []byte("h")}}, + }, + }, + expectedErr: data.ErrHeadersSameHash, + }, { args: make(map[string]slash.SlashingResult), expectedErr: nil, @@ -66,13 +75,18 @@ func TestMultipleSigningProof_GetHeaders_GetLevel(t *testing.T) { Headers: []data.HeaderInfoHandler{hInfo3, hInfo5, hInfo4}, } slashRes3 := slash.SlashingResult{ - SlashingLevel: slash.Medium, + SlashingLevel: slash.Zero, + Headers: []data.HeaderInfoHandler{}, + } + slashRes4 := slash.SlashingResult{ + SlashingLevel: slash.Zero, Headers: nil, } slashRes := map[string]slash.SlashingResult{ "pubKey1": slashRes1, "pubKey2": slashRes2, "pubKey3": slashRes3, + "pubKey4": slashRes4, } proof, err := slash.NewMultipleSigningProof(slashRes) @@ -80,13 +94,15 @@ func TestMultipleSigningProof_GetHeaders_GetLevel(t *testing.T) { require.Equal(t, slash.High, proof.GetLevel([]byte("pubKey1"))) require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey2"))) - require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey3"))) + require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey3"))) require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey4"))) + require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey5"))) require.Len(t, proof.GetHeaders([]byte("pubKey1")), 4) require.Len(t, proof.GetHeaders([]byte("pubKey2")), 3) require.Len(t, proof.GetHeaders([]byte("pubKey3")), 0) require.Len(t, proof.GetHeaders([]byte("pubKey4")), 0) + require.Len(t, proof.GetHeaders([]byte("pubKey5")), 0) require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[0], h1) require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[1], h2) @@ -95,7 +111,6 @@ func TestMultipleSigningProof_GetHeaders_GetLevel(t *testing.T) { require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[0], h3) require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[1], h4) require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[2], h5) - require.Nil(t, proof.GetHeaders([]byte("pubKey4"))) } func TestMultipleSigningProof_GetProofTxData_NotEnoughPublicKeysProvided_ExpectError(t *testing.T) { From df5e3135c3a8b9d243ccdee8d4a0e91186887d32 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 22 Nov 2021 09:55:51 +0200 Subject: [PATCH 33/54] FIX: General refactor --- data/slash/common_test.go | 10 +++++----- data/slash/multipleHeaderProposalProof.go | 1 + data/slash/multipleHeaderProposalProof_test.go | 8 ++++---- data/slash/multipleHeaderSigningProof.go | 1 + data/slash/multipleHeaderSigningProof_test.go | 10 +++++----- data/slash/slash_test.go | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/data/slash/common_test.go b/data/slash/common_test.go index f2f59c140..17852d1dd 100644 --- a/data/slash/common_test.go +++ b/data/slash/common_test.go @@ -9,26 +9,26 @@ import ( "github.com/stretchr/testify/require" ) -func TestGetSortedHeadersV2_NilHeaderInfoList_ExpectError(t *testing.T) { +func TestGetSortedHeadersV2_NilHeaderInfoListExpectError(t *testing.T) { sortedHeaders, err := getSortedHeadersV2(nil) require.Equal(t, HeadersV2{}, sortedHeaders) require.Equal(t, data.ErrNilHeaderInfoList, err) } -func TestGetSortedHeadersV2_NilHeaderInfo_ExpectError(t *testing.T) { +func TestGetSortedHeadersV2_NilHeaderInfoExpectError(t *testing.T) { headerInfoList := []data.HeaderInfoHandler{nil} sortedHeaders, err := getSortedHeadersV2(headerInfoList) require.Equal(t, HeadersV2{}, sortedHeaders) require.Equal(t, data.ErrNilHeaderInfo, err) } -func TestGetSortedHeadersV2_EmptyHeaderInfoList_ExpectEmptyResult(t *testing.T) { +func TestGetSortedHeadersV2_EmptyHeaderInfoListExpectEmptyResult(t *testing.T) { sortedHeaders, err := getSortedHeadersV2([]data.HeaderInfoHandler{}) require.Equal(t, HeadersV2{}, sortedHeaders) require.Nil(t, err) } -func TestGetSortedHeadersV2_NilHeaderHandler_ExpectError(t *testing.T) { +func TestGetSortedHeadersV2_NilHeaderHandlerExpectError(t *testing.T) { headerInfo := &mock.HeaderInfoStub{ Header: nil, Hash: []byte("hash1"), @@ -40,7 +40,7 @@ func TestGetSortedHeadersV2_NilHeaderHandler_ExpectError(t *testing.T) { require.Equal(t, data.ErrNilHeaderHandler, err) } -func TestGetSortedHeadersV2_NilHash_ExpectError(t *testing.T) { +func TestGetSortedHeadersV2_NilHashExpectError(t *testing.T) { header := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} headerInfo := &mock.HeaderInfoStub{ Header: header, diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index d743d1767..a2d797265 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -23,6 +23,7 @@ func (m *MultipleHeaderProposalProof) GetHeaders() []data.HeaderHandler { return m.HeadersV2.GetHeaderHandlers() } +// GetProofTxData returns the necessary ProofTxData to issue a commitment slash tx func (m *MultipleHeaderProposalProof) GetProofTxData() (*ProofTxData, error) { if m == nil { return nil, data.ErrNilPointerReceiver diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index aec6875f5..52084b55e 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -40,7 +40,7 @@ func TestNewMultipleProposalProof(t *testing.T) { } } -func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { +func TestMultipleProposalProof_GetHeadersGetLevelGetType(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} @@ -63,7 +63,7 @@ func TestMultipleProposalProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Equal(t, proof.GetHeaders()[1], h2) } -func TestMultipleHeaderProposalProof_GetProofTxData_NotEnoughHeaders_ExpectError(t *testing.T) { +func TestMultipleHeaderProposalProof_GetProofTxDataNotEnoughHeadersExpectError(t *testing.T) { proof := slash.MultipleHeaderProposalProof{} proofTxData, err := proof.GetProofTxData() @@ -71,7 +71,7 @@ func TestMultipleHeaderProposalProof_GetProofTxData_NotEnoughHeaders_ExpectError require.Equal(t, data.ErrNotEnoughHeadersProvided, err) } -func TestMultipleHeaderProposalProof_GetProofTxData_NilHeader_ExpectError(t *testing.T) { +func TestMultipleHeaderProposalProof_GetProofTxDataNilHeaderExpectError(t *testing.T) { proof := slash.MultipleHeaderProposalProof{ HeadersV2: slash.HeadersV2{ Headers: []*block.HeaderV2{nil}, @@ -108,7 +108,7 @@ func TestMultipleHeaderProposalProof_GetProofTxData(t *testing.T) { require.Nil(t, err) } -func TestMultipleHeaderProposalProof_Marshal_Unmarshal(t *testing.T) { +func TestMultipleHeaderProposalProof_MarshalUnmarshal(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1, LeaderSignature: []byte("sig1")}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2, LeaderSignature: []byte("sig2")}} diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index a10461997..bf4af9a96 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -44,6 +44,7 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand return headersV2.GetHeaderHandlers() } +// GetProofTxData returns the necessary ProofTxData to issue a commitment slash tx func (m *MultipleHeaderSigningProof) GetProofTxData() (*ProofTxData, error) { if m == nil { return nil, data.ErrNilPointerReceiver diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 6ff254621..870e39877 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -44,7 +44,7 @@ func TestNewMultipleSigningProof(t *testing.T) { } } -func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { +func TestMultipleSigningProof_GetHeadersGetLevelGetType(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} @@ -84,7 +84,7 @@ func TestMultipleSigningProof_GetHeaders_GetLevel_GetType(t *testing.T) { require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) } -func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvided_ExpectError(t *testing.T) { +func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvidedExpectError(t *testing.T) { proof := slash.MultipleHeaderSigningProof{} proofTxData, err := proof.GetProofTxData() @@ -92,7 +92,7 @@ func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvided_ExpectErro require.Equal(t, data.ErrNotEnoughPublicKeysProvided, err) } -func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectError(t *testing.T) { +func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvidedExpectError(t *testing.T) { proof := slash.MultipleHeaderSigningProof{PubKeys: [][]byte{[]byte("pub key")}} proofTxData, err := proof.GetProofTxData() @@ -100,7 +100,7 @@ func TestMultipleSigningProof_GetProofTxData_NotEnoughHeadersProvided_ExpectErro require.Equal(t, data.ErrNotEnoughHeadersProvided, err) } -func TestMultipleSigningProof_GetProofTxData_NilHeaderHandler_ExpectError(t *testing.T) { +func TestMultipleSigningProof_GetProofTxData_NilHeaderHandlerExpectError(t *testing.T) { proof := slash.MultipleHeaderSigningProof{ PubKeys: [][]byte{[]byte("pub key")}, HeadersV2: map[string]slash.HeadersV2{ @@ -139,7 +139,7 @@ func TestMultipleSigningProof_GetProofTxData(t *testing.T) { require.Nil(t, err) } -func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { +func TestMultipleSigningProof_MarshalUnmarshal(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} diff --git a/data/slash/slash_test.go b/data/slash/slash_test.go index db7f71233..5425a6e55 100644 --- a/data/slash/slash_test.go +++ b/data/slash/slash_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestHeaders_SetHeaders_InvalidHeaders_ExpectError(t *testing.T) { +func TestHeaders_SetHeadersInvalidHeadersExpectError(t *testing.T) { header := &block.Header{TimeStamp: 1} headers := slash.HeadersV2{} @@ -17,7 +17,7 @@ func TestHeaders_SetHeaders_InvalidHeaders_ExpectError(t *testing.T) { require.Equal(t, data.ErrInvalidTypeAssertion, err) } -func TestHeaders_SetHeaders_GetHeaders_GetHeaderHandlers(t *testing.T) { +func TestHeaders_SetHeadersGetHeadersGetHeaderHandlers(t *testing.T) { header1 := &block.HeaderV2{ Header: &block.Header{ TimeStamp: 1, From cd321ae548d3b5e6adac6f8e2c63077027f58a4b Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 22 Nov 2021 12:27:40 +0200 Subject: [PATCH 34/54] FIX: General refactor pt. 2 --- data/errors.go | 4 +- data/slash/common.go | 31 +++++++-- data/slash/common_test.go | 69 ++++++++++--------- data/slash/multipleHeaderProposalProof.go | 12 +--- .../slash/multipleHeaderProposalProof_test.go | 18 ++--- data/slash/multipleHeaderSigningProof.go | 66 ++++++++++-------- data/slash/multipleHeaderSigningProof_test.go | 22 +++--- 7 files changed, 120 insertions(+), 102 deletions(-) diff --git a/data/errors.go b/data/errors.go index b9e9ffda7..4900056da 100644 --- a/data/errors.go +++ b/data/errors.go @@ -85,8 +85,8 @@ var ErrNilSlashResult = errors.New("slash result is nil") // ErrNilHeaderHandler signals that a nil header handler has been provided var ErrNilHeaderHandler = errors.New("nil header handler") -// ErrNilHeaderInfoList signals that a nil header info list has been provided -var ErrNilHeaderInfoList = errors.New("nil header info list") +// ErrEmptyHeaderInfoList signals that an empty header info list has been provided +var ErrEmptyHeaderInfoList = errors.New("empty header info list") // ErrNilHeaderInfo signals that a nil header info has been provided var ErrNilHeaderInfo = errors.New("nil header info") diff --git a/data/slash/common.go b/data/slash/common.go index 9b86e8858..761185abf 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -34,9 +34,24 @@ const ( MultipleSigningProofID ProofID = 0x2 ) -func getSortedHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, error) { - if headersInfo == nil { - return nil, data.ErrNilHeaderInfoList +func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, error) { + sortedHeaders, err := sortHeaders(headersInfo) + if err != nil { + return nil, err + } + + headersV2 := &HeadersV2{} + err = headersV2.SetHeaders(sortedHeaders) + if err != nil { + return nil, err + } + + return headersV2, nil +} + +func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, error) { + if len(headersInfo) == 0 { + return nil, data.ErrEmptyHeaderInfoList } sortHeadersByHash(headersInfo) @@ -47,19 +62,21 @@ func getSortedHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandle return nil, data.ErrNilHeaderInfo } - headerHandler := headerInfo.GetHeaderHandler() hash := headerInfo.GetHash() + if hash == nil { + return nil, data.ErrNilHash + } + hashStr := string(hash) _, exists := hashes[hashStr] if exists { return nil, data.ErrHeadersSameHash } + + headerHandler := headerInfo.GetHeaderHandler() if check.IfNil(headerHandler) { return nil, data.ErrNilHeaderHandler } - if hash == nil { - return nil, data.ErrNilHash - } headers = append(headers, headerHandler) hashes[hashStr] = struct{}{} diff --git a/data/slash/common_test.go b/data/slash/common_test.go index 87d434a9b..b82498f95 100644 --- a/data/slash/common_test.go +++ b/data/slash/common_test.go @@ -9,79 +9,79 @@ import ( "github.com/stretchr/testify/require" ) -func TestGetSortedHeadersV2_NilHeaderInfoListExpectError(t *testing.T) { - sortedHeaders, err := getSortedHeaders(nil) +func TestSortHeaders_NilHeaderInfoListExpectError(t *testing.T) { + sortedHeaders, err := sortHeaders(nil) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHeaderInfoList, err) + require.Equal(t, data.ErrEmptyHeaderInfoList, err) } -func TestGetSortedHeadersV2_NilHeaderInfoExpectError(t *testing.T) { - headerInfoList := []data.HeaderInfoHandler{nil} - sortedHeaders, err := getSortedHeaders(headerInfoList) +func TestSortHeaders_EmptyHeaderInfoListExpectEmptyResult(t *testing.T) { + sortedHeaders, err := sortHeaders([]data.HeaderInfoHandler{}) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHeaderInfo, err) + require.Equal(t, data.ErrEmptyHeaderInfoList, err) } -func TestGetSortedHeadersV2_EmptyHeaderInfoListExpectEmptyResult(t *testing.T) { - sortedHeaders, err := getSortedHeaders([]data.HeaderInfoHandler{}) - require.Len(t, sortedHeaders, 0) - require.Nil(t, err) +func TestSortHeaders_NilHeaderInfoExpectError(t *testing.T) { + headerInfoList := []data.HeaderInfoHandler{nil} + sortedHeaders, err := sortHeaders(headerInfoList) + require.Nil(t, sortedHeaders) + require.Equal(t, data.ErrNilHeaderInfo, err) } -func TestGetSortedHeadersV2_NilHeaderHandlerExpectError(t *testing.T) { +func TestSortHeaders_NilHeaderHandlerExpectError(t *testing.T) { headerInfo := &mock.HeaderInfoStub{ Header: nil, Hash: []byte("hash1"), } headerInfoList := []data.HeaderInfoHandler{headerInfo} - sortedHeaders, err := getSortedHeaders(headerInfoList) + sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) require.Equal(t, data.ErrNilHeaderHandler, err) } -func TestGetSortedHeadersV2_HeadersSameHash_ExpectError(t *testing.T) { +func TestSortHeaders_NilHashExpectError(t *testing.T) { header1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} header2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} - header3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} headerInfo1 := &mock.HeaderInfoStub{ Header: header1, - Hash: []byte("hash1"), + Hash: []byte("hash"), } headerInfo2 := &mock.HeaderInfoStub{ Header: header2, - Hash: []byte("hash2"), - } - headerInfo3 := &mock.HeaderInfoStub{ - Header: header3, - Hash: []byte("hash2"), + Hash: nil, } - headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2, headerInfo3} + headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2} - sortedHeaders, err := getSortedHeaders(headerInfoList) + sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrHeadersSameHash, err) + require.Equal(t, data.ErrNilHash, err) } -func TestGetSortedHeadersV2_NilHashExpectError(t *testing.T) { +func TestSortHeaders_HeadersSameHashExpectError(t *testing.T) { header1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} header2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} + header3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} headerInfo1 := &mock.HeaderInfoStub{ Header: header1, - Hash: []byte("hash"), + Hash: []byte("hash1"), } headerInfo2 := &mock.HeaderInfoStub{ Header: header2, - Hash: nil, + Hash: []byte("hash2"), } - headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2} + headerInfo3 := &mock.HeaderInfoStub{ + Header: header3, + Hash: []byte("hash2"), + } + headerInfoList := []data.HeaderInfoHandler{headerInfo1, headerInfo2, headerInfo3} - sortedHeaders, err := getSortedHeaders(headerInfoList) + sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHash, err) + require.Equal(t, data.ErrHeadersSameHash, err) } -func TestGetSortedHeadersV2(t *testing.T) { +func TestSortHeaders(t *testing.T) { h1 := &block.HeaderV2{Header: &block.Header{TimeStamp: 1}} h2 := &block.HeaderV2{Header: &block.Header{TimeStamp: 2}} h3 := &block.HeaderV2{Header: &block.Header{TimeStamp: 3}} @@ -100,10 +100,13 @@ func TestGetSortedHeadersV2(t *testing.T) { } headersInfo := []data.HeaderInfoHandler{hInfo3, hInfo1, hInfo2} - sortedHeaders, err := getSortedHeaders(headersInfo) + sortedHeaders, err := sortHeaders(headersInfo) require.Nil(t, err) - require.Equal(t, h1, sortedHeaders[0]) require.Equal(t, h2, sortedHeaders[1]) require.Equal(t, h3, sortedHeaders[2]) + + require.Equal(t, hInfo1, headersInfo[0]) + require.Equal(t, hInfo2, headersInfo[1]) + require.Equal(t, hInfo3, headersInfo[2]) } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index f1875efe0..2e78bf5ab 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -42,22 +42,16 @@ func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProo return nil, data.ErrNilSlashResult } if slashResult.Headers == nil { - return nil, data.ErrNilHeaderInfoList + return nil, data.ErrEmptyHeaderInfoList } - sortedHeaders, err := getSortedHeaders(slashResult.Headers) - if err != nil { - return nil, err - } - - headersV2 := HeadersV2{} - err = headersV2.SetHeaders(sortedHeaders) + sortedHeaders, err := sortAndGetHeadersV2(slashResult.Headers) if err != nil { return nil, err } return &MultipleHeaderProposalProof{ Level: slashResult.SlashingLevel, - HeadersV2: headersV2, + HeadersV2: *sortedHeaders, }, nil } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 90824e106..3c9d4d16c 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -25,12 +25,19 @@ func TestNewMultipleProposalProof(t *testing.T) { SlashingLevel: slash.Medium, Headers: nil, }, - expectedErr: data.ErrNilHeaderInfoList, + expectedErr: data.ErrEmptyHeaderInfoList, }, { args: &slash.SlashingResult{ SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{nil, &dataMock.HeaderInfoStub{}, nil}, + Headers: []data.HeaderInfoHandler{}, + }, + expectedErr: data.ErrEmptyHeaderInfoList, + }, + { + args: &slash.SlashingResult{ + SlashingLevel: slash.Medium, + Headers: []data.HeaderInfoHandler{nil, &dataMock.HeaderInfoStub{}}, }, expectedErr: data.ErrNilHeaderInfo, }, @@ -44,13 +51,6 @@ func TestNewMultipleProposalProof(t *testing.T) { }, expectedErr: data.ErrHeadersSameHash, }, - { - args: &slash.SlashingResult{ - SlashingLevel: slash.Medium, - Headers: []data.HeaderInfoHandler{}, - }, - expectedErr: nil, - }, } for _, currTest := range tests { diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 27d0a5707..80f9892b7 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -99,41 +99,16 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig if err != nil { return nil, err } - sortHeadersByHash(headersInfo) - - idx := uint32(0) - hashIndexMap := make(map[string]uint32) - sortedHeaders := make([]data.HeaderHandler, 0, len(headersInfo)) - for _, headerInfo := range headersInfo { - hashIndexMap[string(headerInfo.GetHash())] = idx - sortedHeaders = append(sortedHeaders, headerInfo.GetHeaderHandler()) - idx++ - } - - signersSlashData := make(map[string]SignerSlashingData) - bitMapLen := len(sortedHeaders)/byteSize + 1 - for pubKey, res := range slashResult { - bitmap := make([]byte, bitMapLen) - for _, header := range res.Headers { - index, exists := hashIndexMap[string(header.GetHash())] - if exists { - sliceUtil.SetIndexInBitmap(index, bitmap) - } - } - signersSlashData[pubKey] = SignerSlashingData{ - SignedHeadersBitMap: bitmap, - ThreatLevel: res.SlashingLevel, - } - } - - headersV2 := HeadersV2{} - err = headersV2.SetHeaders(sortedHeaders) + sortedHeaders, err := sortAndGetHeadersV2(headersInfo) if err != nil { return nil, err } + hashIndexMap := calcHashIndexMap(headersInfo) + signersSlashData := computeSignersSlashData(hashIndexMap, slashResult) + return &MultipleHeaderSigningProof{ - HeadersV2: headersV2, + HeadersV2: *sortedHeaders, SignersSlashData: signersSlashData, }, nil } @@ -168,3 +143,34 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn return headersInfo, nil } + +func calcHashIndexMap(headersInfo []data.HeaderInfoHandler) map[string]uint32 { + idx := uint32(0) + hashIndexMap := make(map[string]uint32) + for _, headerInfo := range headersInfo { + hashIndexMap[string(headerInfo.GetHash())] = idx + idx++ + } + + return hashIndexMap +} + +func computeSignersSlashData(hashIndexMap map[string]uint32, slashResult map[string]SlashingResult) map[string]SignerSlashingData { + signersSlashData := make(map[string]SignerSlashingData) + bitMapLen := len(hashIndexMap)/byteSize + 1 + for pubKey, res := range slashResult { + bitmap := make([]byte, bitMapLen) + for _, header := range res.Headers { + index, exists := hashIndexMap[string(header.GetHash())] + if exists { + sliceUtil.SetIndexInBitmap(index, bitmap) + } + } + signersSlashData[pubKey] = SignerSlashingData{ + SignedHeadersBitMap: bitmap, + ThreatLevel: res.SlashingLevel, + } + } + + return signersSlashData +} diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 90eb72ff1..ed552af32 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -20,11 +20,15 @@ func TestNewMultipleSigningProof(t *testing.T) { args: nil, expectedErr: data.ErrNilSlashResult, }, + { + args: make(map[string]slash.SlashingResult), + expectedErr: data.ErrEmptyHeaderInfoList, + }, { args: map[string]slash.SlashingResult{ "pubKey": {Headers: nil}, }, - expectedErr: nil, + expectedErr: data.ErrEmptyHeaderInfoList, }, { args: map[string]slash.SlashingResult{ @@ -41,10 +45,6 @@ func TestNewMultipleSigningProof(t *testing.T) { }, expectedErr: data.ErrHeadersSameHash, }, - { - args: make(map[string]slash.SlashingResult), - expectedErr: nil, - }, } for _, currTest := range tests { @@ -122,14 +122,12 @@ func TestMultipleSigningProof_GetProofTxDataNotEnoughPublicKeysProvidedExpectErr } func TestMultipleSigningProof_GetProofTxDataNotEnoughHeadersProvidedExpectError(t *testing.T) { - slashResPubKey1 := slash.SlashingResult{ - SlashingLevel: slash.High, - Headers: []data.HeaderInfoHandler{}, - } - slashRes := map[string]slash.SlashingResult{ - "pubKey1": slashResPubKey1, + proof := slash.MultipleHeaderSigningProof{ + HeadersV2: slash.HeadersV2{}, + SignersSlashData: map[string]slash.SignerSlashingData{ + "pubKey1": {}, + }, } - proof, _ := slash.NewMultipleSigningProof(slashRes) proofTxData, err := proof.GetProofTxData() require.Nil(t, proofTxData) From cfff50fa40bb6d89ec02ce1a4746ed9150a5d390 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 22 Nov 2021 14:29:19 +0200 Subject: [PATCH 35/54] FIX: Return fmt.Errorf instead of simple error --- data/slash/common.go | 11 ++++++----- data/slash/common_test.go | 13 +++++++++---- data/slash/multipleHeaderProposalProof_test.go | 4 +++- data/slash/multipleHeaderSigningProof.go | 8 +++++--- data/slash/multipleHeaderSigningProof_test.go | 4 +++- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 761185abf..899ddf775 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -1,6 +1,7 @@ package slash import ( + "fmt" "sort" "github.com/ElrondNetwork/elrond-go-core/core/check" @@ -57,25 +58,25 @@ func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, er sortHeadersByHash(headersInfo) headers := make([]data.HeaderHandler, 0, len(headersInfo)) hashes := make(map[string]struct{}) - for _, headerInfo := range headersInfo { + for idx, headerInfo := range headersInfo { if headerInfo == nil { - return nil, data.ErrNilHeaderInfo + return nil, fmt.Errorf("%w in sorted headers at index: %v", data.ErrNilHeaderInfo, idx) } hash := headerInfo.GetHash() if hash == nil { - return nil, data.ErrNilHash + return nil, fmt.Errorf("%w in sorted headers at index: %v", data.ErrNilHash, idx) } hashStr := string(hash) _, exists := hashes[hashStr] if exists { - return nil, data.ErrHeadersSameHash + return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hashStr) } headerHandler := headerInfo.GetHeaderHandler() if check.IfNil(headerHandler) { - return nil, data.ErrNilHeaderHandler + return nil, fmt.Errorf("%w in sorted headers for hash: %s", data.ErrNilHeaderHandler, hashStr) } headers = append(headers, headerHandler) diff --git a/data/slash/common_test.go b/data/slash/common_test.go index b82498f95..c6d88dc33 100644 --- a/data/slash/common_test.go +++ b/data/slash/common_test.go @@ -1,6 +1,7 @@ package slash import ( + "strings" "testing" "github.com/ElrondNetwork/elrond-go-core/data" @@ -25,7 +26,8 @@ func TestSortHeaders_NilHeaderInfoExpectError(t *testing.T) { headerInfoList := []data.HeaderInfoHandler{nil} sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHeaderInfo, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), data.ErrNilHeaderInfo.Error())) } func TestSortHeaders_NilHeaderHandlerExpectError(t *testing.T) { @@ -37,7 +39,8 @@ func TestSortHeaders_NilHeaderHandlerExpectError(t *testing.T) { sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHeaderHandler, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), data.ErrNilHeaderHandler.Error())) } func TestSortHeaders_NilHashExpectError(t *testing.T) { @@ -55,7 +58,8 @@ func TestSortHeaders_NilHashExpectError(t *testing.T) { sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrNilHash, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), data.ErrNilHash.Error())) } func TestSortHeaders_HeadersSameHashExpectError(t *testing.T) { @@ -78,7 +82,8 @@ func TestSortHeaders_HeadersSameHashExpectError(t *testing.T) { sortedHeaders, err := sortHeaders(headerInfoList) require.Nil(t, sortedHeaders) - require.Equal(t, data.ErrHeadersSameHash, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), data.ErrHeadersSameHash.Error())) } func TestSortHeaders(t *testing.T) { diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 3c9d4d16c..65bb6afe8 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -1,6 +1,7 @@ package slash_test import ( + "strings" "testing" "github.com/ElrondNetwork/elrond-go-core/data" @@ -55,7 +56,8 @@ func TestNewMultipleProposalProof(t *testing.T) { for _, currTest := range tests { _, err := slash.NewMultipleProposalProof(currTest.args) - require.Equal(t, currTest.expectedErr, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), currTest.expectedErr.Error())) } } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 80f9892b7..16588f851 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -2,6 +2,8 @@ package slash import ( + "fmt" + "github.com/ElrondNetwork/elrond-go-core/core/check" "github.com/ElrondNetwork/elrond-go-core/core/sliceUtil" "github.com/ElrondNetwork/elrond-go-core/data" @@ -117,17 +119,17 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn headersInfo := make([]data.HeaderInfoHandler, 0, len(slashResult)) hashes := make(map[string]struct{}) - for _, res := range slashResult { + for pubKey, res := range slashResult { hashesPerPubKey := make(map[string]struct{}) for _, currHeaderInfo := range res.Headers { if currHeaderInfo == nil { - return nil, data.ErrNilHeaderInfo + return nil, fmt.Errorf("%w in slash result for multiple header signing proof for public key: %s", data.ErrNilHeaderInfo, pubKey) } currHash := string(currHeaderInfo.GetHash()) _, exists := hashesPerPubKey[currHash] if exists { - return nil, data.ErrHeadersSameHash + return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, currHash) } _, exists = hashes[currHash] diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index ed552af32..e9824fb41 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -1,6 +1,7 @@ package slash_test import ( + "strings" "testing" "github.com/ElrondNetwork/elrond-go-core/data" @@ -49,7 +50,8 @@ func TestNewMultipleSigningProof(t *testing.T) { for _, currTest := range tests { _, err := slash.NewMultipleSigningProof(currTest.args) - require.Equal(t, currTest.expectedErr, err) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), currTest.expectedErr.Error())) } } From d8124e491bc9a5302c7581d3853e574bef800593 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 22 Nov 2021 16:47:25 +0200 Subject: [PATCH 36/54] FEAT: Add initial benchmark --- data/slash/multipleHeaderSigningProof_test.go | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index e9824fb41..cbcf8c804 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -1,9 +1,12 @@ package slash_test import ( + "fmt" "strings" "testing" + "github.com/ElrondNetwork/elrond-go-core/core" + "github.com/ElrondNetwork/elrond-go-core/core/mock" "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" @@ -249,3 +252,45 @@ func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { require.Equal(t, proof1Unmarshalled, proof1) require.Equal(t, proof2Unmarshalled, proof2) } + +func BenchmarkNewMultipleSigningProof(b *testing.B) { + // Worst case scenario: 25% of a consensus group of 400 validators on metachain + noOfPubKeys := uint32(0.25 * 400) + noOfHeaders := uint32(3) + slashRes := generateSlashResults(b, noOfPubKeys, noOfHeaders) + + for n := 0; n < b.N; n++ { + proof, err := slash.NewMultipleSigningProof(slashRes) + + b.StopTimer() + require.NotNil(b, proof) + require.Nil(b, err) + b.StartTimer() + } +} + +func generateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) map[string]slash.SlashingResult { + hasher := &mock.HasherMock{} + marshaller := &marshal.GogoProtoMarshalizer{} + + headers := make([]data.HeaderInfoHandler, 0, noOfHeaders) + for i := 0; i < int(noOfHeaders); i++ { + header := &block.HeaderV2{Header: &block.Header{Round: 1, TimeStamp: uint64(i)}} + hash, err := core.CalculateHash(marshaller, hasher, header) + require.Nil(b, err) + + headerInfo := &dataMock.HeaderInfoStub{Header: header, Hash: hash} + headers = append(headers, headerInfo) + } + + slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) + for i := 0; i < int(noOfPubKeys); i++ { + tmp := fmt.Sprintf("pubKey%v", i) + pubKey := hasher.Compute(tmp) + slashRes[string(pubKey)] = slash.SlashingResult{ + Headers: headers, + } + } + + return slashRes +} From 1ab31315cf53b8568736ac81c094a0896115b267 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 22 Nov 2021 17:56:59 +0200 Subject: [PATCH 37/54] FIX: Error sprintf --- data/slash/common.go | 5 +++-- data/slash/multipleHeaderSigningProof.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 899ddf775..24f5d4944 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -1,6 +1,7 @@ package slash import ( + "encoding/hex" "fmt" "sort" @@ -71,12 +72,12 @@ func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, er hashStr := string(hash) _, exists := hashes[hashStr] if exists { - return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hashStr) + return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(hash)) } headerHandler := headerInfo.GetHeaderHandler() if check.IfNil(headerHandler) { - return nil, fmt.Errorf("%w in sorted headers for hash: %s", data.ErrNilHeaderHandler, hashStr) + return nil, fmt.Errorf("%w in sorted headers for hash: %s", data.ErrNilHeaderHandler, hex.EncodeToString(hash)) } headers = append(headers, headerHandler) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 16588f851..b645c80f4 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -2,6 +2,7 @@ package slash import ( + "encoding/hex" "fmt" "github.com/ElrondNetwork/elrond-go-core/core/check" @@ -123,13 +124,14 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn hashesPerPubKey := make(map[string]struct{}) for _, currHeaderInfo := range res.Headers { if currHeaderInfo == nil { - return nil, fmt.Errorf("%w in slash result for multiple header signing proof for public key: %s", data.ErrNilHeaderInfo, pubKey) + return nil, fmt.Errorf("%w in slash result for multiple header signing proof for public key: %s", + data.ErrNilHeaderInfo, hex.EncodeToString([]byte(pubKey))) } currHash := string(currHeaderInfo.GetHash()) _, exists := hashesPerPubKey[currHash] if exists { - return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, currHash) + return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(currHeaderInfo.GetHash())) } _, exists = hashes[currHash] From 2923ca0cc5efa2b37c24a12f222067acaeae5b90 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 23 Nov 2021 09:59:08 +0200 Subject: [PATCH 38/54] FIX: Add generator file in testscommon --- data/slash/multipleHeaderSigningProof_test.go | 32 +-------------- data/testscommon/slash/generator.go | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 data/testscommon/slash/generator.go diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index cbcf8c804..9f3180343 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -1,16 +1,14 @@ package slash_test import ( - "fmt" "strings" "testing" - "github.com/ElrondNetwork/elrond-go-core/core" - "github.com/ElrondNetwork/elrond-go-core/core/mock" "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" "github.com/ElrondNetwork/elrond-go-core/data/slash" + testscommon "github.com/ElrondNetwork/elrond-go-core/data/testscommon/slash" "github.com/ElrondNetwork/elrond-go-core/marshal" "github.com/stretchr/testify/require" ) @@ -257,7 +255,7 @@ func BenchmarkNewMultipleSigningProof(b *testing.B) { // Worst case scenario: 25% of a consensus group of 400 validators on metachain noOfPubKeys := uint32(0.25 * 400) noOfHeaders := uint32(3) - slashRes := generateSlashResults(b, noOfPubKeys, noOfHeaders) + slashRes := testscommon.GenerateSlashResults(b, noOfPubKeys, noOfHeaders) for n := 0; n < b.N; n++ { proof, err := slash.NewMultipleSigningProof(slashRes) @@ -268,29 +266,3 @@ func BenchmarkNewMultipleSigningProof(b *testing.B) { b.StartTimer() } } - -func generateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) map[string]slash.SlashingResult { - hasher := &mock.HasherMock{} - marshaller := &marshal.GogoProtoMarshalizer{} - - headers := make([]data.HeaderInfoHandler, 0, noOfHeaders) - for i := 0; i < int(noOfHeaders); i++ { - header := &block.HeaderV2{Header: &block.Header{Round: 1, TimeStamp: uint64(i)}} - hash, err := core.CalculateHash(marshaller, hasher, header) - require.Nil(b, err) - - headerInfo := &dataMock.HeaderInfoStub{Header: header, Hash: hash} - headers = append(headers, headerInfo) - } - - slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) - for i := 0; i < int(noOfPubKeys); i++ { - tmp := fmt.Sprintf("pubKey%v", i) - pubKey := hasher.Compute(tmp) - slashRes[string(pubKey)] = slash.SlashingResult{ - Headers: headers, - } - } - - return slashRes -} diff --git a/data/testscommon/slash/generator.go b/data/testscommon/slash/generator.go new file mode 100644 index 000000000..d6cff7cf4 --- /dev/null +++ b/data/testscommon/slash/generator.go @@ -0,0 +1,41 @@ +package slash + +import ( + "fmt" + "testing" + + "github.com/ElrondNetwork/elrond-go-core/core" + "github.com/ElrondNetwork/elrond-go-core/core/mock" + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" + "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/ElrondNetwork/elrond-go-core/marshal" + "github.com/stretchr/testify/require" +) + +func GenerateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) map[string]slash.SlashingResult { + hasher := &mock.HasherMock{} + marshaller := &marshal.GogoProtoMarshalizer{} + + headers := make([]data.HeaderInfoHandler, 0, noOfHeaders) + for i := 0; i < int(noOfHeaders); i++ { + header := &block.HeaderV2{Header: &block.Header{Round: 1, TimeStamp: uint64(i)}} + hash, err := core.CalculateHash(marshaller, hasher, header) + require.Nil(b, err) + + headerInfo := &dataMock.HeaderInfoStub{Header: header, Hash: hash} + headers = append(headers, headerInfo) + } + + slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) + for i := 0; i < int(noOfPubKeys); i++ { + tmp := fmt.Sprintf("pubKey%v", i) + pubKey := hasher.Compute(tmp) + slashRes[string(pubKey)] = slash.SlashingResult{ + Headers: headers, + } + } + + return slashRes +} From 3af6d5c22887aa3cac9f5ccf5bc8fbda2b9edd6c Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 23 Nov 2021 10:55:44 +0200 Subject: [PATCH 39/54] FIX: Add threat level in generator --- data/slash/common.go | 4 ++++ data/testscommon/slash/generator.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/data/slash/common.go b/data/slash/common.go index 24f5d4944..3f4b0d4ae 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -9,6 +9,10 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) +// MinSlashableNoOfHeaders represents the min number of headers required for a +// multiple proposal/signing proof to be considered slashable +const MinSlashableNoOfHeaders = 2 + // SlashingResult contains the slashable data as well as the severity(slashing level) // for a possible malicious validator type SlashingResult struct { diff --git a/data/testscommon/slash/generator.go b/data/testscommon/slash/generator.go index d6cff7cf4..deb2e4cb3 100644 --- a/data/testscommon/slash/generator.go +++ b/data/testscommon/slash/generator.go @@ -28,12 +28,19 @@ func GenerateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) headers = append(headers, headerInfo) } + threatLevel := slash.Zero + if noOfHeaders == slash.MinSlashableNoOfHeaders { + threatLevel = slash.Medium + } else if noOfHeaders >= slash.MinSlashableNoOfHeaders { + threatLevel = slash.High + } slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) for i := 0; i < int(noOfPubKeys); i++ { tmp := fmt.Sprintf("pubKey%v", i) pubKey := hasher.Compute(tmp) slashRes[string(pubKey)] = slash.SlashingResult{ - Headers: headers, + Headers: headers, + SlashingLevel: threatLevel, } } From 519b307aa84c22f27e5878180d830c9a8271ed23 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 2 Dec 2021 14:04:47 +0200 Subject: [PATCH 40/54] FEAT: Add benchmark for NewMultipleProposalProof --- .../slash/multipleHeaderProposalProof_test.go | 22 +++++++++++ data/slash/multipleHeaderSigningProof_test.go | 2 +- data/testscommon/slash/generator.go | 39 ++++++++++++------- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 65bb6afe8..a9ba73e56 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -8,6 +8,8 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data/block" dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" "github.com/ElrondNetwork/elrond-go-core/data/slash" + testscommon "github.com/ElrondNetwork/elrond-go-core/data/testscommon/slash" + "github.com/ElrondNetwork/elrond-go-core/hashing/blake2b" "github.com/ElrondNetwork/elrond-go-core/marshal" "github.com/stretchr/testify/require" ) @@ -169,3 +171,23 @@ func TestMultipleHeaderProposalProof_MarshalUnmarshal(t *testing.T) { require.Equal(t, proof1Unmarshalled, proof1) require.Equal(t, proof2Unmarshalled, proof2) } + +func BenchmarkNewMultipleProposalProof(b *testing.B) { + hasher, err := blake2b.NewBlake2bWithSize(16) + require.Nil(b, err) + + noOfHeaders := uint32(100) + headers := testscommon.GenerateDistinctHeadersInfo(b, noOfHeaders, hasher) + slashRes := &slash.SlashingResult{ + SlashingLevel: testscommon.CalcThreatLevel(noOfHeaders), + Headers: headers, + } + for n := 0; n < b.N; n++ { + proof, err := slash.NewMultipleProposalProof(slashRes) + + b.StopTimer() + require.NotNil(b, proof) + require.Nil(b, err) + b.StartTimer() + } +} diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 9f3180343..12c0fe1ca 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -252,7 +252,7 @@ func TestMultipleSigningProof_Marshal_Unmarshal(t *testing.T) { } func BenchmarkNewMultipleSigningProof(b *testing.B) { - // Worst case scenario: 25% of a consensus group of 400 validators on metachain + // Worst case scenario: 25% of a consensus group of 400 validators on metachain signed 3 different headers noOfPubKeys := uint32(0.25 * 400) noOfHeaders := uint32(3) slashRes := testscommon.GenerateSlashResults(b, noOfPubKeys, noOfHeaders) diff --git a/data/testscommon/slash/generator.go b/data/testscommon/slash/generator.go index deb2e4cb3..08f9a3c2a 100644 --- a/data/testscommon/slash/generator.go +++ b/data/testscommon/slash/generator.go @@ -5,19 +5,37 @@ import ( "testing" "github.com/ElrondNetwork/elrond-go-core/core" - "github.com/ElrondNetwork/elrond-go-core/core/mock" "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" dataMock "github.com/ElrondNetwork/elrond-go-core/data/mock" "github.com/ElrondNetwork/elrond-go-core/data/slash" + "github.com/ElrondNetwork/elrond-go-core/hashing" + "github.com/ElrondNetwork/elrond-go-core/hashing/blake2b" "github.com/ElrondNetwork/elrond-go-core/marshal" "github.com/stretchr/testify/require" ) func GenerateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) map[string]slash.SlashingResult { - hasher := &mock.HasherMock{} - marshaller := &marshal.GogoProtoMarshalizer{} + hasher, err := blake2b.NewBlake2bWithSize(16) + require.Nil(b, err) + + headers := GenerateDistinctHeadersInfo(b, noOfHeaders, hasher) + slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) + for i := 0; i < int(noOfPubKeys); i++ { + tmp := fmt.Sprintf("pubKey%v", i) + pubKey := hasher.Compute(tmp) + + slashRes[string(pubKey)] = slash.SlashingResult{ + Headers: headers, + SlashingLevel: CalcThreatLevel(noOfHeaders), + } + } + + return slashRes +} +func GenerateDistinctHeadersInfo(b *testing.B, noOfHeaders uint32, hasher hashing.Hasher) []data.HeaderInfoHandler { + marshaller := &marshal.GogoProtoMarshalizer{} headers := make([]data.HeaderInfoHandler, 0, noOfHeaders) for i := 0; i < int(noOfHeaders); i++ { header := &block.HeaderV2{Header: &block.Header{Round: 1, TimeStamp: uint64(i)}} @@ -28,21 +46,16 @@ func GenerateSlashResults(b *testing.B, noOfPubKeys uint32, noOfHeaders uint32) headers = append(headers, headerInfo) } + return headers +} + +func CalcThreatLevel(noOfHeaders uint32) slash.ThreatLevel { threatLevel := slash.Zero if noOfHeaders == slash.MinSlashableNoOfHeaders { threatLevel = slash.Medium } else if noOfHeaders >= slash.MinSlashableNoOfHeaders { threatLevel = slash.High } - slashRes := make(map[string]slash.SlashingResult, noOfPubKeys) - for i := 0; i < int(noOfPubKeys); i++ { - tmp := fmt.Sprintf("pubKey%v", i) - pubKey := hasher.Compute(tmp) - slashRes[string(pubKey)] = slash.SlashingResult{ - Headers: headers, - SlashingLevel: threatLevel, - } - } - return slashRes + return threatLevel } From ec61d7480dcd54d29dc8dfa99f9e9ff1513a2904 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 2 Dec 2021 14:15:56 +0200 Subject: [PATCH 41/54] CLN: Remove ProofID --- data/slash/common.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 3f4b0d4ae..a893d316e 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -25,19 +25,17 @@ type SlashingResult struct { type ProofTxData struct { Round uint64 ShardID uint32 - ProofID ProofID + ProofID byte } -type ProofID byte - // Used by slashing notifier to create a slashing transaction // from a proof. Each transaction identifies a different // slashing event based on this ID const ( // MultipleProposalProofID = MultipleProposal's ID - MultipleProposalProofID ProofID = 0x1 + MultipleProposalProofID byte = 0x1 // MultipleSigningProofID = MultipleSigning's ID - MultipleSigningProofID ProofID = 0x2 + MultipleSigningProofID byte = 0x2 ) func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, error) { From f36ca9e442fd12093bcd2723617029f1e6334f96 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 2 Dec 2021 15:45:18 +0200 Subject: [PATCH 42/54] FEAT: Add GetAllHeaders() --- data/slash/interface.go | 2 ++ data/slash/multipleHeaderSigningProof.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/data/slash/interface.go b/data/slash/interface.go index cead589f8..79bd68aa8 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -29,4 +29,6 @@ type MultipleSigningProofHandler interface { GetLevel(pubKey []byte) ThreatLevel // GetHeaders - returns the slashable signed headers proposed by a given validator GetHeaders(pubKey []byte) []data.HeaderHandler + // GetAllHeaders returns all signed headers + GetAllHeaders() []data.HeaderHandler } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index b645c80f4..3170bc133 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -40,6 +40,14 @@ func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { return slashData.ThreatLevel } +func (m *MultipleHeaderSigningProof) GetAllHeaders() []data.HeaderHandler { + if m == nil { + return nil + } + + return m.HeadersV2.GetHeaderHandlers() +} + // GetHeaders returns all headers that have been signed by a possible malicious validator func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHandler { if m == nil { From 6eaba3d72389e241e4af5b2f19996fc9c9990266 Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 3 Dec 2021 11:17:26 +0200 Subject: [PATCH 43/54] FEAT: Add GetBitmap() --- data/slash/interface.go | 2 ++ data/slash/multipleHeaderSigningProof.go | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/data/slash/interface.go b/data/slash/interface.go index 79bd68aa8..6e2115c07 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -31,4 +31,6 @@ type MultipleSigningProofHandler interface { GetHeaders(pubKey []byte) []data.HeaderHandler // GetAllHeaders returns all signed headers GetAllHeaders() []data.HeaderHandler + // GetBitmap returns a bitmap representing the slashable signed headers proposed by a given validator + GetBitmap(pubKey []byte) []byte } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 3170bc133..1a6428918 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -48,6 +48,19 @@ func (m *MultipleHeaderSigningProof) GetAllHeaders() []data.HeaderHandler { return m.HeadersV2.GetHeaderHandlers() } +func (m *MultipleHeaderSigningProof) GetBitmap(pubKey []byte) []byte { + if m == nil { + return nil + } + + slashData, exists := m.SignersSlashData[string(pubKey)] + if !exists { + return nil + } + + return slashData.GetSignedHeadersBitMap() +} + // GetHeaders returns all headers that have been signed by a possible malicious validator func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHandler { if m == nil { @@ -142,13 +155,13 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(currHeaderInfo.GetHash())) } + hashesPerPubKey[currHash] = struct{}{} _, exists = hashes[currHash] if exists { continue } hashes[currHash] = struct{}{} - hashesPerPubKey[currHash] = struct{}{} headersInfo = append(headersInfo, currHeaderInfo) } } From 5c6bed1626cfa2be45e2bfde7b15e830f59fb4bb Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 6 Dec 2021 11:25:03 +0200 Subject: [PATCH 44/54] FEAT: Remove GetBitmap() --- data/slash/interface.go | 6 ++---- data/slash/multipleHeaderSigningProof.go | 13 ------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/data/slash/interface.go b/data/slash/interface.go index 6e2115c07..9ea7718d4 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -25,12 +25,10 @@ type MultipleSigningProofHandler interface { SlashingProofHandler // GetPubKeys - returns all validator's public keys which have signed multiple headers GetPubKeys() [][]byte + // GetAllHeaders returns all signed headers + GetAllHeaders() []data.HeaderHandler // GetLevel - returns the slashing level for a given validator GetLevel(pubKey []byte) ThreatLevel // GetHeaders - returns the slashable signed headers proposed by a given validator GetHeaders(pubKey []byte) []data.HeaderHandler - // GetAllHeaders returns all signed headers - GetAllHeaders() []data.HeaderHandler - // GetBitmap returns a bitmap representing the slashable signed headers proposed by a given validator - GetBitmap(pubKey []byte) []byte } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 1a6428918..3faab11f5 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -48,19 +48,6 @@ func (m *MultipleHeaderSigningProof) GetAllHeaders() []data.HeaderHandler { return m.HeadersV2.GetHeaderHandlers() } -func (m *MultipleHeaderSigningProof) GetBitmap(pubKey []byte) []byte { - if m == nil { - return nil - } - - slashData, exists := m.SignersSlashData[string(pubKey)] - if !exists { - return nil - } - - return slashData.GetSignedHeadersBitMap() -} - // GetHeaders returns all headers that have been signed by a possible malicious validator func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHandler { if m == nil { From 553f9a5affac7da87c72b52e9a7d2a648616ef42 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 6 Dec 2021 16:36:52 +0200 Subject: [PATCH 45/54] FIX: Review findings --- data/mock/headerInfoStub.go | 3 +++ data/slash/multipleHeaderProposalProof_test.go | 5 +---- data/slash/multipleHeaderSigningProof_test.go | 11 +++-------- data/slash/slash.go | 6 ++---- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/data/mock/headerInfoStub.go b/data/mock/headerInfoStub.go index c45c5d230..1114b4027 100644 --- a/data/mock/headerInfoStub.go +++ b/data/mock/headerInfoStub.go @@ -2,15 +2,18 @@ package mock import "github.com/ElrondNetwork/elrond-go-core/data" +// HeaderInfoStub - type HeaderInfoStub struct { Header data.HeaderHandler Hash []byte } +// GetHeaderHandler - func (his *HeaderInfoStub) GetHeaderHandler() data.HeaderHandler { return his.Header } +// GetHash - func (his *HeaderInfoStub) GetHash() []byte { return his.Hash } diff --git a/data/slash/multipleHeaderProposalProof_test.go b/data/slash/multipleHeaderProposalProof_test.go index 52084b55e..3b77c5764 100644 --- a/data/slash/multipleHeaderProposalProof_test.go +++ b/data/slash/multipleHeaderProposalProof_test.go @@ -57,10 +57,7 @@ func TestMultipleProposalProof_GetHeadersGetLevelGetType(t *testing.T) { require.Equal(t, slash.MultipleProposal, proof.GetType()) require.Equal(t, slash.Medium, proof.GetLevel()) - - require.Len(t, proof.GetHeaders(), 2) - require.Equal(t, proof.GetHeaders()[0], h1) - require.Equal(t, proof.GetHeaders()[1], h2) + require.Equal(t, []data.HeaderHandler{h1, h2}, proof.GetHeaders()) } func TestMultipleHeaderProposalProof_GetProofTxDataNotEnoughHeadersExpectError(t *testing.T) { diff --git a/data/slash/multipleHeaderSigningProof_test.go b/data/slash/multipleHeaderSigningProof_test.go index 870e39877..a04f80a23 100644 --- a/data/slash/multipleHeaderSigningProof_test.go +++ b/data/slash/multipleHeaderSigningProof_test.go @@ -74,17 +74,12 @@ func TestMultipleSigningProof_GetHeadersGetLevelGetType(t *testing.T) { require.Equal(t, slash.Medium, proof.GetLevel([]byte("pubKey2"))) require.Equal(t, slash.Zero, proof.GetLevel([]byte("pubKey3"))) - require.Len(t, proof.GetHeaders([]byte("pubKey1")), 2) - require.Len(t, proof.GetHeaders([]byte("pubKey2")), 1) - require.Len(t, proof.GetHeaders([]byte("pubKey3")), 0) - - require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[0], h1) - require.Equal(t, proof.GetHeaders([]byte("pubKey1"))[1], h2) - require.Equal(t, proof.GetHeaders([]byte("pubKey2"))[0], h3) + require.Equal(t, []data.HeaderHandler{h1, h2}, proof.GetHeaders([]byte("pubKey1"))) + require.Equal(t, []data.HeaderHandler{h3}, proof.GetHeaders([]byte("pubKey2"))) require.Nil(t, proof.GetHeaders([]byte("pubKey3"))) } -func TestMultipleSigningProof_GetProofTxData_EnoughPublicKeysProvidedExpectError(t *testing.T) { +func TestMultipleSigningProof_GetProofTxData_NotEnoughPublicKeysProvidedExpectError(t *testing.T) { proof := slash.MultipleHeaderSigningProof{} proofTxData, err := proof.GetProofTxData() diff --git a/data/slash/slash.go b/data/slash/slash.go index 26fc76ced..8084805f8 100644 --- a/data/slash/slash.go +++ b/data/slash/slash.go @@ -6,8 +6,7 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data/block" ) -// GetHeaderHandlers returns a slice with all data.HeaderHandler. -// Used so we can work with interfaces instead of defined types +// GetHeaderHandlers returns a slice of data.HeaderHandler representing a slice of internal headers v2 func (m *HeadersV2) GetHeaderHandlers() []data.HeaderHandler { if m == nil { return nil @@ -22,8 +21,7 @@ func (m *HeadersV2) GetHeaderHandlers() []data.HeaderHandler { return ret } -// SetHeaders sets internal header structs to a given slice of data.HeaderHandler. -// Used so we can work with interfaces instead of defined types +// SetHeaders sets internal headers v2 slice to a given slice of data.HeaderHandler. func (m *HeadersV2) SetHeaders(headers []data.HeaderHandler) error { if m == nil { return data.ErrNilPointerReceiver From 85cf15ace8affe87ac1b71c413f5f266541690e3 Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 6 Dec 2021 18:22:08 +0200 Subject: [PATCH 46/54] FIX: Review findings --- data/slash/common.go | 49 ++++++++++++++---------- data/slash/multipleHeaderSigningProof.go | 22 ++++------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 24f5d4944..9c5d37d34 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -51,6 +51,30 @@ func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, erro return headersV2, nil } +func checkHeaderInfo(headerInfo data.HeaderInfoHandler, hashes map[string]struct{}) (string, error) { + if headerInfo == nil { + return "", data.ErrNilHeaderInfo + } + + hash := headerInfo.GetHash() + if hash == nil { + return "", data.ErrNilHash + } + + headerHandler := headerInfo.GetHeaderHandler() + if check.IfNil(headerHandler) { + return "", fmt.Errorf("%w in header list for hash: %s", data.ErrNilHeaderHandler, hex.EncodeToString(hash)) + } + + hashStr := string(hash) + _, exists := hashes[hashStr] + if exists { + return "", fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(hash)) + } + + return hashStr, nil +} + func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, error) { if len(headersInfo) == 0 { return nil, data.ErrEmptyHeaderInfoList @@ -60,28 +84,13 @@ func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, er headers := make([]data.HeaderHandler, 0, len(headersInfo)) hashes := make(map[string]struct{}) for idx, headerInfo := range headersInfo { - if headerInfo == nil { - return nil, fmt.Errorf("%w in sorted headers at index: %v", data.ErrNilHeaderInfo, idx) - } - - hash := headerInfo.GetHash() - if hash == nil { - return nil, fmt.Errorf("%w in sorted headers at index: %v", data.ErrNilHash, idx) - } - - hashStr := string(hash) - _, exists := hashes[hashStr] - if exists { - return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(hash)) - } - - headerHandler := headerInfo.GetHeaderHandler() - if check.IfNil(headerHandler) { - return nil, fmt.Errorf("%w in sorted headers for hash: %s", data.ErrNilHeaderHandler, hex.EncodeToString(hash)) + hash, err := checkHeaderInfo(headerInfo, hashes) + if err != nil { + return nil, fmt.Errorf("%w in sorted header list at index: %d", err, idx) } - headers = append(headers, headerHandler) - hashes[hashStr] = struct{}{} + headers = append(headers, headerInfo.GetHeaderHandler()) + hashes[hash] = struct{}{} } return headers, nil diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index b645c80f4..a919fe3e8 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -122,26 +122,20 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn for pubKey, res := range slashResult { hashesPerPubKey := make(map[string]struct{}) - for _, currHeaderInfo := range res.Headers { - if currHeaderInfo == nil { - return nil, fmt.Errorf("%w in slash result for multiple header signing proof for public key: %s", - data.ErrNilHeaderInfo, hex.EncodeToString([]byte(pubKey))) + for _, headerInfo := range res.Headers { + hash, err := checkHeaderInfo(headerInfo, hashesPerPubKey) + if err != nil { + return nil, fmt.Errorf("%w for public key: %s", err, hex.EncodeToString([]byte(pubKey))) } - currHash := string(currHeaderInfo.GetHash()) - _, exists := hashesPerPubKey[currHash] - if exists { - return nil, fmt.Errorf("%w, duplicated hash: %s", data.ErrHeadersSameHash, hex.EncodeToString(currHeaderInfo.GetHash())) - } - - _, exists = hashes[currHash] + _, exists := hashes[hash] if exists { continue } - hashes[currHash] = struct{}{} - hashesPerPubKey[currHash] = struct{}{} - headersInfo = append(headersInfo, currHeaderInfo) + hashes[hash] = struct{}{} + hashesPerPubKey[hash] = struct{}{} + headersInfo = append(headersInfo, headerInfo) } } From bbfb7e26d6b00776e6e9a7d0442bf7578be76464 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 7 Dec 2021 08:15:32 +0200 Subject: [PATCH 47/54] FIX: Minor fix --- data/slash/common.go | 2 +- data/slash/multipleHeaderSigningProof.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 9c5d37d34..2adb44001 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -63,7 +63,7 @@ func checkHeaderInfo(headerInfo data.HeaderInfoHandler, hashes map[string]struct headerHandler := headerInfo.GetHeaderHandler() if check.IfNil(headerHandler) { - return "", fmt.Errorf("%w in header list for hash: %s", data.ErrNilHeaderHandler, hex.EncodeToString(hash)) + return "", fmt.Errorf("%w in header info for hash: %s", data.ErrNilHeaderHandler, hex.EncodeToString(hash)) } hashStr := string(hash) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index a919fe3e8..5fb7df871 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -125,16 +125,16 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn for _, headerInfo := range res.Headers { hash, err := checkHeaderInfo(headerInfo, hashesPerPubKey) if err != nil { - return nil, fmt.Errorf("%w for public key: %s", err, hex.EncodeToString([]byte(pubKey))) + return nil, fmt.Errorf("%w in slash result for public key: %s", err, hex.EncodeToString([]byte(pubKey))) } + hashesPerPubKey[hash] = struct{}{} _, exists := hashes[hash] if exists { continue } hashes[hash] = struct{}{} - hashesPerPubKey[hash] = struct{}{} headersInfo = append(headersInfo, headerInfo) } } From c43273ba84c11338b79a78391acd9361ca62bd0b Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 7 Dec 2021 08:53:52 +0200 Subject: [PATCH 48/54] FEAT: Add CalcBitmapSize --- data/slash/common.go | 10 ++++++++++ data/slash/interface.go | 4 ++-- data/slash/multipleHeaderSigningProof.go | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index caf7293c0..143267482 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -38,6 +38,16 @@ const ( MultipleSigningProofID byte = 0x2 ) +// CalcBitmapSize returns the min required bitmap size, which +// can hold a noOfBits +func CalcBitmapSize(noOfBits int) uint32 { + bitmapSize := noOfBits / 8 + if noOfBits%8 != 0 { + bitmapSize++ + } + return uint32(bitmapSize) +} + func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, error) { sortedHeaders, err := sortHeaders(headersInfo) if err != nil { diff --git a/data/slash/interface.go b/data/slash/interface.go index 9ea7718d4..94f8ff745 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -25,10 +25,10 @@ type MultipleSigningProofHandler interface { SlashingProofHandler // GetPubKeys - returns all validator's public keys which have signed multiple headers GetPubKeys() [][]byte - // GetAllHeaders returns all signed headers + // GetAllHeaders returns all signed headers by all validators GetAllHeaders() []data.HeaderHandler // GetLevel - returns the slashing level for a given validator GetLevel(pubKey []byte) ThreatLevel - // GetHeaders - returns the slashable signed headers proposed by a given validator + // GetHeaders - returns the signed headers by a given validator GetHeaders(pubKey []byte) []data.HeaderHandler } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 6552a1190..6da9c75e9 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -163,9 +163,9 @@ func calcHashIndexMap(headersInfo []data.HeaderInfoHandler) map[string]uint32 { func computeSignersSlashData(hashIndexMap map[string]uint32, slashResult map[string]SlashingResult) map[string]SignerSlashingData { signersSlashData := make(map[string]SignerSlashingData) - bitMapLen := len(hashIndexMap)/byteSize + 1 + bitMapSize := CalcBitmapSize(len(hashIndexMap)) for pubKey, res := range slashResult { - bitmap := make([]byte, bitMapLen) + bitmap := make([]byte, bitMapSize) for _, header := range res.Headers { index, exists := hashIndexMap[string(header.GetHash())] if exists { From 51714adca0f2874b6a4c67c1e42e121ec389d6b5 Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 8 Dec 2021 15:44:11 +0200 Subject: [PATCH 49/54] FIX: Interface description --- data/slash/interface.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/data/slash/interface.go b/data/slash/interface.go index 94f8ff745..2ab0f5d5c 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -4,7 +4,7 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) -// SlashingProofHandler - contains a proof for a slashing event and can be wrapped in a transaction +// SlashingProofHandler contains a proof for a slashing event and can be wrapped in a transaction type SlashingProofHandler interface { // GetProofTxData extracts proof tx data(see ProofTxData) from a slashing proof GetProofTxData() (*ProofTxData, error) @@ -13,22 +13,21 @@ type SlashingProofHandler interface { // MultipleProposalProofHandler contains proof data for a multiple header proposal slashing event type MultipleProposalProofHandler interface { SlashingProofHandler - // GetLevel - contains the slashing level for the current slashing type - // multiple colluding parties should have a higher level + // GetLevel returns the threat level of the proposer GetLevel() ThreatLevel - //GetHeaders - returns the slashable proposed headers + //GetHeaders returns all proposed headers in a certain round GetHeaders() []data.HeaderHandler } // MultipleSigningProofHandler contains proof data for a multiple header signing slashing event type MultipleSigningProofHandler interface { SlashingProofHandler - // GetPubKeys - returns all validator's public keys which have signed multiple headers + // GetPubKeys returns all validator's public keys which have signed multiple headers GetPubKeys() [][]byte // GetAllHeaders returns all signed headers by all validators GetAllHeaders() []data.HeaderHandler - // GetLevel - returns the slashing level for a given validator + // GetLevel returns the threat level of a given validator GetLevel(pubKey []byte) ThreatLevel - // GetHeaders - returns the signed headers by a given validator + // GetHeaders returns the signed headers by a given validator GetHeaders(pubKey []byte) []data.HeaderHandler } From 6ae6b83fe724eb5d4844b707c365902314aca9ae Mon Sep 17 00:00:00 2001 From: Marius Date: Wed, 8 Dec 2021 15:47:32 +0200 Subject: [PATCH 50/54] FIX: Minor description --- data/slash/interface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/slash/interface.go b/data/slash/interface.go index 2ab0f5d5c..035e46f65 100644 --- a/data/slash/interface.go +++ b/data/slash/interface.go @@ -24,7 +24,7 @@ type MultipleSigningProofHandler interface { SlashingProofHandler // GetPubKeys returns all validator's public keys which have signed multiple headers GetPubKeys() [][]byte - // GetAllHeaders returns all signed headers by all validators + // GetAllHeaders returns all signed headers by all validators in a certain round GetAllHeaders() []data.HeaderHandler // GetLevel returns the threat level of a given validator GetLevel(pubKey []byte) ThreatLevel From 013f63e5cb6255442ad90dc42c1b696df4c37c9a Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 23 Dec 2021 17:14:39 +0200 Subject: [PATCH 51/54] FIX: Review findings --- data/slash/common.go | 4 ++-- data/slash/multipleHeaderSigningProof.go | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index 2adb44001..cb93e4834 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -51,7 +51,7 @@ func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, erro return headersV2, nil } -func checkHeaderInfo(headerInfo data.HeaderInfoHandler, hashes map[string]struct{}) (string, error) { +func getAndCheckUniqueHeaderHash(headerInfo data.HeaderInfoHandler, hashes map[string]struct{}) (string, error) { if headerInfo == nil { return "", data.ErrNilHeaderInfo } @@ -84,7 +84,7 @@ func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, er headers := make([]data.HeaderHandler, 0, len(headersInfo)) hashes := make(map[string]struct{}) for idx, headerInfo := range headersInfo { - hash, err := checkHeaderInfo(headerInfo, hashes) + hash, err := getAndCheckUniqueHeaderHash(headerInfo, hashes) if err != nil { return nil, fmt.Errorf("%w in sorted header list at index: %d", err, idx) } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 5fb7df871..2ea509c2c 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -51,16 +51,14 @@ func (m *MultipleHeaderSigningProof) GetHeaders(pubKey []byte) []data.HeaderHand return nil } - idx := uint32(0) bitmap := slashData.GetSignedHeadersBitMap() headers := m.HeadersV2.GetHeaderHandlers() ret := make([]data.HeaderHandler, 0) - for _, header := range headers { - if sliceUtil.IsIndexSetInBitmap(idx, bitmap) { + for idx, header := range headers { + if sliceUtil.IsIndexSetInBitmap(uint32(idx), bitmap) { ret = append(ret, header) } - idx++ } return ret @@ -123,7 +121,7 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn for pubKey, res := range slashResult { hashesPerPubKey := make(map[string]struct{}) for _, headerInfo := range res.Headers { - hash, err := checkHeaderInfo(headerInfo, hashesPerPubKey) + hash, err := getAndCheckUniqueHeaderHash(headerInfo, hashesPerPubKey) if err != nil { return nil, fmt.Errorf("%w in slash result for public key: %s", err, hex.EncodeToString([]byte(pubKey))) } @@ -143,11 +141,9 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn } func calcHashIndexMap(headersInfo []data.HeaderInfoHandler) map[string]uint32 { - idx := uint32(0) hashIndexMap := make(map[string]uint32) - for _, headerInfo := range headersInfo { - hashIndexMap[string(headerInfo.GetHash())] = idx - idx++ + for idx, headerInfo := range headersInfo { + hashIndexMap[string(headerInfo.GetHash())] = uint32(idx) } return hashIndexMap From 346bfb41a48143fe645e48154a7c864800dfae13 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 20 Jan 2022 12:38:35 +0200 Subject: [PATCH 52/54] FIX: Review findings --- data/slash/common.go | 6 +++--- data/slash/multipleHeaderProposalProof.go | 2 +- data/slash/multipleHeaderSigningProof.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index cb93e4834..749485929 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -36,7 +36,7 @@ const ( MultipleSigningProofID ProofID = 0x2 ) -func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, error) { +func getSortedHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, error) { sortedHeaders, err := sortHeaders(headersInfo) if err != nil { return nil, err @@ -51,7 +51,7 @@ func sortAndGetHeadersV2(headersInfo []data.HeaderInfoHandler) (*HeadersV2, erro return headersV2, nil } -func getAndCheckUniqueHeaderHash(headerInfo data.HeaderInfoHandler, hashes map[string]struct{}) (string, error) { +func getHeaderHashIfUnique(headerInfo data.HeaderInfoHandler, hashes map[string]struct{}) (string, error) { if headerInfo == nil { return "", data.ErrNilHeaderInfo } @@ -84,7 +84,7 @@ func sortHeaders(headersInfo []data.HeaderInfoHandler) ([]data.HeaderHandler, er headers := make([]data.HeaderHandler, 0, len(headersInfo)) hashes := make(map[string]struct{}) for idx, headerInfo := range headersInfo { - hash, err := getAndCheckUniqueHeaderHash(headerInfo, hashes) + hash, err := getHeaderHashIfUnique(headerInfo, hashes) if err != nil { return nil, fmt.Errorf("%w in sorted header list at index: %d", err, idx) } diff --git a/data/slash/multipleHeaderProposalProof.go b/data/slash/multipleHeaderProposalProof.go index 2e78bf5ab..debb6fe49 100644 --- a/data/slash/multipleHeaderProposalProof.go +++ b/data/slash/multipleHeaderProposalProof.go @@ -45,7 +45,7 @@ func NewMultipleProposalProof(slashResult *SlashingResult) (MultipleProposalProo return nil, data.ErrEmptyHeaderInfoList } - sortedHeaders, err := sortAndGetHeadersV2(slashResult.Headers) + sortedHeaders, err := getSortedHeadersV2(slashResult.Headers) if err != nil { return nil, err } diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index 2ea509c2c..326191d59 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -100,7 +100,7 @@ func NewMultipleSigningProof(slashResult map[string]SlashingResult) (MultipleSig if err != nil { return nil, err } - sortedHeaders, err := sortAndGetHeadersV2(headersInfo) + sortedHeaders, err := getSortedHeadersV2(headersInfo) if err != nil { return nil, err } @@ -121,7 +121,7 @@ func getAllUniqueHeaders(slashResult map[string]SlashingResult) ([]data.HeaderIn for pubKey, res := range slashResult { hashesPerPubKey := make(map[string]struct{}) for _, headerInfo := range res.Headers { - hash, err := getAndCheckUniqueHeaderHash(headerInfo, hashesPerPubKey) + hash, err := getHeaderHashIfUnique(headerInfo, hashesPerPubKey) if err != nil { return nil, fmt.Errorf("%w in slash result for public key: %s", err, hex.EncodeToString([]byte(pubKey))) } From 6f67cc2ce047d34afbc7a4695925262f6f87c8fa Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 20 Jan 2022 16:34:35 +0200 Subject: [PATCH 53/54] FIX: Review findings --- data/slash/multipleHeaderSigningProof.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data/slash/multipleHeaderSigningProof.go b/data/slash/multipleHeaderSigningProof.go index e9473fd78..b8c5c1954 100644 --- a/data/slash/multipleHeaderSigningProof.go +++ b/data/slash/multipleHeaderSigningProof.go @@ -10,8 +10,6 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" ) -const byteSize = 8 - // GetPubKeys - returns all validator's public keys which have signed multiple headers func (m *MultipleHeaderSigningProof) GetPubKeys() [][]byte { if m == nil { @@ -40,6 +38,7 @@ func (m *MultipleHeaderSigningProof) GetLevel(pubKey []byte) ThreatLevel { return slashData.ThreatLevel } +// GetAllHeaders returns all header handlers stored in the proof func (m *MultipleHeaderSigningProof) GetAllHeaders() []data.HeaderHandler { if m == nil { return nil From 84c4c069bdb3e5d4addb5f43b36d887c4292e4ed Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 20 Jan 2022 16:40:27 +0200 Subject: [PATCH 54/54] FEAT: Add byteSize const --- data/slash/common.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/slash/common.go b/data/slash/common.go index c26873640..4d0c9de0e 100644 --- a/data/slash/common.go +++ b/data/slash/common.go @@ -38,11 +38,13 @@ const ( MultipleSigningProofID byte = 0x2 ) +const byteSize = 8 + // CalcBitmapSize returns the min required bitmap size, which // can hold a noOfBits func CalcBitmapSize(noOfBits int) uint32 { - bitmapSize := noOfBits / 8 - if noOfBits%8 != 0 { + bitmapSize := noOfBits / byteSize + if noOfBits%byteSize != 0 { bitmapSize++ } return uint32(bitmapSize)