Skip to content

Commit e38aa6d

Browse files
committed
multi: itest jobs with SQL graph backend
In this commit, a new `test_native_sql` build flag is defined. If this build flag is used along with the `--use-native-sql` config option, then the SQLStore implementation of the graphdb.V1Store will be initialised. This is then used to run our itest suite against the new SQLStore graph implementation. NOTE that this only works for new nodes currently - the migration from kv-to-sql is yet to be implemeneted.
1 parent b4b1c4b commit e38aa6d

File tree

6 files changed

+88
-21
lines changed

6 files changed

+88
-21
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,14 @@ jobs:
368368
args: backend=bitcoind dbbackend=sqlite
369369
- name: bitcoind-sqlite-nativesql
370370
args: backend=bitcoind dbbackend=sqlite nativesql=true
371+
- name: bitcoind-sqlite=nativesql-experiment
372+
args: backend=bitcoind dbbackend=sqlite nativesql=true tags=test_native_sql
371373
- name: bitcoind-postgres
372374
args: backend=bitcoind dbbackend=postgres
373375
- name: bitcoind-postgres-nativesql
374376
args: backend=bitcoind dbbackend=postgres nativesql=true
377+
- name: bitcoind-postgres-nativesql-experiment
378+
args: backend=bitcoind dbbackend=postgres nativesql=true tags=test_native_sql
375379
steps:
376380
- name: git checkout
377381
uses: actions/checkout@v4

config_builder.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

config_prod.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build !test_native_sql
2+
3+
package lnd
4+
5+
import (
6+
graphdb "github.com/lightningnetwork/lnd/graph/db"
7+
"github.com/lightningnetwork/lnd/kvdb"
8+
"github.com/lightningnetwork/lnd/sqldb"
9+
)
10+
11+
// getGraphStore returns a graphdb.V1Store backed by a graphdb.KVStore
12+
// implementation.
13+
func (d *DefaultDatabaseBuilder) getGraphStore(_ *sqldb.BaseDB,
14+
kvBackend kvdb.Backend,
15+
opts ...graphdb.StoreOptionModifier) (graphdb.V1Store, error) {
16+
17+
return graphdb.NewKVStore(kvBackend, opts...)
18+
}

config_test_native_sql.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build test_native_sql
2+
3+
package lnd
4+
5+
import (
6+
"database/sql"
7+
8+
graphdb "github.com/lightningnetwork/lnd/graph/db"
9+
"github.com/lightningnetwork/lnd/kvdb"
10+
"github.com/lightningnetwork/lnd/sqldb"
11+
)
12+
13+
// getGraphStore returns a graphdb.V1Store backed by a graphdb.SQLStore
14+
// implementation.
15+
func (d *DefaultDatabaseBuilder) getGraphStore(baseDB *sqldb.BaseDB,
16+
_ kvdb.Backend, opts ...graphdb.StoreOptionModifier) (graphdb.V1Store,
17+
error) {
18+
19+
graphExecutor := sqldb.NewTransactionExecutor(
20+
baseDB, func(tx *sql.Tx) graphdb.SQLQueries {
21+
return baseDB.WithTx(tx)
22+
},
23+
)
24+
25+
return graphdb.NewSQLStore(
26+
&graphdb.SQLStoreConfig{
27+
ChainHash: *d.cfg.ActiveNetParams.GenesisHash,
28+
},
29+
graphExecutor, opts...,
30+
)
31+
}

sqldb/migrations_dev.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build test_db_postgres || test_db_sqlite
1+
//go:build test_db_postgres || test_db_sqlite || test_native_sql
22

33
package sqldb
44

sqldb/migrations_prod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !test_db_postgres && !test_db_sqlite
1+
//go:build !test_db_postgres && !test_db_sqlite && !test_native_sql
22

33
package sqldb
44

0 commit comments

Comments
 (0)