Skip to content

Commit d01277a

Browse files
authored
Better parsing for backtesting flag --only-order-ids (#811)
## 📝 Summary Previous version would fail silently with illegal ids (eg: if you forget "bundle:" prefix). Instead if comparing a string to OrderId.to_string() we parse the parameter as OrderId and fail on errors. ## 💡 Motivation and Context Sinc I strted to ad some vodka t my morning cofe mi tiping gat wors, I ned vetter tuols.
1 parent 15e0475 commit d01277a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

crates/rbuilder/src/backtest/build_block/landed_block_from_db.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ahash::HashMap;
1010
use alloy_primitives::utils::format_ether;
1111
use rbuilder_config::load_toml_config;
12+
use rbuilder_primitives::OrderId;
1213
use reth_db::DatabaseEnv;
1314
use reth_node_api::NodeTypesWithDBAdapter;
1415
use reth_node_ethereum::EthereumNode;
@@ -31,7 +32,7 @@ use crate::{
3132
},
3233
};
3334
use clap::Parser;
34-
use std::{path::PathBuf, sync::Arc};
35+
use std::{path::PathBuf, str::FromStr, sync::Arc};
3536

3637
use super::backtest_build_block::{run_backtest_build_block, BuildBlockCfg, OrdersSource};
3738

@@ -75,7 +76,13 @@ impl<ConfigType: LiveBuilderConfig> LandedBlockFromDBOrdersSource<ConfigType> {
7576
let block_data = read_block_data(
7677
&config.base_config().backtest_fetch_output_file,
7778
extra_cfg.block,
78-
extra_cfg.only_order_ids,
79+
extra_cfg
80+
.only_order_ids
81+
.iter()
82+
.map(|id| {
83+
OrderId::from_str(id).map_err(|e| eyre::eyre!("invalid order id: {id}: {e}"))
84+
})
85+
.collect::<Result<Vec<OrderId>, eyre::Error>>()?,
7986
extra_cfg.block_building_time_ms,
8087
extra_cfg.show_missing,
8188
)
@@ -163,7 +170,7 @@ impl<ConfigType: LiveBuilderConfig>
163170
async fn read_block_data(
164171
backtest_fetch_output_file: &PathBuf,
165172
block: u64,
166-
only_order_ids: Vec<String>,
173+
only_order_ids: Vec<OrderId>,
167174
block_building_time_ms: i64,
168175
show_missing: bool,
169176
) -> eyre::Result<BlockData> {

crates/rbuilder/src/backtest/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ impl BlockData {
191191
});
192192
}
193193

194-
pub fn filter_orders_by_ids(&mut self, order_ids: &[String]) {
194+
pub fn filter_orders_by_ids(&mut self, order_ids: &[OrderId]) {
195195
self.available_orders.retain(|order| {
196-
if order_ids.contains(&order.order.id().to_string()) {
196+
if order_ids.contains(&order.order.id()) {
197197
true
198198
} else {
199199
trace!(order = ?order.order.id(), "order filtered by id");

0 commit comments

Comments
 (0)