Open
Conversation
Add /nodestate API
add test for nodestate APIs
refactor: simplify node_state control flow
zoedberg
requested changes
Jul 30, 2025
Member
zoedberg
left a comment
There was a problem hiding this comment.
Thank you!
Requested some small changes. Please also squash into a single signed commit saying add /nodestate API and then rebase on top of the updated master.
Finally check lint and format with the latest stable rust
| mod lock_unlock_changepassword; | ||
| mod multi_hop; | ||
| mod multi_open_close; | ||
| mod node_state_test; |
Member
There was a problem hiding this comment.
Suggested change
| mod node_state_test; | |
| mod node_state; |
|
|
||
| use super::*; | ||
|
|
||
| const TEST_DIR_BASE: &str = "tmp/node_state_test/"; |
Member
There was a problem hiding this comment.
Suggested change
| const TEST_DIR_BASE: &str = "tmp/node_state_test/"; | |
| const TEST_DIR_BASE: &str = "tmp/node_state/"; |
| pub(crate) network_channels: usize, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize)] |
Member
There was a problem hiding this comment.
Suggested change
| #[derive(Deserialize, Serialize)] | |
| #[derive(Debug, PartialEq, Deserialize, Serialize)] |
|
|
||
| #[derive(Deserialize, Serialize)] | ||
| pub(crate) enum NodeState { | ||
| None, |
Member
There was a problem hiding this comment.
Suggested change
| None, | |
| Uninitialized, |
please rename also in openapi
Comment on lines
+1848
to
+1853
| description: | | ||
| The current state of the RGB Lightning Node: | ||
| * `None` - Node is not initialized (no mnemonic file exists) | ||
| * `Locked` - Node is initialized but locked (needs to be unlocked) | ||
| * `Running` - Node is unlocked and running (can perform all operations) | ||
| * `Changing` - Node is in the process of changing state (wait for completion) |
Member
There was a problem hiding this comment.
Suggested change
| description: | | |
| The current state of the RGB Lightning Node: | |
| * `None` - Node is not initialized (no mnemonic file exists) | |
| * `Locked` - Node is initialized but locked (needs to be unlocked) | |
| * `Running` - Node is unlocked and running (can perform all operations) | |
| * `Changing` - Node is in the process of changing state (wait for completion) |
names seem sufficiently descriptive
|
|
||
| let node1_addr = start_daemon(&test_dir_node1, NODE1_PEER_PORT).await; | ||
| let state_response = node_state(node1_addr).await; | ||
| assert!(matches!(state_response.state, NodeState::None)); |
Member
There was a problem hiding this comment.
please use assert_eq! (here and in the rest of this test) since in case of failure it shows also the actual value that is not matching.
Comment on lines
+52
to
+61
| unlock(node1_addr, &password).await; | ||
| let state_response = node_state(node1_addr).await; | ||
| assert!(matches!(state_response.state, NodeState::Running)); | ||
|
|
||
| let node_info_response = node_info(node1_addr).await; | ||
| assert!(!node_info_response.pubkey.is_empty()); | ||
| assert_eq!(node_info_response.num_channels, 0); | ||
| assert_eq!(node_info_response.num_peers, 0); | ||
|
|
||
| println!("Node state test completed successfully"); |
Member
There was a problem hiding this comment.
Suggested change
| unlock(node1_addr, &password).await; | |
| let state_response = node_state(node1_addr).await; | |
| assert!(matches!(state_response.state, NodeState::Running)); | |
| let node_info_response = node_info(node1_addr).await; | |
| assert!(!node_info_response.pubkey.is_empty()); | |
| assert_eq!(node_info_response.num_channels, 0); | |
| assert_eq!(node_info_response.num_peers, 0); | |
| println!("Node state test completed successfully"); | |
| let handle = tokio::task::spawn(async move { | |
| unlock(node1_addr, &password).await; | |
| }); | |
| let state_response = node_state(node1_addr).await; | |
| assert_eq!(state_response.state, NodeState::Changing); | |
| let _ = handle.await; | |
| let state_response = node_state(node1_addr).await; | |
| assert_eq!(state_response.state, NodeState::Running); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding a state API can help users better understand the status of the node.