diff --git a/channeld/Makefile b/channeld/Makefile index 6f26ef416..4b660bb64 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -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 \ @@ -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 \ diff --git a/channeld/channeld.c b/channeld/channeld.c index de1a4741b..86d5f015b 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -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; } @@ -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 @@ -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); @@ -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); } @@ -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)); } } @@ -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)); } } @@ -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); @@ -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) @@ -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) @@ -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, @@ -2490,7 +2490,7 @@ 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)); } } @@ -2498,12 +2498,12 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) 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)); } } @@ -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! */ @@ -2899,7 +2899,7 @@ skip_tlvs: ); } - 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] @@ -2917,7 +2917,7 @@ skip_tlvs: * 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) || @@ -3003,7 +3003,7 @@ got_reestablish: 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 @@ -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; } @@ -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, @@ -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))); @@ -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", @@ -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) @@ -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); @@ -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[]) @@ -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); diff --git a/closingd/Makefile b/closingd/Makefile index 6fca67f75..d641d7857 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -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 \ @@ -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 \ diff --git a/closingd/closingd.c b/closingd/closingd.c index b3f54e3b7..84dc438b5 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -6,12 +6,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -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, diff --git a/common/Makefile b/common/Makefile index 2f5368ad6..d4f9ae8d3 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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 \ @@ -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 \ @@ -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 \ @@ -54,7 +54,6 @@ 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 \ @@ -62,15 +61,16 @@ COMMON_SRC_NOGEN := \ 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 \ diff --git a/common/crypto_sync.h b/common/crypto_sync.h deleted file mode 100644 index 29816289d..000000000 --- a/common/crypto_sync.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef LIGHTNING_COMMON_CRYPTO_SYNC_H -#define LIGHTNING_COMMON_CRYPTO_SYNC_H -#include "config.h" -#include -#include - -struct per_peer_state; - -/* Exits with peer_failed_connection_lost() if write fails. */ -void sync_crypto_write(struct per_peer_state *pps, const void *msg TAKES); - -/* Same, but disabled nagle for this message. */ -void sync_crypto_write_no_delay(struct per_peer_state *pps, - const void *msg TAKES); - -/* Exits with peer_failed_connection_lost() if can't read packet. */ -u8 *sync_crypto_read(const tal_t *ctx, struct per_peer_state *pps); - -#endif /* LIGHTNING_COMMON_CRYPTO_SYNC_H */ diff --git a/common/peer_failed.c b/common/peer_failed.c index 97ec96cfa..909161b65 100644 --- a/common/peer_failed.c +++ b/common/peer_failed.c @@ -2,9 +2,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -38,7 +38,7 @@ peer_failed(struct per_peer_state *pps, } else { msg = towire_errorfmt(desc, channel_id, "%s", desc); } - sync_crypto_write(pps, msg); + peer_write(pps, msg); /* Tell master the error so it can re-xmit. */ msg = towire_status_peer_error(NULL, channel_id, diff --git a/common/crypto_sync.c b/common/peer_io.c similarity index 89% rename from common/crypto_sync.c rename to common/peer_io.c index 58dc8b2a0..43b9a027e 100644 --- a/common/crypto_sync.c +++ b/common/peer_io.c @@ -1,9 +1,9 @@ #include "config.h" #include -#include #include #include #include +#include #include #include #include @@ -15,7 +15,7 @@ #include #include -void sync_crypto_write(struct per_peer_state *pps, const void *msg TAKES) +void peer_write(struct per_peer_state *pps, const void *msg TAKES) { #if DEVELOPER bool post_sabotage = false, post_close; @@ -64,8 +64,7 @@ void sync_crypto_write(struct per_peer_state *pps, const void *msg TAKES) * afterwards. Even if this is wrong on other non-Linux platforms, it * only means one extra packet. */ -void sync_crypto_write_no_delay(struct per_peer_state *pps, - const void *msg TAKES) +void peer_write_no_delay(struct per_peer_state *pps, const void *msg TAKES) { int val; int opt; @@ -92,13 +91,13 @@ void sync_crypto_write_no_delay(struct per_peer_state *pps, complained = true; } } - sync_crypto_write(pps, msg); + peer_write(pps, msg); val = 0; setsockopt(pps->peer_fd, IPPROTO_TCP, opt, &val, sizeof(val)); } -u8 *sync_crypto_read(const tal_t *ctx, struct per_peer_state *pps) +u8 *peer_read(const tal_t *ctx, struct per_peer_state *pps) { u8 *dec = wire_sync_read(ctx, pps->peer_fd); if (!dec) diff --git a/common/peer_io.h b/common/peer_io.h new file mode 100644 index 000000000..0ca6670ac --- /dev/null +++ b/common/peer_io.h @@ -0,0 +1,18 @@ +#ifndef LIGHTNING_COMMON_PEER_IO_H +#define LIGHTNING_COMMON_PEER_IO_H +#include "config.h" +#include +#include + +struct per_peer_state; + +/* Exits with peer_failed_connection_lost() if write fails. */ +void peer_write(struct per_peer_state *pps, const void *msg TAKES); + +/* Same, but disabled nagle for this message. */ +void peer_write_no_delay(struct per_peer_state *pps, const void *msg TAKES); + +/* Exits with peer_failed_connection_lost() if can't read packet. */ +u8 *peer_read(const tal_t *ctx, struct per_peer_state *pps); + +#endif /* LIGHTNING_COMMON_PEER_IO_H */ diff --git a/common/read_peer_msg.c b/common/read_peer_msg.c index f40c15c46..a1c0405e4 100644 --- a/common/read_peer_msg.c +++ b/common/read_peer_msg.c @@ -1,10 +1,10 @@ #include "config.h" #include #include -#include #include #include #include +#include #include #include #include @@ -49,7 +49,7 @@ u8 *peer_or_gossip_sync_read(const tal_t *ctx, } if (FD_ISSET(pps->peer_fd, &readfds)) { - msg = sync_crypto_read(ctx, pps); + msg = peer_read(ctx, pps); *from_gossipd = false; return msg; } @@ -121,10 +121,10 @@ void handle_gossip_msg(struct per_peer_state *pps, const u8 *msg TAKES) /* Gossipd can send us gossip messages, OR warnings */ if (fromwire_peektype(gossip) == WIRE_WARNING) { - sync_crypto_write(pps, gossip); + peer_write(pps, gossip); peer_failed_connection_lost(); } else { - sync_crypto_write(pps, gossip); + peer_write(pps, gossip); } } @@ -141,11 +141,11 @@ bool handle_timestamp_filter(struct per_peer_state *pps, const u8 *msg TAKES) } if (!bitcoin_blkid_eq(&chainparams->genesis_blockhash, &chain_hash)) { - sync_crypto_write(pps, - take(towire_warningfmt(NULL, NULL, - "gossip_timestamp_filter" - " for bad chain: %s", - tal_hex(tmpctx, take(msg))))); + peer_write(pps, + take(towire_warningfmt(NULL, NULL, + "gossip_timestamp_filter" + " for bad chain: %s", + tal_hex(tmpctx, take(msg))))); return true; } @@ -181,7 +181,7 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps, return true; else if (check_ping_make_pong(NULL, msg, &pong)) { if (pong) - sync_crypto_write(pps, take(pong)); + peer_write(pps, take(pong)); return true; } else if (is_msg_for_gossipd(msg)) { if (is_msg_gossip_broadcast(msg)) diff --git a/openingd/Makefile b/openingd/Makefile index 091f51ca1..0ff843e47 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -42,7 +42,6 @@ OPENINGD_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 \ @@ -50,8 +49,6 @@ OPENINGD_COMMON_OBJS := \ common/dev_disconnect.o \ common/features.o \ common/fee_states.o \ - common/status_wiregen.o \ - common/peer_status_wiregen.o \ common/gossip_rcvd_filter.o \ common/gossip_store.o \ common/htlc_state.o \ @@ -65,10 +62,12 @@ OPENINGD_COMMON_OBJS := \ common/msg_queue.o \ common/node_id.o \ common/onionreply.o \ - common/penalty_base.o \ - common/per_peer_state.o \ common/peer_billboard.o \ common/peer_failed.o \ + common/peer_io.o \ + common/peer_status_wiregen.o \ + common/penalty_base.o \ + common/per_peer_state.o \ common/permute_tx.o \ common/ping.o \ common/psbt_internal.o \ @@ -79,6 +78,7 @@ OPENINGD_COMMON_OBJS := \ common/shutdown_scriptpubkey.o \ common/status.o \ common/status_wire.o \ + common/status_wiregen.o \ common/subdaemon.o \ common/type_to_string.o \ common/utils.o \ diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 78c87e651..ed2eb2872 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -396,7 +396,7 @@ static void send_shutdown(struct state *state, const u8 *final_scriptpubkey) /* FIXME: send wrong_funding */ msg = towire_shutdown(NULL, &state->channel_id, final_scriptpubkey, NULL); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); state->shutdown_sent[LOCAL] = true; } @@ -904,7 +904,7 @@ static void dualopend_send_custommsg(struct state *state, const u8 *msg) u8 *inner; if (!fromwire_custommsg_out(tmpctx, msg, &inner)) master_badmsg(WIRE_CUSTOMMSG_OUT, msg); - sync_crypto_write(state->pps, take(inner)); + peer_write(state->pps, take(inner)); } static u8 *psbt_to_tx_sigs_msg(const tal_t *ctx, @@ -1043,7 +1043,7 @@ static void handle_send_tx_sigs(struct state *state, const u8 *msg) /* Send our sigs to peer */ msg = psbt_to_tx_sigs_msg(tmpctx, state, tx_state->psbt); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); /* Notify lightningd that we've sent sigs */ wire_sync_write(REQ_FD, take(towire_dualopend_tx_sigs_sent(NULL))); @@ -1115,7 +1115,7 @@ static bool send_next(struct state *state, } sendmsg: - sync_crypto_write(state->pps, msg); + peer_write(state->pps, msg); return !finished; } @@ -1248,10 +1248,10 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state) peer_wire_name(fromwire_peektype(msg)), type_to_string(tmpctx, struct channel_id, &actual)); - sync_crypto_write(state->pps, - take(towire_errorfmt(NULL, &actual, - "Multiple channels" - " unsupported"))); + peer_write(state->pps, + take(towire_errorfmt(NULL, &actual, + "Multiple channels" + " unsupported"))); tal_free(msg); continue; } @@ -1976,10 +1976,10 @@ static u8 *accepter_commits(struct state *state, master_badmsg(WIRE_DUALOPEND_SEND_TX_SIGS, msg); /* Send our commitment sigs over now */ - sync_crypto_write(state->pps, - take(towire_commitment_signed(NULL, - &state->channel_id, - &local_sig.s, NULL))); + peer_write(state->pps, + take(towire_commitment_signed(NULL, + &state->channel_id, + &local_sig.s, NULL))); return msg; } @@ -2333,7 +2333,7 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) &state->our_points.revocation, &state->their_points.revocation); - sync_crypto_write(state->pps, msg); + peer_write(state->pps, msg); peer_billboard(false, "channel open: accept sent, waiting for reply"); /* This is unused in this flow. We re-use @@ -2533,7 +2533,7 @@ static u8 *opener_commits(struct state *state, msg = towire_commitment_signed(tmpctx, &state->channel_id, &local_sig.s, NULL); - sync_crypto_write(state->pps, msg); + peer_write(state->pps, msg); peer_billboard(false, "channel open: commitment sent, waiting for reply"); /* Wait for the peer to send us our commitment tx signature */ @@ -2735,7 +2735,7 @@ static void opener_start(struct state *state, u8 *msg) state->channel_flags, open_tlv); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); /* This is usually a very transient state... */ peer_billboard(false, "channel open: offered, waiting for" @@ -3151,7 +3151,7 @@ static void rbf_local_start(struct state *state, u8 *msg) tx_state->tx_locktime, tx_state->feerate_per_kw_funding); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); /* ... since their reply should be immediate. */ msg = opening_negotiate_msg(tmpctx, state); @@ -3360,7 +3360,7 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) state->our_role == TX_INITIATOR ? tx_state->opener_funding : tx_state->accepter_funding); - sync_crypto_write(state->pps, msg); + peer_write(state->pps, msg); peer_billboard(false, "channel rbf: ack sent, waiting for reply"); /* We merge with RBF's we've initiated now */ @@ -3394,7 +3394,7 @@ static void send_funding_locked(struct state *state) msg = towire_funding_locked(NULL, &state->channel_id, &next_local_per_commit); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); state->funding_locked[LOCAL] = true; billboard_update(state); @@ -3440,7 +3440,7 @@ static void try_read_gossip_store(struct state *state) u8 *msg = gossip_store_next(tmpctx, state->pps); if (msg) - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); } /* Try to handle a custommsg Returns true if it was a custom message and has @@ -3550,7 +3550,7 @@ static void do_reconnect_dance(struct state *state) , tlvs #endif ); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); peer_billboard(false, "Sent reestablish, waiting for theirs"); bool soft_error = state->funding_locked[REMOTE] @@ -3561,7 +3561,7 @@ static void do_reconnect_dance(struct state *state) * before we've reestablished channel). */ do { clean_tmpctx(); - msg = sync_crypto_read(tmpctx, state->pps); + msg = peer_read(tmpctx, state->pps); } while (dualopend_handle_custommsg(msg) || handle_peer_gossip_or_error(state->pps, &state->channel_id, @@ -3616,7 +3616,7 @@ static void do_reconnect_dance(struct state *state) if (psbt_side_finalized(tx_state->psbt, state->our_role) && !state->funding_locked[REMOTE]) { msg = psbt_to_tx_sigs_msg(NULL, state, tx_state->psbt); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); } if (state->funding_locked[LOCAL]) { @@ -3701,7 +3701,7 @@ static u8 *handle_master_in(struct state *state) * surprise. */ static u8 *handle_peer_in(struct state *state) { - u8 *msg = sync_crypto_read(tmpctx, state->pps); + u8 *msg = peer_read(tmpctx, state->pps); enum peer_wire t = fromwire_peektype(msg); struct channel_id channel_id; @@ -3784,14 +3784,14 @@ static u8 *handle_peer_in(struct state *state) &state->channel_id, false, msg)) return NULL; - sync_crypto_write(state->pps, - take(towire_warningfmt(NULL, - extract_channel_id(msg, - &channel_id) ? - &channel_id : NULL, - "Unexpected message %s: %s", - peer_wire_name(t), - tal_hex(tmpctx, msg)))); + peer_write(state->pps, + take(towire_warningfmt(NULL, + extract_channel_id(msg, + &channel_id) ? + &channel_id : NULL, + "Unexpected message %s: %s", + peer_wire_name(t), + tal_hex(tmpctx, msg)))); /* FIXME: We don't actually want master to try to send an * error, since peer is transient. This is a hack. diff --git a/openingd/openingd.c b/openingd/openingd.c index fede6c811..72471da3f 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -150,7 +150,7 @@ static void negotiation_failed(struct state *state, bool am_opener, msg = towire_errorfmt(NULL, &state->channel_id, "You gave bad parameters: %s", errmsg); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); negotiation_aborted(state, am_opener, errmsg); } @@ -257,10 +257,10 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state, peer_wire_name(fromwire_peektype(msg)), type_to_string(tmpctx, struct channel_id, &actual)); - sync_crypto_write(state->pps, - take(towire_errorfmt(NULL, &actual, - "Multiple channels" - " unsupported"))); + peer_write(state->pps, + take(towire_errorfmt(NULL, &actual, + "Multiple channels" + " unsupported"))); tal_free(msg); continue; } @@ -396,7 +396,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) &state->first_per_commitment_point[LOCAL], channel_flags, open_tlvs); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); /* This is usually a very transient state... */ peer_billboard(false, @@ -640,7 +640,7 @@ static bool funder_finalize_channel_setup(struct state *state, &state->funding.txid, state->funding.n, &sig->s); - sync_crypto_write(state->pps, msg); + peer_write(state->pps, msg); /* BOLT #2: * @@ -1050,7 +1050,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &state->first_per_commitment_point[LOCAL], accept_tlvs); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); peer_billboard(false, "Incoming channel: accepted, now waiting for them to create funding tx"); @@ -1258,7 +1258,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) * surprise. */ static u8 *handle_peer_in(struct state *state) { - u8 *msg = sync_crypto_read(tmpctx, state->pps); + u8 *msg = peer_read(tmpctx, state->pps); enum peer_wire t = fromwire_peektype(msg); struct channel_id channel_id; bool extracted; @@ -1289,7 +1289,7 @@ static u8 *handle_peer_in(struct state *state) &channel_id, msg, state->pps); } - sync_crypto_write(state->pps, + peer_write(state->pps, take(towire_warningfmt(NULL, extracted ? &channel_id : NULL, "Unexpected message %s: %s", @@ -1349,7 +1349,7 @@ static void openingd_send_custommsg(struct state *state, const u8 *msg) u8 *inner; if (!fromwire_custommsg_out(tmpctx, msg, &inner)) master_badmsg(WIRE_CUSTOMMSG_OUT, msg); - sync_crypto_write(state->pps, take(inner)); + peer_write(state->pps, take(inner)); } /* Standard lightningd-fd-is-ready-to-read demux code. Again, we could hang @@ -1393,7 +1393,7 @@ static u8 *handle_master_in(struct state *state) master_badmsg(WIRE_OPENINGD_FUNDER_CANCEL, msg); msg = towire_errorfmt(NULL, &state->channel_id, "Channel open canceled by us"); - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); negotiation_aborted(state, true, "Channel open canceled by RPC"); return NULL; case WIRE_OPENINGD_DEV_MEMLEAK: @@ -1432,7 +1432,7 @@ static void try_read_gossip_store(struct state *state) u8 *msg = gossip_store_next(tmpctx, state->pps); if (msg) - sync_crypto_write(state->pps, take(msg)); + peer_write(state->pps, take(msg)); } int main(int argc, char *argv[])