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

feat: restructure plugin and options in listconfigs #3206 #3283

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

m-schmoock
Copy link
Collaborator

@m-schmoock m-schmoock commented Nov 21, 2019

Addresses #3206 and #3281

This will restructure the lightning-cli listconfigs output in a way that plugins are not duplicated and have their options within a substructure like this:

{
   "# version": "v0.7.3-141-gabdc4af",
   "lightning-dir": "/home/will/.lightning",
   "wallet": "sqlite3:///home/will/.lightning/lightningd.sqlite3",
   "plugins": [
      {
         "name": "autoclean",
         "path": "/home/will/projects/lightning.git/lightningd/../plugins/autoclean",
         "options": {
            "autocleaninvoice-cycle": null,
            "autocleaninvoice-expired-by": null
         }
      },
      {
         "name": "fundchannel",
         "path": "/home/will/projects/lightning.git/lightningd/../plugins/fundchannel"
      },
      {
         "name": "pay",
         "path": "/home/will/projects/lightning.git/lightningd/../plugins/pay"
      },
      {
         "name": "sendinvoiceless.py",
         "path": "/home/will/.lightning/plugins/sendinvoiceless/sendinvoiceless.py",
         "options": {
            "cltv-final": "10",
            "fee-base": "null",
            "fee-per-satoshi": "null"
         }
      },
      {
         "name": "rebalance.py",
         "path": "/home/will/.lightning/plugins/rebalance/rebalance.py",
         "options": {
            "cltv-final": "10"
         }
      },
      {
         "name": "summary.py",
         "path": "/home/will/.lightning/plugins/summary/summary.py",
         "options": {
            "summary-currency": "USD",
            "summary-currency-prefix": "USD $"
         }
      },
      {
         "name": "drain.py",
         "path": "/home/will/.lightning/plugins/drain/drain.py",
         "options": {
            "cltv-final": "10"
         }
      }
   ],
   "network": "testnet",
   "allow-deprecated-apis": false,
   "..." : "..."
}

@m-schmoock
Copy link
Collaborator Author

We could think about add a "name" feature to a plugin so we dont have to use the long command path-name as key...

@cdecker cdecker self-assigned this Nov 21, 2019
@m-schmoock
Copy link
Collaborator Author

@cdecker how about adding a "name" to the plugin interface. For all the old plugins we guess the name by inspecting the commands paths lasts elements:

  • if directory, take submost directory name
  • if filename, take this name and remove extensions like '.py' and such

If we do this we can make this nicely without update all the plugins first...

lightningd/plugin.c Outdated Show resolved Hide resolved
@cdecker
Copy link
Member

cdecker commented Nov 21, 2019

@cdecker how about adding a "name" to the plugin interface. For all the old plugins we guess the name by inspecting the commands paths lasts elements:

  • if directory, take submost directory name
  • if filename, take this name and remove extensions like '.py' and such

If we do this we can make this nicely without update all the plugins first...

I think this is a great idea, though we should also still display the path somewhere so we have a mapping between the file being executed and the (self-assigned) alias.

@m-schmoock
Copy link
Collaborator Author

We can address the dedicated plugin naming to a separate pull request...

@m-schmoock m-schmoock force-pushed the feat/listconfigs_plugins branch 2 times, most recently from 55c5249 to 2973862 Compare November 21, 2019 20:47
Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

Awesome! Needs a Changelog-Deprecated note for changing how the JSON prints though :)

lightningd/plugin.c Outdated Show resolved Hide resolved
lightningd/plugin.c Outdated Show resolved Hide resolved
lightningd/plugin.c Outdated Show resolved Hide resolved
lightningd/plugin.c Show resolved Hide resolved
@m-schmoock m-schmoock force-pushed the feat/listconfigs_plugins branch 2 times, most recently from a5cbdc2 to abdc4af Compare November 22, 2019 11:34
@m-schmoock
Copy link
Collaborator Author

m-schmoock commented Nov 22, 2019

