Skip to content

Commit b3f35b6

Browse files
committed
lnd: skip network validation when migrations are skipped
Skip the chain_params network check when startup is explicitly configured to skip SQL migrations. In that mode the schema is assumed to already be managed externally, and the chain_params table may not exist yet. Avoid failing startup on a missing table in this path.
1 parent 8ba4847 commit b3f35b6

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

config_builder.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,15 +1248,26 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
12481248
// (e.g. mainnet → testnet), which would otherwise lead to
12491249
// silent data corruption. This check applies to all native SQL
12501250
// backends.
1251-
chainParamsStore := chainparams.NewStore(baseDB)
1252-
err = chainParamsStore.ValidateNetwork(
1253-
ctx, d.cfg.ActiveNetParams.Params,
1254-
)
1255-
if err != nil {
1256-
cleanUp()
1257-
d.logger.Error(err)
1251+
//
1252+
// If migrations are explicitly skipped, we also skip this check
1253+
// because the chain_params table may not exist yet. We check
1254+
// only the active backend's flag since only one backend is
1255+
// used at a time.
1256+
skipMigrations := d.cfg.DB.Sqlite.SkipMigrations
1257+
if d.cfg.DB.Backend == lncfg.PostgresBackend {
1258+
skipMigrations = d.cfg.DB.Postgres.SkipMigrations
1259+
}
1260+
if !skipMigrations {
1261+
chainParamsStore := chainparams.NewStore(baseDB)
1262+
err = chainParamsStore.ValidateNetwork(
1263+
ctx, d.cfg.ActiveNetParams.Params,
1264+
)
1265+
if err != nil {
1266+
cleanUp()
1267+
d.logger.Error(err)
12581268

1259-
return nil, nil, err
1269+
return nil, nil, err
1270+
}
12601271
}
12611272

12621273
// Create the invoice store.

0 commit comments

Comments
 (0)