| 1099 | } |
| 1100 | |
| 1101 | static u8 *msg_for_remote_commit(const tal_t *ctx, |
| 1102 | const struct state *state, |
| 1103 | struct penalty_base **pbase, |
| 1104 | char **error) |
| 1105 | { |
| 1106 | struct wally_tx_output *direct_outputs[NUM_SIDES]; |
| 1107 | struct bitcoin_tx *remote_commit; |
| 1108 | struct bitcoin_signature local_sig; |
| 1109 | u32 feerate = 0; // unused since there are no htlcs |
| 1110 | u64 commit_num = 0; |
| 1111 | u8 *msg; |
| 1112 | |
| 1113 | /* Create commitment tx signatures for remote */ |
| 1114 | remote_commit = initial_channel_tx(NULL, NULL, state->channel, |
| 1115 | &state->first_per_commitment_point[REMOTE], |
| 1116 | REMOTE, direct_outputs, error); |
| 1117 | |
| 1118 | if (!remote_commit) { |
| 1119 | return NULL; |
| 1120 | } |
| 1121 | |
| 1122 | /* We ask the HSM to sign their commitment transaction for us: it knows |
| 1123 | * our funding key, it just needs the remote funding key to create the |
| 1124 | * witness script. It also needs the amount of the funding output, |
| 1125 | * as segwit signatures commit to that as well, even though it doesn't |
| 1126 | * explicitly appear in the transaction itself. */ |
| 1127 | msg = towire_hsmd_sign_remote_commitment_tx(NULL, |
| 1128 | remote_commit, |
| 1129 | &state->channel->funding_pubkey[REMOTE], |
| 1130 | &state->first_per_commitment_point[REMOTE], |
| 1131 | true, |
| 1132 | commit_num, |
| 1133 | NULL, /* no HTLCS */ |
| 1134 | feerate); |
| 1135 | wire_sync_write(HSM_FD, take(msg)); |
| 1136 | msg = wire_sync_read(tmpctx, HSM_FD); |
| 1137 | if (!fromwire_hsmd_sign_tx_reply(msg, &local_sig)) |
| 1138 | status_failed(STATUS_FAIL_HSM_IO, |
| 1139 | "Bad sign_tx_reply %s", tal_hex(tmpctx, msg)); |
| 1140 | |
| 1141 | /* You can tell this has been a problem before, since there's a debug |
| 1142 | * message here: */ |
| 1143 | status_debug("signature %s on tx %s using key %s", |
| 1144 | fmt_bitcoin_signature(tmpctx, &local_sig), |
| 1145 | fmt_bitcoin_tx(tmpctx, remote_commit), |
| 1146 | fmt_pubkey(tmpctx, |
| 1147 | &state->our_funding_pubkey)); |
| 1148 | |
| 1149 | |
| 1150 | assert(local_sig.sighash_type == SIGHASH_ALL); |
| 1151 | |
| 1152 | if (pbase && direct_outputs[LOCAL]) |
| 1153 | *pbase = penalty_base_new(ctx, 0, remote_commit, |
| 1154 | direct_outputs[LOCAL]); |
| 1155 | else if (pbase) |
| 1156 | *pbase = NULL; |
| 1157 | |
| 1158 | tal_free(remote_commit); |
no test coverage detected