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

LF Provide function to reversion a contract #19738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

remyhaemmerle-da
Copy link
Collaborator

No description provided.

@remyhaemmerle-da remyhaemmerle-da marked this pull request as ready for review August 13, 2024 08:29
translateValue(typ, value).map(_.toNormalizedValue(dstVer))

// This
def reversion(
Copy link
Contributor

@simonmaxen-da simonmaxen-da Aug 19, 2024

Choose a reason for hiding this comment

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

I've experimented with using this API directly, and as @matthiasS-da observed, the problem we have is that we may observe several Nodes that bind the contract to different target template ids. As I expect we want to use the one with the maximum package version. Then we also need a method an API that calls this converter with the

we only populate with view with a single contract instance although the transaction tree:

 def reversion(
      contract: FatContractInstance,
      maxVersionOfTmplId: Set[Ref.TypeConName],
  ): Result[FatContractInstance] 

)
case None => ResultNone
}
} yield contract.toImplementation.copy(
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously that argument was consistent with the templateId so it is not nice this is no longer the case. It also means that (contract.templateId == dstTmplId) => ResultDone(contract) will not work for pre-converted contracts. An alternative could be to also template the templateId with the converted templateId. If this is to be considered Hash.assertHashContractInstance would need to be modified not to include the packageId.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add an optional reversionedPackageId to FatContractInstance ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@remyhaemmerle-da Please read @simonmaxen-da 's first comment and double-check there is no fundamental problem with the engine. That said, it is totally up to you how you handle things inside of the engine.

Maybe add an optional reversionedPackageId to FatContractInstance ?

Please keep in mind that such a change may be challenging to consume in the Canton repo. If you add the field, please take care of the fall-out, too.

contract: FatContractInstance,
dstTmplId: Ref.TypeConName,
): Result[FatContractInstance] = {
if (contract.templateId == dstTmplId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would not work for pre-converted contracts.

Copy link
Contributor

Choose a reason for hiding this comment

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

@remyhaemmerle-da please double-check there is no problem with the engine. That said, up to you how you handle things.

@matthiasS-da matthiasS-da self-requested a review August 20, 2024 14:25
@matthiasS-da
Copy link
Contributor

@simonmaxen-da and myself have reorganized ourselves. As a result, I'll take over the review of this PR.

@matthiasS-da matthiasS-da requested review from simonmaxen-da and removed request for simonmaxen-da August 20, 2024 14:26
@matthiasS-da
Copy link
Contributor

My main critique right now is that the interface here does not (yet) match what we have agreed on.

For convenience, let me copy over the signature:

def reVersionValue(
                      value: VersionedValue,
                      dstTmplIds: Set[Ref.TypeConName],
                      pkgs: Map[Ref.PackageId, Package]
                    ): Either[Error, VersionedValue]

With the following constraints:

  1. pkgs needs to contain only the package ids from dstTmplIds.
  2. It returns an error only in case of a missing package (cf. 1) or if reversioning is impossible.
  3. Reversioning does not change the contract hash (cf. LfHash.assertHashContractInstance).

Additionally:
4. The returned versioned value needs to be parseable by any participant (possibly running a different Canton version), whose Engine is able to load the packages in pkgs.

Last but not least: please double-check that the pkgs in (1) are really sufficient for reversioning. I'm concerned about the case that a template uses data types defined in a different package.

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.

3 participants