Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ where

/// Updates scorer based on event and returns whether an update occurred so we can decide whether
/// to persist.
fn update_scorer<'a, S: Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
fn update_scorer<'a, S: Deref<Target = SC>, SC: 'a + WriteableScore<'a>>(
scorer: &'a S, event: &Event, duration_since_epoch: Duration,
) -> bool {
match event {
Expand Down Expand Up @@ -887,10 +887,8 @@ pub async fn process_events_async<
P: Deref,
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
EventHandler: Fn(Event) -> EventHandlerFuture,
ES: Deref + Send,
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>
+ Send
+ Sync,
ES: Deref,
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
CM: Deref,
OM: Deref,
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
Expand All @@ -901,7 +899,7 @@ pub async fn process_events_async<
O: Deref,
K: Deref,
OS: Deref<Target = OutputSweeper<T, D, F, CF, K, L, O>>,
S: Deref<Target = SC> + Send + Sync,
S: Deref<Target = SC>,
SC: for<'b> WriteableScore<'b>,
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
Sleeper: Fn(Duration) -> SleepFuture,
Expand Down Expand Up @@ -1356,15 +1354,13 @@ pub async fn process_events_async_with_kv_store_sync<
T: Deref,
F: Deref,
G: Deref<Target = NetworkGraph<L>>,
L: Deref + Send + Sync,
L: Deref,
P: Deref,
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
EventHandler: Fn(Event) -> EventHandlerFuture,
ES: Deref + Send,
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>
+ Send
+ Sync,
CM: Deref + Send + Sync,
ES: Deref,
M: Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>,
CM: Deref,
OM: Deref,
PGS: Deref<Target = P2PGossipSync<G, UL, L>>,
RGS: Deref<Target = RapidGossipSync<G, L>>,
Expand All @@ -1374,7 +1370,7 @@ pub async fn process_events_async_with_kv_store_sync<
O: Deref,
K: Deref,
OS: Deref<Target = OutputSweeperSync<T, D, F, CF, K, L, O>>,
S: Deref<Target = SC> + Send + Sync,
S: Deref<Target = SC>,
SC: for<'b> WriteableScore<'b>,
SleepFuture: core::future::Future<Output = bool> + core::marker::Unpin,
Sleeper: Fn(Duration) -> SleepFuture,
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/events/bump_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ pub trait CoinSelectionSource {
fn select_confirmed_utxos<'a>(
&'a self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &'a [TxOut],
target_feerate_sat_per_1000_weight: u32, max_tx_weight: u64,
) -> AsyncResult<'a, CoinSelection>;
) -> AsyncResult<'a, CoinSelection, ()>;
/// Signs and provides the full witness for all inputs within the transaction known to the
/// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
///
/// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
/// unsigned transaction and then sign it with your wallet.
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction>;
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()>;
}

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

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

fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
self.source.sign_psbt(psbt)
}
}
Expand Down
10 changes: 5 additions & 5 deletions lightning/src/events/bump_transaction/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ impl<T: Deref> WalletSource for WalletSourceSyncWrapper<T>
where
T::Target: WalletSourceSync,
{
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>> {
fn list_confirmed_utxos<'a>(&'a self) -> AsyncResult<'a, Vec<Utxo>, ()> {
let utxos = self.0.list_confirmed_utxos();
Box::pin(async move { utxos })
}

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

fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
let signed_psbt = self.0.sign_psbt(psbt);
Box::pin(async move { signed_psbt })
}
Expand Down Expand Up @@ -171,7 +171,7 @@ where
fn select_confirmed_utxos<'a>(
&'a self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &'a [TxOut],
target_feerate_sat_per_1000_weight: u32, max_tx_weight: u64,
) -> AsyncResult<'a, CoinSelection> {
) -> AsyncResult<'a, CoinSelection, ()> {
let coins = self.0.select_confirmed_utxos(
claim_id,
must_spend,
Expand All @@ -182,7 +182,7 @@ where
Box::pin(async move { coins })
}

fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction> {
fn sign_psbt<'a>(&'a self, psbt: Psbt) -> AsyncResult<'a, Transaction, ()> {
let psbt = self.0.sign_psbt(psbt);
Box::pin(async move { psbt })
}
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ pub trait ChangeDestinationSource {
///
/// This method should return a different value each time it is called, to avoid linking
/// on-chain funds controlled to the same user.
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf>;
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()>;
}

