Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3b1e8e4
commandline
allanbrondum Mar 3, 2026
1d2d485
treestate
allanbrondum Mar 4, 2026
a5563b4
dump
allanbrondum Mar 5, 2026
ef9392f
state
allanbrondum Mar 5, 2026
1a5c731
dump
allanbrondum Mar 5, 2026
282ba14
state
allanbrondum Mar 5, 2026
2a29790
dump
allanbrondum Mar 5, 2026
3c3bbe5
dump
allanbrondum Mar 6, 2026
30bdc8a
dum=p
allanbrondum Mar 6, 2026
0aaa805
dum=p
allanbrondum Mar 6, 2026
a4186c3
dump
allanbrondum Mar 6, 2026
030cd7f
fix
allanbrondum Mar 6, 2026
fbef50e
dump
allanbrondum Mar 7, 2026
e8115b5
dump
allanbrondum Mar 7, 2026
cc7c243
dump
allanbrondum Mar 8, 2026
5cd7b91
dump
allanbrondum Mar 8, 2026
8256842
dump
allanbrondum Mar 8, 2026
9cb2d7a
Allow both revealing attribute and using it in bullet proofs
allanbrondum Mar 8, 2026
bc63ffe
dump
allanbrondum Mar 8, 2026
6dceb37
dump
allanbrondum Mar 9, 2026
4204475
dump
allanbrondum Mar 10, 2026
a91bb46
merge
allanbrondum Mar 10, 2026
2ef4918
merge
allanbrondum Mar 10, 2026
2de147f
fix
allanbrondum Mar 10, 2026
94991a7
dump
allanbrondum Mar 10, 2026
192a00c
fix
allanbrondum Mar 10, 2026
99ca6f1
fix
allanbrondum Mar 11, 2026
7fe157d
dump
allanbrondum Mar 11, 2026
b4f082d
dump
allanbrondum Mar 11, 2026
83e2af5
dump
allanbrondum Mar 11, 2026
5aa8461
dump
allanbrondum Mar 22, 2026
1decae1
lockfile
allanbrondum Mar 22, 2026
5be7ff6
merge
allanbrondum Mar 22, 2026
6581c4d
monad
allanbrondum Mar 22, 2026
edd598e
dump
allanbrondum Mar 22, 2026
25bfabb
dump
allanbrondum Mar 22, 2026
f1d8f93
lockfile
allanbrondum Mar 25, 2026
695e9c5
merge
allanbrondum Mar 25, 2026
7053ec6
dump
allanbrondum Apr 1, 2026
a91a6b9
state
allanbrondum Apr 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions concordium-consensus/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,34 @@ executables:
- optparse-applicative >= 0.15
- filepath >= 1.4

block-state-dump:
main: Main.hs
source-dirs: tools/block-state-dump
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -Wall
- -Wcompat

when:
- condition: os(windows)
then:
ghc-options: -static
else:
when:
- condition: flag(dynamic)
then:
ghc-options: -dynamic
else:
ghc-options: -static
dependencies:
- concordium-consensus
- optparse-applicative >= 0.15
- filepath >= 1.4
- directory >= 1.3
- pretty-simple >= 4.1

tests:
consensus:
main: Spec.hs
Expand Down
8 changes: 7 additions & 1 deletion concordium-consensus/src/Concordium/GlobalState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import Concordium.GlobalState.BlockState
import Concordium.GlobalState.Parameters
import Concordium.GlobalState.Persistent.Account (newAccountCache)
import Concordium.GlobalState.Persistent.BlobStore (BlobStoreT (runBlobStoreT), closeBlobStore, createBlobStore, destroyBlobStore, loadBlobStore)
import Concordium.GlobalState.Persistent.BlockState
import Concordium.GlobalState.Persistent.BlockState (
HashedPersistentBlockState (hpbsPointers),
PersistentBlockStateContext (..),
PersistentBlockStateMonad (runPersistentBlockStateMonad),
hashBlockState,
migratePersistentBlockState,
)
import qualified Concordium.GlobalState.Persistent.BlockState.Modules as Modules
import Concordium.GlobalState.Persistent.Genesis
import Concordium.GlobalState.Persistent.TreeState
Expand Down
51 changes: 51 additions & 0 deletions concordium-consensus/src/Concordium/GlobalState/ContractStateV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Concordium.GlobalState.ContractStateV1 (
-- * Testing
lookupKey,
generatePersistentTree,
dumpPersistentState,
)
where

Expand All @@ -49,6 +50,7 @@ import qualified Data.FixedByteString as FBS

import Concordium.GlobalState.ContractStateFFIHelpers (LoadCallback, StoreCallback, errorLoadCallback)
import Concordium.GlobalState.Persistent.BlobStore
import Foreign.C.String

