From 11412435ce0cae92205178db9a9f4b64d0d78830 Mon Sep 17 00:00:00 2001 From: trueptolemy <823220586@qq.com> Date: Tue, 14 May 2019 17:36:05 +0800 Subject: [PATCH] Channeld: init channel with remote announcement info when restart 1. Add remote_ann_node_sigs and remote_bitcoin_sigs fields in channel_init message; 2. Master add announcement signatures into channel_init message, and send this message to Channeld. Channeld will initial the channel with this signatures when it reenables the channel. --- CHANGELOG.md | 2 ++ channeld/channel_wire.csv | 2 ++ channeld/channeld.c | 20 +++++++++++++++++++- lightningd/channel_control.c | 12 +++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c970372..b81e3e25c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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)) - Config: Added a default plugin directory : `lightning_dir/plugins`. Each plugin directory it contains will be added to lightningd on startup. +- 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 50ae91207..3b7bdc69b 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 5b2e2f951..160f8e708 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,18 @@ 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; + + /* 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); @@ -2959,6 +2975,8 @@ static void init_channel(struct peer *peer) tal_free(fulfilled_sides); tal_free(failed); tal_free(failed_sides); + tal_free(remote_ann_node_sig); + tal_free(remote_ann_bitcoin_sig); peer->channel_direction = node_id_idx(&peer->node_ids[LOCAL], &peer->node_ids[REMOTE]); diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 6ca0c3399..7ffc42e28 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -297,6 +297,7 @@ 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; hsmfd = hsm_get_client_fd(ld, &channel->peer->id, channel->dbid, @@ -370,6 +371,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(tmpctx, channel->peer->ld->wallet, channel->dbid, + &remote_ann_node_sig, &remote_ann_bitcoin_sig)) { + channel_internal_error(channel, + "Could not load remote announcement signatures"); + return; + } + initmsg = towire_channel_init(tmpctx, &get_chainparams(ld)->genesis_blockhash, &channel->funding_txid, @@ -419,7 +427,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));