Skip to content

Commit 3f3d771

Browse files
committed
Update to mempack-0.2
1 parent 56e9620 commit 3f3d771

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

cabal.project

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ repository cardano-haskell-packages
1414
-- update either of these.
1515
index-state:
1616
-- Bump this if you need newer packages from Hackage
17-
, hackage.haskell.org 2025-09-11T01:58:40Z
17+
, hackage.haskell.org 2025-09-26T20:57:57Z
1818
-- Bump this if you need newer packages from CHaP
19-
, cardano-haskell-packages 2025-09-24T15:29:30Z
19+
, cardano-haskell-packages 2025-10-01T14:54:25Z
2020

2121
packages:
2222
ouroboros-consensus
@@ -55,7 +55,9 @@ if impl (ghc >= 9.10)
5555
-- https://github.com/phadej/regression-simple/pull/14
5656
, regression-simple:base
5757

58-
-- source-repository-package
59-
-- type: git
60-
-- location: https://github.com/lehins/mempack
61-
-- tag: 2f2528780c715afd2f270447359c7cde632f2c49
58+
source-repository-package
59+
type: git
60+
location: https://github.com/IntersectMBO/cardano-ledger
61+
tag: fb09078fa55015c881303a2ddb609c024cec258f
62+
--sha256: sha256-9Y9CRiyMn0AWD+C4aNVMaJgrj3FDAYfCX4VrLvtoMaI=
63+
subdir: libs/cardano-ledger-core

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V1/BackingStore/Impl/LMDB/Bridge.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Database.LMDB.Simple.Cursor (CursorM)
4141
import qualified Database.LMDB.Simple.Cursor as Cursor
4242
import qualified Database.LMDB.Simple.Internal as Internal
4343
import Foreign (Storable (peek, poke), castPtr)
44-
import GHC.Ptr (Ptr (..))
44+
import GHC.Exts
4545
import Ouroboros.Consensus.Util.IndexedMemPack
4646

