Skip to content

Commit

Permalink
Revise globalstate Instances test to use V0 and V1 instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak committed Feb 22, 2022
1 parent 9184f47 commit a3ca9f8
Show file tree
Hide file tree
Showing 4 changed files with 420 additions and 354 deletions.
2 changes: 1 addition & 1 deletion concordium-consensus/smart-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module Concordium.GlobalState.ContractStateV1
thawInMemoryPersistent,
toByteString,
-- * Testing
lookupKey
lookupKey,
generatePersistentTree
)
where

Expand Down Expand Up @@ -74,6 +75,9 @@ foreign import ccall "load_persistent_tree_v1" loadPersistentTree :: LoadCallbac
foreign import ccall unsafe "&free_persistent_state_v1" freePersistentState :: FunPtr (Ptr PersistentState -> IO ())
foreign import ccall unsafe "&free_mutable_state_v1" freeMutableState :: FunPtr (Ptr MutableStateInner -> IO ())

{-# WARNING generatePersistentTreeFFI "Only for testing. DO NOT USE IN PRODUCTION." #-}
foreign import ccall "generate_persistent_state_from_seed" generatePersistentTreeFFI :: Word64 -> Word64 -> IO (Ptr PersistentState)

-- |Write out the tree using the provided callback, and return a BlobRef to the root.
foreign import ccall "store_persistent_tree_v1" storePersistentTree :: StoreCallback -> Ptr PersistentState -> IO (BlobRef PersistentState)

Expand Down Expand Up @@ -212,3 +216,17 @@ instance Serialize InMemoryPersistentState where
bytePtr <- serializePersistentState errorLoadCallBack psPtr sizePtr
len <- peek sizePtr
putByteStringLen <$> unsafePackCStringFinalizer (castPtr bytePtr) (fromIntegral len) (rs_free_array_len bytePtr (fromIntegral len))


{-# WARNING generatePersistentTree "Only for testing. DO NOT USE IN PRODUCTION." #-}
{-# NOINLINE generatePersistentTree #-}
generatePersistentTree ::
Word64 -- ^Seed.
-> Word64 -- ^Number of values.
-> InMemoryPersistentState
generatePersistentTree seed len = unsafePerformIO $ do
res <- generatePersistentTreeFFI seed len
if res == nullPtr then
error "Could not generate tree."
else
InMemoryPersistentState . PersistentState <$> newForeignPtr freePersistentState res
1 change: 0 additions & 1 deletion concordium-consensus/src/Concordium/Skov/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import Concordium.Skov.Statistics
import qualified Concordium.TransactionVerification as TV
import Concordium.Types.Updates (uiHeader, updateType, uiPayload)
import Concordium.Scheduler.Types (updateSeqNumber)
import Concordium.GlobalState.TransactionTable (pttDeployCredential)

-- |Determine if one block is an ancestor of another.
-- A block is considered to be an ancestor of itself.
Expand Down
Loading

0 comments on commit a3ca9f8

Please sign in to comment.