@@ -137,38 +137,44 @@ func DeployChainContracts(registry *adapters.DeployChainContractsRegistry) deplo
137137 },
138138 }
139139 if ! cfg .Cfg .IgnoreImportedConfigFromPreviousVersion {
140- // so far we do not need any config from 1.5.0 , so only importing config from 1.6.0
141- // if in the future we need to import some config from 1.5.0,
142- // we should leverage lane version resolver to get the right adapter to import config
143- version := semver .MustParse ("1.6.0" )
144- configImporter , ok := registry .GetConfigImporter (sel , version )
145- if ! ok {
146- return deployment.ChangesetOutput {}, utils .ErrNoAdapterForSelectorRegistered ("ConfigImporter" , sel , version )
147- }
148- populateCfgOutput , err := deploy .PopulateMetaDataFromConfigImporter (e , configImporter , sel )
140+ importNeeded , err := shouldImportConfigFromPreviousVersion (e , registry , sel )
149141 if err != nil {
150- return deployment.ChangesetOutput {}, fmt .Errorf ("failed to populate metadata from config importer for chain %d: %w" , sel , err )
142+ return deployment.ChangesetOutput {}, fmt .Errorf ("failed to check if config import from previous version is needed for chain %d: %w" , sel , err )
151143 }
152- // if the importer found config from previous version,
153- // import it and merge it with the input config, giving precedence to the imported config
154- if len (populateCfgOutput .Metadata .Contracts ) > 0 {
155- importReport , err := operations .ExecuteSequence (
156- e .OperationsBundle ,
157- adapter .SetContractParamsFromImportedConfig (),
158- e .BlockChains , adapters.DeployChainConfigCreatorInput {
159- ChainSelector : sel ,
160- ContractMeta : populateCfgOutput .Metadata .Contracts ,
161- ExistingAddresses : existingAddresses ,
162- UserProvidedConfig : input .ContractParams ,
163- })
164- if err != nil {
165- return deployment.ChangesetOutput {Reports : allReports },
166- fmt .Errorf ("failed to execute config importer sequence for chain %d: %w" , sel , err )
144+ if importNeeded {
145+ // so far we do not need any config from 1.5.0 , so only importing config from 1.6.0
146+ // if in the future we need to import some config from 1.5.0,
147+ // we should leverage lane version resolver to get the right adapter to import config
148+ version := semver .MustParse ("1.6.0" )
149+ configImporter , ok := registry .GetConfigImporter (sel , version )
150+ if ! ok {
151+ return deployment.ChangesetOutput {}, utils .ErrNoAdapterForSelectorRegistered ("ConfigImporter" , sel , version )
167152 }
168- allReports = append (allReports , importReport .ExecutionReports ... )
169- input .ContractParams , err = input .ContractParams .MergeWithOverrideIfNotEmpty (importReport .Output )
153+ populateCfgOutput , err := deploy .PopulateMetaDataFromConfigImporter (e , configImporter , sel )
170154 if err != nil {
171- return deployment.ChangesetOutput {}, fmt .Errorf ("failed to merge imported config with input config for chain %d: %w" , sel , err )
155+ return deployment.ChangesetOutput {}, fmt .Errorf ("failed to populate metadata from config importer for chain %d: %w" , sel , err )
156+ }
157+ // if the importer found config from previous version,
158+ // import it and merge it with the input config, giving precedence to the imported config
159+ if len (populateCfgOutput .Metadata .Contracts ) > 0 {
160+ importReport , err := operations .ExecuteSequence (
161+ e .OperationsBundle ,
162+ adapter .SetContractParamsFromImportedConfig (),
163+ e .BlockChains , adapters.DeployChainConfigCreatorInput {
164+ ChainSelector : sel ,
165+ ContractMeta : populateCfgOutput .Metadata .Contracts ,
166+ ExistingAddresses : existingAddresses ,
167+ UserProvidedConfig : input .ContractParams ,
168+ })
169+ if err != nil {
170+ return deployment.ChangesetOutput {Reports : allReports },
171+ fmt .Errorf ("failed to execute config importer sequence for chain %d: %w" , sel , err )
172+ }
173+ allReports = append (allReports , importReport .ExecutionReports ... )
174+ input .ContractParams , err = input .ContractParams .MergeWithOverrideIfNotEmpty (importReport .Output )
175+ if err != nil {
176+ return deployment.ChangesetOutput {}, fmt .Errorf ("failed to merge imported config with input config for chain %d: %w" , sel , err )
177+ }
172178 }
173179 }
174180 }
@@ -263,3 +269,26 @@ func BuildCommitteeVerifierParams(
263269
264270 return params , nil
265271}
272+
273+ // shouldImportConfigFromPreviousVersion checks if any of the lanes connected to the given chain selector are using version 1.6.0,
274+ // if so, it returns true, indicating that we should import config from previous version, otherwise it returns false
275+ func shouldImportConfigFromPreviousVersion (e deployment.Environment , registry * adapters.DeployChainContractsRegistry , sel uint64 ) (bool , error ) {
276+ res , exists := registry .GetLaneVersionResolver (sel )
277+ if ! exists {
278+ return false , fmt .Errorf ("no lane version resolver registered for chain %d" , sel )
279+ }
280+ if ! res .IsSupportedChain (e , sel ) {
281+ return false , nil
282+ }
283+ _ , versions , err := res .DeriveLaneVersionsForChain (e , sel )
284+ if err != nil {
285+ return false , fmt .Errorf ("failed to derive lane versions for chain %d: %w" , sel , err )
286+ }
287+ reqVersion := semver .MustParse ("1.6.0" )
288+ for _ , v := range versions {
289+ if v .Equal (reqVersion ) {
290+ return true , nil
291+ }
292+ }
293+ return false , nil
294+ }
0 commit comments