From 085c590a51911d94955755b7d1c39ac3a8323233 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 17 Sep 2020 14:46:59 -0500 Subject: [PATCH] dualopen: use separate wire for passing updated PSBTs back to dualopend Rusty pointed out that having an empty channel_id is suboptimal; adding another call is probably the right idea rather than re-using an existing one. Suggested-By: @rustyrussell --- lightningd/dual_open_control.c | 8 +++----- openingd/dualopend.c | 4 ++-- openingd/dualopend_wire.csv | 5 ++++- openingd/dualopend_wiregen.c | 27 +++++++++++++++++++++++++-- openingd/dualopend_wiregen.h | 11 ++++++++--- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 04ca3644d..1f2e58c29 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -500,8 +500,7 @@ openchannel2_changed_hook_cb(struct openchannel2_psbt_payload *payload STEALS) payload); subd_send_msg(dualopend, - take(towire_dual_open_psbt_changed(NULL, - &payload->rcvd->cid, + take(towire_dual_open_psbt_updated(NULL, payload->psbt))); } @@ -1086,7 +1085,6 @@ static struct command_result *json_open_channel_update(struct command *cmd, struct node_id *id; struct peer *peer; struct channel *channel; - struct channel_id chan_id_unused; u8 *msg; if (!param(cmd, buffer, params, @@ -1123,8 +1121,7 @@ static struct command_result *json_open_channel_update(struct command *cmd, peer->uncommitted_channel->fc->cmd = cmd; - memset(&chan_id_unused, 0, sizeof(chan_id_unused)); - msg = towire_dual_open_psbt_changed(NULL, &chan_id_unused, psbt); + msg = towire_dual_open_psbt_updated(NULL, psbt); subd_send_msg(peer->uncommitted_channel->open_daemon, take(msg)); return command_still_pending(cmd); } @@ -1327,6 +1324,7 @@ static unsigned int dual_opend_msg(struct subd *dualopend, case WIRE_DUAL_OPEN_OPENER_INIT: case WIRE_DUAL_OPEN_GOT_OFFER_REPLY: case WIRE_DUAL_OPEN_FAIL: + case WIRE_DUAL_OPEN_PSBT_UPDATED: case WIRE_DUAL_OPEN_DEV_MEMLEAK: break; } diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 67dce1cc7..a0f98b7d4 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -376,7 +376,6 @@ fetch_psbt_changes(struct state *state, const struct wally_psbt *psbt) { u8 *msg; char *err; - struct channel_id unused; struct wally_psbt *updated_psbt; /* Go ask lightningd what other changes we've got */ @@ -387,7 +386,7 @@ fetch_psbt_changes(struct state *state, const struct wally_psbt *psbt) if (fromwire_dual_open_fail(msg, msg, &err)) status_failed(STATUS_FAIL_MASTER_IO, "%s", err); - else if (fromwire_dual_open_psbt_changed(state, msg, &unused, &updated_psbt)) { + else if (fromwire_dual_open_psbt_updated(state, msg, &updated_psbt)) { /* Does our PSBT meet requirements? */ if (!check_balances(state, updated_psbt, state->our_role == TX_INITIATOR, @@ -1706,6 +1705,7 @@ static u8 *handle_master_in(struct state *state) case WIRE_DUAL_OPEN_GOT_OFFER_REPLY: case WIRE_DUAL_OPEN_COMMIT_RCVD: case WIRE_DUAL_OPEN_PSBT_CHANGED: + case WIRE_DUAL_OPEN_PSBT_UPDATED: break; } diff --git a/openingd/dualopend_wire.csv b/openingd/dualopend_wire.csv index fa01c0ecf..ef64fc6d5 100644 --- a/openingd/dualopend_wire.csv +++ b/openingd/dualopend_wire.csv @@ -84,11 +84,14 @@ msgdata,dual_open_commit_rcvd,remote_shutdown_len,u16, msgdata,dual_open_commit_rcvd,remote_shutdown_scriptpubkey,u8,remote_shutdown_len # dualopend->master: peer updated the psbt -# master->dualopend: response from hook when asking for next moves msgtype,dual_open_psbt_changed,7107 msgdata,dual_open_psbt_changed,channel_id,channel_id, msgdata,dual_open_psbt_changed,psbt,wally_psbt, +# master->dualopend: we updated the psbt +msgtype,dual_open_psbt_updated,7108 +msgdata,dual_open_psbt_updated,psbt,wally_psbt, + # master->dualopend: fail this channel open msgtype,dual_open_fail,7003 msgdata,dual_open_fail,reason,wirestring, diff --git a/openingd/dualopend_wiregen.c b/openingd/dualopend_wiregen.c index 6d91a2826..e988d8936 100644 --- a/openingd/dualopend_wiregen.c +++ b/openingd/dualopend_wiregen.c @@ -25,6 +25,7 @@ const char *dualopend_wire_name(int e) case WIRE_DUAL_OPEN_GOT_OFFER_REPLY: return "WIRE_DUAL_OPEN_GOT_OFFER_REPLY"; case WIRE_DUAL_OPEN_COMMIT_RCVD: return "WIRE_DUAL_OPEN_COMMIT_RCVD"; case WIRE_DUAL_OPEN_PSBT_CHANGED: return "WIRE_DUAL_OPEN_PSBT_CHANGED"; + case WIRE_DUAL_OPEN_PSBT_UPDATED: return "WIRE_DUAL_OPEN_PSBT_UPDATED"; case WIRE_DUAL_OPEN_FAIL: return "WIRE_DUAL_OPEN_FAIL"; case WIRE_DUAL_OPEN_FAILED: return "WIRE_DUAL_OPEN_FAILED"; case WIRE_DUAL_OPEN_OPENER_INIT: return "WIRE_DUAL_OPEN_OPENER_INIT"; @@ -44,6 +45,7 @@ bool dualopend_wire_is_defined(u16 type) case WIRE_DUAL_OPEN_GOT_OFFER_REPLY:; case WIRE_DUAL_OPEN_COMMIT_RCVD:; case WIRE_DUAL_OPEN_PSBT_CHANGED:; + case WIRE_DUAL_OPEN_PSBT_UPDATED:; case WIRE_DUAL_OPEN_FAIL:; case WIRE_DUAL_OPEN_FAILED:; case WIRE_DUAL_OPEN_OPENER_INIT:; @@ -308,7 +310,6 @@ bool fromwire_dual_open_commit_rcvd(const tal_t *ctx, const void *p, struct chan /* WIRE: DUAL_OPEN_PSBT_CHANGED */ /* dualopend->master: peer updated the psbt */ -/* master->dualopend: response from hook when asking for next moves */ u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, const struct wally_psbt *psbt) { u8 *p = tal_arr(ctx, u8, 0); @@ -331,6 +332,28 @@ bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct cha return cursor != NULL; } +/* WIRE: DUAL_OPEN_PSBT_UPDATED */ +/* master->dualopend: we updated the psbt */ +u8 *towire_dual_open_psbt_updated(const tal_t *ctx, const struct wally_psbt *psbt) +{ + u8 *p = tal_arr(ctx, u8, 0); + + towire_u16(&p, WIRE_DUAL_OPEN_PSBT_UPDATED); + towire_wally_psbt(&p, psbt); + + return memcheck(p, tal_count(p)); +} +bool fromwire_dual_open_psbt_updated(const tal_t *ctx, const void *p, struct wally_psbt **psbt) +{ + const u8 *cursor = p; + size_t plen = tal_count(p); + + if (fromwire_u16(&cursor, &plen) != WIRE_DUAL_OPEN_PSBT_UPDATED) + return false; + *psbt = fromwire_wally_psbt(ctx, &cursor, &plen); + return cursor != NULL; +} + /* WIRE: DUAL_OPEN_FAIL */ /* master->dualopend: fail this channel open */ u8 *towire_dual_open_fail(const tal_t *ctx, const wirestring *reason) @@ -454,4 +477,4 @@ bool fromwire_dual_open_dev_memleak_reply(const void *p, bool *leak) *leak = fromwire_bool(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:4d357681ca9bea1ad36f3fe4d3482a0a12f808dfe20b71f0b9bee78beed0950e +// SHA256STAMP:37f122e865f6e2432cffb5ae82c77ca2f8a3714baed0c9724a92541092f3aa54 diff --git a/openingd/dualopend_wiregen.h b/openingd/dualopend_wiregen.h index 588756e5a..6f1f464de 100644 --- a/openingd/dualopend_wiregen.h +++ b/openingd/dualopend_wiregen.h @@ -27,8 +27,9 @@ enum dualopend_wire { /* get some signatures for the funding_tx. */ WIRE_DUAL_OPEN_COMMIT_RCVD = 7007, /* dualopend->master: peer updated the psbt */ - /* master->dualopend: response from hook when asking for next moves */ WIRE_DUAL_OPEN_PSBT_CHANGED = 7107, + /* master->dualopend: we updated the psbt */ + WIRE_DUAL_OPEN_PSBT_UPDATED = 7108, /* master->dualopend: fail this channel open */ WIRE_DUAL_OPEN_FAIL = 7003, /* dualopend->master: we failed to negotiate channel */ @@ -74,10 +75,14 @@ bool fromwire_dual_open_commit_rcvd(const tal_t *ctx, const void *p, struct chan /* WIRE: DUAL_OPEN_PSBT_CHANGED */ /* dualopend->master: peer updated the psbt */ -/* master->dualopend: response from hook when asking for next moves */ u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, const struct wally_psbt *psbt); bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct channel_id *channel_id, struct wally_psbt **psbt); +/* WIRE: DUAL_OPEN_PSBT_UPDATED */ +/* master->dualopend: we updated the psbt */ +u8 *towire_dual_open_psbt_updated(const tal_t *ctx, const struct wally_psbt *psbt); +bool fromwire_dual_open_psbt_updated(const tal_t *ctx, const void *p, struct wally_psbt **psbt); + /* WIRE: DUAL_OPEN_FAIL */ /* master->dualopend: fail this channel open */ u8 *towire_dual_open_fail(const tal_t *ctx, const wirestring *reason); @@ -104,4 +109,4 @@ bool fromwire_dual_open_dev_memleak_reply(const void *p, bool *leak); #endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */ -// SHA256STAMP:4d357681ca9bea1ad36f3fe4d3482a0a12f808dfe20b71f0b9bee78beed0950e +// SHA256STAMP:37f122e865f6e2432cffb5ae82c77ca2f8a3714baed0c9724a92541092f3aa54