From 0128bc73629e66ea2f7a55f42d1cd8b62cb0a2f0 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 6 Sep 2018 18:50:09 +0200 Subject: [PATCH] channeld: Use the chainparams to check msatoshi and funding_satoshi --- channeld/full_channel.c | 2 +- lightningd/opening_control.c | 5 +++-- openingd/openingd.c | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/channeld/full_channel.c b/channeld/full_channel.c index d5d930c07..98a22b5f8 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -363,7 +363,7 @@ static enum channel_add_err add_htlc(struct channel *channel, * - for channels with `chain_hash` identifying the Bitcoin blockchain: * - MUST set the four most significant bytes of `amount_msat` to 0. */ - if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) { + if (htlc->msatoshi > channel->chainparams->max_payment_msat) { return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED; } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index b03b9120d..42f0b819a 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -766,6 +766,7 @@ static void json_fund_channel(struct command *cmd, struct channel *channel; u32 *feerate_per_kw; u8 *msg; + u64 max_funding_satoshi = get_chainparams(cmd->ld)->max_funding_satoshi; fc->cmd = cmd; fc->uc = NULL; @@ -777,7 +778,7 @@ static void json_fund_channel(struct command *cmd, NULL)) return; - if (!json_tok_wtx(&fc->wtx, buffer, sattok, MAX_FUNDING_SATOSHI)) + if (!json_tok_wtx(&fc->wtx, buffer, sattok, max_funding_satoshi)) return; if (!feerate_per_kw) { @@ -820,7 +821,7 @@ static void json_fund_channel(struct command *cmd, BITCOIN_SCRIPTPUBKEY_P2WSH_LEN)) return; - assert(fc->wtx.amount <= MAX_FUNDING_SATOSHI); + assert(fc->wtx.amount <= max_funding_satoshi); peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc); fc->uc = peer->uncommitted_channel; diff --git a/openingd/openingd.c b/openingd/openingd.c index 4d0b2c3c1..424f09cc5 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -353,9 +353,10 @@ static u8 *funder_channel(struct state *state, temporary_channel_id(&state->channel_id); - if (state->funding_satoshis > MAX_FUNDING_SATOSHI) + if (state->funding_satoshis > state->chainparams->max_funding_satoshi) status_failed(STATUS_FAIL_MASTER_IO, - "funding_satoshis must be < 2^24, not %"PRIu64, + "funding_satoshis must be < %"PRIu64", not %"PRIu64, + state->chainparams->max_funding_satoshi, state->funding_satoshis); /* BOLT #2: @@ -722,7 +723,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) * * The receiving node ... MUST fail the channel if `funding-satoshis` * is greater than or equal to 2^24 */ - if (state->funding_satoshis > MAX_FUNDING_SATOSHI) { + if (state->funding_satoshis > state->chainparams->max_funding_satoshi) { negotiation_failed(state, false, "funding_satoshis %"PRIu64" too large", state->funding_satoshis);