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
|
stateDiagram-v2
|
||||||
[*] --> InitFSM: OnRequestStuff
|
[*] --> InitFSM: OnRequestStuff
|
||||||
InitFSM
|
InitFSM
|
||||||
InitFSM --> StuffSentOut: OnStuffSentOut
|
|
||||||
InitFSM --> StuffFailed: OnError
|
InitFSM --> StuffFailed: OnError
|
||||||
|
InitFSM --> StuffSentOut: OnStuffSentOut
|
||||||
StuffFailed
|
StuffFailed
|
||||||
StuffSentOut
|
StuffSentOut
|
||||||
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
|
||||||
StuffSentOut --> StuffFailed: OnError
|
StuffSentOut --> StuffFailed: OnError
|
||||||
|
StuffSentOut --> StuffSuccess: OnStuffSuccess
|
||||||
StuffSuccess
|
StuffSuccess
|
||||||
```
|
```
|
||||||
|
|
@ -86,8 +86,11 @@ func writeMermaidFile(filename string, states fsm.States) error {
|
||||||
state = "[*]"
|
state = "[*]"
|
||||||
}
|
}
|
||||||
// write transitions
|
// write transitions
|
||||||
for edge, target := range edges.Transitions {
|
for _, edge := range sortedTransitionKeys(edges.Transitions) {
|
||||||
fmt.Fprintf(&b, "%s --> %s: %s\n", state, target, edge)
|
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)
|
sort.Strings(keys)
|
||||||
return 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
|
stateDiagram-v2
|
||||||
[*] --> Init: OnStart
|
[*] --> Init: OnStart
|
||||||
BuildHtlc
|
BuildHtlc
|
||||||
|
BuildHtlc --> InstantOutFailed: OnError
|
||||||
BuildHtlc --> PushPreimage: OnHtlcSigReceived
|
BuildHtlc --> PushPreimage: OnHtlcSigReceived
|
||||||
BuildHtlc --> InstantFailedOutFailed: OnError
|
BuildHtlc --> InstantOutFailed: OnRecover
|
||||||
BuildHtlc --> InstantFailedOutFailed: OnRecover
|
|
||||||
FailedHtlcSweep
|
FailedHtlcSweep
|
||||||
|
FailedHtlcSweep --> PublishHtlcSweep: OnRecover
|
||||||
|
FinishedHtlcPreimageSweep
|
||||||
FinishedSweeplessSweep
|
FinishedSweeplessSweep
|
||||||
Init
|
Init
|
||||||
|
Init --> InstantOutFailed: OnError
|
||||||
Init --> SendPaymentAndPollAccepted: OnInit
|
Init --> SendPaymentAndPollAccepted: OnInit
|
||||||
Init --> InstantFailedOutFailed: OnError
|
Init --> InstantOutFailed: OnRecover
|
||||||
Init --> InstantFailedOutFailed: OnRecover
|
InstantOutFailed
|
||||||
InstantFailedOutFailed
|
|
||||||
PublishHtlc
|
PublishHtlc
|
||||||
PublishHtlc --> FailedHtlcSweep: OnError
|
PublishHtlc --> FailedHtlcSweep: OnError
|
||||||
|
PublishHtlc --> PublishHtlcSweep: OnHtlcPublished
|
||||||
PublishHtlc --> PublishHtlc: OnRecover
|
PublishHtlc --> PublishHtlc: OnRecover
|
||||||
PublishHtlc --> WaitForHtlcSweepConfirmed: OnHtlcBroadcasted
|
PublishHtlcSweep
|
||||||
|
PublishHtlcSweep --> FailedHtlcSweep: OnError
|
||||||
|
PublishHtlcSweep --> WaitForHtlcSweepConfirmed: OnHtlcSweepPublished
|
||||||
|
PublishHtlcSweep --> PublishHtlcSweep: OnRecover
|
||||||
PushPreimage
|
PushPreimage
|
||||||
|
PushPreimage --> InstantOutFailed: OnError
|
||||||
|
PushPreimage --> PublishHtlc: OnErrorPublishHtlc
|
||||||
PushPreimage --> PushPreimage: OnRecover
|
PushPreimage --> PushPreimage: OnRecover
|
||||||
PushPreimage --> WaitForSweeplessSweepConfirmed: OnSweeplessSweepPublished
|
PushPreimage --> WaitForSweeplessSweepConfirmed: OnSweeplessSweepPublished
|
||||||
PushPreimage --> InstantFailedOutFailed: OnError
|
|
||||||
PushPreimage --> PublishHtlc: OnErrorPublishHtlc
|
|
||||||
SendPaymentAndPollAccepted
|
SendPaymentAndPollAccepted
|
||||||
|
SendPaymentAndPollAccepted --> InstantOutFailed: OnError
|
||||||
SendPaymentAndPollAccepted --> BuildHtlc: OnPaymentAccepted
|
SendPaymentAndPollAccepted --> BuildHtlc: OnPaymentAccepted
|
||||||
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnError
|
SendPaymentAndPollAccepted --> InstantOutFailed: OnRecover
|
||||||
SendPaymentAndPollAccepted --> InstantFailedOutFailed: OnRecover
|
|
||||||
WaitForHtlcSweepConfirmed
|
WaitForHtlcSweepConfirmed
|
||||||
|
WaitForHtlcSweepConfirmed --> FailedHtlcSweep: OnError
|
||||||
WaitForHtlcSweepConfirmed --> FinishedHtlcPreimageSweep: OnHtlcSwept
|
WaitForHtlcSweepConfirmed --> FinishedHtlcPreimageSweep: OnHtlcSwept
|
||||||
WaitForHtlcSweepConfirmed --> WaitForHtlcSweepConfirmed: OnRecover
|
WaitForHtlcSweepConfirmed --> WaitForHtlcSweepConfirmed: OnRecover
|
||||||
WaitForHtlcSweepConfirmed --> FailedHtlcSweep: OnError
|
|
||||||
WaitForSweeplessSweepConfirmed
|
WaitForSweeplessSweepConfirmed
|
||||||
WaitForSweeplessSweepConfirmed --> FinishedSweeplessSweep: OnSweeplessSweepConfirmed
|
|
||||||
WaitForSweeplessSweepConfirmed --> WaitForSweeplessSweepConfirmed: OnRecover
|
|
||||||
WaitForSweeplessSweepConfirmed --> PublishHtlc: OnError
|
WaitForSweeplessSweepConfirmed --> PublishHtlc: OnError
|
||||||
|
WaitForSweeplessSweepConfirmed --> WaitForSweeplessSweepConfirmed: OnRecover
|
||||||
|
WaitForSweeplessSweepConfirmed --> FinishedSweeplessSweep: OnSweeplessSweepConfirmed
|
||||||
```
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue