Skip to content

Commit

Permalink
Fix tail to use lazy bytestring IO
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly committed Sep 22, 2023
1 parent b557f8c commit 951a2b3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cardano-node/src/Cardano/Node/LedgerEvent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,13 @@ deserializeEvent codecVersion bytes =
-- IO action to read ledger events in binary form
tailEvent :: FilePath -> IO ()
tailEvent eventsDb =
withFile eventsDb ReadMode $ \ h -> do
withFile eventsDb ReadMode $ \ h -> LBS.hGetContents h >>= go

Check warning on line 482 in cardano-node/src/Cardano/Node/LedgerEvent.hs

View workflow job for this annotation

GitHub Actions / build

Suggestion in tailEvent in module Cardano.Node.LedgerEvent: Use >=> ▫︎ Found: "\\ h -> LBS.hGetContents h >>= go" ▫︎ Perhaps: "(LBS.hGetContents Control.Monad.>=> go)"

where
go bytes = do
let version = maxBound
len :: Word32 <- unsafeDeserialize version <$> LBS.hGet h 5
event :: (ShortByteString, SlotNo, LedgerEvent) <- trace ("length = " <> show @_ @Text len) $ unsafeDeserialize version <$> LBS.hGet h (fromIntegral len)
putStrLn $ "Ledger Event: " <> show @_ @Text event
case deserialiseFromBytes (toPlainDecoder version decCBOR) bytes of
Right (rest, event :: AnchoredEvent) -> do
putStrLn $ "Anchored Event: " <> show @_ @Text event
go rest
Left err -> putStrLn $ "FIXME: Error: " <> show @_ @Text err

0 comments on commit 951a2b3

Please sign in to comment.