@@ -382,6 +382,8 @@ instance DecCBOR QueryResultDRepStates where
382382-- queryGovState cardano-api wrapper
383383-- Also: cardano-cli:cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs:1617
384384-- CLI invocation
385+ --
386+ -- /O(1)/
385387queryGovState :: NewEpochState era -> GovState era
386388queryGovState nes = nes ^. nesEpochStateL . epochStateGovStateL
387389
@@ -392,12 +394,16 @@ queryGovState nes = nes ^. nesEpochStateL . epochStateGovStateL
392394-- queryConstitution cardano-api wrapper
393395-- Also: cardano-cli:cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs:1589
394396-- CLI invocation
397+ --
398+ -- /O(1)/
395399queryConstitution :: ConwayEraGov era => NewEpochState era -> QueryResultConstitution
396400queryConstitution nes = toQueryResultConstitution $ queryGovState nes ^. constitutionGovStateL
397401
398402-- | Query the constitution hash.
399403--
400404-- Convenience extraction — no corresponding standalone query in @ouroboros-consensus@.
405+ --
406+ -- /O(1)/
401407queryConstitutionHash ::
402408 ConwayEraGov era =>
403409 NewEpochState era ->
@@ -414,6 +420,8 @@ queryConstitutionHash nes =
414420-- CLI invocation
415421--
416422-- Empty 'Set' returns all proposals.
423+ --
424+ -- /O(g)/ where (g) is the proposals considered for ratification, Seq.filter.
417425queryProposals ::
418426 ConwayEraGov era =>
419427 NewEpochState era ->
@@ -438,19 +446,28 @@ queryProposals nes gids
438446-- queryRatifyState cardano-api wrapper
439447-- Also: cardano-cli:cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs:1645
440448-- CLI invocation
449+ --
450+ -- /O(P)/ where (P) is the DRep pulser completion cost, finishedPulserState.
441451queryRatifyState :: ConwayEraGov era => NewEpochState era -> RatifyState era
442452queryRatifyState = snd . finishedPulserState
443453
444454-- | Query committee members. Whenever the system is in No Confidence mode this query will
445455-- return no committee members.
446456-- Source: ouroboros-consensus:ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs:471
447457-- answerPureBlockQuery case for GetCommitteeMembersState
448- -- Also: cardano-api:cardano-api/src/Cardano/Api/Query/Internal/Expr.hs:452
458+ -- Also: cardano-api:cardano-api/src/Cardano/Api/Query/Internal/Expr.hs:454
449459-- queryCommitteeMembersState cardano-api wrapper
450460-- Also: cardano-cli:cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs:1887
451461-- CLI invocation
452462--
453463-- Empty 'Set' returns all matches (i.e. no filtering).
464+ --
465+ -- @
466+ -- O(P + m)
467+ -- @
468+ -- where,
469+ -- (P) is the DRep pulser completion cost, finishedPulserState
470+ -- (m) is the committee members (current + next + state), Map.union and Map.mapWithKey
454471queryCommitteeMembersState ::
455472 forall era .
456473 (ConwayEraGov era , ConwayEraCertState era ) =>
@@ -546,6 +563,8 @@ queryCommitteeMembersState coldCredsFilter hotCredsFilter statusFilter nes =
546563 }
547564
548565-- | Get the committee members that will be in effect at the next epoch boundary.
566+ --
567+ -- /O(P)/ where (P) is the DRep pulser completion cost, finishedPulserState.
549568getNextEpochCommitteeMembers ::
550569 ConwayEraGov era =>
551570 NewEpochState era ->
@@ -564,6 +583,13 @@ getNextEpochCommitteeMembers nes =
564583-- CLI invocation
565584--
566585-- Empty 'Set' returns all DReps.
586+ --
587+ -- @
588+ -- O(d + k)
589+ -- @
590+ -- where,
591+ -- (d) is the total registered DReps, Map.restrictKeys and Map.map
592+ -- (k) is the requested DRep credential set, Map.restrictKeys
567593queryDRepState ::
568594 ConwayEraCertState era =>
569595 NewEpochState era ->
@@ -590,6 +616,15 @@ queryDRepState nes creds =
590616-- queryDRepDelegations cardano-api wrapper (not publicly exported)
591617--
592618-- Empty 'Set' returns all DReps.
619+ --
620+ -- @
621+ -- O(d + k) when all requested DReps are DRepCredentials
622+ -- O(c) when AlwaysAbstain or AlwaysNoConfidence are requested
623+ -- @
624+ -- where,
625+ -- (d) is the registered DReps, Map.restrictKeys
626+ -- (k) is the requested DRep set, Map.restrictKeys
627+ -- (c) is the total staking credentials, Map.foldlWithKey' (full accounts scan)
593628queryDRepDelegations ::
594629 forall era .
595630 ConwayEraCertState era =>
@@ -637,6 +672,14 @@ queryDRepDelegations nes dreps =
637672-- CLI invocation
638673--
639674-- Empty 'Set' returns all DReps.
675+ --
676+ -- @
677+ -- O(P + d + k)
678+ -- @
679+ -- where,
680+ -- (P) is the DRep pulser completion cost, finishedPulserState
681+ -- (d) is the total DReps in the distribution, Map.map
682+ -- (k) is the requested DRep set, Map.restrictKeys
640683queryDRepStakeDistr ::
641684 ConwayEraGov era =>
642685 NewEpochState era ->
@@ -656,6 +699,15 @@ queryDRepStakeDistr nes creds
656699-- No consensus BlockQuery constructor exists yet (GetRegisteredDRepStakeDistr was planned but not added).
657700--
658701-- Empty 'Set' returns all registered DReps.
702+ --
703+ -- @
704+ -- O(d + k + d * c_avg * log(c))
705+ -- @
706+ -- where,
707+ -- (d) is the registered DReps, Map.restrictKeys and Map.foldlWithKey'
708+ -- (k) is the requested DRep credential set, Map.restrictKeys
709+ -- (c_avg) is the average delegators per DRep, foldMap over drepDelegs
710+ -- (c) is the total staking credentials, Map.lookup in instantStake per delegator
659711queryRegisteredDRepStakeDistr ::
660712 (ConwayEraGov era , ConwayEraCertState era ) =>
661713 NewEpochState era ->
@@ -683,13 +735,20 @@ queryRegisteredDRepStakeDistr nes creds =
683735-- | Query the DRep delegatee for each given staking credential.
684736-- Source: ouroboros-consensus:ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs:457
685737-- answerPureBlockQuery case for GetDRepStakeDistr (partial — delegatees extracted separately)
686- -- Also: cardano-api:cardano-api/src/Cardano/Api/Query/Internal/Expr.hs:459
738+ -- Also: cardano-api:cardano-api/src/Cardano/Api/Query/Internal/Expr.hs:469
687739-- queryStakeVoteDelegatees cardano-api wrapper
688740-- Also: cardano-cli:cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs:1042
689741-- CLI invocation
690742--
691743-- Returns the DRep each credential has delegated to. Credentials with no
692744-- DRep delegation are omitted from the result. Empty 'Set' returns all.
745+ --
746+ -- @
747+ -- O(c + k)
748+ -- @
749+ -- where,
750+ -- (c) is the total staking credentials, Map.restrictKeys
751+ -- (k) is the requested credential set, Map.restrictKeys
693752queryDRepDelegatees ::
694753 (EraCertState era , ConwayEraAccounts era ) =>
695754 NewEpochState era ->
@@ -704,6 +763,8 @@ queryDRepDelegatees nes creds =
704763
705764-- | Force the DRep pulser to completion and return the resulting snapshot and
706765-- ratify state. Shared across governance query sub-modules.
766+ --
767+ -- /O(P)/ where (P) is the remaining DRep pulser work, amortised across the epoch.
707768finishedPulserState ::
708769 ConwayEraGov era =>
709770 NewEpochState era ->
0 commit comments