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

CLNRest: performance improvements using sql query #2290

Merged

Conversation

niteshbalusu11
Copy link
Contributor

@niteshbalusu11 niteshbalusu11 commented Jul 15, 2024

Description

Relates to issue: #1637

We spoke about this a bit on the telegram chat, to begin with we will limit the list of transactions to 150. Right now I was able to limit the expensive bkpr-listaccountevents and listinvoices. I couldn't restrict listpays because it doesn't take a limit argument. There is a listsendpays that can take a limit but it doesn't return bolt12 payments (classic CLN).

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Configuration change
  • Locales update
  • Quality assurance
  • Other

I have tested this PR on the following platforms (please specify OS version and phone model/VM):

  • Android
  • iOS

I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):

  • Embedded LND
  • LND (REST)
  • LND (Lightning Node Connect)
  • Core Lightning (CLNRest)
  • Core Lightning (c-lightning-REST)
  • LndHub
  • [DEPRECATED] Core Lightning (Spark)
  • [DEPRECATED] Eclair

@@ -210,7 +210,8 @@ export default class CLNRest {
return this.postRequest('/v1/withdraw', request);
};
getMyNodeInfo = () => this.postRequest('/v1/getinfo');
getInvoices = () => this.postRequest('/v1/listinvoices');
getInvoices = () =>
this.postRequest('/v1/listinvoices', { limit: 150, index: 'created' });
Copy link

Choose a reason for hiding this comment

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

This seems like it might help with my 10k+ transactions :-)

(could make this paginate in a followup)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's the idea.

@newtonick
Copy link
Contributor

I did some testing on this PR. I checked out the PR locally and built from source. I replaced this /v1/listinvoices call with the SQL mentioned above. I did this so the output on the activity page was identical (at least for the visible screen).

It's a noticeable performance increase. I'm running my node on the same local network my phone is connecting to via WIFI. I'm comparing to the current v0.9.0-beta1 release from yesterday to this PR built from source. The activity view loads around 6-7 seconds faster.

Here is a screen recording of the performance. The first (light green) activity view loaded is v0.9.0-beta1 (not this PR). The second (yellow) activity view loaded is this PR. I have lurker privacy mode turned on for the recording.

screenrecording2.mp4

@niteshbalusu11
Copy link
Contributor Author

Nice. Thank you for testing this. This again isn't the perfect solution because of the 150 records limitation but at least it makes the activity view usable.

@kaloudis kaloudis changed the title cln performance improvements using sql query CLNRest: performance improvements using sql query Jul 18, 2024
@kaloudis kaloudis added Core Lightning Issues specific to Core Lightning CLNRest labels Jul 18, 2024
@kaloudis kaloudis added this to the v0.9.0 milestone Jul 18, 2024
@kaloudis
Copy link
Contributor

Let's try this in v09.0-beta2

@kaloudis kaloudis merged commit 8c395f4 into ZeusLN:master Jul 18, 2024
3 checks passed
@niteshbalusu11 niteshbalusu11 deleted the cln-rest-performance-improvements branch July 18, 2024 16:04
@niteshbalusu11
Copy link
Contributor Author

@Sjors can you test RC2 please?

@Sjors
Copy link

Sjors commented Jul 18, 2024

Just tested, I can see my transactions now! 🎉

When I click on a (sent) lightning transaction it immediately crashes.

Clicking on on chain does behave.

I get the impression that I'm not seeing received lightning transactions, though would be mostly zaps and keysend from podcast streaming.

@Sjors
Copy link

Sjors commented Jul 18, 2024

By the way, I'm not a huge fan of the "€1,00 + €0,01 fee" notation. Especially for lightning fees are usually irrelevant and it just seems like visual clutter. It would be better to display fees only if you click on a transaction to see details.

What I would like to see in the overview is a description. Maybe that can go where it says "lightning". And then "You sent" could say "You sent (⚡)"

This is probably totally unrelated to CLNRest :-)

@niteshbalusu11
Copy link
Contributor Author

Just tested, I can see my transactions now! 🎉

When I click on a (sent) lightning transaction it immediately crashes.

Clicking on on chain does behave.

I get the impression that I'm not seeing received lightning transactions, though would be mostly zaps and keysend from podcast streaming.

Will look into this.

@@ -210,7 +210,8 @@ export default class CLNRest {
return this.postRequest('/v1/withdraw', request);
};
getMyNodeInfo = () => this.postRequest('/v1/getinfo');
getInvoices = () => this.postRequest('/v1/listinvoices');
getInvoices = () =>
this.postRequest('/v1/listinvoices', { limit: 150, index: 'created' });
Copy link
Contributor

Choose a reason for hiding this comment

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

{ limit: 150, index: 'created' } limits the list of invoices to the first 150 invoices by created index/timestamp. It would make more sense if it limited it to the last 150 invoices, but this is not what it is doing.

Copy link
Contributor

@newtonick newtonick Jul 17, 2024

Choose a reason for hiding this comment

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

I replaced the /v1/listinvoices call with the following and it worked well for me.

this.postRequest('/v1/sql', {
    query: "SELECT label, bolt11, bolt12, payment_hash, amount_msat, status, amount_received_msat, paid_at, payment_preimage, description, expires_at FROM invoices WHERE status = 'paid' ORDER BY created_index DESC LIMIT 150;"
}).then((data: any) => {
    const invoices: any[] = [];
    data.rows.forEach((invoice: any) => {
        invoices.push({
            label: invoice[0],
            bolt11: invoice[1],
            bolt12: invoice[2],
            payment_hash: invoice[3],
            amount_msat: invoice[4],
            status: invoice[5],
            amount_received_msat: invoice[6],
            paid_at: invoice[7],
            payment_preimage: invoice[8],
            description: invoice[9],
            expires_at: invoice[10]
        });
    });

    return {
        invoices: invoices
    };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLNRest Core Lightning Issues specific to Core Lightning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants