| 1188 | } |
| 1189 | |
| 1190 | static char *do_commit_signed_received(const tal_t *ctx, |
| 1191 | const u8 *msg, |
| 1192 | struct state *state, |
| 1193 | struct tx_state *tx_state, |
| 1194 | struct bitcoin_tx **local_commit, |
| 1195 | struct bitcoin_signature *remote_sig) |
| 1196 | { |
| 1197 | const u8 *wscript; |
| 1198 | char *error; |
| 1199 | struct channel_id cid; |
| 1200 | secp256k1_ecdsa_signature *htlc_sigs; |
| 1201 | struct tlv_commitment_signed_tlvs *cs_tlv |
| 1202 | = tlv_commitment_signed_tlvs_new(tmpctx); |
| 1203 | |
| 1204 | if (!fromwire_commitment_signed(tmpctx, msg, &cid, |
| 1205 | &remote_sig->s, |
| 1206 | &htlc_sigs, &cs_tlv)) |
| 1207 | open_err_fatal(state, "Parsing commitment signed %s", |
| 1208 | tal_hex(tmpctx, msg)); |
| 1209 | |
| 1210 | remote_sig->sighash_type = SIGHASH_ALL; |
| 1211 | check_channel_id(state, &cid, &state->channel_id); |
| 1212 | |
| 1213 | if (htlc_sigs != NULL) |
| 1214 | open_err_fatal(state, "Must not send HTLCs with first" |
| 1215 | " commitment. %s", tal_hex(tmpctx, msg)); |
| 1216 | |
| 1217 | *local_commit = initial_channel_tx(ctx, &wscript, state->channel, |
| 1218 | &state->first_per_commitment_point[LOCAL], |
| 1219 | LOCAL, NULL, &error); |
| 1220 | |
| 1221 | /* This shouldn't happen either, AFAICT. */ |
| 1222 | if (!*local_commit) |
| 1223 | return tal_fmt(ctx, "Could not meet our fees" |
| 1224 | " and reserve: %s", error); |
| 1225 | |
| 1226 | validate_initial_commitment_signature(HSM_FD, *local_commit, remote_sig); |
| 1227 | |
| 1228 | /* BOLT #2: |
| 1229 | * |
| 1230 | * The recipient: |
| 1231 | * - if `signature` is incorrect OR non-compliant with LOW-S-standard |
| 1232 | * rule...: |
| 1233 | * - MUST send a `warning` and close the connection, or send an |
| 1234 | * `error` and fail the channel. |
| 1235 | */ |
| 1236 | if (!check_tx_sig(*local_commit, 0, NULL, wscript, |
| 1237 | &state->their_funding_pubkey, remote_sig)) { |
| 1238 | /* BOLT #1: |
| 1239 | * |
| 1240 | * - when failure was caused by an invalid signature check: |
| 1241 | * - SHOULD include the raw, hex-encoded transaction in reply |
| 1242 | * to a `funding_created`, `funding_signed`, |
| 1243 | * `closing_signed`, or `commitment_signed` message. |
| 1244 | */ |
| 1245 | /*~ This verbosity is not only useful for our own testing, but |
| 1246 | * a courtesy to other implementaters whose brains may be so |
| 1247 | * twisted by coding in Go, Scala and Rust that they can no |
no test coverage detected