Skip to content

Commit

Permalink
opening: pass two messages to channeld to send to peer
Browse files Browse the repository at this point in the history
v2 of channel establishment, in the accpeter case, now sends 2 messages
to our peer after saving the information to disk (our commitment
signatures and our funding transaction signatures)
  • Loading branch information
niftynei committed Aug 25, 2020
1 parent a288097 commit 01f9955
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions channeld/channel_wire.csv
Expand Up @@ -57,6 +57,8 @@ msgdata,channel_init,final_scriptpubkey,u8,final_scriptpubkey_len
msgdata,channel_init,flags,u8,
msgdata,channel_init,init_peer_pkt_len,u16,
msgdata,channel_init,init_peer_pkt,u8,init_peer_pkt_len
msgdata,channel_init,init_peer_pkt_2_len,u16,
msgdata,channel_init,init_peer_pkt_2,u8,init_peer_pkt_2_len
msgdata,channel_init,reached_announce_depth,bool,
msgdata,channel_init,last_remote_secret,secret,
msgdata,channel_init,flen,u16,
Expand Down
13 changes: 8 additions & 5 deletions channeld/channeld.c
Expand Up @@ -3148,7 +3148,7 @@ static void init_channel(struct peer *peer)
enum side opener;
struct existing_htlc **htlcs;
bool reconnected;
u8 *funding_signed;
u8 *fwd_msg_1, *fwd_msg_2;
const u8 *msg;
struct fee_states *fee_states;
u32 minimum_depth;
Expand Down Expand Up @@ -3209,7 +3209,8 @@ static void init_channel(struct peer *peer)
&peer->shutdown_sent[REMOTE],
&peer->final_scriptpubkey,
&peer->channel_flags,
&funding_signed,
&fwd_msg_1,
&fwd_msg_2,
&peer->announce_depth_reached,
&last_remote_per_commit_secret,
&peer->their_features,
Expand Down Expand Up @@ -3311,9 +3312,11 @@ static void init_channel(struct peer *peer)
if (reconnected)
peer_reconnect(peer, &last_remote_per_commit_secret);

/* If we have a funding_signed message, send that immediately */
if (funding_signed)
sync_crypto_write(peer->pps, take(funding_signed));
/* If we have a messages to send, send them immediately */
if (fwd_msg_1)
sync_crypto_write(peer->pps, take(fwd_msg_1));
if (fwd_msg_2)
sync_crypto_write(peer->pps, take(fwd_msg_2));

/* Reenable channel */
channel_announcement_negotiate(peer);
Expand Down
7 changes: 4 additions & 3 deletions lightningd/channel_control.c
Expand Up @@ -427,7 +427,8 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
void peer_start_channeld(struct channel *channel,
struct channel_id *channel_id,
struct per_peer_state *pps,
const u8 **fwd_msgs,
const u8 *fwd_msg_1,
const u8 *fwd_msg_2,
bool reconnected)
{
u8 *initmsg;
Expand Down Expand Up @@ -568,8 +569,8 @@ void peer_start_channeld(struct channel *channel,
channel->shutdown_scriptpubkey[REMOTE] != NULL,
channel->shutdown_scriptpubkey[LOCAL],
channel->channel_flags,
/* FIXME: pass set of msgs */
fwd_msgs ? fwd_msgs[0] : NULL,
fwd_msg_1,
fwd_msg_2,
reached_announce_depth,
&last_remote_per_commit_secret,
channel->peer->their_features,
Expand Down
3 changes: 2 additions & 1 deletion lightningd/channel_control.h
Expand Up @@ -13,7 +13,8 @@ struct per_peer_state;
void peer_start_channeld(struct channel *channel,
struct channel_id *channel_id,
struct per_peer_state *pps,
const u8 **fwd_msgs,
const u8 *fwd_msg_1,
const u8 *fwd_msg_2,
bool reconnected);

/* Returns true if subd told, otherwise false. */
Expand Down
8 changes: 4 additions & 4 deletions lightningd/opening_control.c
Expand Up @@ -389,7 +389,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
wallet_penalty_base_add(ld->wallet, channel->dbid, pbase);

funding_success(channel);
peer_start_channeld(channel, &fc->cid, pps, NULL, false);
peer_start_channeld(channel, &fc->cid, pps, NULL, NULL, false);

cleanup:
subd_release_channel(openingd, fc->uc);
Expand All @@ -403,7 +403,7 @@ static void opening_fundee_finished(struct subd *openingd,
const int *fds,
struct uncommitted_channel *uc)
{
const u8 *msgs[1];
const u8 *fwd_msg;
struct channel_id cid;
struct channel_info channel_info;
struct bitcoin_signature remote_commit_sig;
Expand Down Expand Up @@ -443,7 +443,7 @@ static void opening_fundee_finished(struct subd *openingd,
&push,
&channel_flags,
&feerate,
cast_const2(u8 **, msgs),
cast_const2(u8 **, &fwd_msg),
&uc->our_config.channel_reserve,
&local_upfront_shutdown_script,
&remote_upfront_shutdown_script)) {
Expand Down Expand Up @@ -501,7 +501,7 @@ static void opening_fundee_finished(struct subd *openingd,
derive_channel_id(&cid, &channel->funding_txid, funding_outnum);

/* On to normal operation! */
peer_start_channeld(channel, &cid, pps, fwd_msg, false);
peer_start_channeld(channel, &cid, pps, fwd_msg, NULL, false);

subd_release_channel(openingd, uc);
uc->open_daemon = NULL;
Expand Down
2 changes: 1 addition & 1 deletion lightningd/peer_control.c
Expand Up @@ -970,7 +970,7 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload STEALS,

channel->peer->addr = addr;
peer_start_channeld(channel, &cid, payload->pps,
NULL, true);
NULL, NULL, true);
tal_free(payload);
return;

Expand Down
3 changes: 2 additions & 1 deletion lightningd/test/run-invoice-select-inchan.c
Expand Up @@ -430,7 +430,8 @@ void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDE
void peer_start_channeld(struct channel *channel UNNEEDED,
struct channel_id *channel_id UNNEEDED,
struct per_peer_state *pps UNNEEDED,
const u8 **fwd_msgs UNNEEDED,
const u8 *fwd_msg_1 UNNEEDED,
const u8 *fwd_msg_2 UNNEEDED,
bool reconnected UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_closingd */
Expand Down
3 changes: 2 additions & 1 deletion wallet/test/run-wallet.c
Expand Up @@ -576,7 +576,8 @@ void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDE
void peer_start_channeld(struct channel *channel UNNEEDED,
struct channel_id *channel_id UNNEEDED,
struct per_peer_state *pps UNNEEDED,
const u8 **fwd_msgs UNNEEDED,
const u8 *fwd_msg_1 UNNEEDED,
const u8 *fwd_msg_2 UNNEEDED,
bool reconnected UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_closingd */
Expand Down

0 comments on commit 01f9955

Please sign in to comment.