forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhold_htlcs.py
executable file
·55 lines (40 loc) · 1.25 KB
/
hold_htlcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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 pyln.client 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 {hold_time} seconds".format(
hold_time=plugin.hold_time
))
time.sleep(plugin.hold_time)
print("Onion written to {}".format(fname))
# Give the tester something to look for
plugin.log("htlc_accepted hook called")
return {'result': plugin.hold_result}
plugin.add_option(
'hold-time', 10,
'How long should we hold on to HTLCs?',
opt_type='int'
)
plugin.add_option(
'hold-result',
'continue', 'How should we continue after holding?',
)
@plugin.init()
def init(options, configuration, plugin):
plugin.log("hold_htlcs.py initializing")
plugin.hold_time = options['hold-time']
plugin.hold_result = options['hold-result']
plugin.run()