MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_sign_remote_commitment_tx

Function handle_sign_remote_commitment_tx

hsmd/libhsmd.c:1220–1267  ·  view source on GitHub ↗

~ This is used by channeld to create signatures for the remote peer's * commitment transaction. It's functionally identical to signing our own, * but we expect to do this repeatedly as commitment transactions are * updated. * * The HSM almost certainly *should* do more checks before signing! */ FIXME: make sure it meets some criteria? */

Source from the content-addressed store, hash-verified

1218 */
1219/* FIXME: make sure it meets some criteria? */
1220static u8 *handle_sign_remote_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
1221{
1222 struct pubkey remote_funding_pubkey, local_funding_pubkey;
1223 struct secret channel_seed;
1224 struct bitcoin_tx *tx;
1225 struct bitcoin_signature sig;
1226 struct secrets secrets;
1227 const u8 *funding_wscript;
1228 struct pubkey remote_per_commit;
1229 bool option_static_remotekey;
1230 u64 commit_num;
1231 struct simple_htlc **htlc;
1232 u32 feerate;
1233
1234 if (!fromwire_hsmd_sign_remote_commitment_tx(tmpctx, msg_in,
1235 &tx,
1236 &remote_funding_pubkey,
1237 &remote_per_commit,
1238 &option_static_remotekey,
1239 &commit_num,
1240 &htlc, &feerate))
1241 return hsmd_status_malformed_request(c, msg_in);
1242 tx->chainparams = c->chainparams;
1243
1244 /* Basic sanity checks. */
1245 if (tx->wtx->num_inputs != 1)
1246 return hsmd_status_bad_request_fmt(c, msg_in,
1247 "tx must have 1 input");
1248
1249 if (tx->wtx->num_outputs == 0)
1250 return hsmd_status_bad_request_fmt(c, msg_in,
1251 "tx must have > 0 outputs");
1252
1253 get_channel_seed(&c->id, c->dbid, &channel_seed);
1254 derive_basepoints(&channel_seed,
1255 &local_funding_pubkey, NULL, &secrets, NULL);
1256
1257 funding_wscript = bitcoin_redeem_2of2(tmpctx,
1258 &local_funding_pubkey,
1259 &remote_funding_pubkey);
1260 sign_tx_input(tx, 0, NULL, funding_wscript,
1261 &secrets.funding_privkey,
1262 &local_funding_pubkey,
1263 SIGHASH_ALL,
1264 &sig);
1265
1266 return towire_hsmd_sign_tx_reply(NULL, &sig);
1267}
1268
1269/*~ This is used when the remote peer's commitment transaction is revoked;
1270 * we can use the revocation secret to spend the outputs. For simplicity,

Callers 1

Calls 6

derive_basepointsFunction · 0.85
bitcoin_redeem_2of2Function · 0.85
sign_tx_inputFunction · 0.85
get_channel_seedFunction · 0.70

Tested by

no test coverage detected