From cbcdd4acdd968a43b7540746a3b5ebdd97c405ef Mon Sep 17 00:00:00 2001 From: Andrei Silviu Dragnea Date: Sun, 24 Sep 2023 22:41:51 +0000 Subject: [PATCH] NDEV-2043: Replace tokio::sync::RwLock with RefCell --- evm_loader/lib/src/commands/init_environment.rs | 3 +-- evm_loader/lib/src/commands/transaction_executor.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/evm_loader/lib/src/commands/init_environment.rs b/evm_loader/lib/src/commands/init_environment.rs index bc8067bb74..028bf82b05 100644 --- a/evm_loader/lib/src/commands/init_environment.rs +++ b/evm_loader/lib/src/commands/init_environment.rs @@ -334,8 +334,7 @@ pub async fn execute( let signatures = executor .signatures - .read() - .await + .borrow() .iter() .map(|s| bs58::encode(s).into_string()) .collect::>(); diff --git a/evm_loader/lib/src/commands/transaction_executor.rs b/evm_loader/lib/src/commands/transaction_executor.rs index 849cd1cfc5..b57ec31e50 100644 --- a/evm_loader/lib/src/commands/transaction_executor.rs +++ b/evm_loader/lib/src/commands/transaction_executor.rs @@ -2,7 +2,6 @@ use std::cell::RefCell; use std::future::Future; use serde::{Deserialize, Serialize}; -use tokio::sync::RwLock; use { crate::{errors::NeonError, rpc}, @@ -49,7 +48,7 @@ impl Stats { pub struct TransactionExecutor<'a, 'b> { pub client: &'a dyn rpc::Rpc, pub send_trx: bool, - pub signatures: RwLock>, + pub signatures: RefCell>, pub stats: RefCell, pub fee_payer: &'b dyn Signer, } @@ -59,7 +58,7 @@ impl<'a, 'b> TransactionExecutor<'a, 'b> { Self { client, send_trx, - signatures: RwLock::new(vec![]), + signatures: RefCell::new(vec![]), stats: RefCell::new(Stats::default()), fee_payer, } @@ -97,9 +96,10 @@ impl<'a, 'b> TransactionExecutor<'a, 'b> { } } + #[allow(clippy::await_holding_refcell_ref)] pub async fn checkpoint(&self, commitment: CommitmentConfig) -> Result<(), NeonError> { let recent_blockhash = self.client.get_latest_blockhash().await?; - for sig in self.signatures.read().await.iter() { + for sig in self.signatures.borrow().iter() { self.client .confirm_transaction_with_spinner(sig, &recent_blockhash, commitment) .await?; @@ -170,7 +170,7 @@ impl<'a, 'b> TransactionExecutor<'a, 'b> { match result { Ok(signature) => { warn!("{}: updated in trx {}", name, signature); - self.signatures.write().await.push(signature); + self.signatures.borrow_mut().push(signature); self.stats.borrow_mut().inc_modified_objects(); return Ok(Some(signature)); } @@ -205,7 +205,7 @@ impl<'a, 'b> TransactionExecutor<'a, 'b> { match result { Ok(signature) => { warn!("{}: created in trx {}", name, signature); - self.signatures.write().await.push(signature); + self.signatures.borrow_mut().push(signature); self.stats.borrow_mut().inc_created_objects(); return Ok(Some(signature)); }