From d12663ea7c5f3fe2d37fa2d5c6ee1fd24545704e Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Wed, 21 May 2025 14:16:27 +0200 Subject: [PATCH] staticaddr: channel open states for deposit and fsm --- staticaddr/deposit/deposit.go | 3 ++- staticaddr/deposit/fsm.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/staticaddr/deposit/deposit.go b/staticaddr/deposit/deposit.go index 56dc318d..4cb64bc9 100644 --- a/staticaddr/deposit/deposit.go +++ b/staticaddr/deposit/deposit.go @@ -70,7 +70,8 @@ func (d *Deposit) IsInFinalState() bool { defer d.Unlock() return d.state == Expired || d.state == Withdrawn || - d.state == LoopedIn || d.state == HtlcTimeoutSwept + d.state == LoopedIn || d.state == HtlcTimeoutSwept || + d.state == ChannelPublished } func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool { diff --git a/staticaddr/deposit/fsm.go b/staticaddr/deposit/fsm.go index 0a78b86c..029f7f63 100644 --- a/staticaddr/deposit/fsm.go +++ b/staticaddr/deposit/fsm.go @@ -35,6 +35,8 @@ var ( fsm.OnError: {}, OnWithdrawInitiated: {}, OnWithdrawn: {}, + OnOpeningChannel: {}, + OnChannelPublished: {}, } ) @@ -51,6 +53,15 @@ var ( // Withdrawn signals that the withdrawal transaction has been confirmed. Withdrawn = fsm.StateType("Withdrawn") + // OpeningChannel signals that the open channel transaction has been + // broadcast. + OpeningChannel = fsm.StateType("OpeningChannel") + + // ChannelPublished signals that the open channel transaction has been + // published and that the channel should be managed from lnd from now + // on. + ChannelPublished = fsm.StateType("ChannelPublished") + // LoopingIn signals that the deposit is locked for a loop in swap. LoopingIn = fsm.StateType("LoopingIn") @@ -93,6 +104,15 @@ var ( // OnWithdrawn is sent to the fsm when a withdrawal has been confirmed. OnWithdrawn = fsm.EventType("OnWithdrawn") + // OnOpeningChannel is sent to the fsm when a channel open has been + // initiated. + OnOpeningChannel = fsm.EventType("OnOpeningChannel") + + // OnChannelPublished is sent to the fsm when a channel open has been + // published. Loop has done its work here and the channel should now be + // managed from lnd. + OnChannelPublished = fsm.EventType("OnChannelPublished") + // OnLoopInInitiated is sent to the fsm when a loop in has been // initiated. OnLoopInInitiated = fsm.EventType("OnLoopInInitiated") @@ -253,6 +273,7 @@ func (f *FSM) DepositStatesV0() fsm.States { OnExpiry: PublishExpirySweep, OnWithdrawInitiated: Withdrawing, OnLoopInInitiated: LoopingIn, + OnOpeningChannel: OpeningChannel, // We encounter OnSweepingHtlcTimeout if the // server published the htlc tx without paying // us. We then need to monitor for the timeout @@ -366,6 +387,17 @@ func (f *FSM) DepositStatesV0() fsm.States { }, Action: f.FinalizeDepositAction, }, + OpeningChannel: fsm.State{ + Transitions: fsm.Transitions{ + fsm.OnError: Deposited, + OnChannelPublished: ChannelPublished, + OnRecover: OpeningChannel, + }, + Action: fsm.NoOpAction, + }, + ChannelPublished: fsm.State{ + Action: f.FinalizeDepositAction, + }, } }