What changed, and why it matters
This commit fixes build errors that occurred when compiling LND's new SQL database module (v2) for platforms or build tags that exclude SQLite (for example, WebAssembly or some embedded architectures). It restores a 'stub' implementation so the code still compiles, updates the stub to match the current migration interface, and adds missing helper functions for interpreting Postgres database errors. There is no direct security vulnerability being patched; it is a build-compatibility and error-handling completeness fix.
Treat as a normal build-fix commit. Reviewers should verify that the no_sqlite build tag now compiles in CI and that the new Postgres error helpers behave identically to their SQLite-enabled counterparts. No urgent security response is indicated.
Security signals we found
Build-tag-only code path was out of sync with main implementation, which could hide future security-relevant error-handling gaps.
Restores error classification for Postgres serialization/deadlock/schema errors on no-SQLite targets; misclassification of such errors could affect retry/correctness behavior.
No direct memory-safety, authentication, or cryptographic issue present in the diff.
Evidence from the diff
The patch updates sqldb/v2/no_sqlite.go and sqldb/v2/sqlerrors_no_sqlite.go under the no_sqlite build tag. It removes an unused context import, changes NewSqliteStore and ExecuteMigrations to return a generic ‘not supported on this platform’ error, and renames ApplyAllMigrations to ExecuteMigrations with a simpler signature to match the current interface. In sqlerrors_no_sqlite.go it adds parsing for InFailedSQLTransaction, DeadlockDetected, UndefinedColumn, and UndefinedTable Postgres error codes, plus helper types/functions ErrSchemaError, IsSchemaError, and IsSerializationOrDeadlockError. These helpers mirror logic that already exists in the SQLite-enabled files, making the Postgres-only stub consistent with the rest of the package.
Changed components
sqldb/v2/no_sqlite.gosqldb/v2/sqlerrors_no_sqlite.gono_sqlite build target of lnd/sqldb/v2Inspect captured patch +56 / −7
diff --git a/sqldb/v2/no_sqlite.go b/sqldb/v2/no_sqlite.go
index 0665882..e496e3c 100644
--- a/sqldb/v2/no_sqlite.go
+++ b/sqldb/v2/no_sqlite.go
@@ -3,7 +3,6 @@
package sqldb
import (
- "context"
"fmt"
)
@@ -27,7 +26,7 @@ type SqliteStore struct {
// NewSqliteStore attempts to open a new sqlite database based on the passed
// config.
func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
- return nil, fmt.Errorf("SQLite backend not supported in WebAssembly")
+ return nil, fmt.Errorf("SQLite backend not supported on this platform")
}
// GetBaseDB returns the underlying BaseDB instance for the SQLite store.
@@ -36,10 +35,9 @@ func (s *SqliteStore) GetBaseDB() *BaseDB {
return s.BaseDB
}
-// ApplyAllMigrations applies both the SQLC and custom in-code migrations to
-// the SQLite database.
-func (s *SqliteStore) ApplyAllMigrations(context.Context,
- []MigrationSet) error {
+// ExecuteMigrations returns an error because the SQLite backend is unavailable
+// on this platform.
+func (s *SqliteStore) ExecuteMigrations(MigrationSet) error {
- return fmt.Errorf("SQLite backend not supported in WebAssembly")
+ return fmt.Errorf("SQLite backend not supported on this platform")
}
diff --git a/sqldb/v2/sqlerrors_no_sqlite.go b/sqldb/v2/sqlerrors_no_sqlite.go
index ae79b7f..0c82eca 100644
--- a/sqldb/v2/sqlerrors_no_sqlite.go
+++ b/sqldb/v2/sqlerrors_no_sqlite.go
@@ -46,6 +46,26 @@ func parsePostgresError(pqErr *pgconn.PgError) error {
DBError: pqErr,
}
+ // In failed SQL transaction because we didn't catch a previous
+ // serialization error, so return this one as a serialization error.
+ case pgerrcode.InFailedSQLTransaction:
+ return &ErrSerializationError{
+ DBError: pqErr,
+ }
+
+ // Deadlock detected because of a serialization error, so return this
+ // one as a serialization error.
+ case pgerrcode.DeadlockDetected:
+ return &ErrSerializationError{
+ DBError: pqErr,
+ }
+
+ // Handle schema error.
+ case pgerrcode.UndefinedColumn, pgerrcode.UndefinedTable:
+ return &ErrSchemaError{
+ DBError: pqErr,
+ }
+
default:
return fmt.Errorf("unknown postgres error: %w", pqErr)
}
@@ -84,3 +104,34 @@ func IsSerializationError(err error) bool {
var serializationError *ErrSerializationError
return errors.As(err, &serializationError)
}
+
+// IsSerializationOrDeadlockError returns true if the given error is either a
+// deadlock error or a serialization error.
+//
+// DeadlockDetected errors are already mapped to ErrSerializationError above,
+// so checking for serialization errors is sufficient on no-SQLite targets.
+func IsSerializationOrDeadlockError(err error) bool {
+ return IsSerializationError(err)
+}
+
+// ErrSchemaError is an error type which represents a database agnostic error
+// that the schema of the database is incorrect for the given query.
+type ErrSchemaError struct {
+ DBError error
+}
+
+// Unwrap returns the wrapped error.
+func (e ErrSchemaError) Unwrap() error {
+ return e.DBError
+}
+
+// Error returns the error message.
+func (e ErrSchemaError) Error() string {
+ return e.DBError.Error()
+}
+
+// IsSchemaError returns true if the given error is a schema error.
+func IsSchemaError(err error) bool {
+ var schemaError *ErrSchemaError
+ return errors.As(err, &schemaError)
+}
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.