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

lnrpc+lnwire: append listchannels command with the chan_id and short_chan_id #9390

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

Conversation

NishantBansal2003
Copy link

Change Description

Fixes: #8650
This PR enhances channel ID representation by introducing both integer and string formats for ShortChannelId:

  1. Renamed ChanId to ShortChanIdInt:

    • Renamed to better reflect its role as the integer representation of ShortChannelId.
  2. Added ShortChanId:

    • Introduced a string representation of ShortChannelId in the format block x transaction x output.
  3. Introduced chan_id:

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Copy link
Contributor

coderabbitai bot commented Dec 28, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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?

❤️ Share
🪧 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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NishantBansal2003
Copy link
Author

PTAL @ziggie1984

@ziggie1984
Copy link
Collaborator

ziggie1984 commented Dec 29, 2024

Please read the contribution guidelines thoroughly in particular what was immediately catching my eye is the commit structure

@NishantBansal2003
Copy link
Author

Please read the contribution guidelines thoroughly in particular what was immediately catching my eye is the commit structure

Got it! Working on it Now...

@alexbosworth
Copy link
Contributor

Maybe people should be warned that a renaming an API attribute would break things

@@ -1471,7 +1471,7 @@ message Channel {
height, the next 3 the index within the block, and the last 2 bytes are the
output index for the channel.
*/
uint64 chan_id = 4 [jstype = JS_STRING];
uint64 short_chan_id_int = 4 [jstype = JS_STRING];
Copy link
Collaborator

@ziggie1984 ziggie1984 Dec 29, 2024

Choose a reason for hiding this comment

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

we are not renaming stuff, we are deprecating it instead, so no worries @alexbosworth, this approach is not the right one here.

Copy link
Author

Choose a reason for hiding this comment

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

Should I mark this chan_id as deprecated and introduce fields like short_chan_id_int, short_chan_id, and channel_id?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can keep it but instead return the right chan_id not the short chan id here, but I need to think about backwards-compatibility issues.

Copy link
Author

Choose a reason for hiding this comment

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

The right chan_id being in string format may also introduce backward compatibility issues.

Copy link
Author

Choose a reason for hiding this comment

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

So, I can think of two solutions:

  • Mark chan_id as deprecated and introduce fields like short_chan_id_int, short_chan_id, and channel_id.
  • Introduce new names (eg.- chan_id for uint64, chan_id_str for string, and channel_id for BOLT-2 definition) for the additional fields while preserving the same name for the existing field.

wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah you cannot reuse this, it is uint64 and for the real channel_id we need string or bytes, so best is to start from a clean state and deprecate the old value.

@NishantBansal2003 NishantBansal2003 changed the title lnrpc: append listchannels command with the chan_id and short_chan_id lnrpc+lnwire: append listchannels command with the chan_id and short_chan_id Jan 1, 2025
@NishantBansal2003
Copy link
Author

Hey @ziggie1984, I have addressed the Git commit structure and made the required changes based on your review. Please take a look.

@ziggie1984
Copy link
Collaborator

Thank you for the PR, I think it is enough to have the short_chan_id and the normal channel_id in the rpc msg. Then when for example depicting the channel struct via lncli listchannels we should show both representation for the short channel id, but we should not put the different types into the protofile (int&string) that should then happen at the lncli or application level.

@NishantBansal2003
Copy link
Author

Thank you for the PR, I think it is enough to have the short_chan_id and the normal channel_id in the rpc msg. Then when for example depicting the channel struct via lncli listchannels we should show both representation for the short channel id, but we should not put the different types into the protofile (int&string) that should then happen at the lncli or application level.

Addresses the reviewed changes. Here is how the lncli listchannels output now appears (on the regtest network):

{
    "channels": [
        {
            "active": true,
            "remote_pubkey": "02769271ddfb03149bc9e2e6124bb8d83209284dda3affed0dead73f57b64f45dd",
            "channel_point": "6ab312e3b744e1b80a33a6541697df88766515c31c08e839bf11dc9fcc036a19:0",
            "chan_id": "829031767408640",
            "capacity": "20000",
            "local_balance": "16530",
            "remote_balance": "0",
            "commit_fee": "3140",
            "commit_weight": "772",
            "fee_per_kw": "2500",
            "unsettled_balance": "0",
            "total_satoshis_sent": "0",
            "total_satoshis_received": "0",
            "num_updates": "0",
            "pending_htlcs": [],
            "csv_delay": 144,
            "private": false,
            "initiator": true,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_sat": "354",
            "remote_chan_reserve_sat": "354",
            "static_remote_key": false,
            "commitment_type": "ANCHORS",
            "lifetime": "11",
            "uptime": "11",
            "close_address": "",
            "push_amount_sat": "0",
            "thaw_height": 0,
            "local_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "354",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "19800000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "remote_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "354",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "19800000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "alias_scids": [],
            "zero_conf": false,
            "zero_conf_confirmed_scid": "0",
            "peer_alias": "02769271ddfb03149bc9",
            "peer_scid_alias": "0",
            "memo": "",
            "custom_channel_data": "",
            "channel_id": "196a03cc9fdc11bf39e8081cc315657688df971654a6330ab8e144b7e312b36a",
            "short_chan_id": "829031767408640",
            "short_chan_id_str": "754x1x0"
        },
        {
            "active": true,
            "remote_pubkey": "02769271ddfb03149bc9e2e6124bb8d83209284dda3affed0dead73f57b64f45dd",
            "channel_point": "e428fb553769e4e53dbfb9749f8b057272969517ea85c63f46288487bfd62cf0:0",
            "chan_id": "807041534853120",
            "capacity": "100000",
            "local_balance": "0",
            "remote_balance": "96530",
            "commit_fee": "3140",
            "commit_weight": "772",
            "fee_per_kw": "2500",
            "unsettled_balance": "0",
            "total_satoshis_sent": "0",
            "total_satoshis_received": "0",
            "num_updates": "0",
            "pending_htlcs": [],
            "csv_delay": 144,
            "private": false,
            "initiator": false,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_sat": "1000",
            "remote_chan_reserve_sat": "1000",
            "static_remote_key": false,
            "commitment_type": "ANCHORS",
            "lifetime": "459",
            "uptime": "421",
            "close_address": "",
            "push_amount_sat": "0",
            "thaw_height": 0,
            "local_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "1000",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "99000000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "remote_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "1000",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "99000000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "alias_scids": [],
            "zero_conf": false,
            "zero_conf_confirmed_scid": "0",
            "peer_alias": "02769271ddfb03149bc9",
            "peer_scid_alias": "0",
            "memo": "",
            "custom_channel_data": "",
            "channel_id": "f02cd6bf878428463fc685ea1795967272058b9f74b9bf3de5e4693755fb28e4",
            "short_chan_id": "807041534853120",
            "short_chan_id_str": "734x1x0"
        }
    ]
}

@ziggie1984
Copy link
Collaborator

While looking at the protobuf file, a lot of the structs use chan_id for the short channel id, so I am at this point not convinced about deprecating this value but rather just adding a new field for the longer channel id to keep the change small.

Maybe something like funding_outpoint_id

I think it is not really worth dealing with all these name changes in the protofiles if so many structs are affected. Wdyt @guggero ?

@ziggie1984
Copy link
Collaborator

I have a better idea:

So initial request was to make the lncli listchannels output more detailed by adding the channel_id and also adding the human-readable representation of the short channel_id to the output of the command.

We can do all this by just changing the lncli program rather than touching the lnd core unit. The human-readable representation of the short_channel_id can be derived from the integer value currently already available. Moreover also the Xored ChannelID can be calculated using the ChannelPoint already available in the grpc msg.

So I favour the approach to not change anything in the RPC code, but just add all the information on the lncli side!

Modified the `String` method of `ShortChannelID` to generate a
human-readable representation using 'x' as a separator.
(block x transaction x output).

Signed-off-by: Nishant Bansal <[email protected]>
Signed-off-by: Nishant Bansal <[email protected]>
@NishantBansal2003
Copy link
Author

I have a better idea:

So initial request was to make the lncli listchannels output more detailed by adding the channel_id and also adding the human-readable representation of the short channel_id to the output of the command.

We can do all this by just changing the lncli program rather than touching the lnd core unit. The human-readable representation of the short_channel_id can be derived from the integer value currently already available. Moreover also the Xored ChannelID can be calculated using the ChannelPoint already available in the grpc msg.

So I favour the approach to not change anything in the RPC code, but just add all the information on the lncli side!

Done. Here is how the lncli listchannels output now appears:

{
    "channels": [
        {
            "active": false,
            "remote_pubkey": "02769271ddfb03149bc9e2e6124bb8d83209284dda3affed0dead73f57b64f45dd",
            "channel_point": "6ab312e3b744e1b80a33a6541697df88766515c31c08e839bf11dc9fcc036a19:0",
            "funding_outpoint_id": "196a03cc9fdc11bf39e8081cc315657688df971654a6330ab8e144b7e312b36a",
            "chan_id": "829031767408640",
            "chan_id_str": "754x1x0",
            "capacity": "20000",
            "local_balance": "16530",
            "remote_balance": "0",
            "commit_fee": "3140",
            "commit_weight": "772",
            "fee_per_kw": "2500",
            "unsettled_balance": "0",
            "total_satoshis_sent": "0",
            "total_satoshis_received": "0",
            "num_updates": "0",
            "pending_htlcs": [],
            "csv_delay": 144,
            "private": false,
            "initiator": true,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_sat": "354",
            "remote_chan_reserve_sat": "354",
            "static_remote_key": false,
            "commitment_type": "ANCHORS",
            "lifetime": "0",
            "uptime": "0",
            "close_address": "",
            "push_amount_sat": "0",
            "thaw_height": 0,
            "local_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "354",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "19800000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "remote_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "354",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "19800000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "alias_scids": [],
            "zero_conf": false,
            "zero_conf_confirmed_scid": "0",
            "peer_alias": "02769271ddfb03149bc9",
            "peer_scid_alias": "0",
            "memo": "",
            "custom_channel_data": ""
        },
        {
            "active": false,
            "remote_pubkey": "02769271ddfb03149bc9e2e6124bb8d83209284dda3affed0dead73f57b64f45dd",
            "channel_point": "e428fb553769e4e53dbfb9749f8b057272969517ea85c63f46288487bfd62cf0:0",
            "funding_outpoint_id": "f02cd6bf878428463fc685ea1795967272058b9f74b9bf3de5e4693755fb28e4",
            "chan_id": "807041534853120",
            "chan_id_str": "734x1x0",
            "capacity": "100000",
            "local_balance": "0",
            "remote_balance": "96530",
            "commit_fee": "3140",
            "commit_weight": "772",
            "fee_per_kw": "2500",
            "unsettled_balance": "0",
            "total_satoshis_sent": "0",
            "total_satoshis_received": "0",
            "num_updates": "0",
            "pending_htlcs": [],
            "csv_delay": 144,
            "private": false,
            "initiator": false,
            "chan_status_flags": "ChanStatusDefault",
            "local_chan_reserve_sat": "1000",
            "remote_chan_reserve_sat": "1000",
            "static_remote_key": false,
            "commitment_type": "ANCHORS",
            "lifetime": "0",
            "uptime": "0",
            "close_address": "",
            "push_amount_sat": "0",
            "thaw_height": 0,
            "local_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "1000",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "99000000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "remote_constraints": {
                "csv_delay": 144,
                "chan_reserve_sat": "1000",
                "dust_limit_sat": "354",
                "max_pending_amt_msat": "99000000",
                "min_htlc_msat": "1",
                "max_accepted_htlcs": 483
            },
            "alias_scids": [],
            "zero_conf": false,
            "zero_conf_confirmed_scid": "0",
            "peer_alias": "02769271ddfb03149bc9",
            "peer_scid_alias": "0",
            "memo": "",
            "custom_channel_data": ""
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants