mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
channeld: do init as sync IO.
Saves a special case. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a55b58d0d5
commit
a6b03dec15
1 changed files with 71 additions and 69 deletions
|
@ -1209,7 +1209,8 @@ static void peer_conn_broken(struct io_conn *conn, struct peer *peer)
|
||||||
"peer connection broken: %s", strerror(errno));
|
"peer connection broken: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_channel(struct peer *peer, const u8 *msg)
|
/* We do this synchronously. */
|
||||||
|
static void init_channel(struct peer *peer)
|
||||||
{
|
{
|
||||||
struct privkey seed;
|
struct privkey seed;
|
||||||
struct basepoints points[NUM_SIDES];
|
struct basepoints points[NUM_SIDES];
|
||||||
|
@ -1219,7 +1220,9 @@ static void init_channel(struct peer *peer, const u8 *msg)
|
||||||
struct sha256_double funding_txid;
|
struct sha256_double funding_txid;
|
||||||
bool am_funder;
|
bool am_funder;
|
||||||
u8 *funding_signed;
|
u8 *funding_signed;
|
||||||
|
u8 *msg;
|
||||||
|
|
||||||
|
msg = wire_sync_read(peer, REQ_FD);
|
||||||
if (!fromwire_channel_init(msg, msg, NULL,
|
if (!fromwire_channel_init(msg, msg, NULL,
|
||||||
&funding_txid, &funding_txout,
|
&funding_txid, &funding_txout,
|
||||||
&peer->conf[LOCAL], &peer->conf[REMOTE],
|
&peer->conf[LOCAL], &peer->conf[REMOTE],
|
||||||
|
@ -1273,6 +1276,8 @@ static void init_channel(struct peer *peer, const u8 *msg)
|
||||||
/* If we have a funding_signed message, we send that immediately */
|
/* If we have a funding_signed message, we send that immediately */
|
||||||
if (tal_len(funding_signed) != 0)
|
if (tal_len(funding_signed) != 0)
|
||||||
msg_enqueue(&peer->peer_out, take(funding_signed));
|
msg_enqueue(&peer->peer_out, take(funding_signed));
|
||||||
|
|
||||||
|
tal_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_funding_locked(struct peer *peer, const u8 *msg)
|
static void handle_funding_locked(struct peer *peer, const u8 *msg)
|
||||||
|
@ -1490,10 +1495,6 @@ static void handle_ping_cmd(struct peer *peer, const u8 *inmsg)
|
||||||
static struct io_plan *req_in(struct io_conn *conn, struct daemon_conn *master)
|
static struct io_plan *req_in(struct io_conn *conn, struct daemon_conn *master)
|
||||||
{
|
{
|
||||||
struct peer *peer = container_of(master, struct peer, master);
|
struct peer *peer = container_of(master, struct peer, master);
|
||||||
|
|
||||||
if (!peer->channel)
|
|
||||||
init_channel(peer, master->msg_in);
|
|
||||||
else {
|
|
||||||
enum channel_wire_type t = fromwire_peektype(master->msg_in);
|
enum channel_wire_type t = fromwire_peektype(master->msg_in);
|
||||||
|
|
||||||
/* Waiting for something specific? Defer others. */
|
/* Waiting for something specific? Defer others. */
|
||||||
|
@ -1559,7 +1560,6 @@ static struct io_plan *req_in(struct io_conn *conn, struct daemon_conn *master)
|
||||||
}
|
}
|
||||||
status_failed(WIRE_CHANNEL_BAD_COMMAND, "%u %s", t,
|
status_failed(WIRE_CHANNEL_BAD_COMMAND, "%u %s", t,
|
||||||
channel_wire_type_name(t));
|
channel_wire_type_name(t));
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
/* In case we've now processed reply, process packet backlog. */
|
/* In case we've now processed reply, process packet backlog. */
|
||||||
|
@ -1608,7 +1608,8 @@ int main(int argc, char *argv[])
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
|
||||||
daemon_conn_init(peer, &peer->master, REQ_FD, req_in, master_gone);
|
daemon_conn_init(peer, &peer->master, REQ_FD, req_in, master_gone);
|
||||||
peer->channel = NULL;
|
status_setup_async(&peer->master);
|
||||||
|
|
||||||
peer->htlc_id = 0;
|
peer->htlc_id = 0;
|
||||||
peer->num_pings_outstanding = 0;
|
peer->num_pings_outstanding = 0;
|
||||||
timers_init(&peer->timers, time_mono());
|
timers_init(&peer->timers, time_mono());
|
||||||
|
@ -1618,6 +1619,7 @@ int main(int argc, char *argv[])
|
||||||
peer->handle_master_reply = NULL;
|
peer->handle_master_reply = NULL;
|
||||||
peer->master_reply_type = 0;
|
peer->master_reply_type = 0;
|
||||||
msg_queue_init(&peer->master_deferred, peer);
|
msg_queue_init(&peer->master_deferred, peer);
|
||||||
|
msg_queue_init(&peer->peer_out, peer);
|
||||||
|
|
||||||
/* We send these to HSM to get real signatures; don't have valgrind
|
/* We send these to HSM to get real signatures; don't have valgrind
|
||||||
* complain. */
|
* complain. */
|
||||||
|
@ -1628,15 +1630,15 @@ int main(int argc, char *argv[])
|
||||||
sizeof(peer->announcement_bitcoin_sigs[i]));
|
sizeof(peer->announcement_bitcoin_sigs[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
status_setup_async(&peer->master);
|
|
||||||
msg_queue_init(&peer->peer_out, peer);
|
|
||||||
|
|
||||||
daemon_conn_init(peer, &peer->gossip_client, GOSSIP_FD,
|
daemon_conn_init(peer, &peer->gossip_client, GOSSIP_FD,
|
||||||
gossip_client_recv, gossip_gone);
|
gossip_client_recv, gossip_gone);
|
||||||
|
|
||||||
init_peer_crypto_state(peer, &peer->pcs);
|
init_peer_crypto_state(peer, &peer->pcs);
|
||||||
peer->funding_locked[LOCAL] = peer->funding_locked[REMOTE] = false;
|
peer->funding_locked[LOCAL] = peer->funding_locked[REMOTE] = false;
|
||||||
|
|
||||||
|
/* Read init_channel message sync. */
|
||||||
|
init_channel(peer);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct timer *expired = NULL;
|
struct timer *expired = NULL;
|
||||||
io_loop(&peer->timers, &expired);
|
io_loop(&peer->timers, &expired);
|
||||||
|
|
Loading…
Add table
Reference in a new issue