From d32bf7d47febc0d198f0421abb6e87cf3f0feb55 Mon Sep 17 00:00:00 2001 From: CoderZhi Date: Fri, 25 Oct 2024 13:35:52 +0300 Subject: [PATCH] add blockdao server and grpc blockdao (#4263) Co-authored-by: envestcc --- api/blockdaoservice.go | 163 +++ api/grpcserver.go | 6 +- api/serverV2.go | 2 +- api/serverV2_test.go | 2 +- blockchain/blockchain.go | 8 +- blockchain/blockdao/blockdaopb/blockdao.pb.go | 1078 +++++++++++++++++ blockchain/blockdao/blockdaopb/blockdao.proto | 86 ++ .../blockdao/blockdaopb/blockdao_grpc.pb.go | 465 +++++++ blockchain/blockdao/grpcblockdao.go | 241 ++++ blocksync/blocksync.go | 11 +- chainservice/builder.go | 30 +- 11 files changed, 2078 insertions(+), 14 deletions(-) create mode 100644 api/blockdaoservice.go create mode 100644 blockchain/blockdao/blockdaopb/blockdao.pb.go create mode 100644 blockchain/blockdao/blockdaopb/blockdao.proto create mode 100644 blockchain/blockdao/blockdaopb/blockdao_grpc.pb.go create mode 100644 blockchain/blockdao/grpcblockdao.go diff --git a/api/blockdaoservice.go b/api/blockdaoservice.go new file mode 100644 index 0000000000..3a1b62fa83 --- /dev/null +++ b/api/blockdaoservice.go @@ -0,0 +1,163 @@ +// Copyright (c) 2024 IoTeX Foundation +// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability +// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. +// This source code is governed by Apache License 2.0 that can be found in the LICENSE file. + +package api + +import ( + "context" + "encoding/hex" + + "github.com/iotexproject/go-pkgs/hash" + "github.com/iotexproject/iotex-proto/golang/iotextypes" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/iotexproject/iotex-core/v2/blockchain/blockdao" + "github.com/iotexproject/iotex-core/v2/blockchain/blockdao/blockdaopb" +) + +type blockDAOService struct { + dao blockdao.BlockDAO +} + +func newBlockDAOService(dao blockdao.BlockDAO) *blockDAOService { + return &blockDAOService{ + dao: dao, + } +} + +func (service *blockDAOService) Height(context.Context, *emptypb.Empty) (*blockdaopb.BlockHeightResponse, error) { + height, err := service.dao.Height() + if err != nil { + return nil, err + } + return &blockdaopb.BlockHeightResponse{ + Height: height, + }, nil +} + +func (service *blockDAOService) GetBlockHash(_ context.Context, request *blockdaopb.BlockHeightRequest) (*blockdaopb.BlockHashResponse, error) { + h, err := service.dao.GetBlockHash(request.Height) + if err != nil { + return nil, err + } + + return &blockdaopb.BlockHashResponse{ + Hash: hex.EncodeToString(h[:]), + }, nil +} + +func (service *blockDAOService) GetBlockHeight(_ context.Context, request *blockdaopb.BlockHashRequest) (*blockdaopb.BlockHeightResponse, error) { + h, err := hash.HexStringToHash256(request.Hash) + if err != nil { + return nil, err + } + height, err := service.dao.GetBlockHeight(h) + if err != nil { + return nil, err + } + + return &blockdaopb.BlockHeightResponse{ + Height: height, + }, nil + +} + +func (service *blockDAOService) GetBlock(_ context.Context, request *blockdaopb.BlockHashRequest) (*blockdaopb.GetBlockResponse, error) { + h, err := hash.HexStringToHash256(request.Hash) + if err != nil { + return nil, err + } + blk, err := service.dao.GetBlock(h) + if err != nil { + return nil, err + } + + return &blockdaopb.GetBlockResponse{ + Block: blk.ConvertToBlockPb(), + }, nil +} + +func (service *blockDAOService) GetBlockByHeight(_ context.Context, request *blockdaopb.BlockHeightRequest) (*blockdaopb.GetBlockResponse, error) { + blk, err := service.dao.GetBlockByHeight(request.Height) + if err != nil { + return nil, err + } + return &blockdaopb.GetBlockResponse{ + Block: blk.ConvertToBlockPb(), + }, nil +} + +func (service *blockDAOService) GetReceipts(_ context.Context, request *blockdaopb.BlockHeightRequest) (*iotextypes.Receipts, error) { + receipts, err := service.dao.GetReceipts(request.Height) + if err != nil { + return nil, err + } + arr := make([]*iotextypes.Receipt, 0, len(receipts)) + for _, receipt := range receipts { + arr = append(arr, receipt.ConvertToReceiptPb()) + } + + return &iotextypes.Receipts{ + Receipts: arr, + }, nil +} + +func (service *blockDAOService) ContainsTransactionLog(context.Context, *emptypb.Empty) (*blockdaopb.ContainsTransactionLogResponse, error) { + return &blockdaopb.ContainsTransactionLogResponse{ + Yes: service.dao.ContainsTransactionLog(), + }, nil +} + +func (service *blockDAOService) TransactionLogs(_ context.Context, request *blockdaopb.BlockHeightRequest) (*blockdaopb.TransactionLogsResponse, error) { + logs, err := service.dao.TransactionLogs(request.Height) + if err != nil { + return nil, err + } + return &blockdaopb.TransactionLogsResponse{ + TransactionLogs: logs, + }, nil +} + +func (service *blockDAOService) Header(_ context.Context, request *blockdaopb.BlockHashRequest) (*blockdaopb.HeaderResponse, error) { + h, err := hash.HexStringToHash256(request.Hash) + if err != nil { + return nil, err + } + header, err := service.dao.Header(h) + if err != nil { + return nil, err + } + + return &blockdaopb.HeaderResponse{ + Header: header.Proto(), + }, nil + +} + +func (service *blockDAOService) HeaderByHeight(_ context.Context, request *blockdaopb.BlockHeightRequest) (*blockdaopb.HeaderResponse, error) { + header, err := service.dao.HeaderByHeight(request.Height) + if err != nil { + return nil, err + } + + return &blockdaopb.HeaderResponse{ + Header: header.Proto(), + }, nil +} + +func (service *blockDAOService) FooterByHeight(_ context.Context, request *blockdaopb.BlockHeightRequest) (*blockdaopb.FooterResponse, error) { + footer, err := service.dao.FooterByHeight(request.Height) + if err != nil { + return nil, err + } + footerpb, err := footer.ConvertToBlockFooterPb() + if err != nil { + return nil, err + } + + return &blockdaopb.FooterResponse{ + Footer: footerpb, + }, nil +} diff --git a/api/grpcserver.go b/api/grpcserver.go index bbfdbf718e..4d5de352bd 100644 --- a/api/grpcserver.go +++ b/api/grpcserver.go @@ -41,6 +41,7 @@ import ( "github.com/iotexproject/iotex-core/v2/api/logfilter" apitypes "github.com/iotexproject/iotex-core/v2/api/types" "github.com/iotexproject/iotex-core/v2/blockchain/block" + "github.com/iotexproject/iotex-core/v2/blockchain/blockdao/blockdaopb" "github.com/iotexproject/iotex-core/v2/pkg/log" "github.com/iotexproject/iotex-core/v2/pkg/recovery" "github.com/iotexproject/iotex-core/v2/pkg/tracer" @@ -81,7 +82,7 @@ func RecoveryInterceptor() grpc_recovery.Option { } // NewGRPCServer creates a new grpc server -func NewGRPCServer(core CoreService, grpcPort int) *GRPCServer { +func NewGRPCServer(core CoreService, bds *blockDAOService, grpcPort int) *GRPCServer { if grpcPort == 0 { return nil } @@ -104,6 +105,9 @@ func NewGRPCServer(core CoreService, grpcPort int) *GRPCServer { //serviceName: grpc.health.v1.Health grpc_health_v1.RegisterHealthServer(gSvr, health.NewServer()) iotexapi.RegisterAPIServiceServer(gSvr, newGRPCHandler(core)) + if bds != nil { + blockdaopb.RegisterBlockDAOServiceServer(gSvr, bds) + } grpc_prometheus.EnableHandlingTimeHistogram() grpc_prometheus.Register(gSvr) reflection.Register(gSvr) diff --git a/api/serverV2.go b/api/serverV2.go index 1440dbac20..1916d666ff 100644 --- a/api/serverV2.go +++ b/api/serverV2.go @@ -71,7 +71,7 @@ func NewServerV2( return &ServerV2{ core: coreAPI, - grpcServer: NewGRPCServer(coreAPI, cfg.GRPCPort), + grpcServer: NewGRPCServer(coreAPI, newBlockDAOService(dao), cfg.GRPCPort), httpSvr: NewHTTPServer("", cfg.HTTPPort, wrappedWeb3Handler), websocketSvr: NewHTTPServer("", cfg.WebSocketPort, wrappedWebsocketHandler), tracer: tp, diff --git a/api/serverV2_test.go b/api/serverV2_test.go index b1c9ab0e69..42db6a3b67 100644 --- a/api/serverV2_test.go +++ b/api/serverV2_test.go @@ -26,7 +26,7 @@ func TestServerV2(t *testing.T) { web3Handler := NewWeb3Handler(core, "", _defaultBatchRequestLimit) svr := &ServerV2{ core: core, - grpcServer: NewGRPCServer(core, testutil.RandomPort()), + grpcServer: NewGRPCServer(core, nil, testutil.RandomPort()), httpSvr: NewHTTPServer("", testutil.RandomPort(), newHTTPHandler(web3Handler)), websocketSvr: NewHTTPServer("", testutil.RandomPort(), NewWebsocketHandler(core, web3Handler, nil)), } diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index b77c888378..5b1ea3540c 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -502,10 +502,12 @@ func (bc *blockchain) commitBlock(blk *block.Block) error { putTimer := bc.timerFactory.NewTimer("putBlock") err = bc.dao.PutBlock(ctx, blk) putTimer.End() - switch { - case errors.Cause(err) == filedao.ErrAlreadyExist: + switch errors.Cause(err) { + case filedao.ErrAlreadyExist, blockdao.ErrAlreadyExist: return nil - case err != nil: + case nil: + // do nothing + default: return err } blkHash := blk.HashBlock() diff --git a/blockchain/blockdao/blockdaopb/blockdao.pb.go b/blockchain/blockdao/blockdaopb/blockdao.pb.go new file mode 100644 index 0000000000..34b3ff2277 --- /dev/null +++ b/blockchain/blockdao/blockdaopb/blockdao.pb.go @@ -0,0 +1,1078 @@ +// Copyright (c) 2020 IoTeX +// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability +// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. +// This source code is governed by Apache License 2.0 that can be found in the LICENSE file. + +// To compile the proto, run: +// protoc --go_out=plugins=grpc:. *.proto + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.20.1 +// source: blockdao.proto + +package blockdaopb + +import ( + iotextypes "github.com/iotexproject/iotex-proto/golang/iotextypes" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type BlockHeightRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (x *BlockHeightRequest) Reset() { + *x = BlockHeightRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockHeightRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockHeightRequest) ProtoMessage() {} + +func (x *BlockHeightRequest) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockHeightRequest.ProtoReflect.Descriptor instead. +func (*BlockHeightRequest) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{0} +} + +func (x *BlockHeightRequest) GetHeight() uint64 { + if x != nil { + return x.Height + } + return 0 +} + +type BlockHeightResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (x *BlockHeightResponse) Reset() { + *x = BlockHeightResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockHeightResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockHeightResponse) ProtoMessage() {} + +func (x *BlockHeightResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockHeightResponse.ProtoReflect.Descriptor instead. +func (*BlockHeightResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{1} +} + +func (x *BlockHeightResponse) GetHeight() uint64 { + if x != nil { + return x.Height + } + return 0 +} + +type BlockHashRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (x *BlockHashRequest) Reset() { + *x = BlockHashRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockHashRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockHashRequest) ProtoMessage() {} + +func (x *BlockHashRequest) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockHashRequest.ProtoReflect.Descriptor instead. +func (*BlockHashRequest) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{2} +} + +func (x *BlockHashRequest) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + +type BlockHashResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (x *BlockHashResponse) Reset() { + *x = BlockHashResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockHashResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockHashResponse) ProtoMessage() {} + +func (x *BlockHashResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockHashResponse.ProtoReflect.Descriptor instead. +func (*BlockHashResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{3} +} + +func (x *BlockHashResponse) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + +type GetBlockHeightResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (x *GetBlockHeightResponse) Reset() { + *x = GetBlockHeightResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBlockHeightResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBlockHeightResponse) ProtoMessage() {} + +func (x *GetBlockHeightResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBlockHeightResponse.ProtoReflect.Descriptor instead. +func (*GetBlockHeightResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{4} +} + +func (x *GetBlockHeightResponse) GetHeight() uint64 { + if x != nil { + return x.Height + } + return 0 +} + +type GetBlockRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (x *GetBlockRequest) Reset() { + *x = GetBlockRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBlockRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBlockRequest) ProtoMessage() {} + +func (x *GetBlockRequest) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBlockRequest.ProtoReflect.Descriptor instead. +func (*GetBlockRequest) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{5} +} + +func (x *GetBlockRequest) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + +type GetBlockResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Block *iotextypes.Block `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` +} + +func (x *GetBlockResponse) Reset() { + *x = GetBlockResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBlockResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBlockResponse) ProtoMessage() {} + +func (x *GetBlockResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBlockResponse.ProtoReflect.Descriptor instead. +func (*GetBlockResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{6} +} + +func (x *GetBlockResponse) GetBlock() *iotextypes.Block { + if x != nil { + return x.Block + } + return nil +} + +type GetBlockByHeightRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (x *GetBlockByHeightRequest) Reset() { + *x = GetBlockByHeightRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBlockByHeightRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBlockByHeightRequest) ProtoMessage() {} + +func (x *GetBlockByHeightRequest) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBlockByHeightRequest.ProtoReflect.Descriptor instead. +func (*GetBlockByHeightRequest) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{7} +} + +func (x *GetBlockByHeightRequest) GetHeight() uint64 { + if x != nil { + return x.Height + } + return 0 +} + +type GetBlockByHeightResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Block *iotextypes.Block `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` +} + +func (x *GetBlockByHeightResponse) Reset() { + *x = GetBlockByHeightResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetBlockByHeightResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBlockByHeightResponse) ProtoMessage() {} + +func (x *GetBlockByHeightResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBlockByHeightResponse.ProtoReflect.Descriptor instead. +func (*GetBlockByHeightResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{8} +} + +func (x *GetBlockByHeightResponse) GetBlock() *iotextypes.Block { + if x != nil { + return x.Block + } + return nil +} + +type ContainsTransactionLogResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Yes bool `protobuf:"varint,1,opt,name=yes,proto3" json:"yes,omitempty"` +} + +func (x *ContainsTransactionLogResponse) Reset() { + *x = ContainsTransactionLogResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ContainsTransactionLogResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ContainsTransactionLogResponse) ProtoMessage() {} + +func (x *ContainsTransactionLogResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ContainsTransactionLogResponse.ProtoReflect.Descriptor instead. +func (*ContainsTransactionLogResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{9} +} + +func (x *ContainsTransactionLogResponse) GetYes() bool { + if x != nil { + return x.Yes + } + return false +} + +type TransactionLogsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TransactionLogs *iotextypes.TransactionLogs `protobuf:"bytes,1,opt,name=transactionLogs,proto3" json:"transactionLogs,omitempty"` +} + +func (x *TransactionLogsResponse) Reset() { + *x = TransactionLogsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TransactionLogsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TransactionLogsResponse) ProtoMessage() {} + +func (x *TransactionLogsResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TransactionLogsResponse.ProtoReflect.Descriptor instead. +func (*TransactionLogsResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{10} +} + +func (x *TransactionLogsResponse) GetTransactionLogs() *iotextypes.TransactionLogs { + if x != nil { + return x.TransactionLogs + } + return nil +} + +type PutBlockRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Block *iotextypes.Block `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` +} + +func (x *PutBlockRequest) Reset() { + *x = PutBlockRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PutBlockRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PutBlockRequest) ProtoMessage() {} + +func (x *PutBlockRequest) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PutBlockRequest.ProtoReflect.Descriptor instead. +func (*PutBlockRequest) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{11} +} + +func (x *PutBlockRequest) GetBlock() *iotextypes.Block { + if x != nil { + return x.Block + } + return nil +} + +type HeaderResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Header *iotextypes.BlockHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` +} + +func (x *HeaderResponse) Reset() { + *x = HeaderResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HeaderResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HeaderResponse) ProtoMessage() {} + +func (x *HeaderResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HeaderResponse.ProtoReflect.Descriptor instead. +func (*HeaderResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{12} +} + +func (x *HeaderResponse) GetHeader() *iotextypes.BlockHeader { + if x != nil { + return x.Header + } + return nil +} + +type FooterResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Footer *iotextypes.BlockFooter `protobuf:"bytes,1,opt,name=footer,proto3" json:"footer,omitempty"` +} + +func (x *FooterResponse) Reset() { + *x = FooterResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_blockdao_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FooterResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FooterResponse) ProtoMessage() {} + +func (x *FooterResponse) ProtoReflect() protoreflect.Message { + mi := &file_blockdao_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FooterResponse.ProtoReflect.Descriptor instead. +func (*FooterResponse) Descriptor() ([]byte, []int) { + return file_blockdao_proto_rawDescGZIP(), []int{13} +} + +func (x *FooterResponse) GetFooter() *iotextypes.BlockFooter { + if x != nil { + return x.Footer + } + return nil +} + +var File_blockdao_proto protoreflect.FileDescriptor + +var file_blockdao_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x1a, 0x1c, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, + 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x21, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x6f, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, + 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2c, 0x0a, 0x12, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x2d, 0x0a, 0x13, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x26, 0x0a, 0x10, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x48, 0x61, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x68, + 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, + 0x27, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, 0x30, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x25, 0x0a, 0x0f, 0x47, 0x65, + 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, + 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, + 0x68, 0x22, 0x3b, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x69, 0x6f, 0x74, 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x31, + 0x0a, 0x17, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x42, 0x79, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x22, 0x43, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x42, 0x79, 0x48, + 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, + 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x69, + 0x6f, 0x74, 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, + 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x32, 0x0a, 0x1e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x73, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x79, 0x65, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x79, 0x65, 0x73, 0x22, 0x60, 0x0a, 0x17, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x0f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, + 0x2e, 0x69, 0x6f, 0x74, 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x0f, 0x74, 0x72, 0x61, + 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x3a, 0x0a, 0x0f, + 0x50, 0x75, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x27, 0x0a, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, + 0x2e, 0x69, 0x6f, 0x74, 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x52, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x41, 0x0a, 0x0e, 0x48, 0x65, 0x61, 0x64, + 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x68, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x69, 0x6f, 0x74, + 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0e, 0x46, + 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, + 0x06, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, + 0x69, 0x6f, 0x74, 0x65, 0x78, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x46, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x52, 0x06, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x32, 0xff, + 0x06, 0x0a, 0x0f, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x44, 0x41, 0x4f, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x43, 0x0a, 0x06, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1f, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, + 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, + 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, + 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, + 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x08, 0x47, + 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, + 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, + 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x52, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x42, 0x79, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x0b, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x63, 0x65, 0x69, 0x70, 0x74, 0x73, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x69, 0x6f, 0x74, 0x65, 0x78, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x65, 0x69, 0x70, 0x74, 0x73, 0x22, 0x00, + 0x12, 0x5e, 0x0a, 0x16, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x1a, 0x2a, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x58, 0x0a, 0x0f, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, + 0x6f, 0x67, 0x73, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, + 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, + 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x6f, 0x67, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x06, 0x48, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, + 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x4e, 0x0a, 0x0e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x42, 0x79, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x4e, 0x0a, 0x0e, 0x46, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x42, 0x79, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x70, 0x62, 0x2e, + 0x46, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x42, 0x43, 0x5a, 0x41, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, + 0x6f, 0x74, 0x65, 0x78, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x69, 0x6f, 0x74, 0x65, + 0x78, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x64, 0x61, 0x6f, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x64, 0x61, 0x6f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_blockdao_proto_rawDescOnce sync.Once + file_blockdao_proto_rawDescData = file_blockdao_proto_rawDesc +) + +func file_blockdao_proto_rawDescGZIP() []byte { + file_blockdao_proto_rawDescOnce.Do(func() { + file_blockdao_proto_rawDescData = protoimpl.X.CompressGZIP(file_blockdao_proto_rawDescData) + }) + return file_blockdao_proto_rawDescData +} + +var file_blockdao_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_blockdao_proto_goTypes = []interface{}{ + (*BlockHeightRequest)(nil), // 0: blockdaopb.BlockHeightRequest + (*BlockHeightResponse)(nil), // 1: blockdaopb.BlockHeightResponse + (*BlockHashRequest)(nil), // 2: blockdaopb.BlockHashRequest + (*BlockHashResponse)(nil), // 3: blockdaopb.BlockHashResponse + (*GetBlockHeightResponse)(nil), // 4: blockdaopb.GetBlockHeightResponse + (*GetBlockRequest)(nil), // 5: blockdaopb.GetBlockRequest + (*GetBlockResponse)(nil), // 6: blockdaopb.GetBlockResponse + (*GetBlockByHeightRequest)(nil), // 7: blockdaopb.GetBlockByHeightRequest + (*GetBlockByHeightResponse)(nil), // 8: blockdaopb.GetBlockByHeightResponse + (*ContainsTransactionLogResponse)(nil), // 9: blockdaopb.ContainsTransactionLogResponse + (*TransactionLogsResponse)(nil), // 10: blockdaopb.TransactionLogsResponse + (*PutBlockRequest)(nil), // 11: blockdaopb.PutBlockRequest + (*HeaderResponse)(nil), // 12: blockdaopb.HeaderResponse + (*FooterResponse)(nil), // 13: blockdaopb.FooterResponse + (*iotextypes.Block)(nil), // 14: iotextypes.Block + (*iotextypes.TransactionLogs)(nil), // 15: iotextypes.TransactionLogs + (*iotextypes.BlockHeader)(nil), // 16: iotextypes.BlockHeader + (*iotextypes.BlockFooter)(nil), // 17: iotextypes.BlockFooter + (*emptypb.Empty)(nil), // 18: google.protobuf.Empty + (*iotextypes.Receipts)(nil), // 19: iotextypes.Receipts +} +var file_blockdao_proto_depIdxs = []int32{ + 14, // 0: blockdaopb.GetBlockResponse.block:type_name -> iotextypes.Block + 14, // 1: blockdaopb.GetBlockByHeightResponse.block:type_name -> iotextypes.Block + 15, // 2: blockdaopb.TransactionLogsResponse.transactionLogs:type_name -> iotextypes.TransactionLogs + 14, // 3: blockdaopb.PutBlockRequest.block:type_name -> iotextypes.Block + 16, // 4: blockdaopb.HeaderResponse.header:type_name -> iotextypes.BlockHeader + 17, // 5: blockdaopb.FooterResponse.footer:type_name -> iotextypes.BlockFooter + 18, // 6: blockdaopb.BlockDAOService.Height:input_type -> google.protobuf.Empty + 0, // 7: blockdaopb.BlockDAOService.GetBlockHash:input_type -> blockdaopb.BlockHeightRequest + 2, // 8: blockdaopb.BlockDAOService.GetBlockHeight:input_type -> blockdaopb.BlockHashRequest + 2, // 9: blockdaopb.BlockDAOService.GetBlock:input_type -> blockdaopb.BlockHashRequest + 0, // 10: blockdaopb.BlockDAOService.GetBlockByHeight:input_type -> blockdaopb.BlockHeightRequest + 0, // 11: blockdaopb.BlockDAOService.GetReceipts:input_type -> blockdaopb.BlockHeightRequest + 18, // 12: blockdaopb.BlockDAOService.ContainsTransactionLog:input_type -> google.protobuf.Empty + 0, // 13: blockdaopb.BlockDAOService.TransactionLogs:input_type -> blockdaopb.BlockHeightRequest + 2, // 14: blockdaopb.BlockDAOService.Header:input_type -> blockdaopb.BlockHashRequest + 0, // 15: blockdaopb.BlockDAOService.HeaderByHeight:input_type -> blockdaopb.BlockHeightRequest + 0, // 16: blockdaopb.BlockDAOService.FooterByHeight:input_type -> blockdaopb.BlockHeightRequest + 1, // 17: blockdaopb.BlockDAOService.Height:output_type -> blockdaopb.BlockHeightResponse + 3, // 18: blockdaopb.BlockDAOService.GetBlockHash:output_type -> blockdaopb.BlockHashResponse + 1, // 19: blockdaopb.BlockDAOService.GetBlockHeight:output_type -> blockdaopb.BlockHeightResponse + 6, // 20: blockdaopb.BlockDAOService.GetBlock:output_type -> blockdaopb.GetBlockResponse + 6, // 21: blockdaopb.BlockDAOService.GetBlockByHeight:output_type -> blockdaopb.GetBlockResponse + 19, // 22: blockdaopb.BlockDAOService.GetReceipts:output_type -> iotextypes.Receipts + 9, // 23: blockdaopb.BlockDAOService.ContainsTransactionLog:output_type -> blockdaopb.ContainsTransactionLogResponse + 10, // 24: blockdaopb.BlockDAOService.TransactionLogs:output_type -> blockdaopb.TransactionLogsResponse + 12, // 25: blockdaopb.BlockDAOService.Header:output_type -> blockdaopb.HeaderResponse + 12, // 26: blockdaopb.BlockDAOService.HeaderByHeight:output_type -> blockdaopb.HeaderResponse + 13, // 27: blockdaopb.BlockDAOService.FooterByHeight:output_type -> blockdaopb.FooterResponse + 17, // [17:28] is the sub-list for method output_type + 6, // [6:17] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_blockdao_proto_init() } +func file_blockdao_proto_init() { + if File_blockdao_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_blockdao_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlockHeightRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlockHeightResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlockHashRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlockHashResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetBlockHeightResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetBlockRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetBlockResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetBlockByHeightRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetBlockByHeightResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ContainsTransactionLogResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TransactionLogsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PutBlockRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HeaderResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_blockdao_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FooterResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_blockdao_proto_rawDesc, + NumEnums: 0, + NumMessages: 14, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_blockdao_proto_goTypes, + DependencyIndexes: file_blockdao_proto_depIdxs, + MessageInfos: file_blockdao_proto_msgTypes, + }.Build() + File_blockdao_proto = out.File + file_blockdao_proto_rawDesc = nil + file_blockdao_proto_goTypes = nil + file_blockdao_proto_depIdxs = nil +} diff --git a/blockchain/blockdao/blockdaopb/blockdao.proto b/blockchain/blockdao/blockdaopb/blockdao.proto new file mode 100644 index 0000000000..03a5793fcc --- /dev/null +++ b/blockchain/blockdao/blockdaopb/blockdao.proto @@ -0,0 +1,86 @@ +// Copyright (c) 2020 IoTeX +// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability +// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. +// This source code is governed by Apache License 2.0 that can be found in the LICENSE file. + +// To compile the proto, run: +// protoc --go_out=plugins=grpc:. *.proto +syntax = "proto3"; +package blockdaopb; + +import "proto/types/blockchain.proto"; +import "proto/types/transaction_log.proto"; +import "google/protobuf/empty.proto"; + +option go_package = "github.com/iotexproject/iotex-core/blockchain/blockdao/blockdaopb"; + + +message BlockHeightRequest { + uint64 height = 1; +} + +message BlockHeightResponse { + uint64 height = 1; +} + +message BlockHashRequest { + string hash = 1; +} + +message BlockHashResponse { + string hash = 1; +} + +message GetBlockHeightResponse { + uint64 height = 1; +} + +message GetBlockRequest { + string hash = 1; +} + +message GetBlockResponse { + iotextypes.Block block = 1; +} + +message GetBlockByHeightRequest { + uint64 height = 1; +} + +message GetBlockByHeightResponse { + iotextypes.Block block = 1; +} + +message ContainsTransactionLogResponse { + bool yes = 1; +} + +message TransactionLogsResponse { + iotextypes.TransactionLogs transactionLogs = 1; +} + +message PutBlockRequest { + iotextypes.Block block = 1; +} + +message HeaderResponse { + iotextypes.BlockHeader header = 1; +} + +message FooterResponse { + iotextypes.BlockFooter footer = 1; +} + +service BlockDAOService { + rpc Height(google.protobuf.Empty) returns (BlockHeightResponse) {} + rpc GetBlockHash(BlockHeightRequest) returns (BlockHashResponse) {} + rpc GetBlockHeight(BlockHashRequest) returns (BlockHeightResponse) {} + rpc GetBlock(BlockHashRequest) returns (GetBlockResponse) {} + rpc GetBlockByHeight(BlockHeightRequest) returns (GetBlockResponse) {} + rpc GetReceipts(BlockHeightRequest) returns (iotextypes.Receipts) {} + rpc ContainsTransactionLog(google.protobuf.Empty) returns (ContainsTransactionLogResponse) {} + rpc TransactionLogs(BlockHeightRequest) returns (TransactionLogsResponse) {} + rpc Header(BlockHashRequest) returns (HeaderResponse) {} + rpc HeaderByHeight(BlockHeightRequest) returns (HeaderResponse) {} + rpc FooterByHeight(BlockHeightRequest) returns (FooterResponse) {} +} diff --git a/blockchain/blockdao/blockdaopb/blockdao_grpc.pb.go b/blockchain/blockdao/blockdaopb/blockdao_grpc.pb.go new file mode 100644 index 0000000000..5affb0d784 --- /dev/null +++ b/blockchain/blockdao/blockdaopb/blockdao_grpc.pb.go @@ -0,0 +1,465 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.20.1 +// source: blockdao.proto + +package blockdaopb + +import ( + context "context" + iotextypes "github.com/iotexproject/iotex-proto/golang/iotextypes" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BlockDAOServiceClient is the client API for BlockDAOService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BlockDAOServiceClient interface { + Height(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*BlockHeightResponse, error) + GetBlockHash(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*BlockHashResponse, error) + GetBlockHeight(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*BlockHeightResponse, error) + GetBlock(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) + GetBlockByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) + GetReceipts(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*iotextypes.Receipts, error) + ContainsTransactionLog(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ContainsTransactionLogResponse, error) + TransactionLogs(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*TransactionLogsResponse, error) + Header(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*HeaderResponse, error) + HeaderByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*HeaderResponse, error) + FooterByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*FooterResponse, error) +} + +type blockDAOServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewBlockDAOServiceClient(cc grpc.ClientConnInterface) BlockDAOServiceClient { + return &blockDAOServiceClient{cc} +} + +func (c *blockDAOServiceClient) Height(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*BlockHeightResponse, error) { + out := new(BlockHeightResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/Height", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) GetBlockHash(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*BlockHashResponse, error) { + out := new(BlockHashResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/GetBlockHash", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) GetBlockHeight(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*BlockHeightResponse, error) { + out := new(BlockHeightResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/GetBlockHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) GetBlock(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) { + out := new(GetBlockResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/GetBlock", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) GetBlockByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) { + out := new(GetBlockResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/GetBlockByHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) GetReceipts(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*iotextypes.Receipts, error) { + out := new(iotextypes.Receipts) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/GetReceipts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) ContainsTransactionLog(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ContainsTransactionLogResponse, error) { + out := new(ContainsTransactionLogResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/ContainsTransactionLog", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) TransactionLogs(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*TransactionLogsResponse, error) { + out := new(TransactionLogsResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/TransactionLogs", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) Header(ctx context.Context, in *BlockHashRequest, opts ...grpc.CallOption) (*HeaderResponse, error) { + out := new(HeaderResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/Header", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) HeaderByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*HeaderResponse, error) { + out := new(HeaderResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/HeaderByHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *blockDAOServiceClient) FooterByHeight(ctx context.Context, in *BlockHeightRequest, opts ...grpc.CallOption) (*FooterResponse, error) { + out := new(FooterResponse) + err := c.cc.Invoke(ctx, "/blockdaopb.BlockDAOService/FooterByHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BlockDAOServiceServer is the server API for BlockDAOService service. +// All implementations should embed UnimplementedBlockDAOServiceServer +// for forward compatibility +type BlockDAOServiceServer interface { + Height(context.Context, *emptypb.Empty) (*BlockHeightResponse, error) + GetBlockHash(context.Context, *BlockHeightRequest) (*BlockHashResponse, error) + GetBlockHeight(context.Context, *BlockHashRequest) (*BlockHeightResponse, error) + GetBlock(context.Context, *BlockHashRequest) (*GetBlockResponse, error) + GetBlockByHeight(context.Context, *BlockHeightRequest) (*GetBlockResponse, error) + GetReceipts(context.Context, *BlockHeightRequest) (*iotextypes.Receipts, error) + ContainsTransactionLog(context.Context, *emptypb.Empty) (*ContainsTransactionLogResponse, error) + TransactionLogs(context.Context, *BlockHeightRequest) (*TransactionLogsResponse, error) + Header(context.Context, *BlockHashRequest) (*HeaderResponse, error) + HeaderByHeight(context.Context, *BlockHeightRequest) (*HeaderResponse, error) + FooterByHeight(context.Context, *BlockHeightRequest) (*FooterResponse, error) +} + +// UnimplementedBlockDAOServiceServer should be embedded to have forward compatible implementations. +type UnimplementedBlockDAOServiceServer struct { +} + +func (UnimplementedBlockDAOServiceServer) Height(context.Context, *emptypb.Empty) (*BlockHeightResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Height not implemented") +} +func (UnimplementedBlockDAOServiceServer) GetBlockHash(context.Context, *BlockHeightRequest) (*BlockHashResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlockHash not implemented") +} +func (UnimplementedBlockDAOServiceServer) GetBlockHeight(context.Context, *BlockHashRequest) (*BlockHeightResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeight not implemented") +} +func (UnimplementedBlockDAOServiceServer) GetBlock(context.Context, *BlockHashRequest) (*GetBlockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlock not implemented") +} +func (UnimplementedBlockDAOServiceServer) GetBlockByHeight(context.Context, *BlockHeightRequest) (*GetBlockResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBlockByHeight not implemented") +} +func (UnimplementedBlockDAOServiceServer) GetReceipts(context.Context, *BlockHeightRequest) (*iotextypes.Receipts, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetReceipts not implemented") +} +func (UnimplementedBlockDAOServiceServer) ContainsTransactionLog(context.Context, *emptypb.Empty) (*ContainsTransactionLogResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ContainsTransactionLog not implemented") +} +func (UnimplementedBlockDAOServiceServer) TransactionLogs(context.Context, *BlockHeightRequest) (*TransactionLogsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TransactionLogs not implemented") +} +func (UnimplementedBlockDAOServiceServer) Header(context.Context, *BlockHashRequest) (*HeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Header not implemented") +} +func (UnimplementedBlockDAOServiceServer) HeaderByHeight(context.Context, *BlockHeightRequest) (*HeaderResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HeaderByHeight not implemented") +} +func (UnimplementedBlockDAOServiceServer) FooterByHeight(context.Context, *BlockHeightRequest) (*FooterResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FooterByHeight not implemented") +} + +// UnsafeBlockDAOServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BlockDAOServiceServer will +// result in compilation errors. +type UnsafeBlockDAOServiceServer interface { + mustEmbedUnimplementedBlockDAOServiceServer() +} + +func RegisterBlockDAOServiceServer(s grpc.ServiceRegistrar, srv BlockDAOServiceServer) { + s.RegisterService(&BlockDAOService_ServiceDesc, srv) +} + +func _BlockDAOService_Height_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).Height(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/Height", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).Height(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_GetBlockHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).GetBlockHash(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/GetBlockHash", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).GetBlockHash(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_GetBlockHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).GetBlockHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/GetBlockHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).GetBlockHeight(ctx, req.(*BlockHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_GetBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).GetBlock(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/GetBlock", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).GetBlock(ctx, req.(*BlockHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_GetBlockByHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).GetBlockByHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/GetBlockByHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).GetBlockByHeight(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_GetReceipts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).GetReceipts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/GetReceipts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).GetReceipts(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_ContainsTransactionLog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).ContainsTransactionLog(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/ContainsTransactionLog", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).ContainsTransactionLog(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_TransactionLogs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).TransactionLogs(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/TransactionLogs", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).TransactionLogs(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_Header_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).Header(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/Header", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).Header(ctx, req.(*BlockHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_HeaderByHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).HeaderByHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/HeaderByHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).HeaderByHeight(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BlockDAOService_FooterByHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BlockHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BlockDAOServiceServer).FooterByHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blockdaopb.BlockDAOService/FooterByHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BlockDAOServiceServer).FooterByHeight(ctx, req.(*BlockHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BlockDAOService_ServiceDesc is the grpc.ServiceDesc for BlockDAOService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BlockDAOService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "blockdaopb.BlockDAOService", + HandlerType: (*BlockDAOServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Height", + Handler: _BlockDAOService_Height_Handler, + }, + { + MethodName: "GetBlockHash", + Handler: _BlockDAOService_GetBlockHash_Handler, + }, + { + MethodName: "GetBlockHeight", + Handler: _BlockDAOService_GetBlockHeight_Handler, + }, + { + MethodName: "GetBlock", + Handler: _BlockDAOService_GetBlock_Handler, + }, + { + MethodName: "GetBlockByHeight", + Handler: _BlockDAOService_GetBlockByHeight_Handler, + }, + { + MethodName: "GetReceipts", + Handler: _BlockDAOService_GetReceipts_Handler, + }, + { + MethodName: "ContainsTransactionLog", + Handler: _BlockDAOService_ContainsTransactionLog_Handler, + }, + { + MethodName: "TransactionLogs", + Handler: _BlockDAOService_TransactionLogs_Handler, + }, + { + MethodName: "Header", + Handler: _BlockDAOService_Header_Handler, + }, + { + MethodName: "HeaderByHeight", + Handler: _BlockDAOService_HeaderByHeight_Handler, + }, + { + MethodName: "FooterByHeight", + Handler: _BlockDAOService_FooterByHeight_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "blockdao.proto", +} diff --git a/blockchain/blockdao/grpcblockdao.go b/blockchain/blockdao/grpcblockdao.go new file mode 100644 index 0000000000..30e8dad625 --- /dev/null +++ b/blockchain/blockdao/grpcblockdao.go @@ -0,0 +1,241 @@ +// Copyright (c) 2024 IoTeX Foundation +// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability +// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. +// This source code is governed by Apache License 2.0 that can be found in the LICENSE file. + +package blockdao + +import ( + "context" + "encoding/hex" + "fmt" + "sync/atomic" + + "github.com/iotexproject/go-pkgs/hash" + "github.com/iotexproject/iotex-proto/golang/iotextypes" + "github.com/pkg/errors" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/iotexproject/iotex-core/v2/action" + "github.com/iotexproject/iotex-core/v2/blockchain/block" + "github.com/iotexproject/iotex-core/v2/blockchain/blockdao/blockdaopb" +) + +type GrpcBlockDAO struct { + url string + insecure bool + conn *grpc.ClientConn + client blockdaopb.BlockDAOServiceClient + containsTransactionLog bool + deserializer *block.Deserializer + localHeight atomic.Uint64 +} + +var ( + // ErrRemoteHeightTooLow is the error that remote height is too low + ErrRemoteHeightTooLow = fmt.Errorf("remote height is too low") + // ErrAlreadyExist is the error that block already exists + ErrAlreadyExist = fmt.Errorf("block already exists") +) + +func NewGrpcBlockDAO( + url string, + insecure bool, + deserializer *block.Deserializer, +) *GrpcBlockDAO { + return &GrpcBlockDAO{ + url: url, + insecure: insecure, + deserializer: deserializer, + } +} + +func (gbd *GrpcBlockDAO) Start(ctx context.Context) error { + var err error + opts := []grpc.DialOption{} + if gbd.insecure { + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) + } + gbd.conn, err = grpc.Dial(gbd.url, opts...) + if err != nil { + return err + } + gbd.client = blockdaopb.NewBlockDAOServiceClient(gbd.conn) + + response, err := gbd.client.ContainsTransactionLog(ctx, &emptypb.Empty{}) + if err != nil { + return err + } + gbd.containsTransactionLog = response.Yes + // init local height with remote height + height, err := gbd.rpcHeight() + if err != nil { + return err + } + gbd.localHeight.Store(height) + return nil +} + +func (gbd *GrpcBlockDAO) Stop(ctx context.Context) error { + return gbd.conn.Close() +} + +func (gbd *GrpcBlockDAO) Height() (uint64, error) { + return gbd.localHeight.Load(), nil +} + +func (gbd *GrpcBlockDAO) rpcHeight() (uint64, error) { + response, err := gbd.client.Height(context.Background(), &emptypb.Empty{}) + if err != nil { + return 0, err + } + return response.Height, nil +} + +func (gbd *GrpcBlockDAO) GetBlockHash(height uint64) (hash.Hash256, error) { + response, err := gbd.client.GetBlockHash(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return hash.ZeroHash256, err + } + h, err := hash.HexStringToHash256(response.Hash) + if err != nil { + return hash.ZeroHash256, err + } + return h, nil +} + +func (gbd *GrpcBlockDAO) GetBlockHeight(h hash.Hash256) (uint64, error) { + response, err := gbd.client.GetBlockHeight(context.Background(), &blockdaopb.BlockHashRequest{ + Hash: hex.EncodeToString(h[:]), + }) + if err != nil { + return 0, err + } + + return response.Height, nil +} + +func (gbd *GrpcBlockDAO) GetBlock(h hash.Hash256) (*block.Block, error) { + response, err := gbd.client.GetBlock(context.Background(), &blockdaopb.BlockHashRequest{ + Hash: hex.EncodeToString(h[:]), + }) + if err != nil { + return nil, err + } + + return gbd.deserializer.FromBlockProto(response.Block) +} + +func (gbd *GrpcBlockDAO) GetBlockByHeight(height uint64) (*block.Block, error) { + if height == 0 { + return block.GenesisBlock(), nil + } + response, err := gbd.client.GetBlockByHeight(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + + return gbd.deserializer.FromBlockProto(response.Block) +} + +func (gbd *GrpcBlockDAO) GetReceipts(height uint64) ([]*action.Receipt, error) { + response, err := gbd.client.GetReceipts(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + + receipts := make([]*action.Receipt, 0, len(response.Receipts)) + for _, receiptpb := range response.Receipts { + receipt := &action.Receipt{} + receipt.ConvertFromReceiptPb(receiptpb) + receipts = append(receipts, receipt) + } + + return receipts, nil +} + +func (gbd *GrpcBlockDAO) ContainsTransactionLog() bool { + return gbd.containsTransactionLog +} + +func (gbd *GrpcBlockDAO) TransactionLogs(height uint64) (*iotextypes.TransactionLogs, error) { + response, err := gbd.client.TransactionLogs(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + + return response.TransactionLogs, nil +} + +func (gbd *GrpcBlockDAO) PutBlock(ctx context.Context, blk *block.Block) error { + localHeight := gbd.localHeight.Load() + switch { + case blk.Height() <= localHeight: + return errors.Wrapf(ErrAlreadyExist, "block height %d, local height %d", blk.Height(), localHeight) + case blk.Height() > localHeight+1: + return errors.Errorf("block height %d is larger than local height %d + 1", blk.Height(), localHeight) + } + + remoteHeight, err := gbd.rpcHeight() + if err != nil { + return err + } + if blk.Height() <= remoteHeight { + gbd.localHeight.Store(blk.Height()) + // remote block is already exist + return nil + } + return errors.Wrapf(ErrRemoteHeightTooLow, "block height %d, remote height %d", blk.Height(), remoteHeight) +} + +func (gbd *GrpcBlockDAO) Header(h hash.Hash256) (*block.Header, error) { + response, err := gbd.client.Header(context.Background(), &blockdaopb.BlockHashRequest{ + Hash: hex.EncodeToString(h[:]), + }) + if err != nil { + return nil, err + } + header := &block.Header{} + if err := header.LoadFromBlockHeaderProto(response.Header); err != nil { + return nil, err + } + return header, nil +} + +func (gbd *GrpcBlockDAO) HeaderByHeight(height uint64) (*block.Header, error) { + response, err := gbd.client.HeaderByHeight(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + header := &block.Header{} + if err := header.LoadFromBlockHeaderProto(response.Header); err != nil { + return nil, err + } + return header, nil +} + +func (gbd *GrpcBlockDAO) FooterByHeight(height uint64) (*block.Footer, error) { + response, err := gbd.client.FooterByHeight(context.Background(), &blockdaopb.BlockHeightRequest{ + Height: height, + }) + if err != nil { + return nil, err + } + footer := &block.Footer{} + if err := footer.ConvertFromBlockFooterPb(response.Footer); err != nil { + return nil, err + } + return footer, nil +} diff --git a/blocksync/blocksync.go b/blocksync/blocksync.go index 82cda2aefe..d06d30dd98 100644 --- a/blocksync/blocksync.go +++ b/blocksync/blocksync.go @@ -19,6 +19,7 @@ import ( "google.golang.org/protobuf/proto" "github.com/iotexproject/iotex-core/v2/blockchain/block" + "github.com/iotexproject/iotex-core/v2/blockchain/blockdao" "github.com/iotexproject/iotex-core/v2/pkg/fastrand" "github.com/iotexproject/iotex-core/v2/pkg/lifecycle" "github.com/iotexproject/iotex-core/v2/pkg/log" @@ -163,11 +164,15 @@ func (bs *blockSyncer) commitBlocks(blks []*peerBlock) bool { continue } err := bs.commitBlockHandler(blk.block) - if err == nil { + switch errors.Cause(err) { + case nil: return true + case blockdao.ErrRemoteHeightTooLow: + log.L().Info("remote height too low", zap.Uint64("height", blk.block.Height())) + default: + bs.blockP2pPeer(blk.pid) + log.L().Error("failed to commit block", zap.Error(err), zap.Uint64("height", blk.block.Height()), zap.String("peer", blk.pid)) } - bs.blockP2pPeer(blk.pid) - log.L().Error("failed to commit block", zap.Error(err), zap.Uint64("height", blk.block.Height()), zap.String("peer", blk.pid)) } return false } diff --git a/chainservice/builder.go b/chainservice/builder.go index 46ce4a7dc9..0937a14b1a 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -8,6 +8,7 @@ package chainservice import ( "context" "math/big" + "net/url" "time" "github.com/iotexproject/iotex-address/address" @@ -317,6 +318,21 @@ func (builder *Builder) buildBlockDAO(forTest bool) error { if forTest { store, err = filedao.NewFileDAOInMemForTest() } else { + path := builder.cfg.Chain.ChainDBPath + uri, err := url.Parse(path) + if err != nil { + return errors.Wrapf(err, "failed to parse chain db path %s", path) + } + switch uri.Scheme { + case "grpc": + store = blockdao.NewGrpcBlockDAO(uri.Host, uri.Query().Get("insecure") == "true", block.NewDeserializer(builder.cfg.Chain.EVMNetworkID)) + case "file", "": + dbConfig := cfg.DB + dbConfig.DbPath = uri.Path + store, err = filedao.NewFileDAO(dbConfig, block.NewDeserializer(builder.cfg.Chain.EVMNetworkID)) + default: + return errors.Errorf("unsupported blockdao scheme %s", uri.Scheme) + } dbConfig := cfg.DB if bsPath := cfg.Chain.BlobStoreDBPath; len(bsPath) > 0 { blocksPerHour := time.Hour / cfg.DardanellesUpgrade.BlockInterval @@ -325,8 +341,6 @@ func (builder *Builder) buildBlockDAO(forTest bool) error { uint64(blocksPerHour)*uint64(cfg.Chain.BlobStoreRetentionDays)*24, cfg.Chain.BlobPurgeInterval) opts = append(opts, blockdao.WithBlobStore(blobStore)) } - dbConfig.DbPath = cfg.Chain.ChainDBPath - store, err = filedao.NewFileDAO(dbConfig, block.NewDeserializer(cfg.Chain.EVMNetworkID)) } if err != nil { return err @@ -535,7 +549,7 @@ func (builder *Builder) buildBlockSyncer() error { p2pAgent := builder.cs.p2pAgent chain := builder.cs.chain consens := builder.cs.consensus - blockdao := builder.cs.blockdao + dao := builder.cs.blockdao cfg := builder.cfg // estimateTipHeight estimates the height of the block at the given time // it ignores the influence of the block missing in the blockchain @@ -555,7 +569,7 @@ func (builder *Builder) buildBlockSyncer() error { builder.cfg.BlockSync, chain.TipHeight, func(height uint64) (*block.Block, error) { - blk, err := blockdao.GetBlockByHeight(height) + blk, err := dao.GetBlockByHeight(height) if err != nil { return blk, err } @@ -563,7 +577,7 @@ func (builder *Builder) buildBlockSyncer() error { // block already has blob sidecar attached return blk, nil } - sidecars, hashes, err := blockdao.GetBlobsByHeight(height) + sidecars, hashes, err := dao.GetBlobsByHeight(height) if errors.Cause(err) == db.ErrNotExist { // the block does not have blob or blob has expired return blk, nil @@ -601,6 +615,12 @@ func (builder *Builder) buildBlockSyncer() error { return nil case block.ErrDeltaStateMismatch: log.L().Debug("Delta state mismatched.", zap.Uint64("height", blk.Height())) + case blockdao.ErrRemoteHeightTooLow: + if retries == 1 { + retries = 4 + } + log.L().Debug("Remote height too low.", zap.Uint64("height", blk.Height())) + time.Sleep(100 * time.Millisecond) default: log.L().Debug("Failed to commit the block.", zap.Error(err), zap.Uint64("height", blk.Height())) return err