Skip to content

Commit 4c4185c

Browse files
authored
Merge pull request ethereum#1374 from maticnetwork/mardizzone/grpc
gRPC edge cases
2 parents 6d4d96b + b6efb3f commit 4c4185c

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

eth/filters/IBackend.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ require (
6565
github.com/kylelemons/godebug v1.1.0
6666
github.com/maticnetwork/crand v1.0.2
6767
github.com/maticnetwork/heimdall v1.0.7
68-
github.com/maticnetwork/polyproto v0.0.3
68+
github.com/maticnetwork/polyproto v0.0.4
6969
github.com/mattn/go-colorable v0.1.13
7070
github.com/mattn/go-isatty v0.0.20
7171
github.com/mitchellh/cli v1.1.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,8 @@ github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89
17081708
github.com/maticnetwork/heimdall v1.0.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60=
17091709
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
17101710
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
1711-
github.com/maticnetwork/polyproto v0.0.3 h1:a69rIp97fcl3ABY4LlVX9B2t1qhLa0Jhny3HNOzReBU=
1712-
github.com/maticnetwork/polyproto v0.0.3/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
1711+
github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk=
1712+
github.com/maticnetwork/polyproto v0.0.4/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
17131713
github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8=
17141714
github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
17151715
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=

integration-tests/bor_health.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ do
1111
fi
1212
done
1313

14-
echo $peers
15-
echo $block
14+
echo "$peers"
15+
echo "$block"

integration-tests/smoke_test.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ do
1818
exit 1
1919
fi
2020

21-
if (( $balance > $balanceInit )); then
22-
if [ $stateSyncFound != "true" ]; then
21+
if (( balance > balanceInit )); then
22+
if [ "$stateSyncFound" != "true" ]; then
2323
stateSyncTime=$(( SECONDS - start_time ))
2424
stateSyncFound="true"
2525
fi
2626
fi
2727

2828
checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id)
2929

30-
if [ $checkpointID != "null" ]; then
31-
if [ $checkpointFound != "true" ]; then
30+
if [ "$checkpointID" != "null" ]; then
31+
if [ "$checkpointFound" != "true" ]; then
3232
checkpointTime=$(( SECONDS - start_time ))
3333
checkpointFound="true"
3434
fi
3535
fi
3636

37-
if [ $stateSyncFound == "true" ] && [ $checkpointFound == "true" ]; then
37+
if [ "$stateSyncFound" == "true" ] && [ "$checkpointFound" == "true" ]; then
3838
break
3939
fi
4040

4141
done
4242
echo "Both state sync and checkpoint went through. All tests have passed!"
43-
echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $(($stateSyncTime%3600/60)) $(($stateSyncTime%60)))"
44-
echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $(($checkpointTime%3600/60)) $(($checkpointTime%60)))"
43+
echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $((stateSyncTime%3600/60)) $((stateSyncTime%60)))"
44+
echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $((checkpointTime%3600/60)) $((checkpointTime%60)))"

internal/cli/server/api_service.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66

7+
"github.com/ethereum/go-ethereum/common/hexutil"
8+
"github.com/ethereum/go-ethereum/common/math"
79
"github.com/ethereum/go-ethereum/core/types"
810
"github.com/ethereum/go-ethereum/rpc"
911

@@ -38,7 +40,11 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header {
3840
}
3941

4042
func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) {
41-
header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number))
43+
bN, err := getRpcBlockNumberFromString(req.Number)
44+
if err != nil {
45+
return nil, err
46+
}
47+
header, err := s.backend.APIBackend.HeaderByNumber(ctx, bN)
4248
if err != nil {
4349
return nil, err
4450
}
@@ -47,7 +53,11 @@ func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNu
4753
}
4854

4955
func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) {
50-
block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number))
56+
bN, err := getRpcBlockNumberFromString(req.Number)
57+
if err != nil {
58+
return nil, err
59+
}
60+
block, err := s.backend.APIBackend.BlockByNumber(ctx, bN)
5161
if err != nil {
5262
return nil, err
5363
}
@@ -91,3 +101,27 @@ func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptReque
91101

92102
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil
93103
}
104+
105+
func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) {
106+
switch blockNumber {
107+
case "latest":
108+
return rpc.LatestBlockNumber, nil
109+
case "earliest":
110+
return rpc.EarliestBlockNumber, nil
111+
case "pending":
112+
return rpc.PendingBlockNumber, nil
113+
case "finalized":
114+
return rpc.FinalizedBlockNumber, nil
115+
case "safe":
116+
return rpc.SafeBlockNumber, nil
117+
default:
118+
blckNum, err := hexutil.DecodeUint64(blockNumber)
119+
if err != nil {
120+
return rpc.BlockNumber(0), errors.New("invalid block number")
121+
}
122+
if blckNum > math.MaxInt64 {
123+
return rpc.BlockNumber(0), errors.New("block number out of range")
124+
}
125+
return rpc.BlockNumber(blckNum), nil
126+
}
127+
}

0 commit comments

Comments
 (0)