mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
Merge pull request #1374 from maticnetwork/mardizzone/grpc
gRPC edge cases
This commit is contained in:
commit
4c4185c9ae
6 changed files with 50 additions and 16 deletions
|
|
@ -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.
|
||||
|
|
|
|||
2
go.mod
2
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
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -1708,8 +1708,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=
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ do
|
|||
fi
|
||||
done
|
||||
|
||||
echo $peers
|
||||
echo $block
|
||||
echo "$peers"
|
||||
echo "$block"
|
||||
|
|
|
|||
|
|
@ -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)))"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue