instantout: republish sweepless sweep

This commit changes the instant out fsm to
republish the sweep transaction if we restart
loop.
pull/745/head
sputn1ck 3 weeks ago
parent 3843c3906d
commit eb443ae5f4
No known key found for this signature in database
GPG Key ID: 671103D881A5F0E4

@ -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
}

@ -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,

Loading…
Cancel
Save