Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instantout: republish sweepless sweep #745

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions instantout/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ fsm.EventContext fixes lll

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
}

Expand Down
28 changes: 20 additions & 8 deletions instantout/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix event name


// OnSweeplessSweepPublished is the event that is triggered when the
// sweepless sweep is published.
Expand Down Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is cleaner if we extract the sweepless sweep tx creation from PushPreiamgeAction to PublishSweeplessSweepAction and then rename the transition OnSweeplessSweepBuilt to OnPreimagePushed.
WDYT?

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,
Expand Down
Loading