Skip to content

Commit 419f71c

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 48dde6f commit 419f71c

File tree

6 files changed

+345
-123
lines changed

6 files changed

+345
-123
lines changed

loopd/swapclient_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
14511451
"outpoints")
14521452
}
14531453

1454-
allDeposits, err := s.depositManager.GetAllDeposits()
1454+
allDeposits, err := s.depositManager.GetAllDeposits(ctx)
14551455
if err != nil {
14561456
return nil, err
14571457
}
@@ -1589,7 +1589,7 @@ func toClientState(state fsm.StateType) looprpc.DepositState {
15891589
case deposit.Withdrawn:
15901590
return looprpc.DepositState_WITHDRAWN
15911591

1592-
case deposit.PublishExpiredDeposit:
1592+
case deposit.PublishExpirySweep:
15931593
return looprpc.DepositState_PUBLISH_EXPIRED
15941594

15951595
case deposit.WaitForExpirySweep:
@@ -1618,7 +1618,7 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
16181618
return deposit.Withdrawn
16191619

16201620
case looprpc.DepositState_PUBLISH_EXPIRED:
1621-
return deposit.PublishExpiredDeposit
1621+
return deposit.PublishExpirySweep
16221622

16231623
case looprpc.DepositState_WAIT_FOR_EXPIRY_SWEEP:
16241624
return deposit.WaitForExpirySweep

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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,14 @@ 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 {
7264
d.Lock()
7365
defer d.Unlock()
7466

75-
return d.state == Expired || d.state == Withdrawn || d.state == Failed
67+
return d.state == Expired || d.state == Withdrawn ||
68+
d.state == Failed || d.state == LoopedIn ||
69+
d.state == HtlcTimeoutSwept
7670
}
7771

7872
func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool {
@@ -96,13 +90,21 @@ func (d *Deposit) SetState(state fsm.StateType) {
9690
d.state = state
9791
}
9892

93+
func (d *Deposit) SetStateNoLock(state fsm.StateType) {
94+
d.state = state
95+
}
96+
9997
func (d *Deposit) IsInState(state fsm.StateType) bool {
10098
d.Lock()
10199
defer d.Unlock()
102100

103101
return d.state == state
104102
}
105103

104+
func (d *Deposit) IsInStateNoLock(state fsm.StateType) bool {
105+
return d.state == state
106+
}
107+
106108
// GetRandomDepositID generates a random deposit ID.
107109
func GetRandomDepositID() (ID, error) {
108110
var id ID

0 commit comments

Comments
 (0)