Add a generic public `FutureSpawner` in LDK directly
What changed, and why it matters
This commit simply moves an existing Rust trait called FutureSpawner from one internal crate (lightning-block-sync) into the main lightning crate so it can be reused more widely. It does not change any behavior, fix a bug, or alter security logic. There is no security issue visible in this patch.
No action required. This is a non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff relocates the FutureSpawner trait definition from lightning-block-sync/src/gossip.rs to a new public module lightning/src/util/native_async.rs. The trait signature is nearly identical; the only change is replacing the Send bound with MaybeSend from crate::util::async_poll. The trait remains a generic async-spawning abstraction with no implementation logic. This is a pure refactor in preparation for future background async persistence work.
Changed components
lightning/src/util/native_async.rs (new public module)lightning/src/util/mod.rs (module re-export)lightning-block-sync/src/gossip.rs (trait removed, replaced by re-exported trait)Inspect captured patch +21 / −13
diff --git a/lightning-block-sync/src/gossip.rs b/lightning-block-sync/src/gossip.rs
index 083156b..0fe221b 100644
--- a/lightning-block-sync/src/gossip.rs
+++ b/lightning-block-sync/src/gossip.rs
@@ -10,11 +10,10 @@ use bitcoin::hash_types::BlockHash;
use bitcoin::transaction::{OutPoint, TxOut};
use lightning::ln::peer_handler::APeerManager;
-
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::utxo::{UtxoFuture, UtxoLookup, UtxoLookupError, UtxoResult};
-
use lightning::util::logger::Logger;
+use lightning::util::native_async::FutureSpawner;
use std::collections::VecDeque;
use std::future::Future;
@@ -43,17 +42,6 @@ pub trait UtxoSource: BlockSource + 'static {
fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool>;
}
-/// A generic trait which is able to spawn futures in the background.
-///
-/// If the `tokio` feature is enabled, this is implemented on `TokioSpawner` struct which
-/// delegates to `tokio::spawn()`.
-pub trait FutureSpawner: Send + Sync + 'static {
- /// Spawns the given future as a background task.
- ///
- /// This method MUST NOT block on the given future immediately.
- fn spawn<T: Future<Output = ()> + Send + 'static>(&self, future: T);
-}
-
#[cfg(feature = "tokio")]
/// A trivial [`FutureSpawner`] which delegates to `tokio::spawn`.
pub struct TokioSpawner;
diff --git a/lightning/src/util/mod.rs b/lightning/src/util/mod.rs
index 84c0c11..968f822 100644
--- a/lightning/src/util/mod.rs
+++ b/lightning/src/util/mod.rs
@@ -26,6 +26,7 @@ pub mod base32;
pub(crate) mod base32;
pub mod errors;
pub mod message_signing;
+pub mod native_async;
pub mod persist;
pub mod scid_utils;
pub mod ser;
diff --git a/lightning/src/util/native_async.rs b/lightning/src/util/native_async.rs
new file mode 100644
index 0000000..910e24a
--- /dev/null
+++ b/lightning/src/util/native_async.rs
@@ -0,0 +1,19 @@
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+//! This module contains a few public utility which are used to run LDK in a native Rust async
+//! environment.
+
+use crate::util::async_poll::MaybeSend;
+use core::future::Future;
+
+/// A generic trait which is able to spawn futures in the background.
+pub trait FutureSpawner: Send + Sync + 'static {
+ /// Spawns the given future as a background task.
+ ///
+ /// This method MUST NOT block on the given future immediately.
+ fn spawn<T: Future<Output = ()> + MaybeSend + 'static>(&self, future: T);
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.