@@ -15,30 +15,21 @@ import Cardano.Crypto.Init (cryptoInit)
1515import  Cardano.Tools.DBAnalyser.Block.Cardano  (configFile )
1616import  Cardano.Tools.DBAnalyser.HasAnalysis  (mkProtocolInfo )
1717import  Control.Concurrent 
18- import  Control.Exception 
1918import  Control.Monad  (forever , void )
2019import  Control.Monad.Except 
2120import  DBAnalyser.Parsers 
22- import  qualified  Data.Aeson  as  Aeson 
2321import  qualified  Data.List  as  L 
24- import  qualified  Data.Text  as  Text 
25- import  qualified  Debug.Trace  as  Debug 
26- import  GHC.TypeLits  (Symbol )
2722import  Main.Utf8 
2823import  Options.Applicative 
2924import  Options.Applicative.Help  (Doc , line )
3025import  Ouroboros.Consensus.Cardano.SnapshotConversion 
26+ import  Ouroboros.Consensus.Config 
27+ import  Ouroboros.Consensus.Node.ProtocolInfo 
3128import  Ouroboros.Consensus.Storage.LedgerDB.Snapshots 
3229import  System.Exit 
3330import  System.FSNotify 
3431import  System.FilePath 
3532
36- --  |  FilePaths annotated with the purpose 
37- newtype  FilePath'  (s  ::  Symbol ) =  FP  { rawFilePath  ::  FilePath } 
38- 
39- instance  Show FilePath'  s ) where 
40-   show  =  rawFilePath
41- 
4233data  Config 
4334  =  --  |  Run in daemon mode, with an output directory 
4435    DaemonConfig  (FilePath'  " OutDir" 
@@ -49,19 +40,11 @@ data Config
4940      --  |  Which format the output snapshot must be in 
5041      Format 
5142
52- --  |  Information inferred from the config file 
53- data  FromConfigFile 
54-   =  FromConfigFile 
55-       --  |  The input format once supplied with a particular snapshot 
56-       (FilePath'  " Snapshot" ->  Format )
57-       --  |  The directory of snapshots, to be watched by inotify 
58-       (FilePath'  " Snapshots" 
59- 
6043main  ::  IO () 
6144main =  withStdTerminalHandles $  do 
6245  cryptoInit
6346  (conf, args) <-  getCommandLineConfig
64-   pInfo <-  mkProtocolInfo args
47+   pInfo <-  configCodec  .  pInfoConfig  <$>   mkProtocolInfo args
6548  FromConfigFile  inFormat ledgerDbPath <-  getFormatFromConfig (FP  $  configFile args)
6649  case  conf of 
6750    NoDaemonConfig  f t ->  do 
@@ -219,115 +202,3 @@ parsePath optName strHelp =
219202        , metavar " PATH" 
220203        ]
221204    )
222- 
223- {- ------------------------------------------------------------------------------
224-   Parsing the configuration file 
225- -------------------------------------------------------------------------------}  
226- 
227- instance  Aeson. FromJSONFromConfigFile  where 
228-   parseJSON =  Aeson. withObject " CardanoConfigFile" $  \ o ->  do 
229-     DBPaths  imm vol <-  Aeson. parseJSON (Aeson. Object
230-     inFmt <-  ($  vol) <$>  Aeson. parseJSON (Aeson. Object
231-     pure  $  FromConfigFile  inFmt imm
232- 
233- data  DBPaths  =  DBPaths  (FilePath'  " Snapshots" FilePath'  " Volatile" 
234- 
235- --  |  Possible database locations: 
236- -- 
237- --   (1) Provided as flag: we would need to receive that same flag. For simplicity we will ban this scenario for now, requiring users to put the path in the config file. 
238- -- 
239- --   (2) Not provided: we default to "mainnet" 
240- -- 
241- --   (3) Provided in the config file: 
242- -- 
243- --     (1) One database path: we use that one 
244- -- 
245- --         @@ 
246- --         "DatabasePath": "some/path" 
247- --         @@ 
248- -- 
249- --     (2) Multiple databases paths: we use the immutable one 
250- -- 
251- --         @@ 
252- --         "DatabasePath": { 
253- --           "ImmutableDbPath": "some/path", 
254- --           "VolatileDbPath": "some/other/path", 
255- --         } 
256- --         @@ 
257- instance  Aeson. FromJSONDBPaths  where 
258-   parseJSON =  Aeson. withObject " CardanoConfigFile" $  \ o ->  do 
259-     pncDatabase <-  o Aeson. .:?" DatabasePath" 
260-     (imm, vol) <-  case  pncDatabase of 
261-       Nothing  ->  pure  (" mainnet" " mainnet" --  (2)
262-       Just  p@ (Aeson. Object-> 
263-         Aeson. withObject
264-           " NodeDatabasePaths" 
265-           (\ o' ->  (,) <$>  o' Aeson. .:" ImmutableDbPath" <*>  o' Aeson. .:" VolatileDbPath" --  (3.2)
266-           p
267-       Just  (Aeson. String-> 
268-         let 
269-           s' =  Text. unpack s
270-          in 
271-           pure  (s', s') --  (3.1)
272-       _ ->  fail  " NodeDatabasePaths must be an object or a string" 
273-     pure  $  DBPaths  (FP  $  imm </>  " ledger" FP  vol)
274- 
275- --  |  Possible formats 
276- -- 
277- --   (1) Nothing provided: we use InMemory 
278- -- 
279- --   (2) Provided in config file: 
280- -- 
281- --     (1) "V2InMem": we use InMemory 
282- -- 
283- --         @@ 
284- --         "LedgerDB": { 
285- --           "Backend": "V2InMem" 
286- --         } 
287- --         @@ 
288- -- 
289- --     (2) "V1LMDB": we use LMDB 
290- -- 
291- --         @@ 
292- --         "LedgerDB": { 
293- --           "Backend": "V1LMDB" 
294- --         } 
295- --         @@ 
296- -- 
297- --     (3) "V2LSM" 
298- --         LSM database locations: 
299- --         (1) Nothing provided: we use "lsm" in the volatile directory 
300- -- 
301- --         @@ 
302- --         "LedgerDB": { 
303- --           "Backend": "V2LSM" 
304- --         } 
305- --         @@ 
306- -- 
307- --         (2) Provided in file: we use that one 
308- -- 
309- --         @@ 
310- --         "LedgerDB": { 
311- --           "Backend": "V2LSM", 
312- --           "LSMDatabasePath": "some/path" 
313- --         } 
314- --         @@ 
315- instance  Aeson. FromJSONFilePath'  " Volatile" ->  FilePath'  " Snapshot" ->  Format ) where 
316-   parseJSON =  Aeson. withObject " CardanoConfigFile" $  \ o ->  do 
317-     ldb <-  Debug. traceShowId <$>  o Aeson. .:?" LedgerDB" 
318-     case  ldb of 
319-       Nothing  ->  pure  $  const  $  Mem  .  rawFilePath --  (1)
320-       Just  ldb' ->  do 
321-         bkd <-  ldb' Aeson. .:?" Backend" 
322-         case  bkd ::  Maybe String of 
323-           Just  " V1LMDB" ->  pure  $  const  $  LMDB  .  rawFilePath --  (2.2)
324-           Just  " V2LSM" ->  do 
325-             mDbPath <-  ldb' Aeson. .:?" LSMDatabasePath" 
326-             case  mDbPath of 
327-               Nothing  ->  pure  $  \ v ->  flip  LSM  (rawFilePath v </>  " lsm" .  rawFilePath --  (2.3.1)
328-               Just  dbPath ->  pure  $  const  $  flip  LSM  dbPath .  rawFilePath --  (2.3.2)
329-           _ ->  pure  $  const  $  Mem  .  rawFilePath --  (2.1)
330- 
331- getFormatFromConfig  ::  FilePath'  " ConfigFile" ->  IO FromConfigFile 
332- getFormatFromConfig (FP  configPath) = 
333-   either  (throwIO .  userError ) pure  =<<  Aeson. eitherDecodeFileStrict' configPath
0 commit comments