Skip to content

Commit c9c15dd

Browse files
committed
lnd: validate native-sql network on startup
1 parent 6a54d3b commit c9c15dd

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

config_builder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,22 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
12351235
return nil, nil, err
12361236
}
12371237

1238+
// Validate that the database was initialised for the same
1239+
// network as the currently active network. This catches the
1240+
// case where a user accidentally reuses a postgres DSN across
1241+
// different networks (e.g. mainnet → testnet), which would
1242+
// otherwise lead to silent data corruption. For file-based
1243+
// backends (SQLite) this is a no-op because filesystem paths
1244+
// already enforce network separation.
1245+
network := lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name)
1246+
err = dbs.NativeSQLStore.ValidateNetwork(ctx, network)
1247+
if err != nil {
1248+
cleanUp()
1249+
d.logger.Error(err)
1250+
1251+
return nil, nil, err
1252+
}
1253+
12381254
// With the DB ready and migrations applied, we can now create
12391255
// the base DB and transaction executor for the native SQL
12401256
// invoice store.

0 commit comments

Comments
 (0)