From bd22732e2502b042e5e94a0634a2ab397aadff5d Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 2 Oct 2024 12:12:18 -0400 Subject: [PATCH] fix when contract reader fails on latestRoundData call (#1476) ## Motivation https://github.com/smartcontractkit/ccip/blob/b71329d41b803ca16dc9a1f9d5247c87fd6fbc32/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go#L209 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` --- .../ocr2/plugins/ccip/internal/pricegetter/evm.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go b/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go index 48ad9f3298..4e8b5fbd77 100644 --- a/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go +++ b/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go @@ -203,23 +203,23 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, j) offchainAggregatorRespSlice := result[contractName] - for i, read := range offchainAggregatorRespSlice { + for _, read := range offchainAggregatorRespSlice { val, readErr := read.GetResult() if readErr != nil { - respErr = multierr.Append(respErr, fmt.Errorf("error with method call %v: %w", batchCalls.decimalCalls[i].MethodName(), readErr)) + respErr = multierr.Append(respErr, fmt.Errorf("error with contract reader readName %v: %w", read.ReadName, readErr)) continue } if read.ReadName == DECIMALS_METHOD_NAME { decimal, ok := val.(*uint8) if !ok { - return fmt.Errorf("expected type uint8 for method call %v on contract %v: %w", batchCalls.decimalCalls[i].MethodName(), batchCalls.decimalCalls[i].ContractAddress(), readErr) + return fmt.Errorf("expected type uint8 for method call %v on contract %v: %w", batchCalls.decimalCalls[j].MethodName(), batchCalls.decimalCalls[j].ContractAddress(), readErr) } 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) } latestRoundCR = append(latestRoundCR, *latestRoundDataRes)