3
3
{-# LANGUAGE DataKinds #-}
4
4
{-# LANGUAGE FlexibleInstances #-}
5
5
{-# LANGUAGE GADTs #-}
6
+ {-# LANGUAGE LambdaCase #-}
6
7
{-# LANGUAGE MultiParamTypeClasses #-}
7
8
{-# LANGUAGE OverloadedStrings #-}
8
9
{-# LANGUAGE RankNTypes #-}
@@ -29,6 +30,7 @@ module Cardano.DbSync.Ledger.State (
29
30
runLedgerStateWriteThread ,
30
31
getStakeSlice ,
31
32
getSliceMeta ,
33
+ findProposedCommittee ,
32
34
) where
33
35
34
36
import Cardano.BM.Trace (Trace , logInfo , logWarning )
@@ -856,3 +858,34 @@ findAdaPots = go
856
858
go [] = Nothing
857
859
go (LedgerAdaPots p : _) = Just p
858
860
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