diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index 525954716..9802d8c19 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -75,7 +75,32 @@ func NewDispersalServerV2( onchainStateRefreshInterval time.Duration, _logger logging.Logger, registry *prometheus.Registry, -) *DispersalServerV2 { +) (*DispersalServerV2, error) { + if serverConfig.GrpcPort == "" { + return nil, errors.New("grpc port is required") + } + if blobStore == nil { + return nil, errors.New("blob store is required") + } + if blobMetadataStore == nil { + return nil, errors.New("blob metadata store is required") + } + if chainReader == nil { + return nil, errors.New("chain reader is required") + } + if authenticator == nil { + return nil, errors.New("authenticator is required") + } + if prover == nil { + return nil, errors.New("prover is required") + } + if maxNumSymbolsPerBlob == 0 { + return nil, errors.New("maxNumSymbolsPerBlob is required") + } + if _logger == nil { + return nil, errors.New("logger is required") + } + logger := _logger.With("component", "DispersalServerV2") return &DispersalServerV2{ @@ -93,7 +118,7 @@ func NewDispersalServerV2( onchainStateRefreshInterval: onchainStateRefreshInterval, metrics: newAPIServerV2Metrics(registry), - } + }, nil } func (s *DispersalServerV2) Start(ctx context.Context) error { @@ -233,6 +258,9 @@ func (s *DispersalServerV2) RefreshOnchainState(ctx context.Context) error { } func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaymentStateRequest) (*pb.GetPaymentStateReply, error) { + if s.meterer == nil { + return nil, errors.New("payment meterer is not enabled") + } start := time.Now() defer func() { s.metrics.reportGetPaymentStateLatency(time.Since(start)) diff --git a/disperser/apiserver/server_v2_test.go b/disperser/apiserver/server_v2_test.go index 56ce0f970..a5decc958 100644 --- a/disperser/apiserver/server_v2_test.go +++ b/disperser/apiserver/server_v2_test.go @@ -498,7 +498,7 @@ func newTestServerV2(t *testing.T) *testComponents { }, }, nil) - s := apiserver.NewDispersalServerV2( + s, err := apiserver.NewDispersalServerV2( disperser.ServerConfig{ GrpcPort: "51002", GrpcTimeout: 1 * time.Second, @@ -513,6 +513,7 @@ func newTestServerV2(t *testing.T) *testComponents { time.Hour, logger, prometheus.NewRegistry()) + assert.NoError(t, err) err = s.RefreshOnchainState(context.Background()) assert.NoError(t, err) diff --git a/disperser/cmd/apiserver/main.go b/disperser/cmd/apiserver/main.go index 1b1d98590..2659f0c87 100644 --- a/disperser/cmd/apiserver/main.go +++ b/disperser/cmd/apiserver/main.go @@ -170,7 +170,7 @@ func RunDisperserServer(ctx *cli.Context) error { blobMetadataStore := blobstorev2.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName) blobStore := blobstorev2.NewBlobStore(bucketName, s3Client, logger) - server := apiserver.NewDispersalServerV2( + server, err := apiserver.NewDispersalServerV2( config.ServerConfig, blobStore, blobMetadataStore, @@ -183,6 +183,9 @@ func RunDisperserServer(ctx *cli.Context) error { logger, reg, ) + if err != nil { + return err + } return server.Start(context.Background()) }