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

CLN support, first draft #125

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

CLN support, first draft #125

wants to merge 6 commits into from

Conversation

0ceanSlim
Copy link

I think the partial Payment function may still be broken. But I'm able to spin up my mint, pay and mint all working well. Also I know I need to change the .env to path to rune rather than having to put the rune in the config.

There could also be a short guide to generate a proper rune for all the commands you need rather than just using a master rune. Of course the readme will need changes too when the CLN support is actually added.

Take a look and let me know your feedback

Copy link
Owner

@elnosh elnosh left a comment

Choose a reason for hiding this comment

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

thanks for the PR!

I'm not very familiar with CLN's API but I spun up a mint and did some testing. Happy path in basic operations (like mint and melt) seem to be working fine. Found some issues in certain cases tho.

Tried a payment that will definitively fail (no route) and rather than returning a failed payment status, it returned pending so it left the melt quote in PENDING. Seems like an issue in OutgoingPaymentStatus. I see the response from CLN is empty so then it defaults to pending since it didn't find the payment.

Tried doing an MPP (which would use PayPartialAmount method) and didn't work. Both mints in the payment are able to pay the destination so it should not have failed.

Also, would be good to add some tests. This will likely require some refactoring on my side as those are doing the tests with LND specifically but you can take a look here: https://github.com/elnosh/gonuts/blob/562edf19cc12b969cdddaab3f613d111f1751cdf/mint/mint_integration_test.go. It spins up a mint with LND as the backend and tests all mint operations. I will probably need to make it more generic to pass any lightning backend and test the mint with whatever backend.

Comment on lines +14 to +17
const (
InvoiceExpiryTimeCLN = 3600 // 1 hour
FeePercentCLN = 0.01
)
Copy link
Owner

Choose a reason for hiding this comment

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

we are using the same expiry time for LND and fakebackend. Maybe it would be good to just set this constant one time for all lightning backends rather than for each one individually.

Copy link
Author

Choose a reason for hiding this comment

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

They should be configurable by the user imo. And could be defaulted to what they are now.

Comment on lines 43 to 47
req.Header.Set("Rune", cln.config.Rune)
req.Header.Set("accept", "application/json")
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
Copy link
Owner

Choose a reason for hiding this comment

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

I see all methods are creating a new http client and adding the same headers. I think one http.Client can be reused across all methods. Also probably good to have method that will create request with all these headers.

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes, very good. Will add that for sure.

Comment on lines 93 to 96
// Accept both 200 OK and 201 Created
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return Invoice{}, fmt.Errorf("failed to create invoice: %s", resp.Status)
}
Copy link
Owner

Choose a reason for hiding this comment

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

will responses have errors? Can it return errors rather than just the status code.

Copy link
Author

Choose a reason for hiding this comment

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

The HTTP responses absolutely will for other codes. I'll have to handle those for better debugging. I'll have to take a closer look at the API response body for CLN commands.

Comment on lines 381 to 396
func (sub *CLNInvoiceSub) Recv() (Invoice, error) {
for {
invoice, err := sub.client.InvoiceStatus(sub.paymentHash)
if err != nil {
return Invoice{}, err
}

// If the invoice is settled, return immediately
if invoice.Settled {
return invoice, nil
}

// Wait before checking again
time.Sleep(sub.pollInterval)
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not familiar with CLN's API but is there no way to get updates on an invoice instead of doing this polling?

Copy link
Author

Choose a reason for hiding this comment

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

There probably is , I'll look through all the API again, but if there isn't you could make something to do that with a CLN plugin. But this was a way I knew would work.

@0ceanSlim
Copy link
Author

Got it. I think from your testing I have a little better idea on how to fix all the issues. Sorry I'm familiar with CLN but not quite as familiar with all the duties of a mint and what it's looking for. But I'll make a few changes based on your experience and commit them and let you try again.

@0ceanSlim
Copy link
Author

@elnosh I addressed a few things last night but only had time really to retest that I didn't break anything but could you confirm a MPP ? I was not able to get one to work.

@elnosh
Copy link
Owner

elnosh commented Feb 21, 2025

but could you confirm a MPP ? I was not able to get one to work.

yeah setup is a bit tricky. You will need 2 mints (with MPP enabled) and have a wallet with funds in both. You can try it from the cli wallet using pay --multimint <invoice>. That will try the MPP using funds from both mints (as selected in the prompt after the command)

@elnosh
Copy link
Owner

elnosh commented Feb 25, 2025

@0ceanSlim I refactored the tests here: #126. After this you would just need to do some setup to start the mint with a CLNClient that you created and then you should be able to run the mint tests with CLN by doing something like: go test -v --tags=integration ./mint -args -backend=CLN

@0ceanSlim
Copy link
Author

perfect! I'll get around to testing soon! Sorry I've been very busy developing my nostr relay lately.

@0ceanSlim
Copy link
Author

tried running this and failed test but it was for

2025/02/26 15:58:06 invalid lightning client
FAIL    github.com/elnosh/gonuts/mint   14.238s
FAIL

@elnosh
Copy link
Owner

elnosh commented Feb 26, 2025

you will still need to add some setup to start the mint with CLN like here:

lightningClient1, err = testutils.LndClient(lnd1)
if err != nil {
return 1, err
}

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

Successfully merging this pull request may close these issues.

2 participants