Skip to content

Commit

Permalink
peer_io: replace crypto_sync in daemons, use normal wire messages.
Browse files Browse the repository at this point in the history
Now connectd is doing the crypto, we can use normal wire io.  We
create helper functions to clearly differentiate between "peer" comms
and intra-daemon comms though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jan 20, 2022
1 parent a2b3d33 commit ce8b694
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 130 deletions.
6 changes: 3 additions & 3 deletions channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ CHANNELD_COMMON_OBJS := \
common/channel_id.o \
common/channel_type.o \
common/crypto_state.o \
common/crypto_sync.o \
common/cryptomsg.o \
common/daemon.o \
common/daemon_conn.o \
Expand All @@ -50,9 +49,10 @@ CHANNELD_COMMON_OBJS := \
common/ecdh_hsmd.o \
common/features.o \
common/fee_states.o \
common/status_wiregen.o \
common/peer_status_wiregen.o \
common/gossip_rcvd_filter.o \
common/peer_io.o \
common/peer_status_wiregen.o \
common/status_wiregen.o \
common/gossip_store.o \
common/hmac.o \
common/htlc_state.o \
Expand Down
52 changes: 26 additions & 26 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <channeld/full_channel.h>
#include <channeld/watchtower.h>
#include <common/billboard.h>
#include <common/crypto_sync.h>
#include <common/dev_disconnect.h>
#include <common/ecdh_hsmd.h>
#include <common/gossip_store.h>
Expand All @@ -29,6 +28,7 @@
#include <common/onionreply.h>
#include <common/peer_billboard.h>
#include <common/peer_failed.h>
#include <common/peer_io.h>
#include <common/ping.h>
#include <common/private_channel_announcement.h>
#include <common/read_peer_msg.h>
Expand Down Expand Up @@ -270,7 +270,7 @@ static void maybe_send_stfu(struct peer *peer)
if (!peer->stfu_sent[LOCAL] && !pending_updates(peer->channel, LOCAL, false)) {
u8 *msg = towire_stfu(NULL, &peer->channel_id,
peer->stfu_initiator == LOCAL);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
peer->stfu_sent[LOCAL] = true;
}

Expand Down Expand Up @@ -517,7 +517,7 @@ static void send_announcement_signatures(struct peer *peer)
NULL, &peer->channel_id, &peer->short_channel_ids[LOCAL],
&peer->announcement_node_sigs[LOCAL],
&peer->announcement_bitcoin_sigs[LOCAL]);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}

/* Tentatively create a channel_announcement, possibly with invalid
Expand Down Expand Up @@ -971,7 +971,7 @@ static void maybe_send_shutdown(struct peer *peer)

msg = towire_shutdown(NULL, &peer->channel_id, peer->final_scriptpubkey,
tlvs);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
peer->send_shutdown = false;
peer->shutdown_sent[LOCAL] = true;
billboard_update(peer);
Expand Down Expand Up @@ -1124,7 +1124,7 @@ static void send_ping(struct peer *peer)
exit(0);
}

sync_crypto_write_no_delay(peer->pps, take(make_ping(NULL, 1, 0)));
peer_write_no_delay(peer->pps, take(make_ping(NULL, 1, 0)));
peer->expecting_pong = PONG_EXPECTED_PROBING;
set_ping_timer(peer);
}
Expand Down Expand Up @@ -1326,7 +1326,7 @@ static void send_commit(struct peer *peer)

msg = towire_update_fee(NULL, &peer->channel_id,
feerate_target);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}
}

Expand All @@ -1342,7 +1342,7 @@ static void send_commit(struct peer *peer)
&peer->channel_id,
our_blockheight);

sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}
}

Expand Down Expand Up @@ -1416,7 +1416,7 @@ static void send_commit(struct peer *peer)
msg = towire_commitment_signed(NULL, &peer->channel_id,
&commit_sig.s,
raw_sigs(tmpctx, htlc_sigs));
sync_crypto_write_no_delay(peer->pps, take(msg));
peer_write_no_delay(peer->pps, take(msg));

maybe_send_shutdown(peer);

Expand Down Expand Up @@ -1584,7 +1584,7 @@ static void send_revocation(struct peer *peer,
WIRE_CHANNELD_GOT_COMMITSIG_REPLY);

/* Now we can finally send revoke_and_ack to peer */
sync_crypto_write_no_delay(peer->pps, take(msg));
peer_write_no_delay(peer->pps, take(msg));
}

static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
Expand Down Expand Up @@ -2361,7 +2361,7 @@ static void resend_revoke(struct peer *peer)
struct pubkey point;
/* Current commit is peer->next_index[LOCAL]-1, revoke prior */
u8 *msg = make_revocation_msg(peer, peer->next_index[LOCAL]-2, &point);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}

