Skip to content

Commit

Permalink
sweepbatcher/Store: do not provide LoopOut field
Browse files Browse the repository at this point in the history
This data is not used by Batcher since commit
"sweepbatcher: load swap from loopdb, not own store".

Now sweepbatcher.Store depends only on tables sweeps and sweep_batches
and does not depend on swaps, loopout_swaps and htlc_keys, making it
easier to reuse.
  • Loading branch information
starius committed May 31, 2024
1 parent 4be69e1 commit 7a7ea05
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 152 deletions.
92 changes: 6 additions & 86 deletions loopdb/sqlc/batch.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion loopdb/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions loopdb/sqlc/queries/batch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,13 @@ AND

-- name: GetBatchSweeps :many
SELECT
sweeps.*,
swaps.*,
loopout_swaps.*,
htlc_keys.*
*
FROM
sweeps
JOIN
swaps ON sweeps.swap_hash = swaps.swap_hash
JOIN
loopout_swaps ON sweeps.swap_hash = loopout_swaps.swap_hash
JOIN
htlc_keys ON sweeps.swap_hash = htlc_keys.swap_hash
WHERE
sweeps.batch_id = $1
batch_id = $1
ORDER BY
sweeps.id ASC;
id ASC;

-- name: GetSweepStatus :one
SELECT
Expand Down
57 changes: 4 additions & 53 deletions sweepbatcher/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type BaseDB interface {

// GetBatchSweeps fetches all the sweeps that are part a batch.
GetBatchSweeps(ctx context.Context, batchID int32) (
[]sqlc.GetBatchSweepsRow, error)
[]sqlc.Sweep, error)

// GetBatchSweptAmount returns the total amount of sats swept by a
// (confirmed) batch.
Expand All @@ -34,10 +34,6 @@ type BaseDB interface {
GetParentBatch(ctx context.Context, swapHash []byte) (sqlc.SweepBatch,
error)

// GetSwapUpdates fetches all the updates for a swap.
GetSwapUpdates(ctx context.Context, swapHash []byte) (
[]sqlc.SwapUpdate, error)

// GetUnconfirmedBatches fetches all the batches from the
// database that are not in a confirmed state.
GetUnconfirmedBatches(ctx context.Context) ([]sqlc.SweepBatch, error)
Expand Down Expand Up @@ -154,14 +150,7 @@ func (s *SQLStore) FetchBatchSweeps(ctx context.Context, id int32) (
}

for _, dbSweep := range dbSweeps {
updates, err := s.baseDb.GetSwapUpdates(
ctx, dbSweep.SwapHash,
)
if err != nil {
return err
}

sweep, err := s.convertSweepRow(dbSweep, updates)
sweep, err := s.convertSweepRow(dbSweep)
if err != nil {
return err
}
Expand Down Expand Up @@ -260,9 +249,6 @@ type dbSweep struct {

// Completed indicates whether this sweep is completed.
Completed bool

// LoopOut is the loop out that the sweep belongs to.
LoopOut *loopdb.LoopOut
}

// convertBatchRow converts a batch row from db to a sweepbatcher.Batch struct.
Expand Down Expand Up @@ -354,9 +340,7 @@ func batchToUpdateArgs(batch dbBatch) sqlc.UpdateBatchParams {
}

// convertSweepRow converts a sweep row from db to a sweep struct.
func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
updates []sqlc.SwapUpdate) (dbSweep, error) {

func (s *SQLStore) convertSweepRow(row sqlc.Sweep) (dbSweep, error) {
sweep := dbSweep{
ID: row.ID,
BatchID: row.BatchID,
Expand All @@ -380,40 +364,7 @@ func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
Index: uint32(row.OutpointIndex),
}

sweep.LoopOut, err = loopdb.ConvertLoopOutRow(
s.network,
sqlc.GetLoopOutSwapRow{
ID: row.ID,
SwapHash: row.SwapHash,
Preimage: row.Preimage,
InitiationTime: row.InitiationTime,
AmountRequested: row.AmountRequested,
CltvExpiry: row.CltvExpiry,
MaxMinerFee: row.MaxMinerFee,
MaxSwapFee: row.MaxSwapFee,
InitiationHeight: row.InitiationHeight,
ProtocolVersion: row.ProtocolVersion,
Label: row.Label,
DestAddress: row.DestAddress,
SwapInvoice: row.SwapInvoice,
MaxSwapRoutingFee: row.MaxSwapRoutingFee,
SweepConfTarget: row.SweepConfTarget,
HtlcConfirmations: row.HtlcConfirmations,
OutgoingChanSet: row.OutgoingChanSet,
PrepayInvoice: row.PrepayInvoice,
MaxPrepayRoutingFee: row.MaxPrepayRoutingFee,
PublicationDeadline: row.PublicationDeadline,
SingleSweep: row.SingleSweep,
SenderScriptPubkey: row.SenderScriptPubkey,
ReceiverScriptPubkey: row.ReceiverScriptPubkey,
SenderInternalPubkey: row.SenderInternalPubkey,
ReceiverInternalPubkey: row.ReceiverInternalPubkey,
ClientKeyFamily: row.ClientKeyFamily,
ClientKeyIndex: row.ClientKeyIndex,
}, updates,
)

return sweep, err
return sweep, nil
}

// sweepToUpsertArgs converts a Sweep struct to the arguments needed to insert.
Expand Down

0 comments on commit 7a7ea05

Please sign in to comment.