Skip to content

Commit 2141ba6

Browse files
committed
f Remove {drop, set}_runtime()
1 parent e775a6b commit 2141ba6

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

src/event.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bitcoin::secp256k1::Secp256k1;
1919
use rand::{thread_rng, Rng};
2020
use std::collections::{hash_map, VecDeque};
2121
use std::ops::Deref;
22-
use std::sync::{Arc, Condvar, Mutex, RwLock};
22+
use std::sync::{Arc, Condvar, Mutex};
2323
use std::time::Duration;
2424

2525
/// The event queue will be persisted under this key.
@@ -240,7 +240,7 @@ where
240240
keys_manager: Arc<KeysManager>,
241241
inbound_payments: Arc<PaymentInfoStorage>,
242242
outbound_payments: Arc<PaymentInfoStorage>,
243-
tokio_runtime: RwLock<Option<Arc<tokio::runtime::Runtime>>>,
243+
tokio_runtime: Arc<tokio::runtime::Runtime>,
244244
logger: L,
245245
_config: Arc<Config>,
246246
}
@@ -254,9 +254,9 @@ where
254254
wallet: Arc<Wallet<bdk::sled::Tree>>, event_queue: Arc<EventQueue<K>>,
255255
channel_manager: Arc<ChannelManager>, network_graph: Arc<NetworkGraph>,
256256
keys_manager: Arc<KeysManager>, inbound_payments: Arc<PaymentInfoStorage>,
257-
outbound_payments: Arc<PaymentInfoStorage>, logger: L, _config: Arc<Config>,
257+
outbound_payments: Arc<PaymentInfoStorage>, tokio_runtime: Arc<tokio::runtime::Runtime>,
258+
logger: L, _config: Arc<Config>,
258259
) -> Self {
259-
let tokio_runtime = RwLock::new(None);
260260
Self {
261261
event_queue,
262262
wallet,
@@ -270,14 +270,6 @@ where
270270
_config,
271271
}
272272
}
273-
274-
pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) {
275-
*self.tokio_runtime.write().unwrap() = Some(tokio_runtime);
276-
}
277-
278-
pub(crate) fn drop_runtime(&self) {
279-
*self.tokio_runtime.write().unwrap() = None;
280-
}
281273
}
282274

283275
impl<K: Deref, L: Deref> LdkEventHandler for EventHandler<K, L>
@@ -472,16 +464,10 @@ where
472464
LdkEvent::ProbeFailed { .. } => {}
473465
LdkEvent::HTLCHandlingFailed { .. } => {}
474466
LdkEvent::PendingHTLCsForwardable { time_forwardable } => {
475-
let locked_runtime = self.tokio_runtime.read().unwrap();
476-
if locked_runtime.as_ref().is_none() {
477-
log_error!(self.logger, "Failed process HTLC forwards: No runtime.");
478-
unreachable!("Failed process HTLC forwards: No runtime.");
479-
}
480-
481467
let forwarding_channel_manager = self.channel_manager.clone();
482468
let min = time_forwardable.as_millis() as u64;
483469

484-
locked_runtime.as_ref().unwrap().spawn(async move {
470+
self.tokio_runtime.spawn(async move {
485471
let millis_to_sleep = thread_rng().gen_range(min..min * 5) as u64;
486472
tokio::time::sleep(Duration::from_millis(millis_to_sleep)).await;
487473

0 commit comments

Comments
 (0)