static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
Expand All @@ -2387,7 +2387,7 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
peer_failed_warn(peer->pps, &peer->channel_id,
"HTLC %"PRIu64" state %s not failed/fulfilled",
h->id, htlc_state_name(h->state));
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}

static int cmp_changed_htlc_id(const struct changed_htlc *a,
Expand Down Expand Up @@ -2490,20 +2490,20 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
, tlvs
#endif
);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}
}

/* Make sure they have the correct fee and blockheight. */
if (peer->channel->opener == LOCAL) {
msg = towire_update_fee(NULL, &peer->channel_id,
channel_feerate(peer->channel, REMOTE));
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));

if (peer->channel->lease_expiry > 0) {
msg = towire_update_blockheight(NULL, &peer->channel_id,
channel_blockheight(peer->channel, REMOTE));
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}
}

Expand All @@ -2517,7 +2517,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
msg = towire_commitment_signed(NULL, &peer->channel_id,
&commit_sig.s,
raw_sigs(tmpctx, htlc_sigs));
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));

/* If we have already received the revocation for the previous, the
* other side shouldn't be asking for a retransmit! */
Expand Down Expand Up @@ -2899,7 +2899,7 @@ static void peer_reconnect(struct peer *peer,
);
}

sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));

peer_billboard(false, "Sent reestablish, waiting for theirs");
bool soft_error = peer->funding_locked[REMOTE]
Expand All @@ -2917,7 +2917,7 @@ static void peer_reconnect(struct peer *peer,
* before we've reestablished channel). */
do {
clean_tmpctx();
msg = sync_crypto_read(tmpctx, peer->pps);
msg = peer_read(tmpctx, peer->pps);
} while (channeld_handle_custommsg(msg) ||
handle_peer_gossip_or_error(peer->pps, &peer->channel_id, soft_error,
msg) ||
Expand Down Expand Up @@ -3003,7 +3003,7 @@ static void peer_reconnect(struct peer *peer,
msg = towire_funding_locked(NULL,
&peer->channel_id,
&peer->next_local_per_commit);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}

/* Note: next_index is the index of the current commit we're working
Expand Down Expand Up @@ -3305,7 +3305,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
msg = towire_funding_locked(NULL,
&peer->channel_id,
&peer->next_local_per_commit);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));

peer->funding_locked[LOCAL] = true;
}
Expand Down Expand Up @@ -3371,7 +3371,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
, tlvs
#endif
);
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
start_commit_timer(peer);
/* Tell the master. */
msg = towire_channeld_offer_htlc_reply(NULL, peer->htlc_id,
Expand Down Expand Up @@ -3604,7 +3604,7 @@ static void handle_send_error(struct peer *peer, const u8 *msg)
if (!fromwire_channeld_send_error(msg, msg, &reason))
master_badmsg(WIRE_CHANNELD_SEND_ERROR, msg);
status_debug("Send error reason: %s", reason);
sync_crypto_write(peer->pps,
peer_write(peer->pps,
take(towire_errorfmt(NULL, &peer->channel_id,
"%s", reason)));

Expand Down Expand Up @@ -3632,7 +3632,7 @@ static void handle_send_ping(struct peer *peer, const u8 *msg)
if (tal_count(ping) > 65535)
status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping");

sync_crypto_write_no_delay(peer->pps, take(ping));
peer_write_no_delay(peer->pps, take(ping));

/* Since we're doing this manually, kill and restart timer. */
status_debug("sending ping expecting %sresponse",
Expand Down Expand Up @@ -3714,7 +3714,7 @@ static void channeld_send_custommsg(struct peer *peer, const u8 *msg)
u8 *inner;
if (!fromwire_custommsg_out(tmpctx, msg, &inner))
master_badmsg(WIRE_CUSTOMMSG_OUT, msg);
sync_crypto_write(peer->pps, take(inner));
peer_write(peer->pps, take(inner));
}

static void req_in(struct peer *peer, const u8 *msg)
Expand Down Expand Up @@ -4012,7 +4012,7 @@ static void init_channel(struct peer *peer)

/* If we have a messages to send, send them immediately */
if (fwd_msg)
sync_crypto_write(peer->pps, take(fwd_msg));
peer_write(peer->pps, take(fwd_msg));

/* Reenable channel */
channel_announcement_negotiate(peer);
Expand All @@ -4025,7 +4025,7 @@ static void try_read_gossip_store(struct peer *peer)
u8 *msg = gossip_store_next(tmpctx, peer->pps);

if (msg)
sync_crypto_write(peer->pps, take(msg));
peer_write(peer->pps, take(msg));
}

int main(int argc, char *argv[])
Expand Down Expand Up @@ -4146,7 +4146,7 @@ int main(int argc, char *argv[])
req_in(peer, msg);
} else if (FD_ISSET(peer->pps->peer_fd, &rfds)) {
/* This could take forever, but who cares? */
msg = sync_crypto_read(tmpctx, peer->pps);
msg = peer_read(tmpctx, peer->pps);
peer_in(peer, msg);
} else if (FD_ISSET(peer->pps->gossip_fd, &rfds)) {
msg = wire_sync_read(tmpctx, peer->pps->gossip_fd);
Expand Down
8 changes: 4 additions & 4 deletions closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ CLOSINGD_COMMON_OBJS := \
common/channel_id.o \
common/close_tx.o \
common/crypto_state.o \
common/crypto_sync.o \
common/cryptomsg.o \
common/daemon.o \
common/daemon_conn.o \
common/dev_disconnect.o \
common/derive_basepoints.o \
common/peer_status_wiregen.o \
common/status_wiregen.o \
common/dev_disconnect.o \
common/gossip_rcvd_filter.o \
common/gossip_store.o \
common/htlc_wire.o \
Expand All @@ -45,11 +42,14 @@ CLOSINGD_COMMON_OBJS := \
common/onionreply.o \
common/peer_billboard.o \
common/peer_failed.o \
common/peer_io.o \
common/peer_status_wiregen.o \
common/per_peer_state.o \
common/permute_tx.o \
common/ping.o \
common/psbt_open.o \
common/pseudorand.o \
common/status_wiregen.o \
common/read_peer_msg.o \
common/setup.o \
common/socket_close.o \
Expand Down
4 changes: 2 additions & 2 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <closingd/closingd_wiregen.h>
#include <common/close_tx.h>
#include <common/closing_fee.h>
#include <common/crypto_sync.h>
#include <common/derive_basepoints.h>
#include <common/htlc.h>
#include <common/memleak.h>
#include <common/peer_billboard.h>
#include <common/peer_failed.h>
#include <common/peer_io.h>
#include <common/per_peer_state.h>
#include <common/read_peer_msg.h>
#include <common/socket_close.h>
Expand Down Expand Up @@ -214,7 +214,7 @@ static void send_offer(struct per_peer_state *pps,
msg = towire_closing_signed(NULL, channel_id, fee_to_offer, &our_sig.s,
close_tlvs);

sync_crypto_write(pps, take(msg));
peer_write(pps, take(msg));
}

static void tell_master_their_offer(const struct bitcoin_signature *their_sig,
Expand Down
14 changes: 7 additions & 7 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ COMMON_SRC_NOGEN := \
common/bigsize.c \
common/billboard.c \
common/bip32.c \
common/blinding.c \
common/blindedpath.c \
common/blinding.c \
common/blockheight_states.c \
common/bolt11.c \
common/bolt11_json.c \
Expand All @@ -19,11 +19,10 @@ COMMON_SRC_NOGEN := \
common/channel_config.c \
common/channel_id.c \
common/channel_type.c \
common/coin_mvt.c \
common/close_tx.c \
common/coin_mvt.c \
common/configdir.c \
common/crypto_state.c \
common/crypto_sync.c \
common/cryptomsg.c \
common/daemon.c \
common/daemon_conn.c \
Expand All @@ -38,6 +37,7 @@ COMMON_SRC_NOGEN := \
common/fp16.c \
common/gossip_rcvd_filter.c \
common/gossip_store.c \
common/gossmap.c \
common/hash_u5.c \
common/hmac.c \
common/hsm_encryption.c \
Expand All @@ -54,23 +54,23 @@ COMMON_SRC_NOGEN := \
common/json_tok.c \
common/key_derive.c \
common/keyset.c \
common/gossmap.c \
common/lease_rates.c \
common/memleak.c \
common/msg_queue.c \
common/node_id.c \
common/onion.c \
common/onionreply.c \
common/param.c \
common/penalty_base.c \
common/per_peer_state.c \
common/peer_billboard.c \
common/peer_failed.c \
common/peer_io.c \
common/penalty_base.c \
common/per_peer_state.c \
common/permute_tx.c \
common/ping.c \
common/private_channel_announcement.c \
common/psbt_internal.c \
common/psbt_open.c \
common/private_channel_announcement.c \
common/pseudorand.c \
common/random_select.c \
common/read_peer_msg.c \
Expand Down
19 changes: 0 additions & 19 deletions common/crypto_sync.h

This file was deleted.

Loading

0 comments on commit ce8b694

Please sign in to comment.