mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-12-29 10:04:41 +01:00
9d4148ce68
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>
38 lines
796 B
Python
Executable File
38 lines
796 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Plugin that holds on to HTLCs for 10 seconds.
|
|
|
|
Used to test restarts / crashes while HTLCs were accepted, but not yet
|
|
settled/forwarded/
|
|
|
|
"""
|
|
|
|
|
|
from lightning import Plugin
|
|
import json
|
|
import os
|
|
import tempfile
|
|
import time
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
@plugin.hook("htlc_accepted")
|
|
def on_htlc_accepted(htlc, onion, plugin, **kwargs):
|
|
# Stash the onion so the test can check it
|
|
fname = os.path.join(tempfile.mkdtemp(), "onion.json")
|
|
with open(fname, 'w') as f:
|
|
f.write(json.dumps(onion))
|
|
|
|
plugin.log("Holding onto an incoming htlc for 10 seconds")
|
|
|
|
time.sleep(10)
|
|
|
|
print("Onion written to {}".format(fname))
|
|
|
|
# Give the tester something to look for
|
|
plugin.log("htlc_accepted hook called")
|
|
return {'result': 'continue'}
|
|
|
|
|
|
plugin.run()
|