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

Set node alias #330

Merged
merged 14 commits into from
Oct 7, 2024
Merged

Set node alias #330

merged 14 commits into from
Oct 7, 2024

Conversation

enigbe
Copy link
Contributor

@enigbe enigbe commented Jul 25, 2024

What this PR does:

  • Adds a function to allow users set the node alias.
  • If set, ensures that the provided alias is broadcast with the node announcement

Related issue(s):

@enigbe enigbe mentioned this pull request Jul 25, 2024
@enigbe enigbe changed the title Set node alias WIP: Set node alias Jul 29, 2024
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Excuse the delay here!

Thank you for looking into this, approach already looks pretty good! Just a few comments.

src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@enigbe enigbe changed the title WIP: Set node alias Set node alias Aug 6, 2024
@enigbe enigbe marked this pull request as ready for review August 6, 2024 14:48
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks! I think beyond checking for the node alias and listening addresses before broadcasting, we should also modify the default_user_config method in Config to, if any of the two are unconfigured:

a) set UserConfig::accept_forwards_to_priv_channels to false
b) set ChannelHandshakeConfig::announced_channel to false
c) set ChannelHandshakeLimits::force_announced_channel_preference to true

Additionally, we'll want to return an error from connect_open_channel if any of the two are unconfigured and we try to open an announced channel. To this end, it might be bit cleaner if we'd split the method in two (open_channel and open_announced_channel) rather than having it take a simple bool.

TLDR: We should use the configured listening addresses and node alias as indicators whether we are a forwarding node or not. If we're not, we should disallow announced channels.

Let me know if you'd be up for these additional changes, otherwise I'm happy to pick them up as a follow-up.

README.md Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@enigbe
Copy link
Contributor Author

enigbe commented Aug 7, 2024

Thanks! I think beyond checking for the node alias and listening addresses before broadcasting, we should also modify the default_user_config method in Config to, if any of the two are unconfigured:

a) set UserConfig::accept_forwards_to_priv_channels to false b) set ChannelHandshakeConfig::announced_channel to false c) set ChannelHandshakeLimits::force_announced_channel_preference to true

Additionally, we'll want to return an error from connect_open_channel if any of the two are unconfigured and we try to open an announced channel. To this end, it might be bit cleaner if we'd split the method in two (open_channel and open_announced_channel) rather than having it take a simple bool.

TLDR: We should use the configured listening addresses and node alias as indicators whether we are a forwarding node or not. If we're not, we should disallow announced channels.

Let me know if you'd be up for these additional changes, otherwise I'm happy to pick them up as a follow-up.

Thanks for the review. I am happy to keep working on this until it is ready.

@tnull
Copy link
Collaborator

tnull commented Aug 27, 2024

Thanks for the review. I am happy to keep working on this until it is ready.

Thanks again! Do you still intend to do this in this PR, or would you prefer we land this and do additional changes in a follow up?

Btw. this also needs a rebase already, and there will be larger code changes upcoming in the LDK/BDK/rust-bitcoin upgrade PR, which will likely also lead to further rebase conflicts.

@enigbe
Copy link
Contributor Author

enigbe commented Aug 27, 2024

Thanks for the review. I am happy to keep working on this until it is ready.

Thanks again! Do you still intend to do this in this PR, or would you prefer we land this and do additional changes in a follow up?

Btw. this also needs a rebase already, and there will be larger code changes upcoming in the LDK/BDK/rust-bitcoin upgrade PR, which will likely also lead to further rebase conflicts.

Apologies for the delay. I am almost done and will be pushing changes today. I'll rebase and get it ready for another look before the end of the day.

@tnull
Copy link
Collaborator

tnull commented Aug 27, 2024

Apologies for the delay. I am almost done and will be pushing changes today. I'll rebase and get it ready for another look before the end of the day.

No worries! Cool, thank you!

@enigbe
Copy link
Contributor Author

enigbe commented Aug 29, 2024

Thanks for the review. I am happy to keep working on this until it is ready.

Thanks again! Do you still intend to do this in this PR, or would you prefer we land this and do additional changes in a follow up?
Btw. this also needs a rebase already, and there will be larger code changes upcoming in the LDK/BDK/rust-bitcoin upgrade PR, which will likely also lead to further rebase conflicts.

