File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments