diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 57d90a953f06..50ae91207a8c 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -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 \ No newline at end of file diff --git a/channeld/channeld.c b/channeld/channeld.c index 96e8b837bbfc..2fd10a69c265 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -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); @@ -493,6 +491,10 @@ 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); @@ -500,8 +502,18 @@ static void channel_announcement_negotiate(struct peer *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) @@ -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: diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 894337862825..5304adf227b9 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -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; @@ -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;