Merge pull request #11311 from ziggie1984/fix-sql-graph-empty-signatures
What changed, and why it matters
This is a bug-fix patch for LND's native SQLite graph migration. When moving channel data from the older key-value (KV) database format to the new SQLite format, empty routing-policy signatures were stored differently: KV used an empty-but-non-nil byte slice, while SQLite returned nil. The migration validation treated these as unequal, causing the migration to fail. The fix normalizes empty signatures to nil before comparison so the migration succeeds. It is a correctness/reliability fix rather than an exploitable vulnerability.
Include this fix in any LND release that supports native SQLite graph backend migration. Operators migrating from KV to SQLite should use a release containing this patch to avoid migration failures for channels with empty policy signatures. No runtime configuration or operational workaround is needed.
Security signals we found
Data migration validation failure due to empty byte slice representation mismatch
No cryptographic bypass: signature bytes are still validated if present
Fix only affects comparison logic after migration, not runtime routing policy enforcement
Release notes classify this as a bug fix, not a security issue
Evidence from the diff
The commit modifies graph/db/migration1/sql_migration.go to normalize SigBytes to nil when len()==0 during validation of migrated channel policies. It also updates the migration test to include an empty-signature policy and adjusts expected policy counts. The root cause is a representation mismatch between the KV store (non-nil empty slice) and SQLite (nil for empty BLOB). The effect was a false-positive validation failure during native SQLite graph migrations, not a logic error in consensus or cryptographic validation.
Changed components
graph/db/migration1/sql_migration.gograph/db/migration1/sql_migration_test.goNative SQLite graph migration path in LNDInspect captured patch +41 / −3
### docs/release-notes/release-notes-0.20.6.md
@@ -21,6 +21,11 @@
# Bug Fixes
+* Native SQLite graph migrations [now accept policies with empty
+ signatures](https://github.com/lightningnetwork/lnd/pull/11311) instead of
+ failing validation because the KV and SQL stores use different empty byte
+ slice representations.
+
# New Features
## Functional Enhancements
@@ -56,3 +61,5 @@
## Tooling and Documentation
# Contributors (Alphabetical Order)
+
+* Ziggie
### docs/release-notes/release-notes-0.21.5.md
@@ -21,6 +21,11 @@
# Bug Fixes
+* Native SQLite graph migrations [now accept policies with empty
+ signatures](https://github.com/lightningnetwork/lnd/pull/11311) instead of
+ failing validation because the KV and SQL stores use different empty byte
+ slice representations.
+
# New Features
## Functional Enhancements
@@ -60,3 +65,5 @@
## Tooling and Documentation
# Contributors (Alphabetical Order)
+
+* Ziggie
### graph/db/migration1/sql_migration.go
@@ -856,12 +856,20 @@ func validateMigratedChannelWithBatchData(cfg *SQLStoreConfig,
default:
}
+ // The KV decoder uses a non-nil empty slice, while SQLite
+ // uses nil for an empty BLOB. Normalize both before comparison.
if len(expPolicy.ExtraOpaqueData) == 0 {
expPolicy.ExtraOpaqueData = nil
}
if len(migPolicy.ExtraOpaqueData) == 0 {
migPolicy.ExtraOpaqueData = nil
}
+ if len(expPolicy.SigBytes) == 0 {
+ expPolicy.SigBytes = nil
+ }
+ if len(migPolicy.SigBytes) == 0 {
+ migPolicy.SigBytes = nil
+ }
return sqldb.CompareRecords(
*expPolicy, *migPolicy, "channel policy",
### graph/db/migration1/sql_migration_test.go
@@ -408,11 +408,21 @@ func TestMigrateGraphToSQL(t *testing.T) {
},
),
- // Now, insert a single update for the
- // first channel.
+ // Insert two updates for the first channel,
+ // preserving the non-empty signature case.
// - channel policy count += 1
makeTestPolicy(chanID1, node1, false),
+ // SQLite returns nil when this empty signature is
+ // read back, exercising the representation mismatch.
+ // - channel policy count += 1
+ makeTestPolicy(
+ chanID1, node2, true,
+ func(p *models.ChannelEdgePolicy) {
+ p.SigBytes = []byte{}
+ },
+ ),
+
// Insert two updates for the second
// channel, one for each direction.
// - channel policy count += 1
@@ -429,7 +439,7 @@ func TestMigrateGraphToSQL(t *testing.T) {
expGraphStats: graphStats{
numNodes: 4,
numChannels: 3,
- numPolicies: 3,
+ numPolicies: 4,
},
},
{
@@ -678,9 +688,15 @@ func fetchAllChannelsAndPolicies(t *testing.T, store V1Store) chanSet {
if p1 != nil && len(p1.ExtraOpaqueData) == 0 {
p1.ExtraOpaqueData = nil
}
+ if p1 != nil && len(p1.SigBytes) == 0 {
+ p1.SigBytes = nil
+ }
if p2 != nil && len(p2.ExtraOpaqueData) == 0 {
p2.ExtraOpaqueData = nil
}
+ if p2 != nil && len(p2.SigBytes) == 0 {
+ p2.SigBytes = nil
+ }
channels = append(channels, chanInfo{
edgeInfo: info,Why this scored 30/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.