Apologies for the delay. I am almost done and will be pushing changes today. I'll rebase and get it ready for another look before the end of the day.

Hi @tnull, I have rebased and pushed recommended changes. Unfortunately, the integration tests are flaky and I am uncertain about why. Currently investigating.

@enigbe
Copy link
Contributor Author

enigbe commented Sep 5, 2024

Thanks for the review. I am happy to keep working on this until it is ready.

Thanks again! Do you still intend to do this in this PR, or would you prefer we land this and do additional changes in a follow up?
Btw. this also needs a rebase already, and there will be larger code changes upcoming in the LDK/BDK/rust-bitcoin upgrade PR, which will likely also lead to further rebase conflicts.

Apologies for the delay. I am almost done and will be pushing changes today. I'll rebase and get it ready for another look before the end of the day.

Hi @tnull, I have rebased and pushed recommended changes. Unfortunately, the integration tests are flaky and I am uncertain about why. Currently investigating.

Hi @tnull, thanks for your review so far. Have you had some time to check out the recent changes I have made? I have addressed the comments raised and would be grateful for any further feedback or recommendation.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Hi @tnull, thanks for your review so far. Have you had some time to check out the recent changes I have made? I have addressed the comments raised and would be grateful for any further feedback or recommendation.

Excuse the delay here! Did another round, already looks pretty good, just a few comments.

To make CI pass you'll need to adjust all prior uses of connect_open_channel/connectOpenChannel in the bindings tests (i.e., in bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt for Kotlin and bindings/python/src/ldk_node/test_ldk_node.py for Python).

There are also a few references to connect_open_channel left in tests and comments which should be renamed accordingly.

src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated Show resolved Hide resolved
src/builder.rs Outdated
mod tests {
use lightning::routing::gossip::NodeAlias;

use crate::{builder::sanitize_alias, BuildError};
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Given these tests are in a sub-module of builder, I think you don't need to import these types at all here?

src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
What this commit does:
Implements a method `set_node_alias` on NodeBuilder to allow
callers customize/set the value of the node alias. This method
sanitizes the user-provided alias by ensuring the following:
 + Node alias is UTF-8-encoded String
 + Node alias is non-empty
 + Node alias cannot exceed 32 bytes
 + Node alias is only valid up to the first null byte. Every
   character after the null byte is discraded

Additionally, a test case is provided to cover sanitizing
empty node alias, as well as an alias with emojis (copied and
modified from rust-lightning) and a sandwiched null byte.
What this commit does:
Broadcasts node announcement with the user-provided alias, if set,
else, uses the default [0u8;32].

Additionally, adds a random node alias generating function for use
in the generation of random configuration.
     alias sanitization

- Skips broadcasting node announcement in the event that either
  the node alias or the listening addresses are not set.
- Aligns the InvalidNodeAlias error variant with the others to
  make it work with language bindings.
- Simplifies the method to set the node alias.
- Cleans up the alias sanitizing function to ensure that protocol-
  compliant aliases (in this case, empty strings) are not flagged.
  Additionally, removes the check for sandwiched null byte.
- Finally, adds the relevant update to struct and interface to
  reflect changes in Rust types.
What this commit does:
+ Updates the sanitization function for node alias to return NodeAlias
+ Updates the node alias type in the configuration to NodeAlias and implements a conversion to/from String for bindings
+ With this update, regardless of where the alias is set, i.e. in the set_node_alias or directly, sanitization occurs.
What this commit does:
+ Decomposes connect_open_channel into two different functions:
   open_channel and open_announced_channel. This allows opening
   announced channels based on configured node alias and listening
   addresses values.
+ This enforces channel announcement only on the condition that
    both configuration values are set.
+ Additionally, a new error variant `OpenAnnouncedChannelFailed`
    is introduced to capture failure.

