Skip to content

Commit 02a9af9

Browse files
authored
Merge pull request lightningdevkit#4184 from Fedeparma74/no-std-no-send
Remove `Send + Sync` bounds when `no-std`
2 parents afb80e5 + 8e4b8e4 commit 02a9af9

File tree

8 files changed

+43
-49
lines changed

8 files changed

+43
-49
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ where
300300

301301
/// Updates scorer based on event and returns whether an update occurred so we can decide whether
302302
/// to persist.
303-
fn update_scorer<'a, S: Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
303+
fn update_scorer<'a, S: Deref<Target = SC>, SC: 'a + WriteableScore<'a>>(
304304
scorer: &'a S, event: &Event, duration_since_epoch: Duration,
305305
) -> bool {
306306
match event {
@@ -887,10 +887,8 @@ pub async fn process_events_async<
887887
P: Deref,
888888
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
889889
EventHandler: Fn(Event) -> EventHandlerFuture,
890-
ES: Deref + Send,
891-
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>
892-
+ Send
893-
+ Sync,
890+
ES: Deref,
891+
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
894892
CM: Deref,
895893
OM: Deref,
896894
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
@@ -901,7 +899,7 @@ pub async fn process_events_async<
901899
O: Deref,
902900
K: Deref,
903901
OS: Deref<Target = OutputSweeper<T, D, F, CF, K, L, O>>,
904-
S: Deref<Target = SC> + Send + Sync,
902+
S: Deref<Target = SC>,
905903
SC: for<'b> WriteableScore<'b>,
906904
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
907905
Sleeper: Fn(Duration) -> SleepFuture,
@@ -1356,15 +1354,13 @@ pub async fn process_events_async_with_kv_store_sync<
13561354
T: Deref,
13571355
F: Deref,
13581356
G: Deref<Target = NetworkGraph<L>>,
1359-
L: Deref + Send + Sync,
1357+
L: Deref,
13601358
P: Deref,
13611359
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
13621360
EventHandler: Fn(Event) -> EventHandlerFuture,
1363-
ES: Deref + Send,
1364-
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>
1365-
+ Send
1366-
+ Sync,
1367-
CM: Deref + Send + Sync,
1361+
ES: Deref,
1362+
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
1363+
CM: Deref,
13681364
OM: Deref,
13691365
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
13701366
RGS: Deref<Target = RapidGossipSync<G, L>>,
@@ -1374,7 +1370,7 @@ pub async fn process_events_async_with_kv_store_sync<
13741370
O: Deref,
13751371
K: Deref,
13761372
OS: Deref<Target = OutputSweeperSync<T, D, F, CF, K, L, O>>,
1377-
S: Deref<Target = SC> + Send + Sync,
1373+
S: Deref<Target = SC>,
13781374
SC: for<'b> WriteableScore<'b>,
13791375
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
13801376
Sleeper: Fn(Duration) -> SleepFuture,

lightning/src/events/bump_transaction/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@ pub trait CoinSelectionSource {
391391
fn select_confirmed_utxos<'a>(
392392
&'a self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &'a [TxOut],
393393
target_feerate_sat_per_1000_weight: u32, max_tx_weight: u64,
394-
) -> AsyncResult<'a, CoinSelection>;
394+
) -> AsyncResult<'a, CoinSelection, ()>;
395395
/// Signs and provides the full witness for all inputs within the transaction known to the
396396
/// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
397397
///
398398
/// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
399399
/// unsigned transaction and then sign it with your wallet.
400-
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction>;
400+
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()>;
401401
}
402402

403403
/// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
@@ -406,17 +406,17 @@ pub trait CoinSelectionSource {
406406
/// For a synchronous version of this trait, see [`sync::WalletSourceSync`].
407407
pub trait WalletSource {
408408
/// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
409-
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>>;
409+
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>, ()>;
410410
/// Returns a script to use for change above dust resulting from a successful coin selection
411411
/// attempt.
412-
fn get_change_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf>;
412+
fn get_change_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()>;
413413
/// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
414414
/// the transaction known to the wallet (i.e., any provided via
415415
/// [`WalletSource::list_confirmed_utxos`]).
416416
///
417417
/// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
418418
/// unsigned transaction and then sign it with your wallet.
419-
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction>;
419+
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()>;
420420
}
421421

422422
/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
@@ -608,7 +608,7 @@ where
608608
fn select_confirmed_utxos<'a>(
609609
&'a self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &'a [TxOut],
610610
target_feerate_sat_per_1000_weight: u32, max_tx_weight: u64,
611-
) -> AsyncResult<'a, CoinSelection> {
611+
) -> AsyncResult<'a, CoinSelection, ()> {
612612
Box::pin(async move {
613613
let utxos = self.source.list_confirmed_utxos().await?;
614614
// TODO: Use fee estimation utils when we upgrade to bitcoin v0.30.0.
@@ -659,7 +659,7 @@ where
659659
})
660660
}
661661

