mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 15:04:19 +01:00
lightningd: figure out optimal channel *before* forward_htlc hook.
Otherwise what the hook sees is actually a lie, and if it sets it we might override it. The side effect is that we add an explicit "forward_to" field, and allow hooks to override it. This lets a *hook* control channel choice explicitly. Changelod-Added: Plugins: `htlc_accepted_hook` return can specify what channel to forward htlc to. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
b698a5a5ef
commit
6e86fa9220
31
tests/plugins/htlc_accepted-fwdto.py
Executable file
31
tests/plugins/htlc_accepted-fwdto.py
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
"""A plugin that tells us to forward HTLCs to a specific channel.
|
||||
|
||||
"""
|
||||
from pyln.client import Plugin
|
||||
|
||||
|
||||
plugin = Plugin()
|
||||
|
||||
|
||||
@plugin.hook("htlc_accepted")
|
||||
def on_htlc_accepted(htlc, onion, plugin, **kwargs):
|
||||
if plugin.fwdto is None:
|
||||
return {"result": "continue"}
|
||||
|
||||
return {"result": "continue", "forward_to": plugin.fwdto}
|
||||
|
||||
|
||||
@plugin.method("setfwdto")
|
||||
def setfailonion(plugin, fwdto):
|
||||
"""Sets the channel_id to forward to when receiving an incoming HTLC.
|
||||
"""
|
||||
plugin.fwdto = fwdto
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def on_init(**kwargs):
|
||||
plugin.fwdto = None
|
||||
|
||||
|
||||
plugin.run()
|
||||
Reference in New Issue
Block a user