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

listpays: sort output payments #4518

Merged
merged 4 commits into from
Jun 1, 2021

Conversation

nalinbhardwaj
Copy link
Contributor

Fixes #4481.

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.

I have only a small curiosity and I would like to know more about that.

I'm not able to catch what Is the reason to collect the result from the database and only after sort it, instant to ask the database the list of payment sorted.

The only motivation that I have in mind is that the databases used from c-lightning use a different dialect, but I'm not able to prove that because the ORDER BY should be a basic construct of the SQL language

wallet/wallet.c Outdated Show resolved Hide resolved
@rustyrussell
Copy link
Contributor

OK, this is a great start! Your code is really nice.

Some feedback:

  1. This actually orders the low-level command listsendpays. Which is great, but another commit is needed for the listpays command to order that (which uses listsendpays).
  2. This commit should have a line like Changelog-Changed: JSON: `listsendpays` output is now ordered by `id`.
  3. As @vincenzopalazzo points out, simply adding "ORDER BY id" is a much simpler change.
  4. Create a new commit, which can use your asort code to the plugin/pay.c, except order it by created_at maybe? And you'll need to marshal it into a temporary array to sort it.

Thanks!
Rusty.

@nalinbhardwaj
Copy link
Contributor Author

Thanks for the note @vincenzopalazzo @rustyrussell. I realised that after making this PR (which is why I ended up marking it as a draft PR). I'll make both the noted changes soon.

@nalinbhardwaj nalinbhardwaj marked this pull request as ready for review May 26, 2021 22:30
@nalinbhardwaj
Copy link
Contributor Author

@rustyrussell @vincenzopalazzo ready for review.

@@ -3143,7 +3143,8 @@ wallet_payment_list(const tal_t *ctx,
", partid"
", local_offer_id"
" FROM payments"
" WHERE payment_hash = ?;"));
" WHERE payment_hash = ?"
" ORDER BY id;"));
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo May 30, 2021

Choose a reason for hiding this comment

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

Do you think that sort by timestamp it is a good idea here?

Copy link
Contributor

Choose a reason for hiding this comment

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

id is the order it was placed in the db, which is probably right here.

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.

utack 1459ab0

With two small nit to me, but @rustyrussell can undo my comments if they are wrong.

  • If you sort (ORDER by timestamp ASC | DESC) by timestamp you can avoid the sorting operation, this moves the work from lightning code to database code, and the database can (or should/may) have better performance in sorting things. In addition, this change simplifies the code in the pay plugin.
  • Use the query to sort the element you can avoid using the additional array, but it is in contrast with point 4 of Rusty's comment, so in this case, I can missing some things.

PS: I would like to have an additional test in test_pay that makes sure that the array is really sorted, to avoid crazy debugging in some case in the future.

@rustyrussell
Copy link
Contributor

utack 1459ab0

With two small nit to me, but @rustyrussell can undo my comments if they are wrong.

* If you sort (ORDER by timestamp ASC | DESC) by timestamp you can avoid the sorting operation, this moves the work from lightning code to database code, and the database can (or should/may) have better performance in sorting things. In addition, this change simplifies the code in the pay plugin.

Unfortunately, listpays gathers listsendpays into a hashtable, losing order. So explicit sorting is still required here.

PS: I would like to have an additional test in test_pay that makes sure that the array is really sorted, to avoid crazy debugging in some case in the future.

More tests would always be nice, of course! I will have a go at writing one, since this needs a trivial rebase anyway...

nalinbhardwaj and others added 4 commits May 31, 2021 12:10
Changelog-Changed: JSON: `listsendpays` output is now ordered by `id`.
Changelog-Changed: `listpays` output is now ordered by the `created_at` timestamp.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell
Copy link
Contributor

@nalinbhardwaj Sorry for the delay. Did a trivial rebase to fix the merge conflict with db files, and added tests and docs.

What do you think?

@nalinbhardwaj
Copy link
Contributor Author

@rustyrussell Looks great! Thanks for the rebase and the doc+tests updates. Let me know if there's anything else I missed before.

@niftynei
Copy link
Collaborator

niftynei commented Jun 1, 2021

ACK 0d62227

@niftynei niftynei merged commit 0b01a8c into ElementsProject:master Jun 1, 2021
@nalinbhardwaj nalinbhardwaj deleted the sort_listpay branch June 1, 2021 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

listpays is not sorted
4 participants