Skip to content

Fix persistence-required futures always completing instantly #1845

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

Conversation

TheBlueMatt
Copy link
Collaborator

After the first persistence-required Future wakeup, we'll always complete additional futures instantly as we don't clear the "need wake" bit. Instead, we need to just assume that if a future was generated (and not immediately drop'd) that its sufficient to notify the user.

@TheBlueMatt TheBlueMatt added this to the 0.0.113 milestone Nov 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2022

Codecov Report

Base: 90.74% // Head: 92.01% // Increases project coverage by +1.27% 🎉

Coverage data is based on head (2004451) compared to base (3b2f694).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head 2004451 differs from pull request most recent head f382f56. Consider uploading reports for the commit f382f56 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1845      +/-   ##
==========================================
+ Coverage   90.74%   92.01%   +1.27%     
==========================================
  Files          87       89       +2     
  Lines       47364    61307   +13943     
  Branches    47364    61307   +13943     
==========================================
+ Hits        42980    56412   +13432     
- Misses       4384     4895     +511     
Impacted Files Coverage Δ
lightning/src/ln/channelmanager.rs 88.36% <100.00%> (+3.17%) ⬆️
lightning/src/util/wakers.rs 95.93% <100.00%> (+4.37%) ⬆️
lightning/src/chain/mod.rs 66.66% <0.00%> (-1.52%) ⬇️
lightning/src/util/events.rs 37.89% <0.00%> (-0.51%) ⬇️
lightning-background-processor/src/lib.rs 96.01% <0.00%> (-0.23%) ⬇️
lightning/src/lib.rs 100.00% <0.00%> (ø)
lightning/src/ln/reorg_tests.rs 100.00% <0.00%> (ø)
lightning/src/offers/offer.rs 94.56% <0.00%> (ø)
lightning/src/util/string.rs 100.00% <0.00%> (ø)
lightning/src/ln/features.rs 99.77% <0.00%> (+0.10%) ⬆️
... and 31 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt TheBlueMatt force-pushed the 2022-11-future-wake-fix branch from d7a1380 to 6aefbe5 Compare November 10, 2022 19:04
@TheBlueMatt
Copy link
Collaborator Author

Fixed the doc links, note that we can't actually link await_persistable_update_timeout from await_persistable_update as the former is std-only and the latter is always available.

wpaulino
wpaulino previously approved these changes Nov 10, 2022
jkczyz
jkczyz previously approved these changes Nov 11, 2022
After the first persistence-required `Future` wakeup, we'll always
complete additional futures instantly as we don't clear the
"need wake" bit. Instead, we need to just assume that if a future
was generated (and not immediately drop'd) that its sufficient to
notify the user.
@TheBlueMatt
Copy link
Collaborator Author

Squashed, the fixup commit after @wpaulino's review was:

$ git diff-tree -U1 57855ff9c0b62d4a05b77bb512a3694e2dcaec8b f382f56c
diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs
index 92fdd0165..655fc9cf7 100644
--- a/lightning/src/util/wakers.rs
+++ b/lightning/src/util/wakers.rs
@@ -95,10 +95,12 @@ impl Notifier {
 		}
-		if !future_probably_generated_calls {
-			// If no future made any callbacks and has been drop'd (i.e. the state has only the one
-			// reference we hold), assume the user was not notified and set the
-			// notification-required flag. This will cause the `wait` functions above to return.
-			lock.0 = true;
+		if future_probably_generated_calls {
+			// If a future made some callbacks or has not yet been drop'd (i.e. the state has more
+			// than the one reference we hold), assume the user was notified and skip setting the
+			// notification-required flag. This will not cause the `wait` functions above to return
+			// and avoid any future `Future`s starting in a completed state.
+			return;
 		}
+		lock.0 = true;
 		mem::drop(lock);
-		if !future_probably_generated_calls { self.condvar.notify_all(); }
+		self.condvar.notify_all();
 	}

@TheBlueMatt TheBlueMatt merged commit 838d486 into lightningdevkit:main Nov 11, 2022
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.

4 participants