Skip to content

Commit

Permalink
Disable watchdog if watchdog_timeout_sec config is 0 (#263)
Browse files Browse the repository at this point in the history
## πŸ“ 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)
  • Loading branch information
ferranbt authored Dec 3, 2024
1 parent 936c4ff commit 921db00
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/rbuilder/src/bin/dummy-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn main() -> eyre::Result<()> {
Arc<DatabaseEnv>,
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,
Expand Down
12 changes: 8 additions & 4 deletions crates/rbuilder/src/live_builder/base_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,

/// List of `builders` to be used for live building
pub live_builders: Vec<String>,
Expand Down Expand Up @@ -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<Duration> {
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<PathBuf> {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions crates/rbuilder/src/live_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
P: StateProviderFactory + Clone,
BlocksSourceType: SlotSource,
{
pub watchdog_timeout: Duration,
pub watchdog_timeout: Option<Duration>,
pub error_storage_path: Option<PathBuf>,
pub simulation_threads: usize,
pub order_input_config: OrderInputConfig,
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
};
}
}

Expand Down

0 comments on commit 921db00

Please sign in to comment.