Skip to content

Commit

Permalink
Revert "feat: batch nonce relayers requests (#1491)"
Browse files Browse the repository at this point in the history
This reverts commit f005ea1.
  • Loading branch information
greged93 authored Oct 25, 2024
1 parent 2d8e79e commit dd2ea15
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions src/pool/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use reth_transaction_pool::{
TransactionOrigin, TransactionPool, TransactionPoolExt,
};
use starknet::{
core::types::{requests::GetNonceRequest, BlockId, BlockTag, Felt},
providers::{jsonrpc::HttpTransport, JsonRpcClient, ProviderRequestData, ProviderResponseData},
core::types::{BlockTag, Felt},
providers::{jsonrpc::HttpTransport, JsonRpcClient},
};
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::Mutex;
Expand Down Expand Up @@ -208,33 +208,19 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM
pub fn start_nonce_updater(self: Arc<Self>) {
tokio::spawn(async move {
loop {
// Convert the account addresses into batch requests
let requests = self
.accounts
.keys()
.map(|add| {
ProviderRequestData::GetNonce(GetNonceRequest {
contract_address: *add,
block_id: BlockId::Tag(BlockTag::Pending),
})
})
.collect::<Vec<_>>();

// Try to make the request to the provider. If it fails, display error and retry 1 minute later.
let maybe_new_nonces = self.eth_client.starknet_provider().batch_requests(requests).await;
if maybe_new_nonces.is_err() {
tracing::error!(target: "account_manager", err = ?maybe_new_nonces.unwrap_err(), "failed to get nonces");
// Sleep for 1 minute before the next update
tokio::time::sleep(Duration::from_secs(60)).await;
continue;
}
let new_nonces = maybe_new_nonces.expect("not error");

for ((address, old_nonce), new_nonce) in self.accounts.iter().zip(new_nonces) {
if let ProviderResponseData::GetNonce(new_nonce) = new_nonce {
*old_nonce.lock().await = new_nonce;
tracing::info!(target: "account_manager", ?address, ?new_nonce);
};
for (address, nonce_mutex) in &self.accounts {
// Query the updated nonce for the account from the provider
let new_nonce = self
.eth_client
.starknet_provider()
.get_nonce(starknet::core::types::BlockId::Tag(BlockTag::Pending), *address)
.await
.unwrap_or_default();

let mut nonce = nonce_mutex.lock().await;
*nonce = new_nonce;

tracing::info!(target: "account_manager", ?address, ?new_nonce);
}

// Sleep for 1 minute before the next update
Expand Down

0 comments on commit dd2ea15

Please sign in to comment.