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

Update for PR 6657: fix fundchannel infinite loop with tiny UTXOs #6669

Merged
merged 3 commits into from Sep 13, 2023

Conversation

rustyrussell
Copy link
Contributor

This is #6657 with a test added, Changelog line and git description, and a final neatening patch (I couldn't push to @TonyGiorgio 's branch!)

Closes: #6657
Fixes: #6183

rustyrussell and others added 3 commits September 13, 2023 09:55
Tony Giorgio <tonygiorgio@protonmail.com> says:

Reproduce:

1.  Add 1 600 sat UTXO to a fresh node

2.  Verify the fundchannel command fails with a low fee rate:

```
./lightning-cli fundchannel 0366abc8eb4da61e31a8d2c4520d31cabdf58cc5250f855657397f3dd62493938a 100000 1000
{
   "code": 301,
   "message": "Could not afford 100000sat using all 1 available UTXOs: 99522sat short"
}
```

3.  Now do the command again, but with a higher fee rate, making the 600 sat UTXO uneconomical:

```
./lightning-cli fundchannel 0366abc8eb4da61e31a8d2c4520d31cabdf58cc5250f855657397f3dd62493938a 100000 10000
```

4. Observe the RPC call and the logs. The RPC call will never return, and the logs will stop after this:

```
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: multiconnect done.
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: 'parsefeerate' done
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: fundpsbt.
```

5. Keep CLN running long enough and you'll eventually run OOM.
If a node has an onchain balance with at least one uneconomical UTXO, the fundchannel RPC call will lock up the node and will eventually crash it with OOM issues if the economical UTXO(s) do not add up to the fundchannel amount. This is because the while loop never exits because it keeps pulling in the same uneconomical UTXOs forever.

Changelog-Fixed: wallet: fundchannel no longer loops forever if the wallet contains insufficient funds, but an uneconomical UTXO.
We can keep a single array of 'already considered' utxos, with the same
result as Tony's patch prior.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell rustyrussell added this to the v23.08 Point Releases milestone Sep 13, 2023
@rustyrussell rustyrussell changed the title Guilt/pr 6657 Update for PR 6657: fix fundchannel infinite loop with tiny UTXOs Sep 13, 2023
@TonyGiorgio
Copy link
Contributor

Sorry for the delay if you were trying to get this out quickly. Really wanted to take over PR's in this repo myself more but understand if there's urgency here. Thanks for looking at it so quickly. I think it's been working for us in prod since we've deployed it.

This looks better so I'll close #6657

@rustyrussell
Copy link
Contributor Author

Yes, I'm holding up the point release for this, so I thought it'd be faster if I reworked and hoped you'd review in time!

Thanks for your ack!

@rustyrussell rustyrussell merged commit 79d0872 into ElementsProject:master Sep 13, 2023
39 checks passed
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.

lightningd stuck while funding a channel with a custom backend and eat memory around 20 GB of RAM
2 participants