Skip to content

Commit

Permalink
feat(bundles): update send bundle loop to only wait for new blocks on…
Browse files Browse the repository at this point in the history
… auto bundling mode
  • Loading branch information
0xfourzerofour committed Oct 5, 2023
1 parent c2224ac commit c2824b0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions crates/builder/src/bundle_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ where

loop {
let mut send_bundle_response: Option<oneshot::Sender<SendBundleResult>> = None;
let mut last_block = None;

if self.manual_bundling_mode.load(Ordering::Relaxed) {
tokio::select! {
Expand All @@ -151,34 +152,33 @@ where
continue;
}
}
}
} else {
last_block = rx.recv().await;

// Wait for new block. Block number doesn't matter as the pool will only notify of new blocks
// after the pool has updated its state. The bundle will be formed using the latest pool state
// and can land in the next block
let mut last_block = match rx.recv().await {
Some(b) => b,
None => {
if last_block.is_none() {
error!("Block stream closed");
bail!("Block stream closed");
}
};
// Consume any other blocks that may have been buffered up
loop {
match rx.try_recv() {
Ok(b) => {
last_block = b;
}
Err(mpsc::error::TryRecvError::Empty) => {
break;
}
Err(mpsc::error::TryRecvError::Disconnected) => {
error!("Block stream closed");
bail!("Block stream closed");
// Consume any other blocks that may have been buffered up
loop {
match rx.try_recv() {
Ok(b) => {
last_block = Some(b);
}
Err(mpsc::error::TryRecvError::Empty) => {
break;
}
Err(mpsc::error::TryRecvError::Disconnected) => {
error!("Block stream closed");
bail!("Block stream closed");
}
}
}
}

// Wait for new block. Block number doesn't matter as the pool will only notify of new blocks
// after the pool has updated its state. The bundle will be formed using the latest pool state
// and can land in the next block
self.check_for_and_log_transaction_update().await;
let result = self.send_bundle_with_increasing_gas_fees().await;
match &result {
Expand All @@ -192,7 +192,7 @@ where
} else {
info!("Bundle with hash {tx_hash:?} landed in block {block_number} after increasing gas fees {attempt_number} time(s)");
}
SendBundleResult::NoOperationsInitially => trace!("No ops to send at block {}", last_block.block_number),
SendBundleResult::NoOperationsInitially => trace!("No ops to send at block {}", last_block.unwrap().block_number),
SendBundleResult::NoOperationsAfterFeeIncreases {
initial_op_count,
attempt_number,
Expand Down

0 comments on commit c2824b0

Please sign in to comment.