Skip to content

Commit 8f98514

Browse files
authored
Merge pull request #780 from starius/sweepbatcher-dropbatch-writetx
sweepbatcher: use write tx in DropBatch
2 parents 174a6b8 + b311649 commit 8f98514

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

instantout/reservation/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *SQLStore) CreateReservation(ctx context.Context,
8181
UpdateState: string(reservation.State),
8282
}
8383

84-
return r.baseDb.ExecTx(ctx, &loopdb.SqliteTxOptions{},
84+
return r.baseDb.ExecTx(ctx, loopdb.NewSqlWriteOpts(),
8585
func(q *sqlc.Queries) error {
8686
err := q.CreateReservation(ctx, args)
8787
if err != nil {
@@ -121,7 +121,7 @@ func (r *SQLStore) UpdateReservation(ctx context.Context,
121121
),
122122
}
123123

124-
return r.baseDb.ExecTx(ctx, &loopdb.SqliteTxOptions{},
124+
return r.baseDb.ExecTx(ctx, loopdb.NewSqlWriteOpts(),
125125
func(q *sqlc.Queries) error {
126126
err := q.UpdateReservation(ctx, updateArgs)
127127
if err != nil {

instantout/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (s *SQLStore) CreateInstantLoopOut(ctx context.Context,
132132
UpdateState: string(instantOut.State),
133133
}
134134

135-
return s.baseDb.ExecTx(ctx, &loopdb.SqliteTxOptions{},
135+
return s.baseDb.ExecTx(ctx, loopdb.NewSqlWriteOpts(),
136136
func(q *sqlc.Queries) error {
137137
err := q.InsertSwap(ctx, swapArgs)
138138
if err != nil {
@@ -204,7 +204,7 @@ func (s *SQLStore) UpdateInstantLoopOut(ctx context.Context,
204204
UpdateState: string(instantOut.State),
205205
}
206206

207-
return s.baseDb.ExecTx(ctx, &loopdb.SqliteTxOptions{},
207+
return s.baseDb.ExecTx(ctx, loopdb.NewSqlWriteOpts(),
208208
func(q *sqlc.Queries) error {
209209
err := q.UpdateInstantOut(ctx, updateParams)
210210
if err != nil {

loopdb/sql_store.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (s *BaseDB) FetchLoopOutSwap(ctx context.Context,
9696
func (s *BaseDB) CreateLoopOut(ctx context.Context, hash lntypes.Hash,
9797
swap *LoopOutContract) error {
9898

99-
writeOpts := &SqliteTxOptions{}
99+
writeOpts := NewSqlWriteOpts()
100100
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
101101
insertArgs := loopToInsertArgs(
102102
hash, &swap.SwapContract,
@@ -134,7 +134,7 @@ func (s *BaseDB) CreateLoopOut(ctx context.Context, hash lntypes.Hash,
134134
func (s *BaseDB) BatchCreateLoopOut(ctx context.Context,
135135
swaps map[lntypes.Hash]*LoopOutContract) error {
136136

137-
writeOpts := &SqliteTxOptions{}
137+
writeOpts := NewSqlWriteOpts()
138138
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
139139
for swapHash, swap := range swaps {
140140
swap := swap
@@ -223,7 +223,7 @@ func (s *BaseDB) FetchLoopInSwaps(ctx context.Context) (
223223
func (s *BaseDB) CreateLoopIn(ctx context.Context, hash lntypes.Hash,
224224
swap *LoopInContract) error {
225225

226-
writeOpts := &SqliteTxOptions{}
226+
writeOpts := NewSqlWriteOpts()
227227
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
228228
insertArgs := loopToInsertArgs(
229229
hash, &swap.SwapContract,
@@ -260,7 +260,7 @@ func (s *BaseDB) CreateLoopIn(ctx context.Context, hash lntypes.Hash,
260260
func (s *BaseDB) BatchCreateLoopIn(ctx context.Context,
261261
swaps map[lntypes.Hash]*LoopInContract) error {
262262

263-
writeOpts := &SqliteTxOptions{}
263+
writeOpts := NewSqlWriteOpts()
264264
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
265265
for swapHash, swap := range swaps {
266266
swap := swap
@@ -351,7 +351,7 @@ var _ SwapStore = (*BaseDB)(nil)
351351
func (s *BaseDB) updateLoop(ctx context.Context, hash lntypes.Hash,
352352
time time.Time, state SwapStateData) error {
353353

354-
writeOpts := &SqliteTxOptions{}
354+
writeOpts := NewSqlWriteOpts()
355355
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
356356
updateParams := sqlc.InsertSwapUpdateParams{
357357
SwapHash: hash[:],
@@ -379,7 +379,7 @@ func (s *BaseDB) updateLoop(ctx context.Context, hash lntypes.Hash,
379379
func (s *BaseDB) BatchInsertUpdate(ctx context.Context,
380380
updateData map[lntypes.Hash][]BatchInsertUpdateData) error {
381381

382-
writeOpts := &SqliteTxOptions{}
382+
writeOpts := NewSqlWriteOpts()
383383
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
384384
for swapHash, updates := range updateData {
385385
for _, update := range updates {
@@ -412,7 +412,7 @@ func (s *BaseDB) BatchInsertUpdate(ctx context.Context,
412412
func (b *BaseDB) BatchUpdateLoopOutSwapCosts(ctx context.Context,
413413
costs map[lntypes.Hash]SwapCost) error {
414414

415-
writeOpts := &SqliteTxOptions{}
415+
writeOpts := NewSqlWriteOpts()
416416
return b.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
417417
for swapHash, cost := range costs {
418418
lastUpdateID, err := tx.GetLastUpdateID(

loopdb/sqlite.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,22 @@ type SqliteTxOptions struct {
323323
readOnly bool
324324
}
325325

326-
// NewSqlReadOpts returns a new KeyStoreTxOptions instance triggers a read
326+
// NewSqlReadOpts returns a new KeyStoreTxOptions instance that triggers a read
327327
// transaction.
328328
func NewSqlReadOpts() *SqliteTxOptions {
329329
return &SqliteTxOptions{
330330
readOnly: true,
331331
}
332332
}
333333

334+
// NewSqlWriteOpts returns a new KeyStoreTxOptions instance that triggers a
335+
// write (regular) transaction.
336+
func NewSqlWriteOpts() *SqliteTxOptions {
337+
return &SqliteTxOptions{
338+
readOnly: false,
339+
}
340+
}
341+
334342
// ReadOnly returns true if the transaction should be read only.
335343
//
336344
// NOTE: This implements the TxOptions interface.

sweepbatcher/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (s *SQLStore) InsertSweepBatch(ctx context.Context, batch *dbBatch) (int32,
111111
// DropBatch drops a batch from the database. Note that we only use this call
112112
// for batches that have no sweeps and so we'd not be able to resume.
113113
func (s *SQLStore) DropBatch(ctx context.Context, id int32) error {
114-
readOpts := loopdb.NewSqlReadOpts()
114+
readOpts := loopdb.NewSqlWriteOpts()
115115
return s.baseDb.ExecTx(ctx, readOpts, func(tx *sqlc.Queries) error {
116116
dbSweeps, err := tx.GetBatchSweeps(ctx, id)
117117
if err != nil {

0 commit comments

Comments
 (0)