-
Notifications
You must be signed in to change notification settings - Fork 895
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
Libplugin refactoring #3443
Libplugin refactoring #3443
Conversation
7c475b4
to
d56c7f8
Compare
d56c7f8
to
cf6a1de
Compare
Rebased (and added a1857df for errcodes). |
cf6a1de
to
aa0ff6b
Compare
Re-rebased |
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.
Oops, just realized I didn't hit submit on my review from last week. Just minor stuff...
static struct timers timers; | ||
static size_t in_timer; | ||
|
||
bool deprecated_apis; |
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.
deprecated_apis
is kinda special, I'd be tempted to leave it as a global...
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.
But the plugin
is accessible everywhere ?
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.
- The core code also uses a global, so codesharing is easier this way.
- Without this, the definition of struct plugin doesn't need to be exposed.
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.
Ok, will do tomorrow
I did the change about |
aa0ff6b
to
1a7d3c7
Compare
It's not lightningd-specific and we are going to need it for libplugin. The only drawback is the log_io removal in json_stream_output_write()..
Now that we have json_stream in common/, we can move all the related helpers from lightningd/json to common/json. This way everyone can benefit of them (including libplugin, the plugins themselves, potentially lightning-cli), not lightningd alone! Note that the Makefile of the common/test/ had to be modified, because the new helpers make use of common/wireaddr... Which turns out to \#include <lightingd/lightningd.h> ! So we couldnt just include the .c and add mocks if we redefined some structs (hello run-param).
Having a global object is very handy to pass to `io_plan`s, which would have otherwise required a whole bunch of new globals.
Now we have streams and a global object, we can use them for io_plans. This makes the logic closer from lightningd/plugin (it has been mostly stolen from here), and simplifies the main. This also allows plugins to use io_plans (thanks to the io_loop) for asynchronous connections. This commit only handle incoming commands.
This pass to json_stream helpers for commands outputs, but keeps compatibility with existing plugins which use jout as of now, by not starting/closing the "result"/"error" objects.
And rename the struct name, as it's now only used for RPC.
But not the outreqs helpers, which will be moved when passing send_outreq_ to using ccan/io.
autoclean needs to send outreqs from a timer cb, hence with cmd == NULL.
Trivial rebase on master for test autogen conflicts... |
1a7d3c7
to
4a296b3
Compare
Thanks ! |
In order to correctly (i.e. not loose asynchronicity) implement #3354 I needed libplugin to use
ccan/io
. This escalated quickly to a complete refactoring oflibplugin
.This PR:
json_stream.h
and its corresponding helpers tocommon/
, which was required to properly implementio_plan
s, and which seems generally good as it now allows plugins to use higher-level JSON helpers as inlightningd/*
.stdin
/stdout
plugin connections use exclusivelyio_plan
s which simplifies theplugin_main
and keeps the same logic as the other side:lightningd/plugin
.send_outreq
) useio_plan
s, which I believe could help with Concurrency in libplugin #3401 though I haven't tested it yet. However I'm happy to revert this patch if that clashes with @ZmnSCPxj work with sparks.plugin
.Left for another PR:
Move existing plugins to useDone in libplugin: use json stream helpers and add sanity tests #3480json_stream
helpers instead of "raw"jout
srpc_delve
and co.) ?Changelog-None