Lux Docs

Storage

Unified two-layer storage architecture

Two-Layer Design

┌─────────────────────┐  ┌──────────────────────────┐
│     KV Layer        │  │      Query Layer          │
│     (BadgerDB v4)   │  │  (PostgreSQL / SQLite)    │
│                     │  │                           │
│  - Fast key lookups │  │  - SQL queries            │
│  - Block data       │  │  - Full-text search       │
│  - Vertex/edges     │  │  - Aggregations           │
│  - State storage    │  │  - Pagination             │
└─────────────────────┘  └──────────────────────────┘

PostgreSQL Schema

Core tables (Blockscout-compatible):

TableDescription
blocksBlock headers (partitioned by chain_id)
transactionsAll transaction types
logsEvent logs
internal_transactionsCall traces
addressesAll addresses
tokensERC20/721/1155 metadata
token_transfersTransfer events
token_balancesBalance history (partitioned)
smart_contractsVerified contracts
address_coin_balancesNative balance history

Extensions

CREATE EXTENSION IF NOT EXISTS pg_trgm;         -- Fuzzy search
CREATE EXTENSION IF NOT EXISTS btree_gist;      -- GiST indexes
CREATE EXTENSION IF NOT EXISTS pg_stat_statements; -- Query analysis

Migrations

Four migration files in migrations/:

001_initial_schema.sql      # Core tables
002_indexes.sql             # Index definitions
003_functions.sql           # SQL functions
004_nft_marketplace.sql     # NFT marketplace support

Build Tags

go build ./...                    # SQLite (default)
go build -tags postgres ./...     # PostgreSQL

PostgreSQL v0.2.2 Fixes

  • AUTOINCREMENTSERIAL
  • INSERT OR IGNOREON CONFLICT DO NOTHING
  • datetime()NOW() / to_timestamp()

On this page