diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e481ee737cf..c603b8b10e9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - plugin: the `connected` hook can now send an `error_message` to the rejected peer. - Protocol: we now enforce `option_upfront_shutdown_script` if a peer negotiates it. - JSON API: `listforwards` now includes the local_failed forwards with failcode (Issue [#2435](https://github.com/ElementsProject/lightning/issues/2435), PR [#2524](https://github.com/ElementsProject/lightning/pull/2524)) +- DB: Store the signatures of channel announcement sent from remote peer into DB, and init channel with signatures from DB directly when reenable the channel. +(Issue [#2409](https://github.com/ElementsProject/lightning/issues/2409)) ### Changed diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 50ae91207a8c..3b7bdc69bdeb 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -64,6 +64,8 @@ channel_init,,lflen,u16 channel_init,,localfeatures,lflen*u8 channel_init,,upfront_shutdown_script_len,u16 channel_init,,upfront_shutdown_script,upfront_shutdown_script_len*u8 +channel_init,,remote_ann_node_sig,?secp256k1_ecdsa_signature +channel_init,,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature # master->channeld funding hit new depth(funding locked if >= lock depth) channel_funding_depth,1002 diff --git a/channeld/channeld.c b/channeld/channeld.c index 2fd10a69c265..212105403f83 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2842,6 +2842,8 @@ static void init_channel(struct peer *peer) u32 feerate_per_kw[NUM_SIDES]; u32 minimum_depth; struct secret last_remote_per_commit_secret; + secp256k1_ecdsa_signature *remote_ann_node_sig; + secp256k1_ecdsa_signature *remote_ann_bitcoin_sig; assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK)); @@ -2896,7 +2898,9 @@ static void init_channel(struct peer *peer) &peer->announce_depth_reached, &last_remote_per_commit_secret, &peer->localfeatures, - &peer->remote_upfront_shutdown_script)) { + &peer->remote_upfront_shutdown_script, + &remote_ann_node_sig, + &remote_ann_bitcoin_sig)) { master_badmsg(WIRE_CHANNEL_INIT, msg); } @@ -2915,6 +2919,20 @@ static void init_channel(struct peer *peer) feerate_per_kw[LOCAL], feerate_per_kw[REMOTE], peer->feerate_min, peer->feerate_max); + if(remote_ann_node_sig && remote_ann_bitcoin_sig) { + peer->announcement_node_sigs[REMOTE] = *remote_ann_node_sig; + peer->announcement_bitcoin_sigs[REMOTE] = *remote_ann_bitcoin_sig; + peer->have_sigs[REMOTE] = true; + + tal_steal(tmpctx, remote_ann_node_sig); + tal_steal(tmpctx, remote_ann_bitcoin_sig); + /* Before we store announcement into DB, we have made sure + * remote short_channel_id matched the local. Now we initial + * it directly! + */ + peer->short_channel_ids[REMOTE] = peer->short_channel_ids[LOCAL]; + } + /* First commit is used for opening: if we've sent 0, we're on * index 1. */ assert(peer->next_index[LOCAL] > 0); diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 5304adf227b9..118e48701b04 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -303,6 +303,10 @@ void peer_start_channeld(struct channel *channel, const struct config *cfg = &ld->config; bool reached_announce_depth; struct secret last_remote_per_commit_secret; + secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig; + + remote_ann_node_sig = tal(tmpctx, secp256k1_ecdsa_signature); + remote_ann_bitcoin_sig = tal(tmpctx, secp256k1_ecdsa_signature); hsmfd = hsm_get_client_fd(ld, &channel->peer->id, channel->dbid, @@ -376,6 +380,13 @@ void peer_start_channeld(struct channel *channel, if (ld->config.ignore_fee_limits) log_debug(channel->log, "Ignoring fee limits!"); + if(!wallet_remote_ann_sigs_load(channel->peer->ld->wallet, channel->dbid, + &remote_ann_node_sig, &remote_ann_bitcoin_sig)) { + channel_fail_permanent(channel, + "Could not load remote announcement signatures"); + return; + } + initmsg = towire_channel_init(tmpctx, &get_chainparams(ld)->genesis_blockhash, &channel->funding_txid, @@ -425,7 +436,9 @@ void peer_start_channeld(struct channel *channel, reached_announce_depth, &last_remote_per_commit_secret, channel->peer->localfeatures, - channel->remote_upfront_shutdown_script); + channel->remote_upfront_shutdown_script, + remote_ann_node_sig, + remote_ann_bitcoin_sig); /* We don't expect a response: we are triggered by funding_depth_cb. */ subd_send_msg(channel->owner, take(initmsg));