mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
bitcoin/chainparams: use amount_sat / amount_msat
Simple changes, but ripples through the code. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
cd341b34d6
commit
85b8b25749
11 changed files with 40 additions and 35 deletions
|
@ -10,15 +10,15 @@ const struct chainparams networks[] = {
|
|||
.rpc_port = 8332,
|
||||
.cli = "bitcoin-cli",
|
||||
.cli_args = NULL,
|
||||
.dust_limit = 546,
|
||||
.dust_limit = { 546 },
|
||||
/* BOLT #2:
|
||||
*
|
||||
* The sending node:
|
||||
*...
|
||||
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
|
||||
*/
|
||||
.max_funding_satoshi = (1 << 24) - 1,
|
||||
.max_payment_msat = 0xFFFFFFFFULL,
|
||||
.max_funding = AMOUNT_SAT((1 << 24) - 1),
|
||||
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
|
||||
/* "Lightning Charge Powers Developers & Blockstream Store" */
|
||||
.when_lightning_became_cool = 504500,
|
||||
.testnet = false},
|
||||
|
@ -28,9 +28,9 @@ const struct chainparams networks[] = {
|
|||
.rpc_port = 18332,
|
||||
.cli = "bitcoin-cli",
|
||||
.cli_args = "-regtest",
|
||||
.dust_limit = 546,
|
||||
.max_funding_satoshi = (1 << 24) - 1,
|
||||
.max_payment_msat = 0xFFFFFFFFULL,
|
||||
.dust_limit = { 546 },
|
||||
.max_funding = AMOUNT_SAT((1 << 24) - 1),
|
||||
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
|
||||
.when_lightning_became_cool = 1,
|
||||
.testnet = true},
|
||||
{.network_name = "testnet",
|
||||
|
@ -39,9 +39,9 @@ const struct chainparams networks[] = {
|
|||
.rpc_port = 18332,
|
||||
.cli = "bitcoin-cli",
|
||||
.cli_args = "-testnet",
|
||||
.dust_limit = 546,
|
||||
.max_funding_satoshi = (1 << 24) - 1,
|
||||
.max_payment_msat = 0xFFFFFFFFULL,
|
||||
.dust_limit = { 546 },
|
||||
.max_funding = AMOUNT_SAT((1 << 24) - 1),
|
||||
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
|
||||
.testnet = true},
|
||||
{.network_name = "litecoin",
|
||||
.bip173_name = "ltc",
|
||||
|
@ -49,9 +49,9 @@ const struct chainparams networks[] = {
|
|||
.rpc_port = 9332,
|
||||
.cli = "litecoin-cli",
|
||||
.cli_args = NULL,
|
||||
.dust_limit = 100000,
|
||||
.max_funding_satoshi = 60 * ((1 << 24) - 1),
|
||||
.max_payment_msat = 60 * 0xFFFFFFFFULL,
|
||||
.dust_limit = { 100000 },
|
||||
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
|
||||
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
|
||||
.when_lightning_became_cool = 1320000,
|
||||
.testnet = false},
|
||||
{.network_name = "litecoin-testnet",
|
||||
|
@ -60,9 +60,9 @@ const struct chainparams networks[] = {
|
|||
.rpc_port = 19332,
|
||||
.cli = "litecoin-cli",
|
||||
.cli_args = "-testnet",
|
||||
.dust_limit = 100000,
|
||||
.max_funding_satoshi = 60 * ((1 << 24) - 1),
|
||||
.max_payment_msat = 60 * 0xFFFFFFFFULL,
|
||||
.dust_limit = { 100000 },
|
||||
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
|
||||
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
|
||||
.when_lightning_became_cool = 1,
|
||||
.testnet = true}
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "config.h"
|
||||
#include <bitcoin/block.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/amount.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct chainparams {
|
||||
|
@ -13,9 +14,9 @@ struct chainparams {
|
|||
const int rpc_port;
|
||||
const char *cli;
|
||||
const char *cli_args;
|
||||
const u64 dust_limit;
|
||||
const u64 max_funding_satoshi;
|
||||
const u64 max_payment_msat;
|
||||
const struct amount_sat dust_limit;
|
||||
const struct amount_sat max_funding;
|
||||
const struct amount_msat max_payment;
|
||||
const u32 when_lightning_became_cool;
|
||||
|
||||
/* Whether this is a test network or not */
|
||||
|
|
|
@ -245,8 +245,8 @@ static u64 advertised_htlc_max(const struct channel *channel)
|
|||
if (channel->funding_msat - cumulative_reserve_msat < lower_bound)
|
||||
lower_bound = channel->funding_msat - cumulative_reserve_msat;
|
||||
/* FIXME BOLT QUOTE: https://github.com/lightningnetwork/lightning-rfc/pull/512 once merged */
|
||||
if (channel->chainparams->max_payment_msat < lower_bound)
|
||||
lower_bound = channel->chainparams->max_payment_msat;
|
||||
if (channel->chainparams->max_payment.millisatoshis < lower_bound)
|
||||
lower_bound = channel->chainparams->max_payment.millisatoshis;
|
||||
return lower_bound;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,7 +357,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 > channel->chainparams->max_payment_msat) {
|
||||
if (htlc->msatoshi > channel->chainparams->max_payment.millisatoshis) {
|
||||
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ static struct command_result *check_amount(const struct wallet_tx *wtx,
|
|||
return command_fail(wtx->cmd, FUND_CANNOT_AFFORD,
|
||||
"Cannot afford transaction");
|
||||
}
|
||||
if (amount.satoshis < get_chainparams(wtx->cmd->ld)->dust_limit) {
|
||||
if (amount_sat_less(amount, get_chainparams(wtx->cmd->ld)->dust_limit)) {
|
||||
return command_fail(wtx->cmd, FUND_OUTPUT_IS_DUST,
|
||||
"Output %s would be dust",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
|
@ -93,7 +93,7 @@ struct command_result *wtx_select_utxos(struct wallet_tx *tx,
|
|||
if (res)
|
||||
return res;
|
||||
|
||||
if (tx->change.satoshis < get_chainparams(tx->cmd->ld)->dust_limit) {
|
||||
if (amount_sat_less(tx->change, get_chainparams(tx->cmd->ld)->dust_limit)) {
|
||||
tx->change = AMOUNT_SAT(0);
|
||||
tx->change_key_index = 0;
|
||||
} else {
|
||||
|
|
|
@ -1105,8 +1105,8 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
|||
/* FIXME: https://github.com/lightningnetwork/lightning-rfc/pull/512
|
||||
* says we MUST NOT exceed 2^32-1, but c-lightning did, so just trim
|
||||
* rather than rejecting. */
|
||||
if (htlc_maximum_msat > rstate->chainparams->max_payment_msat)
|
||||
htlc_maximum_msat = rstate->chainparams->max_payment_msat;
|
||||
if (htlc_maximum_msat > rstate->chainparams->max_payment.millisatoshis)
|
||||
htlc_maximum_msat = rstate->chainparams->max_payment.millisatoshis;
|
||||
|
||||
direction = channel_flags & 0x1;
|
||||
set_connection_values(chan, direction, fee_base_msat,
|
||||
|
|
|
@ -435,11 +435,11 @@ static struct command_result *json_invoice(struct command *cmd,
|
|||
|
||||
chainparams = get_chainparams(cmd->ld);
|
||||
if (msatoshi_val
|
||||
&& msatoshi_val->millisatoshis > chainparams->max_payment_msat) {
|
||||
&& amount_msat_greater(*msatoshi_val, chainparams->max_payment)) {
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"msatoshi cannot exceed %"PRIu64
|
||||
" millisatoshis",
|
||||
chainparams->max_payment_msat);
|
||||
"msatoshi cannot exceed %s",
|
||||
type_to_string(tmpctx, struct amount_msat,
|
||||
&chainparams->max_payment));
|
||||
}
|
||||
|
||||
if (fallbacks) {
|
||||
|
|
|
@ -825,7 +825,7 @@ static struct command_result *json_fund_channel(struct command *cmd,
|
|||
u8 *msg;
|
||||
struct amount_sat max_funding_satoshi;
|
||||
|
||||
max_funding_satoshi.satoshis = get_chainparams(cmd->ld)->max_funding_satoshi;
|
||||
max_funding_satoshi = get_chainparams(cmd->ld)->max_funding;
|
||||
|
||||
fc->cmd = cmd;
|
||||
fc->uc = NULL;
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
bool deprecated_apis = false;
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_msat_greater */
|
||||
bool amount_msat_greater(struct amount_msat a UNNEEDED, struct amount_msat b UNNEEDED)
|
||||
{ fprintf(stderr, "amount_msat_greater called!\n"); abort(); }
|
||||
/* Generated stub for amount_msat_sub_sat */
|
||||
bool amount_msat_sub_sat(struct amount_msat *val UNNEEDED,
|
||||
struct amount_msat a UNNEEDED,
|
||||
|
|
|
@ -449,10 +449,11 @@ static u8 *funder_channel(struct state *state,
|
|||
*...
|
||||
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
|
||||
*/
|
||||
if (state->funding_satoshis > state->chainparams->max_funding_satoshi)
|
||||
if (state->funding_satoshis > state->chainparams->max_funding.satoshis)
|
||||
status_failed(STATUS_FAIL_MASTER_IO,
|
||||
"funding_satoshis must be < %"PRIu64", not %"PRIu64,
|
||||
state->chainparams->max_funding_satoshi,
|
||||
"funding_satoshis must be < %s, not %"PRIu64,
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&state->chainparams->max_funding),
|
||||
state->funding_satoshis);
|
||||
|
||||
/* BOLT #2:
|
||||
|
@ -884,7 +885,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 > state->chainparams->max_funding_satoshi) {
|
||||
if (state->funding_satoshis > state->chainparams->max_funding.satoshis) {
|
||||
negotiation_failed(state, false,
|
||||
"funding_satoshis %"PRIu64" too large",
|
||||
state->funding_satoshis);
|
||||
|
|
|
@ -53,7 +53,7 @@ def test_invoice(node_factory):
|
|||
assert 'warning_capacity' in inv
|
||||
|
||||
# Make sure no wumbo invoices
|
||||
with pytest.raises(RpcError, match=r'msatoshi cannot exceed 4294967295 millisatoshis'):
|
||||
with pytest.raises(RpcError, match=r'msatoshi cannot exceed 4294967295msat'):
|
||||
l2.rpc.invoice(4294967295 + 1, 'inv3', '?')
|
||||
l2.rpc.invoice(4294967295, 'inv3', '?')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue