Skip to content

Commit 871d8c6

Browse files
committed
lightningd: add channel_type to openchannel & openchannel2 hooks.
An obvious omission! Changelog-Added: Plugins: `openchannel` and `openchannel2` hooks now expose the `channel_type` field for the offered channel. Signed-off-by: Rusty Russell <[email protected]>
1 parent c602a8a commit 871d8c6

File tree

9 files changed

+31
-8
lines changed

9 files changed

+31
-8
lines changed

doc/developers-guide/plugin-development/hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ This hook is called whenever a remote peer tries to fund a channel to us using t
245245
"to_self_delay": 5,
246246
"max_accepted_htlcs": 483,
247247
"channel_flags": 1,
248+
"channel_type": {'bits': [12, 22], 'names': ['static_remotekey/even', 'anchors/even']},
248249
"locktime": 2453,
249250
"channel_max_msat": 16777215000,
250251
"requested_lease_msat": 100000000,

lightningd/dual_open_control.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct openchannel2_payload {
274274
u32 lease_blockheight_start;
275275
u32 node_blockheight;
276276
bool req_confirmed_ins_remote;
277+
struct channel_type *channel_type;
277278

278279
struct amount_sat accepter_funding;
279280
struct wally_psbt *psbt;
@@ -325,6 +326,7 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload,
325326
}
326327
json_add_bool(stream, "require_confirmed_inputs",
327328
payload->req_confirmed_ins_remote);
329+
json_add_channel_type(stream, "channel_type", payload->channel_type);
328330
json_object_end(stream);
329331
}
330332

@@ -2098,7 +2100,8 @@ static void accepter_got_offer(struct subd *dualopend,
20982100
&payload->shutdown_scriptpubkey,
20992101
&payload->requested_lease_amt,
21002102
&payload->lease_blockheight_start,
2101-
&payload->req_confirmed_ins_remote)) {
2103+
&payload->req_confirmed_ins_remote,
2104+
&payload->channel_type)) {
21022105
channel_internal_error(channel, "Bad DUALOPEND_GOT_OFFER: %s",
21032106
tal_hex(tmpctx, msg));
21042107
return;

lightningd/opening_control.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ struct openchannel_hook_payload {
647647
u8 channel_flags;
648648
u8 *shutdown_scriptpubkey;
649649
const u8 *our_upfront_shutdown_script;
650+
struct channel_type *channel_type;
650651
char *errmsg;
651652
};
652653

@@ -675,6 +676,7 @@ static void openchannel_hook_serialize(struct openchannel_hook_payload *payload,
675676
if (tal_count(payload->shutdown_scriptpubkey) != 0)
676677
json_add_hex_talarr(stream, "shutdown_scriptpubkey",
677678
payload->shutdown_scriptpubkey);
679+
json_add_channel_type(stream, "channel_type", payload->channel_type);
678680
json_object_end(stream); /* .openchannel */
679681
}
680682

@@ -854,7 +856,8 @@ static void opening_got_offer(struct subd *openingd,
854856
&payload->to_self_delay,
855857
&payload->max_accepted_htlcs,
856858
&payload->channel_flags,
857-
&payload->shutdown_scriptpubkey)) {
859+
&payload->shutdown_scriptpubkey,
860+
&payload->channel_type)) {
858861
log_broken(openingd->log, "Malformed opening_got_offer %s",
859862
tal_hex(tmpctx, msg));
860863
tal_free(openingd);

openingd/dualopend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,8 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
25282528
state->upfront_shutdown_script[REMOTE],
25292529
state->requested_lease,
25302530
tx_state->blockheight,
2531-
state->require_confirmed_inputs[REMOTE]);
2531+
state->require_confirmed_inputs[REMOTE],
2532+
state->channel_type);
25322533

25332534
wire_sync_write(REQ_FD, take(msg));
25342535
msg = wire_sync_read(tmpctx, REQ_FD);

openingd/dualopend_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ msgdata,dualopend_got_offer,shutdown_scriptpubkey,u8,shutdown_len
9898
msgdata,dualopend_got_offer,requested_amt,?amount_sat,
9999
msgdata,dualopend_got_offer,lease_blockheight_start,u32,
100100
msgdata,dualopend_got_offer,require_confirmed_inputs,bool,
101+
msgdata,dualopend_got_offer,ctype,channel_type,
101102

