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 improvements #7750

Merged

Conversation

rustyrussell
Copy link
Contributor

This changes libplugin to always have (and require!) a non-NULL struct command context for operations. This is usually easy, but required some work for pay, which didn't pass the command_result codes though.

Also, a driveby fix for pay debug logs (not everything is command 34!).

@rustyrussell rustyrussell added this to the v24.11 milestone Oct 18, 2024
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch 2 times, most recently from 392bc7f to c765ab8 Compare October 22, 2024 00:03
plugins/recover.c Outdated Show resolved Hide resolved
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch from c765ab8 to 8a7cee5 Compare November 1, 2024 02:58
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch 3 times, most recently from 35b3aee to f63de5e Compare November 3, 2024 10:54
@ShahanaFarooqui ShahanaFarooqui force-pushed the libplugin-improvements branch 9 times, most recently from 7fdfe72 to f63de5e Compare November 5, 2024 00:12
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch from f63de5e to 36c9bce Compare November 6, 2024 03:24
And fix the fallout!

Signed-off-by: Rusty Russell <[email protected]>
Sometimes we want to clean up *after* a command has completed, but
we're moving to a model where all libplugin operations require a
`struct command`.  This adds `aux_command` to create an
independent-lifetime command with the same id.

Signed-off-by: Rusty Russell <[email protected]>
We didn't set this previously when it was a notification.

Signed-off-by: Rusty Russell <[email protected]>
This is clearer than the previous "two booleans".

Signed-off-by: Rusty Russell <[email protected]>
This is cleaner: everything can now be associated with a command
context.

You're supposed to eventually dispose of it using timer_complete().

Signed-off-by: Rusty Russell <[email protected]>
All `struct command` should be terminated properly.

Signed-off-by: Rusty Russell <[email protected]>
This does not code changes, but makes the next changes easier.

We short-cut the "we are a child" case and de-indent the main
cases.

Signed-off-by: Rusty Russell <[email protected]>
This means we replace p->cmd with an auxillary command after we've
finished, so we have a valid command to use.

It also means we weave `struct command_result` returns back through
all the callers.

Signed-off-by: Rusty Russell <[email protected]>
We were dereferencing the first character of the id, (always '"') which meant
everything was id 34.

Before:
	plugin-pay: cmd 34 partid 5

After:
	cmd pytest:pay#62/cln:pay#105 partid 0

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: `pay`: debug logging now uses correct JSON ids.
And remove command_done() which was used when there was no
cmd.

Signed-off-by: Rusty Russell <[email protected]>
When we used to allow cmd to be NULL, we had to hand the plugin
everywhere.  We no longer do.

1. Various jsonrpc_ functions no longer need the plugin arg.
2. send_outreq no longer needs a plugin arg.
3. The init function takes a command, not a plugin.
4. Remove command_deprecated_in_nocmd_ok.

Signed-off-by: Rusty Russell <[email protected]>
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch from 36c9bce to d906205 Compare November 6, 2024 11:15
This avoids jsonrpc_request_start() double-evaluating its cmd arg.

Signed-off-by: Rusty Russell <[email protected]>
…helpers.

Without knowing what method was called, we can't have useful general logging
methods, so go through the pain of adding "const char *method" everywhere,
and add:

1. ignore_and_complete - we're done when jsonrpc returned
2. log_broken_and_complete - we're done, but emit BROKEN log.
3. plugin_broken_cb - if this happens, fail the plugin.

Signed-off-by: Rusty Russell <[email protected]>
…command hook.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: libplugin: plugins can now intercept `rpc_command` hook without deadlocking.
On `dev-memleak`, if someone is using rpc_command_hook, we'll call
it when the hook returns.  But it will see these contexts as a leak.

So attach them to tmpctx (which is excluded from leak detection).

Signed-off-by: Rusty Russell <[email protected]>
@rustyrussell rustyrussell force-pushed the libplugin-improvements branch from d906205 to 0b5f37d Compare November 7, 2024 01:27
@rustyrussell rustyrussell merged commit bfc00bc into ElementsProject:master Nov 7, 2024
44 checks passed
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