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

Function msg_for_remote_commit

openingd/dualopend.c:1173–1234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1171}
1172
1173static u8 *msg_for_remote_commit(const tal_t *ctx,
1174 const struct state *state,
1175 struct penalty_base **pbase,
1176 char **error)
1177{
1178 struct wally_tx_output *direct_outputs[NUM_SIDES];
1179 struct bitcoin_tx *remote_commit;
1180 struct bitcoin_signature local_sig;
1181 u32 feerate = 0; // unused since there are no htlcs
1182 u64 commit_num = 0;
1183 u8 *msg;
1184
1185 /* Create commitment tx signatures for remote */
1186 remote_commit = initial_channel_tx(NULL, NULL, state->channel,
1187 &state->first_per_commitment_point[REMOTE],
1188 REMOTE, direct_outputs, error);
1189
1190 if (!remote_commit) {
1191 return NULL;
1192 }
1193
1194 /* We ask the HSM to sign their commitment transaction for us: it knows
1195 * our funding key, it just needs the remote funding key to create the
1196 * witness script. It also needs the amount of the funding output,
1197 * as segwit signatures commit to that as well, even though it doesn't
1198 * explicitly appear in the transaction itself. */
1199 msg = towire_hsmd_sign_remote_commitment_tx(NULL,
1200 remote_commit,
1201 &state->channel->funding_pubkey[REMOTE],
1202 &state->first_per_commitment_point[REMOTE],
1203 true,
1204 commit_num,
1205 NULL, /* no HTLCS */
1206 feerate);
1207 wire_sync_write(HSM_FD, take(msg));
1208 msg = wire_sync_read(tmpctx, HSM_FD);
1209 if (!fromwire_hsmd_sign_tx_reply(msg, &local_sig))
1210 status_failed(STATUS_FAIL_HSM_IO,
1211 "Bad sign_tx_reply %s", tal_hex(tmpctx, msg));
1212
1213 /* You can tell this has been a problem before, since there's a debug
1214 * message here: */
1215 status_debug("signature %s on tx %s using key %s",
1216 fmt_bitcoin_signature(tmpctx, &local_sig),
1217 fmt_bitcoin_tx(tmpctx, remote_commit),
1218 fmt_pubkey(tmpctx,
1219 &state->our_funding_pubkey));
1220
1221
1222 assert(local_sig.sighash_type == SIGHASH_ALL);
1223
1224 if (pbase && direct_outputs[LOCAL])
1225 *pbase = penalty_base_new(ctx, 0, remote_commit,
1226 direct_outputs[LOCAL]);
1227 else if (pbase)
1228 *pbase = NULL;
1229
1230 tal_free(remote_commit);

Callers 3

do_reconnect_commit_sigsFunction · 0.85
accepter_commitsFunction · 0.85
opener_commitsFunction · 0.85

Calls 11

initial_channel_txFunction · 0.85
tal_hexFunction · 0.85
fmt_bitcoin_signatureFunction · 0.85
fmt_bitcoin_txFunction · 0.85
fmt_pubkeyFunction · 0.85
penalty_base_newFunction · 0.85
tal_freeFunction · 0.85
wire_sync_writeFunction · 0.50
wire_sync_readFunction · 0.50
status_failedFunction · 0.50

Tested by

no test coverage detected