Skip to content

lightningd: accept options array in plugin start - #9391

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:plugin-options-obj
Open

lightningd: accept options array in plugin start#9391
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:plugin-options-obj

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

The plugin start command only accepted plugin options flattened onto the RPC call (e.g. via -k/--keyword), but the plugin RPC schema documents an explicit 'options' array. This mismatch meant that callers using named parameters against generated RPC bindings (cln-rpc, grpc, protobuf), which cannot flatten arbitrary options, failed with 'unknown parameter options'.

Handle 'options' as an array of keyword=value strings, merging them with any flattened extra parameters before passing them to plugin_add_params(). Options without a value are treated as boolean flags, matching the flattened form.

Changelog-Fixed: JSON-RPC: plugin start now accepts plugin options as an options array of keyword=value strings, as documented in the plugin schema.

Fixes: #9171

Important

26.09 FREEZE August 5th: Non-bugfix PRs not ready by this date will wait for 26.12.

RC1 is scheduled on August 17th

The final release is scheduled for September 7th.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

@daywalker90
daywalker90 requested a review from cdecker as a code owner August 7, 2026 14:07
@daywalker90 daywalker90 added the Status::Ready for Review The work has been completed and is now awaiting evaluation or approval. label Aug 7, 2026
Andezion
Andezion previously approved these changes Aug 11, 2026

@Andezion Andezion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The main feature solves the reported problem (#9171): buffer/token ownership is handled carefully, and the merge logic reuses existing JSON helpers appropriately!!

* of "keyword=value" strings. This merges both forms into a single JSON
* object of name/value pairs, suitable for plugin_add_params(). An element
* without an '=' is treated as a boolean flag. */
static jsmntok_t *plugin_start_params(const tal_t *ctx, const char *buffer,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!! As i understood when plugin_start_params() builds a new json string (mod_buffer), the code always threads mod_buffer through to plugin_dynamic_start() instead of the original buffer. Using the original buffer with fresh synthesized token offsets would have caused out-of-bounds reads

Comment thread lightningd/plugin_control.c Outdated
* since plugin options must be explicitly named!). */
if (params->type == JSMN_ARRAY) {
if (params->size != 2)
if (params->size > 2 && !options)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the intent of params->size > 2 && !options really just "reject a null in the options slot", or was it meant to also reject trailing garbage after a valid options array in a positional call?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was also meant to reject trailing stuff loudly... fixed.

return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Extra parameters must be in object");
mod_params = NULL;
if (options) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should options array elements be required to be JSON strings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, per the schema, fixed.

The plugin start command only accepted plugin options flattened onto
the RPC call (e.g. via -k/--keyword), but the plugin RPC schema
documents an explicit 'options' array.  This mismatch meant that callers
using named parameters against generated RPC bindings (cln-rpc, grpc,
protobuf), which cannot flatten arbitrary options, failed with
'unknown parameter options'.

Options without a value are treated as boolean flags, matching the
flattened form.

Changelog-Fixed: JSON-RPC: `plugin start` now accepts plugin options as an `options` array of `keyword=value` strings, as documented in the `plugin` schema.
@daywalker90

Copy link
Copy Markdown
Collaborator Author

I reworked the PR to be more strict about mixing stuff. I don't think there is a legit use case to mix flattened AND explicit options array at the same time so i rather reject it. I extended the test with all option types and cases of mixed option passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status::Ready for Review The work has been completed and is now awaiting evaluation or approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin command's options argument expecting flattened options causes problem in generated rust/protobuf code

2 participants