From bf0e31cfea87acd4bbe0723065b5958034e4a5af Mon Sep 17 00:00:00 2001 From: patrickhuie19 Date: Mon, 23 Sep 2024 12:58:30 -0400 Subject: [PATCH] wrapping errors, exporting OffchainAggregator metadata vars --- core/gethwrappers/go_generate_test.go | 3 ++- core/services/ocr2/delegate.go | 8 +++--- .../ocr2/plugins/ccip/exportinternal.go | 4 +++ .../plugins/ccip/internal/pricegetter/evm.go | 26 +++++++++---------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/gethwrappers/go_generate_test.go b/core/gethwrappers/go_generate_test.go index a6253cb1a6..e986f00bb0 100644 --- a/core/gethwrappers/go_generate_test.go +++ b/core/gethwrappers/go_generate_test.go @@ -17,6 +17,7 @@ import ( cutils "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip" "github.com/smartcontractkit/chainlink/v2/core/utils" "github.com/stretchr/testify/assert" @@ -57,7 +58,7 @@ func TestCheckContractHashesFromLastGoGenerate(t *testing.T) { } func isOCRContract(fullpath string) bool { - return strings.Contains(fullpath, "OffchainAggregator") + return strings.Contains(fullpath, ccip.OFFCHAIN_AGGREGATOR) } // VRFv2 currently uses revert error types which are not supported by abigen diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index 1f33d0fde0..699c552030 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -1646,12 +1646,12 @@ func (d *Delegate) newServicesCCIPCommit(ctx context.Context, lggr logger.Sugare relayID := types.RelayID{Network: spec.Relay, ChainID: strconv.FormatUint(chainID, 10)} relay, rerr := d.RelayGetter.Get(relayID) if rerr != nil { - return nil, rerr + return nil, fmt.Errorf("get relay by id=%v: %w", relayID, err) } contractsConfig := make(map[string]evmrelaytypes.ChainContractReader, len(aggregatorContracts)) for i := range aggregatorContracts { - contractsConfig[fmt.Sprintf("%v_%v", "OffchainAggregator", i)] = evmrelaytypes.ChainContractReader{ + contractsConfig[fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, i)] = evmrelaytypes.ChainContractReader{ ContractABI: ccip.OffChainAggregatorABI, Configs: map[string]*evmrelaytypes.ChainReaderDefinition{ "decimals": { // CR consumers choose an alias @@ -1669,12 +1669,12 @@ func (d *Delegate) newServicesCCIPCommit(ctx context.Context, lggr logger.Sugare contractReaderConfigJsonBytes, jerr := json.Marshal(contractReaderConfig) if jerr != nil { - return nil, jerr + return nil, fmt.Errorf("marshal contract reader config: %w", jerr) } contractReader, cerr := relay.NewContractReader(ctx, contractReaderConfigJsonBytes) if cerr != nil { - return nil, cerr + return nil, fmt.Errorf("new ccip commit contract reader %w", cerr) } contractReaders[chainID] = contractReader diff --git a/core/services/ocr2/plugins/ccip/exportinternal.go b/core/services/ocr2/plugins/ccip/exportinternal.go index c7339604af..be39346984 100644 --- a/core/services/ocr2/plugins/ccip/exportinternal.go +++ b/core/services/ocr2/plugins/ccip/exportinternal.go @@ -28,6 +28,10 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" ) +const OFFCHAIN_AGGREGATOR = "OffchainAggregator" +const DECIMALS_METHOD_NAME = "decimals" +const LATEST_ROUND_DATA_METHOD_NAME = "latestRoundData" + func GenericAddrToEvm(addr ccip.Address) (common.Address, error) { return ccipcalc.GenericAddrToEvm(addr) } diff --git a/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go b/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go index 28d0038bb6..bc4bf02743 100644 --- a/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go +++ b/core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go @@ -7,6 +7,8 @@ import ( "math/big" "strings" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface" "go.uber.org/multierr" @@ -25,18 +27,14 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc" ) -const decimalsMethodName = "decimals" -const latestRoundDataMethodName = "latestRoundData" -const OFFCHAIN_AGGREGATOR = "OffchainAggregator" - func init() { // Ensure existence of latestRoundData method on the Aggregator contract. aggregatorABI, err := abi.JSON(strings.NewReader(offchainaggregator.OffchainAggregatorABI)) if err != nil { panic(err) } - ensureMethodOnContract(aggregatorABI, decimalsMethodName) - ensureMethodOnContract(aggregatorABI, latestRoundDataMethodName) + ensureMethodOnContract(aggregatorABI, ccip.DECIMALS_METHOD_NAME) + ensureMethodOnContract(aggregatorABI, ccip.LATEST_ROUND_DATA_METHOD_NAME) } func ensureMethodOnContract(abi abi.ABI, methodName string) { @@ -164,7 +162,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 for i, call := range batchCalls.decimalCalls { bindings = append(bindings, types.BoundContract{ Address: string(ccipcalc.EvmAddrToGeneric(call.ContractAddress())), - Name: fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i), + Name: fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, i), }) } @@ -177,7 +175,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 var decimalsReq uint8 batchGetLatestValuesRequest := make(map[string]types.ContractBatch) for i, call := range batchCalls.decimalCalls { - contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i) + contractName := fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, i) batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{ ReadName: call.MethodName(), ReturnVal: &decimalsReq, @@ -185,7 +183,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 } for i, call := range batchCalls.latestRoundDataCalls { - contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i) + contractName := fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, i) batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{ ReadName: call.MethodName(), ReturnVal: &aggregator_v3_interface.LatestRoundData{}, @@ -205,7 +203,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 latestRoundCR := make([]aggregator_v3_interface.LatestRoundData, 0, nbDecimalCalls) var respErr error for j := range nbCalls { - contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, j) + contractName := fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, j) offchainAggregatorRespSlice := result[contractName] for i, read := range offchainAggregatorRespSlice { @@ -214,14 +212,14 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6 respErr = multierr.Append(respErr, fmt.Errorf("error with method call %v: %w", batchCalls.decimalCalls[i].MethodName(), readErr)) continue } - if read.ReadName == decimalsMethodName { + if read.ReadName == ccip.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) } decimalsCR = append(decimalsCR, *decimal) - } else if read.ReadName == latestRoundDataMethodName { + } else if read.ReadName == ccip.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) @@ -276,12 +274,12 @@ func (d *DynamicPriceGetter) preparePricesAndBatchCallsPerChain(tokens []cciptyp chainCalls := batchCallsPerChain[aggCfg.ChainID] chainCalls.decimalCalls = append(chainCalls.decimalCalls, rpclib.NewEvmCall( d.aggregatorAbi, - decimalsMethodName, + ccip.DECIMALS_METHOD_NAME, aggCfg.AggregatorContractAddress, )) chainCalls.latestRoundDataCalls = append(chainCalls.latestRoundDataCalls, rpclib.NewEvmCall( d.aggregatorAbi, - latestRoundDataMethodName, + ccip.LATEST_ROUND_DATA_METHOD_NAME, aggCfg.AggregatorContractAddress, )) chainCalls.tokenOrder = append(chainCalls.tokenOrder, tk)