Skip to content

Commit 216f74d

Browse files
committed
staticaddr: deposit changes to be squashed
These deposit changes will be squashed into the original commits once merged into staging.
1 parent 7262c2f commit 216f74d

File tree

5 files changed

+289
-104
lines changed

5 files changed

+289
-104
lines changed

staticaddr/deposit/actions.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
)
1414

1515
const (
16-
defaultConfTarget = 3
16+
DefaultConfTarget = 3
1717
)
1818

19-
// PublishDepositExpirySweepAction creates and publishes the timeout transaction
20-
// that spends the deposit from the static address timeout leaf to the
21-
// predefined timeout sweep pkscript.
22-
func (f *FSM) PublishDepositExpirySweepAction(_ fsm.EventContext) fsm.EventType {
19+
// PublishExpirySweepAction creates and publishes the timeout transaction that
20+
// spends the deposit from the static address timeout leaf to the predefined
21+
// timeout sweep pkscript.
22+
func (f *FSM) PublishExpirySweepAction(_ fsm.EventContext) fsm.EventType {
2323
msgTx := wire.NewMsgTx(2)
2424

2525
params, err := f.cfg.AddressManager.GetStaticAddressParameters(f.ctx)
@@ -36,11 +36,11 @@ func (f *FSM) PublishDepositExpirySweepAction(_ fsm.EventContext) fsm.EventType
3636

3737
// Estimate the fee rate of an expiry spend transaction.
3838
feeRateEstimator, err := f.cfg.WalletKit.EstimateFeeRate(
39-
f.ctx, defaultConfTarget,
39+
f.ctx, DefaultConfTarget,
4040
)
4141
if err != nil {
4242
return f.HandleError(fmt.Errorf("timeout sweep fee "+
43-
"estimation failed: %v", err))
43+
"estimation failed: %w", err))
4444
}
4545

4646
weight := script.ExpirySpendWeight()
@@ -111,15 +111,15 @@ func (f *FSM) PublishDepositExpirySweepAction(_ fsm.EventContext) fsm.EventType
111111
// before a timeout sweep is considered successful.
112112
func (f *FSM) WaitForExpirySweepAction(_ fsm.EventContext) fsm.EventType {
113113
spendChan, errSpendChan, err := f.cfg.ChainNotifier.RegisterConfirmationsNtfn( //nolint:lll
114-
f.ctx, nil, f.deposit.TimeOutSweepPkScript, defaultConfTarget,
114+
f.ctx, nil, f.deposit.TimeOutSweepPkScript, DefaultConfTarget,
115115
int32(f.deposit.ConfirmationHeight),
116116
)
117117
if err != nil {
118118
return f.HandleError(err)
119119
}
120120

121121
select {
122-
case err := <-errSpendChan:
122+
case err = <-errSpendChan:
123123
log.Debugf("error while sweeping expired deposit: %v", err)
124124
return fsm.OnError
125125

@@ -148,9 +148,9 @@ func (f *FSM) SweptExpiredDepositAction(_ fsm.EventContext) fsm.EventType {
148148
return fsm.NoOp
149149
}
150150

151-
// WithdrawnDepositAction is the final action after a withdrawal. It signals to
151+
// FinalizeDepositAction is the final action after a withdrawal. It signals to
152152
// the manager that the deposit has been swept and the FSM can be removed.
153-
func (f *FSM) WithdrawnDepositAction(_ fsm.EventContext) fsm.EventType {
153+
func (f *FSM) FinalizeDepositAction(_ fsm.EventContext) fsm.EventType {
154154
select {
155155
case <-f.ctx.Done():
156156
return fsm.OnError

staticaddr/deposit/deposit.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,47 +59,26 @@ type Deposit struct {
5959
sync.Mutex
6060
}
6161

62-
// IsInPendingState returns true if the deposit is pending.
63-
func (d *Deposit) IsInPendingState() bool {
64-
d.Lock()
65-
defer d.Unlock()
66-
67-
return !d.IsInFinalState()
68-
}
69-
7062
// IsInFinalState returns true if the deposit is final.
7163
func (d *Deposit) IsInFinalState() bool {
72-
d.Lock()
73-
defer d.Unlock()
74-
75-
return d.state == Expired || d.state == Withdrawn || d.state == Failed
64+
return d.state == Expired || d.state == Withdrawn ||
65+
d.state == Failed || d.state == LoopedIn ||
66+
d.state == HtlcTimeoutSwept
7667
}
7768

7869
func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool {
79-
d.Lock()
80-
defer d.Unlock()
81-
8270
return currentHeight >= uint32(d.ConfirmationHeight)+expiry
8371
}
8472

8573
func (d *Deposit) GetState() fsm.StateType {
86-
d.Lock()
87-
defer d.Unlock()
88-
8974
return d.state
9075
}
9176

9277
func (d *Deposit) SetState(state fsm.StateType) {
93-
d.Lock()
94-
defer d.Unlock()
95-
9678
d.state = state
9779
}
9880

9981
func (d *Deposit) IsInState(state fsm.StateType) bool {
100-
d.Lock()
101-
defer d.Unlock()
102-
10382
return d.state == state
10483
}
10584

0 commit comments

Comments
 (0)