Skip to content

Commit 1ece7de

Browse files
committed
staticaddr: channel open states for deposit and fsm
1 parent 90ed471 commit 1ece7de

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

staticaddr/deposit/deposit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func (d *Deposit) IsInFinalState() bool {
6565
defer d.Unlock()
6666

6767
return d.state == Expired || d.state == Withdrawn ||
68-
d.state == LoopedIn || d.state == HtlcTimeoutSwept
68+
d.state == LoopedIn || d.state == HtlcTimeoutSwept ||
69+
d.state == ChannelPublished
6970
}
7071

7172
func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool {

staticaddr/deposit/fsm.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
fsm.OnError: {},
3636
OnWithdrawInitiated: {},
3737
OnWithdrawn: {},
38+
OnOpeningChannel: {},
39+
OnChannelPublished: {},
3840
}
3941
)
4042

@@ -51,6 +53,15 @@ var (
5153
// Withdrawn signals that the withdrawal transaction has been confirmed.
5254
Withdrawn = fsm.StateType("Withdrawn")
5355

56+
// OpeningChannel signals that the open channel transaction has been
57+
// broadcast.
58+
OpeningChannel = fsm.StateType("OpeningChannel")
59+
60+
// ChannelPublished signals that the open channel transaction has been
61+
// published and that the channel should be managed from lnd from now
62+
// on.
63+
ChannelPublished = fsm.StateType("ChannelPublished")
64+
5465
// LoopingIn signals that the deposit is locked for a loop in swap.
5566
LoopingIn = fsm.StateType("LoopingIn")
5667

@@ -93,6 +104,15 @@ var (
93104
// OnWithdrawn is sent to the fsm when a withdrawal has been confirmed.
94105
OnWithdrawn = fsm.EventType("OnWithdrawn")
95106

107+
// OnOpeningChannel is sent to the fsm when a channel open has been
108+
// initiated.
109+
OnOpeningChannel = fsm.EventType("OnOpeningChannel")
110+
111+
// OnChannelPublished is sent to the fsm when a channel open has been
112+
// published. Loop has done its work here and the channel should now be
113+
// managed from lnd.
114+
OnChannelPublished = fsm.EventType("OnChannelPublished")
115+
96116
// OnLoopInInitiated is sent to the fsm when a loop in has been
97117
// initiated.
98118
OnLoopInInitiated = fsm.EventType("OnLoopInInitiated")
@@ -253,6 +273,7 @@ func (f *FSM) DepositStatesV0() fsm.States {
253273
OnExpiry: PublishExpirySweep,
254274
OnWithdrawInitiated: Withdrawing,
255275
OnLoopInInitiated: LoopingIn,
276+
OnOpeningChannel: OpeningChannel,
256277
// We encounter OnSweepingHtlcTimeout if the
257278
// server published the htlc tx without paying
258279
// us. We then need to monitor for the timeout
@@ -366,6 +387,17 @@ func (f *FSM) DepositStatesV0() fsm.States {
366387
},
367388
Action: f.FinalizeDepositAction,
368389
},
390+
OpeningChannel: fsm.State{
391+
Transitions: fsm.Transitions{
392+
fsm.OnError: Deposited,
393+
OnChannelPublished: ChannelPublished,
394+
OnRecover: OpeningChannel,
395+
},
396+
Action: fsm.NoOpAction,
397+
},
398+
ChannelPublished: fsm.State{
399+
Action: fsm.NoOpAction,
400+
},
369401
}
370402
}
371403

0 commit comments

Comments
 (0)