-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat : close channel command #198
Conversation
Adds the ability to close channels from the lampo node. Changes done : Adds close_channel function inside lampod/src/ln/channel_manager.rs Adds request/response inside model/close_channel.rs Adds `close` command inside main.rs Some minor changes : Adds `channel_id` inside channels response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good PR thanks for doing it.
I left some comments in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need more works, sorry
When there is only one channel open with the given `node_id` we can just skip the `channel_id` from the `close` request.
When there is only one channel open with the given `node_id` we can just skip the `channel_id` from the `close` request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are close, some rust style suggestion, and we need to make the test better
tests/tests/src/lampo_cln_tests.rs
Outdated
let result: Result<response::CloseChannel, _> = lampo.call( | ||
"close", | ||
request::CloseChannel { | ||
node_id: info_cln.id.to_string(), | ||
channel_id: Some(channels.channels.first().unwrap().channel_id.to_string()), | ||
}, | ||
); | ||
assert!(result.is_err(), "{:?}", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is a poor test, 99% of the code is copied by other test, and your code is not checking nothing import.
You are missing:
- checking that
CloseChannel
contains the information that you need - add another test where the channel_id is not specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test where channel_id
is not specified is already added.
// Closing the second channel - at this point there is only 1 channel with the peer
let result: Result<response::CloseChannel, _> = lampo.call(
"close",
request::CloseChannel {
node_id: info_cln.id.to_string(),
channel_id: None,
},
);
assert!(result.is_ok(), "{:?}", result);
assert_eq!(
result.unwrap().peer_id,
info_cln.id.to_string()
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I do not understand the test, why you are calling 3 time close channel?
For clarity every time that you close a channel you make a new test, and add the reason inside the name. E.g: test_lampo_to_cln_close_channel_without_channel_id_success
and so one all the combination that you added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are four tests in a same one. I'll describe each one of them -
Prior to the test we open two channels.
- 1st test - We call the
close
with aNone
channel_id
, this adds the purpose that when there are two channels open with the same peer, we have to provide respectivechannel_id
. - 2nd test - Closing the first channel - This test demonstrate that we can close the channel with given
channel_id
- 3rd test - Now we have only one channel left - We can close this channel without providing
channel_id
. - 4th test - Now we do not have any channel left - Now closing the channel would give an error.
I avoided making 4 sets of different tests as it would add much more boilerplate code. Let me know if I should make different test cases for each.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if I should make different test cases for each.
Yes please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new set of comments
tests/tests/src/lampo_cln_tests.rs
Outdated
let result: Result<response::CloseChannel, _> = lampo.call( | ||
"close", | ||
request::CloseChannel { | ||
node_id: info_cln.id.to_string(), | ||
channel_id: Some(channels.channels.first().unwrap().channel_id.to_string()), | ||
}, | ||
); | ||
assert!(result.is_err(), "{:?}", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I do not understand the test, why you are calling 3 time close channel?
For clarity every time that you close a channel you make a new test, and add the reason inside the name. E.g: test_lampo_to_cln_close_channel_without_channel_id_success
and so one all the combination that you added
CI is reporting a failure
|
This commits includes some refactoring of the `close` channel tests and adds a `channel_id` test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There are some comments that can be addressed in other PRs
@@ -539,3 +540,373 @@ fn be_able_to_kesend_payments() { | |||
assert!(result.is_ok(), "{:?}", result); | |||
async_run!(cln.stop()).unwrap(); | |||
} | |||
|
|||
#[test] | |||
fn test_closing_two_channels_without_channelid_success() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn test_closing_two_channels_without_channelid_success() { | |
fn test_closing_two_channels_without_channelid_fails() { |
It is returning an error right?
#[test] | ||
fn channel_id_tests() { | ||
let node_id = "039c108cc6777e7d5066dfa33c611c32e6baa1c49de6d546b5b76686486d0360ac".to_string(); | ||
|
||
// This is a correct channel_hex of 32 bytes | ||
let channel_hex = | ||
Some("0a44677526ac8c607616bd91258d7e5df1d86fae9c32e23aa18703a650944c64".to_string()); | ||
let req = CloseChannel { | ||
node_id: node_id.clone(), | ||
channel_id: channel_hex, | ||
}; | ||
let channel_bytes = [ | ||
10, 68, 103, 117, 38, 172, 140, 96, 118, 22, 189, 145, 37, 141, 126, 93, 241, 216, 111, | ||
174, 156, 50, 226, 58, 161, 135, 3, 166, 80, 148, 76, 100, | ||
]; | ||
let channel_id_bytes = req.channel_id(); | ||
assert_eq!(channel_bytes, channel_id_bytes.unwrap().0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be added inside lampo-common/src/model/close_channel.rs
inside the tests there are functional tests, and this is a unit test
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs` and rename some test names. Follow up to vincenzopalazzo#198
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs` and rename some test names. Follow up to vincenzopalazzo#198
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs` and rename some test names. Follow up to #198
Adds the ability to close channels from the lampo node.
Changes done :
Some minor changes :
Fixes #195