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

Function openchannel2_sign_hook_cb

lightningd/dual_open_control.c:1062–1132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1060}
1061
1062static void
1063openchannel2_sign_hook_cb(struct openchannel2_psbt_payload *payload STEALS)
1064{
1065 struct channel *channel = payload->channel;
1066 struct channel_inflight *inflight;
1067 struct bitcoin_txid txid;
1068 u8 *msg;
1069
1070 /* Whatever happens, we free the payload */
1071 tal_steal(tmpctx, payload);
1072
1073 /* Finalize it, if not already. It shouldn't work entirely */
1074 psbt_finalize(payload->psbt);
1075
1076 if (!psbt_side_finalized(payload->psbt, TX_ACCEPTER)) {
1077 log_broken(channel->log,
1078 "Plugin must return a 'psbt' with signatures "
1079 "for their inputs %s",
1080 fmt_wally_psbt(tmpctx,
1081 payload->psbt));
1082 msg = towire_dualopend_fail(NULL, "Peer error with PSBT"
1083 " signatures.");
1084 goto send_msg;
1085 }
1086
1087 inflight = channel_current_inflight(channel);
1088 if (!inflight) {
1089 log_broken(channel->log,
1090 "No current channel inflight");
1091 msg = towire_dualopend_fail(NULL, "No current channel inflight");
1092 goto send_msg;
1093 }
1094
1095 /* Check that we've got the same / correct PSBT */
1096 psbt_txid(NULL, payload->psbt, &txid, NULL);
1097 if (!bitcoin_txid_eq(&inflight->funding->outpoint.txid, &txid)) {
1098 log_broken(channel->log,
1099 "PSBT's txid does not match. %s != %s",
1100 fmt_bitcoin_txid(tmpctx, &txid),
1101 fmt_bitcoin_txid(tmpctx,
1102 &inflight->funding->outpoint.txid));
1103 msg = towire_dualopend_fail(NULL, "Peer error with PSBT"
1104 " signatures.");
1105 goto send_msg;
1106 }
1107
1108 /* Now that we've got the signed PSBT, save it */
1109 tal_free(inflight->funding_psbt);
1110 inflight->funding_psbt = tal_steal(inflight,
1111 cast_const(struct wally_psbt *,
1112 payload->psbt));
1113 wallet_inflight_save(payload->ld->wallet, inflight);
1114 watch_opening_inflight(payload->ld, inflight);
1115 msg = towire_dualopend_send_tx_sigs(NULL, inflight->funding_psbt);
1116
1117send_msg:
1118 /* Peer's gone away, let's try reconnecting */
1119 if (!payload->dualopend) {

Callers

nothing calls this directly

Calls 11

psbt_finalizeFunction · 0.85
psbt_side_finalizedFunction · 0.85
fmt_wally_psbtFunction · 0.85
channel_current_inflightFunction · 0.85
psbt_txidFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
tal_freeFunction · 0.85
wallet_inflight_saveFunction · 0.85
watch_opening_inflightFunction · 0.70
subd_send_msgFunction · 0.70

Tested by

no test coverage detected