|
2 | 2 | {-# LANGUAGE DeriveAnyClass #-} |
3 | 3 | {-# LANGUAGE DeriveGeneric #-} |
4 | 4 | {-# LANGUAGE DerivingStrategies #-} |
| 5 | +{-# LANGUAGE GADTs #-} |
5 | 6 | {-# LANGUAGE LambdaCase #-} |
6 | 7 | {-# LANGUAGE NamedFieldPuns #-} |
7 | 8 | {-# LANGUAGE OverloadedStrings #-} |
@@ -34,7 +35,7 @@ import qualified Cardano.BM.Configuration.Model as CM |
34 | 35 | import Cardano.BM.Setup (setupTrace_) |
35 | 36 | import Cardano.BM.Trace (Trace, logDebug, logError) |
36 | 37 |
|
37 | | -import Cardano.Api (ChainPoint) |
| 38 | +import qualified Cardano.Api as C |
38 | 39 | import Cardano.Protocol.Socket.Client (ChainSyncEvent (..), runChainSync) |
39 | 40 | import CommandLine (AppConfig (..), Command (..), applyOverrides, cmdWithHelpParser) |
40 | 41 | import qualified Config |
@@ -69,31 +70,38 @@ runChainIndex runReq effect = do |
69 | 70 |
|
70 | 71 | chainSyncHandler |
71 | 72 | :: RunRequirements |
| 73 | + -> Bool -- TODO: Needs to be a lot clearer |
72 | 74 | -> ChainSyncEvent |
73 | 75 | -> Slot |
74 | 76 | -> IO () |
75 | | -chainSyncHandler runReq |
76 | | - (RollForward block _) _ = do |
| 77 | +chainSyncHandler runReq alonzoOnward |
| 78 | + (RollForward block@(C.BlockInMode _ eraInMode) _) _ = do |
77 | 79 | let ciBlock = fromCardanoBlock block |
78 | 80 | case ciBlock of |
79 | 81 | Left err -> |
80 | 82 | logError (trace runReq) (ConversionFailed err) |
81 | | - Right txs -> |
82 | | - void $ runChainIndex runReq $ appendBlock (tipFromCardanoBlock block) txs |
83 | | -chainSyncHandler runReq |
| 83 | + Right txs -> void $ |
| 84 | + let toStoreTxs = not alonzoOnward || case eraInMode of |
| 85 | + C.ByronEraInCardanoMode -> False |
| 86 | + C.ShelleyEraInCardanoMode -> False |
| 87 | + C.AllegraEraInCardanoMode -> False |
| 88 | + C.MaryEraInCardanoMode -> False |
| 89 | + C.AlonzoEraInCardanoMode -> True |
| 90 | + in runChainIndex runReq $ appendBlock (tipFromCardanoBlock block) txs toStoreTxs |
| 91 | +chainSyncHandler runReq _ |
84 | 92 | (RollBackward point _) _ = do |
85 | 93 | putStr "Rolling back to " |
86 | 94 | print point |
87 | 95 | -- Do we really want to pass the tip of the new blockchain to the |
88 | 96 | -- rollback function (rather than the point where the chains diverge)? |
89 | 97 | void $ runChainIndex runReq $ rollback (fromCardanoPoint point) |
90 | | -chainSyncHandler runReq |
| 98 | +chainSyncHandler runReq _ |
91 | 99 | (Resume point) _ = do |
92 | 100 | putStr "Resuming from " |
93 | 101 | print point |
94 | 102 | void $ runChainIndex runReq $ resumeSync $ fromCardanoPoint point |
95 | 103 |
|
96 | | -showResumePoints :: [ChainPoint] -> String |
| 104 | +showResumePoints :: [C.ChainPoint] -> String |
97 | 105 | showResumePoints = \case |
98 | 106 | [] -> "none" |
99 | 107 | [x] -> showPoint x |
@@ -167,7 +175,7 @@ main = do |
167 | 175 | (Config.cicSlotConfig config) |
168 | 176 | (Config.cicNetworkId config) |
169 | 177 | resumePoints |
170 | | - (chainSyncHandler runReq) |
| 178 | + (chainSyncHandler runReq (Config.cicAlonzoOnward config)) |
171 | 179 |
|
172 | 180 | putStrLn $ "Starting webserver on port " <> show (Config.cicPort config) |
173 | 181 | Server.serveChainIndexQueryServer (Config.cicPort config) runReq |
0 commit comments