Skip to content

Commit

Permalink
Abort on panic + better instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Feb 15, 2024
1 parent 29c90ed commit 1de9292
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ test-case = "3.1.0"
[features]
default = ["default-config"]
default-config = []

[profile.release]
panic = "abort"
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Service {

let task_runner = TaskRunner::new(app.clone());
task_runner.add_task("Broadcast transactions", tasks::broadcast_txs);
task_runner.add_task("Escalate transactions", tasks::escalate_txs);
task_runner.add_task("Escalate transactions", tasks::escalate_txs_task);
task_runner.add_task("Prune blocks", tasks::prune_blocks);
task_runner.add_task("Prune transactions", tasks::prune_txs);
task_runner.add_task("Finalize transactions", tasks::finalize_txs);
Expand Down
2 changes: 1 addition & 1 deletion src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod metrics;
pub mod prune;

pub use self::broadcast::broadcast_txs;
pub use self::escalate::escalate_txs;
pub use self::escalate::escalate_txs_task;
pub use self::finalize::finalize_txs;
pub use self::handle_reorgs::{handle_hard_reorgs, handle_soft_reorgs};
pub use self::index::index_chain;
Expand Down
46 changes: 25 additions & 21 deletions src/tasks/escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,40 @@ use crate::broadcast_utils::should_send_relayer_transactions;
use crate::db::TxForEscalation;
use crate::types::RelayerInfo;

pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {
pub async fn escalate_txs_task(app: Arc<App>) -> eyre::Result<()> {
loop {
tracing::info!("Escalating transactions");
escalate_txs(&app).await?;

let txs_for_escalation = app
.db
.get_txs_for_escalation(app.config.service.escalation_interval)
.await?;
tokio::time::sleep(app.config.service.escalation_interval).await;
}
}

tracing::info!(
"Got {} transactions to escalate",
txs_for_escalation.len()
);
#[tracing::instrument(skip(app))]
async fn escalate_txs(app: &App) -> eyre::Result<()> {
tracing::info!("Escalating transactions");

let txs_for_escalation = split_txs_per_relayer(txs_for_escalation);
let txs_for_escalation = app
.db
.get_txs_for_escalation(app.config.service.escalation_interval)
.await?;

let mut futures = FuturesUnordered::new();
tracing::info!("Got {} transactions to escalate", txs_for_escalation.len());

for (relayer_id, txs) in txs_for_escalation {
futures.push(escalate_relayer_txs(&app, relayer_id, txs));
}
let txs_for_escalation = split_txs_per_relayer(txs_for_escalation);

while let Some(result) = futures.next().await {
if let Err(err) = result {
tracing::error!(error = ?err, "Failed escalating txs");
}
}
let mut futures = FuturesUnordered::new();

tokio::time::sleep(app.config.service.escalation_interval).await;
for (relayer_id, txs) in txs_for_escalation {
futures.push(escalate_relayer_txs(&app, relayer_id, txs));

Check failure on line 41 in src/tasks/escalate.rs

View workflow job for this annotation

GitHub Actions / cargo test

this expression creates a reference which is immediately dereferenced by the compiler
}

while let Some(result) = futures.next().await {
if let Err(err) = result {
tracing::error!(error = ?err, "Failed escalating txs");
}
}

Ok(())
}

#[tracing::instrument(skip(app, txs))]
Expand Down

0 comments on commit 1de9292

Please sign in to comment.