From 36a2491a8953075de9b50c489f698b38e55809cf Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 19 Jun 2022 16:46:11 +0930 Subject: [PATCH] json: fix up msat amounts in non-_msat fields. We had json_add_amount_msat_only(), which was designed to be used to print out msat fields, if we had sats. However, we misused it, so split it into the three different cases: 1. json_add_amount_sat_msat: We are using it correctly, with a field called xxx_msat. 2. json_add_amount_sats_deprecated: We were using it wrong, so deprecate the old field and create a new one which does end in _msat. 3. json_add_sats: we were using it to hand sats as a JSON parameter to an interface, where "XXXsat". Signed-off-by: Rusty Russell Changelog-Deprecated: Plugins: `rbf_channel` and `openchannel2` hooks `their_funding` (use `their_funding_msat`) Changelog-Deprecated: Plugins: `openchannel2` hook `dust_limit_satoshis` (use `dust_limit_msat`) Changelog-Deprecated: Plugins: `openchannel` hook `funding_satoshis` (use `funding_msat`) Changelog-Deprecated: Plugins: `openchannel` hook `dust_limit_satoshis` (use `dust_limit_msat`) Changelog-Deprecated: Plugins: `openchannel` hook `channel_reserve_satoshis` (use `channel_reserve_msat`) Changelog-Deprecated: Plugins: `channel_opened` notification `amount` (use `funding_msat`) Changelog-Deprecated: JSON-RPC: `listtransactions` `msat` (use `amount_msat`) Changelog-Deprecated: Plugins: `htlc_accepted` `forward_amount` (use `forward_msat`) --- .msggen.json | 1 + cln-grpc/proto/node.proto | 2 +- cln-grpc/src/convert.rs | 2 +- cln-rpc/src/model.rs | 4 +-- common/json.h | 2 +- common/json_helpers.c | 36 ++++++++++++++++--- common/json_helpers.h | 19 ++++++++-- common/test/run-json.c | 2 ++ .../test/run-route_blinding_override_test.c | 8 +++++ common/test/run-route_blinding_test.c | 8 +++++ devtools/Makefile | 1 + devtools/bolt12-cli.c | 3 +- doc/PLUGINS.md | 10 +++--- doc/lightning-listtransactions.7.md | 4 +-- doc/schemas/listtransactions.schema.json | 7 ++-- gossipd/test/run-check_channel_announcement.c | 2 ++ gossipd/test/run-check_node_announcement.c | 2 ++ gossipd/test/run-crc32_of_update.c | 2 ++ gossipd/test/run-extended-info.c | 2 ++ gossipd/test/run-next_block_range.c | 2 ++ gossipd/test/run-txout_failure.c | 2 ++ lightningd/dual_open_control.c | 24 +++++++------ lightningd/gossip_control.c | 2 +- lightningd/notification.c | 7 ++-- lightningd/opening_control.c | 10 +++--- lightningd/peer_control.c | 6 ++-- lightningd/peer_htlcs.c | 6 +++- lightningd/test/run-invoice-select-inchan.c | 10 +++--- plugins/bcli.c | 2 +- plugins/funder.c | 12 +++---- plugins/test/run-route-overlong.c | 2 +- plugins/txprepare.c | 2 +- tests/plugins/misc_notifications.py | 2 +- tests/plugins/openchannel_hook_accepter.py | 4 +-- tests/plugins/reject_odd_funding_amounts.py | 4 +-- tests/test_pay.py | 2 +- tests/test_plugin.py | 10 +++--- tests/test_wallet.py | 2 +- tests/utils.py | 2 +- wallet/reservation.c | 2 +- wallet/test/run-wallet.c | 12 +++---- wallet/walletrpc.c | 2 +- 42 files changed, 164 insertions(+), 82 deletions(-) diff --git a/.msggen.json b/.msggen.json index a664e3346919..5d4265428da1 100644 --- a/.msggen.json +++ b/.msggen.json @@ -806,6 +806,7 @@ "ListTransactions.transactions[].inputs[].type": 4 }, "ListtransactionsTransactionsOutputs": { + "ListTransactions.transactions[].outputs[].amount_msat": 6, "ListTransactions.transactions[].outputs[].channel": 5, "ListTransactions.transactions[].outputs[].index": 1, "ListTransactions.transactions[].outputs[].msat": 2, diff --git a/cln-grpc/proto/node.proto b/cln-grpc/proto/node.proto index a368f2078026..6925b54aed12 100644 --- a/cln-grpc/proto/node.proto +++ b/cln-grpc/proto/node.proto @@ -767,7 +767,7 @@ message ListtransactionsTransactionsOutputs { CHANNEL_UNILATERAL_CHEAT = 10; } uint32 index = 1; - Amount msat = 2; + Amount amount_msat = 6; bytes scriptPubKey = 3; optional ListtransactionsTransactionsOutputsType item_type = 4; optional string channel = 5; diff --git a/cln-grpc/src/convert.rs b/cln-grpc/src/convert.rs index c5c919d6c09e..18afaedfead3 100644 --- a/cln-grpc/src/convert.rs +++ b/cln-grpc/src/convert.rs @@ -546,7 +546,7 @@ impl From<&responses::ListtransactionsTransactionsOutputs> for pb::Listtransacti fn from(c: &responses::ListtransactionsTransactionsOutputs) -> Self { Self { index: c.index.clone(), // Rule #2 for type u32 - msat: Some(c.msat.into()), // Rule #2 for type msat + amount_msat: Some(c.amount_msat.into()), // Rule #2 for type msat script_pub_key: hex::decode(&c.script_pub_key).unwrap(), // Rule #2 for type hex item_type: c.item_type.map(|v| v as i32), channel: c.channel.as_ref().map(|v| v.to_string()), // Rule #2 for type short_channel_id? diff --git a/cln-rpc/src/model.rs b/cln-rpc/src/model.rs index 61697c4f848d..3155667ee8ac 100644 --- a/cln-rpc/src/model.rs +++ b/cln-rpc/src/model.rs @@ -1999,8 +1999,8 @@ pub mod responses { pub struct ListtransactionsTransactionsOutputs { #[serde(alias = "index")] pub index: u32, - #[serde(alias = "msat")] - pub msat: Amount, + #[serde(alias = "amount_msat")] + pub amount_msat: Amount, #[serde(alias = "scriptPubKey")] pub script_pub_key: String, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/common/json.h b/common/json.h index eb4fb05487f0..bdd867f5b46b 100644 --- a/common/json.h +++ b/common/json.h @@ -185,7 +185,7 @@ const char *json_scanv(const tal_t *ctx, /* '"fieldname" : "value"' or '"value"' if fieldname is NULL. Turns * any non-printable chars into JSON escapes, but leaves existing escapes alone. */ -void json_add_string(struct json_stream *result, const char *fieldname, const char *value); +void json_add_string(struct json_stream *result, const char *fieldname, const char *value TAKES); /* '"fieldname" : "value[:value_len]"' or '"value[:value_len]"' if * fieldname is NULL. Turns any non-printable chars into JSON diff --git a/common/json_helpers.c b/common/json_helpers.c index af06c2036a2e..baa7d3918104 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -1,7 +1,9 @@ #include "config.h" #include +#include #include #include +#include #include #include #include @@ -417,19 +419,43 @@ void json_add_amount_sat_compat(struct json_stream *result, const char *msatfieldname) { json_add_u64(result, rawfieldname, sat.satoshis); /* Raw: low-level helper */ - json_add_amount_sat_only(result, msatfieldname, sat); + json_add_amount_sat_msat(result, msatfieldname, sat); } -void json_add_amount_sat_only(struct json_stream *result, - const char *msatfieldname, - struct amount_sat sat) +void json_add_amount_sat_msat(struct json_stream *result, + const char *msatfieldname, + struct amount_sat sat) { struct amount_msat msat; + assert(strends(msatfieldname, "_msat")); if (amount_sat_to_msat(&msat, sat)) json_add_string(result, msatfieldname, type_to_string(tmpctx, struct amount_msat, &msat)); } +/* When I noticed that we were adding "XXXmsat" fields *not* ending in _msat */ +void json_add_amount_sats_deprecated(struct json_stream *result, + const char *fieldname, + const char *msatfieldname, + struct amount_sat sat) +{ + if (deprecated_apis) { + struct amount_msat msat; + assert(!strends(fieldname, "_msat")); + if (amount_sat_to_msat(&msat, sat)) + json_add_string(result, fieldname, + take(fmt_amount_msat(NULL, msat))); + } + json_add_amount_sat_msat(result, msatfieldname, sat); +} + +void json_add_sats(struct json_stream *result, + const char *fieldname, + struct amount_sat sat) +{ + json_add_string(result, fieldname, take(fmt_amount_sat(NULL, sat))); +} + void json_add_secret(struct json_stream *response, const char *fieldname, const struct secret *secret) { @@ -451,7 +477,7 @@ void json_add_preimage(struct json_stream *result, const char *fieldname, void json_add_lease_rates(struct json_stream *result, const struct lease_rates *rates) { - json_add_amount_sat_only(result, "lease_fee_base_msat", + json_add_amount_sat_msat(result, "lease_fee_base_msat", amount_sat(rates->lease_fee_base_sat)); json_add_num(result, "lease_fee_basis", rates->lease_fee_basis); json_add_num(result, "funding_weight", rates->funding_weight); diff --git a/common/json_helpers.h b/common/json_helpers.h index 1f5fe7fe3239..9a6673db0b82 100644 --- a/common/json_helpers.h +++ b/common/json_helpers.h @@ -167,11 +167,24 @@ void json_add_amount_msat_only(struct json_stream *result, NO_NULL_ARGS; /* Adds an 'msat' field */ -void json_add_amount_sat_only(struct json_stream *result, - const char *msatfieldname, - struct amount_sat sat) +void json_add_amount_sat_msat(struct json_stream *result, + const char *msatfieldname, + struct amount_sat sat) NO_NULL_ARGS; +/* Adds an 'msat' field, and an older deprecated field. */ +void json_add_amount_sats_deprecated(struct json_stream *result, + const char *fieldname, + const char *msatfieldname, + struct amount_sat sat) + NO_NULL_ARGS; + +/* This is used to create requests, *never* for output (output is always + * msat!) */ +void json_add_sats(struct json_stream *result, + const char *fieldname, + struct amount_sat sat); + void json_add_sha256(struct json_stream *result, const char *fieldname, const struct sha256 *hash); diff --git a/common/test/run-json.c b/common/test/run-json.c index d5511bce4da8..db437a5e734f 100644 --- a/common/test/run-json.c +++ b/common/test/run-json.c @@ -8,6 +8,8 @@ #include /* AUTOGENERATED MOCKS START */ +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/common/test/run-route_blinding_override_test.c b/common/test/run-route_blinding_override_test.c index c54af6078c33..4fbfd01d8df9 100644 --- a/common/test/run-route_blinding_override_test.c +++ b/common/test/run-route_blinding_override_test.c @@ -53,6 +53,14 @@ struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u /* Generated stub for amount_tx_fee */ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) { fprintf(stderr, "amount_tx_fee called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; +/* Generated stub for fmt_amount_msat */ +const char *fmt_amount_msat(const tal_t *ctx UNNEEDED, struct amount_msat msat UNNEEDED) +{ fprintf(stderr, "fmt_amount_msat called!\n"); abort(); } +/* Generated stub for fmt_amount_sat */ +const char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED) +{ fprintf(stderr, "fmt_amount_sat called!\n"); abort(); } /* Generated stub for fromwire_amount_msat */ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) { fprintf(stderr, "fromwire_amount_msat called!\n"); abort(); } diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c index 6c2f9bbd3aae..82c0b7f2bbf0 100644 --- a/common/test/run-route_blinding_test.c +++ b/common/test/run-route_blinding_test.c @@ -53,6 +53,14 @@ struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u /* Generated stub for amount_tx_fee */ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) { fprintf(stderr, "amount_tx_fee called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; +/* Generated stub for fmt_amount_msat */ +const char *fmt_amount_msat(const tal_t *ctx UNNEEDED, struct amount_msat msat UNNEEDED) +{ fprintf(stderr, "fmt_amount_msat called!\n"); abort(); } +/* Generated stub for fmt_amount_sat */ +const char *fmt_amount_sat(const tal_t *ctx UNNEEDED, struct amount_sat sat UNNEEDED) +{ fprintf(stderr, "fmt_amount_sat called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } diff --git a/devtools/Makefile b/devtools/Makefile index 35ba6da51ced..fd3f66a37516 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -22,6 +22,7 @@ DEVTOOLS_COMMON_OBJS := \ common/bolt11.o \ common/blockheight_states.o \ common/channel_id.o \ + common/configdir.o \ common/decode_array.o \ common/features.o \ common/fee_states.o \ diff --git a/devtools/bolt12-cli.c b/devtools/bolt12-cli.c index a285e851186a..86da7e961ef7 100644 --- a/devtools/bolt12-cli.c +++ b/devtools/bolt12-cli.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #define ERROR_USAGE 3 static bool well_formed = true; -bool deprecated_apis = true; /* Tal wrappers for opt. */ static void *opt_allocfn(size_t size) @@ -463,6 +463,7 @@ int main(int argc, char *argv[]) char *fail; common_setup(argv[0]); + deprecated_apis = true; opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn); opt_register_noarg("--help|-h", opt_usage_and_exit, diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index 553ca10516c9..fdf07e3fe2a7 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -410,7 +410,7 @@ if the funding transaction has been included into a block. { "channel_opened": { "id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f", - "funding_satoshis": "100000000msat", + "funding_msat": "100000000msat", "funding_txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", "funding_locked": false } @@ -721,7 +721,7 @@ i.e. only definitively resolved HTLCs or confirmed bitcoin transactions. "part_id": 0, // (`channel_mvt` only, optional) "credit":"2000000000msat", "debit":"0msat", - "output_value": "2000000000msat", // ('chain_mvt' only) + "output_msat": "2000000000msat", // ('chain_mvt' only) "output_count": 2, // ('chain_mvt' only, typically only channel closes) "fees": "382msat", // ('channel_mvt' only) "tags": ["deposit"], @@ -1185,8 +1185,8 @@ the v2 protocol, and it has passed basic sanity checks: "openchannel2": { "id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f", "channel_id": "252d1b0a1e57895e84137f28cf19ab2c35847e284c112fefdecc7afeaa5c1de7", - "their_funding": "100000000msat", - "dust_limit_satoshis": "546000msat", + "their_funding_msat": "100000000msat", + "dust_limit_msat": "546000msat", "max_htlc_value_in_flight_msat": "18446744073709551615msat", "htlc_minimum_msat": "0msat", "funding_feerate_per_kw": 7500, @@ -1323,7 +1323,7 @@ requests an RBF for a channel funding transaction. "rbf_channel": { "id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f", "channel_id": "252d1b0a1e57895e84137f28cf19ab2c35847e284c112fefdecc7afeaa5c1de7", - "their_funding": "100000000msat", + "their_funding_msat": "100000000msat", "funding_feerate_per_kw": 7500, "feerate_our_max": 10000, "feerate_our_min": 253, diff --git a/doc/lightning-listtransactions.7.md b/doc/lightning-listtransactions.7.md index 157fc0126b0d..ed219f631076 100644 --- a/doc/lightning-listtransactions.7.md +++ b/doc/lightning-listtransactions.7.md @@ -40,7 +40,7 @@ On success, an object containing **transactions** is returned. It is an array o - **channel** (short_channel_id, optional): the channel this input is associated with (*EXPERIMENTAL_FEATURES* only) - **outputs** (array of objects): Each output, in order: - **index** (u32): the 0-based output number - - **msat** (msat): the amount of the output + - **amount_msat** (msat): the amount of the output - **scriptPubKey** (hex): the scriptPubKey - **type** (string, optional): the purpose of this output (*EXPERIMENTAL_FEATURES* only) (one of "theirs", "deposit", "withdraw", "channel_funding", "channel_mutual_close", "channel_unilateral_close", "channel_sweep", "channel_htlc_success", "channel_htlc_timeout", "channel_penalty", "channel_unilateral_cheat") - **channel** (short_channel_id, optional): the channel this output is associated with (*EXPERIMENTAL_FEATURES* only) @@ -104,4 +104,4 @@ RESOURCES --------- Main web site: -[comment]: # ( SHA256STAMP:bd9c33dd27be0f25b0212b4115714768ffbec2ff6e72f083613a4464a3f98bc0) +[comment]: # ( SHA256STAMP:74408f25dcf548f1389ab41123748297ba3116ad75afb41b86ecca453b95fec8) diff --git a/doc/schemas/listtransactions.schema.json b/doc/schemas/listtransactions.schema.json index 0b41b17c779f..3c34ba896372 100644 --- a/doc/schemas/listtransactions.schema.json +++ b/doc/schemas/listtransactions.schema.json @@ -126,7 +126,7 @@ "additionalProperties": false, "required": [ "index", - "msat", + "amount_msat", "scriptPubKey" ], "properties": { @@ -134,10 +134,13 @@ "type": "u32", "description": "the 0-based output number" }, - "msat": { + "amount_msat": { "type": "msat", "description": "the amount of the output" }, + "msat": { + "deprecated": true + }, "scriptPubKey": { "type": "hex", "description": "the scriptPubKey" diff --git a/gossipd/test/run-check_channel_announcement.c b/gossipd/test/run-check_channel_announcement.c index ded89931d24e..a25e48e60f8d 100644 --- a/gossipd/test/run-check_channel_announcement.c +++ b/gossipd/test/run-check_channel_announcement.c @@ -59,6 +59,8 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, const struct half_chan *hc UNNEEDED, const u8 *cupdate UNNEEDED) { fprintf(stderr, "cupdate_different called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/gossipd/test/run-check_node_announcement.c b/gossipd/test/run-check_node_announcement.c index 7d20a8720211..0a53fe4b523e 100644 --- a/gossipd/test/run-check_node_announcement.c +++ b/gossipd/test/run-check_node_announcement.c @@ -27,6 +27,8 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED, /* Generated stub for daemon_conn_send */ void daemon_conn_send(struct daemon_conn *dc UNNEEDED, const u8 *msg UNNEEDED) { fprintf(stderr, "daemon_conn_send called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/gossipd/test/run-crc32_of_update.c b/gossipd/test/run-crc32_of_update.c index 3b46a0f54c15..f02f52d9d934 100644 --- a/gossipd/test/run-crc32_of_update.c +++ b/gossipd/test/run-crc32_of_update.c @@ -45,6 +45,8 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED, /* Generated stub for decode_short_ids */ struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED) { fprintf(stderr, "decode_short_ids called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/gossipd/test/run-extended-info.c b/gossipd/test/run-extended-info.c index a89dabd99a8a..142ba69cdc09 100644 --- a/gossipd/test/run-extended-info.c +++ b/gossipd/test/run-extended-info.c @@ -45,6 +45,8 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED, /* Generated stub for decode_short_ids */ struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED) { fprintf(stderr, "decode_short_ids called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/gossipd/test/run-next_block_range.c b/gossipd/test/run-next_block_range.c index bad28d36720a..21255cad152e 100644 --- a/gossipd/test/run-next_block_range.c +++ b/gossipd/test/run-next_block_range.c @@ -26,6 +26,8 @@ bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED, const struct sha256 *h UNNEEDED, struct pubkey *next UNNEEDED) { fprintf(stderr, "blinding_next_pubkey called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/gossipd/test/run-txout_failure.c b/gossipd/test/run-txout_failure.c index f6687c5bd8fd..10a9b4f34499 100644 --- a/gossipd/test/run-txout_failure.c +++ b/gossipd/test/run-txout_failure.c @@ -30,6 +30,8 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, const struct half_chan *hc UNNEEDED, const u8 *cupdate UNNEEDED) { fprintf(stderr, "cupdate_different called!\n"); abort(); } +/* Generated stub for deprecated_apis */ +bool deprecated_apis; /* Generated stub for ecdh */ void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED) { fprintf(stderr, "ecdh called!\n"); abort(); } diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index d8ac1264396c..d72270a0d0b8 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -195,8 +195,9 @@ static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload, json_object_start(stream, "rbf_channel"); json_add_node_id(stream, "id", &payload->peer_id); json_add_channel_id(stream, "channel_id", &payload->channel_id); - json_add_amount_sat_only(stream, "their_funding", - payload->their_funding); + json_add_amount_sats_deprecated(stream, + "their_funding", "their_funding_msat", + payload->their_funding); json_add_num(stream, "locktime", payload->locktime); json_add_num(stream, "feerate_our_max", payload->feerate_our_max); @@ -204,7 +205,7 @@ static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload, payload->feerate_our_min); json_add_num(stream, "funding_feerate_per_kw", payload->funding_feerate_per_kw); - json_add_amount_sat_only(stream, "channel_max_msat", + json_add_amount_sat_msat(stream, "channel_max_msat", payload->channel_max); json_object_end(stream); } @@ -263,10 +264,11 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload, json_object_start(stream, "openchannel2"); json_add_node_id(stream, "id", &payload->peer_id); json_add_channel_id(stream, "channel_id", &payload->channel_id); - json_add_amount_sat_only(stream, "their_funding", - payload->their_funding); - json_add_amount_sat_only(stream, "dust_limit_satoshis", - payload->dust_limit_satoshis); + json_add_amount_sats_deprecated(stream, "their_funding", "their_funding_msat", + payload->their_funding); + json_add_amount_sats_deprecated(stream, "dust_limit_satoshis", + "dust_limit_msat", + payload->dust_limit_satoshis); json_add_amount_msat_only(stream, "max_htlc_value_in_flight_msat", payload->max_htlc_value_in_flight_msat); json_add_amount_msat_only(stream, "htlc_minimum_msat", @@ -286,10 +288,10 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload, if (tal_bytelen(payload->shutdown_scriptpubkey) != 0) json_add_hex_talarr(stream, "shutdown_scriptpubkey", payload->shutdown_scriptpubkey); - json_add_amount_sat_only(stream, "channel_max_msat", + json_add_amount_sat_msat(stream, "channel_max_msat", payload->channel_max); if (!amount_sat_zero(payload->requested_lease_amt)) { - json_add_amount_sat_only(stream, "requested_lease_msat", + json_add_amount_sat_msat(stream, "requested_lease_msat", payload->requested_lease_amt); json_add_num(stream, "lease_blockheight_start", payload->lease_blockheight_start); @@ -1632,8 +1634,8 @@ static void handle_dry_run_finished(struct subd *dualopend, const u8 *msg) channel->open_attempt = tal_free(channel->open_attempt); response = json_stream_success(cmd); - json_add_amount_sat_only(response, "our_funding_msat", our_funding); - json_add_amount_sat_only(response, "their_funding_msat", their_funding); + json_add_amount_sat_msat(response, "our_funding_msat", our_funding); + json_add_amount_sat_msat(response, "their_funding_msat", their_funding); if (rates) { json_add_lease_rates(response, rates); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 9b36baf749f2..5e23e8b57225 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -401,7 +401,7 @@ static struct command_result *json_setleaserates(struct command *cmd, take(towire_gossipd_new_lease_rates(NULL, rates))); res = json_stream_success(cmd); - json_add_amount_sat_only(res, "lease_fee_base_msat", + json_add_amount_sat_msat(res, "lease_fee_base_msat", amount_sat(rates->lease_fee_base_sat)); json_add_num(res, "lease_fee_basis", rates->lease_fee_basis); json_add_num(res, "funding_weight", rates->funding_weight); diff --git a/lightningd/notification.c b/lightningd/notification.c index 1ea4851068ad..00b29cf71691 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -205,7 +205,7 @@ static void channel_opened_notification_serialize(struct json_stream *stream, { json_object_start(stream, "channel_opened"); json_add_node_id(stream, "id", node_id); - json_add_amount_sat_only(stream, "amount", *funding_sat); + json_add_amount_sats_deprecated(stream, "amount", "funding_msat", *funding_sat); json_add_txid(stream, "funding_txid", funding_txid); json_add_bool(stream, "funding_locked", funding_locked); json_object_end(stream); @@ -482,8 +482,9 @@ static void coin_movement_notification_serialize(struct json_stream *stream, json_add_amount_msat_only(stream, "debit", mvt->debit); /* Only chain movements */ if (mvt->output_val) - json_add_amount_sat_only(stream, "output_value", - *mvt->output_val); + json_add_amount_sats_deprecated(stream, "output_value", + "output_msat", + *mvt->output_val); if (mvt->output_count > 0) json_add_num(stream, "output_count", mvt->output_count); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 9499a76e3e41..17bffd21dd5a 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -605,14 +605,14 @@ static void openchannel_hook_serialize(struct openchannel_hook_payload *payload, struct uncommitted_channel *uc = payload->openingd->channel; json_object_start(stream, "openchannel"); json_add_node_id(stream, "id", &uc->peer->id); - json_add_amount_sat_only(stream, "funding_satoshis", - payload->funding_satoshis); + json_add_amount_sats_deprecated(stream, "funding_satoshis", "funding_msat", + payload->funding_satoshis); json_add_amount_msat_only(stream, "push_msat", payload->push_msat); - json_add_amount_sat_only(stream, "dust_limit_satoshis", - payload->dust_limit_satoshis); + json_add_amount_sats_deprecated(stream, "dust_limit_satoshis", "dust_limit_msat", + payload->dust_limit_satoshis); json_add_amount_msat_only(stream, "max_htlc_value_in_flight_msat", payload->max_htlc_value_in_flight_msat); - json_add_amount_sat_only(stream, "channel_reserve_satoshis", + json_add_amount_sats_deprecated(stream, "channel_reserve_satoshis", "channel_reserve_msat", payload->channel_reserve_satoshis); json_add_amount_msat_only(stream, "htlc_minimum_msat", payload->htlc_minimum_msat); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 6dd8eb3fa783..e3cb6c8d33dc 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -639,7 +639,7 @@ static void json_add_channel(struct lightningd *ld, bitcoin_txid(channel->last_tx, &txid); json_add_txid(response, "scratch_txid", &txid); - json_add_amount_sat_only(response, "last_tx_fee_msat", + json_add_amount_sat_msat(response, "last_tx_fee_msat", bitcoin_tx_compute_fee(channel->last_tx)); } @@ -708,10 +708,10 @@ static void json_add_channel(struct lightningd *ld, inflight->funding->feerate, feerate_style_name( FEERATE_PER_KSIPA))); - json_add_amount_sat_only(response, + json_add_amount_sat_msat(response, "total_funding_msat", inflight->funding->total_funds); - json_add_amount_sat_only(response, + json_add_amount_sat_msat(response, "our_funding_msat", inflight->funding->our_funds); /* Add the expected commitment tx id also */ diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 1cf1acca24e7..04e94dc1fd66 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1044,7 +1044,11 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p, if (p->payload->forward_channel) json_add_short_channel_id(s, "short_channel_id", p->payload->forward_channel); - json_add_amount_msat_only(s, "forward_amount", + if (deprecated_apis) + json_add_string(s, "forward_amount", + fmt_amount_msat(tmpctx, + p->payload->amt_to_forward)); + json_add_amount_msat_only(s, "forward_msat", p->payload->amt_to_forward); json_add_u32(s, "outgoing_cltv_value", p->payload->outgoing_cltv); /* These are specified together in TLV, so only print total_msat diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index e064deb24cb8..5e14ae9ff1ae 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -316,12 +316,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED, const char *msatfieldname) { fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); } -/* Generated stub for json_add_amount_sat_only */ -void json_add_amount_sat_only(struct json_stream *result UNNEEDED, - const char *msatfieldname UNNEEDED, - struct amount_sat sat) +/* Generated stub for json_add_amount_sat_msat */ +void json_add_amount_sat_msat(struct json_stream *result UNNEEDED, + const char *msatfieldname UNNEEDED, + struct amount_sat sat) -{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); } +{ fprintf(stderr, "json_add_amount_sat_msat called!\n"); abort(); } /* Generated stub for json_add_bolt11 */ void json_add_bolt11(struct json_stream *response UNNEEDED, const struct bolt11 *b11 UNNEEDED) diff --git a/plugins/bcli.c b/plugins/bcli.c index 5f0922c77812..514aa0f621b5 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -414,7 +414,7 @@ static struct command_result *process_getutxout(struct bitcoin_cli *bcli) return command_err_bcli_badjson(bcli, err); response = jsonrpc_stream_success(bcli->cmd); - json_add_amount_sat_only(response, "amount", output.amount); + json_add_sats(response, "amount", output.amount); json_add_string(response, "script", tal_hex(response, output.script)); return command_finished(bcli->cmd, response); diff --git a/plugins/funder.c b/plugins/funder.c index 7880a6dbaec5..7967bec3cd2c 100644 --- a/plugins/funder.c +++ b/plugins/funder.c @@ -511,7 +511,7 @@ json_openchannel2_call(struct command *cmd, "{openchannel2:" "{id:%" ",channel_id:%" - ",their_funding:%" + ",their_funding_msat:%" ",max_htlc_value_in_flight_msat:%" ",htlc_minimum_msat:%" ",funding_feerate_per_kw:%" @@ -768,15 +768,15 @@ static void json_add_policy(struct json_stream *stream, funder_opt_name(policy->opt)); json_add_num(stream, "policy_mod", policy->mod); json_add_bool(stream, "leases_only", policy->leases_only); - json_add_amount_sat_only(stream, "min_their_funding_msat", + json_add_amount_sat_msat(stream, "min_their_funding_msat", policy->min_their_funding); - json_add_amount_sat_only(stream, "max_their_funding_msat", + json_add_amount_sat_msat(stream, "max_their_funding_msat", policy->max_their_funding); - json_add_amount_sat_only(stream, "per_channel_min_msat", + json_add_amount_sat_msat(stream, "per_channel_min_msat", policy->per_channel_min); - json_add_amount_sat_only(stream, "per_channel_max_msat", + json_add_amount_sat_msat(stream, "per_channel_max_msat", policy->per_channel_max); - json_add_amount_sat_only(stream, "reserve_tank_msat", + json_add_amount_sat_msat(stream, "reserve_tank_msat", policy->reserve_tank); json_add_num(stream, "fuzz_percent", policy->fuzz_factor); json_add_num(stream, "fund_probability", policy->fund_probability); diff --git a/plugins/test/run-route-overlong.c b/plugins/test/run-route-overlong.c index 2ca73fd9452e..42271efcd5fe 100644 --- a/plugins/test/run-route-overlong.c +++ b/plugins/test/run-route-overlong.c @@ -73,7 +73,7 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const struct short_channel_id *id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ -void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED) +void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED) { fprintf(stderr, "json_add_string called!\n"); abort(); } /* Generated stub for json_add_timeabs */ void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, diff --git a/plugins/txprepare.c b/plugins/txprepare.c index 4de70d44fb47..90d3783bc2c4 100644 --- a/plugins/txprepare.c +++ b/plugins/txprepare.c @@ -378,7 +378,7 @@ static struct command_result *txprepare_continue(struct command *cmd, } if (txp->all_output_idx == -1) - json_add_amount_sat_only(req->js, "satoshi", txp->output_total); + json_add_sats(req->js, "satoshi", txp->output_total); else json_add_string(req->js, "satoshi", "all"); diff --git a/tests/plugins/misc_notifications.py b/tests/plugins/misc_notifications.py index eb019e16a8ef..f11b4da0614a 100755 --- a/tests/plugins/misc_notifications.py +++ b/tests/plugins/misc_notifications.py @@ -18,7 +18,7 @@ def init(plugin, options, configuration): def channel_opened(plugin, channel_opened, **kwargs): plugin.log("A channel was opened to us by {}, with an amount" " of {} and the following funding transaction id: {}" - .format(channel_opened["id"], channel_opened["amount"], + .format(channel_opened["id"], channel_opened["funding_msat"], channel_opened["funding_txid"])) diff --git a/tests/plugins/openchannel_hook_accepter.py b/tests/plugins/openchannel_hook_accepter.py index bf63cf146f15..be409fa45cb4 100755 --- a/tests/plugins/openchannel_hook_accepter.py +++ b/tests/plugins/openchannel_hook_accepter.py @@ -52,13 +52,13 @@ def run_openchannel(funding_sats_str, plugin): @plugin.hook('openchannel') def on_openchannel(openchannel, plugin, **kwargs): - return run_openchannel(openchannel['funding_satoshis'], plugin) + return run_openchannel(openchannel['funding_msat'], plugin) @plugin.hook('openchannel2') def on_openchannel2(openchannel2, plugin, **kwargs): """ Support for v2 channel opens """ - return run_openchannel(openchannel2['their_funding'], plugin) + return run_openchannel(openchannel2['their_funding_msat'], plugin) plugin.run() diff --git a/tests/plugins/reject_odd_funding_amounts.py b/tests/plugins/reject_odd_funding_amounts.py index adf0efc007bd..fc4d67a338b6 100755 --- a/tests/plugins/reject_odd_funding_amounts.py +++ b/tests/plugins/reject_odd_funding_amounts.py @@ -21,7 +21,7 @@ def on_openchannel(openchannel, plugin, **kwargs): print("{} VARS".format(len(openchannel.keys()))) for k in sorted(openchannel.keys()): print("{}={}".format(k, openchannel[k])) - return run_check(openchannel['funding_satoshis']) + return run_check(openchannel['funding_msat']) @plugin.hook('openchannel2') @@ -30,7 +30,7 @@ def on_openchannel2(openchannel2, plugin, **kwargs): for k in sorted(openchannel2.keys()): print("{}={}".format(k, openchannel2[k])) - return run_check(openchannel2['their_funding']) + return run_check(openchannel2['their_funding_msat']) plugin.run() diff --git a/tests/test_pay.py b/tests/test_pay.py index 73585ba7b884..65ff87ea52b8 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3111,7 +3111,7 @@ def test_partial_payment(node_factory, bitcoind, executor): for i in range(2): line = l4.daemon.wait_for_log('print_htlc_onion.py: Got onion') assert "'type': 'tlv'" in line - assert "'forward_amount': '499msat'" in line or "'forward_amount': '501msat'" in line + assert "'forward_msat': '499msat'" in line or "'forward_msat': '501msat'" in line assert "'total_msat': '1000msat'" in line assert "'payment_secret': '{}'".format(paysecret) in line diff --git a/tests/test_plugin.py b/tests/test_plugin.py index b9776b9bd6b3..40a4250ee9e3 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -626,7 +626,7 @@ def test_openchannel_hook(node_factory, bitcoind): # Make sure plugin got all the vars we expect expected = { 'channel_flags': '1', - 'dust_limit_satoshis': '546000msat', + 'dust_limit_msat': '546000msat', 'htlc_minimum_msat': '0msat', 'id': l1.info['id'], 'max_accepted_htlcs': '483', @@ -643,14 +643,14 @@ def test_openchannel_hook(node_factory, bitcoind): 'feerate_our_max': '150000', 'feerate_our_min': '1875', 'locktime': '.*', - 'their_funding': '100000000msat', + 'their_funding_msat': '100000000msat', 'channel_max_msat': '16777215000msat', }) else: expected.update({ - 'channel_reserve_satoshis': '1000000msat', + 'channel_reserve_msat': '1000000msat', 'feerate_per_kw': '7500', - 'funding_satoshis': '100000000msat', + 'funding_msat': '100000000msat', 'push_msat': '0msat', }) @@ -1148,7 +1148,7 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor): assert onion['type'] == 'tlv' assert re.match(r'^11020203e80401..0608................$', onion['payload']) assert len(onion['shared_secret']) == 64 - assert onion['forward_amount'] == '1000msat' + assert onion['forward_msat'] == '1000msat' assert len(onion['next_onion']) == 2 * (1300 + 32 + 33 + 1) f1.result() diff --git a/tests/test_wallet.py b/tests/test_wallet.py index d53d4d9f1281..8cab032acc43 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -952,7 +952,7 @@ def test_transaction_annotations(node_factory, bitcoind): assert(len(txs) == 1) tx = txs[0] output = tx['outputs'][idx] - assert(output['type'] == 'deposit' and output['msat'] == Millisatoshi(1000000000)) + assert(output['type'] == 'deposit' and output['amount_msat'] == Millisatoshi(1000000000)) # ... and all other output should be change, and have no annotations types = [] diff --git a/tests/utils.py b/tests/utils.py index e56b7d6acd5f..682dc535059d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -189,7 +189,7 @@ def extract_utxos(moves): for ev in evs: if ev[0]['vout'] == m['vout']: ev[1] = m - assert ev[0]['output_value'] == m['output_value'] + assert ev[0]['output_msat'] == m['output_msat'] break return utxos diff --git a/wallet/reservation.c b/wallet/reservation.c index 7130159a4d14..f36622536265 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -413,7 +413,7 @@ static struct command_result *finish_psbt(struct command *cmd, json_add_psbt(response, "psbt", psbt); json_add_num(response, "feerate_per_kw", feerate_per_kw); json_add_num(response, "estimated_final_weight", weight); - json_add_amount_sat_only(response, "excess_msat", excess); + json_add_amount_sat_msat(response, "excess_msat", excess); if (excess_as_change) json_add_num(response, "change_outnum", change_outnum); if (reserve) diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 005f4150de64..3c7802e2ba98 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -302,12 +302,12 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED, const char *msatfieldname) { fprintf(stderr, "json_add_amount_sat_compat called!\n"); abort(); } -/* Generated stub for json_add_amount_sat_only */ -void json_add_amount_sat_only(struct json_stream *result UNNEEDED, - const char *msatfieldname UNNEEDED, - struct amount_sat sat) +/* Generated stub for json_add_amount_sat_msat */ +void json_add_amount_sat_msat(struct json_stream *result UNNEEDED, + const char *msatfieldname UNNEEDED, + struct amount_sat sat) -{ fprintf(stderr, "json_add_amount_sat_only called!\n"); abort(); } +{ fprintf(stderr, "json_add_amount_sat_msat called!\n"); abort(); } /* Generated stub for json_add_bool */ void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, bool value UNNEEDED) @@ -356,7 +356,7 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const struct short_channel_id *id UNNEEDED) { fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); } /* Generated stub for json_add_string */ -void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED) +void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value TAKES UNNEEDED) { fprintf(stderr, "json_add_string called!\n"); abort(); } /* Generated stub for json_add_timeabs */ void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 9d7ad17027d9..88df58ab3f24 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -558,7 +558,7 @@ static void json_transaction_details(struct json_stream *response, json_object_start(response, NULL); json_add_u32(response, "index", i); - json_add_amount_sat_only(response, "msat", sat); + json_add_amount_sats_deprecated(response, "msat", "amount_msat", sat); #if EXPERIMENTAL_FEATURES struct tx_annotation *ann = &tx->output_annotations[i];