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

Merged
merged 4 commits into from
Aug 21, 2025

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

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@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 42 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.

@tnull tnull self-requested a review August 21, 2025 11:34
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.

Looks good, mod one minor question.

Also verified that the added test fails on main.

@@ -857,21 +857,15 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
}
if tx.version.0 <= 0xff && !channels.is_empty() {
let chans = channels.iter().map(|(a, b)| (a, b)).collect::<Vec<_>>();
if let Err(e) =
Copy link
Contributor

@tnull tnull Aug 21, 2025

Choose a reason for hiding this comment

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

Hmm, should we just allow this specific error case, i.e., still fail on other errors? Otherwise this might also relax our checks for other errors which we still might want to catch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could, but I'm not really sure its worth bothering here - matching on error messages sucks, and "spurious failure to fund channel" seems like an issue that is better caught with normal functional tests (I imagine it'll be kinda hard to have a spurious failure here, anyway).

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright.

@tnull
Copy link
Contributor

tnull commented Aug 21, 2025

Simple enough, landing.

@tnull tnull merged commit f889222 into lightningdevkit:main Aug 21, 2025
43 of 44 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.

3 participants