From 91cd4a8c8bf3cef6d125c5c01ee28fdc06114ea0 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 21 Jun 2024 17:45:05 +0530 Subject: [PATCH 01/15] add api calls to bor grpc --- go.mod | 2 + go.sum | 4 +- internal/cli/server/api_service.go | 88 ++++++++++++++++++++++++++++++ internal/cli/server/server.go | 5 ++ internal/cli/server/utils.go | 79 +++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 internal/cli/server/api_service.go create mode 100644 internal/cli/server/utils.go diff --git a/go.mod b/go.mod index 17128decbd..1b2d09cfbf 100644 --- a/go.mod +++ b/go.mod @@ -289,3 +289,5 @@ replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.2.7 replace github.com/Masterminds/goutils => github.com/Masterminds/goutils v1.1.1 replace go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver v1.14.0 + +replace github.com/maticnetwork/polyproto => github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e diff --git a/go.sum b/go.sum index de4c422601..d4dbb4efb2 100644 --- a/go.sum +++ b/go.sum @@ -815,6 +815,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5 github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e h1:mpjnlMMyAXoioTDnltukXW6dnH/aPRmoRkB0bpQS+go= +github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/v10 v10.0.1/go.mod h1:YvhnlEePVnBS4+0z3fhPfUy7W1Ikj0Ih0vcRo/gZ1M0= github.com/apache/arrow/go/v11 v11.0.0/go.mod h1:Eg5OsL5H+e299f7u5ssuXsuHQVEGC4xei5aX110hRiI= @@ -1691,8 +1693,6 @@ github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxp github.com/maticnetwork/heimdall v0.3.1-0.20230227104835-81bd1055b0bc/go.mod h1:P2DoKhovYP9G9Kj2EH/zHaiRJF1jNU7ZJOyelG4UCa8= github.com/maticnetwork/heimdall v1.0.4 h1:xSsLn6JE/KqF3Fs9Wlx1s4dclJf2cduIodx2tL6K/cg= github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89eU/XUwH0AgHLs= -github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53 h1:PjYV+lghs106JKkrYgOnrsfDLoTc11BxZd4rUa4Rus4= -github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8= github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go new file mode 100644 index 0000000000..fc5f7d6d5a --- /dev/null +++ b/internal/cli/server/api_service.go @@ -0,0 +1,88 @@ +package server + +import ( + "context" + "errors" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rpc" + protobor "github.com/maticnetwork/polyproto/bor" + protoutil "github.com/maticnetwork/polyproto/utils" +) + +func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) { + rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber) + if err != nil { + return nil, err + } + + return &protobor.GetRootHashResponse{RootHash: rootHash}, nil +} + +func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) { + vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId) + if err != nil { + return nil, err + } + + return &protobor.GetVoteOnHashResponse{Response: vote}, nil +} + +func headerToProtoborHeader(h *types.Header) *protobor.Header { + return &protobor.Header{ + Number: h.Number.Uint64(), + ParentHash: protoutil.ConvertHashToH256(h.ParentHash), + Time: h.Time, + } +} + +func (s *Server) GetHeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { + header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) + if err != nil { + return nil, err + } + + return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil +} + +func (s *Server) GetBlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { + block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) + if err != nil { + return nil, err + } + + return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil +} + +func blockToProtoBlock(h *types.Block) *protobor.Block { + return &protobor.Block{ + Header: headerToProtoborHeader(h.Header()), + } +} + +func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) + if err != nil { + return nil, err + } + + receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) + if err != nil { + return nil, err + } + + if len(receipts) <= int(txnIndex) { + return nil, errors.New("transaction index out of bounds") + } + + return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil +} + +func (s *Server) GetBorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) + if err != nil { + return nil, err + } + + return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil +} diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 34015e23a5..b0268df524 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -21,6 +21,8 @@ import ( semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "google.golang.org/grpc" + protobor "github.com/maticnetwork/polyproto/bor" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -47,6 +49,8 @@ import ( type Server struct { proto.UnimplementedBorServer + protobor.UnimplementedBorApiServer + node *node.Node backend *eth.Ethereum grpcServer *grpc.Server @@ -438,6 +442,7 @@ func (s *Server) gRPCServerByAddress(addr string) error { func (s *Server) gRPCServerByListener(listener net.Listener) error { s.grpcServer = grpc.NewServer(s.withLoggingUnaryInterceptor()) proto.RegisterBorServer(s.grpcServer, s) + protobor.RegisterBorApiServer(s.grpcServer, s) go func() { if err := s.grpcServer.Serve(listener); err != nil { diff --git a/internal/cli/server/utils.go b/internal/cli/server/utils.go new file mode 100644 index 0000000000..4fa8ba0960 --- /dev/null +++ b/internal/cli/server/utils.go @@ -0,0 +1,79 @@ +package server + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" + "github.com/ethereum/go-ethereum/p2p" + + protobor "github.com/maticnetwork/polyproto/bor" + protocommon "github.com/maticnetwork/polyproto/common" + protoutil "github.com/maticnetwork/polyproto/utils" +) + +func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { + return &proto.Peer{ + Id: info.ID, + Enode: info.Enode, + Enr: info.ENR, + Caps: info.Caps, + Name: info.Name, + Trusted: info.Network.Trusted, + Static: info.Network.Static, + } +} + +func ConvertBloomToProtoBloom(bloom types.Bloom) *protobor.Bloom { + return &protobor.Bloom{ + Bloom: bloom.Bytes(), + } +} + +func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log { + var protoLogs []*protobor.Log + for _, log := range logs { + protoLog := &protobor.Log{ + Address: protoutil.ConvertAddressToH160(log.Address), + Topics: ConvertTopicsToProtoTopics(log.Topics), + Data: log.Data, + BlockNumber: log.BlockNumber, + TxHash: protoutil.ConvertHashToH256(log.TxHash), + TxIndex: uint64(log.TxIndex), + BlockHash: protoutil.ConvertHashToH256(log.BlockHash), + Index: uint64(log.Index), + Removed: log.Removed, + } + protoLogs = append(protoLogs, protoLog) + } + + return protoLogs +} + +func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 { + var protoTopics []*protocommon.H256 + for _, topic := range topics { + protoTopics = append(protoTopics, protoutil.ConvertHashToH256(topic)) + } + + return protoTopics +} + +func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt { + return &protobor.Receipt{ + Type: uint64(receipt.Type), + PostState: receipt.PostState, + Status: receipt.Status, + CumulativeGasUsed: receipt.CumulativeGasUsed, + Bloom: ConvertBloomToProtoBloom(receipt.Bloom), + Logs: ConvertLogsToProtoLogs(receipt.Logs), + TxHash: protoutil.ConvertHashToH256(receipt.TxHash), + ContractAddress: protoutil.ConvertAddressToH160(receipt.ContractAddress), + GasUsed: receipt.GasUsed, + EffectiveGasPrice: receipt.EffectiveGasPrice.Int64(), + BlobGasUsed: receipt.BlobGasUsed, + BlobGasPrice: receipt.BlobGasPrice.Int64(), + BlockHash: protoutil.ConvertHashToH256(receipt.BlockHash), + BlockNumber: receipt.BlockNumber.Int64(), + TransactionIndex: uint64(receipt.TransactionIndex), + } +} From 14764d13c53a752432ed26f33381554011adb644 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Sat, 29 Jun 2024 09:06:21 +0530 Subject: [PATCH 02/15] save --- internal/cli/server/api_service.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index fc5f7d6d5a..87787a9826 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -66,16 +66,20 @@ func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.Receip return nil, err } - receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) + receipt, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) if err != nil { return nil, err } - if len(receipts) <= int(txnIndex) { + if receipt == nil { + return nil, errors.New("no receipt found") + } + + if len(receipt) <= int(txnIndex) { return nil, errors.New("transaction index out of bounds") } - return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil + return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt[txnIndex])}, nil } func (s *Server) GetBorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { From 48c1d57e73e20db06cc067ec251174779c7ce736 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Sat, 29 Jun 2024 09:09:20 +0530 Subject: [PATCH 03/15] save --- internal/cli/server/api_service.go | 10 +++++----- internal/cli/server/utils.go | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 87787a9826..f6783804c1 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -66,20 +66,20 @@ func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.Receip return nil, err } - receipt, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) + receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) if err != nil { return nil, err } - if receipt == nil { - return nil, errors.New("no receipt found") + if receipts == nil { + return nil, errors.New("no receipts found") } - if len(receipt) <= int(txnIndex) { + if len(receipts) <= int(txnIndex) { return nil, errors.New("transaction index out of bounds") } - return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt[txnIndex])}, nil + return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil } func (s *Server) GetBorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { diff --git a/internal/cli/server/utils.go b/internal/cli/server/utils.go index 4fa8ba0960..aa461c9e92 100644 --- a/internal/cli/server/utils.go +++ b/internal/cli/server/utils.go @@ -71,7 +71,6 @@ func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt { GasUsed: receipt.GasUsed, EffectiveGasPrice: receipt.EffectiveGasPrice.Int64(), BlobGasUsed: receipt.BlobGasUsed, - BlobGasPrice: receipt.BlobGasPrice.Int64(), BlockHash: protoutil.ConvertHashToH256(receipt.BlockHash), BlockNumber: receipt.BlockNumber.Int64(), TransactionIndex: uint64(receipt.TransactionIndex), From 1918691cfa258eb61042708b897421c1d16c8c42 Mon Sep 17 00:00:00 2001 From: anshalshukla Date: Tue, 10 Sep 2024 11:05:24 +0530 Subject: [PATCH 04/15] upgrade polyproto version --- go.mod | 4 +--- go.sum | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1b2d09cfbf..156afbfc05 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( github.com/kylelemons/godebug v1.1.0 github.com/maticnetwork/crand v1.0.2 github.com/maticnetwork/heimdall v1.0.4 - github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53 + github.com/maticnetwork/polyproto v0.0.3 github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.20 github.com/mitchellh/cli v1.1.5 @@ -289,5 +289,3 @@ replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.2.7 replace github.com/Masterminds/goutils => github.com/Masterminds/goutils v1.1.1 replace go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver v1.14.0 - -replace github.com/maticnetwork/polyproto => github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e diff --git a/go.sum b/go.sum index d4dbb4efb2..771e0b3ecb 100644 --- a/go.sum +++ b/go.sum @@ -815,8 +815,6 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5 github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e h1:mpjnlMMyAXoioTDnltukXW6dnH/aPRmoRkB0bpQS+go= -github.com/anshalshukla/polyproto v0.0.0-20240621120311-ddd84287b14e/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/v10 v10.0.1/go.mod h1:YvhnlEePVnBS4+0z3fhPfUy7W1Ikj0Ih0vcRo/gZ1M0= github.com/apache/arrow/go/v11 v11.0.0/go.mod h1:Eg5OsL5H+e299f7u5ssuXsuHQVEGC4xei5aX110hRiI= @@ -1693,6 +1691,9 @@ github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxp github.com/maticnetwork/heimdall v0.3.1-0.20230227104835-81bd1055b0bc/go.mod h1:P2DoKhovYP9G9Kj2EH/zHaiRJF1jNU7ZJOyelG4UCa8= github.com/maticnetwork/heimdall v1.0.4 h1:xSsLn6JE/KqF3Fs9Wlx1s4dclJf2cduIodx2tL6K/cg= github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89eU/XUwH0AgHLs= +github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= +github.com/maticnetwork/polyproto v0.0.3 h1:a69rIp97fcl3ABY4LlVX9B2t1qhLa0Jhny3HNOzReBU= +github.com/maticnetwork/polyproto v0.0.3/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8= github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= From 7b4666df92288bb9138a95cd568fcd7eefbdb1fb Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 7 Nov 2024 14:14:19 +0100 Subject: [PATCH 05/15] add: logs --- internal/cli/server/api_service.go | 7 +++++++ internal/cli/server/utils.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index f6783804c1..bfd99fc7b9 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -3,6 +3,7 @@ package server import ( "context" "errors" + "fmt" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" @@ -11,6 +12,7 @@ import ( ) func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) { + fmt.Printf(">>>>> GetRootHash: %v\n", req) rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber) if err != nil { return nil, err @@ -20,6 +22,7 @@ func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashReque } func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) { + fmt.Printf(">>>>> GetVoteOnHash: %v\n", req) vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId) if err != nil { return nil, err @@ -37,6 +40,7 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header { } func (s *Server) GetHeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { + fmt.Printf(">>>>> GetHeaderByNumber: %v\n", req) header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { return nil, err @@ -46,6 +50,7 @@ func (s *Server) GetHeaderByNumber(ctx context.Context, req *protobor.GetHeaderB } func (s *Server) GetBlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { + fmt.Printf(">>>>> GetBlockByNumber: %v\n", req) block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { return nil, err @@ -61,6 +66,7 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + fmt.Printf(">>>>> GetTransactionReceipt: %v\n", req) _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { return nil, err @@ -83,6 +89,7 @@ func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.Receip } func (s *Server) GetBorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + fmt.Printf(">>>>> GetBorBlockReceipt: %v\n", req) receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { return nil, err diff --git a/internal/cli/server/utils.go b/internal/cli/server/utils.go index aa461c9e92..e001da0c9b 100644 --- a/internal/cli/server/utils.go +++ b/internal/cli/server/utils.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/internal/cli/server/proto" @@ -12,6 +13,7 @@ import ( ) func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { + fmt.Printf(">>>>> PeerInfoToPeer: %v\n", info) return &proto.Peer{ Id: info.ID, Enode: info.Enode, @@ -24,12 +26,14 @@ func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { } func ConvertBloomToProtoBloom(bloom types.Bloom) *protobor.Bloom { + fmt.Printf(">>>>> ConvertBloomToProtoBloom: %v\n", bloom) return &protobor.Bloom{ Bloom: bloom.Bytes(), } } func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log { + fmt.Printf(">>>>> ConvertLogsToProtoLogs: %v\n", logs) var protoLogs []*protobor.Log for _, log := range logs { protoLog := &protobor.Log{ @@ -50,6 +54,7 @@ func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log { } func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 { + fmt.Printf(">>>>> ConvertTopicsToProtoTopics: %v\n", topics) var protoTopics []*protocommon.H256 for _, topic := range topics { protoTopics = append(protoTopics, protoutil.ConvertHashToH256(topic)) @@ -59,6 +64,7 @@ func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 { } func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt { + fmt.Printf(">>>>> ConvertReceiptToProtoReceipt: %v\n", receipt) return &protobor.Receipt{ Type: uint64(receipt.Type), PostState: receipt.PostState, From aae292c8ca51bd5b744b78273cefe739888820cc Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 11:22:13 +0100 Subject: [PATCH 06/15] chg: add logs --- core/bor_blockchain.go | 2 ++ eth/bor_api_backend.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/core/bor_blockchain.go b/core/bor_blockchain.go index 1a5ce39e62..e0525b8365 100644 --- a/core/bor_blockchain.go +++ b/core/bor_blockchain.go @@ -1,6 +1,7 @@ package core import ( + "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" @@ -8,6 +9,7 @@ import ( // GetBorReceiptByHash retrieves the bor block receipt in a given block. func (bc *BlockChain) GetBorReceiptByHash(hash common.Hash) *types.Receipt { + fmt.Printf(">>>>> GetBorBlockReceiptBorBlockchain\n") if receipt, ok := bc.borReceiptsCache.Get(hash); ok { return receipt } diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index 9f909caa8e..cfa9e74f72 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -20,6 +20,7 @@ var errBorEngineNotAvailable error = errors.New("Only available in Bor engine") // GetRootHash returns root hash for given start and end block func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64) (string, error) { var api *bor.API + fmt.Printf(">>>>> GetRootHashApiBackend\n") for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) { if _api.Namespace == "bor" { @@ -42,6 +43,7 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end // GetRootHash returns root hash for given start and end block func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) { var api *bor.API + fmt.Printf(">>>>> GetVoteOnHashApiBackend\n") for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) { if _api.Namespace == "bor" { @@ -90,6 +92,8 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e // GetBorBlockReceipt returns bor block receipt func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) { + fmt.Printf(">>>>> GetBorBlockReceiptApiBackend\n") + receipt := b.eth.blockchain.GetBorReceiptByHash(hash) if receipt == nil { return nil, ethereum.NotFound @@ -100,6 +104,7 @@ func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash // GetBorBlockLogs returns bor block logs func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) { + fmt.Printf(">>>>> GetBorBlockLogsApiBackend\n") receipt := b.eth.blockchain.GetBorReceiptByHash(hash) if receipt == nil { return nil, nil @@ -110,21 +115,25 @@ func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ( // GetBorBlockTransaction returns bor block tx func (b *EthAPIBackend) GetBorBlockTransaction(ctx context.Context, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { + fmt.Printf(">>>>> GetBorBlockTransactionApiBackend\n") tx, blockHash, blockNumber, index := rawdb.ReadBorTransaction(b.eth.ChainDb(), hash) return tx, blockHash, blockNumber, index, nil } func (b *EthAPIBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { + fmt.Printf(">>>>> GetBorBlockTransactionWithBlockHashApiBackend\n") tx, blockHash, blockNumber, index := rawdb.ReadBorTransactionWithBlockHash(b.eth.ChainDb(), txHash, blockHash) return tx, blockHash, blockNumber, index, nil } // SubscribeStateSyncEvent subscribes to state sync event func (b *EthAPIBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { + fmt.Printf(">>>>> SubscribeStateSyncEventApiBackend\n") return b.eth.BlockChain().SubscribeStateSyncEvent(ch) } // SubscribeChain2HeadEvent subscribes to reorg/head/fork event func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + fmt.Printf(">>>>> SubscribeChain2HeadEventApiBackend\n") return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) } From 5d0d4fbbc55dcb92f2b8e1946dbda91d083b244b Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 11:31:11 +0100 Subject: [PATCH 07/15] chg: register reflection for grpc server --- internal/cli/server/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index b0268df524..f85108bc64 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -3,6 +3,7 @@ package server import ( "context" "fmt" + "google.golang.org/grpc/reflection" "io" "math/big" "net" @@ -443,6 +444,7 @@ func (s *Server) gRPCServerByListener(listener net.Listener) error { s.grpcServer = grpc.NewServer(s.withLoggingUnaryInterceptor()) proto.RegisterBorServer(s.grpcServer, s) protobor.RegisterBorApiServer(s.grpcServer, s) + reflection.Register(s.grpcServer) go func() { if err := s.grpcServer.Serve(listener); err != nil { From af5c3275b2b7fe58dd02c2187a83aa2479e7a9a5 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 12:05:03 +0100 Subject: [PATCH 08/15] chg: fix functions' names --- eth/bor_api_backend.go | 2 +- eth/filters/IBackend.go | 4 ++-- internal/cli/server/api_service.go | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index cfa9e74f72..d4cef2aec8 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -40,7 +40,7 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end return root, nil } -// GetRootHash returns root hash for given start and end block +// GetVoteOnHash returns the vote on hash func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) { var api *bor.API fmt.Printf(">>>>> GetVoteOnHashApiBackend\n") diff --git a/eth/filters/IBackend.go b/eth/filters/IBackend.go index da2c51617a..c04f9b1d16 100644 --- a/eth/filters/IBackend.go +++ b/eth/filters/IBackend.go @@ -132,7 +132,7 @@ func (mr *MockBackendMockRecorder) GetBorBlockLogs(arg0, arg1 interface{}) *gomo // GetBorBlockReceipt mocks base method. func (m *MockBackend) GetBorBlockReceipt(arg0 context.Context, arg1 common.Hash) (*types.Receipt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetBorBlockReceipt", arg0, arg1) + ret := m.ctrl.Call(m, "BorBlockReceipt", arg0, arg1) ret0, _ := ret[0].(*types.Receipt) ret1, _ := ret[1].(error) return ret0, ret1 @@ -141,7 +141,7 @@ func (m *MockBackend) GetBorBlockReceipt(arg0 context.Context, arg1 common.Hash) // GetBorBlockReceipt indicates an expected call of GetBorBlockReceipt. func (mr *MockBackendMockRecorder) GetBorBlockReceipt(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1) } // GetLogs mocks base method. diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index bfd99fc7b9..c59fcf5187 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -39,8 +39,8 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header { } } -func (s *Server) GetHeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { - fmt.Printf(">>>>> GetHeaderByNumber: %v\n", req) +func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { + fmt.Printf(">>>>> HeaderByNumber: %v\n", req) header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { return nil, err @@ -49,8 +49,8 @@ func (s *Server) GetHeaderByNumber(ctx context.Context, req *protobor.GetHeaderB return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil } -func (s *Server) GetBlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { - fmt.Printf(">>>>> GetBlockByNumber: %v\n", req) +func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { + fmt.Printf(">>>>> BlockByNumber: %v\n", req) block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { return nil, err @@ -65,8 +65,8 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } } -func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> GetTransactionReceipt: %v\n", req) +func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + fmt.Printf(">>>>> TransactionReceipt: %v\n", req) _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { return nil, err @@ -88,8 +88,8 @@ func (s *Server) GetTransactionReceipt(ctx context.Context, req *protobor.Receip return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil } -func (s *Server) GetBorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> GetBorBlockReceipt: %v\n", req) +func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { + fmt.Printf(">>>>> BorBlockReceipt: %v\n", req) receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { return nil, err From af939db84b924ef82970bc2b88a779b5c0544880 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 16:22:50 +0100 Subject: [PATCH 09/15] chg: logs --- core/bor_blockchain.go | 2 -- eth/bor_api_backend.go | 8 -------- internal/cli/server/api_service.go | 27 +++++++++++++++++++++------ internal/cli/server/utils.go | 6 ------ 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/bor_blockchain.go b/core/bor_blockchain.go index e0525b8365..1a5ce39e62 100644 --- a/core/bor_blockchain.go +++ b/core/bor_blockchain.go @@ -1,7 +1,6 @@ package core import ( - "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" @@ -9,7 +8,6 @@ import ( // GetBorReceiptByHash retrieves the bor block receipt in a given block. func (bc *BlockChain) GetBorReceiptByHash(hash common.Hash) *types.Receipt { - fmt.Printf(">>>>> GetBorBlockReceiptBorBlockchain\n") if receipt, ok := bc.borReceiptsCache.Get(hash); ok { return receipt } diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index d4cef2aec8..d320b45527 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -20,7 +20,6 @@ var errBorEngineNotAvailable error = errors.New("Only available in Bor engine") // GetRootHash returns root hash for given start and end block func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64) (string, error) { var api *bor.API - fmt.Printf(">>>>> GetRootHashApiBackend\n") for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) { if _api.Namespace == "bor" { @@ -43,7 +42,6 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end // GetVoteOnHash returns the vote on hash func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) { var api *bor.API - fmt.Printf(">>>>> GetVoteOnHashApiBackend\n") for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) { if _api.Namespace == "bor" { @@ -92,7 +90,6 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e // GetBorBlockReceipt returns bor block receipt func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) { - fmt.Printf(">>>>> GetBorBlockReceiptApiBackend\n") receipt := b.eth.blockchain.GetBorReceiptByHash(hash) if receipt == nil { @@ -104,7 +101,6 @@ func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash // GetBorBlockLogs returns bor block logs func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) { - fmt.Printf(">>>>> GetBorBlockLogsApiBackend\n") receipt := b.eth.blockchain.GetBorReceiptByHash(hash) if receipt == nil { return nil, nil @@ -115,25 +111,21 @@ func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ( // GetBorBlockTransaction returns bor block tx func (b *EthAPIBackend) GetBorBlockTransaction(ctx context.Context, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { - fmt.Printf(">>>>> GetBorBlockTransactionApiBackend\n") tx, blockHash, blockNumber, index := rawdb.ReadBorTransaction(b.eth.ChainDb(), hash) return tx, blockHash, blockNumber, index, nil } func (b *EthAPIBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { - fmt.Printf(">>>>> GetBorBlockTransactionWithBlockHashApiBackend\n") tx, blockHash, blockNumber, index := rawdb.ReadBorTransactionWithBlockHash(b.eth.ChainDb(), txHash, blockHash) return tx, blockHash, blockNumber, index, nil } // SubscribeStateSyncEvent subscribes to state sync event func (b *EthAPIBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { - fmt.Printf(">>>>> SubscribeStateSyncEventApiBackend\n") return b.eth.BlockChain().SubscribeStateSyncEvent(ch) } // SubscribeChain2HeadEvent subscribes to reorg/head/fork event func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { - fmt.Printf(">>>>> SubscribeChain2HeadEventApiBackend\n") return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) } diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index c59fcf5187..57813072e5 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -12,22 +12,26 @@ import ( ) func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) { - fmt.Printf(">>>>> GetRootHash: %v\n", req) + fmt.Printf(">>>>> GetRootHash: req %v\n", req) rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber) if err != nil { + fmt.Printf(">>>>> GetRootHash: err %v\n", err) return nil, err } + fmt.Printf(">>>>> GetRootHash: returning\n") return &protobor.GetRootHashResponse{RootHash: rootHash}, nil } func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) { - fmt.Printf(">>>>> GetVoteOnHash: %v\n", req) + fmt.Printf(">>>>> GetVoteOnHash: req %v\n", req) vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId) if err != nil { + fmt.Printf(">>>>> GetVoteOnHash: err %v\n", err) return nil, err } + fmt.Printf(">>>>> GetVoteOnHash: returning\n") return &protobor.GetVoteOnHashResponse{Response: vote}, nil } @@ -40,22 +44,26 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header { } func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { - fmt.Printf(">>>>> HeaderByNumber: %v\n", req) + fmt.Printf(">>>>> HeaderByNumber: req %v\n", req) header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { + fmt.Printf(">>>>> HeaderByNumber: err %v\n", err) return nil, err } + fmt.Printf(">>>>> HeaderByNumber: returning\n") return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil } func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { - fmt.Printf(">>>>> BlockByNumber: %v\n", req) + fmt.Printf(">>>>> BlockByNumber: req %v\n", req) block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { + fmt.Printf(">>>>> BlockByNumber: err %v\n", err) return nil, err } + fmt.Printf(">>>>> BlockByNumber: returning\n") return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil } @@ -66,34 +74,41 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> TransactionReceipt: %v\n", req) + fmt.Printf(">>>>> TransactionReceipt: req %v\n", req) _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { + fmt.Printf(">>>>> TransactionReceipt: err1 %v\n", err) return nil, err } receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) if err != nil { + fmt.Printf(">>>>> TransactionReceipt: err2 %v\n", err) return nil, err } if receipts == nil { + fmt.Printf(">>>>> TransactionReceipt: err3 %v\n", errors.New("no receipts found")) return nil, errors.New("no receipts found") } if len(receipts) <= int(txnIndex) { + fmt.Printf(">>>>> TransactionReceipt: err4 %v\n", errors.New("transaction index out of bounds")) return nil, errors.New("transaction index out of bounds") } + fmt.Printf(">>>>> TransactionReceipt: returning\n") return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil } func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> BorBlockReceipt: %v\n", req) + fmt.Printf(">>>>> BorBlockReceipt: req %v\n", req) receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { + fmt.Printf(">>>>> BorBlockReceipt: err %v\n", err) return nil, err } + fmt.Printf(">>>>> BorBlockReceipt: returning\n") return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil } diff --git a/internal/cli/server/utils.go b/internal/cli/server/utils.go index e001da0c9b..aa461c9e92 100644 --- a/internal/cli/server/utils.go +++ b/internal/cli/server/utils.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/internal/cli/server/proto" @@ -13,7 +12,6 @@ import ( ) func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { - fmt.Printf(">>>>> PeerInfoToPeer: %v\n", info) return &proto.Peer{ Id: info.ID, Enode: info.Enode, @@ -26,14 +24,12 @@ func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { } func ConvertBloomToProtoBloom(bloom types.Bloom) *protobor.Bloom { - fmt.Printf(">>>>> ConvertBloomToProtoBloom: %v\n", bloom) return &protobor.Bloom{ Bloom: bloom.Bytes(), } } func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log { - fmt.Printf(">>>>> ConvertLogsToProtoLogs: %v\n", logs) var protoLogs []*protobor.Log for _, log := range logs { protoLog := &protobor.Log{ @@ -54,7 +50,6 @@ func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log { } func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 { - fmt.Printf(">>>>> ConvertTopicsToProtoTopics: %v\n", topics) var protoTopics []*protocommon.H256 for _, topic := range topics { protoTopics = append(protoTopics, protoutil.ConvertHashToH256(topic)) @@ -64,7 +59,6 @@ func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 { } func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt { - fmt.Printf(">>>>> ConvertReceiptToProtoReceipt: %v\n", receipt) return &protobor.Receipt{ Type: uint64(receipt.Type), PostState: receipt.PostState, From 10f5303fac53403533839399fd0aee50168b4ada Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 17:37:48 +0100 Subject: [PATCH 10/15] chg: remove redundant logs --- internal/cli/server/api_service.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 57813072e5..04cc8ad49e 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -3,8 +3,6 @@ package server import ( "context" "errors" - "fmt" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" protobor "github.com/maticnetwork/polyproto/bor" @@ -12,26 +10,20 @@ import ( ) func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) { - fmt.Printf(">>>>> GetRootHash: req %v\n", req) rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber) if err != nil { - fmt.Printf(">>>>> GetRootHash: err %v\n", err) return nil, err } - fmt.Printf(">>>>> GetRootHash: returning\n") return &protobor.GetRootHashResponse{RootHash: rootHash}, nil } func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) { - fmt.Printf(">>>>> GetVoteOnHash: req %v\n", req) vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId) if err != nil { - fmt.Printf(">>>>> GetVoteOnHash: err %v\n", err) return nil, err } - fmt.Printf(">>>>> GetVoteOnHash: returning\n") return &protobor.GetVoteOnHashResponse{Response: vote}, nil } @@ -44,26 +36,20 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header { } func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { - fmt.Printf(">>>>> HeaderByNumber: req %v\n", req) header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { - fmt.Printf(">>>>> HeaderByNumber: err %v\n", err) return nil, err } - fmt.Printf(">>>>> HeaderByNumber: returning\n") return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil } func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { - fmt.Printf(">>>>> BlockByNumber: req %v\n", req) block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) if err != nil { - fmt.Printf(">>>>> BlockByNumber: err %v\n", err) return nil, err } - fmt.Printf(">>>>> BlockByNumber: returning\n") return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil } @@ -74,41 +60,32 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> TransactionReceipt: req %v\n", req) _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { - fmt.Printf(">>>>> TransactionReceipt: err1 %v\n", err) return nil, err } receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) if err != nil { - fmt.Printf(">>>>> TransactionReceipt: err2 %v\n", err) return nil, err } if receipts == nil { - fmt.Printf(">>>>> TransactionReceipt: err3 %v\n", errors.New("no receipts found")) return nil, errors.New("no receipts found") } if len(receipts) <= int(txnIndex) { - fmt.Printf(">>>>> TransactionReceipt: err4 %v\n", errors.New("transaction index out of bounds")) return nil, errors.New("transaction index out of bounds") } - fmt.Printf(">>>>> TransactionReceipt: returning\n") return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil } func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - fmt.Printf(">>>>> BorBlockReceipt: req %v\n", req) receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { - fmt.Printf(">>>>> BorBlockReceipt: err %v\n", err) return nil, err } - fmt.Printf(">>>>> BorBlockReceipt: returning\n") return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil } From e21905701d14d47602ff379496c2b18b6c773113 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 17:46:55 +0100 Subject: [PATCH 11/15] chg: sort imports --- internal/cli/server/server.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index f85108bc64..713b99f1db 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -3,7 +3,6 @@ package server import ( "context" "fmt" - "google.golang.org/grpc/reflection" "io" "math/big" "net" @@ -12,18 +11,6 @@ import ( "runtime" "time" - "github.com/mattn/go-colorable" - "github.com/mattn/go-isatty" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/sdk/resource" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" - "google.golang.org/grpc" - - protobor "github.com/maticnetwork/polyproto/bor" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -42,10 +29,22 @@ import ( "github.com/ethereum/go-ethereum/metrics/influxdb" "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" + "github.com/mattn/go-colorable" + "github.com/mattn/go-isatty" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" // Force-load the tracer engines to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/js" _ "github.com/ethereum/go-ethereum/eth/tracers/native" + + protobor "github.com/maticnetwork/polyproto/bor" ) type Server struct { From 422122815c0ec21afb00a4e6869f6b08e6ae2446 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 18:16:23 +0100 Subject: [PATCH 12/15] add: deps --- go.sum | 3 ++- internal/cli/server/server.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index ce93e54d7f..4ed86b6fc1 100644 --- a/go.sum +++ b/go.sum @@ -1706,8 +1706,9 @@ github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxp github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89eU/XUwH0AgHLs= github.com/maticnetwork/heimdall v1.0.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60= github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA= -github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53 h1:PjYV+lghs106JKkrYgOnrsfDLoTc11BxZd4rUa4Rus4= github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= +github.com/maticnetwork/polyproto v0.0.3 h1:a69rIp97fcl3ABY4LlVX9B2t1qhLa0Jhny3HNOzReBU= +github.com/maticnetwork/polyproto v0.0.3/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8= github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 57a931baa7..33b89e2b57 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -30,6 +30,16 @@ import ( "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" + "github.com/mattn/go-colorable" + "github.com/mattn/go-isatty" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" // Force-load the tracer engines to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/js" From 2af775c1f8bad0563a79996618de054eb44d68e2 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 18:25:39 +0100 Subject: [PATCH 13/15] fix: build --- internal/cli/server/api_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 04cc8ad49e..080832aed2 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -60,7 +60,7 @@ func blockToProtoBlock(h *types.Block) *protobor.Block { } func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { - _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) + _, _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) if err != nil { return nil, err } From a4eb8db5bff43f24e4f26f2f7c1e614486c137ee Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 18:33:58 +0100 Subject: [PATCH 14/15] fix: lint --- eth/bor_api_backend.go | 1 - 1 file changed, 1 deletion(-) diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index 0d82741d67..88f5e1f34d 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -90,7 +90,6 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e // GetBorBlockReceipt returns bor block receipt func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) { - receipt := b.eth.blockchain.GetBorReceiptByHash(hash) if receipt == nil { return nil, ethereum.NotFound From 7a854127dce21841f3ae3f816b38f827ec7a0360 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 8 Nov 2024 18:40:26 +0100 Subject: [PATCH 15/15] fix: lint --- internal/cli/server/api_service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 080832aed2..67e7c0924c 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -3,8 +3,10 @@ package server import ( "context" "errors" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" + protobor "github.com/maticnetwork/polyproto/bor" protoutil "github.com/maticnetwork/polyproto/utils" )