Skip to content

Commit

Permalink
Completely remove github.com/golang/protobuf dependency (#5098)
Browse files Browse the repository at this point in the history
## Motivation
Follow up to #5092. This completely removes `github.com/golang/protobuf` as a direct dependency.

## Changes
- Replace `github.com/golang/protobuf` with `google.golang.org/protobuf`

## Test Plan
<!-- Please specify how these changes were tested
(e.g. unit tests, manual testing, etc.) -->

## TODO
<!-- This section should be removed when all items are complete -->
- [x] Explain motivation or link existing issue(s)
- [x] Test changes and document test plan
- [x] Update documentation as needed
- [x] Update [changelog](../CHANGELOG.md) as needed
  • Loading branch information
fasmat committed Sep 27, 2023
1 parent 60f149f commit 060a126
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions api/grpcserver/activation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"fmt"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/events"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (s *activationService) Get(ctx context.Context, request *pb.GetRequest) (*p
return resp, nil
}

func (s *activationService) Highest(ctx context.Context, req *empty.Empty) (*pb.HighestResponse, error) {
func (s *activationService) Highest(ctx context.Context, req *emptypb.Empty) (*pb.HighestResponse, error) {
highest, err := s.atxProvider.MaxHeightAtx()
if err != nil {
return &pb.HighestResponse{
Expand Down
6 changes: 3 additions & 3 deletions api/grpcserver/activation_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"math/rand"
"testing"

"github.com/golang/protobuf/ptypes/empty"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/api/grpcserver"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand All @@ -26,7 +26,7 @@ func Test_Highest_ReturnsGoldenAtxOnError(t *testing.T) {
activationService := grpcserver.NewActivationService(atxProvider, goldenAtx)

atxProvider.EXPECT().MaxHeightAtx().Return(types.EmptyATXID, errors.New("blah"))
response, err := activationService.Highest(context.Background(), &empty.Empty{})
response, err := activationService.Highest(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.Equal(t, goldenAtx.Bytes(), response.Atx.Id.Id)
require.Nil(t, response.Atx.Layer)
Expand Down Expand Up @@ -62,7 +62,7 @@ func Test_Highest_ReturnsMaxTickHeight(t *testing.T) {
atxProvider.EXPECT().MaxHeightAtx().Return(id, nil)
atxProvider.EXPECT().GetFullAtx(id).Return(&atx, nil)

response, err := activationService.Highest(context.Background(), &empty.Empty{})
response, err := activationService.Highest(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.Equal(t, atx.ID().Bytes(), response.Atx.Id.Id)
require.Equal(t, atx.PublishEpoch.Uint32(), response.Atx.Layer.Number)
Expand Down
8 changes: 4 additions & 4 deletions api/grpcserver/admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"os"
"time"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/spf13/afero"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/checkpoint"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -102,10 +102,10 @@ func (a AdminService) CheckpointStream(req *pb.CheckpointStreamRequest, stream p
}
}

func (a AdminService) Recover(ctx context.Context, _ *pb.RecoverRequest) (*empty.Empty, error) {
func (a AdminService) Recover(ctx context.Context, _ *pb.RecoverRequest) (*emptypb.Empty, error) {
ctxzap.Info(ctx, "going to recover from checkpoint")
a.recover()
return &empty.Empty{}, nil
return &emptypb.Empty{}, nil
}

func (a AdminService) EventsStream(req *pb.EventStreamRequest, stream pb.AdminService_EventsStreamServer) error {
Expand Down Expand Up @@ -140,7 +140,7 @@ func (a AdminService) EventsStream(req *pb.EventStreamRequest, stream pb.AdminSe
}
}

func (a AdminService) PeerInfoStream(_ *empty.Empty, stream pb.AdminService_PeerInfoStreamServer) error {
func (a AdminService) PeerInfoStream(_ *emptypb.Empty, stream pb.AdminService_PeerInfoStreamServer) error {
for _, p := range a.p.GetPeers() {
select {
case <-stream.Context().Done():
Expand Down
3 changes: 1 addition & 2 deletions api/grpcserver/debug_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"go.uber.org/zap"
Expand Down Expand Up @@ -78,7 +77,7 @@ func (d DebugService) Accounts(ctx context.Context, in *pb.AccountsRequest) (*pb
}

// NetworkInfo query provides NetworkInfoResponse.
func (d DebugService) NetworkInfo(ctx context.Context, _ *empty.Empty) (*pb.NetworkInfoResponse, error) {
func (d DebugService) NetworkInfo(ctx context.Context, _ *emptypb.Empty) (*pb.NetworkInfoResponse, error) {
return &pb.NetworkInfoResponse{Id: d.identity.ID().String()}, nil
}

Expand Down
22 changes: 11 additions & 11 deletions api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"
"time"

"github.com/golang/protobuf/ptypes/empty"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/spacemeshos/merkle-tree"
"github.com/spacemeshos/poet/shared"
Expand All @@ -33,6 +32,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/codec"
Expand Down Expand Up @@ -584,12 +584,12 @@ func TestNodeService(t *testing.T) {
require.Equal(t, "Must include `Msg`", grpcStatus.Message())
}},
{"Version", func(t *testing.T) {
res, err := c.Version(context.Background(), &empty.Empty{})
res, err := c.Version(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.Equal(t, version, res.VersionString.Value)
}},
{"Build", func(t *testing.T) {
res, err := c.Build(context.Background(), &empty.Empty{})
res, err := c.Build(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.Equal(t, build, res.BuildString.Value)
}},
Expand Down Expand Up @@ -620,7 +620,7 @@ func TestNodeService(t *testing.T) {
require.Equal(t, layerVerified.Uint32(), res.Status.VerifiedLayer.Number)
}},
{"NodeInfo", func(t *testing.T) {
resp, err := c.NodeInfo(ctx, &empty.Empty{})
resp, err := c.NodeInfo(ctx, &emptypb.Empty{})
require.NoError(t, err)
require.Equal(t, resp.Hrp, types.NetworkHRP())
require.Equal(t, resp.FirstGenesis, types.FirstEffectiveGenesis().Uint32())
Expand Down Expand Up @@ -921,7 +921,7 @@ func TestSmesherService(t *testing.T) {
c := pb.NewSmesherServiceClient(conn)

t.Run("IsSmeshing", func(t *testing.T) {
res, err := c.IsSmeshing(context.Background(), &empty.Empty{})
res, err := c.IsSmeshing(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.False(t, res.IsSmeshing, "expected IsSmeshing to be false")
})
Expand Down Expand Up @@ -954,7 +954,7 @@ func TestSmesherService(t *testing.T) {
})

t.Run("SmesherID", func(t *testing.T) {
res, err := c.SmesherID(context.Background(), &empty.Empty{})
res, err := c.SmesherID(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.NoError(t, err)
require.Equal(t, signer.NodeID().Bytes(), res.PublicKey)
Expand All @@ -976,15 +976,15 @@ func TestSmesherService(t *testing.T) {
})

t.Run("Coinbase", func(t *testing.T) {
res, err := c.Coinbase(context.Background(), &empty.Empty{})
res, err := c.Coinbase(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
addr, err := types.StringToAddress(res.AccountId.Address)
require.NoError(t, err)
require.Equal(t, addr1.Bytes(), addr.Bytes())
})

t.Run("MinGas", func(t *testing.T) {
_, err := c.MinGas(context.Background(), &empty.Empty{})
_, err := c.MinGas(context.Background(), &emptypb.Empty{})
require.Error(t, err)
statusCode := status.Code(err)
require.Equal(t, codes.Unimplemented, statusCode)
Expand All @@ -1005,7 +1005,7 @@ func TestSmesherService(t *testing.T) {
t.Run("PostSetupStatusStream", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, err := c.PostSetupStatusStream(ctx, &empty.Empty{})
stream, err := c.PostSetupStatusStream(ctx, &emptypb.Empty{})
require.NoError(t, err)

// Expecting the stream to return updates before closing.
Expand Down Expand Up @@ -2450,7 +2450,7 @@ func TestDebugService(t *testing.T) {
id := p2p.Peer("test")
identity.EXPECT().ID().Return(id)

response, err := c.NetworkInfo(context.Background(), &empty.Empty{})
response, err := c.NetworkInfo(context.Background(), &emptypb.Empty{})
require.NoError(t, err)
require.NotNil(t, response)
require.Equal(t, id.String(), response.Id)
Expand All @@ -2477,7 +2477,7 @@ func TestDebugService(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
stream, err := c.ProposalsStream(ctx, &empty.Empty{})
stream, err := c.ProposalsStream(ctx, &emptypb.Empty{})
require.NoError(t, err)

_, err = stream.Header()
Expand Down
8 changes: 4 additions & 4 deletions api/grpcserver/node_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/events"
Expand Down Expand Up @@ -61,14 +61,14 @@ func (s NodeService) Echo(_ context.Context, in *pb.EchoRequest) (*pb.EchoRespon
}

// Version returns the version of the node software as a semver string.
func (s NodeService) Version(context.Context, *empty.Empty) (*pb.VersionResponse, error) {
func (s NodeService) Version(context.Context, *emptypb.Empty) (*pb.VersionResponse, error) {
return &pb.VersionResponse{
VersionString: &pb.SimpleString{Value: s.appVersion},
}, nil
}

// Build returns the build of the node software.
func (s NodeService) Build(context.Context, *empty.Empty) (*pb.BuildResponse, error) {
func (s NodeService) Build(context.Context, *emptypb.Empty) (*pb.BuildResponse, error) {
return &pb.BuildResponse{
BuildString: &pb.SimpleString{Value: s.appCommit},
}, nil
Expand All @@ -89,7 +89,7 @@ func (s NodeService) Status(ctx context.Context, _ *pb.StatusRequest) (*pb.Statu
}, nil
}

func (s NodeService) NodeInfo(context.Context, *empty.Empty) (*pb.NodeInfoResponse, error) {
func (s NodeService) NodeInfo(context.Context, *emptypb.Empty) (*pb.NodeInfoResponse, error) {
return &pb.NodeInfoResponse{
Hrp: types.NetworkHRP(),
FirstGenesis: types.FirstEffectiveGenesis().Uint32(),
Expand Down
16 changes: 8 additions & 8 deletions api/grpcserver/smesher_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"time"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/spacemeshos/post/config"
Expand All @@ -15,6 +14,7 @@ import (
rpcstatus "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -45,7 +45,7 @@ func NewSmesherService(post postSetupProvider, smeshing activation.SmeshingProvi
}

// IsSmeshing reports whether the node is smeshing.
func (s SmesherService) IsSmeshing(context.Context, *empty.Empty) (*pb.IsSmeshingResponse, error) {
func (s SmesherService) IsSmeshing(context.Context, *emptypb.Empty) (*pb.IsSmeshingResponse, error) {
return &pb.IsSmeshingResponse{IsSmeshing: s.smeshingProvider.Smeshing()}, nil
}

Expand Down Expand Up @@ -119,12 +119,12 @@ func (s SmesherService) StopSmeshing(ctx context.Context, in *pb.StopSmeshingReq
}

// SmesherID returns the smesher ID of this node.
func (s SmesherService) SmesherID(context.Context, *empty.Empty) (*pb.SmesherIDResponse, error) {
func (s SmesherService) SmesherID(context.Context, *emptypb.Empty) (*pb.SmesherIDResponse, error) {
return &pb.SmesherIDResponse{PublicKey: s.smeshingProvider.SmesherID().Bytes()}, nil
}

// Coinbase returns the current coinbase setting of this node.
func (s SmesherService) Coinbase(context.Context, *empty.Empty) (*pb.CoinbaseResponse, error) {
func (s SmesherService) Coinbase(context.Context, *emptypb.Empty) (*pb.CoinbaseResponse, error) {
return &pb.CoinbaseResponse{AccountId: &pb.AccountId{Address: s.smeshingProvider.Coinbase().String()}}, nil
}

Expand All @@ -146,7 +146,7 @@ func (s SmesherService) SetCoinbase(_ context.Context, in *pb.SetCoinbaseRequest
}

// MinGas returns the current mingas setting of this node.
func (s SmesherService) MinGas(context.Context, *empty.Empty) (*pb.MinGasResponse, error) {
func (s SmesherService) MinGas(context.Context, *emptypb.Empty) (*pb.MinGasResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "this endpoint is not implemented")
}

Expand All @@ -161,13 +161,13 @@ func (s SmesherService) EstimatedRewards(context.Context, *pb.EstimatedRewardsRe
}

// PostSetupStatus returns post data status.
func (s SmesherService) PostSetupStatus(ctx context.Context, _ *empty.Empty) (*pb.PostSetupStatusResponse, error) {
func (s SmesherService) PostSetupStatus(ctx context.Context, _ *emptypb.Empty) (*pb.PostSetupStatusResponse, error) {
status := s.postSetupProvider.Status()
return &pb.PostSetupStatusResponse{Status: statusToPbStatus(status)}, nil
}

// PostSetupStatusStream exposes a stream of status updates during post setup.
func (s SmesherService) PostSetupStatusStream(_ *empty.Empty, stream pb.SmesherService_PostSetupStatusStreamServer) error {
func (s SmesherService) PostSetupStatusStream(_ *emptypb.Empty, stream pb.SmesherService_PostSetupStatusStreamServer) error {
timer := time.NewTicker(s.streamInterval)
defer timer.Stop()

Expand Down Expand Up @@ -216,7 +216,7 @@ func (s SmesherService) PostSetupProviders(ctx context.Context, in *pb.PostSetup
}

// PostConfig returns the Post protocol config.
func (s SmesherService) PostConfig(context.Context, *empty.Empty) (*pb.PostConfigResponse, error) {
func (s SmesherService) PostConfig(context.Context, *emptypb.Empty) (*pb.PostConfigResponse, error) {
cfg := s.postSetupProvider.Config()

return &pb.PostConfigResponse{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/cosmos/btcutil v1.0.5
github.com/go-llsqlite/crawshaw v0.4.0
github.com/gofrs/flock v0.8.1
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.3.1
Expand Down Expand Up @@ -100,6 +99,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand Down
1 change: 0 additions & 1 deletion hare/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type HareWrapper struct {
termination chan struct{}
clock *mockClock
hare []*Hare
//lint:ignore U1000 pending https://github.com/spacemeshos/go-spacemesh/issues/4001
initialSets []*Set
outputs map[types.LayerID][]*Set
}
Expand Down
4 changes: 2 additions & 2 deletions node/adminservice_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"testing"
"time"

"github.com/golang/protobuf/ptypes/empty"
"github.com/libp2p/go-libp2p/core/peer"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/spacemeshos/go-spacemesh/api/grpcserver"
"github.com/spacemeshos/go-spacemesh/config"
Expand All @@ -34,7 +34,7 @@ func TestPeerInfoApi(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

streamClient, err := adminapi.PeerInfoStream(ctx, &empty.Empty{})
streamClient, err := adminapi.PeerInfoStream(ctx, &emptypb.Empty{})
require.NoError(t, err)
for {
info, err := streamClient.Recv()
Expand Down

0 comments on commit 060a126

Please sign in to comment.