From 1782ae8590830a0b3fb7b11411b506e714ee6ff3 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 31 Aug 2021 13:16:49 -0500 Subject: [PATCH] dual-fund psbt: hoist up single use method so we can test it Also remove all the unused code (checking for differences for a side etc) --- common/psbt_open.c | 16 +++++++++++++ common/psbt_open.h | 9 +++++++ lightningd/dual_open_control.c | 44 +--------------------------------- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/common/psbt_open.c b/common/psbt_open.c index eb654a02f..0ebf71bfa 100644 --- a/common/psbt_open.c +++ b/common/psbt_open.c @@ -491,3 +491,19 @@ bool psbt_has_our_input(const struct wally_psbt *psbt) return false; } + +bool psbt_contribs_changed(struct wally_psbt *orig, + struct wally_psbt *new) +{ + struct psbt_changeset *cs; + bool ok; + cs = psbt_get_changeset(NULL, orig, new); + + ok = tal_count(cs->added_ins) > 0 || + tal_count(cs->rm_ins) > 0 || + tal_count(cs->added_outs) > 0 || + tal_count(cs->rm_outs) > 0; + + tal_free(cs); + return ok; +} diff --git a/common/psbt_open.h b/common/psbt_open.h index bb7a5e57e..b3d0a2c66 100644 --- a/common/psbt_open.h +++ b/common/psbt_open.h @@ -178,4 +178,13 @@ bool psbt_input_is_ours(const struct wally_psbt_input *input); * any input that is ours */ bool psbt_has_our_input(const struct wally_psbt *psbt); + +/* psbt_contribs_changed - Returns true if the psbt's inputs/outputs + * have changed. + * + * @orig - originating psbt + * @new - 'updated' psbt, to verify is unchanged + */ +bool psbt_contribs_changed(struct wally_psbt *orig, + struct wally_psbt *new); #endif /* LIGHTNING_COMMON_PSBT_OPEN_H */ diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 45d14c0a1..38a802775 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -474,48 +474,6 @@ hook_extract_amount(struct subd *dualopend, return true; } -#define CHECK_CHANGES(set, dir) \ - do { \ - for (size_t i = 0; i < tal_count(set); i++) { \ - ok = psbt_get_serial_id(&set[i].dir.unknowns, \ - &serial_id); \ - assert(ok); \ - if (serial_id % 2 != opener_side) \ - return true; \ - } \ - } while (false) - -static bool psbt_side_contribs_changed(struct wally_psbt *orig, - struct wally_psbt *new, - enum side opener_side) -{ - struct psbt_changeset *cs; - u64 serial_id; - bool ok; - - cs = psbt_get_changeset(tmpctx, orig, new); - - if (tal_count(cs->added_ins) == 0 && - tal_count(cs->rm_ins) == 0 && - tal_count(cs->added_outs) == 0 && - tal_count(cs->rm_outs) == 0) - return false; - - /* If there were *any* changes, then the answer to the 'both sides' - * question is "yes, there were changes" */ - if (opener_side == NUM_SIDES) - return true; - - /* Check that none of the included updates have a serial - * id that's the peer's parity */ - CHECK_CHANGES(cs->added_ins, input); - CHECK_CHANGES(cs->rm_ins, input); - CHECK_CHANGES(cs->added_outs, output); - CHECK_CHANGES(cs->rm_outs, output); - - return false; -} - static void rbf_channel_remove_dualopend(struct subd *dualopend, struct rbf_channel_payload *payload) { @@ -932,7 +890,7 @@ openchannel2_signed_deserialize(struct openchannel2_psbt_payload *payload, * totally managled the data here but left the serial_ids intact, * you'll get a failure back from the peer when you send * commitment sigs */ - if (psbt_side_contribs_changed(payload->psbt, psbt, NUM_SIDES)) + if (psbt_contribs_changed(payload->psbt, psbt)) fatal("Plugin must not change psbt input/output set. " "orig: %s. updated: %s", type_to_string(tmpctx, struct wally_psbt,