Skip to content

Commit 1991175

Browse files
authored
Handle tasks run by another crank turner then replaced by new tasks (#81)
* Handle tasks run by another crank turner then replaced by new tasks * is_some_and
1 parent a7ae1c3 commit 1991175

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tuktuk-crank-turner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tuktuk-crank-turner"
3-
version = "0.2.25"
3+
version = "0.2.26"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

tuktuk-crank-turner/src/task_processor.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use solana_sdk::{instruction::InstructionError, signer::Signer, transaction::Tra
55
use solana_transaction_utils::{error::Error as TransactionQueueError, queue::TransactionTask};
66
use tokio_graceful_shutdown::SubsystemHandle;
77
use tracing::{debug, info};
8-
use tuktuk_program::TaskQueueV0;
9-
use tuktuk_sdk::compiled_transaction::{
10-
next_available_task_ids_excluding_in_progress, run_ix_with_free_tasks,
8+
use tuktuk_program::{TaskQueueV0, TaskV0};
9+
use tuktuk_sdk::{
10+
client::GetAnchorAccount,
11+
compiled_transaction::{next_available_task_ids_excluding_in_progress, run_ix_with_free_tasks},
1112
};
1213

1314
use crate::{
@@ -271,6 +272,23 @@ impl TimedTask {
271272
)) if code == 3012 && ctx.rpc_client.get_account(&self.task_key).await.is_err() => {
272273
info!(?self.task_key, "task not found, removing from queue");
273274
}
275+
// Handle task not ready
276+
// There's a race condition where the task was already completed and replaced with a new one,
277+
// yet we're still trying to process the old task.
278+
TransactionQueueError::TransactionError(TransactionError::InstructionError(
279+
_,
280+
InstructionError::Custom(code),
281+
)) if code == 6005
282+
&& ctx
283+
.rpc_client
284+
.anchor_account::<TaskV0>(&self.task_key)
285+
.await
286+
.ok()
287+
.flatten()
288+
.is_some_and(|acc| acc.queued_at != self.task.queued_at) =>
289+
{
290+
info!(?self.task_key, "task was already replaced, skipping");
291+
}
274292
TransactionQueueError::RawTransactionError(_)
275293
| TransactionQueueError::SimulatedTransactionError(_)
276294
| TransactionQueueError::TransactionError(_)

0 commit comments

Comments
 (0)