4747
instance Buffer MDB_val where
@@ -51,6 +51,15 @@ instance Buffer MDB_val where
5151
buffer (MDB_val _ (Ptr addr#)) _ f = f addr#
5252
{-# INLINE buffer #-}
5353

54+
mkBuffer ba# =
55+
MDB_val
56+
(fromIntegral (I# (sizeofByteArray# ba#)))
57+
(Ptr (byteArrayContents# ba#))
58+
{-# INLINE mkBuffer #-}
59+
60+
bufferHasToBePinned = True
61+
{-# INLINE bufferHasToBePinned #-}
62+
5463
{-------------------------------------------------------------------------------
5564
Internal: peek and poke
5665
-------------------------------------------------------------------------------}

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/LSM.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ toTxOutBytes st txout =
109109
in TxOutBytes $ LSM.RawBytes (VP.Vector 0 (PBA.sizeofByteArray barr) barr)
110110

111111
fromTxOutBytes :: IndexedMemPack (l EmptyMK) (TxOut l) => l EmptyMK -> TxOutBytes -> TxOut l
112-
fromTxOutBytes st (TxOutBytes (LSM.RawBytes (VP.force -> (VP.Vector _ _ barr)))) =
113-
case indexedUnpackLeftOver' st barr of
112+
fromTxOutBytes st (TxOutBytes (LSM.RawBytes vec)) =
113+
case indexedUnpackEither st vec of
114114
Left err ->
115115
error $
116116
unlines
117117
[ "There was an error deserializing a TxOut from the LSM backend."
118118
, "This will likely result in a restart-crash loop."
119119
, "The error: " <> show err
120120
]
121-
Right (v, _) -> v
121+
Right v -> v
122122

123123
instance LSM.SerialiseValue TxOutBytes where
124124
serialiseValue = unTxOutBytes
@@ -138,16 +138,16 @@ toTxInBytes _ txin =
138138
in TxInBytes $ LSM.RawBytes (VP.Vector 0 (PBA.sizeofByteArray barr) barr)
139139

140140
fromTxInBytes :: MemPack (TxIn l) => Proxy l -> TxInBytes -> TxIn l
141-
fromTxInBytes _ (TxInBytes (LSM.RawBytes (VP.force -> (VP.Vector _ _ barr)))) =
142-
case unpackLeftOver' barr of
141+
fromTxInBytes _ (TxInBytes (LSM.RawBytes vec)) =
142+
case unpackEither vec of
143143
Left err ->
144144
error $
145145
unlines
146146
[ "There was an error deserializing a TxIn from the LSM backend."
147147
, "This will likely result in a restart-crash loop."
148148
, "The error: " <> show err
149149
]
150-
Right (v, _) -> v
150+
Right v -> v
151151

152152
instance LSM.SerialiseKey TxInBytes where
153153
serialiseKey = unTxInBytes

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Util/IndexedMemPack.hs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ module Ouroboros.Consensus.Util.IndexedMemPack
1616
, indexedPackByteString
1717
, indexedPackByteArray
1818
, indexedUnpackError
19-
, indexedUnpack
20-
, indexedUnpackLeftOver'
21-
, unpackLeftOver'
19+
, indexedUnpackEither
20+
, unpackEither
2221
) where
2322

2423
import qualified Control.Monad as Monad
25-
import Control.Monad.Trans.Fail (Fail, errorFail, failT, runFailAgg)
24+
import Control.Monad.ST
25+
import Control.Monad.Trans.Fail
2626
import Data.Array.Byte (ByteArray (..))
2727
import Data.Bifunctor (first)
2828
import Data.ByteString
@@ -35,7 +35,7 @@ import GHC.Stack
3535
class IndexedMemPack idx a where
3636
indexedPackedByteCount :: idx -> a -> Int
3737
indexedPackM :: idx -> a -> Pack s ()
38-
indexedUnpackM :: Buffer b => idx -> Unpack b a
38+
indexedUnpackM :: Buffer b => forall s. idx -> Unpack s b a
3939
indexedTypeName :: idx -> String
4040

4141
indexedPackByteString ::
@@ -76,24 +76,30 @@ indexedUnpackFail idx b = do
7676
indexedUnpackLeftOver ::
7777
forall idx a b.
7878
(IndexedMemPack idx a, Buffer b, HasCallStack) => idx -> b -> Fail SomeError (a, Int)
79-
indexedUnpackLeftOver idx b = do
79+
indexedUnpackLeftOver idx b = FailT $ pure $ runST $ runFailAggT $ indexedUnpackLeftOverST idx b
80+
{-# INLINEABLE indexedUnpackLeftOver #-}
81+
82+
indexedUnpackLeftOverST ::
83+
forall idx a b s.
84+
(IndexedMemPack idx a, Buffer b, HasCallStack) => idx -> b -> FailT SomeError (ST s) (a, Int)
85+
indexedUnpackLeftOverST idx b = do
8086
let len = bufferByteCount b
8187
res@(_, consumedBytes) <- runStateT (runUnpack (indexedUnpackM idx) b) 0
8288
Monad.when (consumedBytes > len) $ errorLeftOver (indexedTypeName @idx @a idx) consumedBytes len
8389
pure res
84-
{-# INLINEABLE indexedUnpackLeftOver #-}
90+
{-# INLINEABLE indexedUnpackLeftOverST #-}
8591

86-
indexedUnpackLeftOver' ::
92+
indexedUnpackEither ::
8793
forall idx a b.
88-
(IndexedMemPack idx a, Buffer b, HasCallStack) => idx -> b -> Either SomeError (a, Int)
89-
indexedUnpackLeftOver' idx = first fromMultipleErrors . runFailAgg . indexedUnpackLeftOver idx
90-
{-# INLINEABLE indexedUnpackLeftOver' #-}
94+
(IndexedMemPack idx a, Buffer b, HasCallStack) => idx -> b -> Either SomeError a
95+
indexedUnpackEither idx = first fromMultipleErrors . runFailAgg . indexedUnpackFail idx
96+
{-# INLINEABLE indexedUnpackEither #-}
9197

92-
unpackLeftOver' ::
98+
unpackEither ::
9399
forall a b.
94-
(MemPack a, Buffer b, HasCallStack) => b -> Either SomeError (a, Int)
95-
unpackLeftOver' = first fromMultipleErrors . runFailAgg . unpackLeftOver
96-
{-# INLINEABLE unpackLeftOver' #-}
100+
(MemPack a, Buffer b, HasCallStack) => b -> Either SomeError a
101+
unpackEither = first fromMultipleErrors . runFailAgg . unpackFail
102+
{-# INLINEABLE unpackEither #-}
97103

98104
errorLeftOver :: HasCallStack => String -> Int -> Int -> a
99105
errorLeftOver name consumedBytes len =

0 commit comments

Comments
 (0)