How to avoid on-ledger contract Service migrations when an Interface contract reference needs to be updated?
- jvelasco.intellecteuOP 2
Hi,
Given this simple but wonderful Service:
import Daml.Finance.Interface.Account.Factory qualified as Account (F) template MyGreatService with operator : Party provider : Party customer : Party accountFactoryCid : ContractId Account.FSay we have one
MyGreatServiceactive on-ledger and we need to fix the template implementingAccount.Fbecause there’s a bug in it
. In this scenario we would not need to modify the codebase in MyGreatServicebecause we are using Interfaces
. However, we would have to migrate the MyGreatServicecontract on-ledger because we wantMyGreatServicecontract to reference the fixed factory, accountFactoryCid’.
Any ideas about how to approach a Service without having to migrate on-ledger for the scenario above?
Thanks!
Jose - Johan_Sjodin 3
Hello @jvelasco.intellecteu ,
if the
MyGreatServiceinstance contains aContractIdreference field that mutates, you indeed need to update that instance to point to the new instance. Otherwise, it will point to an inactive instance, which may cause issues.In general, if the
ContractIdmutates frequently, it is advisable to use a contract key as a field on yourMyGreatServiceinstance instead of aContractIdreference. This way, yourMyGreatServiceinstance will not require updating every time theContractIdmutates since the key of the new contract instance remains the same.However, in case the referred to instance changes rarely, you might consider updating the
ContractIdof theMyGreatServiceinstance (maybe it could be done in the same action the referred to instance changes). An alternative approach would be to remove theContractIdfield ofMyGreateService, and simply pass it in as argument to the choices it is part of + adding some appropriate checks (e.g. that signatories matches).The use of interfaces has its benefits since it allows you to avoid updating the codebase of your
MyGreatServicein case the implementation of the instance it refers to/makes use of changes. But in order to also not having to update theMyGreatServiceinstance, you would either need to use a key reference or the alternative approach ^.For the particular case of referring to an account factory
Account.Finstance, we believe that such instances typically should be rather stable and rarely mutate (at least our implementation has no consuming choices, and its functionality is limited). Therefore, it might be reasonable to actually let theMyGreatServicerefer to it byContractId. However, we recommend to try the alternative approach of removing theContractIdfield fromMyGreatService, and instead pass it in to the choices where it is needed (thereby also checking that theprovideris the right one).I hope that helps.
Johan