Skip to content

Replace rusqlite with sqlite-thin - #1258

Draft
tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-11-explore-sqlite-thin
Draft

tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-11-explore-sqlite-thin

Conversation

@tnull

@tnull tnull commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

libsqlite3-sys may only be linked once per build and every rusqlite
release pins exactly one version of it, so LDK Node and any application using
SQLite have to agree on a rusqlite release. Our MSRV additionally keeps us
from admitting recent releases, which keeps downstream users from picking up
newer bundled SQLite versions.

This switches SqliteStore to sqlite-thin, a small wrapper that declares the
SQLite C API itself and accepts any libsqlite3-sys release from 0.28 on,
leaving the version choice to the application. It mirrors the subset of
rusqlite's API we use, so the change is an import rename and the on-disk
format is unchanged.

For downstream users this drops 6 crates from the tree (rusqlite, hashlink,
hashbrown, foldhash, fallible-iterator, fallible-streaming-iterator) and
adds 1 (sqlite-thin).

The first commit adds tests for the paths most likely to be affected (empty and
large values, upgrading a database written by LDK Node v0.7, a failed migration
rolling back, and lock contention). They pass both before and after the switch.

Still open: sqlite-thin needs a crates.io release before this can be merged,
and since it doesn't cap libsqlite3-sys, a downstream build without its own
rusqlite resolves to 0.40.0, which requires Rust 1.88 (our MSRV is 1.85).

The SQLite store's tests only ever read databases they wrote
themselves, and neither covered zero-length or multi-megabyte values,
a schema migration failing halfway through, nor contention with a
second connection. These are the paths most likely to change behavior
when the underlying SQLite wrapper is touched.

Add tests asserting that values of any length are stored as BLOBs,
that a database written by LDK Node v0.7 is migrated and remains
usable, that a failed migration leaves the database untouched, and
that writes wait for a lock held by another connection.

Co-Authored-By: HAL 9000
As libsqlite3-sys may only be linked once per build and every rusqlite
release pins a single version of it, LDK Node and any application
using SQLite themselves had to agree on a rusqlite release. Our MSRV
furthermore kept us from admitting recent releases, leaving downstream
users unable to pick up newer bundled SQLite versions.

Access SQLite through sqlite-thin instead, which declares the C API
itself and hence accepts any libsqlite3-sys release from 0.28 on,
leaving the choice to the application. It mirrors the subset of
rusqlite's API we use, so the store's logic remains unchanged. As the
crate is not released yet, we for now pin the revision proposed in
cashubtc/cdk#2963.

Co-Authored-By: HAL 9000
@ldk-reviews-bot

ldk-reviews-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

👋 Hi! This PR is now in draft status.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

@tnull
tnull marked this pull request as draft November 24, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants