@@ -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,16 +171,13 @@ 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
203
179
return err
204
- }, func () {} )
180
+ }, sqldb . NoOpReset )
205
181
if err != nil {
206
182
return nil , fmt .Errorf ("unable to fetch node: %w" , err )
207
183
}
@@ -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 ),
@@ -246,7 +221,7 @@ func (s *SQLStore) HasLightningNode(pubKey [33]byte) (time.Time, bool,
246
221
}
247
222
248
223
return nil
249
- }, func () {} )
224
+ }, sqldb . NoOpReset )
250
225
if err != nil {
251
226
return time.Time {}, false ,
252
227
fmt .Errorf ("unable to fetch node: %w" , err )
@@ -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 (),
@@ -281,7 +255,7 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
281
255
}
282
256
283
257
return nil
284
- }, func () {} )
258
+ }, sqldb . NoOpReset )
285
259
if err != nil {
286
260
return false , nil , fmt .Errorf ("unable to get addresses for " +
287
261
"node(%x): %w" , nodePub .SerializeCompressed (), err )
@@ -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 ),
@@ -321,7 +294,7 @@ func (s *SQLStore) DeleteLightningNode(pubKey route.Vertex) error {
321
294
}
322
295
323
296
return err
324
- }, func () {} )
297
+ }, sqldb . NoOpReset )
325
298
if err != nil {
326
299
return fmt .Errorf ("unable to delete node: %w" , err )
327
300
}
@@ -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 ),
@@ -370,7 +342,7 @@ func (s *SQLStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
370
342
alias = dbNode .Alias .String
371
343
372
344
return nil
373
- }, func () {} )
345
+ }, sqldb . NoOpReset )
374
346
if err != nil {
375
347
return "" , fmt .Errorf ("unable to look up alias: %w" , err )
376
348
}
@@ -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" ,
@@ -401,7 +370,7 @@ func (s *SQLStore) SourceNode() (*models.LightningNode, error) {
401
370
_ , node , err = getNodeByPubKey (ctx , db , nodePub )
402
371
403
372
return err
404
- }, func () {} )
373
+ }, sqldb . NoOpReset )
405
374
if err != nil {
406
375
return nil , fmt .Errorf ("unable to fetch source node: %w" , err )
407
376
}
@@ -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" ,
@@ -442,7 +410,7 @@ func (s *SQLStore) SetSourceNode(node *models.LightningNode) error {
442
410
}
443
411
444
412
return db .AddSourceNode (ctx , id )
445
- }, func () {} )
413
+ }, sqldb . NoOpReset )
446
414
}
447
415
448
416
// NodeUpdatesInHorizon returns all the known lightning node which have an
@@ -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 ()),
@@ -482,7 +447,7 @@ func (s *SQLStore) NodeUpdatesInHorizon(startTime,
482
447
}
483
448
484
449
return nil
485
- }, func () {} )
450
+ }, sqldb . NoOpReset )
486
451
if err != nil {
487
452
return nil , fmt .Errorf ("unable to fetch nodes: %w" , err )
488
453
}
0 commit comments