Database Schemas
ELA Main Chain Storage
LevelDB Key Prefixes
| Prefix | Purpose |
|---|---|
BLK_ | Block data storage |
TX_ | Transaction storage |
UTXO_ | Unspent transaction outputs |
HDR_ | Block headers |
HGT_ | Height-to-hash mapping |
FFE_ | FFLDB file metadata |
SCT_ | Small cross-chain transfers |
CP_ | Checkpoints |
FFLDB (Flat File + LevelDB)
The primary storage engine stores full blocks in sequential flat files with LevelDB as the index:
data/
├── mainnet/
│ ├── block/
│ │ ├── blk00000.fdb # Block data file 0
│ │ ├── blk00001.fdb # Block data file 1
│ │ └── ...
│ └── index/
│ └── MANIFEST-* # LevelDB index files
└── checkpoints/
├── arbiters_* # Arbiter state checkpoints
├── committee_* # Elastos Council checkpoints
└── state_* # Producer state checkpoints
Block storage format:
[4 bytes: network magic] [4 bytes: block size] [block data]
Each flat file grows up to maxBlockFileSize (512 MB) before rotating.
ChainStore Structure
type ChainStore struct {
levelDB IStore // LevelDB for lightweight lookups
fflDB IFFLDBChainStore // FFLDB for block data
currentBlockHeight uint32
persistMutex sync.Mutex
}
Block Index (In-Memory)
type BlockNode struct {
Hash *Uint256
ParentHash *Uint256
Height uint32
Version uint32
Timestamp uint32
Bits uint32
}
The in-memory block index maintains Nodes as a flat array and DepNodes as a dependency map for fork detection.
Arbiter SQLite Schema
Source: store/datastore.go
-- Main chain transaction cache (pending deposits)
CREATE TABLE MainChainTxs (
TransactionHash TEXT PRIMARY KEY,
GenesisBlockAddress TEXT,
TransactionData BLOB,
MerkleProof BLOB,
BlockHeight INTEGER
);
-- Sidechain transaction cache (pending withdrawals)
CREATE TABLE SideChainTxs (
TransactionHash TEXT PRIMARY KEY,
GenesisBlockAddress TEXT,
TransactionData BLOB,
BlockHeight INTEGER
);
-- Finished transactions (succeed/failed tracking)
CREATE TABLE FinishedTxs (
TransactionHash TEXT PRIMARY KEY,
GenesisBlockAddress TEXT,
Status INTEGER,
BlockHeight INTEGER
);
-- Registered sidechains
CREATE TABLE RegisteredSideChains (
GenesisBlockAddress TEXT PRIMARY KEY,
GenesisBlockHash TEXT,
RegisterHeight INTEGER,
ExchangeRate REAL,
EffectiveHeight INTEGER
);
-- Schnorr nonce/R-value cache
CREATE TABLE SchnorrR (
NonceHash TEXT PRIMARY KEY,
Rx TEXT,
Ry TEXT,
Px TEXT,
Py TEXT,
K0 TEXT
);
SPV Storage
Header Store (LevelDB)
Key prefixes in interface/store/prefix.go:
| Prefix | Type | Purpose |
|---|---|---|
BKH | []byte → Header | Block hash → full header data |
BKN | uint32 → []byte | Block height → block hash |
BST | "best" → []byte | Best (tip) block hash |
ARB | uint32 → []byte | Block height → arbiter set |
Data Store (LevelDB)
| Prefix | Type | Purpose |
|---|---|---|
TXD | txhash → TxData | Transaction data |
OPS | outpoint → OpData | Outpoint (UTXO) data |
QUE | seq → NotifyData | Pending listener notification queue |
ADR | address → bool | Watched addresses |
TXT | type → bool | Watched transaction types |
CID | id → data | Custom ID reservations |
SPV Wallet SQLite (sample app)
CREATE TABLE UTXOs (
OutPoint BLOB PRIMARY KEY,
Value INTEGER,
LockTime INTEGER,
AtHeight INTEGER
);
CREATE TABLE STXOs (
OutPoint BLOB PRIMARY KEY,
Value INTEGER,
SpendHash BLOB,
SpendHeight INTEGER
);
CREATE TABLE Txs (
Hash BLOB PRIMARY KEY,
RawData BLOB,
Timestamp INTEGER
);
Hive Node MongoDB Collections
Each user vault has a sandboxed database hive_user_{did_hash}:
| Collection | Purpose |
|---|---|
auth_register | Registered DID documents for authentication |
vault_subscription | Vault subscription records |
backup_subscription | Backup subscription records |
vault_order | Payment orders |
vault_receipt | Payment receipts |
scripts | Registered scripting definitions |
script_temp_files | Temporary files for script file operations |
ipfs_files | File metadata (CID, path, size, timestamps) |
ipfs_cid_ref | IPFS CID reference counting |
collection_metadata | Collection encryption metadata |
| User-defined collections | Application data (per-script/per-app) |
Carrier v2 Storage
SQLite database for local DHT state:
-- Known nodes for routing table persistence
CREATE TABLE nodes (
id BLOB PRIMARY KEY, -- Ed25519 public key (32 bytes)
address TEXT, -- IP:port
last_seen INTEGER, -- Unix timestamp
version INTEGER -- Protocol version
);
-- Stored values (DHT key-value pairs)
CREATE TABLE values (
key BLOB PRIMARY KEY, -- SHA-256 hash
value BLOB, -- Stored data
timestamp INTEGER, -- Creation time
expiry INTEGER -- Expiration time
);
-- Peer announcements
CREATE TABLE peers (
key BLOB, -- Lookup key
peer_id BLOB, -- Peer's node ID
address TEXT, -- Peer's address
timestamp INTEGER,
PRIMARY KEY (key, peer_id)
);