Skip to content

Commit

Permalink
Fix "cache already exists for contract" when deleting/adding LLO job (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav authored Jan 23, 2025
1 parent 7791a28 commit 47ecf57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
20 changes: 0 additions & 20 deletions core/services/llo/channel_definition_cache_factory.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -26,8 +22,6 @@ func NewChannelDefinitionCacheFactory(lggr logger.Logger, orm ChannelDefinitionC
orm,
lp,
client,
make(map[common.Address]map[uint32]struct{}),
sync.Mutex{},
}
}

Expand All @@ -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) {
Expand All @@ -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
}
7 changes: 4 additions & 3 deletions core/services/llo/channel_definition_cache_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 47ecf57

Please sign in to comment.