alexbosworth / lightning

Lightning client methods
MIT License
126 stars 32 forks source link

segmentation fault - fundPsbt #140

Open SeverinAlexB opened 1 year ago

SeverinAlexB commented 1 year ago

I would like to fund a 0conf channel running for the Blocktank LSP. I didn't see openChannel supporting it so I tried the manual route. For that, I need to call fundPsbt. Unfortunately, my app terminates with a segmentation fault every time I call the method. Do you have any suggestion to get around that?

Example:

import * as ln from 'lightning';

const result = await ln.fundPsbt({ // Terminates with segmentation fault.
    lnd: node.rpc,
    outputs: [{
        address: 'bcrt1qz3trhgd4p95l74xda4f57npmrd2p64he4ucjqky77ztw6zulj8aq6nrpds',
        tokens: 100000
    }]
});
console.log(result)

Logs: No new lnd logs appear when I call this.

SeverinAlexB commented 1 year ago

No idea why but changing import('ecpair') to require('ecpair') in ln_methods/onchain/fund_pbst.js fixes the problem for me 🤷‍♂️ Maybe somebody can reproduce this issue + solution.

CleanShot 2023-07-17 at 14 29 16@2x
alexbosworth commented 1 year ago

for the original issue, you can use trusted funding channels, here is an example integration test: https://github.com/alexbosworth/ln-service/blob/master/test/integration/test_trusted_funding.js#L189

for the segmentation fault that is odd, do you have any error strings I could look at? Did you try nodejs 16 or 20?

alexbosworth commented 1 year ago

Maybe this is a caching issue? I saw this issue that might be related https://bugs.chromium.org/p/v8/issues/detail?id=10284 so maybe clear npm build cache etc?

SeverinAlexB commented 1 year ago

Turns out this is a Jest ESM issue. ESM support in Jest (and NodeJs 18 partially?) is still not perfect and import (a ESM feature) broke the code. require (CommonJS feature) worked. If I run the code without Jest, it works. So I am not sure if this is a issue with the library or Jest. I will try to work around it.

for the original issue, you can use trusted funding channels, here is an example integration test: https://github.com/alexbosworth/ln-service/blob/master/test/integration/test_trusted_funding.js#L189

Nice thx. Is it possible to create a fee bump able anchor channel with this method?

On the other hand, I looked a bit deeper into the library. If you want, I can create a PR that adds the zero_conf and commitment_type parameters to the openChannel method. Let me know what you think

alexbosworth commented 1 year ago

The only type of trusted funding channels that LND supports at the moment is anchor channels