-- | Opaque pointer to the mutable state. This state exists only for the duration
-- of a transaction and is then deallocated by running a finalizer.
Expand Down Expand Up @@ -453,3 +455,52 @@ toByteString ps = do
bytePtr <- serializePersistentState loadCallback psPtr sizePtr
len <- peek sizePtr
BSU.unsafePackCStringFinalizer (castPtr bytePtr) (fromIntegral len) (rs_free_array_len bytePtr (fromIntegral len))

-- | Dump PLT block state. Use for debugging purposes only.
dumpPersistentState ::
(MonadBlobStore m) =>
-- | Current block state
PersistentState ->
-- | Parent node
Word64 ->
-- | Path to graph file
String ->
-- | Path to state file
String ->
m ()
dumpPersistentState persistentState parentNode graphFilePath dataFilePath =
do
loadCallbackPtr <- fst <$> getCallbacks
liftIO $ do
withPersistentState persistentState $ \persistentStatePtr ->
withCStringLen graphFilePath $ \(graphFilePathPtr, graphFilePathLen) ->
withCStringLen dataFilePath $ \(dataFilePathPtr, dataFilePathLen) ->
ffiDumpPersistentState
loadCallbackPtr
persistentStatePtr
parentNode
(castPtr graphFilePathPtr)
(fromIntegral graphFilePathLen)
(castPtr dataFilePathPtr)
(fromIntegral dataFilePathLen)

