Browse Source

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.
htlc_accepted_hook
trueptolemy 6 years ago
committed by Christian Decker
parent
commit
11412435ce
  1. 2
      CHANGELOG.md
  2. 2
      channeld/channel_wire.csv
  3. 20
      channeld/channeld.c
  4. 12
      lightningd/channel_control.c

2
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

2
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

Can't render this file because it has a wrong number of fields in line 6.

20
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]);

12
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));

Loading…
Cancel
Save