Skip to content

Commit 4409bbf

Browse files
committed
fix: avoid executing run_with_custom_intervals at the same time using mutex
1 parent 838d0bc commit 4409bbf

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub struct Opts {
6565
#[clap(env, short, long, value_parser = humantime::parse_duration, default_value = "15m")]
6666
pub period: std::time::Duration,
6767
/// Time delay between each intervalgroup of transactions
68-
#[clap(env, short, long, value_parser = humantime::parse_duration, default_value = "10s")]
68+
#[clap(env, short, long, value_parser = humantime::parse_duration, default_value = "6s")]
6969
pub group_delay: std::time::Duration,
7070
/// Override intervals for specific transaction types (JSON format: {"MpcSignEcdsa": "5m", "Swap": "10m"})
7171
#[clap(env, long, value_parser = parse_interval_overwrite)]

src/transaction/engine.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use near_jsonrpc_primitives::types::query::QueryResponseKind;
44
use near_primitives::hash::CryptoHash;
55
use near_primitives::types::{BlockReference, Nonce};
66
use std::{collections::HashMap, sync::Arc};
7+
use tokio::sync::Mutex;
78

89
use tracing::{error, info, warn};
910

@@ -148,21 +149,16 @@ impl Engine {
148149
.or_default()
149150
.extend(default_transactions);
150151
}
152+
let run_account_transactions_once_mutex = Arc::new(Mutex::new(()));
151153

152154
// Spawn a task for each interval group
153-
for (task_id, (interval_duration, transaction_kinds)) in
154-
interval_groups.into_iter().enumerate()
155-
{
155+
for (interval_duration, transaction_kinds) in interval_groups.into_iter() {
156156
let opts_clone = opts.clone();
157157
let metrics_clone = metrics.clone();
158158
let transactions_clone = transactions.clone();
159159

160+
let mutex_clone = Arc::clone(&run_account_transactions_once_mutex);
160161
tasks.spawn(async move {
161-
// Add 3 second delay between each interval group start
162-
if task_id > 0 {
163-
tokio::time::sleep(group_delay).await;
164-
}
165-
166162
let mut interval = interval(interval_duration);
167163
loop {
168164
interval.tick().await;
@@ -181,6 +177,8 @@ impl Engine {
181177
.map(|(kind, tx)| (kind.clone(), tx.clone()))
182178
.collect();
183179

180+
let _lock = mutex_clone.lock().await;
181+
184182
run_account_transactions_once(
185183
filtered_transactions,
186184
opts_clone.clone(),

0 commit comments

Comments
 (0)