Skip to content

Commit

Permalink
peg streamly at 0.9.0 (0.10.0 not yet supported due to API changes)
Browse files Browse the repository at this point in the history
fix reading and writing notifications
previously, notifications were associated with client connections which are transient so we did not write them as part of transaction data
YuMingLiao discovered that the notifications were not restored upon database loading because they were always assigned mempty leading to merkle hash validation failure
because notifications are sent to all connected clients, this fix read and writes notifications as any other transaction data thereby fixing the merkle hash validation
  • Loading branch information
agentm committed Dec 30, 2023
1 parent bdd130e commit 79d1e34
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions project-m36.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cabal-Version: 2.2
Name: project-m36
Version: 0.9.7
Version: 0.9.8
License: MIT
--note that this license specification is erroneous and only labeled MIT to appease hackage which does not recognize public domain packages in cabal >2.2- Project:M36 is dedicated to the public domain
Build-Type: Simple
Expand Down Expand Up @@ -35,7 +35,7 @@ Flag haskell-scripting
Default: True

Library
Build-Depends: base>=4.8 && < 4.17, ghc-paths, mtl, containers, unordered-containers, hashable, haskeline, directory, MonadRandom, random-shuffle, uuid >= 1.3.12, cassava >= 0.4.5.1 && < 0.6, text, bytestring, deepseq, deepseq-generics, vector, parallel, monad-parallel, exceptions, transformers, gnuplot, filepath, zlib, directory, temporary, stm, time, old-locale, rset, attoparsec, either, base64-bytestring, data-interval, extended-reals, aeson >= 1.1, path-pieces, conduit, resourcet, http-api-data, semigroups, QuickCheck, quickcheck-instances, list-t, stm-containers >= 0.2.15, foldl, optparse-applicative, Glob, cryptohash-sha256, text-manipulate >= 0.2.0.1 && < 0.4, winery >= 1.4, curryer-rpc>=0.2.2, network, async, vector-instances, recursion-schemes, streamly >= 0.7.2, convertible, fast-builder, scientific, time-compat >= 1.9.6.1
Build-Depends: base>=4.8 && < 4.17, ghc-paths, mtl, containers, unordered-containers, hashable, haskeline, directory, MonadRandom, random-shuffle, uuid >= 1.3.12, cassava >= 0.4.5.1 && < 0.6, text, bytestring, deepseq, deepseq-generics, vector, parallel, monad-parallel, exceptions, transformers, gnuplot, filepath, zlib, directory, temporary, stm, time, old-locale, rset, attoparsec, either, base64-bytestring, data-interval, extended-reals, aeson >= 1.1, path-pieces, conduit, resourcet, http-api-data, semigroups, QuickCheck, quickcheck-instances, list-t, stm-containers >= 0.2.15, foldl, optparse-applicative, Glob, cryptohash-sha256, text-manipulate >= 0.2.0.1 && < 0.4, winery >= 1.4, curryer-rpc>=0.2.2, network, async, vector-instances, recursion-schemes, streamly == 0.9.0, convertible, fast-builder, scientific, time-compat >= 1.9.6.1
if flag(haskell-scripting)
Build-Depends: ghc >= 8.2 && < 9.3
CPP-Options: -DPM36_HASKELL_SCRIPTING
Expand Down
1 change: 0 additions & 1 deletion src/lib/ProjectM36/HashSecurely.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import qualified Data.Set as S
import Data.Time.Calendar
import Data.Time.Clock
import Codec.Winery (Serialise)
import Data.Int (Int64)

newtype SecureHash = SecureHash { _unSecureHash :: B.ByteString }
deriving (Serialise, Show, Eq)
Expand Down
20 changes: 19 additions & 1 deletion src/lib/ProjectM36/Transaction/Persist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ transactionDir dbdir transId = dbdir </> show transId
transactionInfoPath :: FilePath -> FilePath
transactionInfoPath transdir = transdir </> "info"

notificationsPath :: FilePath -> FilePath
notificationsPath transdir = transdir </> "notifs"

relvarsPath :: FilePath -> FilePath
relvarsPath transdir = transdir </> "relvars"

