Skip to content

Commit

Permalink
New flag require-non-empty-blocklist (#397)
Browse files Browse the repository at this point in the history
## πŸ“ Summary

This flag is backwards compatible.
When set true makes use more robust for those looking to enforce a
blocklist.

## βœ… I have completed the following steps:

* [X] Run `make lint`
* [X] Run `make test`
* [X] Added tests (if applicable)
  • Loading branch information
ZanCorDX authored Jan 31, 2025
1 parent 7a1a272 commit 605cbd0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/rbuilder/src/backtest/backtest_build_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where

let blocklist = config
.base_config()
.blocklist_provider(false, cancel_token.clone())
.blocklist_provider(cancel_token.clone())
.await?
.get_blocklist()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<ConfigType: LiveBuilderConfig> LandedBlockFromDBOrdersSource<ConfigType> {
.await?;
let blocklist = config
.base_config()
.blocklist_provider(false, CancellationToken::new())
.blocklist_provider(CancellationToken::new())
.await?
.get_blocklist()?;

Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/backtest/redistribute/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where

let blocklist = config
.base_config()
.blocklist_provider(false, CancellationToken::new())
.blocklist_provider(CancellationToken::new())
.await?
.get_blocklist()?;

Expand Down
46 changes: 41 additions & 5 deletions crates/rbuilder/src/live_builder/base_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ pub struct BaseConfig {
/// Like blocklist_url_max_age_hours but in secs for integration tests.
pub blocklist_url_max_age_secs: Option<u64>,

/// if true will not allow to start without a blocklist or with an empty blocklist.
pub require_non_empty_blocklist: Option<bool>,

#[serde(deserialize_with = "deserialize_extra_data")]
pub extra_data: Vec<u8>,

Expand Down Expand Up @@ -299,33 +302,49 @@ impl BaseConfig {

pub async fn blocklist_provider(
&self,
validate_blocklist: bool,
cancellation_token: tokio_util::sync::CancellationToken,
) -> eyre::Result<Arc<dyn BlockListProvider>> {
if self.blocklist.is_some() && self.blocklist_file_path.is_some() {
eyre::bail!("You can't use blocklist AND blocklist_file_path")
}

let require_non_empty_blocklist = self
.require_non_empty_blocklist
.unwrap_or(DEFAULT_REQUIRE_NON_EMPTY_BLOCKLIST);
if self.blocklist_file_path.is_none()
&& self.blocklist.is_none()
&& require_non_empty_blocklist
{
eyre::bail!("require_non_empty_blocklist = true but no blocklist used (blocklist_file_path/blocklist are not set)");
}

if let Some(blocklist) = &self.blocklist {
// First try url loading
match Url::parse(blocklist) {
Ok(url) => {
return self
.blocklist_provider_from_url(url, validate_blocklist, cancellation_token)
.blocklist_provider_from_url(
url,
require_non_empty_blocklist,
cancellation_token,
)
.await;
}
Err(_) => {
// second try file loading
return self
.blocklist_provider_from_file(&blocklist.into(), validate_blocklist);
return self.blocklist_provider_from_file(
&blocklist.into(),
require_non_empty_blocklist,
);
}
}
}

// Backwards compatibility
if let Some(blocklist_file_path) = &self.blocklist_file_path {
warn!("blocklist_file_path is deprecated please use blocklist");
return self.blocklist_provider_from_file(blocklist_file_path, validate_blocklist);
return self
.blocklist_provider_from_file(blocklist_file_path, require_non_empty_blocklist);
}

// default to empty
Expand Down Expand Up @@ -467,6 +486,7 @@ pub const DEFAULT_INCOMING_BUNDLES_PORT: u16 = 8645;
pub const DEFAULT_RETH_DB_PATH: &str = "/mnt/data/reth";
/// This will update every 2.4 hours, super reasonable.
pub const DEFAULT_BLOCKLIST_URL_MAX_AGE_HOURS: u64 = 24;
pub const DEFAULT_REQUIRE_NON_EMPTY_BLOCKLIST: bool = false;

impl Default for BaseConfig {
fn default() -> Self {
Expand Down Expand Up @@ -510,6 +530,7 @@ impl Default for BaseConfig {
simulation_threads: 1,
sbundle_mergeable_signers: None,
sbundle_mergeabe_signers: None,
require_non_empty_blocklist: Some(DEFAULT_REQUIRE_NON_EMPTY_BLOCKLIST),
}
}
}
Expand Down Expand Up @@ -611,6 +632,7 @@ mod test {
use reth_node_core::dirs::{DataDirPath, MaybePlatformPath};
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
use tempfile::TempDir;
use tokio_util::sync::CancellationToken;

#[test]
fn test_default_config() {
Expand All @@ -620,6 +642,20 @@ mod test {
assert_eq!(config, config_default);
}

#[tokio::test]
async fn test_require_non_empty_blocklist() {
let config = BaseConfig {
blocklist: None,
blocklist_file_path: None,
require_non_empty_blocklist: Some(true),
..Default::default()
};
assert!(config
.blocklist_provider(CancellationToken::new())
.await
.is_err());
}

#[test]
fn test_reth_db() {
// Setup and initialize a temp reth db (with static files)
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl LiveBuilderConfig for Config {

let blocklist_provider = self
.base_config
.blocklist_provider(false, cancellation_token.clone())
.blocklist_provider(cancellation_token.clone())
.await?;
let payload_event = MevBoostSlotDataGenerator::new(
self.l1_config.beacon_clients()?,
Expand Down

0 comments on commit 605cbd0

Please sign in to comment.