Skip to content

Fix panic when calling batch_funding_transaction_generated early #4015

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

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

Conversation

TheBlueMatt
Copy link
Collaborator

If a user calls `batch_funding_transaction_generated` before a
channel is ready to fund its possible to hit an `unwrap` when the
transaction-scanning logic attempts to fetch the channel's expected
output `scriptPubKey`.

While users shouldn't be doing this, we should also avoid the
panic, so here check the channel state first.

Found by the `full_stack_target` fuzzer.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 16, 2025

👋 I see @joostjager was un-assigned.
If you'd like another reviewer assignment, please click here.

@tnull tnull requested review from tnull and removed request for joostjager August 18, 2025 07:28
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Seems this needs a rebase

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

`functional_tests.rs` is a rather large beast, but with this move
we take it down to under 10k LoC.
If a user calls `batch_funding_transaction_generated` before a
channel is ready to fund its possible to hit an `unwrap` when the
transaction-scanning logic attempts to fetch the channel's expected
output `scriptPubKey`.

While users shouldn't be doing this, we should also avoid the
panic, so here check the channel state first.

Found by the `full_stack_target` fuzzer.
When a channel gets replaced before we can fund it, its possible
now (due to RNG output repetition) to hit the "trying to fund
channel before its ready to be funded" error in the
`full_stack_target` fuzzer.

Thus, we now simply ignore errors when funding.
@TheBlueMatt
Copy link
Collaborator Author

Rebased.

Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 77.58621% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.84%. Comparing base (633cb49) to head (c1fefcf).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 66.66% 9 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs 70.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4015   +/-   ##
=======================================
  Coverage   88.84%   88.84%           
=======================================
  Files         175      175           
  Lines      127723   127762   +39     
  Branches   127723   127762   +39     
=======================================
+ Hits       113472   113516   +44     
+ Misses      11686    11679    -7     
- Partials     2565     2567    +2     
Flag Coverage Δ
fuzzing 21.77% <45.00%> (+0.01%) ⬆️
tests 88.68% <77.58%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants