@@ -43,9 +43,8 @@ import Cardano.DbSync.Util
4343import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
4444import Cardano.Ledger.Alonzo.Scripts
4545import qualified Cardano.Ledger.BaseTypes as Ledger
46- import qualified Cardano.Ledger.Core as Core
4746import Cardano.Ledger.Era (EraCrypto )
48- import qualified Cardano.Ledger.Shelley.API.Wallet as Shelley
47+ import Cardano.Ledger.Shelley.AdaPots ( AdaPots )
4948import Cardano.Ledger.Shelley.LedgerState (EpochState (.. ))
5049import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
5150import Cardano.Prelude hiding (atomically )
@@ -307,14 +306,14 @@ applyBlock env blk = do
307306 ! ledgerDB <- readStateUnsafe env
308307 let oldState = ledgerDbCurrent ledgerDB
309308 let ! result = applyBlk (ExtLedgerCfg (getTopLevelconfigHasLedger env)) blk (clsState oldState)
309+ let ! ledgerEvents = mapMaybe convertAuxLedgerEvent (lrEvents result)
310310 let ! newLedgerState = lrResult result
311311 ! details <- getSlotDetails env (ledgerState newLedgerState) time (cardanoBlockSlotNo blk)
312- let ! newEpoch = mkNewEpoch (clsState oldState) newLedgerState
312+ let ! newEpoch = mkNewEpoch (clsState oldState) newLedgerState (findAdaPots ledgerEvents)
313313 let ! newEpochBlockNo = applyToEpochBlockNo (isJust $ blockIsEBB blk) (isJust newEpoch) (clsEpochBlockNo oldState)
314314 let ! newState = CardanoLedgerState newLedgerState newEpochBlockNo
315315 let ! ledgerDB' = pushLedgerDB ledgerDB newState
316316 writeTVar (leStateVar env) (Strict. Just ledgerDB')
317- let ! ledgerEvents = mapMaybe convertAuxLedgerEvent (lrEvents result)
318317 let ! appResult =
319318 ApplyResult
320319 { apPrices = getPrices newState
@@ -336,16 +335,16 @@ applyBlock env blk = do
336335 Left err -> panic err
337336 Right result -> result
338337
339- mkNewEpoch :: ExtLedgerState CardanoBlock -> ExtLedgerState CardanoBlock -> Maybe Generic. NewEpoch
340- mkNewEpoch oldState newState =
338+ mkNewEpoch :: ExtLedgerState CardanoBlock -> ExtLedgerState CardanoBlock -> Maybe AdaPots -> Maybe Generic. NewEpoch
339+ mkNewEpoch oldState newState mPots =
341340 if ledgerEpochNo env newState /= ledgerEpochNo env oldState + 1
342341 then Nothing
343342 else
344343 Just $
345344 Generic. NewEpoch
346345 { Generic. neEpoch = ledgerEpochNo env newState
347346 , Generic. neIsEBB = isJust $ blockIsEBB blk
348- , Generic. neAdaPots = maybeToStrict $ getAdaPots newState
347+ , Generic. neAdaPots = maybeToStrict mPots
349348 , Generic. neEpochUpdate = Generic. epochUpdate newState
350349 }
351350
@@ -791,19 +790,6 @@ getRegisteredPoolShelley lState =
791790 Shelley. nesEs $
792791 Consensus. shelleyLedgerState lState
793792
794- -- We only compute 'AdaPots' for later eras. This is a time consuming
795- -- function and we only want to run it on epoch boundaries.
796- getAdaPots :: ExtLedgerState CardanoBlock -> Maybe Shelley. AdaPots
797- getAdaPots st =
798- case ledgerState st of
799- LedgerStateByron _ -> Nothing
800- LedgerStateShelley sts -> Just $ totalAdaPots sts
801- LedgerStateAllegra sta -> Just $ totalAdaPots sta
802- LedgerStateMary stm -> Just $ totalAdaPots stm
803- LedgerStateAlonzo sta -> Just $ totalAdaPots sta
804- LedgerStateBabbage stb -> Just $ totalAdaPots stb
805- LedgerStateConway _stc -> panic " TODO: Conway 3"
806-
807793ledgerEpochNo :: HasLedgerEnv -> ExtLedgerState CardanoBlock -> EpochNo
808794ledgerEpochNo env cls =
809795 case ledgerTipSlot (ledgerState cls) of
@@ -840,13 +826,6 @@ tickThenReapplyCheckHash cfg block lsb =
840826 , " ."
841827 ]
842828
843- totalAdaPots ::
844- forall p era .
845- Core. EraTxOut era =>
846- LedgerState (ShelleyBlock p era ) ->
847- Shelley. AdaPots
848- totalAdaPots = Shelley. totalAdaPotsES . Shelley. nesEs . Consensus. shelleyLedgerState
849-
850829getHeaderHash :: HeaderHash CardanoBlock -> ByteString
851830getHeaderHash bh = SBS. fromShort (Consensus. getOneEraHash bh)
852831
@@ -894,3 +873,10 @@ getPrices st = case ledgerState $ clsState st of
894873 ^. Alonzo. ppPricesL
895874 )
896875 _ -> Strict. Nothing
876+
877+ findAdaPots :: [LedgerEvent ] -> Maybe AdaPots
878+ findAdaPots = go
879+ where
880+ go [] = Nothing
881+ go (LedgerAdaPots p: _) = Just p
882+ go (_ : rest) = go rest
0 commit comments