Skip to content

SQLite storage layer implementation #10

@tac0turtle

Description

@tac0turtle

Summary

Implement the SQLite-based storage layer (pkg/store/) as defined in the design doc. This is the foundational persistence layer all other components depend on.

Schema

CREATE TABLE sync_state (
    id INTEGER PRIMARY KEY CHECK (id = 1),
    last_synced_height INTEGER NOT NULL DEFAULT 0,
    start_height INTEGER NOT NULL,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE headers (
    height INTEGER PRIMARY KEY,
    hash BLOB NOT NULL,
    data_hash BLOB NOT NULL,
    raw_header BLOB NOT NULL,
    time TIMESTAMP NOT NULL
);

CREATE TABLE blobs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    height INTEGER NOT NULL,
    namespace BLOB NOT NULL,
    commitment BLOB NOT NULL,
    data BLOB NOT NULL,
    share_version INTEGER NOT NULL,
    signer BLOB,
    blob_index INTEGER NOT NULL,
    UNIQUE(height, namespace, commitment)
);

CREATE INDEX idx_blobs_ns_height ON blobs(namespace, height);

CREATE TABLE namespaces (
    namespace BLOB PRIMARY KEY,
    name TEXT,
    enabled BOOLEAN DEFAULT TRUE
);

Requirements

  • Store interface in pkg/store/store.go
  • SQLite implementation in pkg/store/sqlite.go
  • Schema migrations (embed SQL via embed package)
  • Methods: InsertHeader, InsertBlobs, GetBlobsByHeight, GetBlob (by height+ns+commitment), GetHeader, GetSyncState, UpdateSyncState
  • WAL mode enabled for concurrent read/write
  • Connection pooling via database/sql
  • Unit tests with in-memory SQLite

References

  • Design doc: test_plan.md — Storage Design section

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions