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..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.3 + 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 4ed86b6fc1..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.3 h1:a69rIp97fcl3ABY4LlVX9B2t1qhLa0Jhny3HNOzReBU= -github.com/maticnetwork/polyproto v0.0.3/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= 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 67e7c0924c..3781b6b45d 100644 --- a/internal/cli/server/api_service.go +++ b/internal/cli/server/api_service.go @@ -4,6 +4,8 @@ import ( "context" "errors" + "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" @@ -38,7 +40,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 +53,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 +101,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) { + switch blockNumber { + case "latest": + return rpc.LatestBlockNumber, nil + case "earliest": + return rpc.EarliestBlockNumber, nil + case "pending": + return rpc.PendingBlockNumber, nil + case "finalized": + return rpc.FinalizedBlockNumber, nil + case "safe": + return rpc.SafeBlockNumber, nil + default: + blckNum, err := hexutil.DecodeUint64(blockNumber) + if err != nil { + return rpc.BlockNumber(0), errors.New("invalid block number") + } + if blckNum > math.MaxInt64 { + return rpc.BlockNumber(0), errors.New("block number out of range") + } + return rpc.BlockNumber(blckNum), nil + } +}