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. */
| 237 | * - Note: this is to reduce the above risk. |
| 238 | */ |
| 239 | static struct bitcoin_tx *sign_last_tx(const tal_t *ctx, |
| 240 | const struct channel *channel, |
| 241 | const struct bitcoin_tx *last_tx, |
| 242 | const struct bitcoin_signature *last_sig) |
| 243 | { |
| 244 | struct lightningd *ld = channel->peer->ld; |
| 245 | struct bitcoin_signature sig; |
| 246 | const u8 *msg; |
| 247 | u8 **witness; |
| 248 | u64 commit_index = channel->next_index[LOCAL] - 1; |
| 249 | struct bitcoin_tx *tx = clone_bitcoin_tx(ctx, last_tx); |
| 250 | |
| 251 | assert(!tx->wtx->inputs[0].witness); |
| 252 | msg = towire_hsmd_sign_commitment_tx(NULL, |
| 253 | &channel->peer->id, |
| 254 | channel->dbid, |
| 255 | tx, |
| 256 | &channel->channel_info |
| 257 | .remote_fundingkey, |
| 258 | commit_index); |
| 259 | |
| 260 | msg = hsm_sync_req(tmpctx, ld, take(msg)); |
| 261 | if (!fromwire_hsmd_sign_commitment_tx_reply(msg, &sig)) |
| 262 | fatal("HSM gave bad sign_commitment_tx_reply %s", |
| 263 | tal_hex(tmpctx, msg)); |
| 264 | |
| 265 | witness = |
| 266 | bitcoin_witness_2of2(tx, last_sig, |
| 267 | &sig, &channel->channel_info.remote_fundingkey, |
| 268 | &channel->local_funding_pubkey); |
| 269 | |
| 270 | bitcoin_tx_input_set_witness(tx, 0, take(witness)); |
| 271 | return tx; |
| 272 | } |
| 273 | |
| 274 | bool invalid_last_tx(const struct bitcoin_tx *tx) |
| 275 | { |
no test coverage detected