Skip to content

Commit 96c5bef

Browse files
authored
PLT-9070 - Marconi components; further generalisation of index running machinery (#285)
* PLT-9070 - Allow monadic preprocessing * PLT-9070 - Loosen runEmitterAndConsumer arg reqs * PLT-9070 - Generalise and expose stream emitter * PLT-9070 - Loosen streamEmitter a bit more * PLT-9070 - More experimental changes * PLT-9070 - More experimentation with stateful streaming * PLT-9070 - Removed the transformer wackiness * PLT-9070 - Remove specialised config dependency from streamEmitter * PLT-9070 - More messy experimenting * PLT-9070 - Use optparse-applicative-fork * PLT-9070 - Try to dedupe the streaming changes * PLT-9070 - Added accidentally removed comment back in * PLT-9070 - Tiny comments * PLT-9070 - optparse-applicative-fork in marconi-chain-index-legacy * PLT-9070 - Updated golden files * PLT-9070 - Missed some golden files * PLT-9070 - Dummy file for missing required folder * PLT-9070 - Added golden files back in * PLT-9070 - Moved the golden files into the right folder * Revert "PLT-9070 - Moved the golden files into the right folder" This reverts commit c3460fe. * Revert "PLT-9070 - Added golden files back in" This reverts commit 644a50b. * Revert "PLT-9070 - Dummy file for missing required folder" This reverts commit 97d9c73. * Revert "PLT-9070 - Missed some golden files" This reverts commit adc4c04. * Revert "PLT-9070 - Updated golden files" This reverts commit 4cea62d. * Revert "PLT-9070 - optparse-applicative-fork in marconi-chain-index-legacy" This reverts commit 3aa082b. * PLT-9070 - Remove dependency on optparse-applicative-fork * PLT-9070 - Removed unneeded language ext
1 parent 3944363 commit 96c5bef

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

marconi-cardano-core/src/Marconi/Cardano/Core/Runner.hs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module Marconi.Cardano.Core.Runner (
1212
-- * Runner
1313
runIndexerOnChainSync,
1414
runIndexerOnSnapshot,
15+
runEmitterAndConsumer,
16+
17+
-- * Emitters
18+
streamEmitter,
1519

1620
-- ** Runner Config
1721
RunIndexerConfig (RunIndexerConfig),
@@ -133,8 +137,9 @@ runIndexerOnChainSync
133137
runIndexerOnChainSync config indexer = do
134138
void $
135139
runEmitterAndConsumer
140+
(eventPreprocessing ^. runIndexerExtractTipDistance)
141+
(eventPreprocessing ^. runIndexerExtractBlockNo)
136142
securityParam
137-
eventPreprocessing
138143
(chainSyncEventEmitter config indexer)
139144
Core.CloseOn
140145
where
@@ -155,9 +160,10 @@ runIndexerOnSnapshot
155160
-> IO (Concurrent.MVar (indexer event))
156161
runIndexerOnSnapshot config indexer stream =
157162
runEmitterAndConsumer
163+
(eventPreprocessing ^. runIndexerExtractTipDistance)
164+
(eventPreprocessing ^. runIndexerExtractBlockNo)
158165
securityParam
159-
eventPreprocessing
160-
(streamBlockEventEmitter config indexer stream)
166+
(streamEmitter (eventPreprocessing ^. runIndexerPreprocessEvent) securityParam indexer stream)
161167
Core.CloseOff
162168
where
163169
securityParam = Lens.view runIndexerOnSnapshotConfigSecurityParam config
@@ -179,14 +185,18 @@ runEmitterAndConsumer
179185
, Core.IsIndex (ExceptT Core.IndexerError IO) event indexer
180186
, Core.Closeable IO indexer
181187
)
182-
=> SecurityParam
183-
-> RunIndexerEventPreprocessing rawEvent event
188+
=> (event -> Maybe Word)
189+
-- ^ A tip extraction function
190+
-> (event -> Maybe C.BlockNo)
191+
-- ^ A block extraction function
192+
-> SecurityParam
184193
-> IO (EventEmitter indexer event a)
185194
-> Core.CloseSwitch
186195
-> IO (Concurrent.MVar (indexer event))
187196
runEmitterAndConsumer
197+
tipExtractor
198+
blockExtractor
188199
securityParam
189-
eventPreprocessing
190200
eventEmitter
191201
closeSwitch =
192202
do
@@ -197,7 +207,11 @@ runEmitterAndConsumer
197207
where
198208
consumer queue indexerMVar = do
199209
Core.processQueue
200-
(stablePointComputation securityParam eventPreprocessing)
210+
( stablePointComputation
211+
tipExtractor
212+
blockExtractor
213+
securityParam
214+
)
201215
Map.empty
202216
queue
203217
indexerMVar
@@ -245,30 +259,31 @@ chainSyncEventEmitter
245259
instead of consuming the stream a caller will consume the created queue.
246260
The reason behind this is to provide the same interface as 'chainSyncEventEmitter'.
247261
-}
248-
streamBlockEventEmitter
262+
streamEmitter
249263
:: (Core.Point event ~ C.ChainPoint)
250-
=> RunIndexerOnSnapshotConfig BlockEvent event
264+
=> (pre -> [Core.ProcessedInput C.ChainPoint event])
265+
-- ^ A preprocessing function
266+
-> SecurityParam
251267
-> indexer event
252-
-> S.Stream (S.Of BlockEvent) IO ()
268+
-> S.Stream (S.Of pre) IO ()
253269
-> IO (EventEmitter indexer event ())
254-
streamBlockEventEmitter config indexer stream = do
270+
streamEmitter processEvent securityParam indexer stream = do
255271
queue <- STM.newTBQueueIO $ fromIntegral securityParam
256272
indexerMVar <- Concurrent.newMVar indexer
257-
let processEvent = eventProcessing ^. runIndexerPreprocessEvent
258-
emitEvents = mkEventStream processEvent queue stream
273+
let emitEvents = mkEventStream processEvent queue stream
259274
pure EventEmitter{queue, indexerMVar, emitEvents}
260-
where
261-
securityParam = Lens.view runIndexerOnSnapshotConfigSecurityParam config
262-
eventProcessing = Lens.view runIndexerOnSnapshotConfigEventProcessing config
263275

