From 921db00de2cc3926187aed876e2c021e2e5b474a Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 3 Dec 2024 21:05:36 +0000 Subject: [PATCH] Disable watchdog if watchdog_timeout_sec config is 0 (#263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📝 Summary This PR disables the watchdog if the value from config is zero. --- ## ✅ I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [x] Added tests (if applicable) --- crates/rbuilder/src/bin/dummy-builder.rs | 2 +- crates/rbuilder/src/live_builder/base_config.rs | 12 ++++++++---- crates/rbuilder/src/live_builder/mod.rs | 14 +++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/rbuilder/src/bin/dummy-builder.rs b/crates/rbuilder/src/bin/dummy-builder.rs index cb09bd0b..29c903b0 100644 --- a/crates/rbuilder/src/bin/dummy-builder.rs +++ b/crates/rbuilder/src/bin/dummy-builder.rs @@ -92,7 +92,7 @@ async fn main() -> eyre::Result<()> { Arc, MevBoostSlotDataGenerator, > { - watchdog_timeout: Duration::from_secs(10000), + watchdog_timeout: Some(Duration::from_secs(10000)), error_storage_path: None, simulation_threads: 1, blocks_source: payload_event, diff --git a/crates/rbuilder/src/live_builder/base_config.rs b/crates/rbuilder/src/live_builder/base_config.rs index a3aed895..83a58634 100644 --- a/crates/rbuilder/src/live_builder/base_config.rs +++ b/crates/rbuilder/src/live_builder/base_config.rs @@ -90,7 +90,7 @@ pub struct BaseConfig { /// compares result of root hash using sparse trie and reference root hash pub root_hash_compare_sparse_trie: bool, - pub watchdog_timeout_sec: u64, + pub watchdog_timeout_sec: Option, /// List of `builders` to be used for live building pub live_builders: Vec, @@ -321,8 +321,12 @@ impl BaseConfig { Ok(http_provider(self.backtest_fetch_eth_rpc_url.parse()?)) } - pub fn watchdog_timeout(&self) -> Duration { - Duration::from_secs(self.watchdog_timeout_sec) + pub fn watchdog_timeout(&self) -> Option { + match self.watchdog_timeout_sec { + Some(0) => None, + Some(sec) => Some(Duration::from_secs(sec)), + None => None, + } } pub fn backtest_fetch_mempool_data_dir(&self) -> eyre::Result { @@ -438,7 +442,7 @@ impl Default for BaseConfig { extra_data: "extra_data_change_me".to_string(), root_hash_use_sparse_trie: false, root_hash_compare_sparse_trie: false, - watchdog_timeout_sec: 60 * 3, + watchdog_timeout_sec: None, backtest_fetch_mempool_data_dir: "/mnt/data/mempool".into(), backtest_fetch_eth_rpc_url: "http://127.0.0.1:8545".to_string(), backtest_fetch_eth_rpc_parallel: 1, diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index 8e9b3f06..abdbd973 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -87,7 +87,7 @@ where P: StateProviderFactory + Clone, BlocksSourceType: SlotSource, { - pub watchdog_timeout: Duration, + pub watchdog_timeout: Option, pub error_storage_path: Option, pub simulation_threads: usize, pub order_input_config: OrderInputConfig, @@ -178,7 +178,13 @@ where self.run_sparse_trie_prefetcher, ); - let watchdog_sender = spawn_watchdog_thread(self.watchdog_timeout)?; + let watchdog_sender = match self.watchdog_timeout { + Some(duration) => Some(spawn_watchdog_thread(duration)?), + None => { + info!("Watchdog not enabled"); + None + } + }; while let Some(payload) = payload_events_channel.recv().await { if self.blocklist.contains(&payload.fee_recipient()) { @@ -247,7 +253,9 @@ where time_until_slot_end.try_into().unwrap_or_default(), ); - watchdog_sender.try_send(()).unwrap_or_default(); + if let Some(watchdog_sender) = watchdog_sender.as_ref() { + watchdog_sender.try_send(()).unwrap_or_default(); + }; } }