Browse Source

Send/receive cltv_expiry_delta in open/accept channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
committed by Christian Decker
parent
commit
18e3f9820f
  1. 2
      common/channel_config.h
  2. 12
      lightningd/peer_control.c
  3. 2
      lightningd/peer_htlcs.c
  4. 1
      lightningd/peer_htlcs.h
  5. 29
      openingd/opening.c
  6. 3
      openingd/opening_wire.csv
  7. 24
      wire/gen_peer_wire_csv
  8. 10
      wire/test/run-peer-wire.c

2
common/channel_config.h

@ -19,6 +19,7 @@
* * [`4`:`feerate_per_kw`] * * [`4`:`feerate_per_kw`]
* * [`2`:`to_self_delay`] * * [`2`:`to_self_delay`]
* * [`2`:`max_accepted_htlcs`] * * [`2`:`max_accepted_htlcs`]
* * [`2`:`cltv_expiry_delta`]
*... *...
* 1. type: 33 (`accept_channel`) * 1. type: 33 (`accept_channel`)
* 2. data: * 2. data:
@ -30,6 +31,7 @@
* * [`4`:`minimum_depth`] * * [`4`:`minimum_depth`]
* * [`2`:`to_self_delay`] * * [`2`:`to_self_delay`]
* * [`2`:`max_accepted_htlcs`] * * [`2`:`max_accepted_htlcs`]
* * [`2`:`cltv_expiry_delta`]
*/ */
struct channel_config { struct channel_config {
/* Database ID */ /* Database ID */

12
lightningd/peer_control.c

@ -2266,7 +2266,8 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
&fc->peer->minimum_depth, &fc->peer->minimum_depth,
&channel_info->remote_fundingkey, &channel_info->remote_fundingkey,
&funding_txid, &funding_txid,
&channel_info->feerate_per_kw)) { &channel_info->feerate_per_kw,
&channel_info->their_cltv_expiry_delta)) {
peer_internal_error(fc->peer, "bad shutdown_complete: %s", peer_internal_error(fc->peer, "bad shutdown_complete: %s",
tal_hex(resp, resp)); tal_hex(resp, resp));
return false; return false;
@ -2387,7 +2388,8 @@ static bool opening_fundee_finished(struct subd *opening,
&peer->push_msat, &peer->push_msat,
&peer->channel_flags, &peer->channel_flags,
&channel_info->feerate_per_kw, &channel_info->feerate_per_kw,
&funding_signed)) { &funding_signed,
&channel_info->their_cltv_expiry_delta)) {
log_broken(peer->log, "bad OPENING_FUNDEE_REPLY %s", log_broken(peer->log, "bad OPENING_FUNDEE_REPLY %s",
tal_hex(reply, reply)); tal_hex(reply, reply));
return false; return false;
@ -2528,7 +2530,8 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer,
&peer->our_config, &peer->our_config,
max_to_self_delay, max_to_self_delay,
min_effective_htlc_capacity_msat, min_effective_htlc_capacity_msat,
cs, peer->seed); cs, peer->seed,
ld->config.min_htlc_expiry);
subd_send_msg(peer->owner, take(msg)); subd_send_msg(peer->owner, take(msg));
/* FIXME: Expose the min_feerate_per_kw and max_feerate_per_kw in the config */ /* FIXME: Expose the min_feerate_per_kw and max_feerate_per_kw in the config */
@ -2602,7 +2605,8 @@ static bool gossip_peer_released(struct subd *gossip,
&fc->peer->our_config, &fc->peer->our_config,
max_to_self_delay, max_to_self_delay,
min_effective_htlc_capacity_msat, min_effective_htlc_capacity_msat,
&cs, fc->peer->seed); &cs, fc->peer->seed,
ld->config.min_htlc_expiry);
subd_send_msg(opening, take(msg)); subd_send_msg(opening, take(msg));

2
lightningd/peer_htlcs.c

