Skip to content

Commit

Permalink
Single DataAPI serving both v1 + v2 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork committed Dec 19, 2024
1 parent aba75de commit 9edd9ea
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 772 deletions.
28 changes: 16 additions & 12 deletions disperser/cmd/dataapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
)

type Config struct {
ServerVersion uint
AwsClientConfig aws.ClientConfig
BlobstoreConfig blobstore.Config
EthClientConfig geth.EthClientConfig
LoggerConfig common.LoggerConfig
PrometheusConfig prometheus.Config
MetricsConfig dataapi.MetricsConfig
ChainStateConfig thegraph.Config
ServerVersion uint
AwsClientConfig aws.ClientConfig
BlobstoreConfig blobstore.Config
BlobstoreV2Config blobstore.Config
EthClientConfig geth.EthClientConfig
LoggerConfig common.LoggerConfig
PrometheusConfig prometheus.Config
MetricsConfig dataapi.MetricsConfig
ChainStateConfig thegraph.Config

SocketAddr string
PrometheusApiAddr string
Expand All @@ -37,6 +38,8 @@ type Config struct {
DisperserHostname string
ChurnerHostname string
BatcherHealthEndpt string

BlobMetadataV2TableName string
}

func NewConfig(ctx *cli.Context) (Config, error) {
Expand Down Expand Up @@ -77,10 +80,11 @@ func NewConfig(ctx *cli.Context) (Config, error) {
HTTPPort: ctx.GlobalString(flags.MetricsHTTPPort.Name),
EnableMetrics: ctx.GlobalBool(flags.EnableMetricsFlag.Name),
},
DisperserHostname: ctx.GlobalString(flags.DisperserHostnameFlag.Name),
ChurnerHostname: ctx.GlobalString(flags.ChurnerHostnameFlag.Name),
BatcherHealthEndpt: ctx.GlobalString(flags.BatcherHealthEndptFlag.Name),
ChainStateConfig: thegraph.ReadCLIConfig(ctx),
DisperserHostname: ctx.GlobalString(flags.DisperserHostnameFlag.Name),
ChurnerHostname: ctx.GlobalString(flags.ChurnerHostnameFlag.Name),
BatcherHealthEndpt: ctx.GlobalString(flags.BatcherHealthEndptFlag.Name),
ChainStateConfig: thegraph.ReadCLIConfig(ctx),
BlobMetadataV2TableName: ctx.GlobalString(flags.DynamoV2TableNameFlag.Name),
}
return config, nil
}
7 changes: 7 additions & 0 deletions disperser/cmd/dataapi/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ var (
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "DYNAMO_TABLE_NAME"),
}
DynamoV2TableNameFlag = cli.StringFlag{
Name: common.PrefixFlag(FlagPrefix, "dynamo-v2-table-name"),
Usage: "Name of the dynamo table to store v2 blob metadata",
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "DYNAMO_V2_TABLE_NAME"),
}
S3BucketNameFlag = cli.StringFlag{
Name: common.PrefixFlag(FlagPrefix, "s3-bucket-name"),
Usage: "Name of the bucket to store blobs",
Expand Down Expand Up @@ -143,6 +149,7 @@ var (

var requiredFlags = []cli.Flag{
DynamoTableNameFlag,
DynamoV2TableNameFlag,
SocketAddrFlag,
S3BucketNameFlag,
SubgraphApiBatchMetadataAddrFlag,
Expand Down
43 changes: 11 additions & 32 deletions disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ func RunDataApi(ctx *cli.Context) error {
}

var (
promClient = dataapi.NewPrometheusClient(promApi, config.PrometheusConfig.Cluster)
blobMetadataStore = blobstore.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName, 0)
sharedStorage = blobstore.NewSharedStorage(config.BlobstoreConfig.BucketName, s3Client, blobMetadataStore, logger)
subgraphApi = subgraph.NewApi(config.SubgraphApiBatchMetadataAddr, config.SubgraphApiOperatorStateAddr)
subgraphClient = dataapi.NewSubgraphClient(subgraphApi, logger)
chainState = coreeth.NewChainState(tx, client)
indexedChainState = thegraph.MakeIndexedChainState(config.ChainStateConfig, chainState, logger)
metrics = dataapi.NewMetrics(blobMetadataStore, config.MetricsConfig.HTTPPort, logger)
server = dataapi.NewServer(
promClient = dataapi.NewPrometheusClient(promApi, config.PrometheusConfig.Cluster)
blobMetadataStore = blobstore.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName, 0)
blobMetadataStoreV2 = blobstorev2.NewBlobMetadataStore(dynamoClient, logger, config.BlobMetadataV2TableName)
sharedStorage = blobstore.NewSharedStorage(config.BlobstoreConfig.BucketName, s3Client, blobMetadataStore, logger)
subgraphApi = subgraph.NewApi(config.SubgraphApiBatchMetadataAddr, config.SubgraphApiOperatorStateAddr)
subgraphClient = dataapi.NewSubgraphClient(subgraphApi, logger)
chainState = coreeth.NewChainState(tx, client)
indexedChainState = thegraph.MakeIndexedChainState(config.ChainStateConfig, chainState, logger)
metrics = dataapi.NewMetrics(blobMetadataStore, config.MetricsConfig.HTTPPort, logger)
server = dataapi.NewServer(
dataapi.Config{
ServerMode: config.ServerMode,
SocketAddr: config.SocketAddr,
Expand All @@ -119,6 +120,7 @@ func RunDataApi(ctx *cli.Context) error {
nil,
nil,
nil,
blobMetadataStoreV2,
)
)

Expand All @@ -129,29 +131,6 @@ func RunDataApi(ctx *cli.Context) error {
logger.Info("Enabled metrics for Data Access API", "socket", httpSocket)
}

if config.ServerVersion == 2 {
blobMetadataStorev2 := blobstorev2.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName)
serverv2 := dataapi.NewServerV2(
dataapi.Config{
ServerMode: config.ServerMode,
SocketAddr: config.SocketAddr,
AllowOrigins: config.AllowOrigins,
DisperserHostname: config.DisperserHostname,
ChurnerHostname: config.ChurnerHostname,
BatcherHealthEndpt: config.BatcherHealthEndpt,
},
blobMetadataStorev2,
promClient,
subgraphClient,
tx,
chainState,
indexedChainState,
logger,
metrics,
)
return runServer(serverv2, logger)
}

return runServer(server, logger)
}

Expand Down
Loading

0 comments on commit 9edd9ea

Please sign in to comment.