Skip to content

Commit 9c9b4a8

Browse files
committed
Use lightning::sync via symlink in lightning-liquidity
.. to which end we also need to make some additions to `debug_sync` and `nostd_sync`.
1 parent 3a8e1bf commit 9c9b4a8

File tree

10 files changed

+39
-124
lines changed

10 files changed

+39
-124
lines changed

lightning-liquidity/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ categories = ["cryptography::cryptocurrencies"]
1616
[features]
1717
default = ["std"]
1818
std = ["lightning/std"]
19+
backtrace = ["dep:backtrace"]
1920

2021
[dependencies]
2122
lightning = { version = "0.0.124", path = "../lightning", default-features = false }
@@ -27,6 +28,7 @@ bitcoin = { version = "0.32.2", default-features = false, features = ["serde"] }
2728
chrono = { version = "0.4", default-features = false, features = ["serde", "alloc"] }
2829
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
2930
serde_json = "1.0"
31+
backtrace = { version = "0.3", optional = true }
3032

3133
[dev-dependencies]
3234
lightning = { version = "0.0.124", path = "../lightning", default-features = false, features = ["_test_utils"] }
@@ -43,4 +45,6 @@ level = "forbid"
4345
check-cfg = [
4446
"cfg(lsps1_service)",
4547
"cfg(c_bindings)",
48+
"cfg(backtrace)",
49+
"cfg(ldk_bench)",
4650
]

lightning-liquidity/src/events.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) struct EventQueue {
2828
queue: Arc<Mutex<VecDeque<Event>>>,
2929
waker: Arc<Mutex<Option<Waker>>>,
3030
#[cfg(feature = "std")]
31-
condvar: std::sync::Condvar,
31+
condvar: crate::sync::Condvar,
3232
}
3333

3434
impl EventQueue {
@@ -37,7 +37,7 @@ impl EventQueue {
3737
let waker = Arc::new(Mutex::new(None));
3838
#[cfg(feature = "std")]
3939
{
40-
let condvar = std::sync::Condvar::new();
40+
let condvar = crate::sync::Condvar::new();
4141
Self { queue, waker, condvar }
4242
}
4343
#[cfg(not(feature = "std"))]
@@ -67,8 +67,10 @@ impl EventQueue {
6767

6868
#[cfg(feature = "std")]
6969
pub fn wait_next_event(&self) -> Event {
70-
let mut queue =
71-
self.condvar.wait_while(self.queue.lock().unwrap(), |queue| queue.is_empty()).unwrap();
70+
let mut queue = self
71+
.condvar
72+
.wait_while(self.queue.lock().unwrap(), |queue: &mut VecDeque<Event>| queue.is_empty())
73+
.unwrap();
7274

7375
let event = queue.pop_front().expect("non-empty queue");
7476
let should_notify = !queue.is_empty();

lightning-liquidity/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub mod lsps1;
6262
pub mod lsps2;
6363
mod manager;
6464
pub mod message_queue;
65+
#[allow(dead_code)]
66+
#[allow(unused_imports)]
6567
mod sync;
6668
#[cfg(test)]
6769
mod tests;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../lightning/src/sync/debug_sync.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../lightning/src/sync/fairrwlock.rs

lightning-liquidity/src/sync/mod.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

lightning-liquidity/src/sync/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../lightning/src/sync/mod.rs

lightning-liquidity/src/sync/nostd_sync.rs

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../lightning/src/sync/nostd_sync.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../lightning/src/sync/test_lockorder_checks.rs

lightning/src/sync/debug_sync.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub use alloc::sync::Arc;
2+
use core::fmt;
23
use core::ops::{Deref, DerefMut};
34
use core::time::Duration;
45

@@ -65,6 +66,11 @@ impl Condvar {
6566
pub fn notify_all(&self) {
6667
self.inner.notify_all();
6768
}
69+
70+
#[allow(unused)]
71+
pub fn notify_one(&self) {
72+
self.inner.notify_one();
73+
}
6874
}
6975

7076
thread_local! {
@@ -254,6 +260,21 @@ impl<T: Sized> Mutex<T> {
254260
}
255261
}
256262

263+
impl<T: Sized + fmt::Debug> fmt::Debug for Mutex<T> {
264+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
265+
let mut d = f.debug_struct("Mutex");
266+
match self.try_lock() {
267+
Ok(guard) => {
268+
d.field("data", &&*guard);
269+
},
270+
Err(()) => {
271+
d.field("data", &format_args!("<locked>"));
272+
},
273+
}
274+
d.finish_non_exhaustive()
275+
}
276+
}
277+
257278
#[must_use = "if unused the Mutex will immediately unlock"]
258279
pub struct MutexGuard<'a, T: Sized + 'a> {
259280
mutex: &'a Mutex<T>,

lightning/src/sync/nostd_sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::ops::{Deref, DerefMut};
55

66
pub type LockResult<Guard> = Result<Guard, ()>;
77

8+
#[derive(Debug)]
89
pub struct Mutex<T: ?Sized> {
910
inner: RefCell<T>,
1011
}

0 commit comments

Comments
 (0)