Repository navigation
Conversation
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
|
👋 Hi! This PR is now in draft status. |
vincenzopalazzo
left a comment
There was a problem hiding this comment.
Concept ACK
I added a small comment on how to include the library!
| rustls = { version = "0.23", default-features = false, features = ["ring"] } | ||
| # rusqlite 0.40.0 and 0.40.1 do not compile on our MSRV. | ||
| rusqlite = { version = ">=0.31.0, <0.40.0", features = ["bundled"], optional = true } | ||
| sqlite-thin = { git = "https://github.com/thesimplekid/cdk", rev = "50b2688b0c0b78e55538935a795f83ad1f26c58a", features = ["bundled"], optional = true } |
There was a problem hiding this comment.
My C part of my brain triggers here as an opportunity to remove the bundled version and to be able to load the library dynamically from the system?
IMHO, the cost is about a megabyte, and it has its own SQLite CVEs, but IDK if I am missing some previous discussion about not doing this
There was a problem hiding this comment.
My C part of my brain triggers here as an opportunity to remove the
bundledversion and to be able to load the library dynamically from the system?
That's fine for LDK Server where we can add libsqlite to the prereqs, but I'm not sure we can bet on iOS and Android shipping it.
There was a problem hiding this comment.
Agreed, dropping bundled outright is the wrong default for iOS and Android.
What I meant is not to hardcode features = ["bundled"] on the dependency. sqlite-thin already links -lsqlite3 when that feature is off, so:
storage-sqlite = ["dep:sqlite-thin"]
sqlite-bundled = ["sqlite-thin/bundled"]
libsqlite3-sysmay only be linked once per build and everyrusqliterelease pins exactly one version of it, so LDK Node and any application using
SQLite have to agree on a
rusqliterelease. Our MSRV additionally keeps usfrom admitting recent releases, which keeps downstream users from picking up
newer bundled SQLite versions.
This switches
SqliteStoretosqlite-thin, a small wrapper that declares theSQLite C API itself and accepts any
libsqlite3-sysrelease 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-diskformat is unchanged.
For downstream users this drops 6 crates from the tree (
rusqlite,hashlink,hashbrown,foldhash,fallible-iterator,fallible-streaming-iterator) andadds 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-thinneeds a crates.io release before this can be merged,and since it doesn't cap
libsqlite3-sys, a downstream build without its ownrusqliteresolves to 0.40.0, which requires Rust 1.88 (our MSRV is 1.85).