From 91cd4a8c8bf3cef6d125c5c01ee28fdc06114ea0 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 21 Jun 2024 17:45:05 +0530 Subject: [PATCH 01/31] 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/31] 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/31] 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/31] 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 69470888fab459c0602ba2e8619665888ddb2459 Mon Sep 17 00:00:00 2001 From: luozexuan Date: Thu, 10 Oct 2024 20:48:48 +0800 Subject: [PATCH 05/31] chore: fix function name --- core/chain_makers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index fa9d45d7e8..37f5a23eeb 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -618,7 +618,7 @@ func makeBlockChainWithGenesis(genesis *Genesis, n int, engine consensus.Engine, return db, blocks } -// makeBlockChain creates a deterministic chain of blocks rooted at parent with fake invalid transactions. +// makeFakeNonEmptyBlockChain creates a deterministic chain of blocks rooted at parent with fake invalid transactions. func makeFakeNonEmptyBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int, numTx int) []*types.Block { blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) { addr := common.Address{0: byte(seed), 19: byte(i)} From f08f2ead424a3e85bdc82e89df8f2ac68c16955d Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 31 Oct 2024 10:56:34 +0100 Subject: [PATCH 06/31] chg: some sec fixes --- consensus/bor/heimdall/client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/consensus/bor/heimdall/client.go b/consensus/bor/heimdall/client.go index 680c09d5f7..029164c986 100644 --- a/consensus/bor/heimdall/client.go +++ b/consensus/bor/heimdall/client.go @@ -31,9 +31,10 @@ var ( ) const ( - stateFetchLimit = 50 - apiHeimdallTimeout = 5 * time.Second - retryCall = 5 * time.Second + heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB + stateFetchLimit = 50 + apiHeimdallTimeout = 5 * time.Second + retryCall = 5 * time.Second ) type StateSyncEventsResponse struct { @@ -455,8 +456,11 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte, return nil, nil } + // Limit the number of bytes read from the response body + limitedBody := http.MaxBytesReader(nil, res.Body, heimdallAPIBodyLimit) + // get response - body, err := io.ReadAll(res.Body) + body, err := io.ReadAll(limitedBody) if err != nil { return nil, err } From 7b4666df92288bb9138a95cd568fcd7eefbdb1fb Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 7 Nov 2024 14:14:19 +0100 Subject: [PATCH 07/31] 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 08/31] 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 09/31] 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 10/31] 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 11/31] 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 12/31] 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 13/31] 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 14/31] 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 15/31] 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 16/31] 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 17/31] 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" ) From 9cb6fcac0b7e6b7478950eb86327a75778585e2a Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 11:33:02 +0100 Subject: [PATCH 18/31] chg: handle edge cases with string blockNumber --- eth/filters/IBackend.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- internal/cli/server/api_service.go | 36 ++++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/eth/filters/IBackend.go b/eth/filters/IBackend.go index 7dfd509f83..3a69c90d2e 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, "BorBlockReceipt", arg0, arg1) + ret := m.ctrl.Call(m, "GetBorBlockReceipt", 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, "BorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1) } // GetLogs mocks base method. diff --git a/go.mod b/go.mod index a976c95e21..f8258fb3d8 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/kylelemons/godebug v1.1.0 github.com/maticnetwork/crand v1.0.2 github.com/maticnetwork/heimdall v1.0.7 - github.com/maticnetwork/polyproto v0.0.3 + github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59 github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.20 github.com/mitchellh/cli v1.1.5 diff --git a/go.sum b/go.sum index 4ed86b6fc1..b60ff0b105 100644 --- a/go.sum +++ b/go.sum @@ -1707,8 +1707,8 @@ github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89 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/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/polyproto v0.0.4-0.20241113101917-6744479e4d59 h1:FAezvZ+jt3b1all6taYql6+mafszYBpwfD5KYQqQdNg= +github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59/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/api_service.go b/internal/cli/server/api_service.go index 67e7c0924c..670cb65dbe 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -38,7 +38,11 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header { } func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { - header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number)) + bN, err := getRpcBlockNumberFromString(req.Number) + if err != nil { + return nil, err + } + header, err := s.backend.APIBackend.HeaderByNumber(ctx, bN) if err != nil { return nil, err } @@ -47,7 +51,11 @@ func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNu } func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { - block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number)) + bN, err := getRpcBlockNumberFromString(req.Number) + if err != nil { + return nil, err + } + block, err := s.backend.APIBackend.BlockByNumber(ctx, bN) if err != nil { return nil, err } @@ -91,3 +99,27 @@ func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptReque return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil } + +func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { + if blockNumber == "latest" { + return rpc.LatestBlockNumber, nil + } + + if blockNumber == "earliest" { + return rpc.EarliestBlockNumber, nil + } + + if blockNumber == "pending" { + return rpc.PendingBlockNumber, nil + } + + if blockNumber == "finalized" { + return rpc.FinalizedBlockNumber, nil + } + + if blockNumber == "safe" { + return rpc.SafeBlockNumber, nil + } + + return rpc.BlockNumber(0), errors.New("invalid block number") +} From 927db07fc4d84158a35350eb455b7c4dd8dd024d Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 14:04:19 +0100 Subject: [PATCH 19/31] chg: switch blockNumber --- internal/cli/server/api_service.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 670cb65dbe..a9dba46a1f 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -101,25 +101,18 @@ func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptReque } func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { - if blockNumber == "latest" { + switch blockNumber { + case "latest": return rpc.LatestBlockNumber, nil - } - - if blockNumber == "earliest" { + case "earliest": return rpc.EarliestBlockNumber, nil - } - - if blockNumber == "pending" { + case "pending": return rpc.PendingBlockNumber, nil - } - - if blockNumber == "finalized" { + case "finalized": return rpc.FinalizedBlockNumber, nil - } - - if blockNumber == "safe" { + case "safe": return rpc.SafeBlockNumber, nil + default: + return rpc.BlockNumber(0), errors.New("invalid block number") } - - return rpc.BlockNumber(0), errors.New("invalid block number") } From baa8a2bb6354f2d86c9c4f5c3b2250cdab823564 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 14:45:41 +0100 Subject: [PATCH 20/31] cgh: fix rpc blockNumber and bash warnings --- integration-tests/bor_health.sh | 4 ++-- integration-tests/smoke_test.sh | 14 +++++++------- internal/cli/server/api_service.go | 7 ++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/integration-tests/bor_health.sh b/integration-tests/bor_health.sh index 0791d415fd..469992098c 100644 --- a/integration-tests/bor_health.sh +++ b/integration-tests/bor_health.sh @@ -11,5 +11,5 @@ do fi done -echo $peers -echo $block +echo "$peers" +echo "$block" diff --git a/integration-tests/smoke_test.sh b/integration-tests/smoke_test.sh index 4541ec5d4d..f5354ffde7 100644 --- a/integration-tests/smoke_test.sh +++ b/integration-tests/smoke_test.sh @@ -18,8 +18,8 @@ do exit 1 fi - if (( $balance > $balanceInit )); then - if [ $stateSyncFound != "true" ]; then + if (( balance > balanceInit )); then + if [ "$stateSyncFound" != "true" ]; then stateSyncTime=$(( SECONDS - start_time )) stateSyncFound="true" fi @@ -27,18 +27,18 @@ do checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id) - if [ $checkpointID != "null" ]; then - if [ $checkpointFound != "true" ]; then + if [ "$checkpointID" != "null" ]; then + if [ "$checkpointFound" != "true" ]; then checkpointTime=$(( SECONDS - start_time )) checkpointFound="true" fi fi - if [ $stateSyncFound == "true" ] && [ $checkpointFound == "true" ]; then + if [ "$stateSyncFound" == "true" ] && [ "$checkpointFound" == "true" ]; then break fi done echo "Both state sync and checkpoint went through. All tests have passed!" -echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $(($stateSyncTime%3600/60)) $(($stateSyncTime%60)))" -echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $(($checkpointTime%3600/60)) $(($checkpointTime%60)))" +echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $((stateSyncTime%3600/60)) $((stateSyncTime%60)))" +echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $((checkpointTime%3600/60)) $((checkpointTime%60)))" diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index a9dba46a1f..78ddade84d 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -3,6 +3,7 @@ package server import ( "context" "errors" + "strconv" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" @@ -113,6 +114,10 @@ func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { case "safe": return rpc.SafeBlockNumber, nil default: - return rpc.BlockNumber(0), errors.New("invalid block number") + blckNum, err := strconv.ParseUint(blockNumber, 10, 64) + if err != nil { + return rpc.BlockNumber(0), errors.New("invalid block number") + } + return rpc.BlockNumber(blckNum), nil } } From 32138d70ad37ceff1cf7f4ed10f2ddaca35c24a2 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 14:58:18 +0100 Subject: [PATCH 21/31] cgh: fix possible out of range on blockNumber --- internal/cli/server/api_service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 78ddade84d..2861cf3a9d 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -118,6 +118,9 @@ func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { if err != nil { return rpc.BlockNumber(0), errors.New("invalid block number") } + if blckNum > uint64(^uint32(0)) { + return rpc.BlockNumber(0), errors.New("block number out of range") + } return rpc.BlockNumber(blckNum), nil } } From 0634d11d8652cbd57571e47a63b3de15157e5090 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 15:01:55 +0100 Subject: [PATCH 22/31] cgh: use geth for maxInt --- internal/cli/server/api_service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index 2861cf3a9d..b5469c3752 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -5,6 +5,7 @@ import ( "errors" "strconv" + "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" @@ -118,7 +119,7 @@ func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { if err != nil { return rpc.BlockNumber(0), errors.New("invalid block number") } - if blckNum > uint64(^uint32(0)) { + if blckNum > math.MaxInt64 { return rpc.BlockNumber(0), errors.New("block number out of range") } return rpc.BlockNumber(blckNum), nil From 10d9594b52ee02dcdebc1a0284993b6a89046c72 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 14 Nov 2024 07:19:13 +0100 Subject: [PATCH 23/31] chg: try blocks hex ecnoding --- internal/cli/server/api_service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/server/api_service.go b/internal/cli/server/api_service.go index b5469c3752..3781b6b45d 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -3,8 +3,8 @@ package server import ( "context" "errors" - "strconv" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" @@ -115,7 +115,7 @@ func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { case "safe": return rpc.SafeBlockNumber, nil default: - blckNum, err := strconv.ParseUint(blockNumber, 10, 64) + blckNum, err := hexutil.DecodeUint64(blockNumber) if err != nil { return rpc.BlockNumber(0), errors.New("invalid block number") } From b6efb3f10213157725d682a3a85358a64011e667 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 14 Nov 2024 11:42:54 +0100 Subject: [PATCH 24/31] chg: bump polyproto --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f8258fb3d8..967a73dbef 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/kylelemons/godebug v1.1.0 github.com/maticnetwork/crand v1.0.2 github.com/maticnetwork/heimdall v1.0.7 - github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59 + github.com/maticnetwork/polyproto v0.0.4 github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.20 github.com/mitchellh/cli v1.1.5 diff --git a/go.sum b/go.sum index b60ff0b105..491f81cc7a 100644 --- a/go.sum +++ b/go.sum @@ -1707,8 +1707,8 @@ github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89 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/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= -github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59 h1:FAezvZ+jt3b1all6taYql6+mafszYBpwfD5KYQqQdNg= -github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= +github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk= +github.com/maticnetwork/polyproto v0.0.4/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= From 6d4d96b0b77627e84f2f727fc0fcaa530f8856bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:24:58 +0530 Subject: [PATCH 25/31] build(deps): bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 (#1371) Bumps [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) from 4.5.0 to 4.5.1. - [Release notes](https://github.com/golang-jwt/jwt/releases) - [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md) - [Commits](https://github.com/golang-jwt/jwt/compare/v4.5.0...v4.5.1) --- updated-dependencies: - dependency-name: github.com/golang-jwt/jwt/v4 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index a976c95e21..790daf8f9a 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 github.com/gofrs/flock v0.8.1 - github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/golang-jwt/jwt/v4 v4.5.1 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb diff --git a/go.sum b/go.sum index 4ed86b6fc1..f130a698f2 100644 --- a/go.sum +++ b/go.sum @@ -1292,8 +1292,9 @@ github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw= github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= From ee5318b07b227f7daa1cca3aba2b55e2b80d31f2 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Mon, 18 Nov 2024 14:18:04 +0700 Subject: [PATCH 26/31] core: validate chain before writing block (#1319) --- core/blockchain.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 3097ad4367..818b72e953 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2374,6 +2374,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) status WriteStatus ) + // Before the actual db insertion happens, verify the block against the whitelisted + // milestone and checkpoint. This is to prevent a race condition where a milestone + // or checkpoint was whitelisted while the block execution happened (and wasn't + // available sometime before) and the block turns out to be inavlid (i.e. not + // honouring the milestone or checkpoint). Use the block itself as current block + // so that it's considered as a `past` chain and the validation doesn't get bypassed. + isValid, err = bc.forker.ValidateReorg(block.Header(), []*types.Header{block.Header()}) + if err != nil { + return it.index, err + } + if !isValid { + return it.index, whitelist.ErrMismatch + } + if !setHead { // Don't set the head, only insert the block _, err = bc.writeBlockWithState(block, receipts, logs, statedb) From b45347aa1aa2209eb63f542678a07e985b2295f5 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Thu, 5 Dec 2024 11:03:04 -0600 Subject: [PATCH 27/31] Wrong architecture binary ended up in arm64 --- .github/workflows/packager_deb.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/packager_deb.yml b/.github/workflows/packager_deb.yml index 5a0d3177e2..ff76627e55 100644 --- a/.github/workflows/packager_deb.yml +++ b/.github/workflows/packager_deb.yml @@ -82,6 +82,9 @@ jobs: - name: Building bor for arm64 run: GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 go build -o build/bin/bor ./cmd/cli/main.go + - name: Copying necessary binary file + run: cp -rp build/bin/bor packaging/deb/bor/usr/bin/ + # Control file for arm64 creation - name: create control file run: | From 7869600b244ba0b1a455eb1f2d698d8a18df958a Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Thu, 5 Dec 2024 11:05:20 -0600 Subject: [PATCH 28/31] Updating verbage --- .github/workflows/packager_deb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/packager_deb.yml b/.github/workflows/packager_deb.yml index ff76627e55..526d0e75a6 100644 --- a/.github/workflows/packager_deb.yml +++ b/.github/workflows/packager_deb.yml @@ -82,7 +82,7 @@ jobs: - name: Building bor for arm64 run: GOARCH=arm64 GOOS=linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ CGO_ENABLED=1 go build -o build/bin/bor ./cmd/cli/main.go - - name: Copying necessary binary file + - name: Copying necessary binary post arm64 build run: cp -rp build/bin/bor packaging/deb/bor/usr/bin/ # Control file for arm64 creation From d509034fc9089f8c6c9a353a218ecbac30bdc6c0 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Tue, 10 Dec 2024 08:58:30 +0100 Subject: [PATCH 29/31] chg: update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 9008ea5c32..302df7b253 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 9b67e9dc56..b33ddbbfa5 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 591848766f..77d4fa1589 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 28c58b93a7..d44b33c2ea 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 617c260911..296f2c9807 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 8c22ec7920..4236ced085 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.2 +Version: 1.5.3-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index a6a5e20046..46f5c399cb 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 5 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 5 // Minor version component of the current release + VersionPatch = 3 // Patch version component of the current release + VersionMeta = "beta" // Version metadata to append to the version string ) var GitCommit string From 8f7533076ead5be034da537bc185934e14fcf6ee Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 11 Dec 2024 08:39:16 +0100 Subject: [PATCH 30/31] chg: bump stable version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 302df7b253..90e6823dae 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index b33ddbbfa5..6b964b276f 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 77d4fa1589..40ab62ac87 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index d44b33c2ea..16ec4c00ed 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 296f2c9807..73a5c0fb3b 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 4236ced085..d122a2328e 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.5.3-beta +Version: 1.5.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 46f5c399cb..3bd5d0572a 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 5 // Minor version component of the current release - VersionPatch = 3 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 5 // Minor version component of the current release + VersionPatch = 3 // Patch version component of the current release + VersionMeta = "" // Version metadata to append to the version string ) var GitCommit string From 6c75359553b044a87e9a7d10f801097de7f1b6e1 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 10 Dec 2024 05:26:47 -0800 Subject: [PATCH 31/31] Fix incorrect balance when CreateContract is used in block-stm (#1382) * Fix incorrect balance when CreateContract is used in block-stm * address CR comments --- core/state/statedb.go | 9 +++------ core/state/statedb_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index e477651906..2ea0662ce0 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -418,7 +418,6 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) { switch path.GetSubpath() { case BalancePath: - // todo: @anshalshukla || @cffls - check balance change reason s.SetBalance(addr, sr.GetBalance(addr), tracing.BalanceChangeUnspecified) case NoncePath: s.SetNonce(addr, sr.GetNonce(addr)) @@ -1095,9 +1094,6 @@ func (s *StateDB) createObject(addr common.Address) *stateObject { // consensus bug eventually. func (s *StateDB) CreateAccount(addr common.Address) { s.createObject(addr) - // todo: @anshalshukla || @cffls - // Check the below MV Write, balance path change have been removed - MVWrite(s, blockstm.NewAddressKey(addr)) } // CreateContract is used whenever a contract is created. This may be preceded @@ -1107,13 +1103,14 @@ func (s *StateDB) CreateAccount(addr common.Address) { // correctly handle EIP-6780 'delete-in-same-transaction' logic. func (s *StateDB) CreateContract(addr common.Address) { obj := s.getStateObject(addr) + if obj != nil { + obj = s.mvRecordWritten(obj) + } if !obj.newContract { obj.newContract = true s.journal.append(createContractChange{account: addr}) } - // todo: @anshalshukla || @cffls - // Check the below MV Write, balance path change have been removed MVWrite(s, blockstm.NewAddressKey(addr)) } diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index a514f7c9f4..9fe1cd9995 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -813,6 +813,33 @@ func TestMVHashMapReadWriteDelete(t *testing.T) { assert.Equal(t, uint256.NewInt(0), b) } +func TestMVHashMapCreateContract(t *testing.T) { + t.Parallel() + + db := NewDatabase(rawdb.NewMemoryDatabase()) + mvhm := blockstm.MakeMVHashMap() + s, _ := NewWithMVHashmap(common.Hash{}, db, nil, mvhm) + + states := []*StateDB{s} + + // Create copies of the original state for each transition + for i := 1; i <= 4; i++ { + sCopy := s.Copy() + sCopy.txIndex = i + states = append(states, sCopy) + } + + addr := common.HexToAddress("0x01") + states[0].SetBalance(addr, uint256.NewInt(100), tracing.BalanceChangeTransfer) + states[0].FlushMVWriteSet() + + states[1].CreateContract(addr) + states[1].FlushMVWriteSet() + + b := states[1].GetBalance(addr) + assert.Equal(t, uint256.NewInt(100), b) +} + func TestMVHashMapRevert(t *testing.T) { t.Parallel()