Skip to content

WIP Get started on topup allocations - #12

Draft
dbzguy56 wants to merge 5 commits into
propose-accept-flowfrom
dpak/cip-105-topup-allocations
Draft

WIP Get started on topup allocations#12
dbzguy56 wants to merge 5 commits into
propose-accept-flowfrom
dpak/cip-105-topup-allocations

Conversation

@dbzguy56

Copy link
Copy Markdown

Pull Request Checklist

Cluster Testing

  • If a cluster test is required, comment /cluster_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If an upgrade test is required, comment /upgrade_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a hard-migration test is required (from the latest release), comment /hdm_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a logical synchronizer upgrade test is required (from canton-3.5), comment /lsu_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.

PR Guidelines

  • Include any change that might be observable by our partners or affect their deployment in the release notes.
  • Specify fixed issues with Fixes #n, and mention issues worked on using #n
  • Include a screenshot for frontend-related PRs - see README or use your favorite screenshot tool

Merge Guidelines

  • Make the git commit message look sensible when squash-merging on GitHub (most likely: just copy your PR description).

Comment on lines +110 to +111
isGovernanceAllocationArgument arg = not ( S.null $ governanceMetadataKeys arg.allocation.meta )
|| not (TM.null ( TM.filterWithKey ( \a _ -> "cip-105/" `T.isPrefixOf` a ) arg.extraArgs.context.values))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@jonored @dbzguy56 : what do you think about simplifying this logic as follows:

  1. determine whether this is a governance allocation call based on a single metadata key cip-105/operation-type that encodes the type of operation.
  2. forbid setting any cip-105/ keys in case that is not set

This way we follow standard practices for encoding sum types, and can provide better error messages.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't particularly have any objection to inverting isGovernanceAllocationArgument into a check on cip-105/operation-type and then this check inverted for non-governance-related allocations. Once we enter the actual metadata conversion I think we do follow the usual practice in our typeclass, we just didn't when adding the loose functions for context keys.

I actually think that we might want to do a bit of matching on the choice context separately as well as parse the metadata; if we accept a topup and a governance lock spec together at the daml layer (and check that the topup matches the provided lock spec), then the http API can handle mapping allocation calls into topup operations when possible by finding a matching existing allocation to pass in the context. It looks like it can't modify the metadata as well to do that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't particularly have any objection to inverting isGovernanceAllocationArgument into a check on cip-105/operation-type and then this check inverted for non-governance-related allocations. Once we enter the actual metadata conversion I think we do follow the usual practice in our typeclass, we just didn't when adding the loose functions for context keys.

OK. Let's convert to a principled way then.

I actually think that we might want to do a bit of matching on the choice context separately as well as parse the metadata; if we accept a topup and a governance lock spec together at the daml layer (and check that the topup matches the provided lock spec), then the http API can handle mapping allocation calls into topup operations when possible by finding a matching existing allocation to pass in the context. It looks like it can't modify the metadata as well to do that.

I don't understand what you mean: where do you want to do the matching?

Comment on lines +176 to +177
None -> do
let eitherCid = lookupFromContext @(ContractId V2.Allocation) alloc.extraArgs.context topUpAllocationMetadataKey

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

See my comment above. This approach of try parsing it as a lock, then as a top-up, is prone to surprises. Let's just encode the type of operation directly.

authorizer = alloc.allocation.authorizer
transferLegSides = []
settlementDeadline = Some endDate -- Might as well let it unlock normally at the end of vesting.
settlementDeadline = Some maxComparableTime

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not settlementDeadline = None?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It'll change back to this as soon as we modify the allocation with settlement as it is now; we need to use this max time for the LockedAmulet contract and we're currently doing that by setting it in computeAllocationExpiry if there's a governance lock. We could do a change to split the values where we'd need to to make a None settlementDeadline on a governance lock mean actually no deadline and the lock persists rather than the maxTTL-but-resettable deadline behavior normal allocations have, but I'm not convinced of the value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I was also looking at this and noticed that you can't withdraw from a committed allocation with this deadline set to None, and that's presumably the reason.

vestingLockCid = toInterfaceContractId @V2.Allocation aCid

now <- getFromContextU arg.extraArgs.context effectiveAtKey -- FIXME: read from metadata, not context.
isLedgerTimeGE now >>= require "effectiveAt must not be in the future"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

calling this effectiveAt feels off. I'd suggest to encode a requestedAt argument in our virtual choice argument (GovernanceLockOperation_TopUp) and parse it normally.

Also you can just use assertDeadlineExceeded "requestedAt" requestedAt to encode your restriction.

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.

4 participants