Skip to content

Commit 041238d

Browse files
committed
Remove Send + Sync bounds when no-std
1 parent afb80e5 commit 041238d

File tree

7 files changed

+40
-45
lines changed

7 files changed

+40
-45
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ impl<
259259
G,
260260
&'a (dyn UtxoLookup + Send + Sync),
261261
L,
262-
> where
262+
>
263+
where
263264
L::Target: Logger,
264265
{
265266
/// Initializes a new [`GossipSync::Rapid`] variant.
@@ -276,7 +277,8 @@ impl<'a, L: Deref>
276277
&'a NetworkGraph<L>,
277278
&'a (dyn UtxoLookup + Send + Sync),
278279
L,
279-
> where
280+
>
281+
where
280282
L::Target: Logger,
281283
{
282284
/// Initializes a new [`GossipSync::None`] variant.
@@ -300,7 +302,7 @@ where
300302

301303
/// Updates scorer based on event and returns whether an update occurred so we can decide whether
302304
/// to persist.
303-
fn update_scorer<'a, S: Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
305+
fn update_scorer<'a, S: Deref<Target = SC>, SC: 'a + WriteableScore<'a>>(
304306
scorer: &'a S, event: &Event, duration_since_epoch: Duration,
305307
) -> bool {
306308
match event {
@@ -887,10 +889,8 @@ pub async fn process_events_async<
887889
P: Deref,
888890
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
889891
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,
892+
ES: Deref,
893+
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
894894
CM: Deref,
895895
OM: Deref,
896896
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
@@ -901,7 +901,7 @@ pub async fn process_events_async<
901901
O: Deref,
902902
K: Deref,
903903
OS: Deref<Target = OutputSweeper<T, D, F, CF, K, L, O>>,
904-
S: Deref<Target = SC> + Send + Sync,
904+
S: Deref<Target = SC>,
905905
SC: for<'b> WriteableScore<'b>,
906906
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
907907
Sleeper: Fn(Duration) -> SleepFuture,
@@ -1356,15 +1356,13 @@ pub async fn process_events_async_with_kv_store_sync<
13561356
T: Deref,
13571357
F: Deref,
13581358
G: Deref<Target = NetworkGraph<L>>,
1359-
L: Deref + Send + Sync,
1359+
L: Deref,
13601360
P: Deref,
13611361
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
13621362
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,
1363+
ES: Deref,
1364+
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
1365+
CM: Deref,
13681366
OM: Deref,
13691367
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
13701368
RGS: Deref<Target = RapidGossipSync<G, L>>,
@@ -1374,7 +1372,7 @@ pub async fn process_events_async_with_kv_store_sync<
13741372
O: Deref,
13751373
K: Deref,
13761374
OS: Deref<Target = OutputSweeperSync<T, D, F, CF, K, L, O>>,
1377-
S: Deref<Target = SC> + Send + Sync,
1375+
S: Deref<Target = SC>,
13781376
SC: for<'b> WriteableScore<'b>,
13791377
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
13801378
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ pub(crate) fn dummy_waker() -> Waker {
9494

9595
#[cfg(feature = "std")]
9696
/// 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>>;
97+
pub type AsyncResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + 'a + Send>>;
9898
#[cfg(not(feature = "std"))]
9999
/// 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>>;
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(

0 commit comments

Comments
 (0)