/// A synchronous helper trait that describes an on-chain wallet capable of returning a (change) destination script.
Expand Down Expand Up @@ -1096,7 +1096,7 @@ impl<T: Deref> ChangeDestinationSource for ChangeDestinationSourceSyncWrapper<T>
where
T::Target: ChangeDestinationSourceSync,
{
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf> {
fn get_change_destination_script<'a>(&'a self) -> AsyncResult<'a, ScriptBuf, ()> {
let script = self.0.get_change_destination_script();
Box::pin(async move { script })
}
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/util/async_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ pub(crate) fn dummy_waker() -> Waker {
}

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

/// Marker trait to optionally implement `Sync` under std.
#[cfg(feature = "std")]
Expand Down
18 changes: 9 additions & 9 deletions lightning/src/util/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::chain::transaction::OutPoint;
use crate::ln::types::ChannelId;
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, SignerProvider};
use crate::sync::Mutex;
use crate::util::async_poll::{dummy_waker, MaybeSend, MaybeSync};
use crate::util::async_poll::{dummy_waker, AsyncResult, MaybeSend, MaybeSync};
use crate::util::logger::Logger;
use crate::util::native_async::FutureSpawner;
use crate::util::ser::{Readable, ReadableArgs, Writeable};
Expand Down Expand Up @@ -160,31 +160,31 @@ where
{
fn read(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> {
) -> AsyncResult<'static, Vec<u8>, io::Error> {
let res = self.0.read(primary_namespace, secondary_namespace, key);

Box::pin(async move { res })
}

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

Box::pin(async move { res })
}

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

Box::pin(async move { res })
}

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

Box::pin(async move { res })
Expand Down Expand Up @@ -222,7 +222,7 @@ pub trait KVStore {
/// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
fn read(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>>;
) -> AsyncResult<'static, Vec<u8>, io::Error>;
/// Persists the given data under the given `key`.
///
/// The order of multiple writes to the same key needs to be retained while persisting
Expand All @@ -242,23 +242,23 @@ pub trait KVStore {
/// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the store.
fn write(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>>;
) -> AsyncResult<'static, (), io::Error>;
/// Removes any data that had previously been persisted under the given `key`.
///
/// Returns successfully if no data will be stored for the given `primary_namespace`,
/// `secondary_namespace`, and `key`, independently of whether it was present before its
/// invokation or not.
fn remove(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>>;
) -> AsyncResult<'static, (), io::Error>;
/// Returns a list of keys that are stored under the given `secondary_namespace` in
/// `primary_namespace`.
///
/// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
/// returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
fn list(
&self, primary_namespace: &str, secondary_namespace: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>>;
) -> AsyncResult<'static, Vec<String>, io::Error>;
}

/// Provides additional interface methods that are required for [`KVStore`]-to-[`KVStore`]
Expand Down
7 changes: 2 additions & 5 deletions lightning/src/util/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ use bitcoin::{BlockHash, ScriptBuf, Transaction, Txid};

use core::future::Future;
use core::ops::Deref;
use core::pin::Pin;
use core::sync::atomic::{AtomicBool, Ordering};
use core::task;

use super::async_poll::dummy_waker;
use super::async_poll::{dummy_waker, AsyncResult};

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

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

self.kv_store.write(
Expand Down
9 changes: 5 additions & 4 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use crate::sign::{self, ReceiveAuthKey};
use crate::sign::{ChannelSigner, PeerStorageKey};
use crate::sync::RwLock;
use crate::types::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use crate::util::async_poll::AsyncResult;
use crate::util::config::UserConfig;
use crate::util::dyn_signer::{
DynKeysInterface, DynKeysInterfaceTrait, DynPhantomKeysInterface, DynSigner,
Expand Down Expand Up @@ -1011,13 +1012,13 @@ impl TestStore {
impl KVStore for TestStore {
fn read(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> {
) -> AsyncResult<'static, Vec<u8>, io::Error> {
let res = self.read_internal(&primary_namespace, &secondary_namespace, &key);
Box::pin(async move { res })
}
fn write(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
) -> AsyncResult<'static, (), io::Error> {
let path = format!("{primary_namespace}/{secondary_namespace}/{key}");
let future = Arc::new(Mutex::new((None, None)));

Expand All @@ -1030,13 +1031,13 @@ impl KVStore for TestStore {
}
fn remove(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> {
) -> AsyncResult<'static, (), io::Error> {
let res = self.remove_internal(&primary_namespace, &secondary_namespace, &key);
Box::pin(async move { res })
}
fn list(
&self, primary_namespace: &str, secondary_namespace: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> {
) -> AsyncResult<'static, Vec<String>, io::Error> {
let res = self.list_internal(primary_namespace, secondary_namespace);
Box::pin(async move { res })
}
Expand Down
Loading