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

Removing chain dependencies from NewCommitServices construct #1361

Merged
merged 49 commits into from
Sep 27, 2024

Conversation

patrickhuie19
Copy link
Collaborator

Motivation

LOOP-ify

Solution

Copy link
Contributor

@dimkouv dimkouv left a comment

Choose a reason for hiding this comment

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

let's wait for flaky tests to be resolved before merging

@patrickhuie19
Copy link
Collaborator Author

let's wait for flaky tests to be resolved before merging

@Tofel @lukaszcl re: testcontainers bug

This PR tests https://github.com/smartcontractkit/ccip/pull/1361/files
without changes made to integration-tests/docker/test_env/cl_node.go

---------

Co-authored-by: Patrick <[email protected]>
Comment on lines +1619 to +1687
var priceGetter ccip.AllTokensPriceGetter
withPipeline := strings.Trim(pluginJobSpecConfig.TokenPricesUSDPipeline, "\n\t ") != ""
if withPipeline {
priceGetter, err = ccip.NewPipelineGetter(pluginJobSpecConfig.TokenPricesUSDPipeline, d.pipelineRunner, jb.ID, jb.ExternalJobID, jb.Name.ValueOrZero(), lggr)
if err != nil {
return nil, fmt.Errorf("creating pipeline price getter: %w", err)
}
} else {
// Use dynamic price getter.
if pluginJobSpecConfig.PriceGetterConfig == nil {
return nil, fmt.Errorf("priceGetterConfig is nil")
}

// Configure contract readers for all chains specified in the aggregator configurations.
// Some lanes (e.g. Wemix/Kroma) requires other clients than source and destination, since they use feeds from other chains.
aggregatorChainsToContracts := make(map[uint64][]common.Address)
for _, aggCfg := range pluginJobSpecConfig.PriceGetterConfig.AggregatorPrices {
if _, ok := aggregatorChainsToContracts[aggCfg.ChainID]; !ok {
aggregatorChainsToContracts[aggCfg.ChainID] = make([]common.Address, 0)
}

aggregatorChainsToContracts[aggCfg.ChainID] = append(aggregatorChainsToContracts[aggCfg.ChainID], aggCfg.AggregatorContractAddress)
}

contractReaders := map[uint64]types.ContractReader{}

for chainID, aggregatorContracts := range aggregatorChainsToContracts {
relayID := types.RelayID{Network: spec.Relay, ChainID: strconv.FormatUint(chainID, 10)}
relay, rerr := d.RelayGetter.Get(relayID)
if rerr != nil {
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", ccip.OFFCHAIN_AGGREGATOR, i)] = evmrelaytypes.ChainContractReader{
ContractABI: ccip.OffChainAggregatorABI,
Configs: map[string]*evmrelaytypes.ChainReaderDefinition{
"decimals": { // CR consumers choose an alias
ChainSpecificName: "decimals",
},
"latestRoundData": {
ChainSpecificName: "latestRoundData",
},
},
}
}
contractReaderConfig := evmrelaytypes.ChainReaderConfig{
Contracts: contractsConfig,
}

contractReaderConfigJsonBytes, jerr := json.Marshal(contractReaderConfig)
if jerr != nil {
return nil, fmt.Errorf("marshal contract reader config: %w", jerr)
}

contractReader, cerr := relay.NewContractReader(ctx, contractReaderConfigJsonBytes)
if cerr != nil {
return nil, fmt.Errorf("new ccip commit contract reader %w", cerr)
}

contractReaders[chainID] = contractReader
}

priceGetter, err = ccip.NewDynamicPriceGetter(*pluginJobSpecConfig.PriceGetterConfig, contractReaders)
if err != nil {
return nil, fmt.Errorf("creating dynamic price getter: %w", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to wrap this in a function similar to d.ccipCommitGetDstProvider and d.ccipCommitGetSrcProvider above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +23 to +25
const OFFCHAIN_AGGREGATOR = "OffchainAggregator"
const DECIMALS_METHOD_NAME = "decimals"
const LATEST_ROUND_DATA_METHOD_NAME = "latestRoundData"
Copy link
Contributor

Choose a reason for hiding this comment

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

All caps is not idiomatic (stdlib uses UpperCamelCase, i.e. math.MaxUint64). They were also private before. So two requests:

  1. Can it be private?
  2. Please rename to DecimalsMethodName or decimalsMethodName

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These specific vars are not exported anywhere else, since they live in a package that is defined behind in a leaf of aninternal path. Will rename to UpperCamelCase, thanks for the stdlib callout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +51 to +53
.PHONY: install-chainlink-delve
install-chainlink-delve: operator-ui ## Install the chainlink binary.
go install $(GOFLAGS) -gcflags "all=-N -l" .
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this? It doesn't seem to have anything to do with delve

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The -gcflags "all=-N -l" portion of this compiles the binary in a way that allows a debugger to step through.

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.

Approved, but hoping for a followup to address the nits

@winder winder removed the request for review from Tofel September 27, 2024 13:23
@patrickhuie19 patrickhuie19 merged commit b71329d into ccip-develop Sep 27, 2024
116 of 117 checks passed
@patrickhuie19 patrickhuie19 deleted the feature/commit-init-no-evm branch September 27, 2024 13:52
@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
6 Security Hotspots

See analysis details on SonarQube

valerii-kabisov-cll pushed a commit that referenced this pull request Oct 1, 2024
## Motivation
LOOP-ify

## Solution

---------

Co-authored-by: Bartek Tofel <[email protected]>
Co-authored-by: lukaszcl <[email protected]>
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.

7 participants