Skip to content

Commit

Permalink
Channeld: Add new wire type:channel_got_announcement
Browse files Browse the repository at this point in the history
Channeld sends announcement signatures to Master by this message.
When Channeld receive a new channel announcement msg, (After channel locking)it will sends announcement signatures to Master by this message.
  • Loading branch information
trueptolemy committed May 19, 2019
1 parent 965826f commit 8a4bfb2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
5 changes: 5 additions & 0 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ channel_fail_fallen_behind,,remote_per_commitment_point,struct pubkey
channel_specific_feerates,1029
channel_specific_feerates,,feerate_base,u32
channel_specific_feerates,,feerate_ppm,u32

# When we receive announcement_signatures for channel announce
channel_got_announcement,1017
channel_got_announcement,,remote_ann_node_sig,secp256k1_ecdsa_signature
channel_got_announcement,,remote_ann_bitcoin_sig,secp256k1_ecdsa_signature
19 changes: 16 additions & 3 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ static void announce_channel(struct peer *peer)
{
u8 *cannounce;

check_short_ids_match(peer);

cannounce = create_channel_announcement(tmpctx, peer);

wire_sync_write(GOSSIP_FD, cannounce);
Expand Down Expand Up @@ -493,15 +491,29 @@ static void channel_announcement_negotiate(struct peer *peer)
* has been sent and received AND the funding transaction has at least six confirmations.
*/
if (peer->announce_depth_reached && !peer->have_sigs[LOCAL]) {
/* When we reenable the channel, we will also send the announcement to remote peer, and
* receive the remote announcement reply. But we will rebuild the channel with announcement
* from the DB directly, other than waiting for the remote announcement reply.
*/
send_announcement_signatures(peer);
peer->have_sigs[LOCAL] = true;
billboard_update(peer);
}

/* If we've completed the signature exchange, we can send a real
* announcement, otherwise we send a temporary one */
if (peer->have_sigs[LOCAL] && peer->have_sigs[REMOTE])
if (peer->have_sigs[LOCAL] && peer->have_sigs[REMOTE]) {
check_short_ids_match(peer);

/* After making sure short_channel_ids match, we can send remote
* announcement to MASTER. */
wire_sync_write(MASTER_FD,
take(towire_channel_got_announcement(NULL,
&peer->announcement_node_sigs[REMOTE],
&peer->announcement_bitcoin_sigs[REMOTE])));

announce_channel(peer);
}
}

static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
Expand Down Expand Up @@ -2778,6 +2790,7 @@ static void req_in(struct peer *peer, const u8 *msg)
case WIRE_CHANNEL_GOT_COMMITSIG_REPLY:
case WIRE_CHANNEL_GOT_REVOKE_REPLY:
case WIRE_CHANNEL_GOT_FUNDING_LOCKED:
case WIRE_CHANNEL_GOT_ANNOUNCEMENT:
case WIRE_CHANNEL_GOT_SHUTDOWN:
case WIRE_CHANNEL_SHUTDOWN_COMPLETE:
case WIRE_CHANNEL_DEV_REENABLE_COMMIT_REPLY:
Expand Down
28 changes: 28 additions & 0 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ static void peer_got_funding_locked(struct channel *channel, const u8 *msg)
lockin_complete(channel);
}

static void peer_got_announcement(struct channel *channel, const u8 *msg)
{
secp256k1_ecdsa_signature remote_ann_node_sig;
secp256k1_ecdsa_signature remote_ann_bitcoin_sig;

if(!(channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)) {
channel_internal_error(channel,
"No ANNOUNCE flag, no announcemnt signatures! %s",
tal_hex(tmpctx, msg));
}

if (!fromwire_channel_got_announcement(msg,
&remote_ann_node_sig,
&remote_ann_bitcoin_sig)) {
channel_internal_error(channel,
"bad channel_got_funding_locked %s",
tal_hex(tmpctx, msg));
return;
}

wallet_announcement_save(channel->peer->ld->wallet, channel->dbid,
&remote_ann_node_sig,
&remote_ann_bitcoin_sig);
}

static void peer_got_shutdown(struct channel *channel, const u8 *msg)
{
u8 *scriptpubkey;
Expand Down Expand Up @@ -219,6 +244,9 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
case WIRE_CHANNEL_GOT_FUNDING_LOCKED:
peer_got_funding_locked(sd->channel, msg);
break;
case WIRE_CHANNEL_GOT_ANNOUNCEMENT:
peer_got_announcement(sd->channel, msg);
break;
case WIRE_CHANNEL_GOT_SHUTDOWN:
peer_got_shutdown(sd->channel, msg);
break;
Expand Down

0 comments on commit 8a4bfb2

Please sign in to comment.