From fd6715d665b6d4548f2297e2c120406ef3b27198 Mon Sep 17 00:00:00 2001 From: ConvallariaMaj Date: Thu, 25 Jul 2024 18:09:24 +0000 Subject: [PATCH] Remove unused params (#6173) ## Motivation Cleaning up the code a little bit Co-authored-by: ConvallariaMaj <132993066+ConvallariaMaj@users.noreply.github.com> --- activation/nipost.go | 2 +- activation/poetdb.go | 1 - api/grpcserver/admin_service.go | 16 +++--- api/grpcserver/admin_service_test.go | 8 +-- api/grpcserver/debug_service.go | 18 +++--- api/grpcserver/globalstate_service.go | 24 ++++---- api/grpcserver/globalstate_service_test.go | 5 +- api/grpcserver/grpcserver_test.go | 64 +++++++++------------ api/grpcserver/http_server.go | 1 - api/grpcserver/http_server_test.go | 2 +- api/grpcserver/mesh_service.go | 38 ++++++------ api/grpcserver/mesh_service_test.go | 6 +- api/grpcserver/node_service.go | 22 +++---- api/grpcserver/node_service_test.go | 5 +- api/grpcserver/post_info_service_test.go | 2 +- api/grpcserver/smesher_service.go | 40 ++++++------- api/grpcserver/transaction_service.go | 18 +++--- api/grpcserver/transaction_service_test.go | 11 ++-- api/grpcserver/v2alpha1/account.go | 2 +- api/grpcserver/v2alpha1/account_test.go | 2 +- api/grpcserver/v2alpha1/activation_test.go | 6 +- api/grpcserver/v2alpha1/layer_test.go | 4 +- api/grpcserver/v2alpha1/network_test.go | 2 +- api/grpcserver/v2alpha1/node_test.go | 2 +- api/grpcserver/v2alpha1/reward.go | 2 +- api/grpcserver/v2alpha1/reward_test.go | 4 +- api/grpcserver/v2alpha1/transaction_test.go | 12 ++-- api/grpcserver/v2alpha1/v2alpha1_test.go | 3 +- cmd/bootstrapper/generator_test.go | 2 +- node/node.go | 2 +- 30 files changed, 152 insertions(+), 174 deletions(-) diff --git a/activation/nipost.go b/activation/nipost.go index 3ee0b17b65..bb29387a14 100644 --- a/activation/nipost.go +++ b/activation/nipost.go @@ -355,7 +355,7 @@ func withConditionalTimeout(ctx context.Context, timeout time.Duration) (context return ctx, func() {} } -// Submit the challenge to a single PoET. +// Submit the challenge (register) to a single PoET. func (nb *NIPostBuilder) submitPoetChallenge( ctx context.Context, nodeID types.NodeID, diff --git a/activation/poetdb.go b/activation/poetdb.go index 39650a1e72..d8bdb09d4b 100644 --- a/activation/poetdb.go +++ b/activation/poetdb.go @@ -94,7 +94,6 @@ func (db *PoetDb) Validate( return fmt.Errorf("failed to validate poet proof for poetID %x round %s: %w", shortID, roundID, err) } // TODO(noamnelke): validate signature (or extract public key and use for salting merkle hashes) - return nil } diff --git a/api/grpcserver/admin_service.go b/api/grpcserver/admin_service.go index 3da2e55d4b..eb7f4e9988 100644 --- a/api/grpcserver/admin_service.go +++ b/api/grpcserver/admin_service.go @@ -57,20 +57,20 @@ func NewAdminService(db *sql.Database, dataDir string, p peers) *AdminService { } // RegisterService registers this service with a grpc server instance. -func (a AdminService) RegisterService(server *grpc.Server) { +func (a *AdminService) RegisterService(server *grpc.Server) { pb.RegisterAdminServiceServer(server, a) } -func (s AdminService) RegisterHandlerService(mux *runtime.ServeMux) error { - return pb.RegisterAdminServiceHandlerServer(context.Background(), mux, s) +func (a *AdminService) RegisterHandlerService(mux *runtime.ServeMux) error { + return pb.RegisterAdminServiceHandlerServer(context.Background(), mux, a) } // String returns the name of this service. -func (a AdminService) String() string { +func (a *AdminService) String() string { return "AdminService" } -func (a AdminService) CheckpointStream( +func (a *AdminService) CheckpointStream( req *pb.CheckpointStreamRequest, stream pb.AdminService_CheckpointStreamServer, ) error { @@ -118,13 +118,13 @@ func (a AdminService) CheckpointStream( } } -func (a AdminService) Recover(ctx context.Context, _ *pb.RecoverRequest) (*emptypb.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 &emptypb.Empty{}, nil } -func (a AdminService) EventsStream(req *pb.EventStreamRequest, stream pb.AdminService_EventsStreamServer) error { +func (a *AdminService) EventsStream(_ *pb.EventStreamRequest, stream pb.AdminService_EventsStreamServer) error { sub, buf, err := events.SubscribeUserEvents(events.WithBuffer(1000)) if err != nil { return status.Errorf(codes.FailedPrecondition, err.Error()) @@ -156,7 +156,7 @@ func (a AdminService) EventsStream(req *pb.EventStreamRequest, stream pb.AdminSe } } -func (a AdminService) PeerInfoStream(_ *emptypb.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(): diff --git a/api/grpcserver/admin_service_test.go b/api/grpcserver/admin_service_test.go index e68222adbc..6e3ae789d8 100644 --- a/api/grpcserver/admin_service_test.go +++ b/api/grpcserver/admin_service_test.go @@ -65,7 +65,7 @@ func TestAdminService_Checkpoint(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewAdminServiceClient(conn) stream, err := c.CheckpointStream(ctx, &pb.CheckpointStreamRequest{SnapshotLayer: snapshot}) @@ -101,7 +101,7 @@ func TestAdminService_CheckpointError(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewAdminServiceClient(conn) stream, err := c.CheckpointStream(ctx, &pb.CheckpointStreamRequest{SnapshotLayer: snapshot}) @@ -121,7 +121,7 @@ func TestAdminService_Recovery(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewAdminServiceClient(conn) _, err := c.Recover(ctx, &pb.RecoverRequest{}) @@ -141,7 +141,7 @@ func TestAdminService_PeerInfo(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewAdminServiceClient(conn) p1 := p2p.Peer("p1") diff --git a/api/grpcserver/debug_service.go b/api/grpcserver/debug_service.go index f0e0b6671e..5d13b47a00 100644 --- a/api/grpcserver/debug_service.go +++ b/api/grpcserver/debug_service.go @@ -32,16 +32,16 @@ type DebugService struct { } // RegisterService registers this service with a grpc server instance. -func (d DebugService) RegisterService(server *grpc.Server) { +func (d *DebugService) RegisterService(server *grpc.Server) { pb.RegisterDebugServiceServer(server, d) } -func (s DebugService) RegisterHandlerService(mux *runtime.ServeMux) error { - return pb.RegisterDebugServiceHandlerServer(context.Background(), mux, s) +func (d *DebugService) RegisterHandlerService(mux *runtime.ServeMux) error { + return pb.RegisterDebugServiceHandlerServer(context.Background(), mux, d) } // String returns the name of this service. -func (d DebugService) String() string { +func (d *DebugService) String() string { return "DebugService" } @@ -59,7 +59,7 @@ func NewDebugService(db *sql.Database, conState conservativeState, host networkI } // Accounts returns current counter and balance for all accounts. -func (d DebugService) Accounts(ctx context.Context, in *pb.AccountsRequest) (*pb.AccountsResponse, error) { +func (d *DebugService) Accounts(ctx context.Context, in *pb.AccountsRequest) (*pb.AccountsResponse, error) { var ( accts []*types.Account err error @@ -96,7 +96,7 @@ func (d DebugService) Accounts(ctx context.Context, in *pb.AccountsRequest) (*pb } // NetworkInfo query provides NetworkInfoResponse. -func (d DebugService) NetworkInfo(ctx context.Context, _ *emptypb.Empty) (*pb.NetworkInfoResponse, error) { +func (d *DebugService) NetworkInfo(ctx context.Context, _ *emptypb.Empty) (*pb.NetworkInfoResponse, error) { resp := &pb.NetworkInfoResponse{Id: d.netInfo.ID().String()} for _, a := range d.netInfo.ListenAddresses() { resp.ListenAddresses = append(resp.ListenAddresses, a.String()) @@ -139,7 +139,7 @@ func (d DebugService) NetworkInfo(ctx context.Context, _ *emptypb.Empty) (*pb.Ne } // ActiveSet query provides hare active set for the specified epoch. -func (d DebugService) ActiveSet(ctx context.Context, req *pb.ActiveSetRequest) (*pb.ActiveSetResponse, error) { +func (d *DebugService) ActiveSet(ctx context.Context, req *pb.ActiveSetRequest) (*pb.ActiveSetResponse, error) { actives, err := d.oracle.ActiveSet(ctx, types.EpochID(req.Epoch)) if err != nil { return nil, status.Errorf(codes.Internal, fmt.Sprintf("active set for epoch %d: %s", req.Epoch, err.Error())) @@ -152,7 +152,7 @@ func (d DebugService) ActiveSet(ctx context.Context, req *pb.ActiveSetRequest) ( } // ProposalsStream streams all proposals confirmed by hare. -func (d DebugService) ProposalsStream(_ *emptypb.Empty, stream pb.DebugService_ProposalsStreamServer) error { +func (d *DebugService) ProposalsStream(_ *emptypb.Empty, stream pb.DebugService_ProposalsStreamServer) error { sub := events.SubscribeProposals() if sub == nil { return status.Errorf(codes.FailedPrecondition, "event reporting is not enabled") @@ -177,7 +177,7 @@ func (d DebugService) ProposalsStream(_ *emptypb.Empty, stream pb.DebugService_P } } -func (d DebugService) ChangeLogLevel(ctx context.Context, req *pb.ChangeLogLevelRequest) (*emptypb.Empty, error) { +func (d *DebugService) ChangeLogLevel(ctx context.Context, req *pb.ChangeLogLevelRequest) (*emptypb.Empty, error) { level, err := zap.ParseAtomicLevel(req.GetLevel()) if err != nil { return nil, fmt.Errorf("parse level: %w", err) diff --git a/api/grpcserver/globalstate_service.go b/api/grpcserver/globalstate_service.go index f6ed0c260b..b1c1b167bb 100644 --- a/api/grpcserver/globalstate_service.go +++ b/api/grpcserver/globalstate_service.go @@ -24,16 +24,16 @@ type GlobalStateService struct { } // RegisterService registers this service with a grpc server instance. -func (s GlobalStateService) RegisterService(server *grpc.Server) { +func (s *GlobalStateService) RegisterService(server *grpc.Server) { pb.RegisterGlobalStateServiceServer(server, s) } -func (s GlobalStateService) RegisterHandlerService(mux *runtime.ServeMux) error { +func (s *GlobalStateService) RegisterHandlerService(mux *runtime.ServeMux) error { return pb.RegisterGlobalStateServiceHandlerServer(context.Background(), mux, s) } // String returns the name of the service. -func (s GlobalStateService) String() string { +func (s *GlobalStateService) String() string { return "GlobalStateService" } @@ -46,7 +46,7 @@ func NewGlobalStateService(msh meshAPI, conState conservativeState) *GlobalState } // GlobalStateHash returns the latest layer and its computed global state hash. -func (s GlobalStateService) GlobalStateHash( +func (s *GlobalStateService) GlobalStateHash( context.Context, *pb.GlobalStateHashRequest, ) (*pb.GlobalStateHashResponse, error) { @@ -60,7 +60,7 @@ func (s GlobalStateService) GlobalStateHash( }}, nil } -func (s GlobalStateService) getAccount(addr types.Address) (acct *pb.Account, err error) { +func (s *GlobalStateService) getAccount(addr types.Address) (acct *pb.Account, err error) { balanceActual, err := s.conState.GetBalance(addr) if err != nil { return nil, err @@ -84,7 +84,7 @@ func (s GlobalStateService) getAccount(addr types.Address) (acct *pb.Account, er } // Account returns current and projected counter and balance for one account. -func (s GlobalStateService) Account(ctx context.Context, in *pb.AccountRequest) (*pb.AccountResponse, error) { +func (s *GlobalStateService) Account(ctx context.Context, in *pb.AccountRequest) (*pb.AccountResponse, error) { if in.AccountId == nil { return nil, status.Errorf(codes.InvalidArgument, "`AccountId` must be provided") } @@ -112,7 +112,7 @@ func (s GlobalStateService) Account(ctx context.Context, in *pb.AccountRequest) } // AccountDataQuery returns historical account data such as rewards and receipts. -func (s GlobalStateService) AccountDataQuery( +func (s *GlobalStateService) AccountDataQuery( ctx context.Context, in *pb.AccountDataQueryRequest, ) (*pb.AccountDataQueryResponse, error) { @@ -200,7 +200,7 @@ func (s GlobalStateService) AccountDataQuery( } // SmesherDataQuery returns historical info on smesher rewards. -func (s GlobalStateService) SmesherDataQuery( +func (s *GlobalStateService) SmesherDataQuery( _ context.Context, in *pb.SmesherDataQueryRequest, ) (*pb.SmesherDataQueryResponse, error) { @@ -210,7 +210,7 @@ func (s GlobalStateService) SmesherDataQuery( // STREAMS // AccountDataStream exposes a stream of account-related data. -func (s GlobalStateService) AccountDataStream( +func (s *GlobalStateService) AccountDataStream( in *pb.AccountDataStreamRequest, stream pb.GlobalStateService_AccountDataStreamServer, ) error { @@ -328,7 +328,7 @@ func (s GlobalStateService) AccountDataStream( } // SmesherRewardStream exposes a stream of smesher rewards. -func (s GlobalStateService) SmesherRewardStream( +func (s *GlobalStateService) SmesherRewardStream( in *pb.SmesherRewardStreamRequest, stream pb.GlobalStateService_SmesherRewardStreamServer, ) error { @@ -336,7 +336,7 @@ func (s GlobalStateService) SmesherRewardStream( } // AppEventStream exposes a stream of emitted app events. -func (s GlobalStateService) AppEventStream( +func (s *GlobalStateService) AppEventStream( *pb.AppEventStreamRequest, pb.GlobalStateService_AppEventStreamServer, ) error { @@ -347,7 +347,7 @@ func (s GlobalStateService) AppEventStream( } // GlobalStateStream exposes a stream of global data data items: rewards, receipts, account info, global state hash. -func (s GlobalStateService) GlobalStateStream( +func (s *GlobalStateService) GlobalStateStream( in *pb.GlobalStateStreamRequest, stream pb.GlobalStateService_GlobalStateStreamServer, ) error { diff --git a/api/grpcserver/globalstate_service_test.go b/api/grpcserver/globalstate_service_test.go index b2f8566e82..8df8fc6425 100644 --- a/api/grpcserver/globalstate_service_test.go +++ b/api/grpcserver/globalstate_service_test.go @@ -4,7 +4,6 @@ import ( "context" "math" "testing" - "time" pb "github.com/spacemeshos/api/release/go/spacemesh/v1" "github.com/stretchr/testify/require" @@ -30,9 +29,7 @@ func setupGlobalStateService(t *testing.T) (*globalStateServiceConn, context.Con cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - grpcCtx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(grpcCtx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewGlobalStateServiceClient(conn) return &globalStateServiceConn{ diff --git a/api/grpcserver/grpcserver_test.go b/api/grpcserver/grpcserver_test.go index bf9b7c3769..10f08fc71b 100644 --- a/api/grpcserver/grpcserver_test.go +++ b/api/grpcserver/grpcserver_test.go @@ -124,7 +124,7 @@ func genLayerBlock(layerID types.LayerID, txs []types.TransactionID) *types.Bloc return b } -func dialGrpc(ctx context.Context, tb testing.TB, cfg Config) *grpc.ClientConn { +func dialGrpc(tb testing.TB, cfg Config) *grpc.ClientConn { tb.Helper() conn, err := grpc.NewClient( cfg.PublicListener, @@ -528,9 +528,7 @@ func setupSmesherService(t *testing.T, sig *signing.EdSigner) (*smesherServiceCo cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewSmesherServiceClient(conn) return &smesherServiceConn{ @@ -748,9 +746,7 @@ func TestMeshService(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewMeshServiceClient(conn) // Construct an array of test cases to test each endpoint in turn @@ -1262,7 +1258,7 @@ func TestTransactionServiceSubmitUnsync(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewTransactionServiceClient(conn) serializedTx, err := codec.Encode(globalTx) @@ -1301,7 +1297,7 @@ func TestTransactionServiceSubmitInvalidTx(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewTransactionServiceClient(conn) serializedTx, err := codec.Encode(globalTx) @@ -1334,7 +1330,7 @@ func TestTransactionService_SubmitNoConcurrency(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewTransactionServiceClient(conn) for range numTxs { res, err := c.SubmitTransaction(ctx, &pb.SubmitTransactionRequest{ @@ -1360,9 +1356,7 @@ func TestTransactionService(t *testing.T) { cfg, cleanup := launchServer(t, grpcService) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewTransactionServiceClient(conn) // Construct an array of test cases to test each endpoint in turn @@ -1679,9 +1673,7 @@ func TestAccountMeshDataStream_comprehensive(t *testing.T) { cfg, cleanup := launchServer(t, grpcService) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewMeshServiceClient(conn) // set up the grpc listener stream @@ -1694,7 +1686,7 @@ func TestAccountMeshDataStream_comprehensive(t *testing.T) { }, } - ctx, cancel = context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() stream, err := c.AccountMeshDataStream(ctx, req) require.NoError(t, err, "stream request returned unexpected error") @@ -1729,9 +1721,7 @@ func TestAccountDataStream_comprehensive(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewGlobalStateServiceClient(conn) // set up the grpc listener stream @@ -1745,7 +1735,7 @@ func TestAccountDataStream_comprehensive(t *testing.T) { }, } - ctx, cancel = context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() stream, err := c.AccountDataStream(ctx, req) require.NoError(t, err, "stream request returned unexpected error") @@ -1789,9 +1779,7 @@ func TestGlobalStateStream_comprehensive(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewGlobalStateServiceClient(conn) // set up the grpc listener stream @@ -1802,6 +1790,9 @@ func TestGlobalStateStream_comprehensive(t *testing.T) { pb.GlobalStateDataFlag_GLOBAL_STATE_DATA_FLAG_REWARD), } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + stream, err := c.GlobalStateStream(ctx, req) require.NoError(t, err, "stream request returned unexpected error") // Give the server-side time to subscribe to events @@ -1864,12 +1855,13 @@ func TestLayerStream_comprehensive(t *testing.T) { cfg, cleanup := launchServer(t, grpcService) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) // set up the grpc listener stream c := pb.NewMeshServiceClient(conn) + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() stream, err := c.LayerStream(ctx, &pb.LayerStreamRequest{}) require.NoError(t, err, "stream request returned unexpected error") // Give the server-side time to subscribe to events @@ -2007,8 +1999,8 @@ func TestMultiService(t *testing.T) { cfg, shutDown := launchServer(t, svc1, svc2) t.Cleanup(shutDown) - c1 := pb.NewNodeServiceClient(dialGrpc(ctx, t, cfg)) - c2 := pb.NewMeshServiceClient(dialGrpc(ctx, t, cfg)) + c1 := pb.NewNodeServiceClient(dialGrpc(t, cfg)) + c2 := pb.NewMeshServiceClient(dialGrpc(t, cfg)) // call endpoints and validate results const message = "Hello World" @@ -2050,9 +2042,7 @@ func TestDebugService(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := pb.NewDebugServiceClient(conn) t.Run("Accounts", func(t *testing.T) { @@ -2241,8 +2231,8 @@ func TestEventsReceived(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn1 := dialGrpc(ctx, t, cfg) - conn2 := dialGrpc(ctx, t, cfg) + conn1 := dialGrpc(t, cfg) + conn2 := dialGrpc(t, cfg) txClient := pb.NewTransactionServiceClient(conn1) accountClient := pb.NewGlobalStateServiceClient(conn2) @@ -2329,7 +2319,7 @@ func TestTransactionsRewards(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) t.Cleanup(cancel) - client := pb.NewGlobalStateServiceClient(dialGrpc(ctx, t, cfg)) + client := pb.NewGlobalStateServiceClient(dialGrpc(t, cfg)) address := wallet.Address(types.RandomNodeID().Bytes()) weight := new(big.Rat).SetFloat64(18.7) @@ -2419,7 +2409,7 @@ func TestVMAccountUpdates(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) t.Cleanup(cancel) - client := pb.NewGlobalStateServiceClient(dialGrpc(ctx, t, cfg)) + client := pb.NewGlobalStateServiceClient(dialGrpc(t, cfg)) eg, ctx := errgroup.WithContext(ctx) states := make(chan *pb.AccountState, len(accounts)) for _, account := range accounts { @@ -2512,7 +2502,7 @@ func TestMeshService_EpochStream(t *testing.T) { } ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewMeshServiceClient(conn) stream, err := client.EpochStream(ctx, &pb.EpochStreamRequest{Epoch: epoch.Uint32()}) diff --git a/api/grpcserver/http_server.go b/api/grpcserver/http_server.go index e529f517e3..6c0087c15b 100644 --- a/api/grpcserver/http_server.go +++ b/api/grpcserver/http_server.go @@ -74,7 +74,6 @@ func (s *JSONHTTPServer) Shutdown(ctx context.Context) error { // StartService starts the json api server and listens for status (started, stopped). func (s *JSONHTTPServer) StartService( - ctx context.Context, services ...ServiceAPI, ) error { // At least one service must be enabled diff --git a/api/grpcserver/http_server_test.go b/api/grpcserver/http_server_test.go index 46f75a5bd2..9f72c576f4 100644 --- a/api/grpcserver/http_server_test.go +++ b/api/grpcserver/http_server_test.go @@ -29,7 +29,7 @@ func launchJsonServer(tb testing.TB, services ...ServiceAPI) (Config, func()) { []string{}, false) // start json server - require.NoError(tb, jsonService.StartService(context.Background(), services...)) + require.NoError(tb, jsonService.StartService(services...)) // update config with bound address cfg.JSONListener = jsonService.BoundAddress diff --git a/api/grpcserver/mesh_service.go b/api/grpcserver/mesh_service.go index 2f18793916..9e95a8b82f 100644 --- a/api/grpcserver/mesh_service.go +++ b/api/grpcserver/mesh_service.go @@ -38,16 +38,16 @@ type MeshService struct { } // RegisterService registers this service with a grpc server instance. -func (s MeshService) RegisterService(server *grpc.Server) { +func (s *MeshService) RegisterService(server *grpc.Server) { pb.RegisterMeshServiceServer(server, s) } -func (s MeshService) RegisterHandlerService(mux *runtime.ServeMux) error { +func (s *MeshService) RegisterHandlerService(mux *runtime.ServeMux) error { return pb.RegisterMeshServiceHandlerServer(context.Background(), mux, s) } // String returns the name of this service. -func (s MeshService) String() string { +func (s *MeshService) String() string { return "MeshService" } @@ -77,21 +77,21 @@ func NewMeshService( } // GenesisTime returns the network genesis time as UNIX time. -func (s MeshService) GenesisTime(context.Context, *pb.GenesisTimeRequest) (*pb.GenesisTimeResponse, error) { +func (s *MeshService) GenesisTime(context.Context, *pb.GenesisTimeRequest) (*pb.GenesisTimeResponse, error) { return &pb.GenesisTimeResponse{Unixtime: &pb.SimpleInt{ Value: uint64(s.genTime.GenesisTime().Unix()), }}, nil } // CurrentLayer returns the current layer number. -func (s MeshService) CurrentLayer(context.Context, *pb.CurrentLayerRequest) (*pb.CurrentLayerResponse, error) { +func (s *MeshService) CurrentLayer(context.Context, *pb.CurrentLayerRequest) (*pb.CurrentLayerResponse, error) { return &pb.CurrentLayerResponse{Layernum: &pb.LayerNumber{ Number: s.genTime.CurrentLayer().Uint32(), }}, nil } // CurrentEpoch returns the current epoch number. -func (s MeshService) CurrentEpoch(context.Context, *pb.CurrentEpochRequest) (*pb.CurrentEpochResponse, error) { +func (s *MeshService) CurrentEpoch(context.Context, *pb.CurrentEpochRequest) (*pb.CurrentEpochResponse, error) { curLayer := s.genTime.CurrentLayer() return &pb.CurrentEpochResponse{Epochnum: &pb.EpochNumber{ Number: curLayer.GetEpoch().Uint32(), @@ -99,26 +99,26 @@ func (s MeshService) CurrentEpoch(context.Context, *pb.CurrentEpochRequest) (*pb } // GenesisID returns the network ID. -func (s MeshService) GenesisID(context.Context, *pb.GenesisIDRequest) (*pb.GenesisIDResponse, error) { +func (s *MeshService) GenesisID(context.Context, *pb.GenesisIDRequest) (*pb.GenesisIDResponse, error) { return &pb.GenesisIDResponse{GenesisId: s.genesisID.Bytes()}, nil } // EpochNumLayers returns the number of layers per epoch (a network parameter). -func (s MeshService) EpochNumLayers(context.Context, *pb.EpochNumLayersRequest) (*pb.EpochNumLayersResponse, error) { +func (s *MeshService) EpochNumLayers(context.Context, *pb.EpochNumLayersRequest) (*pb.EpochNumLayersResponse, error) { return &pb.EpochNumLayersResponse{Numlayers: &pb.LayerNumber{ Number: s.layersPerEpoch, }}, nil } // LayerDuration returns the layer duration in seconds (a network parameter). -func (s MeshService) LayerDuration(context.Context, *pb.LayerDurationRequest) (*pb.LayerDurationResponse, error) { +func (s *MeshService) LayerDuration(context.Context, *pb.LayerDurationRequest) (*pb.LayerDurationResponse, error) { return &pb.LayerDurationResponse{Duration: &pb.SimpleInt{ Value: uint64(s.layerDuration.Seconds()), }}, nil } // MaxTransactionsPerSecond returns the max number of tx per sec (a network parameter). -func (s MeshService) MaxTransactionsPerSecond( +func (s *MeshService) MaxTransactionsPerSecond( context.Context, *pb.MaxTransactionsPerSecondRequest, ) (*pb.MaxTransactionsPerSecondResponse, error) { @@ -129,7 +129,7 @@ func (s MeshService) MaxTransactionsPerSecond( // QUERIES -func (s MeshService) getFilteredTransactions( +func (s *MeshService) getFilteredTransactions( from types.LayerID, address types.Address, ) ([]*types.MeshTransaction, error) { @@ -142,7 +142,7 @@ func (s MeshService) getFilteredTransactions( } // AccountMeshDataQuery returns account data. -func (s MeshService) AccountMeshDataQuery( +func (s *MeshService) AccountMeshDataQuery( ctx context.Context, in *pb.AccountMeshDataQueryRequest, ) (*pb.AccountMeshDataQueryResponse, error) { @@ -264,7 +264,7 @@ func convertActivation(a *types.ActivationTx) *pb.Activation { } } -func (s MeshService) readLayer( +func (s *MeshService) readLayer( ctx context.Context, layerID types.LayerID, layerStatus pb.Layer_LayerStatus, @@ -332,7 +332,7 @@ func (s MeshService) readLayer( } // LayersQuery returns all mesh data, layer by layer. -func (s MeshService) LayersQuery(ctx context.Context, in *pb.LayersQueryRequest) (*pb.LayersQueryResponse, error) { +func (s *MeshService) LayersQuery(ctx context.Context, in *pb.LayersQueryRequest) (*pb.LayersQueryResponse, error) { var startLayer, endLayer types.LayerID if in.StartLayer != nil { startLayer = types.LayerID(in.StartLayer.Number) @@ -383,7 +383,7 @@ func (s MeshService) LayersQuery(ctx context.Context, in *pb.LayersQueryRequest) // STREAMS // AccountMeshDataStream exposes a stream of transactions and activations for an account. -func (s MeshService) AccountMeshDataStream( +func (s *MeshService) AccountMeshDataStream( in *pb.AccountMeshDataStreamRequest, stream pb.MeshService_AccountMeshDataStreamServer, ) error { @@ -478,7 +478,7 @@ func (s MeshService) AccountMeshDataStream( } // LayerStream exposes a stream of all mesh data per layer. -func (s MeshService) LayerStream(_ *pb.LayerStreamRequest, stream pb.MeshService_LayerStreamServer) error { +func (s *MeshService) LayerStream(_ *pb.LayerStreamRequest, stream pb.MeshService_LayerStreamServer) error { var ( layerCh <-chan events.LayerUpdate layersBufFull <-chan struct{} @@ -528,7 +528,7 @@ func convertLayerStatus(in int) pb.Layer_LayerStatus { } } -func (s MeshService) EpochStream(req *pb.EpochStreamRequest, stream pb.MeshService_EpochStreamServer) error { +func (s *MeshService) EpochStream(req *pb.EpochStreamRequest, stream pb.MeshService_EpochStreamServer) error { epoch := types.EpochID(req.Epoch) var ( sendErr error @@ -565,7 +565,7 @@ func (s MeshService) EpochStream(req *pb.EpochStreamRequest, stream pb.MeshServi return nil } -func (s MeshService) MalfeasanceQuery( +func (s *MeshService) MalfeasanceQuery( ctx context.Context, req *pb.MalfeasanceRequest, ) (*pb.MalfeasanceResponse, error) { @@ -587,7 +587,7 @@ func (s MeshService) MalfeasanceQuery( }, nil } -func (s MeshService) MalfeasanceStream( +func (s *MeshService) MalfeasanceStream( req *pb.MalfeasanceStreamRequest, stream pb.MeshService_MalfeasanceStreamServer, ) error { diff --git a/api/grpcserver/mesh_service_test.go b/api/grpcserver/mesh_service_test.go index 6acb9465aa..82a8fbd087 100644 --- a/api/grpcserver/mesh_service_test.go +++ b/api/grpcserver/mesh_service_test.go @@ -157,9 +157,7 @@ func TestMeshService_MalfeasanceQuery(t *testing.T) { cfg, cleanup := launchServer(t, srv) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewMeshServiceClient(conn) nodeID, proof := BallotMalfeasance(t, db) @@ -212,7 +210,7 @@ func TestMeshService_MalfeasanceStream(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewMeshServiceClient(conn) for range 10 { diff --git a/api/grpcserver/node_service.go b/api/grpcserver/node_service.go index c3fb61e4c2..48261f5921 100644 --- a/api/grpcserver/node_service.go +++ b/api/grpcserver/node_service.go @@ -31,16 +31,16 @@ type NodeService struct { } // RegisterService registers this service with a grpc server instance. -func (s NodeService) RegisterService(server *grpc.Server) { +func (s *NodeService) RegisterService(server *grpc.Server) { pb.RegisterNodeServiceServer(server, s) } -func (s NodeService) RegisterHandlerService(mux *runtime.ServeMux) error { +func (s *NodeService) RegisterHandlerService(mux *runtime.ServeMux) error { return pb.RegisterNodeServiceHandlerServer(context.Background(), mux, s) } // String returns the name of this service. -func (s NodeService) String() string { +func (s *NodeService) String() string { return "NodeService" } @@ -64,7 +64,7 @@ func NewNodeService( } // Echo returns the response for an echo api request. It's used for E2E tests. -func (s NodeService) Echo(_ context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { +func (s *NodeService) Echo(_ context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { if in.Msg != nil { return &pb.EchoResponse{Msg: &pb.SimpleString{Value: in.Msg.Value}}, nil } @@ -72,14 +72,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, *emptypb.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, *emptypb.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 @@ -87,7 +87,7 @@ func (s NodeService) Build(context.Context, *emptypb.Empty) (*pb.BuildResponse, // Status returns a status object providing information about the connected peers, sync status, // current and verified layer. -func (s NodeService) Status(ctx context.Context, _ *pb.StatusRequest) (*pb.StatusResponse, error) { +func (s *NodeService) Status(ctx context.Context, _ *pb.StatusRequest) (*pb.StatusResponse, error) { curLayer, latestLayer, verifiedLayer := s.getLayers() return &pb.StatusResponse{ Status: &pb.NodeStatus{ @@ -100,7 +100,7 @@ func (s NodeService) Status(ctx context.Context, _ *pb.StatusRequest) (*pb.Statu }, nil } -func (s NodeService) NodeInfo(context.Context, *emptypb.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(), @@ -109,7 +109,7 @@ func (s NodeService) NodeInfo(context.Context, *emptypb.Empty) (*pb.NodeInfoResp }, nil } -func (s NodeService) getLayers() (curLayer, latestLayer, verifiedLayer uint32) { +func (s *NodeService) getLayers() (curLayer, latestLayer, verifiedLayer uint32) { // We cannot get meaningful data from the mesh during the genesis epochs since there are no blocks in these // epochs, so just return the current layer instead curLayerObj := s.genTime.CurrentLayer() @@ -127,7 +127,7 @@ func (s NodeService) getLayers() (curLayer, latestLayer, verifiedLayer uint32) { // STREAMS // StatusStream exposes a stream of node status updates. -func (s NodeService) StatusStream(_ *pb.StatusStreamRequest, stream pb.NodeService_StatusStreamServer) error { +func (s *NodeService) StatusStream(_ *pb.StatusStreamRequest, stream pb.NodeService_StatusStreamServer) error { var ( statusCh <-chan events.Status statusBufFull <-chan struct{} @@ -174,7 +174,7 @@ func (s NodeService) StatusStream(_ *pb.StatusStreamRequest, stream pb.NodeServi } // ErrorStream exposes a stream of node errors. -func (s NodeService) ErrorStream(_ *pb.ErrorStreamRequest, stream pb.NodeService_ErrorStreamServer) error { +func (s *NodeService) ErrorStream(_ *pb.ErrorStreamRequest, stream pb.NodeService_ErrorStreamServer) error { var ( errorsCh <-chan events.NodeError errorsBufFull <-chan struct{} diff --git a/api/grpcserver/node_service_test.go b/api/grpcserver/node_service_test.go index 57d0590bd2..6c0b2e6701 100644 --- a/api/grpcserver/node_service_test.go +++ b/api/grpcserver/node_service_test.go @@ -3,7 +3,6 @@ package grpcserver import ( "context" "testing" - "time" pb "github.com/spacemeshos/api/release/go/spacemesh/v1" "github.com/stretchr/testify/require" @@ -37,9 +36,7 @@ func setupNodeService(t *testing.T) (*nodeServiceConn, context.Context) { cfg, cleanup := launchServer(t, grpcService) t.Cleanup(cleanup) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewNodeServiceClient(conn) return &nodeServiceConn{ diff --git a/api/grpcserver/post_info_service_test.go b/api/grpcserver/post_info_service_test.go index fab31cab0c..04ea43d578 100644 --- a/api/grpcserver/post_info_service_test.go +++ b/api/grpcserver/post_info_service_test.go @@ -41,7 +41,7 @@ func TestPostInfoService(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewPostInfoServiceClient(conn) existingStates := map[types.IdentityDescriptor]types.PostState{ diff --git a/api/grpcserver/smesher_service.go b/api/grpcserver/smesher_service.go index c2815fb061..3a557f41b4 100644 --- a/api/grpcserver/smesher_service.go +++ b/api/grpcserver/smesher_service.go @@ -36,16 +36,16 @@ type SmesherService struct { } // RegisterService registers this service with a grpc server instance. -func (s SmesherService) RegisterService(server *grpc.Server) { +func (s *SmesherService) RegisterService(server *grpc.Server) { pb.RegisterSmesherServiceServer(server, s) } -func (s SmesherService) RegisterHandlerService(mux *runtime.ServeMux) error { +func (s *SmesherService) RegisterHandlerService(mux *runtime.ServeMux) error { return pb.RegisterSmesherServiceHandlerServer(context.Background(), mux, s) } // String returns the name of this service. -func (s SmesherService) String() string { +func (s *SmesherService) String() string { return "SmesherService" } @@ -74,7 +74,7 @@ func (s *SmesherService) SetPostServiceConfig(cfg activation.PostSupervisorConfi } // IsSmeshing reports whether the node is smeshing. -func (s SmesherService) IsSmeshing(context.Context, *emptypb.Empty) (*pb.IsSmeshingResponse, error) { +func (s *SmesherService) IsSmeshing(context.Context, *emptypb.Empty) (*pb.IsSmeshingResponse, error) { if s.sig == nil { return nil, status.Errorf(codes.FailedPrecondition, "node is not configured for supervised smeshing") } @@ -82,7 +82,7 @@ func (s SmesherService) IsSmeshing(context.Context, *emptypb.Empty) (*pb.IsSmesh } // StartSmeshing requests that the node begin smeshing. -func (s SmesherService) StartSmeshing( +func (s *SmesherService) StartSmeshing( ctx context.Context, in *pb.StartSmeshingRequest, ) (*pb.StartSmeshingResponse, error) { @@ -119,7 +119,7 @@ func (s SmesherService) StartSmeshing( }, nil } -func (s SmesherService) postSetupOpts(in *pb.PostSetupOpts) (activation.PostSetupOpts, error) { +func (s *SmesherService) postSetupOpts(in *pb.PostSetupOpts) (activation.PostSetupOpts, error) { if in == nil { return activation.PostSetupOpts{}, errors.New("`Opts` must be provided") } @@ -146,7 +146,7 @@ func (s SmesherService) postSetupOpts(in *pb.PostSetupOpts) (activation.PostSetu } // StopSmeshing requests that the node stop smeshing. -func (s SmesherService) StopSmeshing( +func (s *SmesherService) StopSmeshing( ctx context.Context, in *pb.StopSmeshingRequest, ) (*pb.StopSmeshingResponse, error) { @@ -164,11 +164,11 @@ func (s SmesherService) StopSmeshing( } // SmesherID returns the smesher ID of this node. -func (s SmesherService) SmesherID(context.Context, *emptypb.Empty) (*pb.SmesherIDResponse, error) { +func (s *SmesherService) SmesherID(context.Context, *emptypb.Empty) (*pb.SmesherIDResponse, error) { return nil, status.Errorf(codes.Unimplemented, "this endpoint has been deprecated, use `SmesherIDs` instead") } -func (s SmesherService) SmesherIDs(context.Context, *emptypb.Empty) (*pb.SmesherIDsResponse, error) { +func (s *SmesherService) SmesherIDs(context.Context, *emptypb.Empty) (*pb.SmesherIDsResponse, error) { ids := s.smeshingProvider.SmesherIDs() res := &pb.SmesherIDsResponse{} for _, id := range ids { @@ -178,12 +178,12 @@ func (s SmesherService) SmesherIDs(context.Context, *emptypb.Empty) (*pb.Smesher } // Coinbase returns the current coinbase setting of this node. -func (s SmesherService) Coinbase(context.Context, *emptypb.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 } // SetCoinbase sets the current coinbase setting of this node. -func (s SmesherService) SetCoinbase(_ context.Context, in *pb.SetCoinbaseRequest) (*pb.SetCoinbaseResponse, error) { +func (s *SmesherService) SetCoinbase(_ context.Context, in *pb.SetCoinbaseRequest) (*pb.SetCoinbaseResponse, error) { if in.Id == nil { return nil, status.Errorf(codes.InvalidArgument, "`Id` must be provided") } @@ -200,17 +200,17 @@ func (s SmesherService) SetCoinbase(_ context.Context, in *pb.SetCoinbaseRequest } // MinGas returns the current mingas setting of this node. -func (s SmesherService) MinGas(context.Context, *emptypb.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") } // SetMinGas sets the mingas setting of this node. -func (s SmesherService) SetMinGas(context.Context, *pb.SetMinGasRequest) (*pb.SetMinGasResponse, error) { +func (s *SmesherService) SetMinGas(context.Context, *pb.SetMinGasRequest) (*pb.SetMinGasResponse, error) { return nil, status.Errorf(codes.Unimplemented, "this endpoint is not implemented") } // EstimatedRewards returns estimated smeshing rewards over the next epoch. -func (s SmesherService) EstimatedRewards( +func (s *SmesherService) EstimatedRewards( context.Context, *pb.EstimatedRewardsRequest, ) (*pb.EstimatedRewardsResponse, error) { @@ -218,13 +218,13 @@ func (s SmesherService) EstimatedRewards( } // PostSetupStatus returns post data status. -func (s SmesherService) PostSetupStatus(ctx context.Context, _ *emptypb.Empty) (*pb.PostSetupStatusResponse, error) { +func (s *SmesherService) PostSetupStatus(ctx context.Context, _ *emptypb.Empty) (*pb.PostSetupStatusResponse, error) { status := s.postSupervisor.Status() return &pb.PostSetupStatusResponse{Status: statusToPbStatus(status)}, nil } // PostSetupStatusStream exposes a stream of status updates during post setup. -func (s SmesherService) PostSetupStatusStream( +func (s *SmesherService) PostSetupStatusStream( _ *emptypb.Empty, stream pb.SmesherService_PostSetupStatusStreamServer, ) error { @@ -244,8 +244,8 @@ func (s SmesherService) PostSetupStatusStream( } } -// PostSetupComputeProviders returns a list of available Post setup compute providers. -func (s SmesherService) PostSetupProviders( +// PostSetupProviders returns a list of available Post setup compute providers. +func (s *SmesherService) PostSetupProviders( ctx context.Context, in *pb.PostSetupProvidersRequest, ) (*pb.PostSetupProvidersResponse, error) { @@ -279,7 +279,7 @@ func (s SmesherService) PostSetupProviders( } // PostConfig returns the Post protocol config. -func (s SmesherService) PostConfig(context.Context, *emptypb.Empty) (*pb.PostConfigResponse, error) { +func (s *SmesherService) PostConfig(context.Context, *emptypb.Empty) (*pb.PostConfigResponse, error) { cfg := s.postSupervisor.Config() return &pb.PostConfigResponse{ @@ -302,7 +302,7 @@ func statusToPbStatus(status *activation.PostSetupStatus) *pb.PostSetupStatus { var providerID *uint32 if status.LastOpts.ProviderID.Value() != nil { providerID = new(uint32) - *providerID = uint32(*status.LastOpts.ProviderID.Value()) + *providerID = *status.LastOpts.ProviderID.Value() } pbStatus.Opts = &pb.PostSetupOpts{ diff --git a/api/grpcserver/transaction_service.go b/api/grpcserver/transaction_service.go index a0713b3b8c..ba0eea8cfe 100644 --- a/api/grpcserver/transaction_service.go +++ b/api/grpcserver/transaction_service.go @@ -37,16 +37,16 @@ type TransactionService struct { } // RegisterService registers this service with a grpc server instance. -func (s TransactionService) RegisterService(server *grpc.Server) { +func (s *TransactionService) RegisterService(server *grpc.Server) { pb.RegisterTransactionServiceServer(server, s) } -func (s TransactionService) RegisterHandlerService(mux *runtime.ServeMux) error { +func (s *TransactionService) RegisterHandlerService(mux *runtime.ServeMux) error { return pb.RegisterTransactionServiceHandlerServer(context.Background(), mux, s) } // String returns the name of this service. -func (s TransactionService) String() string { +func (s *TransactionService) String() string { return "TransactionService" } @@ -69,7 +69,7 @@ func NewTransactionService( } } -func (s TransactionService) ParseTransaction( +func (s *TransactionService) ParseTransaction( ctx context.Context, in *pb.ParseTransactionRequest, ) (*pb.ParseTransactionResponse, error) { @@ -94,7 +94,7 @@ func (s TransactionService) ParseTransaction( } // SubmitTransaction allows a new tx to be submitted. -func (s TransactionService) SubmitTransaction( +func (s *TransactionService) SubmitTransaction( ctx context.Context, in *pb.SubmitTransactionRequest, ) (*pb.SubmitTransactionResponse, error) { @@ -129,7 +129,7 @@ func (s TransactionService) SubmitTransaction( // Get transaction and status for a given txid. It's not an error if we cannot find the tx, // we just return all nils. -func (s TransactionService) getTransactionAndStatus( +func (s *TransactionService) getTransactionAndStatus( txID types.TransactionID, ) (*types.Transaction, pb.TransactionState_TransactionState) { var state pb.TransactionState_TransactionState @@ -149,7 +149,7 @@ func (s TransactionService) getTransactionAndStatus( } // TransactionsState returns current tx data for one or more txs. -func (s TransactionService) TransactionsState( +func (s *TransactionService) TransactionsState( _ context.Context, in *pb.TransactionsStateRequest, ) (*pb.TransactionsStateResponse, error) { @@ -186,7 +186,7 @@ func (s TransactionService) TransactionsState( // STREAMS // TransactionsStateStream exposes a stream of tx data. -func (s TransactionService) TransactionsStateStream( +func (s *TransactionService) TransactionsStateStream( in *pb.TransactionsStateStreamRequest, stream pb.TransactionService_TransactionsStateStreamServer, ) error { @@ -338,7 +338,7 @@ func (s TransactionService) TransactionsStateStream( } // StreamResults allows to query historical results and subscribe to live data using the same filter. -func (s TransactionService) StreamResults( +func (s *TransactionService) StreamResults( in *pb.TransactionResultsRequest, stream pb.TransactionService_StreamResultsServer, ) error { diff --git a/api/grpcserver/transaction_service_test.go b/api/grpcserver/transaction_service_test.go index 343e30ed58..7fe12a9e34 100644 --- a/api/grpcserver/transaction_service_test.go +++ b/api/grpcserver/transaction_service_test.go @@ -51,7 +51,7 @@ func TestTransactionService_StreamResults(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := pb.NewTransactionServiceClient(conn) t.Run("All", func(t *testing.T) { @@ -166,7 +166,7 @@ func BenchmarkStreamResults(b *testing.B) { cfg, cleanup := launchServer(b, svc) b.Cleanup(cleanup) - conn := dialGrpc(ctx, b, cfg) + conn := dialGrpc(b, cfg) client := pb.NewTransactionServiceClient(conn) b.Logf("setup took %s", time.Since(start)) @@ -217,13 +217,12 @@ func parseOk() parseExpectation { func TestParseTransactions(t *testing.T) { db := sql.InMemory() - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - t.Cleanup(cancel) + vminst := vm.New(db) cfg, cleanup := launchServer(t, NewTransactionService(db, nil, nil, txs.NewConservativeState(vminst, db), nil, nil)) t.Cleanup(cleanup) var ( - conn = dialGrpc(ctx, t, cfg) + conn = dialGrpc(t, cfg) client = pb.NewTransactionServiceClient(conn) keys = make([]signing.PrivateKey, 4) accounts = make([]types.Account, len(keys)) @@ -232,7 +231,7 @@ func TestParseTransactions(t *testing.T) { for i := range keys { pub, priv, err := ed25519.GenerateKey(rng) require.NoError(t, err) - keys[i] = signing.PrivateKey(priv) + keys[i] = priv accounts[i] = types.Account{Address: wallet.Address(pub), Balance: 1e12} } require.NoError(t, vminst.ApplyGenesis(accounts)) diff --git a/api/grpcserver/v2alpha1/account.go b/api/grpcserver/v2alpha1/account.go index ee57ce6506..3bc9a30493 100644 --- a/api/grpcserver/v2alpha1/account.go +++ b/api/grpcserver/v2alpha1/account.go @@ -49,7 +49,7 @@ func (s *AccountService) String() string { } func (s *AccountService) List( - ctx context.Context, + _ context.Context, request *spacemeshv2alpha1.AccountRequest, ) (*spacemeshv2alpha1.AccountList, error) { switch { diff --git a/api/grpcserver/v2alpha1/account_test.go b/api/grpcserver/v2alpha1/account_test.go index 3d8684d5bc..a61d1c6fe0 100644 --- a/api/grpcserver/v2alpha1/account_test.go +++ b/api/grpcserver/v2alpha1/account_test.go @@ -66,7 +66,7 @@ func TestAccountService_List(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewAccountServiceClient(conn) t.Run("limit set too high", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/activation_test.go b/api/grpcserver/v2alpha1/activation_test.go index 70b97330fe..183bd11c8b 100644 --- a/api/grpcserver/v2alpha1/activation_test.go +++ b/api/grpcserver/v2alpha1/activation_test.go @@ -37,7 +37,7 @@ func TestActivationService_List(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewActivationServiceClient(conn) t.Run("limit set too high", func(t *testing.T) { @@ -120,7 +120,7 @@ func TestActivationStreamService_Stream(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewActivationStreamServiceClient(conn) t.Run("all", func(t *testing.T) { @@ -240,7 +240,7 @@ func TestActivationService_ActivationsCount(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewActivationServiceClient(conn) t.Run("count without filter", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/layer_test.go b/api/grpcserver/v2alpha1/layer_test.go index bfc082b068..59af523ea9 100644 --- a/api/grpcserver/v2alpha1/layer_test.go +++ b/api/grpcserver/v2alpha1/layer_test.go @@ -40,7 +40,7 @@ func TestLayerService_List(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewLayerServiceClient(conn) t.Run("limit set too high", func(t *testing.T) { @@ -116,7 +116,7 @@ func TestLayerStreamService_Stream(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewLayerStreamServiceClient(conn) t.Run("all", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/network_test.go b/api/grpcserver/v2alpha1/network_test.go index c0119ace71..989ab92a1e 100644 --- a/api/grpcserver/v2alpha1/network_test.go +++ b/api/grpcserver/v2alpha1/network_test.go @@ -19,7 +19,7 @@ func TestNetworkService_Info(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewNetworkServiceClient(conn) t.Run("network info", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/node_test.go b/api/grpcserver/v2alpha1/node_test.go index 10b93b0fb0..4ff5a85c27 100644 --- a/api/grpcserver/v2alpha1/node_test.go +++ b/api/grpcserver/v2alpha1/node_test.go @@ -31,7 +31,7 @@ func TestNodeService_Status(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewNodeServiceClient(conn) t.Run("node status", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/reward.go b/api/grpcserver/v2alpha1/reward.go index d6f3b88a03..ea54c66cb7 100644 --- a/api/grpcserver/v2alpha1/reward.go +++ b/api/grpcserver/v2alpha1/reward.go @@ -165,7 +165,7 @@ func (s *RewardService) String() string { } func (s *RewardService) List( - ctx context.Context, + _ context.Context, request *spacemeshv2alpha1.RewardRequest, ) (*spacemeshv2alpha1.RewardList, error) { ops, err := toRewardOperations(request) diff --git a/api/grpcserver/v2alpha1/reward_test.go b/api/grpcserver/v2alpha1/reward_test.go index 50952097d1..d0afdda5be 100644 --- a/api/grpcserver/v2alpha1/reward_test.go +++ b/api/grpcserver/v2alpha1/reward_test.go @@ -35,7 +35,7 @@ func TestRewardService_List(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewRewardServiceClient(conn) t.Run("limit set too high", func(t *testing.T) { @@ -118,7 +118,7 @@ func TestRewardStreamService_Stream(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewRewardStreamServiceClient(conn) t.Run("all", func(t *testing.T) { diff --git a/api/grpcserver/v2alpha1/transaction_test.go b/api/grpcserver/v2alpha1/transaction_test.go index 3128b470d5..4929015b0c 100644 --- a/api/grpcserver/v2alpha1/transaction_test.go +++ b/api/grpcserver/v2alpha1/transaction_test.go @@ -57,7 +57,7 @@ func TestTransactionService_List(t *testing.T) { cfg, cleanup := launchServer(t, svc) t.Cleanup(cleanup) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewTransactionServiceClient(conn) t.Run("limit set too high", func(t *testing.T) { @@ -200,7 +200,7 @@ func TestTransactionService_EstimateGas(t *testing.T) { []types.Transaction{{RawTx: types.NewRawTx(wallet.SelfSpawn(keys[0], 0))}}, nil) require.NoError(t, err) - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewTransactionServiceClient(conn) t.Run("valid tx", func(t *testing.T) { @@ -266,7 +266,7 @@ func TestTransactionService_ParseTransaction(t *testing.T) { mangled := wallet.Spend(keys[0], accounts[3].Address, 100, 0) mangled[len(mangled)-1] -= 1 - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) client := spacemeshv2alpha1.NewTransactionServiceClient(conn) t.Run("valid tx", func(t *testing.T) { @@ -363,7 +363,7 @@ func TestTransactionServiceSubmitUnsync(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := spacemeshv2alpha1.NewTransactionServiceClient(conn) signer, err := signing.NewEdSigner() @@ -406,7 +406,7 @@ func TestTransactionServiceSubmitInvalidTx(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := spacemeshv2alpha1.NewTransactionServiceClient(conn) signer, err := signing.NewEdSigner() @@ -443,7 +443,7 @@ func TestTransactionService_SubmitNoConcurrency(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - conn := dialGrpc(ctx, t, cfg) + conn := dialGrpc(t, cfg) c := spacemeshv2alpha1.NewTransactionServiceClient(conn) signer, err := signing.NewEdSigner() diff --git a/api/grpcserver/v2alpha1/v2alpha1_test.go b/api/grpcserver/v2alpha1/v2alpha1_test.go index 0be2834f50..27d5d9f7ac 100644 --- a/api/grpcserver/v2alpha1/v2alpha1_test.go +++ b/api/grpcserver/v2alpha1/v2alpha1_test.go @@ -1,7 +1,6 @@ package v2alpha1 import ( - "context" "testing" "time" @@ -36,7 +35,7 @@ func launchServer(tb testing.TB, services ...grpcserver.ServiceAPI) (grpcserver. return cfg, func() { assert.NoError(tb, grpc.Close()) } } -func dialGrpc(ctx context.Context, tb testing.TB, cfg grpcserver.Config) *grpc.ClientConn { +func dialGrpc(tb testing.TB, cfg grpcserver.Config) *grpc.ClientConn { tb.Helper() conn, err := grpc.NewClient( cfg.PublicListener, diff --git a/cmd/bootstrapper/generator_test.go b/cmd/bootstrapper/generator_test.go index d84cf2a288..346e57209d 100644 --- a/cmd/bootstrapper/generator_test.go +++ b/cmd/bootstrapper/generator_test.go @@ -71,7 +71,7 @@ func launchServer(tb testing.TB, cdb *datastore.CachedDB) (grpcserver.Config, fu // start gRPC and json servers err := grpcService.Start() require.NoError(tb, err) - err = jsonService.StartService(context.Background(), s) + err = jsonService.StartService(s) require.NoError(tb, err) // update config with bound addresses diff --git a/node/node.go b/node/node.go index 969e7c21d2..8581a92307 100644 --- a/node/node.go +++ b/node/node.go @@ -1760,7 +1760,7 @@ func (app *App) startAPIServices(ctx context.Context) error { app.Config.CollectMetrics, ) - if err := app.jsonAPIServer.StartService(ctx, maps.Values(publicSvcs)...); err != nil { + if err := app.jsonAPIServer.StartService(maps.Values(publicSvcs)...); err != nil { return fmt.Errorf("start listen server: %w", err) } logger.With().Info("json listener started",