Skip to content

Commit

Permalink
nil checks in disperser v2 server constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Dec 17, 2024
1 parent b679a14 commit 09f47ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
32 changes: 30 additions & 2 deletions disperser/apiserver/server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,35 @@ 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 meterer == nil {
return nil, errors.New("meterer 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{
Expand All @@ -92,7 +120,7 @@ func NewDispersalServerV2(
onchainStateRefreshInterval: onchainStateRefreshInterval,

metrics: newAPIServerV2Metrics(registry),
}
}, nil
}

func (s *DispersalServerV2) Start(ctx context.Context) error {
Expand Down
3 changes: 2 additions & 1 deletion disperser/apiserver/server_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func newTestServerV2(t *testing.T) *testComponents {
},
}, nil)

s := apiserver.NewDispersalServerV2(
s, err := apiserver.NewDispersalServerV2(
disperser.ServerConfig{
GrpcPort: "51002",
GrpcTimeout: 1 * time.Second,
Expand All @@ -512,6 +512,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)
Expand Down
5 changes: 4 additions & 1 deletion disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -183,6 +183,9 @@ func RunDisperserServer(ctx *cli.Context) error {
logger,
reg,
)
if err != nil {
return err
}
return server.Start(context.Background())
}

Expand Down

0 comments on commit 09f47ba

Please sign in to comment.