| 218 | } |
| 219 | |
| 220 | static void sign_last_tx(struct channel *channel, |
| 221 | struct bitcoin_tx *last_tx, |
| 222 | struct bitcoin_signature *last_sig) |
| 223 | { |
| 224 | struct lightningd *ld = channel->peer->ld; |
| 225 | struct bitcoin_signature sig; |
| 226 | u8 *msg, **witness; |
| 227 | |
| 228 | u64 commit_index = channel->next_index[LOCAL] - 1; |
| 229 | |
| 230 | assert(!last_tx->wtx->inputs[0].witness); |
| 231 | msg = towire_hsmd_sign_commitment_tx(tmpctx, |
| 232 | &channel->peer->id, |
| 233 | channel->dbid, |
| 234 | last_tx, |
| 235 | &channel->channel_info |
| 236 | .remote_fundingkey, |
| 237 | commit_index); |
| 238 | |
| 239 | if (!wire_sync_write(ld->hsm_fd, take(msg))) |
| 240 | fatal("Could not write to HSM: %s", strerror(errno)); |
| 241 | |
| 242 | msg = wire_sync_read(tmpctx, ld->hsm_fd); |
| 243 | if (!fromwire_hsmd_sign_commitment_tx_reply(msg, &sig)) |
| 244 | fatal("HSM gave bad sign_commitment_tx_reply %s", |
| 245 | tal_hex(tmpctx, msg)); |
| 246 | |
| 247 | witness = |
| 248 | bitcoin_witness_2of2(last_tx, last_sig, |
| 249 | &sig, &channel->channel_info.remote_fundingkey, |
| 250 | &channel->local_funding_pubkey); |
| 251 | |
| 252 | bitcoin_tx_input_set_witness(last_tx, 0, take(witness)); |
| 253 | } |
| 254 | |
| 255 | static void remove_sig(struct bitcoin_tx *signed_tx) |
| 256 | { |
no test coverage detected