Skip to main content
ALL CHAINS

Database Schemas

ELA Main Chain Storage

LevelDB Key Prefixes

PrefixPurpose
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:

PrefixTypePurpose
BKH[]byte → HeaderBlock hash → full header data
BKNuint32 → []byteBlock height → block hash
BST"best" → []byteBest (tip) block hash
ARBuint32 → []byteBlock height → arbiter set

Data Store (LevelDB)

PrefixTypePurpose
TXDtxhash → TxDataTransaction data
OPSoutpoint → OpDataOutpoint (UTXO) data
QUEseq → NotifyDataPending listener notification queue
ADRaddress → boolWatched addresses
TXTtype → boolWatched transaction types
CIDid → dataCustom 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}:

CollectionPurpose
auth_registerRegistered DID documents for authentication
vault_subscriptionVault subscription records
backup_subscriptionBackup subscription records
vault_orderPayment orders
vault_receiptPayment receipts
scriptsRegistered scripting definitions
script_temp_filesTemporary files for script file operations
ipfs_filesFile metadata (CID, path, size, timestamps)
ipfs_cid_refIPFS CID reference counting
collection_metadataCollection encryption metadata
User-defined collectionsApplication 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)
);