Skip to content

Commit

Permalink
fsm: add reservation fsm compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
sputn1ck committed Jan 17, 2024
1 parent d1e1499 commit 6fdaaa4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func (s *StateMachine) SendEvent(event EventType, eventCtx EventContext) error {
// current state.
state, err := s.getNextState(event)
if err != nil {
log.Errorf("unable to get next state: %v from event: "+
"%v, current state: %v", err, event, s.current)
return ErrEventRejected
}

Expand Down
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/reservation"
)

func main() {
Expand Down Expand Up @@ -41,6 +42,13 @@ func run() error {
return err
}

case "reservation":
reservationFSM := &reservation.FSM{}
err = writeMermaidFile(fp, reservationFSM.GetReservationStates())
if err != nil {
return err
}

default:
fmt.Println("Missing or wrong argument: fsm must be one of:")
fmt.Println("\treservations")
Expand Down
17 changes: 17 additions & 0 deletions instantout/reservation/reservation_fsm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```mermaid
stateDiagram-v2
[*] --> Init: OnServerRequest
Confirmed
Confirmed --> TimedOut: OnTimedOut
Confirmed --> Confirmed: OnRecover
Failed
Init
Init --> Failed: OnError
Init --> WaitForConfirmation: OnBroadcast
Init --> Failed: OnRecover
TimedOut
WaitForConfirmation
WaitForConfirmation --> WaitForConfirmation: OnRecover
WaitForConfirmation --> Confirmed: OnConfirmed
WaitForConfirmation --> TimedOut: OnTimedOut
```
3 changes: 2 additions & 1 deletion scripts/fsm-generate.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
go run ./fsm/stateparser/stateparser.go --out ./fsm/example_fsm.md --fsm example
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

0 comments on commit 6fdaaa4

Please sign in to comment.