Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix when contract reader fails on latestRoundData call #1476

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

patrickhuie19
Copy link
Collaborator

Motivation

respErr = multierr.Append(respErr, fmt.Errorf("error with method call %v: %w", batchCalls.decimalCalls[i].MethodName(), readErr))
will panic with

panic: runtime error: index out of range [1] with length 1

goroutine 3683 [running]:
github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/pricegetter.(*DynamicPriceGetter).performBatchCall(0x8?, {0x46d85c0, 0x67ae360}, 0xa77ab4f8?, 0xc0174776d0, 0xc017475aa0)
	/chainlink/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go:209 +0x1998

This can happen when the contract reader fails on a LatestRoundData call when only one aggregator contract is requested in the batch call.

Solution

Use read.ReadName

}

decimalsCR = append(decimalsCR, *decimal)
} else if read.ReadName == LATEST_ROUND_DATA_METHOD_NAME {
latestRoundDataRes, ok := val.(*aggregator_v3_interface.LatestRoundData)
if !ok {
return fmt.Errorf("expected type latestRoundDataConfig for method call %v on contract %v: %w", batchCalls.latestRoundDataCalls[i/2].MethodName(), batchCalls.latestRoundDataCalls[i/2].ContractAddress(), readErr)
return fmt.Errorf("expected type latestRoundDataConfig for method call %v on contract %v: %w", batchCalls.latestRoundDataCalls[j].MethodName(), batchCalls.latestRoundDataCalls[j].ContractAddress(), readErr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add an assertion to the top that len(batchCalls.decimalCalls) == len(batchCalls.latestRoundDataCalls)

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@patrickhuie19 patrickhuie19 enabled auto-merge (squash) October 2, 2024 15:59
@patrickhuie19 patrickhuie19 merged commit bd22732 into ccip-develop Oct 2, 2024
111 checks passed
@patrickhuie19 patrickhuie19 deleted the fix/commit-init-no-evm branch October 2, 2024 16:12
@cl-sonarqube-production
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants