BOLT #2: * A node: * - MUST NOT broadcast old (revoked) commitment transactions, * - Note: doing so will allow the other node to seize all channel funds. * - SHOULD NOT sign commitment transactions, unless it's about to broadcast * them (due to a failed connection), * - Note: this is to reduce the above risk. */
| 244 | * - Note: this is to reduce the above risk. |
| 245 | */ |
| 246 | static struct bitcoin_tx *sign_last_tx(const tal_t *ctx, |
| 247 | const struct channel *channel, |
| 248 | const struct bitcoin_tx *last_tx, |
| 249 | const struct bitcoin_signature *last_sig, |
| 250 | const struct pubkey *remote_fundingkey) |
| 251 | { |
| 252 | struct lightningd *ld = channel->peer->ld; |
| 253 | struct bitcoin_signature sig; |
| 254 | const u8 *msg; |
| 255 | u8 **witness; |
| 256 | u64 commit_index = channel->next_index[LOCAL] - 1; |
| 257 | struct bitcoin_tx *tx = clone_bitcoin_tx(ctx, last_tx); |
| 258 | |
| 259 | assert(!tx->wtx->inputs[0].witness); |
| 260 | msg = towire_hsmd_sign_commitment_tx(NULL, |
| 261 | &channel->peer->id, |
| 262 | channel->dbid, |
| 263 | tx, |
| 264 | remote_fundingkey, |
| 265 | commit_index); |
| 266 | |
| 267 | msg = hsm_sync_req(tmpctx, ld, take(msg)); |
| 268 | if (!fromwire_hsmd_sign_commitment_tx_reply(msg, &sig)) |
| 269 | fatal("HSM gave bad sign_commitment_tx_reply %s", |
| 270 | tal_hex(tmpctx, msg)); |
| 271 | |
| 272 | witness = |
| 273 | bitcoin_witness_2of2(tx, last_sig, |
| 274 | &sig, remote_fundingkey, |
| 275 | &channel->local_funding_pubkey); |
| 276 | |
| 277 | bitcoin_tx_input_set_witness(tx, 0, take(witness)); |
| 278 | return tx; |
| 279 | } |
| 280 | |
| 281 | /* The peer may use a new funding key for a splice: that inflight's |
| 282 | * commitment spends the splice output, not the current funding. */ |
no test coverage detected