Skip to content
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

Merged
merged 4 commits into from
Mar 22, 2024

Conversation

Harshit933
Copy link
Collaborator

@Harshit933 Harshit933 commented Mar 19, 2024

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.

Fixes #195

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.
@Harshit933 Harshit933 changed the title Feat/close feat : close channel command Mar 19, 2024
Copy link
Owner

@vincenzopalazzo vincenzopalazzo left a 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

Copy link
Owner

@vincenzopalazzo vincenzopalazzo left a 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

vincenzopalazzo referenced this pull request Mar 20, 2024
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.
Copy link
Owner

@vincenzopalazzo vincenzopalazzo left a 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

Comment on lines 682 to 689
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);
Copy link
Owner

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

Copy link
Collaborator Author

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

Copy link
Owner

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

Copy link
Collaborator Author

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 a None channel_id, this adds the purpose that when there are two channels open with the same peer, we have to provide respective channel_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.

Copy link
Owner

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

Copy link
Owner

@vincenzopalazzo vincenzopalazzo left a 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

Comment on lines 682 to 689
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);
Copy link
Owner

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

@vincenzopalazzo
Copy link
Owner

CI is reporting a failure

test lampo_cln_tests::test_lampo_to_cln_close_channel_without_channel_id_success ... ok

failures:

---- lampo_cln_tests::test_close_channel_without_opening_a_channel_success stdout ----
thread 'lampo_cln_tests::test_close_channel_without_opening_a_channel_success' panicked at tests/tests/src/lampo_cln_tests.rs:870:5:
callback got a timeout
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: tests::lampo_cln_tests::test_close_channel_without_opening_a_channel_success
             at ./src/lampo_cln_tests.rs:870:5
   3: tests::lampo_cln_tests::test_close_channel_without_opening_a_channel_success::{{closure}}
             at ./src/lampo_cln_tests.rs:857:58
   4: core::ops::function::FnOnce::call_once
             at /build/rustc-1.75.0-src/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    lampo_cln_tests::test_close_channel_without_opening_a_channel_success

This commits includes some refactoring of the `close` channel tests
and adds a `channel_id` test.
Copy link
Owner

@vincenzopalazzo vincenzopalazzo left a 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() {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
fn test_closing_two_channels_without_channelid_success() {
fn test_closing_two_channels_without_channelid_fails() {

It is returning an error right?

Comment on lines +895 to +912
#[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);
}
Copy link
Owner

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

@vincenzopalazzo vincenzopalazzo merged commit 9ba4c71 into vincenzopalazzo:main Mar 22, 2024
4 of 5 checks passed
Harshit933 added a commit to Harshit933/lampo.rs that referenced this pull request Mar 23, 2024
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs`
and rename some test names.

Follow up to vincenzopalazzo#198
Harshit933 added a commit to Harshit933/lampo.rs that referenced this pull request Mar 23, 2024
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs`
and rename some test names.

Follow up to vincenzopalazzo#198
vincenzopalazzo pushed a commit that referenced this pull request Mar 23, 2024
Moving `channel_id` test from `lampo_cln_test` to `close_channel.rs`
and rename some test names.

Follow up to #198
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.

implement the command to close a channel
2 participants