Skip to content

Commit 46285be

Browse files
committed
Reduce syncing and shutdown timeouts considerably
Previously, we had to configure enormous syncing timeouts as the BDK wallet syncing would hold a central mutex that could lead to large parts of event handling and syncing locking up. Here, we drop the configured timeouts considerably across the board, since such huge values are hopefully not required anymore.
1 parent 8aefd5b commit 46285be

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/chain/electrum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use std::time::{Duration, Instant};
4040

4141
const BDK_ELECTRUM_CLIENT_BATCH_SIZE: usize = 5;
4242
const ELECTRUM_CLIENT_NUM_RETRIES: u8 = 3;
43-
const ELECTRUM_CLIENT_TIMEOUT_SECS: u8 = 20;
43+
const ELECTRUM_CLIENT_TIMEOUT_SECS: u8 = 10;
4444

4545
pub(crate) struct ElectrumRuntimeClient {
4646
electrum_client: Arc<ElectrumClient>,

src/config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ pub(crate) const NODE_ANN_BCAST_INTERVAL: Duration = Duration::from_secs(60 * 60
6565
pub(crate) const WALLET_SYNC_INTERVAL_MINIMUM_SECS: u64 = 10;
6666

6767
// The timeout after which we abort a wallet syncing operation.
68-
pub(crate) const BDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 90;
68+
pub(crate) const BDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 20;
6969

7070
// The timeout after which we abort a wallet syncing operation.
71-
pub(crate) const LDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 30;
71+
pub(crate) const LDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 10;
72+
73+
// The timeout after which we give up waiting on LDK's event handler to exit on shutdown.
74+
pub(crate) const LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS: u64 = 30;
7275

7376
// The timeout after which we abort a fee rate cache update operation.
7477
pub(crate) const FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS: u64 = 5;

src/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ pub use builder::NodeBuilder as Builder;
126126

127127
use chain::ChainSource;
128128
use config::{
129-
default_user_config, may_announce_channel, ChannelConfig, Config, NODE_ANN_BCAST_INTERVAL,
130-
PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
129+
default_user_config, may_announce_channel, ChannelConfig, Config,
130+
LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL,
131+
RGS_SYNC_INTERVAL,
131132
};
132133
use connection::ConnectionManager;
133134
use event::{EventHandler, EventQueue};
@@ -645,6 +646,7 @@ impl Node {
645646
pub fn stop(&self) -> Result<(), Error> {
646647
let mut runtime_lock = self.runtime.write().unwrap();
647648
let _runtime = runtime_lock.take().ok_or(Error::NotRunning)?;
649+
648650
#[cfg(tokio_unstable)]
649651
let metrics_runtime = Arc::clone(&_runtime);
650652

@@ -673,15 +675,12 @@ impl Node {
673675
let event_handling_stopped_logger = Arc::clone(&self.logger);
674676
let mut event_handling_stopped_receiver = self.event_handling_stopped_sender.subscribe();
675677

676-
// FIXME: For now, we wait up to 100 secs (BDK_WALLET_SYNC_TIMEOUT_SECS + 10) to allow
677-
// event handling to exit gracefully even if it was blocked on the BDK wallet syncing. We
678-
// should drop this considerably post upgrading to BDK 1.0.
679678
let stop_runtime =
680679
tokio::runtime::Builder::new_current_thread().enable_time().build().unwrap();
681680
let timeout_res = tokio::task::block_in_place(move || {
682681
stop_runtime.block_on(async {
683682
tokio::time::timeout(
684-
Duration::from_secs(100),
683+
Duration::from_secs(LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS),
685684
event_handling_stopped_receiver.changed(),
686685
)
687686
.await

0 commit comments

Comments
 (0)