From c3efba16ff2cb440bd53bb84693fd282bf2decf5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2022 19:52:09 +0930 Subject: [PATCH] JSON: don't print deprecated amount fields any more A small change in one routine creates a lot of changes! We actually recommended moving away from these in v0.7.0 (2019-02-28), but never deprecated them formally. Changelog-Deprecated: JSON-RPC: `pay`, `decode`, `decodepay`, `getroute`, `listinvoices`, `listpays` and `listsendpays` `msatoshi` fields (use `amount_msat`). Changelog-Deprecated: JSON-RPC: `getinfo` `msatoshi_fees_collected` field (use `fees_collected_msat`). Changelog-Deprecated: JSON-RPC: `listpeers` `channels`: `msatoshi_to_us`, `msatoshi_to_us_min`, `msatoshi_to_us_max`, `msatoshi_total`, `dust_limit_satoshis`, `our_channel_reserve_satoshis`, `their_channel_reserve_satoshis`, `spendable_msatoshi`, `receivable_msatoshi`, `in_msatoshi_offered`, `in_msatoshi_fulfilled`, `out_msatoshi_offered`, `out_msatoshi_fulfilled`, `max_htlc_value_in_flight_msat` and `htlc_minimum_msat` (use `to_us_msat`, `min_to_us_msat`, `max_to_us_msat`, `total_msat`, `dust_limit_msat`, `our_reserve_msat`, `their_reserve_msat`, `spendable_msat`, `receivable_msat`, `in_offered_msat`, `in_fulfilled_msat`, `out_offered_msat`, `out_fulfilled_msat`, `max_total_htlc_in_msat` and `minimum_htlc_in_msat`). Changelog-Deprecated: JSON-RPC: `listinvoices` and `pay` `msatoshi_received` and `msatoshi_sent` (use `amount_received_msat`, `amount_sent_msat`) Changelog-Deprecated: JSON-RPC: `listpays` and `listsendpays` `msatoshi_sent` (use `amount_sent_msat`) Changelog-Deprecated: JSON-RPC: `listforwards` `in_msatoshi`, `out_msatoshi` and `fee` (use `in_msat`, `out_msat` and `fee_msat`) Changelog-Deprecated: JSON-RPC: `listfunds` `outputs` `value` (use `amount_msat`) Signed-off-by: Rusty Russell --- common/json_helpers.c | 11 +++++------ doc/lightning-listfunds.7.md | 2 +- doc/schemas/listfunds.schema.json | 4 ---- tests/test_gossip.py | 2 -- tests/test_misc.py | 1 - tests/test_pay.py | 14 ++++---------- tests/test_wallet.py | 2 +- 7 files changed, 11 insertions(+), 25 deletions(-) diff --git a/common/json_helpers.c b/common/json_helpers.c index 3b1e210ce..aaf601435 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -401,9 +401,8 @@ void json_add_amount_msat_compat(struct json_stream *result, const char *rawfieldname, const char *msatfieldname) { - json_add_u64(result, rawfieldname, msat.millisatoshis); /* Raw: low-level helper */ - if (!deprecated_apis) - assert(strends(msatfieldname, "_msat")); + if (deprecated_apis) + json_add_u64(result, rawfieldname, msat.millisatoshis); /* Raw: low-level helper */ json_add_amount_msat_only(result, msatfieldname, msat); } @@ -422,7 +421,8 @@ void json_add_amount_sat_compat(struct json_stream *result, const char *rawfieldname, const char *msatfieldname) { - json_add_u64(result, rawfieldname, sat.satoshis); /* Raw: low-level helper */ + if (deprecated_apis) + json_add_u64(result, rawfieldname, sat.satoshis); /* Raw: low-level helper */ json_add_amount_sat_msat(result, msatfieldname, sat); } @@ -433,8 +433,7 @@ void json_add_amount_sat_msat(struct json_stream *result, 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)); + json_add_amount_msat_only(result, msatfieldname, msat); } /* When I noticed that we were adding "XXXmsat" fields *not* ending in _msat */ diff --git a/doc/lightning-listfunds.7.md b/doc/lightning-listfunds.7.md index d2dc247fd..1ce69088b 100644 --- a/doc/lightning-listfunds.7.md +++ b/doc/lightning-listfunds.7.md @@ -68,4 +68,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:e2b4f817ca6032ab4421fccaba226c03e0995c8dbfbfeb2f7c8572987ffe7dc4) +[comment]: # ( SHA256STAMP:fdc550a0ff11f6fbbf51c29340c0494077d831566ae7ab008cce4b93034a76c5) diff --git a/doc/schemas/listfunds.schema.json b/doc/schemas/listfunds.schema.json index bd1f73382..5ebd497af 100644 --- a/doc/schemas/listfunds.schema.json +++ b/doc/schemas/listfunds.schema.json @@ -33,10 +33,6 @@ "type": "msat", "description": "the amount of the output" }, - "value": { - "type": "u64", - "deprecated": true - }, "scriptpubkey": { "type": "hex", "description": "the scriptPubkey of the output" diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 0b1cd7619..750bdd63b 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -2019,7 +2019,6 @@ def test_gossip_store_upgrade_v7_v8(node_factory): 'destination': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'short_channel_id': '103x1x1', 'public': False, - 'satoshis': 1000000, 'amount_msat': Millisatoshi(1000000000), 'message_flags': 1, 'channel_flags': 0, @@ -2036,7 +2035,6 @@ def test_gossip_store_upgrade_v7_v8(node_factory): 'destination': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'short_channel_id': '103x1x1', 'public': False, - 'satoshis': 1000000, 'amount_msat': Millisatoshi(1000000000), 'message_flags': 1, 'channel_flags': 1, diff --git a/tests/test_misc.py b/tests/test_misc.py index 793c6fb5f..e2ac16fd7 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -969,7 +969,6 @@ def test_cli(node_factory): ' "invoices": [', ' {', r' "label": "l\"[]{}",', - ' "msatoshi": 123000,', ' "amount_msat": "123000msat",', ' "status": "unpaid",', r' "description": "d\"[]{}",', diff --git a/tests/test_pay.py b/tests/test_pay.py index d1037f293..159a63db6 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -1292,11 +1292,9 @@ def test_forward_pad_fees_and_cltv(node_factory, bitcoind): assert route[1]['delay'] == 9 # Modify so we overpay, overdo the cltv. - route[0]['msatoshi'] += 2000 - route[0]['amount_msat'] = Millisatoshi(route[0]['msatoshi']) + route[0]['amount_msat'] += 2000 route[0]['delay'] += 20 - route[1]['msatoshi'] += 1000 - route[1]['amount_msat'] = Millisatoshi(route[1]['msatoshi']) + route[1]['amount_msat'] += 1000 route[1]['delay'] += 10 # This should work. @@ -2174,13 +2172,11 @@ def test_setchannel_routing(node_factory, bitcoind): # 1337 + 4000000 * 137 / 1000000 = 1885 route_ok = l1.rpc.getroute(l3.info['id'], 4000000, 1)["route"] assert len(route_ok) == 2 - assert route_ok[0]['msatoshi'] == 4001885 - assert route_ok[1]['msatoshi'] == 4000000 + assert route_ok[0]['amount_msat'] == 4001885 + assert route_ok[1]['amount_msat'] == 4000000 # Make variant that tries to pay more than allowed htlc! route_bad = copy.deepcopy(route_ok) - route_bad[0]['msatoshi'] = 4001887 - route_bad[1]['msatoshi'] = 4000001 route_bad[0]['amount_msat'] = Millisatoshi(4001887) route_bad[1]['amount_msat'] = Millisatoshi(4000001) assert route_bad != route_ok @@ -2211,8 +2207,6 @@ def test_setchannel_routing(node_factory, bitcoind): assert route_ok[1]['amount_msat'] == 17 route_bad = copy.deepcopy(route_ok) - route_bad[0]['msatoshi'] = 1337 + 16 - route_bad[1]['msatoshi'] = 16 route_bad[0]['amount_msat'] = Millisatoshi(1337 + 16) route_bad[1]['amount_msat'] = Millisatoshi(16) assert route_bad != route_ok diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 2c6ed0072..d6e1d30c3 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -945,7 +945,7 @@ def test_transaction_annotations(node_factory, bitcoind): assert(len(outputs) == 1 and outputs[0]['status'] == 'confirmed') out = outputs[0] idx = out['output'] - assert(idx in [0, 1] and out['value'] == 10**6) + assert(idx in [0, 1] and out['amount_msat'] == Millisatoshi("{}sat".format(10**6))) # ... and it should have an annotation on the output reading 'deposit' txs = l1.rpc.listtransactions()['transactions']