Browse Source

lightningd: hand HSM fd to channeld.

For the moment, it's just to do ECDH to read the onion.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
a815500653
  1. 110
      lightningd/peer_control.c

110
lightningd/peer_control.c

@ -657,6 +657,38 @@ static int channel_msg(struct subd *sd, const u8 *msg, const int *unused)
return 0; return 0;
} }
struct channeld_start {
struct peer *peer;
const u8 *initmsg;
};
/* We've got fd from HSM for channeld */
static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
const int *fds,
struct channeld_start *cds)
{
cds->peer->owner = new_subd(cds->peer->ld, cds->peer->ld,
"lightningd_channel", cds->peer,
channel_wire_type_name,
channel_msg, NULL,
cds->peer->fd,
cds->peer->gossip_client_fd, fds[0], -1);
if (!cds->peer->owner) {
log_unusual(cds->peer->log, "Could not subdaemon channel: %s",
strerror(errno));
peer_set_condition(cds->peer, "Failed to subdaemon channel");
tal_free(cds->peer);
return true;
}
cds->peer->fd = -1;
peer_set_condition(cds->peer, "Waiting for funding confirmations");
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(cds->peer->owner, take(cds->initmsg));
tal_free(cds);
return true;
}
/* opening is done, start lightningd_channel for peer. */ /* opening is done, start lightningd_channel for peer. */
static void peer_start_channeld(struct peer *peer, bool am_funder, static void peer_start_channeld(struct peer *peer, bool am_funder,
const struct channel_config *their_config, const struct channel_config *their_config,
@ -666,49 +698,43 @@ static void peer_start_channeld(struct peer *peer, bool am_funder,
const struct basepoints *theirbase, const struct basepoints *theirbase,
const struct pubkey *their_per_commit_point) const struct pubkey *their_per_commit_point)
{ {
u8 *msg; struct channeld_start *cds = tal(peer, struct channeld_start);
/* Normal channel daemon. */ /* Unowned: back to being owned by main daemon. */
peer->owner = new_subd(peer->ld, peer->ld, peer->owner = NULL;
"lightningd_channel", peer, tal_steal(peer->ld, peer);
channel_wire_type_name,
channel_msg, NULL, peer_set_condition(peer, "Waiting for HSM file descriptor");
peer->fd, peer->gossip_client_fd, -1);
if (!peer->owner) { cds->peer = peer;
log_unusual(peer->log, "Could not subdaemon channel: %s", /* Prepare init message now while we have access to all the data. */
strerror(errno)); cds->initmsg = towire_channel_init(cds,
peer_set_condition(peer, "Failed to subdaemon channel"); peer->funding_txid,
tal_free(peer); peer->funding_outnum,
return; &peer->our_config,
} their_config,
peer->fd = -1; commit_sig,
crypto_state,
peer_set_condition(peer, "Waiting for funding confirmations"); remote_fundingkey,
msg = towire_channel_init(peer, &theirbase->revocation,
peer->funding_txid, &theirbase->payment,
peer->funding_outnum, &theirbase->delayed_payment,
&peer->our_config, their_per_commit_point,
their_config, am_funder,
commit_sig, /* FIXME: real feerate! */
crypto_state, 15000,
remote_fundingkey, peer->funding_satoshi,
&theirbase->revocation, peer->push_msat,
&theirbase->payment, peer->seed,
&theirbase->delayed_payment, &peer->ld->dstate.id,
their_per_commit_point, peer->id,
am_funder, time_to_msec(peer->ld->dstate.config
/* FIXME: real feerate! */ .commit_time));
15000,
peer->funding_satoshi, /* Get fd from hsm. */
peer->push_msat, subd_req(peer->ld->hsm,
peer->seed, take(towire_hsmctl_hsmfd_ecdh(peer, peer->unique_id)), -1, 1,
&peer->ld->dstate.id, peer_start_channeld_hsmfd, cds);
peer->id,
time_to_msec(peer->ld->dstate.config
.commit_time));
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(peer->owner, take(msg));
} }
static bool opening_release_tx(struct subd *opening, const u8 *resp, static bool opening_release_tx(struct subd *opening, const u8 *resp,

Loading…
Cancel
Save