Skip to content

Commit

Permalink
Rename proposalsRemoveDescendentIds to `proposalsRemoveWithDescenda…
Browse files Browse the repository at this point in the history
…nts`

* Emphasize in the name that not only descendants will be removed, but
  also the govActionIds supplied as arguments
* Marked is for testing only, since it is not suitable for deleting
  roots
* Fixed the spelling: descendant is someone who descended from an anscentor
  • Loading branch information
lehins committed Feb 1, 2024
1 parent dbf79c1 commit 30f7c7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.13.0.0

* Rename `proposalsRemoveDescendentIds` to `proposalsRemoveWithDescendants` (fixed spelling too)
* Rename:
* `pfPParamUpdateL` to `grPParamUpdateL`
* `pfHardForkL` to `grHardForkL`
Expand Down
2 changes: 1 addition & 1 deletion eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module Cardano.Ledger.Conway.Governance (
grConstitutionL,
proposalsActions,
proposalsAddAction,
proposalsRemoveDescendentIds,
proposalsRemoveWithDescendants,
proposalsAddVote,
proposalsIds,
proposalsApplyEnactment,
Expand Down
28 changes: 14 additions & 14 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance/Proposals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
-- operation to fail, since all invariants are expected to hold and
-- only an implementation bug could cause this operation to fail.
-- After applying this operation we expect the @`Proposals`@ to be in
-- a state, where (i) all expired actions and their descendents have
-- a state, where (i) all expired actions and their descendants have
-- been pruned, and (ii) the sequence of enacted action-ids have been
-- promoted to be the root of the respective tree and their competing
-- or sibling action-ids and their descendents have been pruned from
-- or sibling action-ids and their descendants have been pruned from
-- the @`Proposals`@ tree.
--
-- 2.2. The resultant @`Proposals`@ forest has all the latest
Expand Down Expand Up @@ -87,14 +87,14 @@ module Cardano.Ledger.Conway.Governance.Proposals (
proposalsSize,
proposalsAddAction,
proposalsApplyEnactment,
proposalsRemoveDescendentIds,
proposalsAddVote,
proposalsLookupId,
proposalsActionsMap,
toPrevGovActionIds,
fromPrevGovActionIds,

-- * To be used only for testing
proposalsRemoveWithDescendants,
TreeMaybe (..),
toGovRelationTree,
toGovRelationTreeEither,
Expand Down Expand Up @@ -356,34 +356,34 @@ proposalsRemoveIds gais ps =
govRelationL . pGraphNodesL %~ Map.adjust (peChildrenL %~ Set.delete gpi) parentGpi
)

-- | Remove the set of given action-ids with their descendents from the
-- @`Proposals`@ forest
proposalsRemoveDescendentIds ::
-- | Remove the set of given action-ids with their descendants from the
-- @`Proposals`@ forest. Cannot be used for removing enacted GovActionIds (i.e. roots)
proposalsRemoveWithDescendants ::
EraPParams era =>
Set (GovActionId (EraCrypto era)) ->
Proposals era ->
(Proposals era, Map (GovActionId (EraCrypto era)) (GovActionState era))
proposalsRemoveDescendentIds gais ps@(Proposals omap _roots graph) =
proposalsRemoveIds (gais <> foldMap getAllDescendents gais) ps
proposalsRemoveWithDescendants gais ps@(Proposals omap _roots graph) =
proposalsRemoveIds (gais <> foldMap getAllDescendants gais) ps
where
getAllDescendents gai =
-- Recursively aet all of the descendants for those actions that have lineage
getAllDescendants gai =
case OMap.lookup gai omap of
Nothing -> assert False mempty
Just gas -> withGovActionParent gas mempty $ \govRelationL _ ->
let go acc gpi =
case Map.lookup gpi $ graph ^. govRelationL . pGraphNodesL of
-- Impossible! getAllDescendents: GovPurposeId not found
Nothing -> assert False acc
Just (PEdges _parent children) ->
foldl' go (Set.map unGovPurposeId children <> acc) children
in go mempty

-- | For use in the @`EPOCH`@ rule. Apply the result of
-- @`extractDRepPulsingState`@ to the @`Proposals`@ forest, so that:
-- i. all the expired action-ids and their descendents are removed,
-- i. all the expired action-ids and their descendants are removed,
-- and
-- ii. the sequence of enacted action-ids is promoted to the root,
-- removing competing/sibling action-ids and their descendents at each
-- removing competing/sibling action-ids and their descendants at each
-- step
proposalsApplyEnactment ::
forall era.
Expand All @@ -396,7 +396,7 @@ proposalsApplyEnactment ::
, Map (GovActionId (EraCrypto era)) (GovActionState era) -- Removed due to expiry
)
proposalsApplyEnactment enactedGass expiredGais props =
let (unexpiredProposals, expiredRemoved) = proposalsRemoveDescendentIds expiredGais props
let (unexpiredProposals, expiredRemoved) = proposalsRemoveWithDescendants expiredGais props
(enactedProposalsState, enactedRemoved) =
foldl' enact (unexpiredProposals, Map.empty) enactedGass
in (enactedProposalsState, enactedRemoved, expiredRemoved)
Expand Down Expand Up @@ -426,7 +426,7 @@ proposalsApplyEnactment enactedGass expiredGais props =
case Map.lookup gpi $ ps ^. pGraphL . govRelationL . pGraphNodesL of
Nothing -> assert False Set.empty
Just pe -> peChildren pe
(withoutSiblings, removedActions) = proposalsRemoveDescendentIds siblings ps
(withoutSiblings, removedActions) = proposalsRemoveWithDescendants siblings ps
newGraph = Map.delete gpi $ withoutSiblings ^. pGraphL . govRelationL . pGraphNodesL
(newOMap, enactedAction) =
OMap.extractKeys (Set.singleton gai) $ withoutSiblings ^. pPropsL
Expand Down

0 comments on commit 30f7c7e

Please sign in to comment.