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

Fixed the certStateSpec #4783

Merged
merged 1 commit into from
Dec 5, 2024
Merged

Fixed the certStateSpec #4783

merged 1 commit into from
Dec 5, 2024

Conversation

TimSheard
Copy link
Contributor

@TimSheard TimSheard commented Dec 5, 2024

addresses Issue #4775

  1. Embedded in the UMap of the DState, is the virtual DRep map with type
    Map (Credential Staking c) (DRep c)

  2. There is a related map in the VState
    Map (Credential 'DRepRole c) (DRepState c)

Given the following two facts
A. every (Credential 'DRepRole c) corresponds to a unique DRep
B. Each DRepState contains a field drepDelegs:: DRepState -> Set (Credential Staking c)

There is a sort of inversse relation between the two maps
For every (Credential 'DRepRole c) in the Map in the VState, and every Set of Staking credentials associated with it, there is a corresponding entry in the DState Map, showing that each credential has delegated to the DRep uniquely identified by the (Credential 'DRepRole cere is a function that computes the invariant

-- | Compute the map of DReps, to those that delegate to them,
--   from the delegation map (Map (Credential 'Staking) Drep) which is stored in the DState
--   This ensures that every staking Credential, delegates to exactly one DRep.
aggregateDRep ::
  Map (Credential 'Staking c) (DRep c) ->
  Map (Credential 'DRepRole c) (Set (Credential 'Staking c))
aggregateDRep m = Map.foldlWithKey accum Map.empty m
  where
    accum ans cred (DRepKeyHash kh) = Map.insertWith Set.union (KeyHashObj kh) (Set.singleton cred) ans
    accum ans cred (DRepScriptHash sh) = Map.insertWith Set.union (ScriptHashObj sh) (Set.singleton cred) ans
    accum ans _ _ = ans

Maintaining this invariant is crucial. The problem was that in our attempt to state this invariant, we over-constrained the system, and the generators could not solve the over-constrained system,

This PR slightly restructures things so the invariant is maintained, and the system is no longer over constrained.

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

@TimSheard TimSheard marked this pull request as ready for review December 5, 2024 16:42
@TimSheard TimSheard requested a review from a team as a code owner December 5, 2024 16:42
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.

Thank you for the detailed explanation!
Looks good to me

@TimSheard TimSheard merged commit 172dca9 into master Dec 5, 2024
154 checks passed
@TimSheard TimSheard deleted the ts-fixIssue-4775 branch December 5, 2024 21:56
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