Skip to content

Commit

Permalink
Fix timeout/delay_for bug in eth sender
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Apr 5, 2021
1 parent 774c206 commit 4c045de
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions core/bin/zksync_eth_sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,12 @@ impl<DB: DatabaseInterface> ETHSender<DB> {
/// Main routine of `ETHSender`.
pub async fn run(mut self) {
loop {
let load_new_operation_future = time::timeout(
self.options.sender.tx_poll_period(),
self.load_new_operations(),
);
// If the time has expired then we do nothing, but if we received an error
// when loading an new operation, then panic.
if let Ok(load_new_operation) = load_new_operation_future.await {
load_new_operation.unwrap_or_else(|e| panic!("Failed load new operations: {}", e));
// We perform a loading routine every X seconds.
tokio::time::delay_for(self.options.sender.tx_poll_period()).await;
// If we received an error when loading an new operation, we can't do anything about it and should panic.
if let Err(error) = self.load_new_operations().await {
vlog::error!("Unable to restore operations from the database: {}", error);
panic!("Unable to restore operations from the database: {}", error);
}

if self.options.sender.is_enabled {
Expand All @@ -215,6 +213,12 @@ impl<DB: DatabaseInterface> ETHSender<DB> {

let new_operations = self.db.load_new_operations(&mut transaction).await?;

if !new_operations.is_empty() {
vlog::info!("Loaded {} new operations", new_operations.len());
} else {
vlog::debug!("No new operations are loaded from the database");
}

// let's mark the operations as successful processed.
// So that next time you do not add them to the queue again.
let operations_id = new_operations.iter().map(|(id, _)| *id).collect::<Vec<_>>();
Expand Down

0 comments on commit 4c045de

Please sign in to comment.