Skip to content

Commit

Permalink
wrapping errors, exporting OffchainAggregator metadata vars
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Sep 23, 2024
1 parent 0b5b79d commit bf0e31c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion core/gethwrappers/go_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/services/ocr2/plugins/ccip/exportinternal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
26 changes: 12 additions & 14 deletions core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
})
}

Expand All @@ -177,15 +175,15 @@ 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,
})
}

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{},
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bf0e31c

Please sign in to comment.