Remove Error Message Type (#3533)

* proto change

* fix test

* fix error resp
This commit is contained in:
Nishant Das 2019-09-20 19:43:38 +05:30 committed by Raul Jordan
parent 4bc2d628b1
commit 44e5e5de65
4 changed files with 28 additions and 213 deletions

View File

@ -6,7 +6,6 @@ import (
"io"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
const genericError = "internal service error"
@ -19,7 +18,7 @@ var responseCodeServerError = byte(0x02)
func (r *RegularSync) generateErrorResponse(code byte, reason string) ([]byte, error) {
buf := bytes.NewBuffer([]byte{code})
if _, err := r.p2p.Encoding().EncodeWithLength(buf, &pb.ErrorMessage{ErrorMessage: reason}); err != nil {
if _, err := r.p2p.Encoding().EncodeWithLength(buf, []byte(reason)); err != nil {
return nil, err
}

View File

@ -5,7 +5,6 @@ import (
"testing"
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
func TestRegularSync_generateErrorResponse(t *testing.T) {
@ -25,11 +24,11 @@ func TestRegularSync_generateErrorResponse(t *testing.T) {
if b[0] != responseCodeServerError {
t.Errorf("The first byte was not the status code. Got %#x wanted %#x", b, responseCodeServerError)
}
msg := &pb.ErrorMessage{}
if err := r.p2p.Encoding().DecodeWithLength(buf, msg); err != nil {
msg := make([]byte, 0)
if err := r.p2p.Encoding().DecodeWithLength(buf, &msg); err != nil {
t.Fatal(err)
}
if msg.ErrorMessage != "something bad happened" {
if string(msg) != "something bad happened" {
t.Errorf("Received the wrong message: %v", msg)
}
}

View File

@ -173,88 +173,38 @@ func (m *BeaconBlocksByRangeRequest) GetStep() uint64 {
return 0
}
type ErrorMessage struct {
ErrorMessage string `protobuf:"bytes,1,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ErrorMessage) Reset() { *m = ErrorMessage{} }
func (m *ErrorMessage) String() string { return proto.CompactTextString(m) }
func (*ErrorMessage) ProtoMessage() {}
func (*ErrorMessage) Descriptor() ([]byte, []int) {
return fileDescriptor_a1d590cda035b632, []int{2}
}
func (m *ErrorMessage) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ErrorMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ErrorMessage.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalTo(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ErrorMessage) XXX_Merge(src proto.Message) {
xxx_messageInfo_ErrorMessage.Merge(m, src)
}
func (m *ErrorMessage) XXX_Size() int {
return m.Size()
}
func (m *ErrorMessage) XXX_DiscardUnknown() {
xxx_messageInfo_ErrorMessage.DiscardUnknown(m)
}
var xxx_messageInfo_ErrorMessage proto.InternalMessageInfo
func (m *ErrorMessage) GetErrorMessage() string {
if m != nil {
return m.ErrorMessage
}
return ""
}
func init() {
proto.RegisterType((*Status)(nil), "ethereum.beacon.p2p.v1.Status")
proto.RegisterType((*BeaconBlocksByRangeRequest)(nil), "ethereum.beacon.p2p.v1.BeaconBlocksByRangeRequest")
proto.RegisterType((*ErrorMessage)(nil), "ethereum.beacon.p2p.v1.ErrorMessage")
}
func init() { proto.RegisterFile("proto/beacon/p2p/v1/messages.proto", fileDescriptor_a1d590cda035b632) }
var fileDescriptor_a1d590cda035b632 = []byte{
// 395 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xb1, 0x8e, 0xd3, 0x40,
0x10, 0x86, 0xb5, 0x87, 0xef, 0x44, 0x56, 0x0e, 0xc7, 0xad, 0x10, 0xb2, 0x0e, 0x91, 0x3b, 0x99,
0x82, 0x6b, 0xce, 0x56, 0x12, 0x0a, 0x40, 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 0xcb, 0x38, 0xf5, 0x92, 0x78, 0x0b, 0x0b, 0x37, 0x47, 0x54, 0x7a, 0x8d, 0x46, 0xbb, 0x87,
0xdd, 0xa0, 0x7d, 0x1a, 0x9d, 0x4d, 0x0d, 0xa7, 0xfd, 0x0b, 0x3a, 0x88, 0x4a, 0xdc, 0xf0, 0xce,
0x69, 0x12, 0x32, 0x0c, 0x22, 0xfd, 0xcf, 0x90, 0x8d, 0x34, 0xe7, 0x24, 0x7c, 0x2a, 0xab, 0xc2,
0xe4, 0x4d, 0xfa, 0x40, 0xb2, 0x6b, 0xe7, 0xec, 0x7f, 0x4b, 0x86, 0xc4, 0x57, 0x47, 0x5e, 0x26,
0xa8, 0xf4, 0x3a, 0x29, 0xa9, 0x39, 0x4f, 0x50, 0x19, 0xef, 0x8c, 0xf7, 0x6c, 0xfa, 0x73, 0x76,
0x82, 0xc1, 0x4a, 0xda, 0x6f, 0x8e, 0x97, 0x86, 0xe0, 0xc0, 0x6b, 0x01, 0x52, 0x89, 0x7b, 0x4e,
0x1b, 0xba, 0x7e, 0xd9, 0xac, 0x12, 0xd9, 0xd9, 0x7d, 0x4a, 0x92, 0x2c, 0x14, 0x7b, 0xcd, 0xb9,
0x54, 0x5e, 0xae, 0xaa, 0xdc, 0x1a, 0xe5, 0x36, 0xa9, 0x52, 0x06, 0x8b, 0x0b, 0x5e, 0x0f, 0xb0,
0x48, 0xd5, 0x71, 0xc9, 0xea, 0x22, 0x04, 0xd7, 0xa4, 0x82, 0x8c, 0xd6, 0xd2, 0x1c, 0x3a, 0xdb,
0xad, 0x8f, 0x7d, 0x9f, 0x7d, 0xee, 0xfb, 0xec, 0x6b, 0xdf, 0x67, 0x7e, 0x83, 0x1e, 0x6c, 0xf6,
0x13, 0x00, 0x00, 0xff, 0xff, 0x12, 0xe0, 0xa8, 0xc9, 0x1d, 0x02, 0x00, 0x00,
}
func (m *Status) Marshal() (dAtA []byte, err error) {
@ -348,33 +298,6 @@ func (m *BeaconBlocksByRangeRequest) MarshalTo(dAtA []byte) (int, error) {
return i, nil
}
func (m *ErrorMessage) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ErrorMessage) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if len(m.ErrorMessage) > 0 {
dAtA[i] = 0xa
i++
i = encodeVarintMessages(dAtA, i, uint64(len(m.ErrorMessage)))
i += copy(dAtA[i:], m.ErrorMessage)
}
if m.XXX_unrecognized != nil {
i += copy(dAtA[i:], m.XXX_unrecognized)
}
return i, nil
}
func encodeVarintMessages(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
@ -439,22 +362,6 @@ func (m *BeaconBlocksByRangeRequest) Size() (n int) {
return n
}
func (m *ErrorMessage) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.ErrorMessage)
if l > 0 {
n += 1 + l + sovMessages(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovMessages(x uint64) (n int) {
for {
n++
@ -807,92 +714,6 @@ func (m *BeaconBlocksByRangeRequest) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ErrorMessage) 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 ErrIntOverflowMessages
}
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: ErrorMessage: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ErrorMessage: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ErrorMessage", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowMessages
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthMessages
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthMessages
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ErrorMessage = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipMessages(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthMessages
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthMessages
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipMessages(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -18,7 +18,3 @@ message BeaconBlocksByRangeRequest {
uint64 count = 3;
uint64 step = 4;
}
message ErrorMessage {
string error_message = 1;
}