Skip to content

Feature add state api #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lukegao209
Copy link
Contributor

Adding a state API can help users better understand the status of the node.

Copy link
Member

@zoedberg zoedberg left a comment

Choose a reason for hiding this comment

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

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

@@ -1676,6 +1690,7 @@ mod issue;
mod lock_unlock_changepassword;
mod multi_hop;
mod multi_open_close;
mod node_state_test;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mod node_state_test;
mod node_state;


use super::*;

const TEST_DIR_BASE: &str = "tmp/node_state_test/";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const TEST_DIR_BASE: &str = "tmp/node_state_test/";
const TEST_DIR_BASE: &str = "tmp/node_state/";

@@ -791,6 +791,19 @@ pub(crate) struct NodeInfoResponse {
pub(crate) network_channels: usize,
}

#[derive(Deserialize, Serialize)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[derive(Deserialize, Serialize)]
#[derive(Debug, PartialEq, Deserialize, Serialize)]

@@ -791,6 +791,19 @@ pub(crate) struct NodeInfoResponse {
pub(crate) network_channels: usize,
}

#[derive(Deserialize, Serialize)]
pub(crate) enum NodeState {
None,
Copy link
Member

Choose a reason for hiding this comment

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

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)
Copy link
Member

Choose a reason for hiding this comment

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

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));
Copy link
Member

Choose a reason for hiding this comment

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

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");
Copy link
Member

Choose a reason for hiding this comment

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

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);

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.

2 participants