| 2547 | } |
| 2548 | |
| 2549 | static void handle_validate_rbf(struct subd *dualopend, |
| 2550 | const u8 *msg) |
| 2551 | { |
| 2552 | struct wally_psbt *candidate_psbt; |
| 2553 | struct channel_inflight *inflight; |
| 2554 | struct channel *channel = dualopend->channel; |
| 2555 | bool *inputs_present; |
| 2556 | struct amount_sat candidate_fee, last_fee; |
| 2557 | |
| 2558 | if (!fromwire_dualopend_rbf_validate(tmpctx, msg, |
| 2559 | &candidate_psbt)) { |
| 2560 | channel_internal_error(channel, |
| 2561 | "Bad DUALOPEND_RBF_VALIDATE: %s", |
| 2562 | tal_hex(tmpctx, msg)); |
| 2563 | return; |
| 2564 | } |
| 2565 | |
| 2566 | inputs_present = tal_arr(tmpctx, bool, candidate_psbt->num_inputs); |
| 2567 | memset(inputs_present, true, tal_bytelen(inputs_present)); |
| 2568 | |
| 2569 | /* BOLT #2: |
| 2570 | * |
| 2571 | * - if this is an RBF attempt: |
| 2572 | * - MUST fail the negotiation if: |
| 2573 | * ... |
| 2574 | * - the transaction does not share at least one input with |
| 2575 | * each previous funding transaction |
| 2576 | */ |
| 2577 | list_for_each(&channel->inflights, inflight, list) { |
| 2578 | /* Remove every non-matching input from set */ |
| 2579 | for (size_t i = 0; i < candidate_psbt->num_inputs; i++) { |
| 2580 | const struct wally_psbt_input *input = |
| 2581 | &candidate_psbt->inputs[i]; |
| 2582 | struct bitcoin_outpoint outpoint; |
| 2583 | |
| 2584 | wally_psbt_input_get_outpoint(input, &outpoint); |
| 2585 | |
| 2586 | if (!psbt_has_input(inflight->funding_psbt, |
| 2587 | &outpoint)) |
| 2588 | inputs_present[i] = false; |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | /* Are there any inputs that were present on all txs? */ |
| 2593 | if (memeqzero(inputs_present, tal_bytelen(inputs_present))) { |
| 2594 | char *errmsg; |
| 2595 | |
| 2596 | inflight = list_tail(&channel->inflights, |
| 2597 | struct channel_inflight, |
| 2598 | list); |
| 2599 | assert(inflight); |
| 2600 | |
| 2601 | errmsg = tal_fmt(tmpctx, "No overlapping input" |
| 2602 | " present. New: %s, last: %s", |
| 2603 | fmt_wally_psbt(tmpctx, |
| 2604 | candidate_psbt), |
| 2605 | fmt_wally_psbt(tmpctx, |
| 2606 | inflight->funding_psbt)); |
no test coverage detected