Skip to content

fsm: generate and verify static address diagrams#1179

Open
GustavoStingelin wants to merge 5 commits into
lightninglabs:masterfrom
GustavoStingelin:feat/static-address-fsm-diagrams
Open

fsm: generate and verify static address diagrams#1179
GustavoStingelin wants to merge 5 commits into
lightninglabs:masterfrom
GustavoStingelin:feat/static-address-fsm-diagrams

Conversation

@GustavoStingelin

Copy link
Copy Markdown

Summary

  • make FSM diagram generation deterministic by sorting states and transitions
  • generate diagrams for the static address deposit and loop-in state machines
  • rename the reservation diagram to use fsm.md consistently
  • add make fsm-check and run it in CI to detect stale generated diagrams

Test

  • make fsm-check

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the reliability and coverage of the project's state machine documentation. By enforcing deterministic sorting during diagram generation and adding a verification step to the CI pipeline, the changes ensure that documentation remains synchronized with the implementation. Furthermore, the scope of the generated diagrams has been expanded to include critical static address components, improving overall project transparency.

Highlights

  • Deterministic Generation: Implemented sorting for states and transitions in the FSM parser to ensure consistent and reproducible diagram generation.
  • Expanded Documentation: Added support for generating FSM diagrams for static address deposit and loop-in state machines.
  • CI Verification: Introduced a new make fsm-check target to detect and prevent stale generated diagrams in the repository.
  • Consistency Improvements: Renamed the reservation FSM diagram file to fsm.md to maintain a consistent naming convention across the project.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/main.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces automated checks and generation for FSM (Finite State Machine) Mermaid diagrams, including new diagrams for static address deposits and loop-ins. It refactors the state parser to sort transition keys deterministically and support the new FSM selectors. Feedback on the changes includes defining a reusable variable in the Makefile to avoid duplicating the list of FSM files, renaming a local variable in the state parser to prevent shadowing an imported package, and building the parser binary once in the generation script instead of executing go run multiple times to improve performance.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread Makefile
Comment on lines +198 to +220
fsm-check: fsm
@$(call print, "Verifying generated state machine docs")
if test -n "$$(git status --porcelain -- \
fsm/example_fsm.md \
instantout/fsm.md \
instantout/reservation/fsm.md \
staticaddr/deposit/fsm.md \
staticaddr/loopin/fsm.md)"; then \
echo "Generated FSM diagrams are not up-to-date!"; \
git status --porcelain -- \
fsm/example_fsm.md \
instantout/fsm.md \
instantout/reservation/fsm.md \
staticaddr/deposit/fsm.md \
staticaddr/loopin/fsm.md; \
git diff -- \
fsm/example_fsm.md \
instantout/fsm.md \
instantout/reservation/fsm.md \
staticaddr/deposit/fsm.md \
staticaddr/loopin/fsm.md; \
exit 1; \
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The list of FSM files is duplicated three times in the fsm-check target. Defining a variable FSM_FILES to hold this list improves maintainability and readability, making it easier to add or remove FSM files in the future.

FSM_FILES := \
	fsm/example_fsm.md \
	instantout/fsm.md \
	instantout/reservation/fsm.md \
	staticaddr/deposit/fsm.md \
	staticaddr/loopin/fsm.md

fsm-check: fsm
	@$(call print, "Verifying generated state machine docs")
	if test -n "$$(git status --porcelain -- $(FSM_FILES))"; then \
		echo "Generated FSM diagrams are not up-to-date!"; \
		git status --porcelain -- $(FSM_FILES); \
		git diff -- $(FSM_FILES); \
		exit 1; \
	fi

Comment on lines 60 to +62
case "instantout":
instantout := &instantout.FSM{}
err = writeMermaidFile(fp, instantout.GetV1ReservationStates())
if err != nil {
return err
}
return instantout.GetV1ReservationStates(), nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable name instantout shadows the imported package name instantout. It is a best practice in Go to avoid shadowing package names to prevent confusion and potential compilation issues. Renaming it to instantOutFSM aligns with the naming pattern used for other FSM variables in this switch block.

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

Comment thread scripts/fsm-generate.sh
Comment on lines 4 to +8
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 ./instantout/fsm.md --fsm instantout No newline at end of file
go run ./fsm/stateparser/stateparser.go --out ./instantout/reservation/fsm.md --fsm reservation
go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout
go run ./fsm/stateparser/stateparser.go --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit
go run ./fsm/stateparser/stateparser.go --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Running go run multiple times compiles the stateparser tool repeatedly, which introduces unnecessary overhead and slows down the script execution. Building the binary once into a temporary directory and executing it multiple times is much more efficient.

Suggested change
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 ./instantout/fsm.md --fsm instantout
\ No newline at end of file
go run ./fsm/stateparser/stateparser.go --out ./instantout/reservation/fsm.md --fsm reservation
go run ./fsm/stateparser/stateparser.go --out ./instantout/fsm.md --fsm instantout
go run ./fsm/stateparser/stateparser.go --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit
go run ./fsm/stateparser/stateparser.go --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin
BIN_DIR=$(mktemp -d)
trap 'rm -rf "$BIN_DIR"' EXIT
go build -o "$BIN_DIR/stateparser" ./fsm/stateparser/stateparser.go
"$BIN_DIR/stateparser" --out ./fsm/example_fsm.md --fsm example
"$BIN_DIR/stateparser" --out ./instantout/reservation/fsm.md --fsm reservation
"$BIN_DIR/stateparser" --out ./instantout/fsm.md --fsm instantout
"$BIN_DIR/stateparser" --out ./staticaddr/deposit/fsm.md --fsm staticaddr-deposit
"$BIN_DIR/stateparser" --out ./staticaddr/loopin/fsm.md --fsm staticaddr-loopin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant