pylightning: Warn users of plugins that may break due to extra args

We recently noticed that the way we unpack the call arguments for hooks and
notifications in pylightning breaks pretty quickly once you start changing the
hook and notification params. If you add params they will not get mapped
correctly causing the plugin to error out.

This can be fixed by adding a `VAR_KEYWORD` argument to the calbacks, i.e., by
adding a single `**kwargs` argument at the end of the signature. This commit
adds a check that such a catch-all argument exists, and emits a warning if it
doesn't.

It also fixes up the plugins that we ship ourselves.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2019-08-05 02:19:48 +02:00
committed by Rusty Russell
parent e808aaa1bb
commit 9d4148ce68
11 changed files with 40 additions and 14 deletions

View File

@@ -20,22 +20,22 @@ def hello(plugin, name="world"):
@plugin.init()
def init(options, configuration, plugin):
def init(options, configuration, plugin, **kwargs):
plugin.log("Plugin helloworld.py initialized")
@plugin.subscribe("connect")
def on_connect(plugin, id, address):
def on_connect(plugin, id, address, **kwargs):
plugin.log("Received connect event for peer {}".format(id))
@plugin.subscribe("disconnect")
def on_disconnect(plugin, id):
def on_disconnect(plugin, id, **kwargs):
plugin.log("Received disconnect event for peer {}".format(id))
@plugin.subscribe("invoice_payment")
def on_payment(plugin, invoice_payment):
def on_payment(plugin, invoice_payment, **kwargs):
plugin.log("Received invoice_payment event for label {}, preimage {},"
" and amount of {}".format(invoice_payment.get("label"),
invoice_payment.get("preimage"),
@@ -43,7 +43,7 @@ def on_payment(plugin, invoice_payment):
@plugin.hook("htlc_accepted")
def on_htlc_accepted(onion, htlc, plugin):
def on_htlc_accepted(onion, htlc, plugin, **kwargs):
plugin.log('on_htlc_accepted called')
time.sleep(20)
return {'result': 'continue'}