Skip to content

Commit dace671

Browse files
committed
Add function that computes future committee
1 parent c45efbf commit dace671

File tree

1 file changed

+33
-0
lines changed
  • cardano-db-sync/src/Cardano/DbSync/Ledger

1 file changed

+33
-0
lines changed

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE DataKinds #-}
44
{-# LANGUAGE FlexibleInstances #-}
55
{-# LANGUAGE GADTs #-}
6+
{-# LANGUAGE LambdaCase #-}
67
{-# LANGUAGE MultiParamTypeClasses #-}
78
{-# LANGUAGE OverloadedStrings #-}
89
{-# LANGUAGE RankNTypes #-}
@@ -29,6 +30,7 @@ module Cardano.DbSync.Ledger.State (
2930
runLedgerStateWriteThread,
3031
getStakeSlice,
3132
getSliceMeta,
33+
findProposedCommittee,
3234
) where
3335

3436
import Cardano.BM.Trace (Trace, logInfo, logWarning)
@@ -856,3 +858,34 @@ findAdaPots = go
856858
go [] = Nothing
857859
go (LedgerAdaPots p : _) = Just p
858860
go (_ : rest) = go rest
861+
862+
-- | Given an committee action id and the current GovState, return the proposed committee.
863+
-- If the id is not included in the proposals, return Nothing.
864+
findProposedCommittee :: GovActionId StandardCrypto -> ConwayGovState StandardConway -> Maybe (Committee StandardConway)
865+
findProposedCommittee gaId cgs = do
866+
(rootCommittee, updateList) <- findRoot gaId
867+
computeCommittee rootCommittee updateList
868+
where
869+
ps = cgsProposals cgs
870+
findRoot = findRootRecursively []
871+
872+
findRootRecursively :: [GovAction StandardConway] -> GovActionId StandardCrypto -> Maybe (StrictMaybe (Committee StandardConway), [GovAction StandardConway])
873+
findRootRecursively acc gid = do
874+
gas <- proposalsLookupId gid ps
875+
let ga = pProcGovAction (gasProposalProcedure gas)
876+
case ga of
877+
NoConfidence _ -> Just (Ledger.SNothing, acc)
878+
UpdateCommittee Ledger.SNothing _ _ _ -> Just (cgsCommittee cgs, ga : acc)
879+
UpdateCommittee gpid _ _ _
880+
| gpid == ps ^. pRootsL . grCommitteeL . prRootL ->
881+
Just (cgsCommittee cgs, ga : acc)
882+
UpdateCommittee (Ledger.SJust gpid) _ _ _ -> findRootRecursively (ga : acc) (unGovPurposeId gpid)
883+
_ -> Nothing
884+
885+
computeCommittee :: StrictMaybe (Committee StandardConway) -> [GovAction StandardConway] -> Maybe (Committee StandardConway)
886+
computeCommittee sCommittee actions =
887+
Ledger.strictMaybeToMaybe $ foldl applyCommitteeUpdate sCommittee actions
888+
889+
applyCommitteeUpdate scommittee = \case
890+
UpdateCommittee _ toRemove toAdd q -> Ledger.SJust $ updatedCommittee toRemove toAdd q scommittee
891+
_ -> Ledger.SNothing -- Should never happen since the accumulator only gets UpdateCommittee

0 commit comments

Comments
 (0)