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)
This commit is contained in:
parent
d6192c2cb0
commit
1782ae8590
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue