Skip to content

Commit

Permalink
Merge branch 'develop' into regossip-atxs-periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 27, 2023
2 parents e42f55d + 060a126 commit e5bef32
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 88 deletions.
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,7 @@ issues:
# exclude:
# - abcdef
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some `staticcheck` messages.
- linters:
- staticcheck
text: "SA1019:"
# exclude-rules:
# Independently of option `exclude` we use default exclude patterns,
# it can be disabled by this option.
# To list all excluded by default patterns execute `golangci-lint run --help`.
Expand Down
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
51 changes: 24 additions & 27 deletions api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package grpcserver

//lint:file-ignore SA1019 hide deprecated protobuf version error
import (
"bytes"
"context"
Expand All @@ -15,14 +14,10 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"testing"
"time"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"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 @@ -35,6 +30,9 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"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 @@ -466,11 +464,10 @@ func (*SmeshingAPIMock) Coinbase() types.Address {
func (*SmeshingAPIMock) SetCoinbase(coinbase types.Address) {
}

func marshalProto(t *testing.T, msg proto.Message) string {
var buf bytes.Buffer
var m jsonpb.Marshaler
require.NoError(t, m.Marshal(&buf, msg))
return buf.String()
func marshalProto(t *testing.T, msg proto.Message) []byte {
buf, err := protojson.Marshal(msg)
require.NoError(t, err)
return buf
}

func launchServer(tb testing.TB, services ...ServiceAPI) (Config, func()) {
Expand Down Expand Up @@ -501,15 +498,15 @@ func launchServer(tb testing.TB, services ...ServiceAPI) (Config, func()) {
}
}

func callEndpoint(t *testing.T, url, payload string) (string, int) {
resp, err := http.Post(url, "application/json", strings.NewReader(payload))
func callEndpoint(t *testing.T, url string, payload []byte) ([]byte, int) {
resp, err := http.Post(url, "application/json", bytes.NewReader(payload))
require.NoError(t, err)
require.Equal(t, "application/json", resp.Header.Get("Content-Type"))
buf, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

return string(buf), resp.StatusCode
return buf, resp.StatusCode
}

func getFreePort(optionalPort int) (int, error) {
Expand Down Expand Up @@ -587,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 @@ -623,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 @@ -924,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 @@ -957,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 @@ -979,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 @@ -1008,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 @@ -2361,7 +2358,7 @@ func TestJsonApi(t *testing.T) {

payload := marshalProto(t, &pb.EchoRequest{Msg: &pb.SimpleString{Value: message}})
url := fmt.Sprintf("http://%s/%s", cfg.JSONListener, "v1/node/echo")
_, err := http.Post(url, "application/json", strings.NewReader(payload))
_, err := http.Post(url, "application/json", bytes.NewReader(payload))
require.Error(t, err)
shutDown()

Expand All @@ -2384,14 +2381,14 @@ func TestJsonApi(t *testing.T) {
respBody, respStatus := callEndpoint(t, fmt.Sprintf("http://%s/%s", cfg.JSONListener, "v1/node/echo"), payload)
require.Equal(t, http.StatusOK, respStatus)
var msg pb.EchoResponse
require.NoError(t, jsonpb.UnmarshalString(respBody, &msg))
require.NoError(t, protojson.Unmarshal(respBody, &msg))
require.Equal(t, message, msg.Msg.Value)

// Test MeshService
respBody2, respStatus2 := callEndpoint(t, fmt.Sprintf("http://%s/%s", cfg.JSONListener, "v1/mesh/genesistime"), "")
respBody2, respStatus2 := callEndpoint(t, fmt.Sprintf("http://%s/%s", cfg.JSONListener, "v1/mesh/genesistime"), nil)
require.Equal(t, http.StatusOK, respStatus2)
var msg2 pb.GenesisTimeResponse
require.NoError(t, jsonpb.UnmarshalString(respBody2, &msg2))
require.NoError(t, protojson.Unmarshal(respBody2, &msg2))
require.Equal(t, uint64(genesis.Unix()), msg2.Unixtime.Value)
}

Expand Down Expand Up @@ -2453,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 @@ -2480,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

0 comments on commit e5bef32

Please sign in to comment.