Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pay listpeerchannels fix #7235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -2113,11 +2113,6 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,

chan = tal(ctx, struct listpeers_channel);

json_to_node_id(buffer, idtok, &chan->id);
json_to_bool(buffer, conntok, &chan->connected);
json_to_bool(buffer, privtok, &chan->private);
chan->state = json_strdup(chan, buffer, statetok);
json_to_txid(buffer, ftxidtok, &chan->funding_txid);
if (scidtok != NULL) {
assert(dirtok != NULL);
chan->scid = tal(chan, struct short_channel_id);
Expand Down Expand Up @@ -2154,6 +2149,12 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
if (!chan->scid && !chan->alias[LOCAL])
return tal_free(chan);

json_to_node_id(buffer, idtok, &chan->id);
json_to_bool(buffer, conntok, &chan->connected);
json_to_bool(buffer, privtok, &chan->private);
chan->state = json_strdup(chan, buffer, statetok);
json_to_txid(buffer, ftxidtok, &chan->funding_txid);

json_to_int(buffer, dirtok, &chan->direction);
json_to_msat(buffer, tmsattok, &chan->total_msat);
json_to_msat(buffer, smsattok, &chan->spendable_msat);
Expand Down
32 changes: 32 additions & 0 deletions tests/plugins/openchannel_hook_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""Plugin to test openchannel_hook

Will simply accept any channel. Useful fot testing chained hook.
"""

from pyln.client import Plugin
import time

plugin = Plugin()


@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin, **kwargs):
delaytime = float(plugin.get_option('delaytime'))
msg = f'delaying WIRE_ACCEPT_CHANNEL for {delaytime}s'
plugin.log(msg)
time.sleep(delaytime)
return {'result': 'continue'}


@plugin.hook('openchannel2')
def on_openchannel2(openchannel2, plugin, **kwargs):
delaytime = float(plugin.get_option('delaytime'))
msg = f'delaying WIRE_ACCEPT_CHANNEL for {delaytime}s'
plugin.log(msg)
time.sleep(delaytime)
return {'result': 'continue'}


plugin.add_option('delaytime', '10', 'How long to hold the WIRE_OPEN_CHANNEL.')
plugin.run()
16 changes: 16 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5588,3 +5588,19 @@ def test_pay_partial_msat(node_factory, executor):

l1pay.result(TIMEOUT)
l3pay.result(TIMEOUT)


def test_pay_while_opening_channel(node_factory, bitcoind, executor):
delay_plugin = {'plugin': os.path.join(os.getcwd(),
'tests/plugins/openchannel_hook_delay.py'),
'delaytime': '10'}
l1, l2 = node_factory.line_graph(2, fundamount=10**6, wait_for_announce=True)
l3 = node_factory.get_node(options=delay_plugin)
l1.connect(l3)
executor.submit(l1.rpc.fundchannel, l3.info['id'], 100000)
wait_for(lambda: l1.rpc.listpeerchannels(l3.info['id'])['channels'] != [])

# the uncommitted channel should now show up in listpeerchannels
assert only_one(l1.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'OPENINGD'
inv = l2.rpc.invoice(10000, "inv", "inv")
l1.rpc.pay(inv['bolt11'])
Loading