Skip to content

Commit 3fed19f

Browse files
committed
deposit: guard unconfirmed deposits against expiry
Unconfirmed deposits (ConfirmationHeight <= 0) cannot have started their CSV timer, so IsExpired now returns false for them. Update the Deposited state and OnStart event documentation to reflect that deposits are detected from the mempool rather than after reaching a confirmation threshold.
1 parent 52d50fe commit 3fed19f

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

staticaddr/deposit/deposit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool {
8282
d.Lock()
8383
defer d.Unlock()
8484

85+
if d.ConfirmationHeight <= 0 {
86+
return false
87+
}
88+
8589
return currentHeight >= uint32(d.ConfirmationHeight)+expiry
8690
}
8791

staticaddr/deposit/deposit_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package deposit
2+
3+
import "testing"
4+
5+
// TestIsExpiredUnconfirmed checks that unconfirmed deposits don't start their
6+
// expiry timer.
7+
func TestIsExpiredUnconfirmed(t *testing.T) {
8+
deposit := &Deposit{
9+
ConfirmationHeight: 0,
10+
}
11+
12+
if deposit.IsExpired(500, 100) {
13+
t.Fatal("unconfirmed deposit should not be expired")
14+
}
15+
}

staticaddr/deposit/fsm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ var (
4242

4343
// States.
4444
var (
45-
// Deposited signals that funds at a static address have reached the
46-
// confirmation height.
45+
// Deposited signals that funds at a static address have been detected
46+
// and are available to the client.
4747
Deposited = fsm.StateType("Deposited")
4848

4949
// Replaced signals that an unconfirmed deposit disappeared from the
@@ -105,8 +105,8 @@ var (
105105
// Events.
106106
var (
107107
// OnStart is sent to the fsm once the deposit outpoint has been
108-
// sufficiently confirmed. It transitions the fsm into the Deposited
109-
// state from where we can trigger a withdrawal, a loopin or an expiry.
108+
// detected. It transitions the fsm into the Deposited state from where
109+
// we can trigger a withdrawal, a loopin or an expiry.
110110
OnStart = fsm.EventType("OnStart")
111111

112112
// OnWithdrawInitiated is sent to the fsm when a withdrawal has been

0 commit comments

Comments
 (0)