I wonder if we can improve on the yet untyped/null values, what are those, date/times?:

            "autocleaninvoice-cycle": null,
            "autocleaninvoice-expired-by": null

From a code perspective autocleaninvoice-cycle is a u64, so should be possible to output this as json int, autocleaninvoice-expired-by should be a string, but the code that checks the type of that option does not return it as string. Seems like if (opt->value->as_str) and if (opt->value->as_int) does not work here.

Update: seems like those values are C NULL values, however for other python plugins add_option('some_name', None, 'some description') gives you a string "null", the latter one is the problem, for example sendinvoiceless reports an unset 'integer' value as "fee-base": "null", which is wrong in three ways:

  • it actually holds a non-null runtime value
  • the type should be integer
  • if it would really be null it should not be reported as a string containing the 4 letters "null".

Open Questions:

  • How do we handle python plugin parameters more correctly that are None or non-string types?
  • Can the C code reflect the current (runtime) value of a plugins options? It seems to me that the current way only outputs the plugins default values ("fee-per-satoshi": "null" should no be null, as the value is set in plugins init() method.)
  • Currently some plugins (i.e. mine and @gallizoltan ) are using values that should be taken from clightningd directly instead of redefining a runtime copy of them :D

We could/should address these problems in another PR...

Copy link
Collaborator

@darosior darosior left a comment

Choose a reason for hiding this comment

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

ACK 82ef5f5

I have some nits (ah and the commit message is wrong (_cmd)) about the code, but the interface is much cleaner that way !
I think too that this "null" fields should be fixed as part of another PR.

I wonder if we can improve on the yet untyped/null values, what are those, date/times?:

I think having null values is OK. Don't forget that's Javascript Object Notation so the typing is ... You know.... :D

How do we handle python plugin parameters more correctly that are None or non-string types?

By setting them to null Pylightning side ?..

Can the C code reflect the current (runtime) value of a plugins options? It seems to me that the current way only outputs the plugins default values ("fee-per-satoshi": "null" should no be null, as the value is set in plugins init() method.)

Shouldn't be set as a default instead of at init() ? Or even add a method to set it, but I don't think a startup option is meant to be set at runtime.

lightningd/plugin.c Outdated Show resolved Hide resolved
lightningd/plugin.c Outdated Show resolved Hide resolved
lightningd/plugin.c Outdated Show resolved Hide resolved
@m-schmoock m-schmoock force-pushed the feat/listconfigs_plugins branch 2 times, most recently from 6ebcde6 to 5c48e1b Compare November 23, 2019 18:35
@m-schmoock
Copy link
Collaborator Author

m-schmoock commented Nov 23, 2019

Okay, lets use the basename including extension for now until plugin can set their name properly.
Parameter type binding and naming can be addressed later as we all seem to agree.

This will change the command `listconfigs` output in several ways:

 - Deprecated the duplicated "plugin" JSON output by replacing it with
 - a "plugins" array with substructures for each plugin with:
 - path, name and their options

Changelog-Changed: JSON-RPC: `listconfigs` now structures plugins and include their options
Changelog-Deprecated: JSON-RPC: `listconfigs` duplicated "plugin" paths
@darosior
Copy link
Collaborator

ACK 02059ee

@darosior
Copy link
Collaborator

@m-schmoock Regarding

How do we handle python plugin parameters more correctly that are None or non-string types?

By setting them to null Pylightning side ?..

I gave a quick look to pyln and they seem to actually be set to null :

def _write_locked(self, obj):
# ensure_ascii turns UTF-8 into \uXXXX so we need to suppress that,
# then utf8 ourselves.
s = bytes(json.dumps(obj, cls=LightningRpc.LightningJSONEncoder, ensure_ascii=False) + "\n\n", encoding='utf-8')
...

@cdecker cdecker dismissed niftynei’s stale review November 25, 2019 17:14

Seems to have been addressed.

@cdecker cdecker merged commit 6ed3201 into ElementsProject:master Nov 25, 2019
@m-schmoock m-schmoock deleted the feat/listconfigs_plugins branch November 28, 2019 10:27
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.

None yet

4 participants