lnd
lnd copied to clipboard
Feature/quiescence protofsm
This is an experimental PR designed to implement a real live protocol state machine using the new protofsm package. The intent of this is to have a realistic usage of the package.
My current review of the package is that its API design is lacking for the stfu flow. Given that quiescence is one of the simpler protocols we may try to build off of this, I think that means we ought to change it up sooner than later.
In particular, the issue I have is the phantom events we need to emit because we don't have a simple way to specify that the state change should follow the send of an event. It is possible that the choices I made in this PR are overly pedantic, but afaict, if we need to tie states to when the messages are actually sent as opposed to staged for the next opportunity then the ergonomics here leave a lot to be desired.
Further, the way things are designed here are that the Event type is "closed" and the State type is "open". I believe this should be reversed. We want finitely enumerable states so we can consider the state graph as a whole, whereas being able to introduce new event types can be done a bit more piecemeal. This is a subtler critique and isn't a showstopper, but it is something I observed.
Additionally, it should be noted that state synchronization is race-y. Sending an event and querying state are concurrent operations with no way to flush the consequences of an event trigger all the way to a stable state before querying it.
As of right now I feel reluctant to write substantial parts of the codebase in this style as I'm not sure if the power it brings is worth but wanted to solicit other opinions.
Also worth noting that the complexity of protofsm seems to be in the state transition code and its power comes from not having to rewrite the drivers, so the savings may not be reflected here at this time. I'll have some follow up commits where I try and plug the machine into the ChannelLink and see if the cost of integration with the existing code is low, since that's where I'd expect to see code savings.
Finally, the more I think about it, the more I am convinced that making every state machine concurrent is a recipe for disaster. I think that there are good reasons to have coroutines per peer connection, per channel link, per event source etc. However, having separate state machines for quiescence, commitment updates, dynamic commitment negotiation, channel closure, and channel funding gives us a combinatorial explosion of potential synchronization issues in an environment where we have strong consistency requirements across these components.
Finally, I recommend comparing this to my original implementation to see the difference in complexity.
[!IMPORTANT]
Auto Review Skipped
Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository.To trigger a single review, invoke the
@coderabbitai reviewcommand.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>.Generate unit-tests for this file.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit tests for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai generate interesting stats about this repository from git and render them as a table.@coderabbitai show all the console.log statements in this repository.@coderabbitai read src/utils.ts and generate unit tests.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - The JSON schema for the configuration file is available here.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json
CodeRabbit Discord Community
Join our Discord Community to get help, request features, and share feedback.
@roasbeef: review reminder @yyforyongyu: review reminder @morehouse: review reminder
@roasbeef: review reminder @yyforyongyu: review reminder @morehouse: review reminder
Closing due to inactivity
Closing due to inactivity
Closing due to inactivity
Closing due to inactivity
Closing due to inactivity
Closing due to inactivity
Closing due to inactivity
!lightninglabs-deploy mute
I'm once again closing this since protofsm's design is still being stabilized and significant effort has been invested into polishing #8270