Skip to content

Commit be7e2f5

Browse files
committed
feature(cardano-db-sync): Replace DRep pulsing state in ledger state
Before retrieving the DRep pulsing state, force its evaluation, then save it to the ledger state. This will prevent us from unnecessarily recalculating it.
1 parent 61b87bf commit be7e2f5

File tree

1 file changed

+9
-8
lines changed
  • cardano-db-sync/src/Cardano/DbSync/Ledger

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import qualified Data.Strict.Maybe as Strict
8484
import qualified Data.Text as Text
8585
import Data.Time.Clock (UTCTime, diffUTCTime, getCurrentTime)
8686
import GHC.IO.Exception (userError)
87-
import Lens.Micro ((^.))
87+
import Lens.Micro ((%~), (^.), (^?))
8888
import Ouroboros.Consensus.Block (
8989
CodecConfig,
9090
Point (..),
@@ -226,7 +226,7 @@ applyBlock env blk = do
226226
!result <- fromEitherSTM $ tickThenReapplyCheckHash (ExtLedgerCfg (getTopLevelconfigHasLedger env)) blk (clsState oldState)
227227
let ledgerEventsFull = mapMaybe (convertAuxLedgerEvent (leHasRewards env)) (lrEvents result)
228228
let (ledgerEvents, deposits) = splitDeposits ledgerEventsFull
229-
let !newLedgerState = lrResult result
229+
let !newLedgerState = finaliseDrepDistr (lrResult result)
230230
!details <- getSlotDetails env (ledgerState newLedgerState) time (cardanoBlockSlotNo blk)
231231
!newEpoch <- fromEitherSTM $ mkNewEpoch (clsState oldState) newLedgerState (findAdaPots ledgerEvents)
232232
let !newEpochBlockNo = applyToEpochBlockNo (isJust $ blockIsEBB blk) (isJust newEpoch) (clsEpochBlockNo oldState)
@@ -282,18 +282,19 @@ applyBlock env blk = do
282282
applyToEpochBlockNo _ _ GenesisEpochBlockNo = EpochBlockNo 0
283283
applyToEpochBlockNo _ _ EBBEpochBlockNo = EpochBlockNo 0
284284

285+
getDrepState :: ExtLedgerState CardanoBlock -> Maybe (DRepPulsingState StandardConway)
286+
getDrepState ls = ls ^? newEpochStateT . Shelley.newEpochStateDRepPulsingStateL
287+
288+
finaliseDrepDistr :: ExtLedgerState CardanoBlock -> ExtLedgerState CardanoBlock
289+
finaliseDrepDistr ledger =
290+
ledger & newEpochStateT %~ forceDRepPulsingState @StandardConway
291+
285292
getEnacted :: ExtLedgerState CardanoBlock -> Maybe (GovRelation StrictMaybe StandardConway)
286293
getEnacted ls = case ledgerState ls of
287294
LedgerStateConway cls ->
288295
Just $ govStatePrevGovActionIds $ Consensus.shelleyLedgerState cls ^. Shelley.newEpochStateGovStateL
289296
_ -> Nothing
290297

291-
getDrepState :: ExtLedgerState CardanoBlock -> Maybe (DRepPulsingState StandardConway)
292-
getDrepState ls = case ledgerState ls of
293-
LedgerStateConway cls ->
294-
Just $ Consensus.shelleyLedgerState cls ^. Shelley.newEpochStateDRepPulsingStateL
295-
_ -> Nothing
296-
297298
getCommittee :: ExtLedgerState CardanoBlock -> Maybe (StrictMaybe (Committee StandardConway))
298299
getCommittee ls = case ledgerState ls of
299300
LedgerStateConway cls ->

0 commit comments

Comments
 (0)