-- | Dump PLT block state. Use for debugging purposes only.
--
-- See the exported function in the Rust code for documentation of safety.
foreign import ccall "ffi_dump_persistent_state"
ffiDumpPersistentState ::
-- | Called to read data from blob store.
LoadCallback ->
-- | Pointer to the block state to dump.
Ptr PersistentState ->
-- | Parent node
Word64 ->
-- | Path to graph file
Ptr Word8 ->
-- | Length of path to graph file
CSize ->
-- | Path to state file
Ptr Word8 ->
-- | Length of path to state file
CSize ->
IO ()
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module Concordium.GlobalState.Persistent.BlobStore (
migrateReference,

-- ** 'BufferedRef'
BufferedRef,
BufferedRef (..),
makeBufferedRef,
blobRefToBufferedRef,
loadBufferedRef,
Expand All @@ -84,7 +84,7 @@ module Concordium.GlobalState.Persistent.BlobStore (
uncacheBufferedRef,

-- ** 'EagerBufferedRef'
EagerBufferedRef,
EagerBufferedRef (..),
eagerBufferedDeref,
eagerBufferedRefFromBufferedRef,
migrateEagerBufferedRef,
Expand All @@ -93,7 +93,7 @@ module Concordium.GlobalState.Persistent.BlobStore (
LazyBufferedRef,

-- ** 'HashedBufferedRef'
HashedBufferedRef',
HashedBufferedRef' (..),
HashedBufferedRef,
bufferHashed,
makeHashedBufferedRef,
Expand All @@ -102,12 +102,12 @@ module Concordium.GlobalState.Persistent.BlobStore (
HashedBufferedRefO,

-- ** 'EagerlyHashedBufferedRef'
EagerlyHashedBufferedRef',
EagerlyHashedBufferedRef' (..),
EagerlyHashedBufferedRef,
migrateEagerlyHashedBufferedRefKeepHash,

-- ** 'UnbufferedRef'
UnbufferedRef,
UnbufferedRef (..),
makeUnbufferedRef,
makeFlushedUnbufferedRef,
blobRefToUnbufferedRef,
Expand Down Expand Up @@ -1686,7 +1686,7 @@ makeHashedBufferedRef val = do
return $ HashedBufferedRef br hashRef

instance (DirectBlobStorable m a, MHashableTo m h a) => MHashableTo m h (HashedBufferedRef' h a) where
getHashM HashedBufferedRef{..} =
getHashM HashedBufferedRef{..} = do
liftIO (readIORef bufferedHash) >>= \case
Null -> do
!h <- getHashM bufferedReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Concordium.GlobalState.Persistent.BlockState.ProtocolLevelTokens.RustPLTB
withPLTBlockState,
migrate,
ProtocolLevelTokensHash (..),
dumpPLTBlockState,
) where

import qualified Data.Serialize as S
Expand All @@ -22,6 +23,7 @@ import qualified Concordium.GlobalState.Persistent.BlobStore as BlobStore
import qualified Concordium.Types.HashableTo as Hashable
import Control.Monad.Trans (lift, liftIO)
import qualified Data.FixedByteString as FixedByteString
import qualified Foreign.C as FFI

-- | Opaque type representing a Rust maintained PLT state.
-- The value is allocated in Rust and must be deallocated in Rust.
Expand Down Expand Up @@ -167,3 +169,52 @@ foreign import ccall "ffi_migrate_plt_block_state"
FFI.Ptr RustPLTBlockState ->
-- | Pointer to the new block state.
IO (FFI.Ptr RustPLTBlockState)

-- | Dump PLT block state. Use for debugging purposes only.
dumpPLTBlockState ::
(BlobStore.MonadBlobStore m) =>
-- | Current block state
ForeignPLTBlockStatePtr ->
-- | Parent node
FFI.Word64 ->
-- | Path to graph file
String ->
-- | Path to state file
String ->
m ()
dumpPLTBlockState blockState parentNode graphFilePath dataFilePath =
do
loadCallbackPtr <- fst <$> BlobStore.getCallbacks
liftIO $ do
withPLTBlockState blockState $ \blockStatePtr ->
FFI.withCStringLen graphFilePath $ \(graphFilePathPtr, graphFilePathLen) ->
FFI.withCStringLen dataFilePath $ \(dataFilePathPtr, dataFilePathLen) ->
ffiDumpPLTBlockState
loadCallbackPtr
blockStatePtr
parentNode
(FFI.castPtr graphFilePathPtr)
(fromIntegral graphFilePathLen)
(FFI.castPtr dataFilePathPtr)
(fromIntegral dataFilePathLen)

-- | Dump PLT block state. Use for debugging purposes only.
--
-- See the exported function in the Rust code for documentation of safety.
foreign import ccall "ffi_dump_plt_block_state"
ffiDumpPLTBlockState ::
-- | Called to read data from blob store.
FFI.LoadCallback ->
-- | Pointer to the block state to dump.
FFI.Ptr RustPLTBlockState ->
-- | Parent node
FFI.Word64 ->
-- | Path to graph file
FFI.Ptr FFI.Word8 ->
-- | Length of path to graph file
FFI.CSize ->
-- | Path to state file
FFI.Ptr FFI.Word8 ->
-- | Length of path to state file
FFI.CSize ->
IO ()
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module Concordium.GlobalState.Persistent.LFMBTree (

-- * Tree type
LFMBTree,
LFMBTree',
LFMBTree' (..),
size,
T (..),

-- * Construction
empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pairBranch (k1, v1) (k2, v2)
-- | Trie with keys all of same fixed length treated as lists of bytes.
-- The first parameter of 'TrieF' is the type of keys, which should
-- by an instance of 'FixedTrieKey'.
-- The second parameter is the type of values.
-- The second paraDmeter is the type of values.
-- The third parameter is the recursive type argument: a type for Tries
-- is obtained by applying a fixed-point combinator to @TrieF k v@.
data TrieF k v r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data StoredBlock (pv :: ProtocolVersion) = StoredBlock
-- | Pointer to the state in the block state storage.
stbStatePointer :: !(BlockStateRef pv)
}
deriving (Show)

type instance BlockProtocolVersion (StoredBlock pv) = pv

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module BlockStateDump.Config where

import Data.Functor.Identity
import Options.Applicative

import Concordium.Types

data Config
= DumpState
{ cTreeStateDbPath :: FilePath,
cAccountMapDbPath :: FilePath,
cBlockStatePath :: FilePath,
cOutDir :: FilePath,
cProtocolVersion :: ProtocolVersion,
cBlockHeights :: [BlockHeight]
}

config :: Parser (Identity Config)
config =
Identity
<$> ( hsubparser
( metavar "command"
<> ( command
"state"
( info
( DumpState
<$> strOption
( long "tree-state-db-path"
<> metavar "TREESTATEDBPATH"
<> help "Path to tree state LMDB database directory (e.g. xyz/database-v4/treestate-0)"
)
<*> strOption
( long "account-map-db-path"
<> metavar "ACCOUNTMAPDBPATH"
<> help "Path to account map LMDB database directory (e.g. xyz/database-v4/accountmap)"
)
<*> strOption
( long "block-state-path"
<> metavar "BLOCKSTATEPATH"
<> help "Path to block state file (e.g. xyz/database-v4/blockstate-0.dat)"
)
<*> strOption
( long "out-dir"
<> metavar "OUTDIR"
<> help "Path to directory to output dump to"
)
<*> option
auto
( long "protocol-version"
<> metavar "PROTOCOLVERSION"
<> help "Protocol version for the tree state and block state, e.g. P9"
)
<*> option
auto
( long "block-heights"
<> metavar "BLOCKHEIGHTS"
<> help "Relative heights of block to dump state for"
)
)
(progDesc "Dump block state")
)
)
)
)
Loading