Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Oct 11, 2024
1 parent 7db60e4 commit cfb6225
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/pool/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,31 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM
// Collect the accounts into a vector for shuffling
let mut accounts: Vec<_> = self.accounts.iter().collect();

// Shuffle the accounts randomly before iterating
accounts.shuffle(&mut rng);

loop {
if accounts.is_empty() {
return Err(eyre::eyre!("failed to fetch funded account"));
}

// Shuffle the accounts randomly before iterating
accounts.shuffle(&mut rng);

// Create the future locks with indices for more efficient removal
// use [`select_all`] to poll an iterator over impl Future<Output = (Felt, MutexGuard<Felt>)>
// We use Box::pin because this Future doesn't implement `Unpin`.
let fut_locks = accounts.iter().map(|(address, nonce)| Box::pin(async { (*address, nonce.lock().await) }));
let ((account_address, guard), _, _) = select_all(fut_locks).await;
let fut_locks = accounts
.iter()
.enumerate()
.map(|(index, (address, nonce))| Box::pin(async move { (index, *address, nonce.lock().await) }));

// Select the first account that gets unlocked
let ((index, account_address, guard), _, _) = select_all(fut_locks).await;

// Fetch the balance of the selected account
let balance = self.get_balance(*account_address).await?;

// If the balance is lower than the threshold, continue
// If the balance is lower than the threshold, remove the account using swap_remove
if balance < U256::from(ONE_TENTH_ETH) {
accounts.retain(|(addr, _)| *addr != account_address);
accounts.swap_remove(index);
continue;
}

Expand Down

0 comments on commit cfb6225

Please sign in to comment.