Skip to content

Commit

Permalink
Remove notional cache from the api component (#500)
Browse files Browse the repository at this point in the history
### Summary

The `api` component was importing and initializing the notional cache, but not using it.

This pull request removes the unnecessary dependency.
  • Loading branch information
agodnic committed Jul 5, 2023
1 parent 9e4aa45 commit 4ce2d1e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@
"type": "string"
},
"emitterNativeAddress": {
"description": "EmitterNativeAddress contains the VAA's emitter address in the emitter chain's native format.",
"description": "EmitterNativeAddress contains the VAA's emitter address, encoded in the emitter chain's native format.",
"type": "string"
},
"id": {
Expand Down
4 changes: 2 additions & 2 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ definitions:
hex.
type: string
emitterNativeAddress:
description: EmitterNativeAddress contains the VAA's emitter address in the
emitter chain's native format.
description: EmitterNativeAddress contains the VAA's emitter address, encoded
in the emitter chain's native format.
type: string
id:
type: string
Expand Down
2 changes: 0 additions & 2 deletions api/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type AppConfig struct {
}
Cache struct {
URL string
Channel string
TvlKey string
TvlExpiration int
Enabled bool
Expand Down Expand Up @@ -71,7 +70,6 @@ func defaulConfig() *AppConfig {
return &AppConfig{
Cache: struct {
URL string
Channel string
TvlKey string
TvlExpiration int
Enabled bool
Expand Down
29 changes: 14 additions & 15 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan"
rpcApi "github.com/wormhole-foundation/wormhole-explorer/api/rpc"
wormscanCache "github.com/wormhole-foundation/wormhole-explorer/common/client/cache"
wormscanNotionalCache "github.com/wormhole-foundation/wormhole-explorer/common/client/cache/notional"
xlogger "github.com/wormhole-foundation/wormhole-explorer/common/logger"
"github.com/wormhole-foundation/wormhole-explorer/common/utils"
"go.uber.org/zap"
Expand Down Expand Up @@ -106,13 +105,16 @@ func main() {
rootLogger.Info("connecting to MongoDB")
cli, err := db.Connect(appCtx, cfg.DB.URL)
if err != nil {
panic(err)
rootLogger.Fatal("failed to connect to MongoDB", zap.Error(err))
}
db := cli.Database(cfg.DB.Name)

// Get cache get function
rootLogger.Info("initializing notional cache")
cache, notionalCache := NewCache(appCtx, cfg, rootLogger)
rootLogger.Info("initializing cache")
cache, err := NewCache(appCtx, cfg, rootLogger)
if err != nil {
rootLogger.Fatal("failed to initialize cache", zap.Error(err))
}

// cfg.Cache.Expiration
rootLogger.Info("initializing TVL cache")
Expand Down Expand Up @@ -219,33 +221,30 @@ func main() {
rootLogger.Info("cleanup tasks...")
rootLogger.Info("shutting down server...")
app.Shutdown()
rootLogger.Info("closing notional cache...")
notionalCache.Close()
rootLogger.Info("closing cache...")
cache.Close()
rootLogger.Info("terminated API service successfully")
}

// NewCache get a CacheGetFunc to get a value by a Key from cache and a CacheReadable to get a value by a Key from notional local cache.
func NewCache(ctx context.Context, cfg *config.AppConfig, logger *zap.Logger) (wormscanCache.Cache, wormscanNotionalCache.NotionalLocalCacheReadable) {
func NewCache(ctx context.Context, cfg *config.AppConfig, logger *zap.Logger) (wormscanCache.Cache, error) {

// if run mode is development with cache is disabled, return a dummy cache client and a dummy notional cache client.
if cfg.RunMode == config.RunModeDevelopmernt && !cfg.Cache.Enabled {
dummyCacheClient := wormscanCache.NewDummyCacheClient()
dummyNotionalCache := wormscanNotionalCache.NewDummyNotionalCache()
return dummyCacheClient, dummyNotionalCache
return dummyCacheClient, nil
}

// if we are not in development mode, use a distributed cache and for notional a pubsub to sync local cache.
redisClient := redis.NewClient(&redis.Options{Addr: cfg.Cache.URL})

// get cache client
cacheClient, _ := wormscanCache.NewCacheClient(redisClient, cfg.Cache.Enabled, cfg.Cache.Prefix, logger)

// get notional cache client and init load to local cache
notionalCache, _ := wormscanNotionalCache.NewNotionalCache(ctx, redisClient, cfg.Cache.Prefix, cfg.Cache.Channel, logger)
notionalCache.Init(ctx)
cacheClient, err := wormscanCache.NewCacheClient(redisClient, cfg.Cache.Enabled, cfg.Cache.Prefix, logger)
if err != nil {
return nil, fmt.Errorf("failed to initialize cache client: %w", err)
}

return cacheClient, notionalCache
return cacheClient, nil
}

func newInfluxClient(url, token string) influxdb2.Client {
Expand Down
2 changes: 0 additions & 2 deletions deploy/api/api-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ spec:
key: redis-prefix
- name: WORMSCAN_CACHE_ENABLED
value: "true"
- name: WORMSCAN_CACHE_CHANNEL
value: "WORMSCAN:NOTIONAL"
- name: WORMSCAN_CACHE_TVLKEY
value: "WORMSCAN:TVL"
- name: WORMSCAN_CACHE_TVLEXPIRATION
Expand Down

0 comments on commit 4ce2d1e

Please sign in to comment.