662-
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
662+
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
663663
self.source.sign_psbt(psbt)
664664
}
665665
}

lightning/src/events/bump_transaction/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ impl<T: Deref> WalletSource for WalletSourceSyncWrapper<T>
5858
where
5959
T::Target: WalletSourceSync,
6060
{
61-
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>> {
61+
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>, ()> {
6262
let utxos = self.0.list_confirmed_utxos();
6363
Box::pin(async move { utxos })
6464
}
6565

66-
fn get_change_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf> {
66+
fn get_change_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()> {
6767
let script = self.0.get_change_script();
6868
Box::pin(async move { script })
6969
}
7070

71-
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
71+
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
7272
let signed_psbt = self.0.sign_psbt(psbt);
7373
Box::pin(async move { signed_psbt })
7474
}
@@ -171,7 +171,7 @@ where
171171
fn select_confirmed_utxos<'a>(
172172
&'a self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &'a [TxOut],
173173
target_feerate_sat_per_1000_weight: u32, max_tx_weight: u64,
174-
) -> AsyncResult<'a, CoinSelection> {
174+
) -> AsyncResult<'a, CoinSelection, ()> {
175175
let coins = self.0.select_confirmed_utxos(
176176
claim_id,
177177
must_spend,
@@ -182,7 +182,7 @@ where
182182
Box::pin(async move { coins })
183183
}
184184

185-
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
185+
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
186186
let psbt = self.0.sign_psbt(psbt);
187187
Box::pin(async move { psbt })
188188
}

lightning/src/sign/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ pub trait ChangeDestinationSource {
10641064
///
10651065
/// This method should return a different value each time it is called, to avoid linking
10661066
/// on-chain funds controlled to the same user.
1067-
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf>;
1067+
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()>;
10681068
}
10691069

10701070
/// A synchronous helper trait that describes an on-chain wallet capable of returning a (change) destination script.
@@ -1096,7 +1096,7 @@ impl<T: Deref> ChangeDestinationSource for ChangeDestinationSourceSyncWrapper<T>
10961096
where
10971097
T::Target: ChangeDestinationSourceSync,
10981098
{
1099-
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf> {
1099+
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()> {
11001100
let script = self.0.get_change_destination_script();
11011101
Box::pin(async move { script })
11021102
}

lightning/src/util/async_poll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ pub(crate) fn dummy_waker() -> Waker {
9393
}
9494

9595
#[cfg(feature = "std")]
96-
/// A type alias for a future that returns a result of type T.
97-
pub type AsyncResult<'a, T> = Pin<Box<dyn Future<Output = Result<T, ()>> + 'a + Send>>;
96+
/// A type alias for a future that returns a result of type `T` or error `E`.
97+
pub type AsyncResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + 'a + Send>>;
9898
#[cfg(not(feature = "std"))]
99-
/// A type alias for a future that returns a result of type T.
100-
pub type AsyncResult<'a, T> = Pin<Box<dyn Future<Output = Result<T, ()>> + 'a>>;
99+
/// A type alias for a future that returns a result of type `T` or error `E`.
100+
pub type AsyncResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + 'a>>;
101101

102102
/// Marker trait to optionally implement `Sync` under std.
103103
#[cfg(feature = "std")]

lightning/src/util/persist.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::chain::transaction::OutPoint;
3434
use crate::ln::types::ChannelId;
3535
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, SignerProvider};
3636
use crate::sync::Mutex;
37-
use crate::util::async_poll::{dummy_waker, MaybeSend, MaybeSync};
37+
use crate::util::async_poll::{dummy_waker, AsyncResult, MaybeSend, MaybeSync};
3838
use crate::util::logger::Logger;
3939
use crate::util::native_async::FutureSpawner;
4040
use crate::util::ser::{Readable, ReadableArgs, Writeable};
@@ -160,31 +160,31 @@ where
160160
{
161161
fn read(
162162
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
163-
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> {
163+
) -> AsyncResult<'static, Vec<u8>, io::Error> {
164164
let res = self.0.read(primary_namespace, secondary_namespace, key);
165165

166166
Box::pin(async move { res })
167167
}
168168

169169
fn write(
170170
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
171-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
171+
) -> AsyncResult<'static, (), io::Error> {
172172
let res = self.0.write(primary_namespace, secondary_namespace, key, buf);
173173

174174
Box::pin(async move { res })
175175
}
176176

177177
fn remove(
178178
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
179-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
179+
) -> AsyncResult<'static, (), io::Error> {
180180
let res = self.0.remove(primary_namespace, secondary_namespace, key);
181181

182182
Box::pin(async move { res })
183183
}
184184