Expand Down Expand Up @@ -82,13 +85,14 @@ readTransaction dbdir transId mScriptSession = do
incDeps <- readIncDeps transDir
typeCons <- readTypeConstructorMapping transDir
sschemas <- readSubschemas transDir
notifs <- readNotifications transDir
dbcFuncs <- readFuncs transDir (dbcFuncsPath transDir) basicDatabaseContextFunctions mScriptSession
atomFuncs <- readFuncs transDir (atomFuncsPath transDir) precompiledAtomFunctions mScriptSession
registeredQs <- readRegisteredQueries transDir
let newContext = DatabaseContext { inclusionDependencies = incDeps,
relationVariables = relvars,
typeConstructorMapping = typeCons,
notifications = M.empty,
notifications = notifs,
atomFunctions = atomFuncs,
dbcFunctions = dbcFuncs,
registeredQueries = registeredQs }
Expand All @@ -108,6 +112,7 @@ writeTransaction sync dbdir trans = do
writeIncDeps sync tempTransDir (inclusionDependencies context)
writeFuncs sync (atomFuncsPath tempTransDir) (HS.toList (atomFunctions context))
writeFuncs sync (dbcFuncsPath tempTransDir) (HS.toList (dbcFunctions context))
writeNotifications sync tempTransDir (notifications context)
writeTypeConstructorMapping sync tempTransDir (typeConstructorMapping context)
writeSubschemas sync tempTransDir (subschemas trans)
writeRegisteredQueries sync tempTransDir (registeredQueries context)
Expand Down Expand Up @@ -280,3 +285,16 @@ writeRegisteredQueries :: DiskSync -> FilePath -> RegisteredQueries -> IO ()
writeRegisteredQueries sync transDir regQs = do
let regQsPath = registeredQueriesPath transDir
traceBlock "write registered queries" $ writeSerialiseSync sync regQsPath regQs

readNotifications :: FilePath -> IO Notifications
readNotifications transDir = do
let notifsPath = notificationsPath transDir
readFileDeserialise notifsPath

writeNotifications :: DiskSync -> FilePath -> Notifications -> IO ()
writeNotifications sync transDir notifs = do
let notifsPath = notificationsPath transDir
traceBlock "write notifications" $ writeSerialiseSync sync notifsPath notifs



8 changes: 4 additions & 4 deletions test/TransactionGraph/Persist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ testList = TestList [testBootstrapDB,
testDBSimplePersistence,
testFunctionPersistence,
testMerkleHashValidation]


stamp' :: UTCTime
stamp' = UTCTime (fromGregorian 1980 01 01) (secondsToDiffTime 1000)
Expand Down Expand Up @@ -85,6 +84,9 @@ testMerkleHashValidation = TestCase $
conn <- assertIOEither $ connectProjectM36 connInfo
sess <- assertIOEither $ createSessionAtHead conn "master"
Right _ <- executeDatabaseContextExpr sess conn (Assign "x" (ExistingRelation relationTrue))
-- add a notification because we forgot to read/write it as part of the transaction before
let relX = RelationVariable "x" ()
Right _ <- executeDatabaseContextExpr sess conn (AddNotification "testnotif" relX relX relX)
Right _ <- commit sess conn
val <- C.validateMerkleHashes sess conn
assertEqual "merkle success" (Right ()) val
Expand Down Expand Up @@ -130,8 +132,6 @@ testMerkleHashValidation = TestCase $
assertEqual "open connection merkle validation" (DatabaseValidationError [MerkleValidationError (transactionId trans) regMerkleHash malMerkleHash]) err
Right _ -> assertFailure "open connection validation"



--only Haskell-scripted dbc and atom functions can be serialized
testFunctionPersistence :: Test
#if !defined(PM36_HASKELL_SCRIPTING)
Expand Down Expand Up @@ -159,7 +159,7 @@ testFunctionPersistence = TestCase $
let expectedRel = mkRelationFromList (attributesFromList [Attribute "a" IntAtomType]) [[IntAtom 3]]
assertEqual "testdisk dbc function run" expectedRel res

#endif
#endif

assertIOEither :: (Show a) => IO (Either a b) -> IO b
assertIOEither x = do
Expand Down

0 comments on commit 79d1e34

Please sign in to comment.