@@ -1046,23 +1046,6 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
10461046 )
10471047 }
10481048
1049- graphStore , err := graphdb .NewKVStore (
1050- databaseBackends .GraphDB , graphDBOptions ... ,
1051- )
1052- if err != nil {
1053- return nil , nil , err
1054- }
1055-
1056- dbs .GraphDB , err = graphdb .NewChannelGraph (graphStore , chanGraphOpts ... )
1057- if err != nil {
1058- cleanUp ()
1059-
1060- err = fmt .Errorf ("unable to open graph DB: %w" , err )
1061- d .logger .Error (err )
1062-
1063- return nil , nil , err
1064- }
1065-
10661049 dbOptions := []channeldb.OptionModifier {
10671050 channeldb .OptionDryRunMigration (cfg .DryRunMigration ),
10681051 channeldb .OptionKeepFailedPaymentAttempts (
@@ -1098,6 +1081,10 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
10981081 return nil , nil , err
10991082 }
11001083
1084+ // The graph store implementation we will use depends on whether
1085+ // native SQL is enabled or not.
1086+ var graphStore graphdb.V1Store
1087+
11011088 // Instantiate a native SQL store if the flag is set.
11021089 if d .cfg .DB .UseNativeSQL {
11031090 migrations := sqldb .GetMigrations ()
@@ -1156,17 +1143,27 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
11561143 // the base DB and transaction executor for the native SQL
11571144 // invoice store.
11581145 baseDB := dbs .NativeSQLStore .GetBaseDB ()
1159- executor := sqldb .NewTransactionExecutor (
1146+ invoiceExecutor := sqldb .NewTransactionExecutor (
11601147 baseDB , func (tx * sql.Tx ) invoices.SQLInvoiceQueries {
11611148 return baseDB .WithTx (tx )
11621149 },
11631150 )
11641151
11651152 sqlInvoiceDB := invoices .NewSQLStore (
1166- executor , clock .NewDefaultClock (),
1153+ invoiceExecutor , clock .NewDefaultClock (),
11671154 )
11681155
11691156 dbs .InvoiceDB = sqlInvoiceDB
1157+
1158+ graphStore , err = d .getGraphStore (
1159+ baseDB , databaseBackends .GraphDB , graphDBOptions ... ,
1160+ )
1161+ if err != nil {
1162+ err = fmt .Errorf ("unable to get graph store: %w" , err )
1163+ d .logger .Error (err )
1164+
1165+ return nil , nil , err
1166+ }
11701167 } else {
11711168 // Check if the invoice bucket tombstone is set. If it is, we
11721169 // need to return and ask the user switch back to using the
@@ -1188,6 +1185,23 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
11881185 }
11891186
11901187 dbs .InvoiceDB = dbs .ChanStateDB
1188+
1189+ graphStore , err = graphdb .NewKVStore (
1190+ databaseBackends .GraphDB , graphDBOptions ... ,
1191+ )
1192+ if err != nil {
1193+ return nil , nil , err
1194+ }
1195+ }
1196+
1197+ dbs .GraphDB , err = graphdb .NewChannelGraph (graphStore , chanGraphOpts ... )
1198+ if err != nil {
1199+ cleanUp ()
1200+
1201+ err = fmt .Errorf ("unable to open channel graph DB: %w" , err )
1202+ d .logger .Error (err )
1203+
1204+ return nil , nil , err
11911205 }
11921206
11931207 // Wrap the watchtower client DB and make sure we clean up.
0 commit comments