185185
fn list(
186186
&self, primary_namespace: &str, secondary_namespace: &str,
187-
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> {
187+
) -> AsyncResult<'static, Vec<String>, io::Error> {
188188
let res = self.0.list(primary_namespace, secondary_namespace);
189189

190190
Box::pin(async move { res })
@@ -222,7 +222,7 @@ pub trait KVStore {
222222
/// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
223223
fn read(
224224
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
225-
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>>;
225+
) -> AsyncResult<'static, Vec<u8>, io::Error>;
226226
/// Persists the given data under the given `key`.
227227
///
228228
/// The order of multiple writes to the same key needs to be retained while persisting
@@ -242,23 +242,23 @@ pub trait KVStore {
242242
/// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the store.
243243
fn write(
244244
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
245-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>>;
245+
) -> AsyncResult<'static, (), io::Error>;
246246
/// Removes any data that had previously been persisted under the given `key`.
247247
///
248248
/// Returns successfully if no data will be stored for the given `primary_namespace`,
249249
/// `secondary_namespace`, and `key`, independently of whether it was present before its
250250
/// invokation or not.
251251
fn remove(
252252
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
253-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>>;
253+
) -> AsyncResult<'static, (), io::Error>;
254254
/// Returns a list of keys that are stored under the given `secondary_namespace` in
255255
/// `primary_namespace`.
256256
///
257257
/// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
258258
/// returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
259259
fn list(
260260
&self, primary_namespace: &str, secondary_namespace: &str,
261-
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>>;
261+
) -> AsyncResult<'static, Vec<String>, io::Error>;
262262
}
263263

264264
/// Provides additional interface methods that are required for [`KVStore`]-to-[`KVStore`]

lightning/src/util/sweep.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ use bitcoin::{BlockHash, ScriptBuf, Transaction, Txid};
3535

3636
use core::future::Future;
3737
use core::ops::Deref;
38-
use core::pin::Pin;
3938
use core::sync::atomic::{AtomicBool, Ordering};
4039
use core::task;
4140

42-
use super::async_poll::dummy_waker;
41+
use super::async_poll::{dummy_waker, AsyncResult};
4342

4443
/// The number of blocks we wait before we prune the tracked spendable outputs.
4544
pub const PRUNE_DELAY_BLOCKS: u32 = ARCHIVAL_DELAY_BLOCKS + ANTI_REORG_DELAY;
@@ -604,9 +603,7 @@ where
604603
sweeper_state.dirty = true;
605604
}
606605

607-
fn persist_state<'a>(
608-
&self, sweeper_state: &SweeperState,
609-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'a + Send>> {
606+
fn persist_state<'a>(&self, sweeper_state: &SweeperState) -> AsyncResult<'a, (), io::Error> {
610607
let encoded = sweeper_state.encode();
611608

612609
self.kv_store.write(

lightning/src/util/test_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use crate::sign::{self, ReceiveAuthKey};
5050
use crate::sign::{ChannelSigner, PeerStorageKey};
5151
use crate::sync::RwLock;
5252
use crate::types::features::{ChannelFeatures, InitFeatures, NodeFeatures};
53+
use crate::util::async_poll::AsyncResult;
5354
use crate::util::config::UserConfig;
5455
use crate::util::dyn_signer::{
5556
DynKeysInterface, DynKeysInterfaceTrait, DynPhantomKeysInterface, DynSigner,
@@ -1011,13 +1012,13 @@ impl TestStore {
10111012
impl KVStore for TestStore {
10121013
fn read(
10131014
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1014-
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> {
1015+
) -> AsyncResult<'static, Vec<u8>, io::Error> {
10151016
let res = self.read_internal(&primary_namespace, &secondary_namespace, &key);
10161017
Box::pin(async move { res })
10171018
}
10181019
fn write(
10191020
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
1020-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
1021+
) -> AsyncResult<'static, (), io::Error> {
10211022
let path = format!("{primary_namespace}/{secondary_namespace}/{key}");
10221023
let future = Arc::new(Mutex::new((None, None)));
10231024

@@ -1030,13 +1031,13 @@ impl KVStore for TestStore {
10301031
}
10311032
fn remove(
10321033
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1033-
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
1034+
) -> AsyncResult<'static, (), io::Error> {
10341035
let res = self.remove_internal(&primary_namespace, &secondary_namespace, &key);
10351036
Box::pin(async move { res })
10361037
}
10371038
fn list(
10381039
&self, primary_namespace: &str, secondary_namespace: &str,
1039-
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> {
1040+
) -> AsyncResult<'static, Vec<String>, io::Error> {
10401041
let res = self.list_internal(primary_namespace, secondary_namespace);
10411042
Box::pin(async move { res })
10421043
}

0 commit comments

Comments
 (0)