Skip to content

Commit

Permalink
feature(cardano-db-sync): Replace DRep pulsing state in ledger state
Browse files Browse the repository at this point in the history
Before retrieving the DRep pulsing state, force its evaluation, then
save it to the ledger state. This will prevent us from unnecessarily
recalculating it.
  • Loading branch information
sgillespie committed Apr 29, 2024
1 parent 552e162 commit 480e395
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import qualified Data.Strict.Maybe as Strict
import qualified Data.Text as Text
import Data.Time.Clock (UTCTime, diffUTCTime, getCurrentTime)
import GHC.IO.Exception (userError)
import Lens.Micro ((^.))
import Lens.Micro ((%~), (^.), (^?))
import Ouroboros.Consensus.Block (
CodecConfig,
Point (..),
Expand Down Expand Up @@ -225,7 +225,7 @@ applyBlock env blk = do
!result <- fromEitherSTM $ tickThenReapplyCheckHash (ExtLedgerCfg (getTopLevelconfigHasLedger env)) blk (clsState oldState)
let ledgerEventsFull = mapMaybe (convertAuxLedgerEvent (leHasRewards env)) (lrEvents result)
let (ledgerEvents, deposits) = splitDeposits ledgerEventsFull
let !newLedgerState = lrResult result
let !newLedgerState = finaliseDrepDistr (lrResult result)
!details <- getSlotDetails env (ledgerState newLedgerState) time (cardanoBlockSlotNo blk)
!newEpoch <- fromEitherSTM $ mkNewEpoch (clsState oldState) newLedgerState (findAdaPots ledgerEvents)
let !newEpochBlockNo = applyToEpochBlockNo (isJust $ blockIsEBB blk) (isJust newEpoch) (clsEpochBlockNo oldState)
Expand Down Expand Up @@ -280,11 +280,12 @@ applyBlock env blk = do
applyToEpochBlockNo _ _ GenesisEpochBlockNo = EpochBlockNo 0
applyToEpochBlockNo _ _ EBBEpochBlockNo = EpochBlockNo 0

getDrepDistr :: ExtLedgerState CardanoBlock -> Maybe (DRepPulsingState StandardConway)
getDrepDistr ls = case ledgerState ls of
LedgerStateConway cls ->
Just $ Consensus.shelleyLedgerState cls ^. Shelley.newEpochStateDRepPulsingStateL
_ -> Nothing
getDrepDistr :: ExtLedgerState CardanoBlock -> Maybe (DRepPulsingState StandardConway)
getDrepDistr ls = ls ^? newEpochStateT . Shelley.newEpochStateDRepPulsingStateL

finaliseDrepDistr :: ExtLedgerState CardanoBlock -> ExtLedgerState CardanoBlock
finaliseDrepDistr ledger =
ledger & newEpochStateT %~ forceDRepPulsingState @StandardConway

getEnacted :: ExtLedgerState CardanoBlock -> Maybe (EnactState StandardConway)
getEnacted ls = case ledgerState ls of
Expand Down

0 comments on commit 480e395

Please sign in to comment.