Remove notional cache from the `api` component (#500)

### Summary

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

This pull request removes the unnecessary dependency.
This commit is contained in:
agodnic 2023-07-05 15:07:24 -03:00 committed by GitHub
parent 9e4aa45305
commit 4ce2d1e329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 23 deletions

View File

@ -1748,7 +1748,7 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"emitterNativeAddress": { "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" "type": "string"
}, },
"id": { "id": {

View File

@ -1741,7 +1741,7 @@
"type": "string" "type": "string"
}, },
"emitterNativeAddress": { "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" "type": "string"
}, },
"id": { "id": {

View File

@ -27,8 +27,8 @@ definitions:
hex. hex.
type: string type: string
emitterNativeAddress: emitterNativeAddress:
description: EmitterNativeAddress contains the VAA's emitter address in the description: EmitterNativeAddress contains the VAA's emitter address, encoded
emitter chain's native format. in the emitter chain's native format.
type: string type: string
id: id:
type: string type: string

View File

@ -33,7 +33,6 @@ type AppConfig struct {
} }
Cache struct { Cache struct {
URL string URL string
Channel string
TvlKey string TvlKey string
TvlExpiration int TvlExpiration int
Enabled bool Enabled bool
@ -71,7 +70,6 @@ func defaulConfig() *AppConfig {
return &AppConfig{ return &AppConfig{
Cache: struct { Cache: struct {
URL string URL string
Channel string
TvlKey string TvlKey string
TvlExpiration int TvlExpiration int
Enabled bool Enabled bool

View File

@ -40,7 +40,6 @@ import (
"github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan" "github.com/wormhole-foundation/wormhole-explorer/api/routes/wormscan"
rpcApi "github.com/wormhole-foundation/wormhole-explorer/api/rpc" rpcApi "github.com/wormhole-foundation/wormhole-explorer/api/rpc"
wormscanCache "github.com/wormhole-foundation/wormhole-explorer/common/client/cache" 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" xlogger "github.com/wormhole-foundation/wormhole-explorer/common/logger"
"github.com/wormhole-foundation/wormhole-explorer/common/utils" "github.com/wormhole-foundation/wormhole-explorer/common/utils"
"go.uber.org/zap" "go.uber.org/zap"
@ -106,13 +105,16 @@ func main() {
rootLogger.Info("connecting to MongoDB") rootLogger.Info("connecting to MongoDB")
cli, err := db.Connect(appCtx, cfg.DB.URL) cli, err := db.Connect(appCtx, cfg.DB.URL)
if err != nil { if err != nil {
panic(err) rootLogger.Fatal("failed to connect to MongoDB", zap.Error(err))
} }
db := cli.Database(cfg.DB.Name) db := cli.Database(cfg.DB.Name)
// Get cache get function // Get cache get function
rootLogger.Info("initializing notional cache") rootLogger.Info("initializing cache")
cache, notionalCache := NewCache(appCtx, cfg, rootLogger) cache, err := NewCache(appCtx, cfg, rootLogger)
if err != nil {
rootLogger.Fatal("failed to initialize cache", zap.Error(err))
}
// cfg.Cache.Expiration // cfg.Cache.Expiration
rootLogger.Info("initializing TVL cache") rootLogger.Info("initializing TVL cache")
@ -219,33 +221,30 @@ func main() {
rootLogger.Info("cleanup tasks...") rootLogger.Info("cleanup tasks...")
rootLogger.Info("shutting down server...") rootLogger.Info("shutting down server...")
app.Shutdown() app.Shutdown()
rootLogger.Info("closing notional cache...")
notionalCache.Close()
rootLogger.Info("closing cache...") rootLogger.Info("closing cache...")
cache.Close() cache.Close()
rootLogger.Info("terminated API service successfully") 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. // 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 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 { if cfg.RunMode == config.RunModeDevelopmernt && !cfg.Cache.Enabled {
dummyCacheClient := wormscanCache.NewDummyCacheClient() dummyCacheClient := wormscanCache.NewDummyCacheClient()
dummyNotionalCache := wormscanNotionalCache.NewDummyNotionalCache() return dummyCacheClient, nil
return dummyCacheClient, dummyNotionalCache
} }
// if we are not in development mode, use a distributed cache and for notional a pubsub to sync local cache. // 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}) redisClient := redis.NewClient(&redis.Options{Addr: cfg.Cache.URL})
// get cache client // get cache client
cacheClient, _ := wormscanCache.NewCacheClient(redisClient, cfg.Cache.Enabled, cfg.Cache.Prefix, logger) 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)
}
// get notional cache client and init load to local cache return cacheClient, nil
notionalCache, _ := wormscanNotionalCache.NewNotionalCache(ctx, redisClient, cfg.Cache.Prefix, cfg.Cache.Channel, logger)
notionalCache.Init(ctx)
return cacheClient, notionalCache
} }
func newInfluxClient(url, token string) influxdb2.Client { func newInfluxClient(url, token string) influxdb2.Client {

View File

@ -95,8 +95,6 @@ spec:
key: redis-prefix key: redis-prefix
- name: WORMSCAN_CACHE_ENABLED - name: WORMSCAN_CACHE_ENABLED
value: "true" value: "true"
- name: WORMSCAN_CACHE_CHANNEL
value: "WORMSCAN:NOTIONAL"
- name: WORMSCAN_CACHE_TVLKEY - name: WORMSCAN_CACHE_TVLKEY
value: "WORMSCAN:TVL" value: "WORMSCAN:TVL"
- name: WORMSCAN_CACHE_TVLEXPIRATION - name: WORMSCAN_CACHE_TVLEXPIRATION