diff --git a/instantout/actions.go b/instantout/actions.go index 71a411fdc..888912b43 100644 --- a/instantout/actions.go +++ b/instantout/actions.go @@ -425,21 +425,31 @@ func (f *FSM) PushPreimageAction(eventCtx fsm.EventContext) fsm.EventType { return OnErrorPublishHtlc } + f.InstantOut.FinalizedSweeplessSweepTx = sweepTx + txHash := f.InstantOut.FinalizedSweeplessSweepTx.TxHash() + + f.InstantOut.SweepTxHash = &txHash + + return OnSweeplessSweepBuilt +} + +// PublishSweeplessSweepAction publishes the sweepless sweep transaction. +func (f *FSM) PublishSweeplessSweepAction(eventCtx fsm.EventContext) fsm.EventType { + if f.InstantOut.FinalizedSweeplessSweepTx == nil { + return f.HandleError(errors.New("sweep tx not finalized")) + } + txLabel := fmt.Sprintf("sweepless-sweep-%v", f.InstantOut.swapPreimage.Hash()) + sweepTx := f.InstantOut.FinalizedSweeplessSweepTx + // Publish the sweepless sweep transaction. - err = f.cfg.Wallet.PublishTransaction(f.ctx, sweepTx, txLabel) + err := f.cfg.Wallet.PublishTransaction(f.ctx, sweepTx, txLabel) if err != nil { - f.LastActionError = err - return OnErrorPublishHtlc + return f.HandleError(err) } - f.InstantOut.FinalizedSweeplessSweepTx = sweepTx - txHash := f.InstantOut.FinalizedSweeplessSweepTx.TxHash() - - f.InstantOut.SweepTxHash = &txHash - return OnSweeplessSweepPublished } diff --git a/instantout/fsm.go b/instantout/fsm.go index 21559df76..a3d7cc1c5 100644 --- a/instantout/fsm.go +++ b/instantout/fsm.go @@ -58,6 +58,10 @@ var ( // PushPreimage is the state where the preimage is pushed to the server. PushPreimage = fsm.StateType("PushPreimage") + // PublishSweeplessSweep is the state where the sweepless sweep is + // published. + PublishSweeplessSweep = fsm.StateType("PublishSweeplessSweep") + // WaitForSweeplessSweepConfirmed is the state where we wait for the // sweepless sweep to be confirmed. WaitForSweeplessSweepConfirmed = fsm.StateType( @@ -105,9 +109,9 @@ var ( // is received. OnHtlcSigReceived = fsm.EventType("OnHtlcSigReceived") - // OnPreimagePushed is the event that is triggered when the preimage - // is pushed to the server. - OnPreimagePushed = fsm.EventType("OnPreimagePushed") + // OnSweeplessSweepBuilt is the event that is triggered when the preimage + // is pushed to the server and the sweepless sweep tx has been built. + OnSweeplessSweepBuilt = fsm.EventType("OnPreimagePushed") // OnSweeplessSweepPublished is the event that is triggered when the // sweepless sweep is published. @@ -267,17 +271,25 @@ func (f *FSM) GetV1ReservationStates() fsm.States { }, PushPreimage: fsm.State{ Transitions: fsm.Transitions{ - OnSweeplessSweepPublished: WaitForSweeplessSweepConfirmed, - fsm.OnError: Failed, - OnErrorPublishHtlc: PublishHtlc, - OnRecover: PushPreimage, + OnSweeplessSweepBuilt: PublishSweeplessSweep, + fsm.OnError: Failed, + OnErrorPublishHtlc: PublishHtlc, + OnRecover: PushPreimage, }, Action: f.PushPreimageAction, }, + PublishSweeplessSweep: fsm.State{ + Transitions: fsm.Transitions{ + OnSweeplessSweepPublished: WaitForSweeplessSweepConfirmed, + fsm.OnError: PublishHtlc, + OnRecover: PublishSweeplessSweep, + }, + Action: f.PublishSweeplessSweepAction, + }, WaitForSweeplessSweepConfirmed: fsm.State{ Transitions: fsm.Transitions{ OnSweeplessSweepConfirmed: FinishedSweeplessSweep, - OnRecover: WaitForSweeplessSweepConfirmed, + OnRecover: PublishSweeplessSweep, fsm.OnError: PublishHtlc, }, Action: f.WaitForSweeplessSweepConfirmedAction,