From 1ffb634d97792dae1204d463ab380aeca638e5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Thu, 3 Oct 2024 23:29:35 +0200 Subject: [PATCH 01/10] feat: implement custom error types for DA Introduced multiple custom error types for the DA package. Because of JSON-RPC library used, each error has to be it's own type (can't use sentinel values). gRPC on the other hand doesn't support wrapping typed errors, and codes are "standardized" (currently only "Not Found" used). --- errors.go | 72 +++++++++++++++++++++++++++++++++++++++++ proxy/grpc/client.go | 6 ++++ proxy/jsonrpc/client.go | 11 ++++++- proxy/jsonrpc/server.go | 11 ++++++- test/dummy.go | 2 +- test/test_suite.go | 3 +- 6 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 errors.go diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..593d606 --- /dev/null +++ b/errors.go @@ -0,0 +1,72 @@ +package da + +import ( + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type Code int + +// Codes are used by JSON-RPC client and server +const ( + CodeBlobNotFound Code = 32001 + CodeBlobSizeOverLimit Code = 32002 + CodeTxTimedOut Code = 32003 + CodeTxAlreadyInMempool Code = 32004 + CodeTxIncorrectAccountSequence Code = 32005 + CodeTxTooLarge Code = 32006 + CodeContextDeadline Code = 32007 +) + +// ErrBlobNotFound is used to indicate that the blob was not found. +type ErrBlobNotFound struct{} + +func (e *ErrBlobNotFound) Error() string { + return "blob: not found" +} + +func (e *ErrBlobNotFound) GRPCStatus() *status.Status { + return status.New(codes.NotFound, e.Error()) +} + +// ErrBlobSizeOverLimit is used to indicate that the blob size is over limit. +type ErrBlobSizeOverLimit struct{} + +func (e *ErrBlobSizeOverLimit) Error() string { + return "blob: over size limit" +} + +// ErrTxTimedOut is the error message returned by the DA when mempool is congested. +type ErrTxTimedOut struct{} + +func (e *ErrTxTimedOut) Error() string { + return "timed out waiting for tx to be included in a block" +} + +// ErrTxAlreadyInMempool is the error message returned by the DA when tx is already in mempool. +type ErrTxAlreadyInMempool struct{} + +func (e *ErrTxAlreadyInMempool) Error() string { + return "tx already in mempool" +} + +// ErrTxIncorrectAccountSequence is the error message returned by the DA when tx has incorrect sequence. +type ErrTxIncorrectAccountSequence struct{} + +func (e *ErrTxIncorrectAccountSequence) Error() string { + return "incorrect account sequence" +} + +// ErrTxTooLarge is the err message returned by the DA when tx size is too large. +type ErrTxTooLarge struct{} + +func (e *ErrTxTooLarge) Error() string { + return "tx too large" +} + +// ErrContextDeadline is the error message returned by the DA when context deadline exceeds. +type ErrContextDeadline struct{} + +func (e *ErrContextDeadline) Error() string { + return "context deadline" +} diff --git a/proxy/grpc/client.go b/proxy/grpc/client.go index 3babea8..b3ff79c 100644 --- a/proxy/grpc/client.go +++ b/proxy/grpc/client.go @@ -2,6 +2,7 @@ package grpc import ( "context" + "google.golang.org/grpc/status" "github.com/cosmos/gogoproto/types" "google.golang.org/grpc" @@ -59,6 +60,11 @@ func (c *Client) Get(ctx context.Context, ids []da.ID, namespace da.Namespace) ( } resp, err := c.client.Get(ctx, req) if err != nil { + s, ok := status.FromError(err) + if ok && s.Message() == "blob: not found" { + return nil, &da.ErrBlobNotFound{} + } + return nil, err } diff --git a/proxy/jsonrpc/client.go b/proxy/jsonrpc/client.go index 4e7b192..44c5e24 100644 --- a/proxy/jsonrpc/client.go +++ b/proxy/jsonrpc/client.go @@ -109,8 +109,17 @@ func NewClient(ctx context.Context, addr string, token string) (*Client, error) func newClient(ctx context.Context, addr string, authHeader http.Header) (*Client, error) { var multiCloser multiClientCloser var client Client + errs := jsonrpc.NewErrors() + errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) + errs.Register(jsonrpc.ErrorCode(da.CodeBlobNotFound), new(*da.ErrBlobNotFound)) + errs.Register(jsonrpc.ErrorCode(da.CodeBlobSizeOverLimit), new(*da.ErrBlobSizeOverLimit)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTimedOut), new(*da.ErrTxTimedOut)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) + errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) for name, module := range moduleMap(&client) { - closer, err := jsonrpc.NewClient(ctx, addr, name, module, authHeader) + closer, err := jsonrpc.NewMergeClient(ctx, addr, name, []interface{}{module}, authHeader, jsonrpc.WithErrors(errs)) if err != nil { return nil, err } diff --git a/proxy/jsonrpc/server.go b/proxy/jsonrpc/server.go index 92b9864..63ac661 100644 --- a/proxy/jsonrpc/server.go +++ b/proxy/jsonrpc/server.go @@ -32,7 +32,16 @@ func (s *Server) RegisterService(namespace string, service interface{}, out inte // NewServer accepts the host address port and the DA implementation to serve as a jsonrpc service func NewServer(address, port string, DA da.DA) *Server { - rpc := jsonrpc.NewServer() + errs := jsonrpc.NewErrors() + errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) + errs.Register(jsonrpc.ErrorCode(da.CodeBlobNotFound), new(*da.ErrBlobNotFound)) + errs.Register(jsonrpc.ErrorCode(da.CodeBlobSizeOverLimit), new(*da.ErrBlobSizeOverLimit)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTimedOut), new(*da.ErrTxTimedOut)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) + errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) + rpc := jsonrpc.NewServer(jsonrpc.WithServerErrors(errs)) srv := &Server{ rpc: rpc, srv: &http.Server{ diff --git a/test/dummy.go b/test/dummy.go index 8600307..f0eeb98 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -78,7 +78,7 @@ func (d *DummyDA) Get(ctx context.Context, ids []da.ID, _ da.Namespace) ([]da.Bl } } if !found { - return nil, errors.New("no blob for given ID") + return nil, &da.ErrBlobNotFound{} } } return blobs, nil diff --git a/test/test_suite.go b/test/test_suite.go index 9c0cef2..2aabf00 100644 --- a/test/test_suite.go +++ b/test/test_suite.go @@ -81,8 +81,9 @@ func BasicDATest(t *testing.T, d da.DA) { // CheckErrors ensures that errors are handled properly by DA. func CheckErrors(t *testing.T, d da.DA) { ctx := context.TODO() - blob, err := d.Get(ctx, []da.ID{[]byte("invalid")}, testNamespace) + blob, err := d.Get(ctx, []da.ID{[]byte("invalid blob id")}, testNamespace) assert.Error(t, err) + assert.ErrorIs(t, err, &da.ErrBlobNotFound{}) assert.Empty(t, blob) } From 31031bbcd14bcc8ae18469356c76c32f9a004ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Sun, 6 Oct 2024 23:47:01 +0200 Subject: [PATCH 02/10] feat: add detailed gRPC error handling for DA errors Implemented detailed gRPC error handling by defining custom error types and appropriate error codes for better differentiation in the DA package. Each error type now provides a gRPC status with granular error details using the newly introduced error codes. --- errors.go | 56 ++++++++- proto/da/da.proto | 15 +++ proxy/grpc/client.go | 8 +- proxy/grpc/errors.go | 47 +++++++ types/pb/da/da.pb.go | 294 ++++++++++++++++++++++++++++++++++++------- 5 files changed, 366 insertions(+), 54 deletions(-) create mode 100644 proxy/grpc/errors.go diff --git a/errors.go b/errors.go index 593d606..e69504c 100644 --- a/errors.go +++ b/errors.go @@ -3,8 +3,13 @@ package da import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + pbda "github.com/rollkit/go-da/types/pb/da" ) +// Code defines error codes for JSON-RPC. +// +// They are reused for GRPC type Code int // Codes are used by JSON-RPC client and server @@ -25,10 +30,6 @@ func (e *ErrBlobNotFound) Error() string { return "blob: not found" } -func (e *ErrBlobNotFound) GRPCStatus() *status.Status { - return status.New(codes.NotFound, e.Error()) -} - // ErrBlobSizeOverLimit is used to indicate that the blob size is over limit. type ErrBlobSizeOverLimit struct{} @@ -70,3 +71,50 @@ type ErrContextDeadline struct{} func (e *ErrContextDeadline) Error() string { return "context deadline" } + +// gRPC checks for GPRCStatus method on errors to enable advanced error handling. + +// getGRPCStatus constructs a gRPC status with error details based on the provided error, gRPC code, and DA error code. +func getGRPCStatus(err error, grpcCode codes.Code, daCode pbda.ErrorCode) *status.Status { + base := status.New(grpcCode, err.Error()) + detailed, err := base.WithDetails(&pbda.ErrorDetails{Code: daCode}) + if err != nil { + return base + } + return detailed +} + +// GRPCStatus returns the gRPC status with details for an ErrBlobNotFound error. +func (e *ErrBlobNotFound) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.NotFound, pbda.ErrorCode_BlobNotFound) +} + +// GRPCStatus returns the gRPC status with details for an ErrBlobSizeOverLimit error. +func (e *ErrBlobSizeOverLimit) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_BlobSizeOverLimit) +} + +// GRPCStatus returns the gRPC status with details for an ErrTxTimedOut error. +func (e *ErrTxTimedOut) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_TxTimedOut) +} + +// GRPCStatus returns the gRPC status with details for an ErrTxAlreadyInMempool error. +func (e *ErrTxAlreadyInMempool) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.AlreadyExists, pbda.ErrorCode_TxAlreadyInMempool) +} + +// GRPCStatus returns the gRPC status with details for an ErrTxIncorrectAccountSequence error. +func (e *ErrTxIncorrectAccountSequence) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.InvalidArgument, pbda.ErrorCode_TxIncorrectAccountSequence) +} + +// GRPCStatus returns the gRPC status with details for an ErrTxTooLarge error. +func (e *ErrTxTooLarge) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_TxTooLarge) +} + +// GRPCStatus returns the gRPC status with details for an ErrContextDeadline error. +func (e *ErrContextDeadline) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ContextDeadline) +} diff --git a/proto/da/da.proto b/proto/da/da.proto index de3ab40..42833aa 100644 --- a/proto/da/da.proto +++ b/proto/da/da.proto @@ -130,3 +130,18 @@ message ValidateRequest { message ValidateResponse { repeated bool results = 1; } + +enum ErrorCode { + Unknown = 0; + BlobNotFound = 32001; + BlobSizeOverLimit = 32002; + TxTimedOut = 32003; + TxAlreadyInMempool = 32004; + TxIncorrectAccountSequence = 32005; + TxTooLarge = 32006; + ContextDeadline = 32007; +} + +message ErrorDetails { + ErrorCode code = 1; +} \ No newline at end of file diff --git a/proxy/grpc/client.go b/proxy/grpc/client.go index b3ff79c..b90570d 100644 --- a/proxy/grpc/client.go +++ b/proxy/grpc/client.go @@ -2,7 +2,6 @@ package grpc import ( "context" - "google.golang.org/grpc/status" "github.com/cosmos/gogoproto/types" "google.golang.org/grpc" @@ -60,12 +59,7 @@ func (c *Client) Get(ctx context.Context, ids []da.ID, namespace da.Namespace) ( } resp, err := c.client.Get(ctx, req) if err != nil { - s, ok := status.FromError(err) - if ok && s.Message() == "blob: not found" { - return nil, &da.ErrBlobNotFound{} - } - - return nil, err + return nil, tryToMapError(err) } return blobsPB2DA(resp.Blobs), nil diff --git a/proxy/grpc/errors.go b/proxy/grpc/errors.go new file mode 100644 index 0000000..c28197f --- /dev/null +++ b/proxy/grpc/errors.go @@ -0,0 +1,47 @@ +package grpc + +import ( + "errors" + + "google.golang.org/grpc/status" + + "github.com/rollkit/go-da" + pbda "github.com/rollkit/go-da/types/pb/da" +) + +func tryToMapError(err error) error { + s, ok := status.FromError(err) + if ok { + details := s.Proto().Details + if len(details) == 1 { + var errorDetail pbda.ErrorDetails + unmarshalError := errorDetail.Unmarshal(details[0].Value) + if unmarshalError != nil { + return err + } + return errorForCode(errorDetail.Code) + } + } + return err +} + +func errorForCode(code pbda.ErrorCode) error { + switch code { + case pbda.ErrorCode_BlobNotFound: + return &da.ErrBlobNotFound{} + case pbda.ErrorCode_BlobSizeOverLimit: + return &da.ErrBlobSizeOverLimit{} + case pbda.ErrorCode_TxTimedOut: + return &da.ErrTxTimedOut{} + case pbda.ErrorCode_TxAlreadyInMempool: + return &da.ErrTxAlreadyInMempool{} + case pbda.ErrorCode_TxIncorrectAccountSequence: + return &da.ErrTxIncorrectAccountSequence{} + case pbda.ErrorCode_TxTooLarge: + return &da.ErrTxTooLarge{} + case pbda.ErrorCode_ContextDeadline: + return &da.ErrContextDeadline{} + default: + return errors.New("unknown error code") + } +} diff --git a/types/pb/da/da.pb.go b/types/pb/da/da.pb.go index ec3bdfb..bb67cb2 100644 --- a/types/pb/da/da.pb.go +++ b/types/pb/da/da.pb.go @@ -29,6 +29,49 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type ErrorCode int32 + +const ( + ErrorCode_Unknown ErrorCode = 0 + ErrorCode_BlobNotFound ErrorCode = 32001 + ErrorCode_BlobSizeOverLimit ErrorCode = 32002 + ErrorCode_TxTimedOut ErrorCode = 32003 + ErrorCode_TxAlreadyInMempool ErrorCode = 32004 + ErrorCode_TxIncorrectAccountSequence ErrorCode = 32005 + ErrorCode_TxTooLarge ErrorCode = 32006 + ErrorCode_ContextDeadline ErrorCode = 32007 +) + +var ErrorCode_name = map[int32]string{ + 0: "Unknown", + 32001: "BlobNotFound", + 32002: "BlobSizeOverLimit", + 32003: "TxTimedOut", + 32004: "TxAlreadyInMempool", + 32005: "TxIncorrectAccountSequence", + 32006: "TxTooLarge", + 32007: "ContextDeadline", +} + +var ErrorCode_value = map[string]int32{ + "Unknown": 0, + "BlobNotFound": 32001, + "BlobSizeOverLimit": 32002, + "TxTimedOut": 32003, + "TxAlreadyInMempool": 32004, + "TxIncorrectAccountSequence": 32005, + "TxTooLarge": 32006, + "ContextDeadline": 32007, +} + +func (x ErrorCode) String() string { + return proto.EnumName(ErrorCode_name, int32(x)) +} + +func (ErrorCode) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_feb508392bc12c0f, []int{0} +} + // Namespace is the location for the blob to be submitted to, if supported by the DA layer. type Namespace struct { Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` @@ -956,7 +999,52 @@ func (m *ValidateResponse) GetResults() []bool { return nil } +type ErrorDetails struct { + Code ErrorCode `protobuf:"varint,1,opt,name=code,proto3,enum=da.ErrorCode" json:"code,omitempty"` +} + +func (m *ErrorDetails) Reset() { *m = ErrorDetails{} } +func (m *ErrorDetails) String() string { return proto.CompactTextString(m) } +func (*ErrorDetails) ProtoMessage() {} +func (*ErrorDetails) Descriptor() ([]byte, []int) { + return fileDescriptor_feb508392bc12c0f, []int{19} +} +func (m *ErrorDetails) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ErrorDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ErrorDetails.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ErrorDetails) XXX_Merge(src proto.Message) { + xxx_messageInfo_ErrorDetails.Merge(m, src) +} +func (m *ErrorDetails) XXX_Size() int { + return m.Size() +} +func (m *ErrorDetails) XXX_DiscardUnknown() { + xxx_messageInfo_ErrorDetails.DiscardUnknown(m) +} + +var xxx_messageInfo_ErrorDetails proto.InternalMessageInfo + +func (m *ErrorDetails) GetCode() ErrorCode { + if m != nil { + return m.Code + } + return ErrorCode_Unknown +} + func init() { + proto.RegisterEnum("da.ErrorCode", ErrorCode_name, ErrorCode_value) proto.RegisterType((*Namespace)(nil), "da.Namespace") proto.RegisterType((*Blob)(nil), "da.Blob") proto.RegisterType((*ID)(nil), "da.ID") @@ -976,53 +1064,65 @@ func init() { proto.RegisterType((*SubmitResponse)(nil), "da.SubmitResponse") proto.RegisterType((*ValidateRequest)(nil), "da.ValidateRequest") proto.RegisterType((*ValidateResponse)(nil), "da.ValidateResponse") + proto.RegisterType((*ErrorDetails)(nil), "da.ErrorDetails") } func init() { proto.RegisterFile("da/da.proto", fileDescriptor_feb508392bc12c0f) } var fileDescriptor_feb508392bc12c0f = []byte{ - // 641 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x4f, 0x13, 0x41, - 0x14, 0xef, 0xb6, 0x50, 0xba, 0x6f, 0x6d, 0x81, 0xa1, 0xe2, 0x66, 0xd5, 0x15, 0xe6, 0xd4, 0xf8, - 0x51, 0x14, 0x13, 0xbf, 0x4e, 0x8a, 0x24, 0x0d, 0x07, 0x0d, 0xd9, 0x12, 0x13, 0x13, 0x13, 0x32, - 0x65, 0x87, 0xb2, 0x49, 0xb7, 0xb3, 0x76, 0xa6, 0x84, 0xe0, 0xd9, 0xbb, 0x89, 0xff, 0x94, 0x47, - 0x8e, 0x1e, 0x0d, 0xfc, 0x23, 0x66, 0x76, 0x66, 0x76, 0xbb, 0x90, 0xda, 0x34, 0xf1, 0xf8, 0xbe, - 0x7e, 0xef, 0x37, 0xef, 0xfd, 0xde, 0x80, 0x13, 0x92, 0xad, 0x90, 0xb4, 0x93, 0x11, 0x13, 0x0c, - 0x95, 0x43, 0xe2, 0x3d, 0xe8, 0x33, 0xd6, 0x1f, 0xd0, 0xad, 0xd4, 0xd3, 0x1b, 0x1f, 0x6f, 0x89, - 0x28, 0xa6, 0x5c, 0x90, 0x38, 0x51, 0x49, 0x78, 0x13, 0xec, 0x8f, 0x24, 0xa6, 0x3c, 0x21, 0x47, - 0x14, 0x35, 0x61, 0xf1, 0x94, 0x0c, 0xc6, 0xd4, 0xb5, 0x36, 0xac, 0xd6, 0xad, 0x40, 0x19, 0xf8, - 0x1e, 0x2c, 0xec, 0x0c, 0x58, 0x6f, 0x4a, 0xd4, 0x83, 0xf2, 0xde, 0xee, 0x94, 0x18, 0x06, 0x78, - 0xcf, 0xe2, 0x38, 0x12, 0x31, 0x1d, 0x8a, 0x29, 0x39, 0xf7, 0x61, 0x71, 0x7f, 0xc4, 0xd8, 0xf1, - 0x94, 0x70, 0x13, 0xd0, 0x07, 0x72, 0x26, 0xfb, 0x77, 0xa3, 0x73, 0x1a, 0xd0, 0xaf, 0x63, 0xca, - 0x05, 0x7e, 0x0d, 0x6b, 0x05, 0x2f, 0x4f, 0xd8, 0x90, 0x53, 0x84, 0xa1, 0x1e, 0x93, 0xb3, 0xc3, - 0xde, 0x80, 0xf5, 0x0e, 0x79, 0x74, 0xae, 0xa0, 0x16, 0x02, 0x27, 0xce, 0x73, 0x71, 0x17, 0xa0, - 0x43, 0x85, 0x06, 0x42, 0x2e, 0x54, 0xa2, 0x90, 0xbb, 0xd6, 0x46, 0xa5, 0xe5, 0x6c, 0x57, 0xdb, - 0x21, 0x69, 0xef, 0xed, 0x06, 0xd2, 0x85, 0x1e, 0x81, 0x3d, 0x34, 0x83, 0x71, 0xcb, 0x1b, 0x56, - 0xcb, 0xd9, 0xae, 0xcb, 0x78, 0x36, 0xad, 0x20, 0x8f, 0xe3, 0x27, 0xe0, 0xa4, 0xa0, 0x9a, 0x87, - 0x0f, 0x8b, 0x92, 0x83, 0xc1, 0xad, 0xc9, 0x3a, 0x49, 0x20, 0x50, 0x6e, 0x7c, 0x00, 0xf5, 0x0e, - 0x15, 0x7b, 0x21, 0x37, 0x34, 0xd6, 0xa1, 0x7a, 0x42, 0xa3, 0xfe, 0x89, 0xd0, 0x8c, 0xb5, 0x35, - 0x1f, 0x89, 0x10, 0x1a, 0x06, 0x55, 0xf3, 0x98, 0xfe, 0xba, 0x57, 0x60, 0x67, 0x4a, 0xd0, 0xc0, - 0x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, 0x5d, 0x36, 0xb9, 0xf9, 0xa3, 0x78, 0x77, 0x6e, 0xf8, 0x55, 0x1f, - 0x5c, 0x42, 0x2d, 0xa8, 0x74, 0xa8, 0x40, 0xe9, 0x82, 0xf3, 0xaf, 0xc3, 0x5b, 0xce, 0xec, 0x2c, - 0xf3, 0x19, 0x54, 0xd5, 0x05, 0xa2, 0x55, 0x1d, 0xcc, 0x6f, 0xdc, 0x43, 0x93, 0xae, 0xac, 0xe4, - 0x0d, 0xd8, 0x99, 0xe6, 0x51, 0x53, 0xa7, 0x14, 0xae, 0xcb, 0xbb, 0x7d, 0xcd, 0x3b, 0xd9, 0x4e, - 0x09, 0x4e, 0xb5, 0x2b, 0xdc, 0x80, 0x6a, 0x57, 0x14, 0xae, 0x2a, 0x51, 0x2b, 0x57, 0x25, 0x05, - 0x4d, 0xaa, 0x92, 0xa2, 0x22, 0x70, 0x09, 0xbd, 0x84, 0x9a, 0x19, 0x3e, 0x5a, 0x93, 0x19, 0xd7, - 0x74, 0xe0, 0x35, 0x8b, 0x4e, 0x53, 0xb8, 0xe3, 0xfe, 0xba, 0xf4, 0xad, 0x8b, 0x4b, 0xdf, 0xfa, - 0x73, 0xe9, 0x5b, 0x3f, 0xae, 0xfc, 0xd2, 0xc5, 0x95, 0x5f, 0xfa, 0x7d, 0xe5, 0x97, 0x7a, 0xd5, - 0xf4, 0x8b, 0x79, 0xfe, 0x37, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x5c, 0x10, 0x6e, 0xaf, 0x06, 0x00, - 0x00, + // 821 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x5b, 0x6f, 0xe3, 0x44, + 0x14, 0xce, 0x34, 0x6d, 0x5a, 0x1f, 0x37, 0xa9, 0x3b, 0xdb, 0xdd, 0xb5, 0x0c, 0x84, 0xee, 0x3c, + 0x45, 0x0b, 0xa4, 0x6c, 0x91, 0xb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b0, 0x53, 0xc8, 0x0d, 0xdf, 0x90, + 0x11, 0x2f, 0x29, 0xdf, 0x3a, 0xa8, 0x1b, 0x8b, 0xc4, 0x53, 0xf3, 0xef, 0xcb, 0x2e, 0x7a, 0x71, + 0xd9, 0x45, 0xff, 0x5e, 0x76, 0xd1, 0x1f, 0x57, 0xdd, 0xc6, 0x8b, 0xab, 0x6e, 0xe3, 0x9f, 0xab, + 0x6e, 0x63, 0xda, 0xca, 0x8e, 0xea, 0x07, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x5d, 0xd2, 0x55, + 0xa2, 0xa1, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1298,7 +1398,6 @@ func _DAService_Validate_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -var DAService_serviceDesc = _DAService_serviceDesc var _DAService_serviceDesc = grpc.ServiceDesc{ ServiceName: "da.DAService", HandlerType: (*DAServiceServer)(nil), @@ -2082,6 +2181,34 @@ func (m *ValidateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ErrorDetails) 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 *ErrorDetails) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ErrorDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Code != 0 { + i = encodeVarintDa(dAtA, i, uint64(m.Code)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintDa(dAtA []byte, offset int, v uint64) int { offset -= sovDa(v) base := offset @@ -2394,6 +2521,18 @@ func (m *ValidateResponse) Size() (n int) { return n } +func (m *ErrorDetails) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Code != 0 { + n += 1 + sovDa(uint64(m.Code)) + } + return n +} + func sovDa(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -4299,6 +4438,75 @@ func (m *ValidateResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *ErrorDetails) 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 ErrIntOverflowDa + } + 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: ErrorDetails: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ErrorDetails: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Code", wireType) + } + m.Code = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDa + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Code |= ErrorCode(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDa(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDa + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipDa(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 25a3a0329751f23f1c2f5c7bb9a0c1cc0bebc4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 00:05:00 +0200 Subject: [PATCH 03/10] refactor: add proper support for future height error Introduced a new error code and corresponding error type for when a requested height is from the future. Updated functions to handle this new type and included its gRPC status representation. --- errors.go | 13 +++++ proto/da/da.proto | 1 + proxy/grpc/errors.go | 6 +++ proxy/jsonrpc/client.go | 1 + proxy/jsonrpc/server.go | 1 + test/dummy.go | 5 +- test/test_suite.go | 3 +- types/pb/da/da.pb.go | 105 +++++++++++++++++++++------------------- 8 files changed, 79 insertions(+), 56 deletions(-) diff --git a/errors.go b/errors.go index e69504c..0aa2472 100644 --- a/errors.go +++ b/errors.go @@ -21,6 +21,7 @@ const ( CodeTxIncorrectAccountSequence Code = 32005 CodeTxTooLarge Code = 32006 CodeContextDeadline Code = 32007 + CodeFutureHeight Code = 32008 ) // ErrBlobNotFound is used to indicate that the blob was not found. @@ -72,6 +73,13 @@ func (e *ErrContextDeadline) Error() string { return "context deadline" } +// ErrFutureHeight is returned when requested height is from the future +type ErrFutureHeight struct{} + +func (e *ErrFutureHeight) Error() string { + return "given height is from the future" +} + // gRPC checks for GPRCStatus method on errors to enable advanced error handling. // getGRPCStatus constructs a gRPC status with error details based on the provided error, gRPC code, and DA error code. @@ -118,3 +126,8 @@ func (e *ErrTxTooLarge) GRPCStatus() *status.Status { func (e *ErrContextDeadline) GRPCStatus() *status.Status { return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ContextDeadline) } + +// GRPCStatus returns the gRPC status with details for an ErrFutureHeight error. +func (e *ErrFutureHeight) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.OutOfRange, pbda.ErrorCode_FutureHeight) +} diff --git a/proto/da/da.proto b/proto/da/da.proto index 42833aa..c10251a 100644 --- a/proto/da/da.proto +++ b/proto/da/da.proto @@ -140,6 +140,7 @@ enum ErrorCode { TxIncorrectAccountSequence = 32005; TxTooLarge = 32006; ContextDeadline = 32007; + FutureHeight = 32008; } message ErrorDetails { diff --git a/proxy/grpc/errors.go b/proxy/grpc/errors.go index c28197f..d6b8fd4 100644 --- a/proxy/grpc/errors.go +++ b/proxy/grpc/errors.go @@ -10,6 +10,10 @@ import ( ) func tryToMapError(err error) error { + if err == nil { + return nil + } + s, ok := status.FromError(err) if ok { details := s.Proto().Details @@ -41,6 +45,8 @@ func errorForCode(code pbda.ErrorCode) error { return &da.ErrTxTooLarge{} case pbda.ErrorCode_ContextDeadline: return &da.ErrContextDeadline{} + case pbda.ErrorCode_FutureHeight: + return &da.ErrFutureHeight{} default: return errors.New("unknown error code") } diff --git a/proxy/jsonrpc/client.go b/proxy/jsonrpc/client.go index 44c5e24..fd45d2c 100644 --- a/proxy/jsonrpc/client.go +++ b/proxy/jsonrpc/client.go @@ -118,6 +118,7 @@ func newClient(ctx context.Context, addr string, authHeader http.Header) (*Clien errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) + errs.Register(jsonrpc.ErrorCode(da.CodeFutureHeight), new(*da.ErrFutureHeight)) for name, module := range moduleMap(&client) { closer, err := jsonrpc.NewMergeClient(ctx, addr, name, []interface{}{module}, authHeader, jsonrpc.WithErrors(errs)) if err != nil { diff --git a/proxy/jsonrpc/server.go b/proxy/jsonrpc/server.go index 63ac661..3281e15 100644 --- a/proxy/jsonrpc/server.go +++ b/proxy/jsonrpc/server.go @@ -41,6 +41,7 @@ func NewServer(address, port string, DA da.DA) *Server { errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) + errs.Register(jsonrpc.ErrorCode(da.CodeFutureHeight), new(*da.ErrFutureHeight)) rpc := jsonrpc.NewServer(jsonrpc.WithServerErrors(errs)) srv := &Server{ rpc: rpc, diff --git a/test/dummy.go b/test/dummy.go index f0eeb98..9d678a1 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -17,9 +17,6 @@ import ( // DefaultMaxBlobSize is the default max blob size const DefaultMaxBlobSize = 64 * 64 * 482 -// ErrTooHigh is returned when requested height is to high -var ErrTooHigh = errors.New("given height is from the future") - // DummyDA is a simple implementation of in-memory DA. Not production ready! Intended only for testing! // // Data is stored in a map, where key is a serialized sequence number. This key is returned as ID. @@ -90,7 +87,7 @@ func (d *DummyDA) GetIDs(ctx context.Context, height uint64, _ da.Namespace) (*d defer d.mu.Unlock() if height > d.height { - return nil, ErrTooHigh + return nil, &da.ErrFutureHeight{} } kvps, ok := d.data[height] diff --git a/test/test_suite.go b/test/test_suite.go index 2aabf00..c742751 100644 --- a/test/test_suite.go +++ b/test/test_suite.go @@ -141,7 +141,7 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) { for i := uint64(1); i <= 100; i++ { _, err := d.GetIDs(ctx, i, []byte{}) if err != nil { - assert.Equal(t, err.Error(), ErrTooHigh.Error()) + assert.ErrorIs(t, err, &da.ErrFutureHeight{}) } } }() @@ -162,5 +162,6 @@ func HeightFromFutureTest(t *testing.T, d da.DA) { ctx := context.TODO() ret, err := d.GetIDs(ctx, 999999999, []byte{}) assert.Error(t, err) + assert.ErrorIs(t, err, &da.ErrFutureHeight{}) assert.Nil(t, ret) } diff --git a/types/pb/da/da.pb.go b/types/pb/da/da.pb.go index bb67cb2..ac2eb8d 100644 --- a/types/pb/da/da.pb.go +++ b/types/pb/da/da.pb.go @@ -40,6 +40,7 @@ const ( ErrorCode_TxIncorrectAccountSequence ErrorCode = 32005 ErrorCode_TxTooLarge ErrorCode = 32006 ErrorCode_ContextDeadline ErrorCode = 32007 + ErrorCode_FutureHeight ErrorCode = 32008 ) var ErrorCode_name = map[int32]string{ @@ -51,6 +52,7 @@ var ErrorCode_name = map[int32]string{ 32005: "TxIncorrectAccountSequence", 32006: "TxTooLarge", 32007: "ContextDeadline", + 32008: "FutureHeight", } var ErrorCode_value = map[string]int32{ @@ -62,6 +64,7 @@ var ErrorCode_value = map[string]int32{ "TxIncorrectAccountSequence": 32005, "TxTooLarge": 32006, "ContextDeadline": 32007, + "FutureHeight": 32008, } func (x ErrorCode) String() string { @@ -1070,59 +1073,59 @@ func init() { func init() { proto.RegisterFile("da/da.proto", fileDescriptor_feb508392bc12c0f) } var fileDescriptor_feb508392bc12c0f = []byte{ - // 821 bytes of a gzipped FileDescriptorProto + // 832 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x5b, 0x6f, 0xe3, 0x44, 0x14, 0xce, 0x34, 0x6d, 0x5a, 0x1f, 0x37, 0xa9, 0x3b, 0xdb, 0xdd, 0xb5, 0x0c, 0x84, 0xee, 0x3c, - 0x45, 0x0b, 0xa4, 0x6c, 0x91, 0xb8, 0x3d, 0xd1, 0x36, 0x10, 0x45, 0xda, 0x9b, 0x9c, 0x80, 0x84, - 0x84, 0x54, 0x4d, 0xec, 0xd9, 0xac, 0x85, 0xed, 0x31, 0xf6, 0xb8, 0x84, 0xe5, 0x89, 0xcb, 0xc2, - 0x2b, 0x12, 0x7f, 0x87, 0x1f, 0xc0, 0xe3, 0x3e, 0xf2, 0x88, 0xda, 0x7f, 0x91, 0x27, 0x34, 0x1e, - 0x5f, 0xe2, 0x5d, 0x85, 0x2a, 0xd2, 0x3e, 0xce, 0xb9, 0x7c, 0xe7, 0x9b, 0x73, 0xbe, 0x73, 0x40, - 0x77, 0xe9, 0x91, 0x4b, 0xfb, 0x51, 0xcc, 0x05, 0xc7, 0x1b, 0x2e, 0xb5, 0xde, 0x9e, 0x71, 0x3e, - 0xf3, 0xd9, 0x51, 0x66, 0x99, 0xa6, 0x4f, 0x8e, 0x84, 0x17, 0xb0, 0x44, 0xd0, 0x20, 0x52, 0x41, - 0xe4, 0x0e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 0x71, 0xd9, 0x45, 0xff, 0x5e, 0x76, + 0xd1, 0x9f, 0x57, 0xdd, 0xc6, 0xc5, 0x55, 0xb7, 0xf1, 0xcf, 0x55, 0xb7, 0x31, 0x69, 0x65, 0x42, + 0xfb, 0xc1, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xf5, 0xc7, 0x84, 0xb5, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From 15443a31bd369c940fd0313f40d719ec999cc35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 00:06:26 +0200 Subject: [PATCH 04/10] feat: add error mapping to all methods in gRPC proxy client Previously, only `Get` method supported proper error mapping. --- proxy/grpc/client.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/proxy/grpc/client.go b/proxy/grpc/client.go index b90570d..39dc0cc 100644 --- a/proxy/grpc/client.go +++ b/proxy/grpc/client.go @@ -43,7 +43,7 @@ func (c *Client) MaxBlobSize(ctx context.Context) (uint64, error) { req := &pbda.MaxBlobSizeRequest{} resp, err := c.client.MaxBlobSize(ctx, req) if err != nil { - return 0, err + return 0, tryToMapError(err) } return resp.MaxBlobSize, nil } @@ -70,7 +70,7 @@ func (c *Client) GetIDs(ctx context.Context, height uint64, namespace da.Namespa req := &pbda.GetIdsRequest{Height: height, Namespace: &pbda.Namespace{Value: namespace}} resp, err := c.client.GetIds(ctx, req) if err != nil { - return nil, err + return nil, tryToMapError(err) } timestamp, err := types.TimestampFromProto(resp.Timestamp) @@ -103,7 +103,7 @@ func (c *Client) Commit(ctx context.Context, blobs []da.Blob, namespace da.Names resp, err := c.client.Commit(ctx, req) if err != nil { - return nil, err + return nil, tryToMapError(err) } return commitsPB2DA(resp.Commitments), nil @@ -119,7 +119,7 @@ func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, resp, err := c.client.Submit(ctx, req) if err != nil { - return nil, err + return nil, tryToMapError(err) } ids := make([]da.ID, len(resp.Ids)) @@ -141,7 +141,7 @@ func (c *Client) SubmitWithOptions(ctx context.Context, blobs []da.Blob, gasPric resp, err := c.client.Submit(ctx, req) if err != nil { - return nil, err + return nil, tryToMapError(err) } ids := make([]da.ID, len(resp.Ids)) @@ -160,5 +160,5 @@ func (c *Client) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, n Namespace: &pbda.Namespace{Value: namespace}, } resp, err := c.client.Validate(ctx, req) - return resp.Results, err + return resp.Results, tryToMapError(err) } From e875df49003b17a735eb200ea82fc4d1a2adf095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 00:09:43 +0200 Subject: [PATCH 05/10] refactor: extract error mapping into a reusable function Centralize the error code to error type mapping by creating a reusable `getKnownErrorsMapping` function. This change reduces code redundancy and improves maintainability. --- proxy/jsonrpc/client.go | 11 +---------- proxy/jsonrpc/errors.go | 21 +++++++++++++++++++++ proxy/jsonrpc/server.go | 12 +----------- 3 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 proxy/jsonrpc/errors.go diff --git a/proxy/jsonrpc/client.go b/proxy/jsonrpc/client.go index fd45d2c..144dd44 100644 --- a/proxy/jsonrpc/client.go +++ b/proxy/jsonrpc/client.go @@ -109,16 +109,7 @@ func NewClient(ctx context.Context, addr string, token string) (*Client, error) func newClient(ctx context.Context, addr string, authHeader http.Header) (*Client, error) { var multiCloser multiClientCloser var client Client - errs := jsonrpc.NewErrors() - errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) - errs.Register(jsonrpc.ErrorCode(da.CodeBlobNotFound), new(*da.ErrBlobNotFound)) - errs.Register(jsonrpc.ErrorCode(da.CodeBlobSizeOverLimit), new(*da.ErrBlobSizeOverLimit)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxTimedOut), new(*da.ErrTxTimedOut)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) - errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) - errs.Register(jsonrpc.ErrorCode(da.CodeFutureHeight), new(*da.ErrFutureHeight)) + errs := getKnownErrorsMapping() for name, module := range moduleMap(&client) { closer, err := jsonrpc.NewMergeClient(ctx, addr, name, []interface{}{module}, authHeader, jsonrpc.WithErrors(errs)) if err != nil { diff --git a/proxy/jsonrpc/errors.go b/proxy/jsonrpc/errors.go new file mode 100644 index 0000000..2ff4489 --- /dev/null +++ b/proxy/jsonrpc/errors.go @@ -0,0 +1,21 @@ +package jsonrpc + +import ( + "github.com/filecoin-project/go-jsonrpc" + + "github.com/rollkit/go-da" +) + +// getKnownErrorsMapping returns a mapping of known error codes to their corresponding error types. +func getKnownErrorsMapping() jsonrpc.Errors { + errs := jsonrpc.NewErrors() + errs.Register(jsonrpc.ErrorCode(da.CodeBlobNotFound), new(*da.ErrBlobNotFound)) + errs.Register(jsonrpc.ErrorCode(da.CodeBlobSizeOverLimit), new(*da.ErrBlobSizeOverLimit)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTimedOut), new(*da.ErrTxTimedOut)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) + errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) + errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) + errs.Register(jsonrpc.ErrorCode(da.CodeFutureHeight), new(*da.ErrFutureHeight)) + return errs +} diff --git a/proxy/jsonrpc/server.go b/proxy/jsonrpc/server.go index 3281e15..3afb060 100644 --- a/proxy/jsonrpc/server.go +++ b/proxy/jsonrpc/server.go @@ -32,17 +32,7 @@ func (s *Server) RegisterService(namespace string, service interface{}, out inte // NewServer accepts the host address port and the DA implementation to serve as a jsonrpc service func NewServer(address, port string, DA da.DA) *Server { - errs := jsonrpc.NewErrors() - errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) - errs.Register(jsonrpc.ErrorCode(da.CodeBlobNotFound), new(*da.ErrBlobNotFound)) - errs.Register(jsonrpc.ErrorCode(da.CodeBlobSizeOverLimit), new(*da.ErrBlobSizeOverLimit)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxTimedOut), new(*da.ErrTxTimedOut)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxAlreadyInMempool), new(*da.ErrTxAlreadyInMempool)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxIncorrectAccountSequence), new(*da.ErrTxIncorrectAccountSequence)) - errs.Register(jsonrpc.ErrorCode(da.CodeTxTooLarge), new(*da.ErrTxTooLarge)) - errs.Register(jsonrpc.ErrorCode(da.CodeContextDeadline), new(*da.ErrContextDeadline)) - errs.Register(jsonrpc.ErrorCode(da.CodeFutureHeight), new(*da.ErrFutureHeight)) - rpc := jsonrpc.NewServer(jsonrpc.WithServerErrors(errs)) + rpc := jsonrpc.NewServer(jsonrpc.WithServerErrors(getKnownErrorsMapping())) srv := &Server{ rpc: rpc, srv: &http.Server{ From e0bdd5c116fa0ad4ff22c47f29ccda01936a3a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 00:15:59 +0200 Subject: [PATCH 06/10] refactor: reformat ErrorCode enum entries Unified the indentation style for all enum entries in ErrorCode. This improves code readability and consistency within the proto file. --- proto/da/da.proto | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/proto/da/da.proto b/proto/da/da.proto index c10251a..4f5d3c1 100644 --- a/proto/da/da.proto +++ b/proto/da/da.proto @@ -132,15 +132,15 @@ message ValidateResponse { } enum ErrorCode { - Unknown = 0; - BlobNotFound = 32001; - BlobSizeOverLimit = 32002; - TxTimedOut = 32003; - TxAlreadyInMempool = 32004; - TxIncorrectAccountSequence = 32005; - TxTooLarge = 32006; - ContextDeadline = 32007; - FutureHeight = 32008; + Unknown = 0; + BlobNotFound = 32001; + BlobSizeOverLimit = 32002; + TxTimedOut = 32003; + TxAlreadyInMempool = 32004; + TxIncorrectAccountSequence = 32005; + TxTooLarge = 32006; + ContextDeadline = 32007; + FutureHeight = 32008; } message ErrorDetails { From 181b67491393a47bdf5fd0f7ac34636a42035a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 00:24:50 +0200 Subject: [PATCH 07/10] chore: fix protobuf enum names (linting) --- errors.go | 16 ++--- proto/da/da.proto | 18 ++--- proxy/grpc/errors.go | 16 ++--- types/pb/da/da.pb.go | 166 ++++++++++++++++++++++--------------------- 4 files changed, 110 insertions(+), 106 deletions(-) diff --git a/errors.go b/errors.go index 0aa2472..55ca55d 100644 --- a/errors.go +++ b/errors.go @@ -94,40 +94,40 @@ func getGRPCStatus(err error, grpcCode codes.Code, daCode pbda.ErrorCode) *statu // GRPCStatus returns the gRPC status with details for an ErrBlobNotFound error. func (e *ErrBlobNotFound) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.NotFound, pbda.ErrorCode_BlobNotFound) + return getGRPCStatus(e, codes.NotFound, pbda.ErrorCode_ERROR_CODE_BLOB_NOT_FOUND) } // GRPCStatus returns the gRPC status with details for an ErrBlobSizeOverLimit error. func (e *ErrBlobSizeOverLimit) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_BlobSizeOverLimit) + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_BLOB_SIZE_OVER_LIMIT) } // GRPCStatus returns the gRPC status with details for an ErrTxTimedOut error. func (e *ErrTxTimedOut) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_TxTimedOut) + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_TX_TIMED_OUT) } // GRPCStatus returns the gRPC status with details for an ErrTxAlreadyInMempool error. func (e *ErrTxAlreadyInMempool) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.AlreadyExists, pbda.ErrorCode_TxAlreadyInMempool) + return getGRPCStatus(e, codes.AlreadyExists, pbda.ErrorCode_ERROR_CODE_TX_ALREADY_IN_MEMPOOL) } // GRPCStatus returns the gRPC status with details for an ErrTxIncorrectAccountSequence error. func (e *ErrTxIncorrectAccountSequence) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.InvalidArgument, pbda.ErrorCode_TxIncorrectAccountSequence) + return getGRPCStatus(e, codes.InvalidArgument, pbda.ErrorCode_ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE) } // GRPCStatus returns the gRPC status with details for an ErrTxTooLarge error. func (e *ErrTxTooLarge) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_TxTooLarge) + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_TX_TOO_LARGE) } // GRPCStatus returns the gRPC status with details for an ErrContextDeadline error. func (e *ErrContextDeadline) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ContextDeadline) + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_CONTEXT_DEADLINE) } // GRPCStatus returns the gRPC status with details for an ErrFutureHeight error. func (e *ErrFutureHeight) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.OutOfRange, pbda.ErrorCode_FutureHeight) + return getGRPCStatus(e, codes.OutOfRange, pbda.ErrorCode_ERROR_CODE_FUTURE_HEIGHT) } diff --git a/proto/da/da.proto b/proto/da/da.proto index 4f5d3c1..1b2fff7 100644 --- a/proto/da/da.proto +++ b/proto/da/da.proto @@ -132,15 +132,15 @@ message ValidateResponse { } enum ErrorCode { - Unknown = 0; - BlobNotFound = 32001; - BlobSizeOverLimit = 32002; - TxTimedOut = 32003; - TxAlreadyInMempool = 32004; - TxIncorrectAccountSequence = 32005; - TxTooLarge = 32006; - ContextDeadline = 32007; - FutureHeight = 32008; + ERROR_CODE_UNSPECIFIED = 0; + ERROR_CODE_BLOB_NOT_FOUND = 32001; + ERROR_CODE_BLOB_SIZE_OVER_LIMIT = 32002; + ERROR_CODE_TX_TIMED_OUT = 32003; + ERROR_CODE_TX_ALREADY_IN_MEMPOOL = 32004; + ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE = 32005; + ERROR_CODE_TX_TOO_LARGE = 32006; + ERROR_CODE_CONTEXT_DEADLINE = 32007; + ERROR_CODE_FUTURE_HEIGHT = 32008; } message ErrorDetails { diff --git a/proxy/grpc/errors.go b/proxy/grpc/errors.go index d6b8fd4..81fea40 100644 --- a/proxy/grpc/errors.go +++ b/proxy/grpc/errors.go @@ -31,21 +31,21 @@ func tryToMapError(err error) error { func errorForCode(code pbda.ErrorCode) error { switch code { - case pbda.ErrorCode_BlobNotFound: + case pbda.ErrorCode_ERROR_CODE_BLOB_NOT_FOUND: return &da.ErrBlobNotFound{} - case pbda.ErrorCode_BlobSizeOverLimit: + case pbda.ErrorCode_ERROR_CODE_BLOB_SIZE_OVER_LIMIT: return &da.ErrBlobSizeOverLimit{} - case pbda.ErrorCode_TxTimedOut: + case pbda.ErrorCode_ERROR_CODE_TX_TIMED_OUT: return &da.ErrTxTimedOut{} - case pbda.ErrorCode_TxAlreadyInMempool: + case pbda.ErrorCode_ERROR_CODE_TX_ALREADY_IN_MEMPOOL: return &da.ErrTxAlreadyInMempool{} - case pbda.ErrorCode_TxIncorrectAccountSequence: + case pbda.ErrorCode_ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE: return &da.ErrTxIncorrectAccountSequence{} - case pbda.ErrorCode_TxTooLarge: + case pbda.ErrorCode_ERROR_CODE_TX_TOO_LARGE: return &da.ErrTxTooLarge{} - case pbda.ErrorCode_ContextDeadline: + case pbda.ErrorCode_ERROR_CODE_CONTEXT_DEADLINE: return &da.ErrContextDeadline{} - case pbda.ErrorCode_FutureHeight: + case pbda.ErrorCode_ERROR_CODE_FUTURE_HEIGHT: return &da.ErrFutureHeight{} default: return errors.New("unknown error code") diff --git a/types/pb/da/da.pb.go b/types/pb/da/da.pb.go index ac2eb8d..d1cbb8c 100644 --- a/types/pb/da/da.pb.go +++ b/types/pb/da/da.pb.go @@ -32,39 +32,39 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type ErrorCode int32 const ( - ErrorCode_Unknown ErrorCode = 0 - ErrorCode_BlobNotFound ErrorCode = 32001 - ErrorCode_BlobSizeOverLimit ErrorCode = 32002 - ErrorCode_TxTimedOut ErrorCode = 32003 - ErrorCode_TxAlreadyInMempool ErrorCode = 32004 - ErrorCode_TxIncorrectAccountSequence ErrorCode = 32005 - ErrorCode_TxTooLarge ErrorCode = 32006 - ErrorCode_ContextDeadline ErrorCode = 32007 - ErrorCode_FutureHeight ErrorCode = 32008 + ErrorCode_ERROR_CODE_UNSPECIFIED ErrorCode = 0 + ErrorCode_ERROR_CODE_BLOB_NOT_FOUND ErrorCode = 32001 + ErrorCode_ERROR_CODE_BLOB_SIZE_OVER_LIMIT ErrorCode = 32002 + ErrorCode_ERROR_CODE_TX_TIMED_OUT ErrorCode = 32003 + ErrorCode_ERROR_CODE_TX_ALREADY_IN_MEMPOOL ErrorCode = 32004 + ErrorCode_ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE ErrorCode = 32005 + ErrorCode_ERROR_CODE_TX_TOO_LARGE ErrorCode = 32006 + ErrorCode_ERROR_CODE_CONTEXT_DEADLINE ErrorCode = 32007 + ErrorCode_ERROR_CODE_FUTURE_HEIGHT ErrorCode = 32008 ) var ErrorCode_name = map[int32]string{ - 0: "Unknown", - 32001: "BlobNotFound", - 32002: "BlobSizeOverLimit", - 32003: "TxTimedOut", - 32004: "TxAlreadyInMempool", - 32005: "TxIncorrectAccountSequence", - 32006: "TxTooLarge", - 32007: "ContextDeadline", - 32008: "FutureHeight", + 0: "ERROR_CODE_UNSPECIFIED", + 32001: "ERROR_CODE_BLOB_NOT_FOUND", + 32002: "ERROR_CODE_BLOB_SIZE_OVER_LIMIT", + 32003: "ERROR_CODE_TX_TIMED_OUT", + 32004: "ERROR_CODE_TX_ALREADY_IN_MEMPOOL", + 32005: "ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE", + 32006: "ERROR_CODE_TX_TOO_LARGE", + 32007: "ERROR_CODE_CONTEXT_DEADLINE", + 32008: "ERROR_CODE_FUTURE_HEIGHT", } var ErrorCode_value = map[string]int32{ - "Unknown": 0, - "BlobNotFound": 32001, - "BlobSizeOverLimit": 32002, - "TxTimedOut": 32003, - "TxAlreadyInMempool": 32004, - "TxIncorrectAccountSequence": 32005, - "TxTooLarge": 32006, - "ContextDeadline": 32007, - "FutureHeight": 32008, + "ERROR_CODE_UNSPECIFIED": 0, + "ERROR_CODE_BLOB_NOT_FOUND": 32001, + "ERROR_CODE_BLOB_SIZE_OVER_LIMIT": 32002, + "ERROR_CODE_TX_TIMED_OUT": 32003, + "ERROR_CODE_TX_ALREADY_IN_MEMPOOL": 32004, + "ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE": 32005, + "ERROR_CODE_TX_TOO_LARGE": 32006, + "ERROR_CODE_CONTEXT_DEADLINE": 32007, + "ERROR_CODE_FUTURE_HEIGHT": 32008, } func (x ErrorCode) String() string { @@ -1043,7 +1043,7 @@ func (m *ErrorDetails) GetCode() ErrorCode { if m != nil { return m.Code } - return ErrorCode_Unknown + return ErrorCode_ERROR_CODE_UNSPECIFIED } func init() { @@ -1073,59 +1073,63 @@ func init() { func init() { proto.RegisterFile("da/da.proto", fileDescriptor_feb508392bc12c0f) } var fileDescriptor_feb508392bc12c0f = []byte{ - // 832 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x5b, 0x6f, 0xe3, 0x44, - 0x14, 0xce, 0x34, 0x6d, 0x5a, 0x1f, 0x37, 0xa9, 0x3b, 0xdb, 0xdd, 0xb5, 0x0c, 0x84, 0xee, 0x3c, - 0x55, 0x0b, 0xa4, 0x6c, 0x91, 0xb8, 0x3d, 0xd1, 0x36, 0x6c, 0x88, 0xb4, 0x37, 0x39, 0x01, 0x09, - 0x09, 0xa9, 0x9a, 0xd8, 0xb3, 0x59, 0x0b, 0xdb, 0x63, 0xec, 0x71, 0x09, 0xcb, 0x13, 0x97, 0x05, - 0x1e, 0x91, 0xf8, 0x53, 0x3c, 0xf6, 0x91, 0x47, 0xd4, 0xfe, 0x8b, 0x3c, 0xa1, 0xf1, 0xf8, 0x12, - 0xef, 0x2a, 0x54, 0x91, 0xf6, 0x71, 0xce, 0xf5, 0x9b, 0x73, 0xbe, 0xf3, 0x81, 0xee, 0xd2, 0x43, - 0x97, 0xf6, 0xa2, 0x98, 0x0b, 0x8e, 0xd7, 0x5c, 0x6a, 0xbd, 0x3d, 0xe5, 0x7c, 0xea, 0xb3, 0xc3, - 0xcc, 0x32, 0x49, 0x9f, 0x1e, 0x0a, 0x2f, 0x60, 0x89, 0xa0, 0x41, 0xa4, 0x82, 0xc8, 0x1d, 0xd0, - 0x1e, 0xd1, 0x80, 0x25, 0x11, 0x75, 0x18, 0xde, 0x83, 0x8d, 0x73, 0xea, 0xa7, 0xcc, 0x44, 0xfb, - 0xe8, 0x60, 0xdb, 0x56, 0x0f, 0xf2, 0x26, 0xac, 0x9f, 0xf8, 0x7c, 0xb2, 0xc4, 0x6b, 0xc1, 0xda, - 0xb0, 0xbf, 0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0x5e, 0x09, 0xa8, 0xb5, 0x53, 0xbe, 0xcb, 0xc8, 0x7b, 0xd0, 0x52, 0x3a, - 0x84, 0x77, 0x73, 0x67, 0xa5, 0x74, 0x16, 0x5e, 0x34, 0x95, 0x29, 0x9f, 0x82, 0x56, 0x5e, 0x3e, - 0xde, 0xcb, 0x43, 0x6a, 0x1a, 0x63, 0xdd, 0x7c, 0xc9, 0xba, 0xd8, 0x4e, 0x9d, 0x9d, 0x6a, 0x57, - 0x53, 0x02, 0xd5, 0xae, 0x7e, 0xbe, 0x2a, 0x45, 0x11, 0x5f, 0xa5, 0xd4, 0x2e, 0x53, 0xa5, 0xd4, - 0xef, 0x82, 0x34, 0xf0, 0x47, 0xb0, 0x55, 0x50, 0x10, 0xdf, 0x90, 0x11, 0x2f, 0x5d, 0x83, 0xb5, - 0x57, 0x37, 0x16, 0x89, 0x27, 0xe6, 0xdf, 0x97, 0x5d, 0x74, 0x71, 0xd9, 0x45, 0xff, 0x5e, 0x76, - 0xd1, 0x9f, 0x57, 0xdd, 0xc6, 0xc5, 0x55, 0xb7, 0xf1, 0xcf, 0x55, 0xb7, 0x31, 0x69, 0x65, 0x42, - 0xfb, 0xc1, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xf5, 0xc7, 0x84, 0xb5, 0x07, 0x00, 0x00, + // 888 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4d, 0x6f, 0xdb, 0x46, + 0x10, 0x15, 0x25, 0x5b, 0xb1, 0x46, 0x91, 0xc2, 0x6c, 0x5c, 0x47, 0x55, 0x1a, 0xd9, 0x5e, 0xa0, + 0x85, 0x90, 0xb6, 0x72, 0xe3, 0x02, 0xfd, 0x3a, 0x55, 0x22, 0xd7, 0x0a, 0x01, 0x89, 0x74, 0x57, + 0x54, 0x90, 0x14, 0x05, 0x16, 0x94, 0xb9, 0x51, 0x08, 0x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x82, 0x52, 0xe2, 0x38, 0x68, 0x3b, 0xa2, 0x64, 0xbc, 0xad, 0xfe, 0xce, 0x85, + 0x68, 0xba, 0x9d, 0x58, 0x77, 0xd1, 0x2e, 0xe3, 0x40, 0xa2, 0x5d, 0xd6, 0x36, 0x44, 0x8a, 0x58, + 0x38, 0x91, 0x92, 0x71, 0x04, 0x91, 0x92, 0xdd, 0x47, 0x9c, 0x43, 0x9f, 0xc3, 0x56, 0x3c, 0xfa, + 0xe8, 0x4e, 0xc0, 0xb8, 0xb0, 0x85, 0xf5, 0xed, 0x6c, 0x30, 0x4e, 0xec, 0xd4, 0xde, 0x9c, 0x35, + 0xa4, 0xb7, 0x67, 0x0d, 0xe9, 0xef, 0xb3, 0x86, 0xf4, 0xc7, 0x79, 0x23, 0xf7, 0xf6, 0xbc, 0x91, + 0xfb, 0xeb, 0xbc, 0x91, 0x1b, 0x15, 0x43, 0x83, 0xff, 0xf4, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x07, 0xc0, 0x94, 0xa0, 0x2d, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. From e9f4c7ac6fba27a59e068f8cd504ca0fb1c01a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 09:27:15 +0200 Subject: [PATCH 08/10] chore: regenerate protobuf with latest version of protoc-gen-gocosmos --- types/pb/da/da.pb.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types/pb/da/da.pb.go b/types/pb/da/da.pb.go index d1cbb8c..0df0c6f 100644 --- a/types/pb/da/da.pb.go +++ b/types/pb/da/da.pb.go @@ -1405,6 +1405,7 @@ func _DAService_Validate_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +var DAService_serviceDesc = _DAService_serviceDesc var _DAService_serviceDesc = grpc.ServiceDesc{ ServiceName: "da.DAService", HandlerType: (*DAServiceServer)(nil), From 61b9787549f5354101fc8912873453d6cf6e6f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Oct 2024 09:28:31 +0200 Subject: [PATCH 09/10] docs: fix typos in comments --- errors.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/errors.go b/errors.go index 55ca55d..31d71e8 100644 --- a/errors.go +++ b/errors.go @@ -9,7 +9,7 @@ import ( // Code defines error codes for JSON-RPC. // -// They are reused for GRPC +// They are reused for gRPC type Code int // Codes are used by JSON-RPC client and server @@ -80,7 +80,7 @@ func (e *ErrFutureHeight) Error() string { return "given height is from the future" } -// gRPC checks for GPRCStatus method on errors to enable advanced error handling. +// gRPC checks for GRPCStatus method on errors to enable advanced error handling. // getGRPCStatus constructs a gRPC status with error details based on the provided error, gRPC code, and DA error code. func getGRPCStatus(err error, grpcCode codes.Code, daCode pbda.ErrorCode) *status.Status { From 6dc122e85ad66bf56fd2d648c88a853db277b126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Tue, 5 Nov 2024 09:01:49 +0100 Subject: [PATCH 10/10] refactor: group methods by type in errors.go --- errors.go | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/errors.go b/errors.go index 31d71e8..fb84c79 100644 --- a/errors.go +++ b/errors.go @@ -12,6 +12,8 @@ import ( // They are reused for gRPC type Code int +// gRPC checks for GRPCStatus method on errors to enable advanced error handling. + // Codes are used by JSON-RPC client and server const ( CodeBlobNotFound Code = 32001 @@ -31,6 +33,11 @@ func (e *ErrBlobNotFound) Error() string { return "blob: not found" } +// GRPCStatus returns the gRPC status with details for an ErrBlobNotFound error. +func (e *ErrBlobNotFound) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.NotFound, pbda.ErrorCode_ERROR_CODE_BLOB_NOT_FOUND) +} + // ErrBlobSizeOverLimit is used to indicate that the blob size is over limit. type ErrBlobSizeOverLimit struct{} @@ -38,6 +45,11 @@ func (e *ErrBlobSizeOverLimit) Error() string { return "blob: over size limit" } +// GRPCStatus returns the gRPC status with details for an ErrBlobSizeOverLimit error. +func (e *ErrBlobSizeOverLimit) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_BLOB_SIZE_OVER_LIMIT) +} + // ErrTxTimedOut is the error message returned by the DA when mempool is congested. type ErrTxTimedOut struct{} @@ -45,6 +57,11 @@ func (e *ErrTxTimedOut) Error() string { return "timed out waiting for tx to be included in a block" } +// GRPCStatus returns the gRPC status with details for an ErrTxTimedOut error. +func (e *ErrTxTimedOut) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_TX_TIMED_OUT) +} + // ErrTxAlreadyInMempool is the error message returned by the DA when tx is already in mempool. type ErrTxAlreadyInMempool struct{} @@ -52,6 +69,11 @@ func (e *ErrTxAlreadyInMempool) Error() string { return "tx already in mempool" } +// GRPCStatus returns the gRPC status with details for an ErrTxAlreadyInMempool error. +func (e *ErrTxAlreadyInMempool) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.AlreadyExists, pbda.ErrorCode_ERROR_CODE_TX_ALREADY_IN_MEMPOOL) +} + // ErrTxIncorrectAccountSequence is the error message returned by the DA when tx has incorrect sequence. type ErrTxIncorrectAccountSequence struct{} @@ -59,6 +81,11 @@ func (e *ErrTxIncorrectAccountSequence) Error() string { return "incorrect account sequence" } +// GRPCStatus returns the gRPC status with details for an ErrTxIncorrectAccountSequence error. +func (e *ErrTxIncorrectAccountSequence) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.InvalidArgument, pbda.ErrorCode_ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE) +} + // ErrTxTooLarge is the err message returned by the DA when tx size is too large. type ErrTxTooLarge struct{} @@ -66,6 +93,11 @@ func (e *ErrTxTooLarge) Error() string { return "tx too large" } +// GRPCStatus returns the gRPC status with details for an ErrTxTooLarge error. +func (e *ErrTxTooLarge) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_TX_TOO_LARGE) +} + // ErrContextDeadline is the error message returned by the DA when context deadline exceeds. type ErrContextDeadline struct{} @@ -73,6 +105,11 @@ func (e *ErrContextDeadline) Error() string { return "context deadline" } +// GRPCStatus returns the gRPC status with details for an ErrContextDeadline error. +func (e *ErrContextDeadline) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_CONTEXT_DEADLINE) +} + // ErrFutureHeight is returned when requested height is from the future type ErrFutureHeight struct{} @@ -80,7 +117,10 @@ func (e *ErrFutureHeight) Error() string { return "given height is from the future" } -// gRPC checks for GRPCStatus method on errors to enable advanced error handling. +// GRPCStatus returns the gRPC status with details for an ErrFutureHeight error. +func (e *ErrFutureHeight) GRPCStatus() *status.Status { + return getGRPCStatus(e, codes.OutOfRange, pbda.ErrorCode_ERROR_CODE_FUTURE_HEIGHT) +} // getGRPCStatus constructs a gRPC status with error details based on the provided error, gRPC code, and DA error code. func getGRPCStatus(err error, grpcCode codes.Code, daCode pbda.ErrorCode) *status.Status { @@ -91,43 +131,3 @@ func getGRPCStatus(err error, grpcCode codes.Code, daCode pbda.ErrorCode) *statu } return detailed } - -// GRPCStatus returns the gRPC status with details for an ErrBlobNotFound error. -func (e *ErrBlobNotFound) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.NotFound, pbda.ErrorCode_ERROR_CODE_BLOB_NOT_FOUND) -} - -// GRPCStatus returns the gRPC status with details for an ErrBlobSizeOverLimit error. -func (e *ErrBlobSizeOverLimit) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_BLOB_SIZE_OVER_LIMIT) -} - -// GRPCStatus returns the gRPC status with details for an ErrTxTimedOut error. -func (e *ErrTxTimedOut) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_TX_TIMED_OUT) -} - -// GRPCStatus returns the gRPC status with details for an ErrTxAlreadyInMempool error. -func (e *ErrTxAlreadyInMempool) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.AlreadyExists, pbda.ErrorCode_ERROR_CODE_TX_ALREADY_IN_MEMPOOL) -} - -// GRPCStatus returns the gRPC status with details for an ErrTxIncorrectAccountSequence error. -func (e *ErrTxIncorrectAccountSequence) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.InvalidArgument, pbda.ErrorCode_ERROR_CODE_TX_INCORRECT_ACCOUNT_SEQUENCE) -} - -// GRPCStatus returns the gRPC status with details for an ErrTxTooLarge error. -func (e *ErrTxTooLarge) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.ResourceExhausted, pbda.ErrorCode_ERROR_CODE_TX_TOO_LARGE) -} - -// GRPCStatus returns the gRPC status with details for an ErrContextDeadline error. -func (e *ErrContextDeadline) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.DeadlineExceeded, pbda.ErrorCode_ERROR_CODE_CONTEXT_DEADLINE) -} - -// GRPCStatus returns the gRPC status with details for an ErrFutureHeight error. -func (e *ErrFutureHeight) GRPCStatus() *status.Status { - return getGRPCStatus(e, codes.OutOfRange, pbda.ErrorCode_ERROR_CODE_FUTURE_HEIGHT) -}