MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_validate_rbf

Function handle_validate_rbf

lightningd/dual_open_control.c:2499–2589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2497}
2498
2499static void handle_validate_rbf(struct subd *dualopend,
2500 const u8 *msg)
2501{
2502 struct wally_psbt *candidate_psbt;
2503 struct channel_inflight *inflight;
2504 struct channel *channel = dualopend->channel;
2505 bool *inputs_present;
2506 struct amount_sat candidate_fee, last_fee;
2507
2508 if (!fromwire_dualopend_rbf_validate(tmpctx, msg,
2509 &candidate_psbt)) {
2510 channel_internal_error(channel,
2511 "Bad DUALOPEND_RBF_VALIDATE: %s",
2512 tal_hex(tmpctx, msg));
2513 return;
2514 }
2515
2516 inputs_present = tal_arr(tmpctx, bool, candidate_psbt->num_inputs);
2517 memset(inputs_present, true, tal_bytelen(inputs_present));
2518
2519 /* BOLT #2:
2520 *
2521 * - if this is an RBF attempt:
2522 * - MUST fail the negotiation if:
2523 * ...
2524 * - the transaction does not share at least one input with
2525 * each previous funding transaction
2526 */
2527 list_for_each(&channel->inflights, inflight, list) {
2528 /* Remove every non-matching input from set */
2529 for (size_t i = 0; i < candidate_psbt->num_inputs; i++) {
2530 const struct wally_psbt_input *input =
2531 &candidate_psbt->inputs[i];
2532 struct bitcoin_outpoint outpoint;
2533
2534 wally_psbt_input_get_outpoint(input, &outpoint);
2535
2536 if (!psbt_has_input(inflight->funding_psbt,
2537 &outpoint))
2538 inputs_present[i] = false;
2539 }
2540 }
2541
2542 /* Are there any inputs that were present on all txs? */
2543 if (memeqzero(inputs_present, tal_bytelen(inputs_present))) {
2544 char *errmsg;
2545
2546 inflight = list_tail(&channel->inflights,
2547 struct channel_inflight,
2548 list);
2549 assert(inflight);
2550
2551 errmsg = tal_fmt(tmpctx, "No overlapping input"
2552 " present. New: %s, last: %s",
2553 fmt_wally_psbt(tmpctx,
2554 candidate_psbt),
2555 fmt_wally_psbt(tmpctx,
2556 inflight->funding_psbt));

Callers 1

dual_opend_msgFunction · 0.85

Calls 11

tal_hexFunction · 0.85
tal_bytelenFunction · 0.85
psbt_has_inputFunction · 0.85
memeqzeroFunction · 0.85
fmt_wally_psbtFunction · 0.85
psbt_compute_feeFunction · 0.85
amount_sat_greaterFunction · 0.85
channel_internal_errorFunction · 0.70
subd_send_msgFunction · 0.70
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected