Skip to content

Commit

Permalink
Fix performance regression of `GetFilteredDelegationsAndRewardAccount…
Browse files Browse the repository at this point in the history
…s` (#104)

# Description

Addition of deposits made `rewView` extremly expensive, because it now
iterates the full staking credentials Map. The proper way to do it is to
restrict the Map first and then do the conversion.

This will very likely fix the timeout issue in
CardanoSolutions/ogmios#313
  • Loading branch information
amesgen authored May 23, 2023
2 parents 68649f7 + 1e47302 commit 1a421bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->


### Patch

- Fix performance regression of `GetFilteredDelegationsAndRewardAccounts` query

<!--
### Non-Breaking
- A bullet item for the Non-Breaking category.
-->
<!--
### Breaking
- A bullet item for the Breaking category.
-->
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import qualified Cardano.Ledger.Shelley.LedgerState as SL (RewardAccounts)
import qualified Cardano.Ledger.Shelley.PParams as SL (emptyPPPUpdates)
import qualified Cardano.Ledger.Shelley.RewardProvenance as SL
(RewardProvenance)
import Cardano.Ledger.UMap (View (..), domRestrictedView, rewView)
import Cardano.Ledger.UMap (UMap (..), rdReward, tripDelegation,
tripReward)
import Codec.CBOR.Decoding (Decoder)
import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
Expand Down Expand Up @@ -589,10 +590,12 @@ getFilteredDelegationsAndRewardAccounts ::
getFilteredDelegationsAndRewardAccounts ss creds =
(filteredDelegations, filteredRwdAcnts)
where
u = SL.dsUnified $ getDState ss
UMap umElems _ = SL.dsUnified $ getDState ss
umElemsRestricted = Map.restrictKeys umElems creds

filteredDelegations = domRestrictedView creds $ Delegations u
filteredRwdAcnts = rewView u `Map.restrictKeys` creds
filteredDelegations = Map.mapMaybe tripDelegation umElemsRestricted
filteredRwdAcnts =
Map.mapMaybe (\e -> fromCompact . rdReward <$> tripReward e) umElemsRestricted

{-------------------------------------------------------------------------------
Serialisation
Expand Down

0 comments on commit 1a421bd

Please sign in to comment.