102103
# master->dualopend: reply back with our first funding info/contribs
103104
msgtype,dualopend_got_offer_reply,7105

openingd/openingd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
10091009
state->remoteconf.to_self_delay,
10101010
state->remoteconf.max_accepted_htlcs,
10111011
channel_flags,
1012-
state->upfront_shutdown_script[REMOTE]);
1012+
state->upfront_shutdown_script[REMOTE],
1013+
state->channel_type);
10131014
wire_sync_write(REQ_FD, take(msg));
10141015
msg = wire_sync_read(tmpctx, REQ_FD);
10151016

openingd/openingd_wire.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ msgdata,openingd_got_offer,max_accepted_htlcs,u16,
4444
msgdata,openingd_got_offer,channel_flags,u8,
4545
msgdata,openingd_got_offer,shutdown_len,u16,
4646
msgdata,openingd_got_offer,shutdown_scriptpubkey,u8,shutdown_len
47+
msgdata,openingd_got_offer,ctype,channel_type,
4748

4849
# master->openingd: optional rejection message
4950
msgtype,openingd_got_offer_reply,6105

tests/plugins/openchannel_hook_accepter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
plugin = Plugin()
1717

1818

19-
def run_openchannel(funding_sats_str, plugin):
19+
def run_openchannel(funding_sats_str, ctype, plugin):
2020
# Convert from string to satoshis
2121
funding_sats = Millisatoshi(funding_sats_str).to_satoshi()
2222

@@ -46,19 +46,19 @@ def run_openchannel(funding_sats_str, plugin):
4646
return {'result': 'continue', 'close_to': 'bc1qlq8srqnz64wgklmqvurv7qnr4rvtq2u96hhfg2'}
4747

4848
# - otherwise: accept and don't include the close_to
49-
plugin.log("accept by design")
49+
plugin.log(f"accept by design: channel_type {ctype}")
5050
return {'result': 'continue'}
5151

5252

5353
@plugin.hook('openchannel')
5454
def on_openchannel(openchannel, plugin, **kwargs):
55-
return run_openchannel(openchannel['funding_msat'], plugin)
55+
return run_openchannel(openchannel['funding_msat'], openchannel['channel_type'], plugin)
5656

5757

5858
@plugin.hook('openchannel2')
5959
def on_openchannel2(openchannel2, plugin, **kwargs):
6060
""" Support for v2 channel opens """
61-
return run_openchannel(openchannel2['their_funding_msat'], plugin)
61+
return run_openchannel(openchannel2['their_funding_msat'], openchannel2['channel_type'], plugin)
6262

6363

6464
plugin.run()

tests/test_plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ def test_openchannel_hook(node_factory, bitcoind):
691691
'max_accepted_htlcs': '483',
692692
'max_htlc_value_in_flight_msat': 18446744073709551615,
693693
'to_self_delay': '5',
694+
'channel_type': r"{'bits': \[12, 22\], 'names': \['static_remotekey/even', 'anchors/even'\]}",
694695
}
695696

696697
if 'anchors/even' in only_one(l1.rpc.listpeerchannels()['channels'])['channel_type']['names']:
@@ -4328,3 +4329,14 @@ def test_peer_storage(node_factory, bitcoind):
43284329
# This should never happen
43294330
assert not l1.daemon.is_in_log(r'PeerStorageFailed')
43304331
assert not l2.daemon.is_in_log(r'PeerStorageFailed')
4332+
4333+
4334+
@pytest.mark.openchannel('v1')
4335+
@pytest.mark.openchannel('v2')
4336+
def test_openchannel_hook_channel_type(node_factory, bitcoind):
4337+
"""openchannel hook should get a channel_type field.
4338+
"""
4339+
opts = {'plugin': os.path.join(os.getcwd(), 'tests/plugins/openchannel_hook_accepter.py')}
4340+
l1, l2 = node_factory.line_graph(2, opts=opts)
4341+
4342+
l2.daemon.wait_for_log(r"plugin-openchannel_hook_accepter.py: accept by design: channel_type {'bits': \[12, 22\], 'names': \['static_remotekey/even', 'anchors/even'\]}")

0 commit comments

Comments
 (0)