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:
Rusty Russell
2022-09-25 22:44:12 +09:30
committed by Christian Decker
parent b698a5a5ef
commit 6e86fa9220
7 changed files with 178 additions and 47 deletions

View File

@@ -1722,14 +1722,22 @@ def test_zeroconf_multichan_forward(node_factory):
# Now create a channel that is twice as large as the real channel,
# and don't announce it.
l2.fundwallet(10**7)
l2.rpc.fundchannel(l3.info['id'], 2 * 10**6, mindepth=0)
zeroconf_cid = l2.rpc.fundchannel(l3.info['id'], 2 * 10**6, mindepth=0)['channel_id']
l2.daemon.wait_for_log(r'peer_in WIRE_CHANNEL_READY')
l3.daemon.wait_for_log(r'peer_in WIRE_CHANNEL_READY')
inv = l3.rpc.invoice(amount_msat=10000, label='lbl1', description='desc')['bolt11']
l1.rpc.pay(inv)
assert l2.daemon.is_in_log(r'Chose a better channel: .*')
for c in only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels']:
if c['channel_id'] == zeroconf_cid:
zeroconf_scid = c['alias']['local']
else:
normal_scid = c['short_channel_id']
assert l2.daemon.is_in_log(r'Chose a better channel than {}: {}'
.format(normal_scid, zeroconf_scid))
def test_zeroreserve(node_factory, bitcoind):