What changed, and why it matters
This change is a code cleanup in LND's database migration logic. It threads 'reset' callbacks through helper functions that iterate over old-style database entries, so that batch-processing variables can be properly reset on retries. The commit message frames it as preparation for future retry handling on the source database side. There is no direct security fix here; it is defensive maintenance that could prevent data-integrity issues during migrations if retries occur.
Treat as routine maintenance. If deploying or reviewing related migration code, ensure the future retry logic that consumes these reset callbacks correctly reinitializes state and does not double-apply or skip entries. No immediate security action is required based solely on this commit.
Security signals we found
Defensive data-integrity maintenance in database migration helpers
No direct vulnerability or exploit path visible in the diff
No vendor security disclosure or CVE references present
Change is framed by commit author as preparation for future retry handling
Evidence from the diff
The patch modifies graph/db/sql_migration.go and its test file. It adds a reset func() parameter to forEachPruneLogEntry, forEachZombieEntry, and forEachClosedSCID, and passes those reset functions into the underlying kvdb.View calls instead of no-op callbacks. The reset closures reinitialize per-batch counters (count, chunk, t0) and reallocate batch maps/slices. This is preparatory work for source-DB-side retries. The diff shows no vulnerability being patched, no bounds checks, no input validation, and no cryptographic changes.
Changed components
graph/db/sql_migration.gograph/db/sql_migration_test.goDatabase migration helpers: forEachPruneLogEntry, forEachZombieEntry, forEachClosedSCIDMigration functions: migratePruneLog, migrateClosedSCIDIndex, migrateZombieIndexInspect captured patch +30 / −9
diff --git a/graph/db/sql_migration.go b/graph/db/sql_migration.go
index 5aea3d3..45656e6 100644
--- a/graph/db/sql_migration.go
+++ b/graph/db/sql_migration.go
@@ -923,6 +923,14 @@ func migratePruneLog(ctx context.Context, cfg *sqldb.QueryConfig,
return nil
},
+ func() {
+ count = 0
+ chunk = 0
+ t0 = time.Now()
+ batch = make(
+ map[uint32]chainhash.Hash, cfg.MaxBatchSize,
+ )
+ },
)
if err != nil {
return fmt.Errorf("could not migrate prune log: %w", err)
@@ -975,7 +983,7 @@ func migratePruneLog(ctx context.Context, cfg *sqldb.QueryConfig,
// forEachPruneLogEntry iterates over each prune log entry in the KV
// backend and calls the provided callback function for each entry.
func forEachPruneLogEntry(db kvdb.Backend, cb func(height uint32,
- hash *chainhash.Hash) error) error {
+ hash *chainhash.Hash) error, reset func()) error {
return kvdb.View(db, func(tx kvdb.RTx) error {
metaBucket := tx.ReadBucket(graphMetaBucket)
@@ -997,7 +1005,7 @@ func forEachPruneLogEntry(db kvdb.Backend, cb func(height uint32,
return cb(blockHeight, &blockHash)
})
- }, func() {})
+ }, reset)
}
// migrateClosedSCIDIndex migrates the closed SCID index from the KV backend to
@@ -1091,7 +1099,14 @@ func migrateClosedSCIDIndex(ctx context.Context, cfg *sqldb.QueryConfig,
return nil
}
- err := forEachClosedSCID(kvBackend, migrateSingleClosedSCID)
+ err := forEachClosedSCID(
+ kvBackend, migrateSingleClosedSCID, func() {
+ count = 0
+ chunk = 0
+ t0 = time.Now()
+ batch = make([][]byte, 0, cfg.MaxBatchSize)
+ },
+ )
if err != nil {
return fmt.Errorf("could not migrate closed SCID index: %w",
err)
@@ -1270,6 +1285,11 @@ func migrateZombieIndex(ctx context.Context, cfg *sqldb.QueryConfig,
})
return nil
+ }, func() {
+ count = 0
+ chunk = 0
+ t0 = time.Now()
+ batch = make(map[uint64]*zombieEntry, cfg.MaxBatchSize)
})
if err != nil {
return fmt.Errorf("could not migrate zombie index: %w", err)
@@ -1293,7 +1313,7 @@ func migrateZombieIndex(ctx context.Context, cfg *sqldb.QueryConfig,
// forEachZombieEntry iterates over each zombie channel entry in the
// KV backend and calls the provided callback function for each entry.
func forEachZombieEntry(db kvdb.Backend, cb func(chanID uint64, pubKey1,
- pubKey2 [33]byte) error) error {
+ pubKey2 [33]byte) error, reset func()) error {
return kvdb.View(db, func(tx kvdb.RTx) error {
edges := tx.ReadBucket(edgeBucket)
@@ -1312,13 +1332,13 @@ func forEachZombieEntry(db kvdb.Backend, cb func(chanID uint64, pubKey1,
return cb(byteOrder.Uint64(k), pubKey1, pubKey2)
})
- }, func() {})
+ }, reset)
}
// forEachClosedSCID iterates over each closed SCID in the KV backend and calls
// the provided callback function for each SCID.
func forEachClosedSCID(db kvdb.Backend,
- cb func(lnwire.ShortChannelID) error) error {
+ cb func(lnwire.ShortChannelID) error, reset func()) error {
return kvdb.View(db, func(tx kvdb.RTx) error {
closedScids := tx.ReadBucket(closedScidBucket)
@@ -1331,5 +1351,5 @@ func forEachClosedSCID(db kvdb.Backend,
byteOrder.Uint64(k),
))
})
- }, func() {})
+ }, reset)
}
diff --git a/graph/db/sql_migration_test.go b/graph/db/sql_migration_test.go
index 13e3bff..d4bba60 100644
--- a/graph/db/sql_migration_test.go
+++ b/graph/db/sql_migration_test.go
@@ -600,6 +600,7 @@ func checkKVPruneLogEntries(t *testing.T, kv *KVStore, sql *SQLStore,
return nil
},
+ func() {},
)
require.NoError(t, err)
@@ -631,7 +632,7 @@ func checkClosedSCIDIndex(t *testing.T, kv kvdb.Backend, sql *SQLStore) {
require.True(t, closed)
return nil
- })
+ }, func() {})
require.NoError(t, err)
}
@@ -663,7 +664,7 @@ func checkZombieIndex(t *testing.T, kv kvdb.Backend, sql *SQLStore) {
}
return nil
- })
+ }, func() {})
require.NoError(t, err)
}
Why this scored 22/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.