    Note: I thought I added the `InvalidNodeAlias` variant in the
    previous commit
What this commit does:
+ Replaces calls to `connect_open_channel` with `open_channel` and
    `open_announced_channel` where appropriate.

Status: Work In Progress (WIP)

Observation:
+ The integration tests are now flaky and need further investigation
    to ascertain the reason(s) why and then to fix.
What this commit does:
+ Removes the wrapping Arc from the channel config. This is a missed
    update after rebasing.
@enigbe enigbe force-pushed the feat-set-node-alias branch 2 times, most recently from c2589f3 to a740401 Compare September 24, 2024 08:12
This commit addresses changes necessary to:
- fix failing tests for generated bindings
- remove unnecessary error variant previously introduced to capture
  failure associated with opening announced channels, and re-use
  existing variants that better capture the reasons, i.e. `InvalidNodeAlias`
  and `InvalidSocketAddress`, why opening an announced channel failed.
- correct visibility specifiers for objects, and
- cleanup nitpicks

Specific modifications across several files include:
- updating the UDL file, as well as tests related to python and kotlin
  that call `open_channel` and/or open_announced_channel
- repositioning/rearranging methods and struct fields
- introducing enums (`ChannelAnnouncementStatus` & `ChannelAnnouncementBlocker`)
  to capture and codify channel announceable eligibility, providing reasons
  for unannounceable channels
- modifying `can_announce_channel` to utilize the aforementioned enums,
  as opposed to simply returning a boolean value.
- cleaning up and renaming `connect_open_channel` to `open_channel_inner`,
  and maintaining a boolean flag for channel announcement
- updating documentation, unit, and integration tests that factor all
  these changes
@tnull
Copy link
Collaborator

tnull commented Sep 26, 2024

Seems CI is failing. Let me know when this is ready for another round of review!

@enigbe enigbe force-pushed the feat-set-node-alias branch 2 times, most recently from 59f77b2 to 5d5d1cd Compare September 26, 2024 23:16
… addresses

This commit addresses flaky test issues related to conditional channel
opening between nodes, considering node aliases and listening addresses.

Changes in test modules:
- Add/modify helper functions to randomize channel announcement flags
- Generate random node aliases based on announcement flags:
  * Set custom alias if announce_channel is true
  * Use default alias otherwise
- Update channel opening logic to account for node and channel announcements
@enigbe
Copy link
Contributor Author

enigbe commented Sep 27, 2024

Seems CI is failing. Let me know when this is ready for another round of review!

I have made some changes to address flaky tests that were failing in CI. They are all passing now with the exception of Rust Tests / build(windows-latest, 1.63.0) which runs endlessly until it is cancelled. It appears stuck building the project.

I am currently investigating it. I would be grateful for another review while I try to fix the build.

Edit:

I was able to replicate the issue locally (on Windows 11 Home) using rust 1.63.0. The build consistently hangs while compiling the secp256k1-sys crate (see image below).

If you have time, it would be helpful if you could try running the build locally to see if it's replicable or investigate whether this is related to a specific environment setup.

I am uncertain about why this is happening but I will keep looking into known issues related to secp256k1-sys on this version of rust.

ldk-node-stuck-windows-build-2

@enigbe enigbe requested a review from tnull September 27, 2024 10:54
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks and excuse the delay once more! This generally LGTM, although I found a few nits and disgree with the test changes in the last commit. I think I'll land this as is and address the changes in a quick follow-up as we're expecting considerable changes across the codebase in #358 and follow-up PRs, which would likely make rebasing this over and over again pretty painful.

src/builder.rs Show resolved Hide resolved
src/config.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/config.rs Show resolved Hide resolved
tests/common/mod.rs Show resolved Hide resolved
tests/common/mod.rs Show resolved Hide resolved
tests/common/mod.rs Show resolved Hide resolved
tests/integration_tests_rust.rs Show resolved Hide resolved
@tnull tnull merged commit c9ebeb6 into lightningdevkit:main Oct 7, 2024
12 of 13 checks passed
@tnull tnull mentioned this pull request Oct 7, 2024
@tnull
Copy link
Collaborator

tnull commented Oct 7, 2024

Now opened a follow-up PR to address the remaining feedback here: #366

@enigbe
Copy link
Contributor Author

enigbe commented Oct 17, 2024

Thank you @tnull for your patient review of this and for cleaning up the nits in #366.

@tnull
Copy link
Collaborator

tnull commented Oct 17, 2024

Thank you @tnull for your patient review of this and for cleaning up the nits in #366.

Sure, I hope you don't mind I tackled them in a follow-up. I mainly wanted to make sure this lands in 0.4 and wanted to spare you the rebase conflicts that would have ensued..

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