Skip to content

Commit

Permalink
Indexing of node data works.
Browse files Browse the repository at this point in the history
  • Loading branch information
raduom committed Aug 8, 2022
1 parent 620e29f commit 336d774
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Expand Up @@ -14,6 +14,7 @@ module Marconi.Index.TxConfirmationStatus

import Cardano.Api (SlotNo (SlotNo))
import Control.Applicative ((<|>))
import Control.Exception (SomeException, catch)
import Control.Lens.Operators ((^.))
import Data.Foldable (forM_)
import Data.Functor ((<&>))
Expand Down Expand Up @@ -76,7 +77,7 @@ open
-> Depth
-> IO TCSIndex
open dbPath (Depth k) = do
ix <- fromJust <$> Ix.newBoxed query store onInsert k ((k + 1) * 4) dbPath
ix <- fromJust <$> Ix.newBoxed query store onInsert k ((k + 1) * 2) dbPath
let c = ix ^. Ix.handle
SQL.execute_ c "CREATE TABLE IF NOT EXISTS tx_status (txId TEXT NOT NULL PRIMARY KEY, blockNo INT NOT NULL, slotNo INT NOT NULL)"
pure ix
Expand Down Expand Up @@ -115,13 +116,11 @@ query ix txId' events = (<|>) <$> searchInMemory

store :: TCSIndex -> IO ()
store ix = do
events <- Ix.getEvents $ ix ^. Ix.storage
buffer <- Ix.getBuffer $ ix ^. Ix.storage
let all' = buffer ++ events
c = ix ^. Ix.handle
let c = ix ^. Ix.handle
SQL.execute_ c "BEGIN"
forM_ all' $
SQL.execute c "INSERT INTO tx_status (txId, blockNumber, slotNo) VALUES (?, ?, ?)"
forM_ buffer $ \event -> do
SQL.execute c "INSERT INTO tx_status (txId, blockNo, slotNo) VALUES (?, ?, ?)" event `catch` (\e -> putStrLn $ "SQL Exception: " <> show (txId event) <> " " <> show (e :: SomeException))
SQL.execute_ c "COMMIT"

onInsert :: TCSIndex -> Event -> IO [()]
Expand Down
Expand Up @@ -84,7 +84,7 @@ startNodeClient config instancesState = do
(\block slot -> handleSyncAction $ processMockBlock instancesState env block slot
)
AlonzoNode -> do
utxoIx <- Ix.open "./utxos.sqlite3" (Ix.Depth 2160) >>= newIORef
utxoIx <- Ix.open "./utxos.sqlite3" (Ix.Depth 100) >>= newIORef
let resumePoints = maybeToList $ toCardanoPoint resumePoint
void $ Client.runChainSync socket nullTracer slotConfig networkId resumePoints
(\block -> do
Expand Down

0 comments on commit 336d774

Please sign in to comment.