Skip to content

Commit

Permalink
NDEV-2043: Replace tokio::sync::RwLock with RefCell
Browse files Browse the repository at this point in the history
  • Loading branch information
andreisilviudragnea committed Sep 25, 2023
1 parent 1beebf1 commit cbcdd4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions evm_loader/lib/src/commands/init_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ pub async fn execute(

let signatures = executor
.signatures
.read()
.await
.borrow()
.iter()
.map(|s| bs58::encode(s).into_string())
.collect::<Vec<String>>();
Expand Down
12 changes: 6 additions & 6 deletions evm_loader/lib/src/commands/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -49,7 +48,7 @@ impl Stats {
pub struct TransactionExecutor<'a, 'b> {
pub client: &'a dyn rpc::Rpc,
pub send_trx: bool,
pub signatures: RwLock<Vec<Signature>>,
pub signatures: RefCell<Vec<Signature>>,
pub stats: RefCell<Stats>,
pub fee_payer: &'b dyn Signer,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit cbcdd4a

Please sign in to comment.