From 3a9c559dc6cae42a869d7023917e5b6f3203fa57 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 29 Mar 2017 21:25:15 +1030 Subject: [PATCH] lightningd/channel: quote BOLT #2 for checking expiry. https://github.com/lightningnetwork/lightning-rfc/pull/138: BOLT 2: htlc-cltv must be in blocks. Signed-off-by: Rusty Russell --- lightningd/channel.c | 9 +++++++-- lightningd/channel.h | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 15068d9ae..62031f582 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -227,7 +227,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel, enum side sender, u64 id, u64 msatoshi, - u32 expiry, + u32 cltv_expiry, const struct sha256 *payment_hash, const u8 routing[1254]) { @@ -248,7 +248,12 @@ enum channel_add_err channel_add_htlc(struct channel *channel, htlc->state = RCVD_ADD_HTLC; htlc->id = id; htlc->msatoshi = msatoshi; - if (!blocks_to_abs_locktime(expiry, &htlc->expiry)) + /* BOLT #2: + * + * A receiving node SHOULD fail the channel if a sending node... sets + * `cltv-expiry` to greater or equal to 500000000. + */ + if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) return CHANNEL_ERR_INVALID_EXPIRY; htlc->rhash = *payment_hash; htlc->r = NULL; diff --git a/lightningd/channel.h b/lightningd/channel.h index 32bfaf486..5cbde2c16 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -207,7 +207,7 @@ enum channel_add_err { * @offerer: the side offering the HTLC (to the other side). * @id: unique HTLC id. * @msatoshi: amount in millisatoshi. - * @expiry: block number when HTLC can no longer be redeemed. + * @cltv_expiry: block number when HTLC can no longer be redeemed. * @payment_hash: hash whose preimage can redeem HTLC. * @routing: routing information (copied) * @@ -219,7 +219,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel, enum side sender, u64 id, u64 msatoshi, - u32 expiry, + u32 cltv_expiry, const struct sha256 *payment_hash, const u8 routing[1254]);