mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
Send/receive cltv_expiry_delta in open/accept channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2a28173891
commit
18e3f9820f
@ -19,6 +19,7 @@
|
||||
* * [`4`:`feerate_per_kw`]
|
||||
* * [`2`:`to_self_delay`]
|
||||
* * [`2`:`max_accepted_htlcs`]
|
||||
* * [`2`:`cltv_expiry_delta`]
|
||||
*...
|
||||
* 1. type: 33 (`accept_channel`)
|
||||
* 2. data:
|
||||
@ -30,6 +31,7 @@
|
||||
* * [`4`:`minimum_depth`]
|
||||
* * [`2`:`to_self_delay`]
|
||||
* * [`2`:`max_accepted_htlcs`]
|
||||
* * [`2`:`cltv_expiry_delta`]
|
||||
*/
|
||||
struct channel_config {
|
||||
/* Database ID */
|
||||
|
@ -2266,7 +2266,8 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
|
||||
&fc->peer->minimum_depth,
|
||||
&channel_info->remote_fundingkey,
|
||||
&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",
|
||||
tal_hex(resp, resp));
|
||||
return false;
|
||||
@ -2387,7 +2388,8 @@ static bool opening_fundee_finished(struct subd *opening,
|
||||
&peer->push_msat,
|
||||
&peer->channel_flags,
|
||||
&channel_info->feerate_per_kw,
|
||||
&funding_signed)) {
|
||||
&funding_signed,
|
||||
&channel_info->their_cltv_expiry_delta)) {
|
||||
log_broken(peer->log, "bad OPENING_FUNDEE_REPLY %s",
|
||||
tal_hex(reply, reply));
|
||||
return false;
|
||||
@ -2528,7 +2530,8 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer,
|
||||
&peer->our_config,
|
||||
max_to_self_delay,
|
||||
min_effective_htlc_capacity_msat,
|
||||
cs, peer->seed);
|
||||
cs, peer->seed,
|
||||
ld->config.min_htlc_expiry);
|
||||
|
||||
subd_send_msg(peer->owner, take(msg));
|
||||
/* 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,
|
||||
max_to_self_delay,
|
||||
min_effective_htlc_capacity_msat,
|
||||
&cs, fc->peer->seed);
|
||||
&cs, fc->peer->seed,
|
||||
ld->config.min_htlc_expiry);
|
||||
|
||||
subd_send_msg(opening, take(msg));
|
||||
|
||||
|
@ -537,7 +537,7 @@ static void forward_htlc(struct htlc_in *hin,
|
||||
|
||||
/* 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:
|
||||
* 1. type: UPDATE|14 (`expiry_too_soon`)
|
||||
* 2. data:
|
||||
|
@ -15,6 +15,7 @@ struct channel_info {
|
||||
* and the remote_per_commit is for the commit_tx we're modifying now. */
|
||||
struct pubkey remote_per_commit, old_remote_per_commit;
|
||||
u32 feerate_per_kw;
|
||||
u16 their_cltv_expiry_delta;
|
||||
};
|
||||
|
||||
/* Get all HTLCs for a peer, to send in init message. */
|
||||
|
@ -199,6 +199,7 @@ static u8 *funder_channel(struct state *state,
|
||||
const struct pubkey *our_funding_pubkey,
|
||||
const struct basepoints *ours,
|
||||
u32 max_minimum_depth,
|
||||
u16 our_cltv_expiry_delta,
|
||||
u64 change_satoshis, u32 change_keyindex,
|
||||
u8 channel_flags,
|
||||
const struct utxo *utxos,
|
||||
@ -211,6 +212,7 @@ static u8 *funder_channel(struct state *state,
|
||||
struct pubkey their_funding_pubkey, changekey;
|
||||
secp256k1_ecdsa_signature sig;
|
||||
u32 minimum_depth;
|
||||
u16 their_cltv_expiry_delta;
|
||||
const u8 *wscript;
|
||||
struct bitcoin_tx *funding;
|
||||
const struct utxo **utxomap;
|
||||
@ -249,12 +251,14 @@ static u8 *funder_channel(struct state *state,
|
||||
state->feerate_per_kw,
|
||||
state->localconf.to_self_delay,
|
||||
state->localconf.max_accepted_htlcs,
|
||||
our_cltv_expiry_delta,
|
||||
our_funding_pubkey,
|
||||
&ours->revocation,
|
||||
&ours->payment,
|
||||
&ours->delayed_payment,
|
||||
&state->next_per_commit[LOCAL],
|
||||
channel_flags);
|
||||
|
||||
if (!sync_crypto_write(&state->cs, PEER_FD, msg))
|
||||
status_failed(STATUS_FAIL_PEER_IO,
|
||||
"Writing open_channel: %s", strerror(errno));
|
||||
@ -283,6 +287,7 @@ static u8 *funder_channel(struct state *state,
|
||||
&minimum_depth,
|
||||
&state->remoteconf->to_self_delay,
|
||||
&state->remoteconf->max_accepted_htlcs,
|
||||
&their_cltv_expiry_delta,
|
||||
&their_funding_pubkey,
|
||||
&theirs.revocation,
|
||||
&theirs.payment,
|
||||
@ -445,7 +450,8 @@ static u8 *funder_channel(struct state *state,
|
||||
minimum_depth,
|
||||
&their_funding_pubkey,
|
||||
&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:
|
||||
@ -454,6 +460,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
const struct pubkey *our_funding_pubkey,
|
||||
const struct basepoints *ours,
|
||||
u32 minimum_depth,
|
||||
u16 our_cltv_expiry_delta,
|
||||
u32 min_feerate, u32 max_feerate, const u8 *peer_msg)
|
||||
{
|
||||
struct channel_id id_in;
|
||||
@ -465,6 +472,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
u8 *msg;
|
||||
const u8 *wscript;
|
||||
u8 channel_flags;
|
||||
u16 their_cltv_expiry_delta;
|
||||
|
||||
state->remoteconf = tal(state, struct channel_config);
|
||||
|
||||
@ -485,6 +493,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
&state->feerate_per_kw,
|
||||
&state->remoteconf->to_self_delay,
|
||||
&state->remoteconf->max_accepted_htlcs,
|
||||
&their_cltv_expiry_delta,
|
||||
&their_funding_pubkey,
|
||||
&theirs.revocation,
|
||||
&theirs.payment,
|
||||
@ -556,6 +565,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
minimum_depth,
|
||||
state->localconf.to_self_delay,
|
||||
state->localconf.max_accepted_htlcs,
|
||||
our_cltv_expiry_delta,
|
||||
our_funding_pubkey,
|
||||
&ours->revocation,
|
||||
&ours->payment,
|
||||
@ -668,7 +678,8 @@ static u8 *fundee_channel(struct state *state,
|
||||
state->push_msat,
|
||||
channel_flags,
|
||||
state->feerate_per_kw,
|
||||
msg);
|
||||
msg,
|
||||
their_cltv_expiry_delta);
|
||||
}
|
||||
|
||||
#ifndef TESTING
|
||||
@ -687,6 +698,7 @@ int main(int argc, char *argv[])
|
||||
struct utxo *utxos;
|
||||
struct ext_key bip32_base;
|
||||
u32 network_index;
|
||||
u16 our_cltv_expiry_delta;
|
||||
|
||||
if (argc == 2 && streq(argv[1], "--version")) {
|
||||
printf("%s\n", version());
|
||||
@ -708,7 +720,8 @@ int main(int argc, char *argv[])
|
||||
&state->max_to_self_delay,
|
||||
&state->min_effective_htlc_capacity_msat,
|
||||
&state->cs,
|
||||
&seed))
|
||||
&seed,
|
||||
&our_cltv_expiry_delta))
|
||||
master_badmsg(WIRE_OPENING_INIT, msg);
|
||||
|
||||
tal_free(msg);
|
||||
@ -741,13 +754,15 @@ int main(int argc, char *argv[])
|
||||
&change_satoshis, &change_keyindex,
|
||||
&channel_flags, &utxos, &bip32_base))
|
||||
msg = funder_channel(state, &our_funding_pubkey, &our_points,
|
||||
max_minimum_depth, change_satoshis,
|
||||
change_keyindex, channel_flags,
|
||||
max_minimum_depth, our_cltv_expiry_delta,
|
||||
change_satoshis, change_keyindex,
|
||||
channel_flags,
|
||||
utxos, &bip32_base);
|
||||
else if (fromwire_opening_fundee(state, msg, NULL, &minimum_depth,
|
||||
&min_feerate, &max_feerate, &peer_msg))
|
||||
msg = fundee_channel(state, &our_funding_pubkey, &our_points,
|
||||
minimum_depth, min_feerate, max_feerate,
|
||||
minimum_depth, our_cltv_expiry_delta,
|
||||
min_feerate, max_feerate,
|
||||
peer_msg);
|
||||
else
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
|
@ -11,6 +11,7 @@ opening_init,,min_effective_htlc_capacity_msat,u64
|
||||
opening_init,,crypto_state,struct crypto_state
|
||||
# Seed to generate all the keys from
|
||||
opening_init,,seed,struct privkey
|
||||
opening_init,,our_cltv_expiry_delta,u16
|
||||
|
||||
#include <common/bip32.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,,funding_txid,struct sha256_double
|
||||
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)
|
||||
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.
|
||||
opening_fundee_reply,,msglen,u16
|
||||
opening_fundee_reply,,funding_signed_msg,msglen*u8
|
||||
opening_fundee_reply,,their_cltv_expiry_delta,u16
|
||||
|
|
@ -26,12 +26,13 @@ open_channel,104,htlc_minimum_msat,8
|
||||
open_channel,112,feerate_per_kw,4
|
||||
open_channel,116,to_self_delay,2
|
||||
open_channel,118,max_accepted_htlcs,2
|
||||
open_channel,120,funding_pubkey,33
|
||||
open_channel,153,revocation_basepoint,33
|
||||
open_channel,186,payment_basepoint,33
|
||||
open_channel,219,delayed_payment_basepoint,33
|
||||
open_channel,252,first_per_commitment_point,33
|
||||
open_channel,285,channel_flags,1
|
||||
open_channel,120,cltv_expiry_delta,2
|
||||
open_channel,122,funding_pubkey,33
|
||||
open_channel,155,revocation_basepoint,33
|
||||
open_channel,188,payment_basepoint,33
|
||||
open_channel,221,delayed_payment_basepoint,33
|
||||
open_channel,254,first_per_commitment_point,33
|
||||
open_channel,287,channel_flags,1
|
||||
accept_channel,33
|
||||
accept_channel,0,temporary_channel_id,32
|
||||
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,68,to_self_delay,2
|
||||
accept_channel,70,max_accepted_htlcs,2
|
||||
accept_channel,72,funding_pubkey,33
|
||||
accept_channel,105,revocation_basepoint,33
|
||||
accept_channel,138,payment_basepoint,33
|
||||
accept_channel,171,delayed_payment_basepoint,33
|
||||
accept_channel,204,first_per_commitment_point,33
|
||||
accept_channel,72,cltv_expiry_delta,2
|
||||
accept_channel,74,funding_pubkey,33
|
||||
accept_channel,107,revocation_basepoint,33
|
||||
accept_channel,140,payment_basepoint,33
|
||||
accept_channel,173,delayed_payment_basepoint,33
|
||||
accept_channel,206,first_per_commitment_point,33
|
||||
funding_created,34
|
||||
funding_created,0,temporary_channel_id,32
|
||||
funding_created,32,funding_txid,32
|
||||
|
@ -105,6 +105,7 @@ struct msg_accept_channel {
|
||||
u32 minimum_depth;
|
||||
u16 to_self_delay;
|
||||
u16 max_accepted_htlcs;
|
||||
u16 cltv_expiry_delta;
|
||||
struct pubkey funding_pubkey;
|
||||
struct pubkey revocation_basepoint;
|
||||
struct pubkey payment_basepoint;
|
||||
@ -176,6 +177,7 @@ struct msg_open_channel {
|
||||
u32 feerate_per_kw;
|
||||
u16 to_self_delay;
|
||||
u16 max_accepted_htlcs;
|
||||
u16 cltv_expiry_delta;
|
||||
struct pubkey funding_pubkey;
|
||||
struct pubkey revocation_basepoint;
|
||||
struct pubkey payment_basepoint;
|
||||
@ -269,6 +271,7 @@ static void *towire_struct_open_channel(const tal_t *ctx,
|
||||
s->feerate_per_kw,
|
||||
s->to_self_delay,
|
||||
s->max_accepted_htlcs,
|
||||
s->cltv_expiry_delta,
|
||||
&s->funding_pubkey,
|
||||
&s->revocation_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->to_self_delay,
|
||||
&s->max_accepted_htlcs,
|
||||
&s->cltv_expiry_delta,
|
||||
&s->funding_pubkey,
|
||||
&s->revocation_basepoint,
|
||||
&s->payment_basepoint,
|
||||
@ -315,6 +319,7 @@ static void *towire_struct_accept_channel(const tal_t *ctx,
|
||||
s->minimum_depth,
|
||||
s->to_self_delay,
|
||||
s->max_accepted_htlcs,
|
||||
s->cltv_expiry_delta,
|
||||
&s->funding_pubkey,
|
||||
&s->revocation_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->htlc_minimum_msat,
|
||||
&s->minimum_depth,
|
||||
&s->cltv_expiry_delta,
|
||||
&s->to_self_delay,
|
||||
&s->max_accepted_htlcs,
|
||||
&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,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user