') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Add concrete `NO_*` consts to avoid users having to specify types by TheBlueMatt · Pull Request #4100 · lightningdevkit/rust-lightning · GitHub
Skip to content

Add concrete NO_* consts to avoid users having to specify types - #4100

Merged
tnull merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2025-09-bp-no-consts
Sep 22, 2025
Merged

Add concrete NO_* consts to avoid users having to specify types#4100
tnull merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2025-09-bp-no-consts

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

When building a background processor without an onion messenger or liquidity manager, users still need to pass None into the background processor initialization methods. Sadly, Rust will require a concrete type for the (unused) Some variant of the Option passed in, which requires specifying out a lot of type gook.

Instead, provide some constants which users can pass in trivially.

Fixes#3612

@TheBlueMattTheBlueMatt added this to the 0.2 milestone Sep 22, 2025
@ldk-reviews-bot

ldk-reviews-bot commented Sep 22, 2025

Copy link
Copy Markdown

👋 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.

@codecov

codecovBot commented Sep 22, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.69%. Comparing base (1ed6c4b) to head (0d59d73).
⚠️ Report is 12 commits behind head on main.

Files with missing linesPatch %Lines
lightning-background-processor/src/lib.rs90.00%1 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4100 +/- ##
==========================================
- Coverage 88.71% 88.69% -0.02% 
==========================================
Files 176 176 Lines 132778 132859 +81 Branches 132778 132859 +81 ==========================================
+ Hits 117790 117836 +46 - Misses 12304 12336 +32 - Partials 2684 2687 +3 
FlagCoverage Δ
fuzzing21.55% <ø> (+<0.01%)⬆️
tests88.53% <90.00%> (-0.02%)⬇️

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.

@tnulltnull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK. I still think a builder pattern would be the prettier solution here (if we could make it work), but given how few users will actually use the raw background processor going forward, spending much more time on optimizing the API (esp. after we already spent some time over at #3688) probably doesn't make sense for now.

Note that CI is failing, also

Comment threadlightning-background-processor/src/lib.rs Outdated
@tnull
tnull removed the request for review from valentinewallaceSeptember 22, 2025 07:36
@TheBlueMatt
TheBlueMattforce-pushed the 2025-09-bp-no-consts branch 2 times, most recently from f676ce8 to e76eb2eCompareSeptember 22, 2025 15:09
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor
$ git diff-tree -U1 9ee959c533 e76eb2ed5e
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index 1ce0f1dd12..b7e67f1667 100644
--- a/lightning-background-processor/src/lib.rs+++ b/lightning-background-processor/src/lib.rs@@ -3476,6 +3476,24 @@ mod tests {
#[test]
-	fn test_no_moves() {- // Make sure the NO_* constants can be moved so that they can be passed to BP methods.- let no_liq = crate::NO_LIQUIDITY_MANAGER;- let no_om = crate::NO_ONION_MESSENGER;+	fn test_no_consts() {+ // Compile-test the NO_* constants can be used.+ let (_, nodes) = create_nodes(1, "test_no_consts");+ let data_dir = nodes[0].kv_store.get_data_dir();+ let persister = Arc::new(Persister::new(data_dir));+ let bg_processor = BackgroundProcessor::start(+ persister,+ move |_: Event| Ok(()),+ Arc::clone(&nodes[0].chain_monitor),+ Arc::clone(&nodes[0].node),+ crate::NO_ONION_MESSENGER,+ nodes[0].no_gossip_sync(),+ Arc::clone(&nodes[0].peer_manager),+ crate::NO_LIQUIDITY_MANAGER,+ Some(Arc::clone(&nodes[0].sweeper)),+ Arc::clone(&nodes[0].logger),+ Some(Arc::clone(&nodes[0].scorer)),+ );++ if !std::thread::panicking() {+ bg_processor.stop().unwrap();+ }
}

@TheBlueMatt

TheBlueMatt commented Sep 22, 2025

Copy link
Copy Markdown
CollaboratorAuthor

Oops, fixed the CI issues

$ git diff-tree -U1 e76eb2ed5e eafb72d649
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index b7e67f1667..350908adb7 100644
--- a/lightning-background-processor/src/lib.rs+++ b/lightning-background-processor/src/lib.rs@@ -86,2 +86,4 @@ use std::time::Instant;
use alloc::boxed::Box;
+#[cfg(not(feature = "std"))]+use alloc::sync::Arc;@@ -3476,2 +3478,3 @@ mod tests {
#[test]
+	#[cfg(not(c_bindings))]
fn test_no_consts() {

@valentinewallace

Copy link
Copy Markdown
Contributor

I believe there's still CI issues?

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Yep, stuff that wasn't being checked in a local ci/ci-tests.sh run :/

$ git diff-tree -U1 eafb72d64 cd7e3479f
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index 350908adb7..dcf433605e 100644
--- a/lightning-background-processor/src/lib.rs+++ b/lightning-background-processor/src/lib.rs@@ -86,3 +86,3 @@ use std::time::Instant;
use alloc::boxed::Box;
-#[cfg(not(feature = "std"))]+#[cfg(all(not(c_bindings), not(feature = "std")))]
use alloc::sync::Arc;
@@ -360,2 +360,13 @@ type DynMessageRouter = lightning::onion_message::messenger::DefaultMessageRoute
+#[cfg(all(not(c_bindings), not(taproot)))]+type DynSignerProvider = dyn lightning::sign::SignerProvider<+	EcdsaSigner = lightning::sign::InMemorySigner,+>;++#[cfg(all(not(c_bindings), taproot))]+type DynSignerProvider = dyn lightning::sign::SignerProvider<+	EcdsaSigner = lightning::sign::InMemorySigner,+	TaprootSigner = lightning::sign::InMemorySigner,+>;+
#[cfg(not(c_bindings))]
@@ -366,3 +377,3 @@ type DynChannelManager = lightning::ln::channelmanager::ChannelManager<
&'static dyn lightning::sign::NodeSigner,
-	&'static dyn lightning::sign::SignerProvider<EcdsaSigner = lightning::sign::InMemorySigner>,+	&'static DynSignerProvider,
&'static dyn FeeEstimator,

When building a background processor without an onion messenger or
liquidity manager, users still need to pass `None` into the
background processor initialization methods. Sadly, Rust will
require a concrete type for the (unused) `Some` variant of the
`Option` passed in, which requires specifying out a lot of type
gook.
Instead, provide some constants which users can pass in trivially.
Fixeslightningdevkit#3612
@tnull
tnull merged commit c2e3ae0 into lightningdevkit:mainSep 22, 2025
25 checks passed
Sign up for freeto 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.

Add BackgroundProcessor::start_without_om

4 participants

@TheBlueMatt@ldk-reviews-bot@valentinewallace@tnull