Skip to content

Commit

Permalink
Auto-enable metadata API (#446)
Browse files Browse the repository at this point in the history
Remove the option to start the metadata API.

Automatically start it if the replication API is enabled.
  • Loading branch information
mkysel authored Jan 31, 2025
1 parent ce3e7c7 commit c47fcf5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
1 change: 0 additions & 1 deletion dev/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export XMTPD_PAYER_ENABLE=true
export XMTPD_REPLICATION_ENABLE=true
export XMTPD_SYNC_ENABLE=true
export XMTPD_INDEXER_ENABLE=true
export XMTPD_METADATA_ENABLE=true

go run -ldflags="-X main.Version=$(git describe HEAD --tags --long)" cmd/replication/main.go "$@"
5 changes: 0 additions & 5 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ type SyncOptions struct {
Enable bool `long:"enable" env:"XMTPD_SYNC_ENABLE" description:"Enable the sync server"`
}

type MetadataOptions struct {
Enable bool `long:"enable" env:"XMTPD_METADATA_ENABLE" description:"Enable the metadata API"`
}

type MlsValidationOptions struct {
GrpcAddress string `long:"grpc-address" env:"XMTPD_MLS_VALIDATION_GRPC_ADDRESS" description:"Address of the MLS validation service"`
}
Expand Down Expand Up @@ -84,7 +80,6 @@ type ServerOptions struct {
DB DbOptions `group:"Database Options" namespace:"db"`
Log LogOptions `group:"Log Options" namespace:"log"`
Indexer IndexerOptions `group:"Indexer Options" namespace:"indexer"`
Metadata MetadataOptions `group:"Metadata Options" namespace:"metadata"`
Metrics MetricsOptions `group:"Metrics Options" namespace:"metrics"`
MlsValidation MlsValidationOptions `group:"MLS Validation Options" namespace:"mls-validation"`
Payer PayerOptions `group:"Payer Options" namespace:"payer"`
Expand Down
6 changes: 0 additions & 6 deletions pkg/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ func ValidateServerOptions(options ServerOptions) error {
}
}

if options.Metadata.Enable {
if options.DB.WriterConnectionString == "" {
missingSet["--DB.WriterConnectionString"] = struct{}{}
}
}

if options.Indexer.Enable {
if options.DB.WriterConnectionString == "" {
missingSet["--DB.WriterConnectionString"] = struct{}{}
Expand Down
33 changes: 15 additions & 18 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package server
import (
"context"
"database/sql"
"github.com/xmtp/xmtpd/pkg/api/metadata"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/metadata_api"
"net"
"os"
"os/signal"
Expand All @@ -16,7 +18,6 @@ import (

"github.com/xmtp/xmtpd/pkg/api"
"github.com/xmtp/xmtpd/pkg/api/message"
"github.com/xmtp/xmtpd/pkg/api/metadata"
"github.com/xmtp/xmtpd/pkg/api/payer"
"github.com/xmtp/xmtpd/pkg/authn"
"github.com/xmtp/xmtpd/pkg/blockchain"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/xmtp/xmtpd/pkg/metrics"
"github.com/xmtp/xmtpd/pkg/mlsvalidate"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/message_api"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/metadata_api"
"github.com/xmtp/xmtpd/pkg/proto/xmtpv4/payer_api"
"github.com/xmtp/xmtpd/pkg/registrant"
"github.com/xmtp/xmtpd/pkg/registry"
Expand Down Expand Up @@ -126,7 +126,7 @@ func NewReplicationServer(
log.Info("Indexer service enabled")
}

if options.Payer.Enable || options.Replication.Enable || options.Metadata.Enable {
if options.Payer.Enable || options.Replication.Enable {
err = startAPIServer(
s.ctx,
log,
Expand Down Expand Up @@ -197,6 +197,18 @@ func startAPIServer(
message_api.RegisterReplicationApiServer(grpcServer, replicationService)

log.Info("Replication service enabled")

metadataService, err := metadata.NewMetadataApiService(
ctx,
log,
writerDB,
)
if err != nil {
return err
}
metadata_api.RegisterMetadataApiServer(grpcServer, metadataService)

log.Info("Metadata service enabled")
}

if options.Payer.Enable {
Expand All @@ -219,21 +231,6 @@ func startAPIServer(
log.Info("Payer service enabled")
}

if options.Metadata.Enable {

metadataService, err := metadata.NewMetadataApiService(
ctx,
log,
writerDB,
)
if err != nil {
return err
}
metadata_api.RegisterMetadataApiServer(grpcServer, metadataService)

log.Info("Metadata service enabled")
}

return nil
}

Expand Down

0 comments on commit c47fcf5

Please sign in to comment.