From 371f546dd23019efae39b18cc6f84af314b4c6dc Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Mon, 29 Apr 2024 15:37:34 -0500 Subject: [PATCH] Fix: use concurrent map --- services/rfq/relayer/service/chainindexer.go | 4 ++-- services/rfq/relayer/service/relayer.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/rfq/relayer/service/chainindexer.go b/services/rfq/relayer/service/chainindexer.go index 7c337cc963..3b1e7b7acb 100644 --- a/services/rfq/relayer/service/chainindexer.go +++ b/services/rfq/relayer/service/chainindexer.go @@ -162,7 +162,7 @@ func (r *Relayer) getDecimalsFromBridgeTx(parentCtx context.Context, bridgeTx fa func (r *Relayer) getDecimals(ctx context.Context, addr common.Address, chainID uint32) (decimals *uint8, err error) { // attempt to load decimal from cache key := getDecimalsKey(addr, chainID) - decimals, ok := r.decimalsCache[key] + decimals, ok := r.decimalsCache.Load(key) if ok { return decimals, nil } @@ -186,7 +186,7 @@ func (r *Relayer) getDecimals(ctx context.Context, addr common.Address, chainID } // update the cache - r.decimalsCache[key] = &dec + r.decimalsCache.Store(key, &dec) return &dec, nil } diff --git a/services/rfq/relayer/service/relayer.go b/services/rfq/relayer/service/relayer.go index d42bfd36c4..340b0b15b0 100644 --- a/services/rfq/relayer/service/relayer.go +++ b/services/rfq/relayer/service/relayer.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ipfs/go-log" "github.com/jellydator/ttlcache/v3" + "github.com/puzpuzpuz/xsync/v2" "github.com/synapsecns/sanguine/core/dbcommon" "github.com/synapsecns/sanguine/core/metrics" "github.com/synapsecns/sanguine/ethergo/listener" @@ -45,7 +46,7 @@ type Relayer struct { submitter submitter.TransactionSubmitter signer signer.Signer claimCache *ttlcache.Cache[common.Hash, bool] - decimalsCache map[string]*uint8 + decimalsCache *xsync.MapOf[string, *uint8] } var logger = log.Logger("relayer") @@ -127,7 +128,7 @@ func NewRelayer(ctx context.Context, metricHandler metrics.Handler, cfg relconfi quoter: q, metrics: metricHandler, claimCache: cache, - decimalsCache: make(map[string]*uint8), + decimalsCache: xsync.NewMapOf[*uint8](), cfg: cfg, inventory: im, submitter: sm,