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

Fix drep delegation invariant preservation #4709

Merged

Conversation

lehins
Copy link
Collaborator

@lehins lehins commented Oct 21, 2024

Description

This PR fixes two bugs that where introduced in #4652:

  1. Delegating to an SPO by a stake credential that was already delegated to a DRep violated the internal invariant leading to an inconsistency in which upon this DRep unregistration the delegation would not get cleaned up. Thus it would lead to a way to surpass the protection of delegation to a non-registered DRep
  2. For testing and benchmarking we have ability to inject DReps and their delegations through the Genesis file. This injection was broken for DReps, since it did not maintain the internal invariant of DRep delegations

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • 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)
  • 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)
  • 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 requested a review from a team as a code owner October 21, 2024 20:56
@lehins lehins force-pushed the lehins/fix-drep-delegation-invariant-during-genesis-injection branch from 8f35cd2 to 74bdd2d Compare October 21, 2024 21:24
@lehins lehins mentioned this pull request Oct 21, 2024
9 tasks
@lehins lehins changed the title Fix drep delegation invariant during genesis injection Fix drep delegation invariant preservation Oct 21, 2024
Introduction of an internal variant allows us using it in the DELEG
ledger rule where we have current delegation readily available
@lehins lehins force-pushed the lehins/fix-drep-delegation-invariant-during-genesis-injection branch from 74bdd2d to 8db9bb8 Compare October 21, 2024 22:01
Copy link
Contributor

@teodanciu teodanciu left a comment

Choose a reason for hiding this comment

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

The refactored version is much easier to grasp, and great bug catch, so subtle!

It took me a while to understand that the old code in Transition was actually doing the delegations, especially I couldn't understand where the oldStakePool <|> newStakePool is handled. But after staring enough at it I can see it in processDelegation.

Anyway! Looks good to me

@lehins lehins enabled auto-merge October 21, 2024 23:05
@lehins lehins merged commit bc52d81 into master Oct 22, 2024
153 of 154 checks passed
@lehins lehins deleted the lehins/fix-drep-delegation-invariant-during-genesis-injection branch October 22, 2024 00: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.

2 participants