@ -537,7 +537,7 @@ static void forward_htlc(struct htlc_in *hin,
/* BOLT #4: /* BOLT #4:
* *
* If the cltv-expiry is too near, we tell them the the current channel * If the `cltv_expiry` is too near, we tell them the the current channel
* setting for the outgoing channel: * setting for the outgoing channel:
* 1. type: UPDATE|14 (`expiry_too_soon`) * 1. type: UPDATE|14 (`expiry_too_soon`)
* 2. data: * 2. data:

1
lightningd/peer_htlcs.h

@ -15,6 +15,7 @@ struct channel_info {
* and the remote_per_commit is for the commit_tx we're modifying now. */ * and the remote_per_commit is for the commit_tx we're modifying now. */
struct pubkey remote_per_commit, old_remote_per_commit; struct pubkey remote_per_commit, old_remote_per_commit;
u32 feerate_per_kw; u32 feerate_per_kw;
u16 their_cltv_expiry_delta;
}; };
/* Get all HTLCs for a peer, to send in init message. */ /* Get all HTLCs for a peer, to send in init message. */

29
openingd/opening.c

@ -199,6 +199,7 @@ static u8 *funder_channel(struct state *state,
const struct pubkey *our_funding_pubkey, const struct pubkey *our_funding_pubkey,
const struct basepoints *ours, const struct basepoints *ours,
u32 max_minimum_depth, u32 max_minimum_depth,
u16 our_cltv_expiry_delta,
u64 change_satoshis, u32 change_keyindex, u64 change_satoshis, u32 change_keyindex,
u8 channel_flags, u8 channel_flags,
const struct utxo *utxos, const struct utxo *utxos,
@ -211,6 +212,7 @@ static u8 *funder_channel(struct state *state,
struct pubkey their_funding_pubkey, changekey; struct pubkey their_funding_pubkey, changekey;
secp256k1_ecdsa_signature sig; secp256k1_ecdsa_signature sig;
u32 minimum_depth; u32 minimum_depth;
u16 their_cltv_expiry_delta;
const u8 *wscript; const u8 *wscript;
struct bitcoin_tx *funding; struct bitcoin_tx *funding;
const struct utxo **utxomap; const struct utxo **utxomap;
@ -249,12 +251,14 @@ static u8 *funder_channel(struct state *state,
state->feerate_per_kw, state->feerate_per_kw,
state->localconf.to_self_delay, state->localconf.to_self_delay,
state->localconf.max_accepted_htlcs, state->localconf.max_accepted_htlcs,
our_cltv_expiry_delta,
our_funding_pubkey, our_funding_pubkey,
&ours->revocation, &ours->revocation,
&ours->payment, &ours->payment,
&ours->delayed_payment, &ours->delayed_payment,
&state->next_per_commit[LOCAL], &state->next_per_commit[LOCAL],
channel_flags); channel_flags);
if (!sync_crypto_write(&state->cs, PEER_FD, msg)) if (!sync_crypto_write(&state->cs, PEER_FD, msg))
status_failed(STATUS_FAIL_PEER_IO, status_failed(STATUS_FAIL_PEER_IO,
"Writing open_channel: %s", strerror(errno)); "Writing open_channel: %s", strerror(errno));
@ -283,6 +287,7 @@ static u8 *funder_channel(struct state *state,
&minimum_depth, &minimum_depth,
&state->remoteconf->to_self_delay, &state->remoteconf->to_self_delay,
&state->remoteconf->max_accepted_htlcs, &state->remoteconf->max_accepted_htlcs,
&their_cltv_expiry_delta,
&their_funding_pubkey, &their_funding_pubkey,
&theirs.revocation, &theirs.revocation,
&theirs.payment, &theirs.payment,
@ -445,7 +450,8 @@ static u8 *funder_channel(struct state *state,
minimum_depth, minimum_depth,
&their_funding_pubkey, &their_funding_pubkey,
&state->funding_txid, &state->funding_txid,
state->feerate_per_kw); state->feerate_per_kw,
their_cltv_expiry_delta);
} }
/* This is handed the message the peer sent which caused gossip to stop: /* This is handed the message the peer sent which caused gossip to stop:
@ -454,6 +460,7 @@ static u8 *fundee_channel(struct state *state,
const struct pubkey *our_funding_pubkey, const struct pubkey *our_funding_pubkey,
const struct basepoints *ours, const struct basepoints *ours,
u32 minimum_depth, u32 minimum_depth,
u16 our_cltv_expiry_delta,
u32 min_feerate, u32 max_feerate, const u8 *peer_msg) u32 min_feerate, u32 max_feerate, const u8 *peer_msg)
{ {
struct channel_id id_in; struct channel_id id_in;
@ -465,6 +472,7 @@ static u8 *fundee_channel(struct state *state,
u8 *msg; u8 *msg;
const u8 *wscript; const u8 *wscript;
u8 channel_flags; u8 channel_flags;
u16 their_cltv_expiry_delta;
state->remoteconf = tal(state, struct channel_config); state->remoteconf = tal(state, struct channel_config);
@ -485,6 +493,7 @@ static u8 *fundee_channel(struct state *state,
&state->feerate_per_kw, &state->feerate_per_kw,
&state->remoteconf->to_self_delay, &state->remoteconf->to_self_delay,
&state->remoteconf->max_accepted_htlcs, &state->remoteconf->max_accepted_htlcs,
&their_cltv_expiry_delta,
&their_funding_pubkey, &their_funding_pubkey,
&theirs.revocation, &theirs.revocation,
&theirs.payment, &theirs.payment,
@ -556,6 +565,7 @@ static u8 *fundee_channel(struct state *state,
minimum_depth, minimum_depth,
state->localconf.to_self_delay, state->localconf.to_self_delay,
state->localconf.max_accepted_htlcs, state->localconf.max_accepted_htlcs,
our_cltv_expiry_delta,
our_funding_pubkey, our_funding_pubkey,
&ours->revocation, &ours->revocation,
&ours->payment, &ours->payment,
@ -668,7 +678,8 @@ static u8 *fundee_channel(struct state *state,
state->push_msat, state->push_msat,
channel_flags, channel_flags,
state->feerate_per_kw, state->feerate_per_kw,
msg); msg,
their_cltv_expiry_delta);
} }
#ifndef TESTING #ifndef TESTING
@ -687,6 +698,7 @@ int main(int argc, char *argv[])
struct utxo *utxos; struct utxo *utxos;
struct ext_key bip32_base; struct ext_key bip32_base;
u32 network_index; u32 network_index;
u16 our_cltv_expiry_delta;
if (argc == 2 && streq(argv[1], "--version")) { if (argc == 2 && streq(argv[1], "--version")) {
printf("%s\n", version()); printf("%s\n", version());
@ -708,7 +720,8 @@ int main(int argc, char *argv[])
&state->max_to_self_delay, &state->max_to_self_delay,
&state->min_effective_htlc_capacity_msat, &state->min_effective_htlc_capacity_msat,
&state->cs, &state->cs,
&seed)) &seed,
&our_cltv_expiry_delta))
master_badmsg(WIRE_OPENING_INIT, msg); master_badmsg(WIRE_OPENING_INIT, msg);
tal_free(msg); tal_free(msg);
@ -741,14 +754,16 @@ int main(int argc, char *argv[])
&change_satoshis, &change_keyindex, &change_satoshis, &change_keyindex,
&channel_flags, &utxos, &bip32_base)) &channel_flags, &utxos, &bip32_base))
msg = funder_channel(state, &our_funding_pubkey, &our_points, msg = funder_channel(state, &our_funding_pubkey, &our_points,
max_minimum_depth, change_satoshis, max_minimum_depth, our_cltv_expiry_delta,
change_keyindex, channel_flags, change_satoshis, change_keyindex,
channel_flags,
utxos, &bip32_base); utxos, &bip32_base);
else if (fromwire_opening_fundee(state, msg, NULL, &minimum_depth, else if (fromwire_opening_fundee(state, msg, NULL, &minimum_depth,
&min_feerate, &max_feerate, &peer_msg)) &min_feerate, &max_feerate, &peer_msg))
msg = fundee_channel(state, &our_funding_pubkey, &our_points, msg = fundee_channel(state, &our_funding_pubkey, &our_points,
minimum_depth, min_feerate, max_feerate, minimum_depth, our_cltv_expiry_delta,
peer_msg); min_feerate, max_feerate,
peer_msg);
else else
status_failed(STATUS_FAIL_MASTER_IO, status_failed(STATUS_FAIL_MASTER_IO,
"neither funder nor fundee: %s", "neither funder nor fundee: %s",

3
openingd/opening_wire.csv

@ -11,6 +11,7 @@ opening_init,,min_effective_htlc_capacity_msat,u64
opening_init,,crypto_state,struct crypto_state opening_init,,crypto_state,struct crypto_state
# Seed to generate all the keys from # Seed to generate all the keys from
opening_init,,seed,struct privkey opening_init,,seed,struct privkey
opening_init,,our_cltv_expiry_delta,u16
#include <common/bip32.h> #include <common/bip32.h>
#include <common/htlc_wire.h> #include <common/htlc_wire.h>
@ -42,6 +43,7 @@ opening_funder_reply,,minimum_depth,u32
opening_funder_reply,,remote_fundingkey,struct pubkey opening_funder_reply,,remote_fundingkey,struct pubkey
opening_funder_reply,,funding_txid,struct sha256_double opening_funder_reply,,funding_txid,struct sha256_double
opening_funder_reply,,feerate_per_kw,u32 opening_funder_reply,,feerate_per_kw,u32
opening_funder_reply,,their_cltv_expiry_delta,u16
# This means they offer the open (contains their offer packet) # This means they offer the open (contains their offer packet)
opening_fundee,6003 opening_fundee,6003
@ -71,3 +73,4 @@ opening_fundee_reply,,feerate_per_kw,u32
# The (encrypted) funding signed message: send this and we're committed. # The (encrypted) funding signed message: send this and we're committed.
opening_fundee_reply,,msglen,u16 opening_fundee_reply,,msglen,u16
opening_fundee_reply,,funding_signed_msg,msglen*u8 opening_fundee_reply,,funding_signed_msg,msglen*u8
opening_fundee_reply,,their_cltv_expiry_delta,u16

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

24
wire/gen_peer_wire_csv

@ -26,12 +26,13 @@ open_channel,104,htlc_minimum_msat,8
open_channel,112,feerate_per_kw,4 open_channel,112,feerate_per_kw,4
open_channel,116,to_self_delay,2 open_channel,116,to_self_delay,2
open_channel,118,max_accepted_htlcs,2 open_channel,118,max_accepted_htlcs,2
open_channel,120,funding_pubkey,33 open_channel,120,cltv_expiry_delta,2
open_channel,153,revocation_basepoint,33 open_channel,122,funding_pubkey,33
open_channel,186,payment_basepoint,33 open_channel,155,revocation_basepoint,33
open_channel,219,delayed_payment_basepoint,33 open_channel,188,payment_basepoint,33
open_channel,252,first_per_commitment_point,33 open_channel,221,delayed_payment_basepoint,33
open_channel,285,channel_flags,1 open_channel,254,first_per_commitment_point,33
open_channel,287,channel_flags,1
accept_channel,33 accept_channel,33
accept_channel,0,temporary_channel_id,32 accept_channel,0,temporary_channel_id,32
accept_channel,32,dust_limit_satoshis,8 accept_channel,32,dust_limit_satoshis,8
@ -41,11 +42,12 @@ accept_channel,56,htlc_minimum_msat,8
accept_channel,64,minimum_depth,4 accept_channel,64,minimum_depth,4
accept_channel,68,to_self_delay,2 accept_channel,68,to_self_delay,2
accept_channel,70,max_accepted_htlcs,2 accept_channel,70,max_accepted_htlcs,2
accept_channel,72,funding_pubkey,33 accept_channel,72,cltv_expiry_delta,2
accept_channel,105,revocation_basepoint,33 accept_channel,74,funding_pubkey,33
accept_channel,138,payment_basepoint,33 accept_channel,107,revocation_basepoint,33
accept_channel,171,delayed_payment_basepoint,33 accept_channel,140,payment_basepoint,33
accept_channel,204,first_per_commitment_point,33 accept_channel,173,delayed_payment_basepoint,33
accept_channel,206,first_per_commitment_point,33
funding_created,34 funding_created,34
funding_created,0,temporary_channel_id,32 funding_created,0,temporary_channel_id,32
funding_created,32,funding_txid,32 funding_created,32,funding_txid,32

10
wire/test/run-peer-wire.c

@ -105,6 +105,7 @@ struct msg_accept_channel {
u32 minimum_depth; u32 minimum_depth;
u16 to_self_delay; u16 to_self_delay;
u16 max_accepted_htlcs; u16 max_accepted_htlcs;
u16 cltv_expiry_delta;
struct pubkey funding_pubkey; struct pubkey funding_pubkey;
struct pubkey revocation_basepoint; struct pubkey revocation_basepoint;
struct pubkey payment_basepoint; struct pubkey payment_basepoint;
@ -176,6 +177,7 @@ struct msg_open_channel {
u32 feerate_per_kw; u32 feerate_per_kw;
u16 to_self_delay; u16 to_self_delay;
u16 max_accepted_htlcs; u16 max_accepted_htlcs;
u16 cltv_expiry_delta;
struct pubkey funding_pubkey; struct pubkey funding_pubkey;
struct pubkey revocation_basepoint; struct pubkey revocation_basepoint;
struct pubkey payment_basepoint; struct pubkey payment_basepoint;
@ -269,6 +271,7 @@ static void *towire_struct_open_channel(const tal_t *ctx,
s->feerate_per_kw, s->feerate_per_kw,
s->to_self_delay, s->to_self_delay,
s->max_accepted_htlcs, s->max_accepted_htlcs,
s->cltv_expiry_delta,
&s->funding_pubkey, &s->funding_pubkey,
&s->revocation_basepoint, &s->revocation_basepoint,
&s->payment_basepoint, &s->payment_basepoint,
@ -293,6 +296,7 @@ static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, c
&s->feerate_per_kw, &s->feerate_per_kw,
&s->to_self_delay, &s->to_self_delay,
&s->max_accepted_htlcs, &s->max_accepted_htlcs,
&s->cltv_expiry_delta,
&s->funding_pubkey, &s->funding_pubkey,
&s->revocation_basepoint, &s->revocation_basepoint,
&s->payment_basepoint, &s->payment_basepoint,
@ -315,6 +319,7 @@ static void *towire_struct_accept_channel(const tal_t *ctx,
s->minimum_depth, s->minimum_depth,
s->to_self_delay, s->to_self_delay,
s->max_accepted_htlcs, s->max_accepted_htlcs,
s->cltv_expiry_delta,
&s->funding_pubkey, &s->funding_pubkey,
&s->revocation_basepoint, &s->revocation_basepoint,
&s->payment_basepoint, &s->payment_basepoint,
@ -333,6 +338,7 @@ static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ct
&s->channel_reserve_satoshis, &s->channel_reserve_satoshis,
&s->htlc_minimum_msat, &s->htlc_minimum_msat,
&s->minimum_depth, &s->minimum_depth,
&s->cltv_expiry_delta,
&s->to_self_delay, &s->to_self_delay,
&s->max_accepted_htlcs, &s->max_accepted_htlcs,
&s->funding_pubkey, &s->funding_pubkey,
@ -799,7 +805,7 @@ static bool revoke_and_ack_eq(const struct msg_revoke_and_ack *a,
static bool open_channel_eq(const struct msg_open_channel *a, static bool open_channel_eq(const struct msg_open_channel *a,
const struct msg_open_channel *b) const struct msg_open_channel *b)
{ {
return eq_with(a, b, max_accepted_htlcs) return eq_with(a, b, cltv_expiry_delta)
&& eq_between(a, b, funding_pubkey, channel_flags); && eq_between(a, b, funding_pubkey, channel_flags);
} }
@ -813,7 +819,7 @@ static bool channel_update_eq(const struct msg_channel_update *a,
static bool accept_channel_eq(const struct msg_accept_channel *a, static bool accept_channel_eq(const struct msg_accept_channel *a,
const struct msg_accept_channel *b) const struct msg_accept_channel *b)
{ {
return eq_with(a, b, max_accepted_htlcs) return eq_with(a, b, cltv_expiry_delta)
&& eq_between(a, b, funding_pubkey, first_per_commitment_point); && eq_between(a, b, funding_pubkey, first_per_commitment_point);
} }

Loading…
Cancel
Save