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

multi: specify retrieving active, inactive, public, and private channels from listchannels rpc #834

Merged
merged 4 commits into from
Mar 20, 2018

Conversation

wpaulino
Copy link
Contributor

This PR adds parameters to the listchannels RPC in order to specify retrieving active, inactive, public, and private channels.

Also fixes #810.

@meshcollider meshcollider added rpc Related to the RPC interface channels labels Mar 13, 2018
lnrpc/rpc.proto Outdated
/// Whether this channel is active or not
bool active = 1 [json_name = "active"];

/// Whether this channel is advertised to the network or not
bool public = 2 [json_name = "public"];
Copy link
Contributor

Choose a reason for hiding this comment

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

in OpenChannelRequest we are using the private flag. Maybe use that here as well, to be consistent? :)

rpcserver.go Outdated
// Next, we'll determine whether we should add this channel to
// our list depending on the type of channels requested to us.
isActive := peerOnline && linkActive
isPublic := dbChannel.ChannelFlags&lnwire.FFAnnounceChannel ==
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be isPublic := dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 0

rpcserver.go Outdated
lnwire.FFAnnounceChannel

switch {
case in.Active && in.Inactive || !in.Active && !in.Inactive:
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend just making the "in params" active_only, inactive_only etc, then just filter out channels that don't match the criteria (and you could return error early if two incpompatible flags are both set). Should simplify this code significantly!

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

Great feature, thanks @wilmerpaulino! I like the new behavior that you and @halseth worked out for the flags. Just one small request for fixing the updates to the proto file

lnrpc/rpc.proto Outdated
/// Whether this channel is active or not
bool active = 1 [json_name = "active"];

/// Whether this channel is advertised to the network or not
bool private = 2 [json_name = "private"];
Copy link
Contributor

Choose a reason for hiding this comment

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

in order to maintain backwards compatibility for proto files, sequence numbers for existing field should never change. this field should be added to the end of the definition, and the indexes of prior fields should have their indexes reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I believe since we don’t actually store the serialized data of the invoice proto anywhere, it should be fine. I could be mistaken though. I’ll apply your suggestion for consistency regardless.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, for our use case it's probably okay. But that doesn't preclude others from storing/continuing to use the proto definitions ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely! Will fix.

@cfromknecht
Copy link
Contributor

@wilmerpaulino thank you for updating the proto files, LGTM! can you rebase/fixup?

@wpaulino
Copy link
Contributor Author

Done!

Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Alright, on last change to the two error messages, then this looks good! 👍

@@ -1472,6 +1472,16 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
func (r *rpcServer) ListChannels(ctx context.Context,
in *lnrpc.ListChannelsRequest) (*lnrpc.ListChannelsResponse, error) {

if in.ActiveOnly && in.InactiveOnly {
return nil, fmt.Errorf("either `active_only` or " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly right, you should be able to not set any of them :)

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.

rpcserver.go Outdated
}

if in.PublicOnly && in.PrivateOnly {
return nil, fmt.Errorf("either `public_only` or " +
Copy link
Contributor

Choose a reason for hiding this comment

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

same

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.

Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM!

@cfromknecht
Copy link
Contributor

Ready for merge! LGTM 📺

@halseth halseth merged commit 9c0fc02 into lightningnetwork:master Mar 20, 2018
@wpaulino wpaulino deleted the list-channels branch March 20, 2018 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channels rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

activate listchannels --active_only
4 participants