Skip to content

Commit fb9988c

Browse files
committed
set max bundle tx limit and gas limit
1 parent 230544c commit fb9988c

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

crates/ingress-rpc/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ pub struct Config {
193193
#[arg(long, env = "TIPS_INGRESS_BACKRUN_ENABLED", default_value = "false")]
194194
pub backrun_enabled: bool,
195195

196+
/// Maximum number of transactions allowed in a backrun bundle (including target tx)
197+
#[arg(long, env = "MAX_BACKRUN_TXS", default_value = "5")]
198+
pub max_backrun_txs: usize,
199+
200+
/// Maximum total gas limit for all transactions in a backrun bundle
201+
#[arg(long, env = "MAX_BACKRUN_GAS_LIMIT", default_value = "5000000")]
202+
pub max_backrun_gas_limit: u64,
203+
196204
/// URL of third-party RPC endpoint to forward raw transactions to (enables forwarding if set)
197205
#[arg(long, env = "TIPS_INGRESS_RAW_TX_FORWARD_RPC")]
198206
pub raw_tx_forward_rpc: Option<Url>,

crates/ingress-rpc/src/service.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub struct IngressService<Q: MessageQueue, M: Mempool> {
8282
builder_tx: broadcast::Sender<MeterBundleResponse>,
8383
backrun_enabled: bool,
8484
builder_backrun_tx: broadcast::Sender<AcceptedBundle>,
85+
max_backrun_txs: usize,
86+
max_backrun_gas_limit: u64,
8587
}
8688

8789
impl<Q: MessageQueue, M: Mempool> IngressService<Q, M> {
@@ -127,6 +129,8 @@ impl<Q: MessageQueue, M: Mempool> IngressService<Q, M> {
127129
builder_tx,
128130
backrun_enabled: config.backrun_enabled,
129131
builder_backrun_tx,
132+
max_backrun_txs: config.max_backrun_txs,
133+
max_backrun_gas_limit: config.max_backrun_gas_limit,
130134
}
131135
}
132136
}
@@ -135,10 +139,6 @@ impl<Q: MessageQueue, M: Mempool> IngressService<Q, M> {
135139
impl<Q: MessageQueue + 'static, M: Mempool + 'static> IngressApiServer for IngressService<Q, M> {
136140
async fn send_backrun_bundle(&self, bundle: Bundle) -> RpcResult<BundleHash> {
137141
if !self.backrun_enabled {
138-
info!(
139-
message = "Backrun bundle submission is disabled",
140-
backrun_enabled = self.backrun_enabled
141-
);
142142
return Err(
143143
EthApiError::InvalidParams("Backrun bundle submission is disabled".into())
144144
.into_rpc_err(),
@@ -149,16 +149,40 @@ impl<Q: MessageQueue + 'static, M: Mempool + 'static> IngressApiServer for Ingre
149149
let (accepted_bundle, bundle_hash) =
150150
self.validate_parse_and_meter_bundle(&bundle, false).await?;
151151

152-
self.metrics.backrun_bundles_received_total.increment(1);
152+
if accepted_bundle.txs.len() < 2 {
153+
return Err(EthApiError::InvalidParams(
154+
"Backrun bundle must have at least 2 transactions (target + backrun)".into(),
155+
)
156+
.into_rpc_err());
157+
}
153158

154-
if let Err(e) = self.builder_backrun_tx.send(accepted_bundle.clone()) {
155-
warn!(
156-
message = "Failed to send backrun bundle to builders",
157-
bundle_hash = %bundle_hash,
158-
error = %e
159-
);
159+
if accepted_bundle.txs.len() > self.max_backrun_txs {
160+
return Err(EthApiError::InvalidParams(format!(
161+
"Backrun bundle exceeds max transaction count: {} > {}",
162+
accepted_bundle.txs.len(),
163+
self.max_backrun_txs
164+
))
165+
.into_rpc_err());
160166
}
161167

168+
let total_gas_limit: u64 = accepted_bundle.txs.iter().map(|tx| tx.gas_limit()).sum();
169+
if total_gas_limit > self.max_backrun_gas_limit {
170+
return Err(EthApiError::InvalidParams(format!(
171+
"Backrun bundle exceeds max gas limit: {} > {}",
172+
total_gas_limit, self.max_backrun_gas_limit
173+
))
174+
.into_rpc_err());
175+
}
176+
177+
self.metrics.backrun_bundles_received_total.increment(1);
178+
179+
self.builder_backrun_tx
180+
.send(accepted_bundle.clone())
181+
.map_err(|e| {
182+
EthApiError::InvalidParams(format!("Failed to send backrun bundle: {e}"))
183+
.into_rpc_err()
184+
})?;
185+
162186
self.send_audit_event(&accepted_bundle, bundle_hash);
163187

164188
self.metrics
@@ -578,6 +602,8 @@ mod tests {
578602
raw_tx_forward_rpc: None,
579603
chain_id: 11,
580604
user_operation_topic: String::new(),
605+
max_backrun_txs: 5,
606+
max_backrun_gas_limit: 5000000,
581607
}
582608
}
583609

0 commit comments

Comments
 (0)