Skip to content

Commit 1c0f4fc

Browse files
AnieeGCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7f8da3d commit 1c0f4fc

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

chains/evm/deployment/v1_5_0/adapters/configimport.go

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,60 @@ func GetSupportedTokensPerRemoteChain(ctx context.Context, l logger.Logger, toke
222222
if err != nil {
223223
return fmt.Errorf("failed to instantiate token pool contract at %s on chain %d: %w", poolAddr.String(), chain.Selector, err)
224224
}
225+
226+
// Cache the token address per pool so we only fetch it once, and
227+
// track when certain pool methods appear to be unsupported so we
228+
// can avoid repeated failed calls and warning spam.
229+
var (
230+
tokenAddr common.Address
231+
tokenFetched bool
232+
isSupportedChainUnsupported bool
233+
getTokenUnsupported bool
234+
)
235+
225236
for _, remoteChain := range remoteChains {
237+
// If we've already determined that IsSupportedChain or GetToken
238+
// are unsupported for this pool, stop checking further chains.
239+
if isSupportedChainUnsupported || getTokenUnsupported {
240+
break
241+
}
242+
226243
supported, err := tokenPoolC.IsSupportedChain(&bind.CallOpts{
227244
Context: grpCtx,
228245
}, remoteChain)
229246
if err != nil {
230-
// if we fail to check if the pool supports a remote chain, we skip it and move on to avoid failing the entire config import
231-
// since it's possible for some pools do not support the isSupportedChain function
247+
// If we fail to check if the pool supports a remote chain,
248+
// assume this method isn't supported by this pool, log once,
249+
// and short-circuit to avoid failing the entire import and
250+
// spamming warnings for every remote chain.
232251
l.Warnf("failed to check if token pool at %s on chain %d supports remote chain %d: %v", poolAddr.String(), chain.Selector, remoteChain, err)
252+
isSupportedChainUnsupported = true
253+
break
254+
}
255+
if !supported {
233256
continue
234257
}
235-
if supported {
236-
tokenAddr, err := tokenPoolC.GetToken(&bind.CallOpts{
258+
259+
// Fetch the token address at most once per pool.
260+
if !tokenFetched {
261+
tokenAddr, err = tokenPoolC.GetToken(&bind.CallOpts{
237262
Context: grpCtx,
238263
})
239264
if err != nil {
240-
// if we fail to get the token address for a pool, we skip it and move on to avoid failing the entire config import
241-
// since it's possible for some pools do not support the getToken function
265+
// If we fail to get the token address for a pool, assume
266+
// this method isn't supported or is consistently failing
267+
// for this pool. Log once and short-circuit further
268+
// attempts for this pool to avoid warning spam.
242269
l.Warnf("failed to get token address for token pool at %s on chain %d: %v", poolAddr.String(), chain.Selector, err)
243-
continue
270+
getTokenUnsupported = true
271+
break
244272
}
245-
mu.Lock()
246-
tokensPerRemoteChain[remoteChain] = append(tokensPerRemoteChain[remoteChain], tokenAddr)
247-
mu.Unlock()
273+
tokenFetched = true
248274
}
275+
276+
mu.Lock()
277+
tokensPerRemoteChain[remoteChain] = append(tokensPerRemoteChain[remoteChain], tokenAddr)
278+
mu.Unlock()
249279
}
250280
return nil
251281
})

0 commit comments

Comments
 (0)