<div dir="ltr"><div dir="ltr">Notice that this is already partially documented in the plugins.md file [1]. I say partially because it's missing the "configuration" key. I have a commit in my next PR that addresses this and adds documentation for the JSON-RPC passthrough.<div><br></div><div><br></div><div>[1] <a href="https://github.com/ElementsProject/lightning/blob/master/doc/plugins.md#the-init-method">https://github.com/ElementsProject/lightning/blob/master/doc/plugins.md#the-init-method</a></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 14, 2018 at 7:00 PM Richard Bondi <<a href="mailto:socketexception@gmail.com">socketexception@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Logs would help, so I created my own log to file and here is what the issue was<br>
<br>
the "init" message looks like this<br>
<br>
{ "jsonrpc": "2.0", "method": "init", "id": 1, "params": {<br>
"options": { "greeting": "greeting" }, "configuration": {<br>
"lightning-dir": "/home/richard/.lightning", "rpc-file":<br>
"lightning-rpc" } }}<br>
<br>
I was not expecting the "params" to be an object and the plugin was<br>
crashing because of this, I was always trying to read as array of<br>
strings, for the hello response and never imagined. I am sure this<br>
will lead me to a fix for the go version also.<br>
<br>
I think it would be good to document the the expected requests, I will<br>
make a PR.<br>
<br>
Thank you both for your time and responses.<br>
On Sun, Dec 9, 2018 at 10:48 PM Rusty Russell <<a href="mailto:rusty@rustcorp.com.au" target="_blank">rusty@rustcorp.com.au</a>> wrote:<br>
><br>
> Pretty sure Christian is right, you need to flush in your plugin, *or*<br>
> you're not closing your JSON reply. Both will give you hangs like this<br>
> as c-lightning waits for the complete response.<br>
><br>
> We should do I/O logging on plugins so that this kind of thing can be<br>
> diagnosed more easily.<br>
><br>
> Cheers,<br>
> Rusty.<br>
><br>
> Richard Bondi <<a href="mailto:socketexception@gmail.com" target="_blank">socketexception@gmail.com</a>> writes:<br>
> > Additional info, it hangs here<br>
> > <a href="https://github.com/ElementsProject/lightning/blob/8238fe6acfc7db9e397ecac21e9e82cdc25c40be/cli/lightning-cli.c#L322" rel="noreferrer" target="_blank">https://github.com/ElementsProject/lightning/blob/8238fe6acfc7db9e397ecac21e9e82cdc25c40be/cli/lightning-cli.c#L322</a><br>
> ><br>
> > the `cmd` variable = 0x55555577d868 "{ \\"method\\" : \\"hello\\",<br>
> > \\"id\\" : \\"lightning-cli-10719\\", \\"params\\" : [ \\"fred\\"] }"<br>
> ><br>
> > also, when I follow the `read` function in my ide, it takes me to<br>
> > cli/test/run-large-input.c which does not look right, and I never seem<br>
> > to hit a breakpoint there, what other info could I provide that would<br>
> > be useful?<br>
> > On Sat, Dec 8, 2018 at 11:53 AM Richard Bondi <<a href="mailto:socketexception@gmail.com" target="_blank">socketexception@gmail.com</a>> wrote:<br>
> >><br>
> >> Thanks Christian,<br>
> >><br>
> >> This is exactly the approach I took, except with formatted json<br>
> >> response, but I updated to unformatted and the results I get are as<br>
> >> expected from the shell, so it seems my assumptions were correct.<br>
> >><br>
> >> However, I still have the issue as described.<br>
> >><br>
> >> I created a repository<br>
> >> <a href="https://github.com/rsbondi/clightning-dotnet-plugin/tree/9b0e73fa77691a40e3f2a010c8b8bff0deeb861a" rel="noreferrer" target="_blank">https://github.com/rsbondi/clightning-dotnet-plugin/tree/9b0e73fa77691a40e3f2a010c8b8bff0deeb861a</a><br>
> >><br>
> >> This shows in the gifs that in shell I get the responses expected, but<br>
> >> when running clightning and calling commands from the cli, the result<br>
> >> is not as expected<br>
> >><br>
> >> > The JSON you posted got mangled somewhere, i.e., it's missing the<br>
> >> > quotes. I think this might actually be the shell doing random things<br>
> >> > with quotes. And testing with escaping or single-quoting the parameter<br>
> >> > seems to work:<br>
> >><br>
> >> My intention here was only to show that the plugin was registered and<br>
> >> responding to the command, but only on errors(mangled json), not on<br>
> >> valid input `lightning-cli hello fred`.<br>
> >> On Sat, Dec 8, 2018 at 2:38 AM Christian Decker<br>
> >> <<a href="mailto:decker.christian@gmail.com" target="_blank">decker.christian@gmail.com</a>> wrote:<br>
> >> ><br>
> >> > Hi Richard,<br>
> >> ><br>
> >> > the plugins being simple executables that communicate over stdin and<br>
> >> > stdout should be able to be started directly from the shell and you<br>
> >> > should also be able to interact with the from there. So you can try<br>
> >> > starting your plugin and issuing some JSON-RPC requests and see how it<br>
> >> > reacts. For the initialization you should be able to do the following<br>
> >> > (taking the helloworld.py plugin as an example:<br>
> >> ><br>
> >> > ```<br>
> >> > {"jsonrpc":"2.0", "id":1, "method":"getmanifest", "params":[]}<br>
> >> > {"jsonrpc": "2.0", "result": {"options": [{"name": "greeting", "type": "string", "default": "World", "description": "What name should I call you?"}], "rpcmethods": [{"name": "hello", "description": "Returns a personalized greeting for {name}"}, {"name": "fail", "description": "Always returns a failure for testing"}]}, "id": 1}<br>
> >> > ```<br>
> >> ><br>
> >> > The first line is what you send, the second is the reply from the<br>
> >> > plugin. After that you can issue the `init` call:<br>
> >> ><br>
> >> > ```<br>
> >> > {"jsonrpc":"2.0", "id":2, "method":"init", "params": {"options": {"greeting": "Richard"}}}<br>
> >> > {"jsonrpc": "2.0", "result": "ok", "id": 2}<br>
> >> > ```<br>
> >> ><br>
> >> > And from hereon the plugin is registered and can start doing its<br>
> >> > magic.<br>
> >> ><br>
> >> > > When I call the plugin it just hangs. I have tried just ignoring all<br>
> >> > > input and returning the same response as the init and getmanifest,<br>
> >> > > still hangs. It seems the passthrough is taking place, if I put in a<br>
> >> > > command like<br>
> >> ><br>
> >> > This could have something to do with buffering, since some languages<br>
> >> > will buffer output. Notice that the python3 plugin always adds newlines<br>
> >> > and flushes to make sure it clears buffers. Not sure how the situation<br>
> >> > is with C#, but python2 was acting up as well.<br>
> >> ><br>
> >> > > cli/lightning-cli hello {"greeting":"fred"}<br>
> >> > ><br>
> >> > > I get a response<br>
> >> > ><br>
> >> > > Invalid token in json input: '{ "method" : "hello", "id" :<br>
> >> > > "lightning-cli-25109", "params" : [ {greeting:fred}] }'<br>
> >> > ><br>
> >> > > which make sense, if I do an echo passing the same json I get the<br>
> >> > > broken json<br>
> >> ><br>
> >> ><br>
> >> > The JSON you posted got mangled somewhere, i.e., it's missing the<br>
> >> > quotes. I think this might actually be the shell doing random things<br>
> >> > with quotes. And testing with escaping or single-quoting the parameter<br>
> >> > seems to work:<br>
> >> ><br>
> >> > ```<br>
> >> > lightning-cli hello '{"greeting":"fred"}'<br>
> >> > "Hello {'greeting': 'fred'}"<br>
> >> > ```<br>
> >> ><br>
> >> > > what I expect to happen is, when I type in<br>
> >> > ><br>
> >> > > cli/lightning-cli hello fred<br>
> >> > ><br>
> >> > > I expect my message with "fred" substituted in or I expect the command<br>
> >> > > that I look for in code to be<br>
> >> > ><br>
> >> > > { "method" : "hello", "id" : "lightning-cli-25109", "params" : ["fred"] }<br>
> >> ><br>
> >> > The reason you get the full quoted text back is because `lightning-cli`<br>
> >> > takes that first argument (the JSON serialized object) and passes it in<br>
> >> > as the first positional parameter, and doesn't use the entire object as<br>
> >> > the params (i.e., it doesn't unpack). So to get `Hello fred` you'd have<br>
> >> > to run `lightning-cli hello fred` instead.<br>
> >> ><br>
> >> > > The other issue is when I try to do in go, it seems to call<br>
> >> > > `plugin_read_json_one` more than once for the same plugin's<br>
> >> > > getmanifest and I get the "Received a JSON-RPC response for<br>
> >> > > non-existent request" error. It seems to have the same buffer value,<br>
> >> > > but no request. I have gone as far in my code to remove getmanifest<br>
> >> > > from the map so there is no way it could erroneously send the request<br>
> >> > > a second time.<br>
> >> ><br>
> >> > This could happen in a couple of different ways: the plugin code issues<br>
> >> > the request twice (this would be a lightningd bug), the plugin responds<br>
> >> > multiple times (bug in the plugin), the plugin code doesn't clear the<br>
> >> > buffer inbetween responses (lightningd issue).<br>
> >> ><br>
> >> > We can easily eliminate the second case by running the plugin from the<br>
> >> > command line like explained above, and go from there.<br>
> >> ><br>
> >> > HTH,<br>
> >> > Christian<br>
> > --<br>
> > c-lightning mailing list<br>
> > <a href="mailto:c-lightning@lists.ozlabs.org" target="_blank">c-lightning@lists.ozlabs.org</a><br>
> > <a href="https://lists.ozlabs.org/listinfo/c-lightning" rel="noreferrer" target="_blank">https://lists.ozlabs.org/listinfo/c-lightning</a><br>
</blockquote></div>