Professional Documents
Culture Documents
High-level Design
Objectives
KV-ledger
(High level components)
Block storage
Stores and retrieves blocks
Assumes blocks arrive in exact sequence
Queries supported
Retrieve blocks by block-hash and block-number
Scan blocks range between two block numbers
Retrieve Transaction by txId
Transactions execution
Simulates transactions and produces ReadWriteSet (Endorser)
Queries/Updates GetKey/SetKey/GetKeyRange
Validates And applies ReadWriteSet (Committer)
Key version based validation (MVCC)
Read-only queries
GetKey/GetKeyRange
Usage
File seg-1
RocksDB
block
index
blockHash
blockNum
txId
SegNo + offset
SegNo + offset
SegNo + offset
Block-1
Block-2 length
Block-2
Cons
Custom block data management on file system
Need to maintain sanity of file segments and consistency between block files and RocksDB
indexes
Need utilities to validate that block files and RocksDB are in sync, and to re-build indexes
as needed
Version maintenance
Should be possible to detect if a key has changed between simulation and committing phase of a
transaction (MVCC validation)
Versioning scheme for a unique version per key two options:
Incrementing numbers (initial implementation)
txID of the last committed transaction that updated the key (implement with config option and compare)
Cons
Transaction ids significantly longer than incrementing numbers (txIds may be 32 bytes if used crypto
hash of contents) in the case of pbft
Transaction simulation
RocksDB
State
index
ccId+keyId
version+deleteMarker+latestValueBytes
This is a simulation runtime optimization. Alternatively, state key index could point to ledger block/transaction
storage write set, and we could read values from there as the single source of truth, but would not be as efficient.
Bitcoin uses a similar index in LevelDB for unspent transactions.