Skip to content

Commit 77cfd21

Browse files
committed
loopd: return full CSV value for unconfirmed deposit expiry
Unconfirmed deposits still have the full CSV window ahead of them, so depositBlocksUntilExpiry should return the full expiry value rather than 0, which would misleadingly suggest the deposit is about to expire.
1 parent 44d976e commit 77cfd21

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

loopd/swapclient_server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,12 +2162,13 @@ func (s *swapClientServer) populateBlocksUntilExpiry(ctx context.Context,
21622162
}
21632163

21642164
// depositBlocksUntilExpiry returns the remaining blocks until a deposit
2165-
// expires. Unconfirmed deposits return 0 because the CSV has not started yet.
2165+
// expires. Unconfirmed deposits return the full CSV value because the timeout
2166+
// has not started yet.
21662167
func depositBlocksUntilExpiry(confirmationHeight int64, expiry uint32,
21672168
bestBlockHeight int64) int64 {
21682169

21692170
if confirmationHeight <= 0 {
2170-
return 0
2171+
return int64(expiry)
21712172
}
21722173

21732174
return confirmationHeight + int64(expiry) - bestBlockHeight

loopd/swapclient_server_deposit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import "testing"
66
// confirmed and unconfirmed deposits.
77
func TestDepositBlocksUntilExpiry(t *testing.T) {
88
t.Run("unconfirmed", func(t *testing.T) {
9-
if blocks := depositBlocksUntilExpiry(0, 144, 500); blocks != 0 {
10-
t.Fatalf("expected 0 blocks for unconfirmed deposit, got %d",
9+
if blocks := depositBlocksUntilExpiry(0, 144, 500); blocks != 144 {
10+
t.Fatalf("expected 144 blocks for unconfirmed deposit, got %d",
1111
blocks)
1212
}
1313
})

0 commit comments

Comments
 (0)