@@ -139,27 +139,6 @@ func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore,
139
139
return s , nil
140
140
}
141
141
142
- // TxOptions defines the set of db txn options the SQLQueries
143
- // understands.
144
- type TxOptions struct {
145
- // readOnly governs if a read only transaction is needed or not.
146
- readOnly bool
147
- }
148
-
149
- // ReadOnly returns true if the transaction should be read only.
150
- //
151
- // NOTE: This implements the TxOptions.
152
- func (a * TxOptions ) ReadOnly () bool {
153
- return a .readOnly
154
- }
155
-
156
- // NewReadTx creates a new read transaction option set.
157
- func NewReadTx () * TxOptions {
158
- return & TxOptions {
159
- readOnly : true ,
160
- }
161
- }
162
-
163
142
// AddLightningNode adds a vertex/node to the graph database. If the node is not
164
143
// in the database from before, this will add a new, unconnected one to the
165
144
// graph. If it is present from before, this will update that node's
@@ -192,11 +171,8 @@ func (s *SQLStore) FetchLightningNode(pubKey route.Vertex) (
192
171
193
172
ctx := context .TODO ()
194
173
195
- var (
196
- readTx = NewReadTx ()
197
- node * models.LightningNode
198
- )
199
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
174
+ var node * models.LightningNode
175
+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
200
176
var err error
201
177
_ , node , err = getNodeByPubKey (ctx , db , pubKey )
202
178
@@ -222,11 +198,10 @@ func (s *SQLStore) HasLightningNode(pubKey [33]byte) (time.Time, bool,
222
198
ctx := context .TODO ()
223
199
224
200
var (
225
- readTx = NewReadTx ()
226
201
exists bool
227
202
lastUpdate time.Time
228
203
)
229
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
204
+ err := s .db .ExecTx (ctx , sqldb . ReadTxOpt () , func (db SQLQueries ) error {
230
205
dbNode , err := db .GetNodeByPubKey (
231
206
ctx , sqlc.GetNodeByPubKeyParams {
232
207
Version : int16 (ProtocolV1 ),
@@ -266,11 +241,10 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
266
241
ctx := context .TODO ()
267
242
268
243
var (
269
- readTx = NewReadTx ()
270
244
addresses []net.Addr
271
245
known bool
272
246
)
273
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
247
+ err := s .db .ExecTx (ctx , sqldb . ReadTxOpt () , func (db SQLQueries ) error {
274
248
var err error
275
249
known , addresses , err = getNodeAddresses (
276
250
ctx , db , nodePub .SerializeCompressed (),
@@ -297,8 +271,7 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
297
271
func (s * SQLStore ) DeleteLightningNode (pubKey route.Vertex ) error {
298
272
ctx := context .TODO ()
299
273
300
- var writeTxOpts TxOptions
301
- err := s .db .ExecTx (ctx , & writeTxOpts , func (db SQLQueries ) error {
274
+ err := s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
302
275
res , err := db .DeleteNodeByPubKey (
303
276
ctx , sqlc.DeleteNodeByPubKeyParams {
304
277
Version : int16 (ProtocolV1 ),
@@ -346,11 +319,10 @@ func (s *SQLStore) FetchNodeFeatures(nodePub route.Vertex) (
346
319
// NOTE: part of the V1Store interface.
347
320
func (s * SQLStore ) LookupAlias (pub * btcec.PublicKey ) (string , error ) {
348
321
var (
349
- ctx = context .TODO ()
350
- readTx = NewReadTx ()
351
- alias string
322
+ ctx = context .TODO ()
323
+ alias string
352
324
)
353
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
325
+ err := s .db .ExecTx (ctx , sqldb . ReadTxOpt () , func (db SQLQueries ) error {
354
326
dbNode , err := db .GetNodeByPubKey (
355
327
ctx , sqlc.GetNodeByPubKeyParams {
356
328
Version : int16 (ProtocolV1 ),
@@ -387,11 +359,8 @@ func (s *SQLStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
387
359
func (s * SQLStore ) SourceNode () (* models.LightningNode , error ) {
388
360
ctx := context .TODO ()
389
361
390
- var (
391
- readTx = NewReadTx ()
392
- node * models.LightningNode
393
- )
394
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
362
+ var node * models.LightningNode
363
+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
395
364
_ , nodePub , err := getSourceNode (ctx , db , ProtocolV1 )
396
365
if err != nil {
397
366
return fmt .Errorf ("unable to fetch V1 source node: %w" ,
@@ -416,9 +385,8 @@ func (s *SQLStore) SourceNode() (*models.LightningNode, error) {
416
385
// NOTE: part of the V1Store interface.
417
386
func (s * SQLStore ) SetSourceNode (node * models.LightningNode ) error {
418
387
ctx := context .TODO ()
419
- var writeTxOpts TxOptions
420
388
421
- return s .db .ExecTx (ctx , & writeTxOpts , func (db SQLQueries ) error {
389
+ return s .db .ExecTx (ctx , sqldb . WriteTxOpt () , func (db SQLQueries ) error {
422
390
id , err := upsertNode (ctx , db , node )
423
391
if err != nil {
424
392
return fmt .Errorf ("unable to upsert source node: %w" ,
@@ -456,11 +424,8 @@ func (s *SQLStore) NodeUpdatesInHorizon(startTime,
456
424
457
425
ctx := context .TODO ()
458
426
459
- var (
460
- readTx = NewReadTx ()
461
- nodes []models.LightningNode
462
- )
463
- err := s .db .ExecTx (ctx , readTx , func (db SQLQueries ) error {
427
+ var nodes []models.LightningNode
428
+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
464
429
dbNodes , err := db .GetNodesByLastUpdateRange (
465
430
ctx , sqlc.GetNodesByLastUpdateRangeParams {
466
431
StartTime : sqldb .SQLInt64 (startTime .Unix ()),
0 commit comments