Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The great msat purge #5306

Merged

Conversation

rustyrussell
Copy link
Contributor

@ShahanaFarooqui urged me to complete the msat transition. This series does that, but some msat fields which were not named correctly leaked in, forcing broader deprecations.

  1. All "msat" fields now end in _msat. This allows e.g. the Python code to turn them into Millisatoshi() class unconditionally
  2. All "msat" fields will become raw numbers; this happens currently with allow-deprecated-apis=false. Code should handle both a "123msat" JSON string and 123 for the transition.
  3. We rename some input arguments similarly for consistency.

@cdecker
Copy link
Member

cdecker commented Jun 7, 2022

Yep, that compatibility mode for _msat fields broke cln-rpc and cln-grpc in interesting ways, since now the type of the field changed unexpectedly. I'll try to replicate the compat mode described above.

@cdecker
Copy link
Member

cdecker commented Jun 7, 2022

@rustyrussell are there any raw amounts (just u64) that do not have msat as their unit? The problem is that we built a higher level Amount concept on top of non-bare amounts (i.e., with sat or msat suffix) when building the cln-rpc abstraction, and we don't have the field name readily available to differentiate them. My hope would be that the unit type would also be reflected in the schema, so that we can differentiate it that way when generating the code.

fiatjaf added a commit to nbd-wtf/poncho that referenced this pull request Jun 8, 2022
@rustyrussell
Copy link
Contributor Author

Yes, schema should be correct! We should add tooling on this (that all outgoing msat fields have names _msat, and all _msat field have msat values) though.

@rustyrussell rustyrussell force-pushed the guilt/the-great-msat-purge branch 2 times, most recently from 8037b56 to f697809 Compare June 18, 2022 04:30
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f697809

This example predates the pay plugin!  It's obsolete, unmaintained,
and probably doesn't work.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Fixed: lightningd: `log-level` `io` shows JSONRPC output, as well as input.
Signed-off-by: Rusty Russell <[email protected]>
This is *much* easier to do inside parsing than in the caller!

Signed-off-by: Rusty Russell <[email protected]>
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 <[email protected]>
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`)
We don't always want to round down, sometimes we want to fail.

Signed-off-by: Rusty Russell <[email protected]>
In general, we don't like to use `null` in JSON: simply omit the
field.  I found this one because it broke our 'msat' parsing (made
stricter in followup) which doesn't allow `null`.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Deprecated: `listconfigs` `plugins` `options` which are not set are omitted, not `null`.
The new msat fields are turned into Millisatoshi, so handle that correctly
too in tests too.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Deprecated: Plugins: `coin_movement` notification: `balance`, `credit`, `debit` and `fees` (use `balance_msat`, `credit_msat`, `debit_msat` and `fees_msat`)
This is consistent with our output changes, and increases consistency.
It also keeps future sanity checks happy, that we only use JSON msat
helpers with '_msat' fields.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Changed: JSON-RPC: `invoice`, `sendonion`, `sendpay`, `pay`, `keysend`, `fetchinvoice`, `sendinvoice`: `msatoshi` argument is now called `amount_msat` to match other fields.
Changelog-Deprecated: JSON-RPC: `invoice`, `sendonion`, `sendpay`, `pay`, `keysend`, `fetchinvoice`, `sendinvoice` `msatoshi` (use `amount_msat`)
Changelog-Added: Plugins: `htlc_accepted_hook` `amount_msat` field.
Changelog-Deprecated: Plugins: `htlc_accepted_hook` `amount` field (use `amount_msat`)

Signed-off-by: Rusty Russell <[email protected]>
Nobody really parses this though, fortunately.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `pay` `attempts` `amount_msat` field.
Changelog-Deprecated: JSON-RPC: `pay` `attempts` `amount` field (use `amount_msat`).
The name in the spec is `msat`, but I don't want to make an API exception.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `fetchinvoice` `changes` `amount_msat`
Changelog-Deprecated: JSON-RPC: `fetchinvoice` `changes` `msat` (use `amount_msat`)
Now we've fixed them all, make sure no new ones slip in!

Signed-off-by: Rusty Russell <[email protected]>
This prepares for when they start being u64, not strings with msat appended.

This has a strange side effect on our schema: despite the name,
decodepay's `fee_base_msat` is actually a u64, which we now convert to
msat on decode.

Signed-off-by: Rusty Russell <[email protected]>
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 <[email protected]>
We should be using amount_msat always.  Many tests were not.  Plus,
deprecating it simplifies the code.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Deprecated: JSONRPC: `sendpay` `route` elements `msatoshi` (use `amount_msat`)
…l have "msat" appended.

After next patch, it's a raw u64, and this code broke.

Signed-off-by: Rusty Russell <[email protected]>
Let the parsing handle if they're the wrong type (soon they'll be u64).

Signed-off-by: Rusty Russell <[email protected]>
rustyrussell and others added 6 commits June 20, 2022 19:52
We would otherwise multiply them by 1000.

Signed-off-by: Rusty Russell <[email protected]>
This code was buggy: handing "1000" as a parameter to
min_their_funding_msat, don't turn that into "1000sat"!

Signed-off-by: Rusty Russell <[email protected]>
We would otherwise multiply them by 1000.

Signed-off-by: Rusty Russell <[email protected]>
This changes many fields: in non-deprecated mode, they're now raw integers.
This was always the intention, but the transition was never completed.

Suggested-By: @ShahanaFarooqui
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Changed: JSON-RPC: "_msat" fields can be raw numbers, not "123msat" strings (please handle both!)
Changelog-Deprecated: JSON-RPC: "_msat" fields as "123msat" strings (will be only numbers)
Since we want to transition to raw `u64` values we need to accept both
for some time.
@rustyrussell
Copy link
Contributor Author

rustyrussell commented Jun 20, 2022

Trivial rebase to address conflicts, and update examples in PLUGINS.md.

Ack 6132e9f

@rustyrussell
Copy link
Contributor Author

Ack 6132e9f
(In case ackbot is waiting for a separate message, not an edited one?)

@jsarenik
Copy link
Collaborator

Please do not release a stable version until lightningd/plugins#369 is fixed (here in pyln). Thanks.

@jsarenik
Copy link
Collaborator

Or rother there in the summary plugin? OK.

vincenzopalazzo added a commit to laanwj/cln4rust that referenced this pull request Sep 6, 2022
8461e3f fix(rpc): MSat accepts both strings ending with msat and u64 (Riccardo Casatta)

Pull request description:

  According to ElementsProject/lightning#5306  the fields ending with msat will be raw numbers

  "Code should handle both a "123msat" JSON string and 123 for the transition."

  I am not 100% sure if it's allowed somewhere to have negative numbers, I thought there aren't based on the `MSat` type on branch master which contains a `u64`

Top commit has no ACKs.

Tree-SHA512: 734c644a42a30e9985e6da8891912ca6754d924a3a55562e9a670e482aaefe71d89c865160da356944f43e29d829d192b0b91733b5331d9698051c2f159bef2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants