mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 15:04:19 +01:00
openchannel hook: add new close_to field
Rounds out the application of `upfront_shutdown_script`, allowing an accepting node to specify a close_to address. Prior to this, only the opening node could specify one. Changelog-Added: Plugins: Allow the 'accepter' to specify an upfront_shutdown_script for a channel via a `close_to` field in the openchannel hook result
This commit is contained in:
committed by
Rusty Russell
parent
654faa6174
commit
de16d0f0b4
@@ -455,7 +455,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
u32 feerate;
|
||||
u8 channel_flags;
|
||||
struct channel *channel;
|
||||
u8 *remote_upfront_shutdown_script;
|
||||
u8 *remote_upfront_shutdown_script, *local_upfront_shutdown_script;
|
||||
struct per_peer_state *pps;
|
||||
|
||||
log_debug(uc->log, "Got opening_fundee_finish_response");
|
||||
@@ -482,6 +482,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
&feerate,
|
||||
&funding_signed,
|
||||
&uc->our_config.channel_reserve,
|
||||
&local_upfront_shutdown_script,
|
||||
&remote_upfront_shutdown_script)) {
|
||||
log_broken(uc->log, "bad OPENING_FUNDEE_REPLY %s",
|
||||
tal_hex(reply, reply));
|
||||
@@ -510,7 +511,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
channel_flags,
|
||||
&channel_info,
|
||||
feerate,
|
||||
NULL,
|
||||
local_upfront_shutdown_script,
|
||||
remote_upfront_shutdown_script);
|
||||
if (!channel) {
|
||||
uncommitted_channel_disconnect(uc, "Commit channel failed");
|
||||
@@ -753,6 +754,7 @@ static void openchannel_hook_cb(struct openchannel_hook_payload *payload,
|
||||
const jsmntok_t *toks)
|
||||
{
|
||||
struct subd *openingd = payload->openingd;
|
||||
const u8 *our_upfront_shutdown_script;
|
||||
const char *errmsg = NULL;
|
||||
|
||||
/* We want to free this, whatever happens. */
|
||||
@@ -782,14 +784,41 @@ static void openchannel_hook_cb(struct openchannel_hook_payload *payload,
|
||||
log_debug(openingd->ld->log,
|
||||
"openchannel_hook_cb says '%s'",
|
||||
errmsg);
|
||||
our_upfront_shutdown_script = NULL;
|
||||
} else if (!json_tok_streq(buffer, t, "continue"))
|
||||
fatal("Plugin returned an invalid result for the "
|
||||
"openchannel hook: %.*s",
|
||||
t->end - t->start, buffer + t->start);
|
||||
}
|
||||
|
||||
/* Check for a 'close_to' address passed back */
|
||||
if (!errmsg) {
|
||||
t = json_get_member(buffer, toks, "close_to");
|
||||
if (t) {
|
||||
switch (json_to_address_scriptpubkey(tmpctx, chainparams,
|
||||
buffer, t,
|
||||
&our_upfront_shutdown_script)) {
|
||||
case ADDRESS_PARSE_UNRECOGNIZED:
|
||||
fatal("Plugin returned an invalid response to the"
|
||||
" openchannel.close_to hook: %.*s",
|
||||
t->end - t->start, buffer + t->start);
|
||||
case ADDRESS_PARSE_WRONG_NETWORK:
|
||||
fatal("Plugin returned invalid response to the"
|
||||
" openchannel.close_to hook: address %s is"
|
||||
" not on network %s",
|
||||
tal_hex(NULL, our_upfront_shutdown_script),
|
||||
chainparams->network_name);
|
||||
case ADDRESS_PARSE_SUCCESS:
|
||||
errmsg = NULL;
|
||||
}
|
||||
} else
|
||||
our_upfront_shutdown_script = NULL;
|
||||
}
|
||||
} else
|
||||
our_upfront_shutdown_script = NULL;
|
||||
|
||||
subd_send_msg(openingd,
|
||||
take(towire_opening_got_offer_reply(NULL, errmsg)));
|
||||
take(towire_opening_got_offer_reply(NULL, errmsg,
|
||||
our_upfront_shutdown_script)));
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN_HOOK(openchannel,
|
||||
@@ -808,7 +837,7 @@ static void opening_got_offer(struct subd *openingd,
|
||||
if (peer_active_channel(uc->peer)) {
|
||||
subd_send_msg(openingd,
|
||||
take(towire_opening_got_offer_reply(NULL,
|
||||
"Already have active channel")));
|
||||
"Already have active channel", NULL)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user