Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC edge cases #1374

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eth/filters/IBackend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/bor_health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ do
fi
done

echo $peers
echo $block
echo "$peers"
echo "$block"
14 changes: 7 additions & 7 deletions integration-tests/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ 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
fi

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)))"
34 changes: 32 additions & 2 deletions internal/cli/server/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"errors"
"strconv"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -38,7 +39,11 @@
}

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
}
Expand All @@ -47,7 +52,11 @@
}

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
}
Expand Down Expand Up @@ -91,3 +100,24 @@

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 := strconv.ParseUint(blockNumber, 10, 64)
marcello33 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return rpc.BlockNumber(0), errors.New("invalid block number")
}
return rpc.BlockNumber(blckNum), nil
Fixed Show fixed Hide fixed
}
}
Loading