-
Notifications
You must be signed in to change notification settings - Fork 912
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
Field filtering: limit what fields will be returned from (almost) any JSON command. #5681
Field filtering: limit what fields will be returned from (almost) any JSON command. #5681
Conversation
very nice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool idea. Apart from a minor suggestion to locate the result post-processing separately from the arguments to the method, I think this is good to go 👍
lightningd-rpc -- Lightning Daemon RPC Protocols | ||
================================================ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to add this to the docs 👍
On Tue, Nov 01, 2022 at 10:21:59AM -0700, Christian Decker wrote:
An alternative to this would have been to slightly break with the JSON-RPC spec and allow us to add meta-parameters in the top-level dict, instead of in the `payload` keyed dict. This is would have been nice since the filtering, and eventually paging, is orthogonal to the actual operations we're asking `lightningd` to perform.
I originally assumed this is how it would have been implemented but I'm
ok with the current implementation as well.
|
Hmm, good point re: a separate field being neater. However, that also means every layer above needs to know about it.
I'd like @ShahanaFarooqui input on this! |
Signed-off-by: Rusty Russell <[email protected]>
e3252e2
to
f451c08
Compare
Keeping it as a separate field looks more logical and neat solution, even though it will require some top layer updates initially. Regarding c-lightning-rest, this update should not take much time to implement. |
Since the "struct command" is different from plugins and lightningd, we need an accessor for this to work (the plugin one is a dummy for now!). Signed-off-by: Rusty Russell <[email protected]>
8632d98
to
ebbc324
Compare
OK, this reworks it to use a (non-standard) "filter" object in the request. This is simpler, though we now need to have an explicit lightning-cli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1ae3a47
```python | ||
with rpc.reply_filter({"transactions": [{"outputs": [{"amount_msat": true, "type": true}]}]}): | ||
rpc.listtransactions() | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stole it from your context code I think!!
ebbc324
to
1ae3a47
Compare
Source code checker choked on duplicate include. Fixed and force-pushed. |
Hm, still fails, this time because with Two options:
What do you think @rustyrussell ? |
No tests currently use it, and if they do we'll want to do some per-test objects. Otherwise, we are about it introduce a dependency on common/json_filter.o, which is a can of worms. Signed-off-by: Rusty Russell <[email protected]>
Found a trivial fix: remove the other JSON common objects from the fuzz makefile! Ack 3bbdd35 |
1ae3a47
to
3bbdd35
Compare
Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: JSON-RPC: `filter` object allows reduction of JSON response to (most) commands.
We suppress schema reply checking when filter is set: we could just remove all the `required` fields in the JSON schema. Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: pyln: LightningRpc has new `reply_filter` context manager for reducing output of RPC commands.
Signed-off-by: Rusty Russell <[email protected]>
This documents how to communicate with lightningd over RPC, including use of the `filter` object. Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: Documentation: `lightningd-rpc` manual page describes details of our JSON-RPC interface, including compatibility and filtering.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: cli: new `--filter` parameter to reduce JSON output.
3bbdd35
to
a6f38a2
Compare
Fuzz fix was trivial (stop including other JSON files). Ack a6f38a2 |
Sometimes you only care about a single field from a request: this especially makes this faster if you're running remotely (RTL, commando, etc). So we add a simple
_filter
field, which is a template of the same form as the request, but only fields mentioned in this template will be included.In future, commands may examine the filter to avoid calculations altogether. And pyln may also be enhanced to support it (plugins which don't support it have it stripped, so no change for them!).