From 47ecf574c80751f4a3c883e6d74e40e69fe0383f Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Jan 2025 07:25:19 -0500 Subject: [PATCH] Fix "cache already exists for contract" when deleting/adding LLO job (#16044) --- .../llo/channel_definition_cache_factory.go | 20 ------------------- .../channel_definition_cache_factory_test.go | 7 ++++--- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/core/services/llo/channel_definition_cache_factory.go b/core/services/llo/channel_definition_cache_factory.go index 3306a274aef..55a79ed7a91 100644 --- a/core/services/llo/channel_definition_cache_factory.go +++ b/core/services/llo/channel_definition_cache_factory.go @@ -1,11 +1,7 @@ package llo import ( - "fmt" "net/http" - "sync" - - "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink-common/pkg/logger" llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo" @@ -26,8 +22,6 @@ func NewChannelDefinitionCacheFactory(lggr logger.Logger, orm ChannelDefinitionC orm, lp, client, - make(map[common.Address]map[uint32]struct{}), - sync.Mutex{}, } } @@ -36,9 +30,6 @@ type channelDefinitionCacheFactory struct { orm ChannelDefinitionCacheORM lp logpoller.LogPoller client *http.Client - - caches map[common.Address]map[uint32]struct{} - mu sync.Mutex } func (f *channelDefinitionCacheFactory) NewCache(cfg lloconfig.PluginConfig) (llotypes.ChannelDefinitionCache, error) { @@ -50,16 +41,5 @@ func (f *channelDefinitionCacheFactory) NewCache(cfg lloconfig.PluginConfig) (ll fromBlock := cfg.ChannelDefinitionsContractFromBlock donID := cfg.DonID - f.mu.Lock() - defer f.mu.Unlock() - - if _, exists := f.caches[addr][donID]; exists { - // This shouldn't really happen and isn't supported - return nil, fmt.Errorf("cache already exists for contract address %s and don ID %d", addr.Hex(), donID) - } - if _, exists := f.caches[addr]; !exists { - f.caches[addr] = make(map[uint32]struct{}) - } - f.caches[addr][donID] = struct{}{} return NewChannelDefinitionCache(f.lggr, f.orm, f.client, f.lp, addr, donID, fromBlock), nil } diff --git a/core/services/llo/channel_definition_cache_factory_test.go b/core/services/llo/channel_definition_cache_factory_test.go index 1be9d3dd0bc..2c8be2ba3b0 100644 --- a/core/services/llo/channel_definition_cache_factory_test.go +++ b/core/services/llo/channel_definition_cache_factory_test.go @@ -31,12 +31,13 @@ func Test_ChannelDefinitionCacheFactory(t *testing.T) { require.NoError(t, err) require.IsType(t, &channelDefinitionCache{}, cdc) - // returns error if you try to do it again with the same addr/donID - _, err = cdcFactory.NewCache(lloconfig.PluginConfig{ + // creates another one if you try to do it again with the same addr/donID + cdc, err = cdcFactory.NewCache(lloconfig.PluginConfig{ ChannelDefinitionsContractAddress: common.HexToAddress("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), DonID: 1, }) - require.EqualError(t, err, "cache already exists for contract address 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa and don ID 1") + require.NoError(t, err) + require.IsType(t, &channelDefinitionCache{}, cdc) // is fine if you do it again with different addr cdc, err = cdcFactory.NewCache(lloconfig.PluginConfig{