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

Add conway-specific certs to deposit/refunds #3700

Merged
merged 2 commits into from
Sep 6, 2023

Conversation

aniketd
Copy link
Contributor

@aniketd aniketd commented Sep 4, 2023

Description

Closes #3696

I suspect that this implementation may be incorrect, because:

  1. although we track RegDepositTxCert and UnRegDepositTxCert (in Conway.UTxO) separately from RegTxCert and UnRegTxCert (in Mary.UTxO) they could be considered essentially the same, because these could be mixed up submissions in the same Tx, and need to be calculated together in Conway?
  2. with respect to deregistering, we have a RegDepositDelegTxCert that has no equivalent Un_ counterpart (as it does not need one), but then, the natural question to ask myself is, should this also be considered to be accounted for along with the group of certs being tracked in point 1?

In other words, should the deposit/refund calculation be the following:

produced =
  getSum @Int 
    (  foldMap'
        (  \case
            RegTxCert {} -> 1
            RegDepositTxCert {} -> 1
            RegDepositDelegTxCert {} -> 1
            _ -> 0
        )
        (txBody ^. certsTxBodyL)
    )
    <x> pp 
    ^. ppKeyDepositL

and

consumed = 
  let go accum@(!depositsInTx, !totalRefunds) = \case
        -- tracking registrations in the same tx
        RegTxCert c -> (Set.insert c depositsInTx, totalRefund)
        RegDepositTxCert c _ -> (Set.insert c depositsInTx, totalRefund)
        RegDepositDelegTxCert c _ _ -> (Set.insert c depositsInTx, totalRefund)
        -- cancelling out registrations in the same tx and refunding otherwise
        UnRegTxCert c
          | Set.member c depositsInTx -> (Set.delete c depositsInTx, totalRefund <+> pp ^. ppKeyDepositL)
          | Just deposit <- lookupKeyDeposit c -> (depositsInTx, totalRefund <+> deposit)
        UnRegDepositTxCert c _
          | Set.member c depositsInTx -> (Set.delete c depositsInTx, totalRefund <+> pp ^. ppKeyDepositL)
          | Just deposit <- lookupKeyDeposit c -> (depositsInTx, totalRefund <+> deposit)
   in snd $ foldl' go (Set.empty, Coin 0) $ txBody ^. certsTxBodyL

unified in conway and not partially separated out (for reuse) in shelleyProducedValue and getConsumedMaryValue?

Let me know what you guys think!

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

@lehins lehins force-pushed the aniketd/cert-deposits-refunds branch from 8b86317 to ba18d99 Compare September 4, 2023 13:30
@aniketd aniketd force-pushed the aniketd/cert-deposits-refunds branch from ba18d99 to f4c36c2 Compare September 4, 2023 15:10
@aniketd aniketd requested a review from lehins September 4, 2023 15:12
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Perfect!

@aniketd aniketd enabled auto-merge (squash) September 4, 2023 21:04
aniketd and others added 2 commits September 6, 2023 10:14
Deprecate is(De)RegKey in favour of is(Un)RegStakeTxCert
…rom API:

* `lookupRegStakeTxCert` and `lookupUnRegStakeTxCert`
* `isRegStakeTxCert` and `isUnRegStakeTxCert`, received a less strict
  `EraTxCert` constraint as well.
@lehins lehins force-pushed the aniketd/cert-deposits-refunds branch from 80d8c81 to eca3a0e Compare September 6, 2023 06:39
@aniketd aniketd merged commit 16a9090 into master Sep 6, 2023
11 of 12 checks passed
@iohk-bors iohk-bors bot deleted the aniketd/cert-deposits-refunds branch September 6, 2023 10:07
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.

Account for new delegation certificates in deposit/refund calculation
2 participants