From 5435ef54081d79bfc623668db75e535459c59f4c Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Tue, 10 Dec 2024 20:19:32 +0000 Subject: [PATCH] Make `get_transaction()` yieldy When this method reaches out to blockstore, yield the thread --- rpc/src/rpc.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 9349201c5f4af0..6beb3280f6defb 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -1707,13 +1707,22 @@ impl JsonRpcRequestProcessor { if self.config.enable_rpc_transaction_history { let confirmed_bank = self.bank(Some(CommitmentConfig::confirmed())); - let confirmed_transaction = if commitment.is_confirmed() { - let highest_confirmed_slot = confirmed_bank.slot(); - self.blockstore - .get_complete_transaction(signature, highest_confirmed_slot) - } else { - self.blockstore.get_rooted_transaction(signature) - }; + let confirmed_transaction = self + .runtime + .spawn_blocking({ + let blockstore = Arc::clone(&self.blockstore); + let confirmed_bank = Arc::clone(&confirmed_bank); + move || { + if commitment.is_confirmed() { + let highest_confirmed_slot = confirmed_bank.slot(); + blockstore.get_complete_transaction(signature, highest_confirmed_slot) + } else { + blockstore.get_rooted_transaction(signature) + } + } + }) + .await + .expect("Failed to spawn blocking task"); let encode_transaction = |confirmed_tx_with_meta: ConfirmedTransactionWithStatusMeta| -> Result {