mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
fsm: make diagram generation deterministic
This commit is contained in:
parent
39c97e60d2
commit
1d5b1c564a
3 changed files with 37 additions and 17 deletions
|
|
@ -2,11 +2,11 @@
|
|||
stateDiagram-v2
|
||||
[*] --> InitFSM: OnRequestStuff
|
||||
InitFSM
|
||||
InitFSM --> StuffSentOut: OnStuffSentOut
|
||||
InitFSM --> StuffFailed: OnError
|
||||
InitFSM --> StuffSentOut: OnStuffSentOut
|
||||
StuffFailed
|
||||
StuffSentOut
|
||||
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
||||
StuffSentOut --> StuffFailed: OnError
|
||||
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
||||
StuffSuccess
|
||||
```
|
||||
|
|
@ -86,8 +86,11 @@ func writeMermaidFile(filename string, states fsm.States) error {
|
|||
state = "[*]"
|
||||
}
|
||||
// write transitions
|
||||
for edge, target := range edges.Transitions {
|
||||
fmt.Fprintf(&b, "%s --> %s: %s\n", state, target, edge)
|
||||
for _, edge := range sortedTransitionKeys(edges.Transitions) {
|
||||
fmt.Fprintf(
|
||||
&b, "%s --> %s: %s\n", state,
|
||||
edges.Transitions[fsm.EventType(edge)], edge,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,3 +113,14 @@ func sortedKeys(m fsm.States) []string {
|
|||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
func sortedTransitionKeys(m fsm.Transitions) []string {
|
||||
keys := make([]string, len(m))
|
||||
i := 0
|
||||
for k := range m {
|
||||
keys[i] = string(k)
|
||||
i++
|
||||
}
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,35 +2,41 @@
|
|||
stateDiagram-v2
|
||||
[*] --> Init: OnStart
|
||||
BuildHtlc
|
||||
BuildHtlc --> InstantOutFailed: OnError
|
||||
BuildHtlc --> PushPreimage: OnHtlcSigReceived
|
||||
BuildHtlc --> InstantFailedOutFailed: OnError
|
||||
BuildHtlc --> InstantFailedOutFailed: OnRecover
|
||||
BuildHtlc --> InstantOutFailed: OnRecover
|
||||
FailedHtlcSweep
|
||||
FailedHtlcSweep --> PublishHtlcSweep: OnRecover
|
||||
FinishedHtlcPreimageSweep
|
||||
FinishedSweeplessSweep
|
||||
Init
|
||||
Init --> InstantOutFailed: OnError
|
||||
Init --> SendPaymentAndPollAccepted: OnInit
|
||||
Init --> InstantFailedOutFailed: OnError
|
||||
Init --> InstantFailedOutFailed: OnRecover
|
||||
InstantFailedOutFailed
|
||||
Init --> InstantOutFailed: OnRecover
|
||||
InstantOutFailed
|
||||
PublishHtlc
|
||||
PublishHtlc --> FailedHtlcSweep: OnError
|
||||
PublishHtlc --> PublishHtlcSweep: OnHtlcPublished
|
||||
PublishHtlc --> PublishHtlc: OnRecover
|
||||
PublishHtlc --> WaitForHtlcSweepConfirmed: OnHtlcBroadcasted
|
||||
PublishHtlcSweep
|
||||
PublishHtlcSweep --> FailedHtlcSweep: OnError
|
||||
PublishHtlcSweep --> WaitForHtlcSweepConfirmed: OnHtlcSweepPublished
|
||||
PublishHtlcSweep --> PublishHtlcSweep: OnRecover
|
||||
PushPreimage
|
||||
PushPreimage --> InstantOutFailed: OnError
|
||||
PushPreimage --> PublishHtlc: OnErrorPublishHtlc
|
||||
PushPreimage --> PushPreimage: OnRecover
|
||||
PushPreimage --> WaitForSweeplessSweepConfirmed: OnSweeplessSweepPublished
|
||||
PushPreimage --> InstantFailedOutFailed: OnError
|
||||
PushPreimage --> PublishHtlc: OnErrorPublishHtlc
|
||||
SendPaymentAndPollAccepted
|
||||
SendPaymentAndPollAccepted --> InstantOutFailed: OnError
|
||||
SendPaymentAndPollAccepted --> BuildHtlc: OnPaymentAccepted
|
||||
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnError
|
||||
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnRecover
|
||||
SendPaymentAndPollAccepted --> InstantOutFailed: OnRecover
|
||||
WaitForHtlcSweepConfirmed
|
||||
WaitForHtlcSweepConfirmed --> FailedHtlcSweep: OnError
|
||||
WaitForHtlcSweepConfirmed --> FinishedHtlcPreimageSweep: OnHtlcSwept
|
||||
WaitForHtlcSweepConfirmed --> WaitForHtlcSweepConfirmed: OnRecover
|
||||
WaitForHtlcSweepConfirmed --> FailedHtlcSweep: OnError
|
||||
WaitForSweeplessSweepConfirmed
|
||||
WaitForSweeplessSweepConfirmed --> FinishedSweeplessSweep: OnSweeplessSweepConfirmed
|
||||
WaitForSweeplessSweepConfirmed --> WaitForSweeplessSweepConfirmed: OnRecover
|
||||
WaitForSweeplessSweepConfirmed --> PublishHtlc: OnError
|
||||
WaitForSweeplessSweepConfirmed --> WaitForSweeplessSweepConfirmed: OnRecover
|
||||
WaitForSweeplessSweepConfirmed --> FinishedSweeplessSweep: OnSweeplessSweepConfirmed
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue