Skip to content

Commit

Permalink
fsm: add instanout fsm parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sputn1ck committed Nov 22, 2023
1 parent 17ee610 commit a400601
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
8 changes: 8 additions & 0 deletions fsm/stateparser/stateparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"

"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/instantout"
"github.com/lightninglabs/loop/reservation"
)

Expand Down Expand Up @@ -49,6 +50,13 @@ func run() error {
return err
}

case "instantout":
instantout := &instantout.FSM{}
err = writeMermaidFile(fp, instantout.GetV1ReservationStates())
if err != nil {
return err
}

default:
fmt.Println("Missing or wrong argument: fsm must be one of:")
fmt.Println("\treservations")
Expand Down
36 changes: 36 additions & 0 deletions instantout/fsm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
```mermaid
stateDiagram-v2
[*] --> Init: OnStart
BuildHtlc
BuildHtlc --> PushPreimage: OnHtlcSigReceived
BuildHtlc --> InstantFailedOutFailed: OnError
BuildHtlc --> InstantFailedOutFailed: OnRecover
FailedHtlcSweep
FinishedCoop
Init
Init --> InstantFailedOutFailed: OnRecover
Init --> SendPaymentAndPollAccepted: OnInit
Init --> InstantFailedOutFailed: OnError
InstantFailedOutFailed
PublishHtlc
PublishHtlc --> WaitForHtlcSweepConfirmed: OnHtlcBroadcasted
PublishHtlc --> FailedHtlcSweep: OnError
PublishHtlc --> PublishHtlc: OnRecover
PushPreimage
PushPreimage --> WaitForSweeplessSweepConfirmed: OnSweeplessSweepBroadcasted
PushPreimage --> InstantFailedOutFailed: OnError
PushPreimage --> PublishHtlc: OnErrorPublishHtlc
PushPreimage --> PushPreimage: OnRecover
SendPaymentAndPollAccepted
SendPaymentAndPollAccepted --> BuildHtlc: OnPaymentAccepted
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnError
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnRecover
WaitForHtlcSweepConfirmed
WaitForHtlcSweepConfirmed --> FinishedHtlcPreimageSweep: OnHtlcSwept
WaitForHtlcSweepConfirmed --> WaitForHtlcSweepConfirmed: OnRecover
WaitForHtlcSweepConfirmed --> FailedHtlcSweep: OnError
WaitForSweeplessSweepConfirmed
WaitForSweeplessSweepConfirmed --> FinishedCoop: OnSweeplessSweepConfirmed
WaitForSweeplessSweepConfirmed --> WaitForSweeplessSweepConfirmed: OnRecover
WaitForSweeplessSweepConfirmed --> PublishHtlc: OnError
```
2 changes: 1 addition & 1 deletion reservation/reservation_fsm.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Confirmed --> TimedOut: OnTimedOut
Confirmed --> Confirmed: OnRecover
Failed
Init
Init --> Failed: OnError
Init --> WaitForConfirmation: OnBroadcast
Init --> Failed: OnRecover
Init --> Failed: OnError
SpendBroadcasted
SpendBroadcasted --> SpendConfirmed: OnSpendConfirmed
SpendConfirmed
Expand Down
3 changes: 2 additions & 1 deletion scripts/fsm-generate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
go run ./fsm/stateparser/stateparser.go --out ./fsm/example_fsm.md --fsm example
go run ./fsm/stateparser/stateparser.go --out ./reservation/reservation_fsm.md --fsm reservation
go run ./fsm/stateparser/stateparser.go --out ./reservation/reservation_fsm.md --fsm reservation
go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout

0 comments on commit a400601

Please sign in to comment.