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

Normalizes node features so they use LDK NodeFeatures #77

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Aug 24, 2023

Currently we were using a pretty hacky way of parsing LND features that only parsed the keysend feature (given is the only we care about atm).

This PR properly loads the feature vector returned by LND's GetNodeInfo and parses it so a complete NodeFeatures object can be constructed.

Also sets NodeInfo::features to NodeFeatures for consistency

@sr-gi
Copy link
Member Author

sr-gi commented Aug 24, 2023

Some manual testing to make sure the features are properly parsed will be appreciated (I'm looking at you @okjodom, AKA fast-merger lol)

@sr-gi sr-gi force-pushed the normalize-node-features branch 2 times, most recently from 11ca6b6 to b5e2566 Compare August 24, 2023 13:16
@sr-gi
Copy link
Member Author

sr-gi commented Aug 25, 2023

I've opened a PR upstream to add the regular feature bit parsing. We should be able to simplify this if that gets merged (I have code locally for it).

I think we could squash this and go with the current approach for now.

For reference: lightningdevkit/rust-lightning#2522

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Bless you for persevering with this! Just a few comments on readability, I think we can also squash the two commits into one?

.getinfo(GetinfoRequest {})
.await
.map_err(|err| LightningError::GetInfoError(err.to_string()))?
.into_inner();

//FIXME: our_features is returning None, but it should not :S
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this comment still apply?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, and I'm not sure why :S

Comment on lines 27 to 30
// FIXME: Do better with this error
// TODO: We could even generalize this to parse any type of Features
/// Parses the node features from the format returned by LND gRPC to LDK NodeFeatures
fn parse_node_features(features: HashSet<&u32>) -> Result<NodeFeatures, String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just return NodeFeatures since this doesn't error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, you're right. I mixed this with the previous commit

@@ -47,7 +67,8 @@ impl LndNode {
info: NodeInfo {
pubkey: PublicKey::from_str(&identity_pubkey)
.map_err(|err| LightningError::GetInfoError(err.to_string()))?,
features: features.keys().copied().collect(),
features: parse_node_features(features.keys().collect())
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than parse_node_features taking &u32 could we do keys().cloned().collect() here? Seems like a more normal function signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I don't think that'll be a big deal

fn parse_node_features(features: HashSet<&u32>) -> Result<NodeFeatures, String> {
let mut flags = vec![0; 256];

// Set well known features first
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't really make sense to me? Looks like we're setting lower value features first, not known ones?

Perhaps reword to note that < 255 are protocol features, so we allocate enough for the "standard" protocol features first?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, same, this was from the initial apporach

Currently we were using a pretty hacky way of parsing LND features that only
parsed the keysend feature (given is the only we care about atm).

This PR properly loads the feature vector returned by LND's GetNodeInfo and
parses it so a complete NodeFeatures object can be constructed.

Also sets NodeInfo::features to NodeFeatures for consistency

This is based on LDK's code for parsing features, there's currently an open
PR to merge this upstream, so we can simplify if that gets merged.
@sr-gi
Copy link
Member Author

sr-gi commented Aug 25, 2023

Fixed @carlaKC comments and squashed both commits.

@sr-gi sr-gi requested a review from carlaKC August 28, 2023 07:10
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

LGTM!

If we're going to merge before figuring out why our_features is None let's open a bug issue so that we don't forget about it !

@carlaKC
Copy link
Contributor

carlaKC commented Aug 29, 2023

@sr-gi any reason not to merge this one? I think it's ready to go 🚀

@sr-gi
Copy link
Member Author

sr-gi commented Aug 29, 2023

LGTM!

If we're going to merge before figuring out why our_features is None let's open a bug issue so that we don't forget about it !

I'm trying to figure out this, will merge tomorrow otherwise

@carlaKC
Copy link
Contributor

carlaKC commented Aug 29, 2023

I'm trying to figure out this, will merge tomorrow otherwise

Sounds like a plan! Goood luck to ya 🫡

@sr-gi
Copy link
Member Author

sr-gi commented Aug 29, 2023

For the record: ElementsProject/lightning#6635

We may want to merge this and keep track of the fix, if it doesn't happen to be me doing something weird

@carlaKC
Copy link
Contributor

carlaKC commented Aug 30, 2023

We may want to merge this and keep track of the fix, if it doesn't happen to be me doing something weird

SGTM - created #85 to keep track of it!

@sr-gi sr-gi merged commit 98b2350 into bitcoin-dev-project:main Aug 30, 2023
2 checks passed
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