mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
channeld: Use the chainparams to check msatoshi and funding_satoshi
This commit is contained in:
@@ -363,7 +363,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
* - for channels with `chain_hash` identifying the Bitcoin blockchain:
|
* - for channels with `chain_hash` identifying the Bitcoin blockchain:
|
||||||
* - MUST set the four most significant bytes of `amount_msat` to 0.
|
* - 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;
|
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -766,6 +766,7 @@ static void json_fund_channel(struct command *cmd,
|
|||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
u32 *feerate_per_kw;
|
u32 *feerate_per_kw;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
u64 max_funding_satoshi = get_chainparams(cmd->ld)->max_funding_satoshi;
|
||||||
|
|
||||||
fc->cmd = cmd;
|
fc->cmd = cmd;
|
||||||
fc->uc = NULL;
|
fc->uc = NULL;
|
||||||
@@ -777,7 +778,7 @@ static void json_fund_channel(struct command *cmd,
|
|||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!json_tok_wtx(&fc->wtx, buffer, sattok, MAX_FUNDING_SATOSHI))
|
if (!json_tok_wtx(&fc->wtx, buffer, sattok, max_funding_satoshi))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!feerate_per_kw) {
|
if (!feerate_per_kw) {
|
||||||
@@ -820,7 +821,7 @@ static void json_fund_channel(struct command *cmd,
|
|||||||
BITCOIN_SCRIPTPUBKEY_P2WSH_LEN))
|
BITCOIN_SCRIPTPUBKEY_P2WSH_LEN))
|
||||||
return;
|
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);
|
peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc);
|
||||||
fc->uc = peer->uncommitted_channel;
|
fc->uc = peer->uncommitted_channel;
|
||||||
|
|||||||
@@ -353,9 +353,10 @@ static u8 *funder_channel(struct state *state,
|
|||||||
|
|
||||||
temporary_channel_id(&state->channel_id);
|
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,
|
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);
|
state->funding_satoshis);
|
||||||
|
|
||||||
/* BOLT #2:
|
/* 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`
|
* The receiving node ... MUST fail the channel if `funding-satoshis`
|
||||||
* is greater than or equal to 2^24 */
|
* 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,
|
negotiation_failed(state, false,
|
||||||
"funding_satoshis %"PRIu64" too large",
|
"funding_satoshis %"PRIu64" too large",
|
||||||
state->funding_satoshis);
|
state->funding_satoshis);
|
||||||
|
|||||||
Reference in New Issue
Block a user