@@ -214,19 +214,19 @@ readStateUnsafe env = do
214
214
Strict. Nothing -> throwSTM $ userError " LedgerState.readStateUnsafe: Ledger state is not found"
215
215
Strict. Just st -> pure st
216
216
217
- applyBlockAndSnapshot :: HasLedgerEnv -> CardanoBlock -> Bool -> IO (ApplyResult , Bool )
218
- applyBlockAndSnapshot ledgerEnv blk isCons = do
219
- (oldState, appResult) <- applyBlock ledgerEnv blk
217
+ applyBlockAndSnapshot :: Trace IO Text -> HasLedgerEnv -> CardanoBlock -> Bool -> IO (ApplyResult , Bool )
218
+ applyBlockAndSnapshot trce ledgerEnv blk isCons = do
219
+ (oldState, appResult) <- applyBlock trce ledgerEnv blk
220
220
tookSnapshot <- storeSnapshotAndCleanupMaybe ledgerEnv oldState appResult (blockNo blk) isCons (isSyncedWithinSeconds (apSlotDetails appResult) 600 )
221
221
pure (appResult, tookSnapshot)
222
222
223
223
-- The function 'tickThenReapply' does zero validation, so add minimal validation ('blockPrevHash'
224
224
-- matches the tip hash of the 'LedgerState'). This was originally for debugging but the check is
225
225
-- cheap enough to keep.
226
- applyBlock :: HasLedgerEnv -> CardanoBlock -> IO (CardanoLedgerState , ApplyResult )
227
- applyBlock env blk = do
226
+ applyBlock :: Trace IO Text -> HasLedgerEnv -> CardanoBlock -> IO (CardanoLedgerState , ApplyResult )
227
+ applyBlock trce env blk = do
228
228
time <- getCurrentTime
229
- atomically $ do
229
+ (oldState, newState, intermediateResults) <- atomically $ do
230
230
! ledgerDB <- readStateUnsafe env
231
231
let oldState = ledgerDbCurrent ledgerDB
232
232
! result <- fromEitherSTM $ tickThenReapplyCheckHash (ExtLedgerCfg (getTopLevelconfigHasLedger env)) blk (clsState oldState)
@@ -239,24 +239,29 @@ applyBlock env blk = do
239
239
let ! newState = CardanoLedgerState newLedgerState newEpochBlockNo
240
240
let ! ledgerDB' = pushLedgerDB ledgerDB newState
241
241
writeTVar (leStateVar env) (Strict. Just ledgerDB')
242
- let ! appResult =
243
- if leUseLedger env
244
- then
245
- ApplyResult
246
- { apPrices = getPrices newState
247
- , apGovExpiresAfter = getGovExpiration newState
248
- , apPoolsRegistered = getRegisteredPools oldState
249
- , apNewEpoch = maybeToStrict newEpoch
250
- , apOldLedger = Strict. Just oldState
251
- , apDeposits = maybeToStrict $ Generic. getDeposits newLedgerState
252
- , apSlotDetails = details
253
- , apStakeSlice = getStakeSlice env newState False
254
- , apEvents = ledgerEvents
255
- , apGovActionState = getGovState newLedgerState
256
- , apDepositsMap = DepositsMap deposits
257
- }
258
- else defaultApplyResult details
259
- pure (oldState, appResult)
242
+ pure (oldState, newState, (ledgerEvents, deposits, details, newEpoch))
243
+ stakeSlices <- liftIO $ getStakeSlice trce env newState False
244
+ appResult <- atomically $ do
245
+ let (ledgerEvents, deposits, details, newEpoch) = intermediateResults
246
+ pure $
247
+ if leUseLedger env
248
+ then
249
+ ApplyResult
250
+ { apPrices = getPrices newState
251
+ , apGovExpiresAfter = getGovExpiration newState
252
+ , apPoolsRegistered = getRegisteredPools oldState
253
+ , apNewEpoch = maybeToStrict newEpoch
254
+ , apOldLedger = Strict. Just oldState
255
+ , apDeposits = maybeToStrict $ Generic. getDeposits (clsState newState)
256
+ , apSlotDetails = details
257
+ , apStakeSlice = stakeSlices
258
+ , apEvents = ledgerEvents
259
+ , apGovActionState = getGovState (clsState newState)
260
+ , apDepositsMap = DepositsMap deposits
261
+ }
262
+ else defaultApplyResult details
263
+
264
+ pure (oldState, appResult)
260
265
where
261
266
mkOnNewEpoch :: ExtLedgerState CardanoBlock -> ExtLedgerState CardanoBlock -> Maybe AdaPots -> Either SyncNodeError (Maybe Generic. NewEpoch )
262
267
mkOnNewEpoch oldState newState mPots = do
@@ -305,16 +310,17 @@ getGovState ls = case ledgerState ls of
305
310
Just $ Consensus. shelleyLedgerState cls ^. Shelley. newEpochStateGovStateL
306
311
_ -> Nothing
307
312
308
- getStakeSlice :: HasLedgerEnv -> CardanoLedgerState -> Bool -> Generic. StakeSliceRes
309
- getStakeSlice env cls isMigration =
313
+ getStakeSlice :: Trace IO Text -> HasLedgerEnv -> CardanoLedgerState -> Bool -> IO Generic. StakeSliceRes
314
+ getStakeSlice trce env cls isMigration =
310
315
case clsEpochBlockNo cls of
311
316
EpochBlockNo n ->
312
317
Generic. getStakeSlice
318
+ trce
313
319
(leProtocolInfo env)
314
320
n
315
321
(clsState cls)
316
322
isMigration
317
- _ -> Generic. NoSlices
323
+ _ -> pure Generic. NoSlices
318
324
319
325
getSliceMeta :: Generic. StakeSliceRes -> Maybe (Bool , EpochNo )
320
326
getSliceMeta (Generic. Slice (Generic. StakeSlice epochNo _) isFinal) = Just (isFinal, epochNo)
0 commit comments