Skip to content

Commit

Permalink
Channeld: init channel with remote announcement info when restart
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trueptolemy committed May 19, 2019
1 parent 8a4bfb2 commit 43e47fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 43e47fb

Please sign in to comment.