Skip to content

Commit 4749c02

Browse files
committed
loopdb: add migraton and DB code to handle payment timeout
1 parent 461ceee commit 4749c02

File tree

9 files changed

+36
-8
lines changed

9 files changed

+36
-8
lines changed

loopdb/loopout.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type LoopOutContract struct {
6161
// allow the server to delay the publication in exchange for possibly
6262
// lower fees.
6363
SwapPublicationDeadline time.Time
64+
65+
// PaymentTimeout is the timeout for any individual off-chain payment
66+
// attempt.
67+
PaymentTimeout time.Duration
6468
}
6569

6670
// ChannelSet stores a set of channels.

loopdb/sql_store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ func loopOutToInsertArgs(hash lntypes.Hash,
443443
PrepayInvoice: loopOut.PrepayInvoice,
444444
MaxPrepayRoutingFee: int64(loopOut.MaxPrepayRoutingFee),
445445
PublicationDeadline: loopOut.SwapPublicationDeadline.UTC(),
446+
PaymentTimeout: int32(loopOut.PaymentTimeout.Seconds()),
446447
}
447448
}
448449

@@ -536,6 +537,9 @@ func ConvertLoopOutRow(network *chaincfg.Params, row sqlc.GetLoopOutSwapRow,
536537
PrepayInvoice: row.PrepayInvoice,
537538
MaxPrepayRoutingFee: btcutil.Amount(row.MaxPrepayRoutingFee),
538539
SwapPublicationDeadline: row.PublicationDeadline,
540+
PaymentTimeout: time.Duration(
541+
row.PaymentTimeout,
542+
) * time.Second,
539543
},
540544
Loop: Loop{
541545
Hash: swapHash,

loopdb/sql_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestSqliteLoopOutStore(t *testing.T) {
6060
SweepConfTarget: 2,
6161
HtlcConfirmations: 2,
6262
SwapPublicationDeadline: initiationTime,
63+
PaymentTimeout: time.Second * 11,
6364
}
6465

6566
t.Run("no outgoing set", func(t *testing.T) {
@@ -120,6 +121,8 @@ func testSqliteLoopOutStore(t *testing.T, pendingSwap *LoopOutContract) {
120121
if expectedState == StatePreimageRevealed {
121122
require.NotNil(t, swap.State().HtlcTxHash)
122123
}
124+
125+
require.Equal(t, time.Second*11, swap.Contract.PaymentTimeout)
123126
}
124127

125128
// If we create a new swap, then it should show up as being initialized

loopdb/sqlc/batch.sql.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- payment_timeout is the timeout in seconds for each individual off-chain
2+
-- payment.
3+
ALTER TABLE loopout_swaps DROP COLUMN payment_timeout;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- payment_timeout is the timeout in seconds for each individual off-chain
2+
-- payment.
3+
ALTER TABLE loopout_swaps ADD payment_timeout INTEGER NOT NULL DEFAULT 0;

loopdb/sqlc/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/queries/swaps.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ INSERT INTO loopout_swaps (
105105
prepay_invoice,
106106
max_prepay_routing_fee,
107107
publication_deadline,
108-
single_sweep
108+
single_sweep,
109+
payment_timeout
109110
) VALUES (
110-
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
111+
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
111112
);
112113

113114
-- name: InsertLoopIn :exec
@@ -131,4 +132,4 @@ INSERT INTO htlc_keys(
131132
client_key_index
132133
) VALUES (
133134
$1, $2, $3, $4, $5, $6, $7
134-
);
135+
);

loopdb/sqlc/swaps.sql.go

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)