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

cln-rpc & cln-grpc: Backfill more methods #5104

Merged
merged 35 commits into from
Apr 1, 2022

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Mar 16, 2022

I now know how @rustyrussell felt filling in the JSON-Schemas for the JSON-RPC responses. This PR mostly consists of me backfilling the JSON-RPC request schemas, and then autogenerating the derived files, occasionally addressing a conversion issue or a missing type.

The PR is based on topp of #5013 and starts with the msggen: Add meta file to keep the field numbers stable commit (daa26ff at the time of writing).

The following files where changed manually, all others were generated and are unlikely to hold any surprises:

  • cln-grpc/proto/primitives.proto to add the Feerate, Utxo and OutputDesc primitives
  • cln-grpc/src/pb.rs to add a number of protobuf <-> JSON-RPC conversions
  • cln-rpc/Cargo.toml to add the hex dependency
  • cln-rpc/src/primitives.rs
  • contrib/msggen/msggen/__main__.py to allowlist more RPC methods and add method renaming for connect which is already used by grpc internally
  • contrib/msggen/msggen/grpc.py to add the fixed mapping from field path to field number required for grpc to work across versions (renumbering fields is not allowed by protobuf and grpc since that's how fields are identified).
  • contrib/msggen/msggen/model.py and contrib/msggen/msggen/rust.py to add mapped types
  • The following request schemas:
    • doc/schemas/connect.request.json
    • doc/schemas/createinvoice.request.json
    • doc/schemas/createonion.request.json
    • doc/schemas/datastore.request.json
    • doc/schemas/deldatastore.request.json
    • doc/schemas/delexpiredinvoice.request.json
    • doc/schemas/delinvoice.request.json
    • doc/schemas/fundpsbt.request.json
    • doc/schemas/invoice.request.json
    • doc/schemas/keysend.request.json
    • doc/schemas/listdatastore.request.json
    • doc/schemas/listinvoices.request.json
    • doc/schemas/listnodes.request.json
    • doc/schemas/listsendpays.request.json
    • doc/schemas/listtransactions.request.json
    • doc/schemas/newaddr.request.json
    • doc/schemas/pay.request.json
    • doc/schemas/sendonion.request.json
    • doc/schemas/sendpay.request.json
    • doc/schemas/sendpsbt.request.json
    • doc/schemas/signpsbt.request.json
    • doc/schemas/utxopsbt.request.json
    • doc/schemas/waitanyinvoice.request.json
    • doc/schemas/waitinvoice.request.json
    • doc/schemas/waitsendpay.request.json
    • doc/schemas/withdraw.request.json

It is likely easiest to review the final diff and not the individual commits, since I jumped around a bit between methods that are more or less related. As for completeness you can look at contrib/msggen/msggen/__main__.py as to which methods are mapped and which aren't yet. Please let me know if there are any methods that are needed for your use-cases and that should be mapped.

This has to be considered experimental code, since I couldn't test most of these commands, due to the sheer surface size. The code compiles, but we make liberal use of panics, which may lead to unexpected results. You have been warned, but feedback is very much welcome to stabilize this interface.

@cdecker cdecker force-pushed the cln-grpc-methods branch 3 times, most recently from 93c10c2 to f0a5b05 Compare March 17, 2022 10:17
@cdecker cdecker marked this pull request as ready for review March 17, 2022 16:33
@cdecker cdecker added this to the v0.11 milestone Mar 17, 2022
@rustyrussell
Copy link
Contributor

Yeah, we really need to add these request schemas to to python framework for testing!

OK, this isn't complete, but my proposal can be found (on top of this!) here: https://github.com/rustyrussell/lightning/tree/guilt/pr-5104

@rustyrussell
Copy link
Contributor

OK, my tree now has all the schema fixes, and some others. If you don't want to mess up your parsing, you can just cherry pick some of those changes (and not the part which actually validates it against the testsuite).

@cdecker cdecker marked this pull request as draft March 25, 2022 18:09
@cdecker
Copy link
Member Author

cdecker commented Mar 25, 2022

I incorporated @rustyrussell's changes and fixes and got things working again. Currently backfilling some more types since they can be hard and might be considered braking changes if we do it later. Also added a couple of tests to gain some more certainty that the conversion code is working.

Will finish the changes by Monday, hoping to get these in asap

@cdecker cdecker changed the base branch from master to cln-grpc-plugin March 28, 2022 10:55
@cdecker cdecker force-pushed the cln-grpc-methods branch 4 times, most recently from d70c2ce to c88effb Compare March 29, 2022 10:34
@cdecker cdecker marked this pull request as ready for review March 29, 2022 10:35
@rustyrussell
Copy link
Contributor

Some commands have changed schemas maybe? Needs rebasing I think...

@rustyrussell
Copy link
Contributor

Didn't get time to fold these, but:

diff --git a/doc/schemas/signmessage.request.json b/doc/schemas/signmessage.request.json
index f5fd75727..163239e20 100644
--- a/doc/schemas/signmessage.request.json
+++ b/doc/schemas/signmessage.request.json
@@ -2,7 +2,7 @@
   "$schema": "http://json-schema.org/draft-07/schema#",
   "type": "object",
   "required": [
-    "id"
+    "message"
   ],
   "additionalProperties": false,
   "properties": {
diff --git a/tests/test_pay.py b/tests/test_pay.py
index bf8adf148..f4f5cc33b 100644
--- a/tests/test_pay.py
+++ b/tests/test_pay.py
@@ -2136,12 +2136,12 @@ def test_setchannel_routing(node_factory, bitcoind):
         l1.rpc.getroute(l3.info['id'], 4001793, 1, fuzzpercent=0)["route"]
 
     # We should consider this unroutable!  (MPP is disabled!)
-    inv = l3.rpc.call('invoice', {'msatoshi': 4001793,
-                                  'label': 'test_setchannel_1',
-                                  'description': 'desc',
-                                  'dev-routes': []})
+    inv = l3.dev_invoice(msatoshi=4001793,
+                         label='test_setchannel_1',
+                         description='desc',
+                         dev_routes=[])
     with pytest.raises(RpcError) as routefail:
-        l1.rpc.dev_pay(inv['bolt11'], use_shadow=False)
+        l1.dev_pay(inv['bolt11'], use_shadow=False)
     assert routefail.value.error['attempts'][0]['failreason'] == 'No path found'
 
     # 1337 + 4000000 * 137 / 1000000 = 1885

@rustyrussell
Copy link
Contributor

Folded those simple fixes...

@rustyrussell
Copy link
Contributor

Hmm, I put some cruft test changes in the rebase somehow. Fixed and once it's tested locally I'll push again...

Otherwise we get less nicely consecutive numbers because request and
response share one domain. This separates them again.
rustyrussell and others added 19 commits April 1, 2022 15:00
This will override the schema later.

Signed-off-by: Rusty Russell <[email protected]>
This will override the schema later.

Signed-off-by: Rusty Russell <[email protected]>
lightningd is happy, but our schema won't be.

Signed-off-by: Rusty Russell <[email protected]>
These are useful for requests:
1. "outpoint": <txid>:<outnum>
2. "feerate": strings or a number
3. "outputdesc": bitcoin-style addresses-as-keys
4. "msat_or_all": amount or "all"
4. "msat_or_any": amount or "any"
5. "short_channel_id_dir": scid with /0 or /1.

Signed-off-by: Rusty Russell <[email protected]>
Types are fixed, in particular:

* rename "OutputDesc" to more consistent "outputdesc".
* rename "utxo" to more consistent "outpoint".
* it's "boolean" not "bool".
* "number" means int or float, usually it should be u32.

Specific commands:

* close `id` can be by channel id, scid.
* close `feerange` is a feerate type.
* datastore/deldatastore/listdatastore `key` can be singleton.
* delexpiredinvoice: `maxexpirytime` is not required, is a u64.
* invoice/delinvoice/listinvoice `label` can be an integer
* fundpsbt: many fields are u32 not number (JSON for int or float).
* invoice: `msatoshi` can be "any".
* invoice: `expiry` has a type (now must be numeric).
* invoice: `exposeprivatechannels` can be bool or array of scids.
* invoice: `deschashonly` added
* keysend: there's no "float" type, use "number" or "u32" etc.
* keysend: `routehints` is a valid arg, as is `extratlvs` (EXPERIMENTAL_FEATURES)
* listdatastore: `key` is not required.
* newaddr: `addresstype` can be "all"
* pay: `exemptfee` is "msat", new fields `locaofferid` and `exclude`
* sendonion: was mis-formatted, missed `localofferid` and `groupid` fields.
* sendpay: add `localofferid` and `groupid` params.
* signpsbt: add `signonly` param.
* txprepare "outptus" typo.
* waitsendpay: add `groupid` and  fix `partid` type.
* withdraw: `destination` is a bitcoin address, not a pubkey.

Signed-off-by: Rusty Russell <[email protected]>
This means suppressing schemas in some places too.

Signed-off-by: Rusty Russell <[email protected]>
Sometimes we just want to paper over the schema directly. Mostly
useful to sidestep the `oneof` things that are required for
expressiveness.
These json structs are gigantic, so let's externalize them a bit.
Got some issues parsing dates for example.
It's schema definition is weirdly asymmetric, with variants dependent
on another fields' value. Need to decide if we want to either
hand-code a superset or make a more complex decoding, but definitely
not something we'd want the generator to be able to do.
So far we were papering over the actual error with a generic string
that isn't very useful. Now we decode the error and forward it through
the grpc layer as well (though still as a string).
 - disconnect
 - feerates
 - getroute
 - listforwards
 - listpays
 - ping
 - signmessage
@cdecker cdecker changed the base branch from cln-grpc-plugin to master April 1, 2022 10:05
@cdecker
Copy link
Member Author

cdecker commented Apr 1, 2022

Rebased, and addressed flake.

rustyrussell and others added 3 commits April 1, 2022 15:09
Signed-off-by: Rusty Russell <[email protected]>
Didn't want to pollute each commit with the changes in the derived
files so here are all the changes in one commit :-)
@rustyrussell
Copy link
Contributor

Ack 9a76d84

Remaining memleak flake is known, on my workaround list soon.

@rustyrussell rustyrussell merged commit aae5e3d into ElementsProject:master Apr 1, 2022
@cdecker cdecker deleted the cln-grpc-methods branch April 8, 2022 02:45
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