Skip to content

Commit 35b5269

Browse files
committed
refactor: Move LexeBitcoind, LxTask into common
1 parent 71018f8 commit 35b5269

File tree

17 files changed

+78
-50
lines changed

17 files changed

+78
-50
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod rng;
2929
pub mod root_seed;
3030
pub mod sha256;
3131
pub mod shutdown;
32+
pub mod task;
3233

3334
/// Assert at compile time that two `usize` values are equal. This assert has a
3435
/// nice benefit where there compiler error will actually _print out_ the

common/src/task.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use core::future::Future;
2+
use core::pin::Pin;
3+
use core::task::{Context, Poll};
4+
5+
use tokio::task::{JoinError, JoinHandle};
6+
7+
/// A thin wrapper around [`tokio::task::JoinHandle`] that adds the
8+
/// `#[must_use]` lint to ensure that all spawned tasks are joined or explictly
9+
/// annotated that no joining is required.
10+
#[must_use]
11+
pub struct LxTask<T>(JoinHandle<T>);
12+
13+
impl<T> LxTask<T> {
14+
#[allow(clippy::disallowed_methods)]
15+
pub fn spawn<F>(future: F) -> LxTask<F::Output>
16+
where
17+
F: Future<Output = T> + Send + 'static,
18+
F::Output: Send + 'static,
19+
{
20+
Self(tokio::spawn(future))
21+
}
22+
}
23+
24+
impl<T> Future for LxTask<T> {
25+
type Output = Result<T, JoinError>;
26+
fn poll(
27+
mut self: Pin<&mut Self>,
28+
cx: &mut Context<'_>,
29+
) -> Poll<Self::Output> {
30+
Pin::new(&mut self.0).poll(cx)
31+
}
32+
}

lexe-ln/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ anyhow = "1"
5050
once_cell = "1"
5151
# A wrapper type for carefully handling secrets
5252
secrecy = "0.8"
53+
# Serialization / deserialization framework
54+
serde = { version = "1", features = ["derive"] }
55+
serde_json = "1"
5356
# Logging
5457
tracing = "0.1"
5558
tracing-core = "0.1"
@@ -58,3 +61,19 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
5861
"fmt",
5962
"tracing-log",
6063
] }
64+
65+
# --- PATCHED DEPENDENCIES --- #
66+
# - Be sure to use the specific patched versions.
67+
# - See the workspace Cargo.toml for patch declarations.
68+
# - The versions for transitive dependencies (such as hyper, mio, ring, etc) are
69+
# declared in `common`'s Cargo.toml and propagated to other crates by
70+
# workspace-level dependency resolution.
71+
72+
tokio = { version = "=1.15.0", default-features = false, features = [
73+
"io-util",
74+
"macros",
75+
"net",
76+
"rt",
77+
"sync",
78+
"time"
79+
] }

node/src/lexe/bitcoind/mod.rs renamed to lexe-ln/src/bitcoind/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bitcoin::consensus::encode;
1111
use bitcoin::hash_types::{BlockHash, Txid};
1212
use bitcoin::util::address::Address;
1313
use common::cli::{BitcoindRpcInfo, Network};
14+
use common::task::LxTask;
1415
use lightning::chain::chaininterface::{
1516
BroadcasterInterface, ConfirmationTarget, FeeEstimator,
1617
};
@@ -22,8 +23,6 @@ use lightning_block_sync::{
2223
use tokio::time;
2324
use tracing::{debug, error};
2425

25-
use crate::types::LxTask;
26-
2726
mod types;
2827

2928
pub use types::*;
File renamed without changes.

lexe-ln/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! The `lexe-ln` crate contains shared Lexe newtypes for bitcoin / lightning
22
//! types (usually) defined in LDK.
33
4+
// Enforce disallowed methods clippy lint
5+
#![deny(clippy::disallowed_methods)]
6+
7+
pub mod bitcoind;
48
pub mod keys_manager;
59
pub mod logger;

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ futures = "0.3"
6060
http = "0.2"
6161
# Used to hold a Tokio runtime used by the sync fns in the Persister trait impl
6262
once_cell = "1"
63-
# Used to serialize / deserialize from API
63+
# Serialization / deserialization framework
6464
serde = { version = "1", features = ["derive"] }
6565
serde_qs = "0"
6666
serde_json = "1"

node/src/event_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use bitcoin::secp256k1::Secp256k1;
1212
use bitcoin_bech32::WitnessProgram;
1313
use common::cli::Network;
1414
use common::hex;
15+
use common::task::LxTask;
16+
use lexe_ln::bitcoind::LexeBitcoind;
1517
use lexe_ln::keys_manager::LexeKeysManager;
1618
use lightning::chain::chaininterface::{
1719
BroadcasterInterface, ConfirmationTarget, FeeEstimator,
@@ -21,10 +23,9 @@ use lightning::util::events::{Event, EventHandler, PaymentPurpose};
2123
use tokio::runtime::Handle;
2224
use tracing::{debug, error};
2325

24-
use crate::lexe::bitcoind::LexeBitcoind;
2526
use crate::lexe::channel_manager::NodeChannelManager;
2627
use crate::types::{
27-
HTLCStatus, LxTask, MillisatAmount, NetworkGraphType, PaymentInfo,
28+
HTLCStatus, MillisatAmount, NetworkGraphType, PaymentInfo,
2829
PaymentInfoStorageType,
2930
};
3031

node/src/inactivity_timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ mod tests {
227227

228228
// Spawn a task to generate an activity event 500ms in
229229
let activity_tx = mats.activity_tx.clone();
230-
use crate::types::LxTask;
230+
use common::task::LxTask;
231231
let activity_task = LxTask::spawn(async move {
232232
time::sleep(Duration::from_millis(500)).await;
233233
let _ = activity_tx.send(()).await;
@@ -255,7 +255,7 @@ mod tests {
255255
// signal 750ms in
256256
let activity_tx = mats.activity_tx.clone();
257257
let shutdown = mats.shutdown.clone();
258-
use crate::types::LxTask;
258+
use common::task::LxTask;
259259
let activity_task = LxTask::spawn(async move {
260260
time::sleep(Duration::from_millis(500)).await;
261261
let _ = activity_tx.send(()).await;

0 commit comments

Comments
 (0)