Skip to content

Commit 8fb5e6e

Browse files
committed
staticaddr: expire spent expiry sweeps
1 parent e10730e commit 8fb5e6e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

staticaddr/deposit/actions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (f *FSM) PublishDepositExpirySweepAction(ctx context.Context,
101101
log.Errorf("%v: %v", txLabel, err)
102102
f.LastActionError = err
103103
return fsm.OnError
104+
} else {
105+
// If the output has already been spent the deposit is
106+
// expired.
107+
return OnExpiry
104108
}
105109
} else {
106110
f.Debugf("published timeout sweep with txid: %v",

staticaddr/deposit/fsm.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,23 @@ func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig,
222222
func (f *FSM) handleBlockNotification(ctx context.Context,
223223
currentHeight uint32) {
224224

225+
expire := func() {
226+
err := f.SendEvent(ctx, OnExpiry, nil)
227+
if err != nil {
228+
log.Debugf("error sending OnExpiry event: %v", err)
229+
}
230+
}
231+
225232
// If the deposit is expired but not yet sufficiently confirmed, we
226233
// republish the expiry sweep transaction.
227234
if f.deposit.IsExpired(currentHeight, f.params.Expiry) {
228235
if f.deposit.IsInState(WaitForExpirySweep) {
229-
f.PublishDepositExpirySweepAction(ctx, nil)
236+
event := f.PublishDepositExpirySweepAction(ctx, nil)
237+
if event != OnExpiryPublished {
238+
go expire()
239+
}
230240
} else {
231-
go func() {
232-
err := f.SendEvent(ctx, OnExpiry, nil)
233-
if err != nil {
234-
log.Debugf("error sending OnExpiry "+
235-
"event: %v", err)
236-
}
237-
}()
241+
go expire()
238242
}
239243
}
240244
}
@@ -267,6 +271,7 @@ func (f *FSM) DepositStatesV0() fsm.States {
267271
Transitions: fsm.Transitions{
268272
OnRecover: PublishExpirySweep,
269273
OnExpiryPublished: WaitForExpirySweep,
274+
OnExpiry: Expired,
270275
// If the timeout sweep failed we go back to
271276
// Deposited, hoping that another timeout sweep
272277
// attempt will be successful. Alternatively,

0 commit comments

Comments
 (0)