@@ -43,9 +43,8 @@ import Cardano.DbSync.Util
43
43
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
44
44
import Cardano.Ledger.Alonzo.Scripts
45
45
import qualified Cardano.Ledger.BaseTypes as Ledger
46
- import qualified Cardano.Ledger.Core as Core
47
46
import Cardano.Ledger.Era (EraCrypto )
48
- import qualified Cardano.Ledger.Shelley.API.Wallet as Shelley
47
+ import Cardano.Ledger.Shelley.AdaPots ( AdaPots )
49
48
import Cardano.Ledger.Shelley.LedgerState (EpochState (.. ))
50
49
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
51
50
import Cardano.Prelude hiding (atomically )
@@ -307,14 +306,14 @@ applyBlock env blk = do
307
306
! ledgerDB <- readStateUnsafe env
308
307
let oldState = ledgerDbCurrent ledgerDB
309
308
let ! result = applyBlk (ExtLedgerCfg (getTopLevelconfigHasLedger env)) blk (clsState oldState)
309
+ let ! ledgerEvents = mapMaybe convertAuxLedgerEvent (lrEvents result)
310
310
let ! newLedgerState = lrResult result
311
311
! details <- getSlotDetails env (ledgerState newLedgerState) time (cardanoBlockSlotNo blk)
312
- let ! newEpoch = mkNewEpoch (clsState oldState) newLedgerState
312
+ let ! newEpoch = mkNewEpoch (clsState oldState) newLedgerState (findAdaPots ledgerEvents)
313
313
let ! newEpochBlockNo = applyToEpochBlockNo (isJust $ blockIsEBB blk) (isJust newEpoch) (clsEpochBlockNo oldState)
314
314
let ! newState = CardanoLedgerState newLedgerState newEpochBlockNo
315
315
let ! ledgerDB' = pushLedgerDB ledgerDB newState
316
316
writeTVar (leStateVar env) (Strict. Just ledgerDB')
317
- let ! ledgerEvents = mapMaybe convertAuxLedgerEvent (lrEvents result)
318
317
let ! appResult =
319
318
ApplyResult
320
319
{ apPrices = getPrices newState
@@ -336,16 +335,16 @@ applyBlock env blk = do
336
335
Left err -> panic err
337
336
Right result -> result
338
337
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 =
341
340
if ledgerEpochNo env newState /= ledgerEpochNo env oldState + 1
342
341
then Nothing
343
342
else
344
343
Just $
345
344
Generic. NewEpoch
346
345
{ Generic. neEpoch = ledgerEpochNo env newState
347
346
, Generic. neIsEBB = isJust $ blockIsEBB blk
348
- , Generic. neAdaPots = maybeToStrict $ getAdaPots newState
347
+ , Generic. neAdaPots = maybeToStrict mPots
349
348
, Generic. neEpochUpdate = Generic. epochUpdate newState
350
349
}
351
350
@@ -791,19 +790,6 @@ getRegisteredPoolShelley lState =
791
790
Shelley. nesEs $
792
791
Consensus. shelleyLedgerState lState
793
792
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
-
807
793
ledgerEpochNo :: HasLedgerEnv -> ExtLedgerState CardanoBlock -> EpochNo
808
794
ledgerEpochNo env cls =
809
795
case ledgerTipSlot (ledgerState cls) of
@@ -840,13 +826,6 @@ tickThenReapplyCheckHash cfg block lsb =
840
826
, " ."
841
827
]
842
828
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
-
850
829
getHeaderHash :: HeaderHash CardanoBlock -> ByteString
851
830
getHeaderHash bh = SBS. fromShort (Consensus. getOneEraHash bh)
852
831
@@ -894,3 +873,10 @@ getPrices st = case ledgerState $ clsState st of
894
873
^. Alonzo. ppPricesL
895
874
)
896
875
_ -> 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