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

Libplugin refactoring #3443

Merged
merged 12 commits into from
Feb 4, 2020
Merged

Conversation

darosior
Copy link
Collaborator

@darosior darosior commented Jan 27, 2020

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 of libplugin.

This PR:

  • Moves json_stream.h and its corresponding helpers to common/, which was required to properly implement io_plans, and which seems generally good as it now allows plugins to use higher-level JSON helpers as in lightningd/*.
  • Makes stdin / stdout plugin connections use exclusively io_plans which simplifies the plugin_main and keeps the same logic as the other side: lightningd/plugin.
  • Makes async RPC requests (send_outreq) use io_plans, 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.
  • Overall removes globals in favor of a top-level struct, creatively named plugin.

Left for another PR:

Changelog-None

@cdecker cdecker requested review from rustyrussell and cdecker and removed request for rustyrussell January 27, 2020 11:39
@darosior darosior force-pushed the libplugin_io_plan branch 4 times, most recently from 7c475b4 to d56c7f8 Compare January 27, 2020 22:03
@darosior darosior marked this pull request as ready for review January 27, 2020 23:27
@darosior
Copy link
Collaborator Author

darosior commented Feb 1, 2020

Rebased (and added a1857df for errcodes).

@darosior
Copy link
Collaborator Author

darosior commented Feb 2, 2020

Re-rebased

Copy link
Contributor

@rustyrussell rustyrussell left a 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...

plugins/libplugin.h Outdated Show resolved Hide resolved
static struct timers timers;
static size_t in_timer;

bool deprecated_apis;
Copy link
Contributor

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...

Copy link
Collaborator Author

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The core code also uses a global, so codesharing is easier this way.
  2. Without this, the definition of struct plugin doesn't need to be exposed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, will do tomorrow

plugins/libplugin.c Outdated Show resolved Hide resolved
@darosior
Copy link
Collaborator Author

darosior commented Feb 3, 2020

I did the change about rpc_conn in a new top-commit, if that's ok it avoids me 3 conflicting rebases (this branch, #3480, and the Bitcoin backend plugin's branch).

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.
@rustyrussell
Copy link
Contributor

Trivial rebase on master for test autogen conflicts...

@darosior
Copy link
Collaborator Author

darosior commented Feb 4, 2020

Thanks !

@rustyrussell rustyrussell added this to the 0.8.1 milestone Feb 4, 2020
@rustyrussell rustyrussell merged commit 02fe34e into ElementsProject:master Feb 4, 2020
@darosior darosior deleted the libplugin_io_plan branch February 8, 2020 17:09
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