Fraktal VM state database
Stand-alone C++20 executable and library used for Fraktal VM state. Fork of with state & account class overrides. State access done thru nonce-locks to enable replayablity & thread safety.
make all
NOTE: Dependencies must be compiled & linked into compilation aswell.
fraktal-state-db comes with various commandline functions, including :
Get - get a value at (contract address, key) pair in state
./bin/fraktal-state-db get --snapshotFile ./path/to/snapshot.json --contractAddress 4200000000000000000000000000000000000000 --key 42
Set - set a value at (contract address, key) pair in state ( and saves changes )
./bin/fraktal-state-db set --snapshotFile ./path/to/snapshot.json --contractAddress 4200000000000000000000000000000000000000 --key 42 --value 512
Run - runs an RPC server giving access to Fraktal VM state db ( for gets and sets ) ( TODO: not yet implemented )
./bin/fraktal-state-db run --snapshotFile ./path/to/snapshot.json --rpcPort 8999
# Get request
curl -X POST -H "Content-Type: application/json" --data '--contractAddress 4200000000000000000000000000000000000000 --key 42' http://localhost:8999
# Set request
curl -X POST -H "Content-Type: application/json" --data '--contractAddress 4200000000000000000000000000000000000000 --key 42 --value 512' http://localhost:8999
Note : Use -h
flag on each sub-command to see more options
- intx : 256-bit (32-byte) unsigned integers
- ethash : Ethereum hash functions
- evm-cpp-utils : EVM state types + utils
This repo contains various tests under ./test/
to make sure things are working.
To run use :
make get-test
make set-test
# RPC test
make run-rpc-local
# In a seperate terminal
make get-rpc-test
make set-rpc-test
make get-rpc-test
# Ctrl-C to stop RPC & snapshot state
Check the diff in ./test/snapshot.json
to see if things processed properly.
Fraktal VM allows parallel execution of smart contracts. Thus, there are potential race conditions on state access operations.
In order to prevent race conditions on set operations :
FraktalState
provides amutexSpace
, a fixed size array of mutexes for accessing state.- When
FraktalAccount
does asetStorage
operation, lock the mutex at positionhash(contract addr, storage key) % mutexSpaceSize
In order to prevent race conditions on get operations :
FraktalState
providesmutexNonces
, nonce that increments when corresponding mutex locks.FraktalAccount
providesstorageNonces
, nonce that increments when storage value is set.FraktalAccount
providesstorageNonceValueHistory
, prunable 2d map from key -> nonce -> value- When
FraktalAccount
does agetStorage
operation, get thestorageNonce
at key then get the value at the corresponding(key, storage nonce)
pair in history
In order to allow custom locking operations for things like sudo-atomic operations ( Not implemented ) :
FraktalAccount
providesmutexStorage
, a dynamic mutex storage set
Fraktal State DB provides extra functionality for snapshotting new nonces & history.
DA ( Not implemented ) : Fraktal State DB provides mutex, nonce, and value history data to DA agent(s).
Brandon Roberts @b-j-roberts