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

Adds a set of convenience methods to set non-custom features #2522

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

sr-gi
Copy link
Contributor

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

Currently only custom features can be set by specifying the feature bit. This PR adds the ability to do so for regular features too.

The rationale for this PR is being able to build a Features instance from a collection of feature bits, as returned different LND's RPC responses (such as get_info, get_node_info, ...)

@TheBlueMatt
Copy link
Collaborator

Is this better done by deserializing the features object? We could add a new constructor that makes that a bit more explicit?

@sr-gi
Copy link
Contributor Author

sr-gi commented Aug 26, 2023

Sure, a deserializer that takes a collection of feature bits and builds the Feature<T> object should also do, but I think most of the code for the bit packing will be replicated from the existing set_custom_bit method, wouldn't it?

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Mmm, I guess I'm just kinda annoyed that we're adapting our safe API to support converting from LND's API...is there no way to get the serialized features out of LND in a clean way? Otherwise, LGTM.

lightning/src/ln/features.rs Show resolved Hide resolved
@wpaulino
Copy link
Contributor

Regardless of what lnd's API does, I still think it's a useful change, and we already have the logic to do it on custom feature bits.

@TheBlueMatt
Copy link
Collaborator

I mean I don't really see the point here if not to support some strange API that outputs a list of features by their bits and we want to "deserialize" that - if you want to build a features object with BOLT-range features, you probably want to select the features via the usual setters, setting it via a bit is pretty weird?

@wpaulino
Copy link
Contributor

I agree, but still I'd rather just expose this than have the user (who may not be able to change the API they're using) implement it themselves.

@TheBlueMatt
Copy link
Collaborator

Oh, I agree, if there's no better way to munge LND's API responses into features this is better than not-this.

lightning/src/ln/features.rs Show resolved Hide resolved
self.set_feature_bit(bit - (bit % 2))
}

/// Sets an custom feature bit. Errors if `bit` is outside the feature range as defined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just realised this read "an custom feature bit" when it should read "an optional feature bit"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 992f102

@sr-gi
Copy link
Contributor Author

sr-gi commented Aug 30, 2023

Oh, I agree, if there's no better way to munge LND's API responses into features this is better than not-this.

I feel your pain and I partially agree with your view, but I don't think there is any other way to get the feature bit data from LND using their RPC interface. If you think this is worth the compromise, I'm happy to fix the nits, if not we'll go with a custom parser downstream

@TheBlueMatt
Copy link
Collaborator

Yea, okay, IMO let's take this, I'm just annoyed.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Rest lgtm

Comment on lines 1113 to 1121


// Set flags manually
let mut features = NodeFeatures::empty();
assert!(features.set_optional_feature_bit(55).is_ok());
assert!(features.supports_keysend());
assert!(features.set_optional_feature_bit(255).is_ok());
assert!(features.set_required_feature_bit(256).is_err());

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there're just a few extra newlines here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed by 992f102

Currently only custom features can be set by specifying the feature bit. Add also the
ability to do so for regular features.
@sr-gi
Copy link
Contributor Author

sr-gi commented Sep 1, 2023

Fixes nits

@TheBlueMatt TheBlueMatt merged commit e9d9711 into lightningdevkit:main Sep 1, 2023
12 of 14 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.

None yet

4 participants