264276
stablePointComputation
265-
:: SecurityParam
266-
-> RunIndexerEventPreprocessing rawEvent event
277+
:: (event -> Maybe Word)
278+
-- ^ A tip extraction function
279+
-> (event -> Maybe C.BlockNo)
280+
-- ^ A block extraction function
281+
-> SecurityParam
267282
-> Core.Timed C.ChainPoint (Maybe event)
268283
-> State (Map C.BlockNo C.ChainPoint) (Maybe C.ChainPoint)
269-
stablePointComputation securityParam preprocessing (Core.Timed point event) = do
270-
let distanceM = preprocessing ^. runIndexerExtractTipDistance =<< event
271-
blockNoM = preprocessing ^. runIndexerExtractBlockNo =<< event
284+
stablePointComputation tipExtractor blockExtractor securityParam (Core.Timed point event) = do
285+
let distanceM = tipExtractor =<< event
286+
blockNoM = blockExtractor =<< event
272287
case (distanceM, blockNoM) of
273288
(Just distance, Just blockNo) ->
274289
if distance > fromIntegral securityParam
@@ -290,8 +305,8 @@ getBlockNo (C.BlockInMode block _eraInMode) =
290305

291306
-- | Event preprocessing, to ease the coordinator work
292307
mkEventStream
293-
:: (inputEvent -> [Core.ProcessedInput (Core.Point inputEvent) outputEvent])
294-
-> STM.TBQueue (Core.ProcessedInput (Core.Point inputEvent) outputEvent)
308+
:: (inputEvent -> [Core.ProcessedInput (Core.Point outputEvent) outputEvent])
309+
-> STM.TBQueue (Core.ProcessedInput (Core.Point outputEvent) outputEvent)
295310
-> S.Stream (S.Of inputEvent) IO r
296311
-> IO r
297312
mkEventStream processEvent q =
@@ -321,7 +336,10 @@ withDistanceAndTipPreprocessor =
321336
getDistance _ = Nothing
322337
blockNoFromBlockEvent (TipAndBlock _ (Just event)) = Just . getBlockNo . blockInMode $ getEvent event
323338
blockNoFromBlockEvent _ = Nothing
324-
in RunIndexerEventPreprocessing extractChainTipAndAddDistance blockNoFromBlockEvent getDistance
339+
in RunIndexerEventPreprocessing
340+
extractChainTipAndAddDistance
341+
blockNoFromBlockEvent
342+
getDistance
325343

326344
withNoPreprocessor :: RunIndexerEventPreprocessing (ChainSyncEvent BlockEvent) BlockEvent
327345
withNoPreprocessor =

marconi-cardano-indexers/test-lib/Test/Integration.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ unboundedValidityRange :: (C.TxValidityLowerBound C.BabbageEra, C.TxValidityUppe
9393
unboundedValidityRange = (C.TxValidityNoLowerBound, C.TxValidityNoUpperBound C.ValidityNoUpperBoundInBabbageEra)
9494

9595
{- Transaction operations -}
96-
9796
validateAndSubmitTx
9897
:: (MonadIO m)
9998
=> C.LocalNodeConnectInfo C.CardanoMode

0 commit comments

Comments
 (0)