From 1d8138bcb3c58a37399e31a1fec6e0c92640aa2b Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:46:19 +0200 Subject: [PATCH] fix: end2end testing (#1425) various fixes discovered during end2end testing --- src/main.rs | 12 ++----- src/pool/mempool.rs | 16 ++++----- src/pool/sepolia_accounts.json | 35 +++---------------- src/pool/validate.rs | 10 ++---- .../eth_provider/starknet/relayer.rs | 6 +--- 5 files changed, 17 insertions(+), 62 deletions(-) diff --git a/src/main.rs b/src/main.rs index af0a9f782..ec58373d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,16 +50,8 @@ async fn main() -> Result<()> { let starknet_provider = Arc::new(starknet_provider); // Get the pool config - let config = { - #[cfg(feature = "hive")] - { - PoolConfig { minimal_protocol_basefee: 0, ..Default::default() } - } - #[cfg(not(feature = "hive"))] - { - PoolConfig::default() - } - }; + // TODO call Kakarot.get_base_fee + let config = PoolConfig { minimal_protocol_basefee: 0, ..Default::default() }; let eth_client = EthClient::try_new(starknet_provider, config, db.clone()).await.expect("failed to start ethereum client"); diff --git a/src/pool/mempool.rs b/src/pool/mempool.rs index fb4a643cb..3a975648e 100644 --- a/src/pool/mempool.rs +++ b/src/pool/mempool.rs @@ -95,7 +95,7 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM let maybe_relayer = manager.lock_account().await; if maybe_relayer.is_err() { // If we fail to fetch a relayer, we need to re-insert the transaction in the pool - tracing::error!(target: "account_manager", err = ?maybe_relayer.unwrap(), "failed to fetch relayer"); + tracing::error!(target: "account_manager", err = ?maybe_relayer.unwrap_err(), "failed to fetch relayer"); let _ = manager .eth_client .mempool() @@ -110,7 +110,7 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM let res = relayer.relay_transaction(&transaction_signed).await; if res.is_err() { // If the relayer failed to relay the transaction, we need to reposition it in the mempool - tracing::error!(target: "account_manager", err = ?res.unwrap(), "failed to relay transaction"); + tracing::error!(target: "account_manager", err = ?res.unwrap_err(), "failed to relay transaction"); let _ = manager .eth_client .mempool() @@ -146,13 +146,7 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM let ((account_address, guard), _, _) = select_all(fut_locks).await; // Fetch the balance of the selected account - let balance = self - .get_balance(*account_address) - .await - .inspect_err(|err| { - tracing::error!(target: "account_manager", ?account_address, ?err, "failed to fetch balance"); - }) - .unwrap_or_default(); + let balance = self.get_balance(*account_address).await?; // If the balance is lower than the threshold, continue if balance < U256::from(ONE_TENTH_ETH) { @@ -161,12 +155,14 @@ impl<SP: starknet::providers::Provider + Send + Sync + Clone + 'static> AccountM } let balance = into_via_try_wrapper!(balance)?; + let chain_id = self.eth_client.starknet_provider().chain_id().await?; + let account = LockedRelayer::new( guard, *account_address, balance, JsonRpcClient::new(HttpTransport::new(RPC_CONFIG.network_url.clone())), - self.eth_client.starknet_provider().chain_id().await.expect("Failed to get chain id"), + chain_id, ); // Return the account address and the guard on the nonce diff --git a/src/pool/sepolia_accounts.json b/src/pool/sepolia_accounts.json index d981f6bd0..80ef2139b 100644 --- a/src/pool/sepolia_accounts.json +++ b/src/pool/sepolia_accounts.json @@ -1,32 +1,7 @@ [ - "0xb89b13d4cd81e673590d5c5fe07b7a95c9bdae37e7da993bb55060c49dd21b", - "0x7e28affdd5dc3903fc11ddf667c313cad5f7593ec68c81c8936a8fc4cafce25", - "0xd740608de6e375938944c34aecb5d5f5469bbabe264cc28c672a946588adc5", - "0x7732f430974ab068c4989ebf4f4b8024b450a7663dba6064ef1f11f71ecbc60", - "0xc9b62b08a81e88fb7894967ce6c7257bec9c95faf308238f79fba669a3c913", - "0x1bb0355251fc030c90537908f5431d5dd77dd01d5ccdd6461b2e1bee759a632", - "0x2563a565f7b156c1ea814b8b6bc16a310c049c0fc5c1fd6c6edee2f4ec02d6a", - "0x19395269310dd7a2520d67fb7722796e03541eae8d83349b1361b30cecc775d", - "0x41b98540dfb3a3456abe2c0e6c206fb66d5c268fcf8b81cd5dc4d30abeef7d8", - "0x511d0f2ed36cbe939ae05f5dc9cc3141de7893723f5f152ae11917c6d3f7211", - "0x1b61866fe2e195aa10b859594066c9bbe39d43a3b90b65865f5cf666ee3ba79", - "0x6b94e632ae5ddbc6b54d58c72ce6339f2c6fed5a579243859ddc54f6dbeddf5", - "0xc0ae2d70922a941295d6a07fc1c6b84bcb063b83de2750f6abc9b024fe6b2c", - "0x75f628d8199c4e6f8b7cea4798241adbc14a291d4e0aa1b64302a7b78ed98fb", - "0xd77153735ed2fd33aa9e031df8fe416deb456e76585cee92e98f8fb1d7dbae", - "0x109d5fa7e4f228647c202e1922a81306b1c4efae0d7b2ded7c71521565f6af4", - "0x4f3f076a44f26dc0c8c1364652287f96ab45da2f9a93ccc54a0f2f64f1050f9", - "0x6cd3732a00849eaee57041aadac6d747a8823939da40870eeb0302b3f7affb8", - "0x394d012f18a366fa30ae21be6b2b1019d2c9e08b1fd9b469d5decddbd243109", - "0x22fb3426c949e74ea9eccc48932e6036454c369764e7a28df440c5c6eb47750", - "0x209d52fe2a4632ed2294f45faf94cb9a7ea16e950f1a38fe60294aa946eb745", - "0x1f8a93a3d83b99ec90b098eb93c9c90dafe57c0eb8dae4dab37beece56f078e", - "0x3c89ab21270f228f66aef83ab8ef74158a789dfef9ed9c08b6c1cfd23fda292", - "0x226a05817ddc19e329cdc64e047f0076a8d338bfe684f0883ba37f2aa171094", - "0x5e39291bc104f0cd82f66e368bdd972fd975eb154083458057c2f2738ad7521", - "0x17e012f88b87e6c44f6a93d755b93c5a5d5f082f9f97b100abf9f40452caa1a", - "0x79781f343ab264bbc26580694817cc117d628ddc262d85c5d1539a7cb793419", - "0x402f507f0d448d37728c6902b8efcd8edb3bda96d15fbd25215e58726836c9b", - "0x4cd4cf8ae23b251743c3ea56c6adcfd39ec4a066325bd28e73aa954786afc3f", - "0x64c147dbcc1fd952b7e5956136353f73a5dfc0ed29a0c343eabc7527462be90" + "0x4a24cf6a552591dde0f654c15c42227dbdb66d7634aee144703c61d1b519268", + "0x595e3ee91ac131371399044b603b5909f33d44bdf72748e5233f6394098f5ba", + "0xe76bd52863c4d15f8fc4b1e3c51f1ed6c0a29254f5912b2dcfab8752d32f11", + "0x4806466971baa2a234e49409340ee1c0a703a7865176c01dea458ae0d6a8b06", + "0x3a427aca2f11e22ef583e131013a81a37054df72ee48dded88c3f1a83463c16" ] diff --git a/src/pool/validate.rs b/src/pool/validate.rs index 8a72e4fe9..0de1d3483 100644 --- a/src/pool/validate.rs +++ b/src/pool/validate.rs @@ -10,6 +10,7 @@ use reth_primitives::{ EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; use reth_revm::DatabaseRef; +use reth_rpc_types::BlockNumberOrTag; use reth_transaction_pool::{ error::InvalidPoolTransactionError, validate::{ensure_intrinsic_gas, ForkTracker, ValidTransaction, DEFAULT_MAX_TX_INPUT_BYTES}, @@ -312,13 +313,8 @@ where return TransactionValidationOutcome::Invalid(transaction, err); } - let handle = tokio::runtime::Handle::current(); - let block = match tokio::task::block_in_place(|| handle.block_on(self.provider.block_number())) { - Ok(b) => b, - Err(err) => return TransactionValidationOutcome::Error(*transaction.hash(), Box::new(err)), - }; - let db = EthDatabase::new(Arc::new(&self.provider), BlockId::from(block.to::<u64>())); - + // Fetch the account state for the Pending block + let db = EthDatabase::new(Arc::new(&self.provider), BlockId::from(BlockNumberOrTag::Pending)); let account = match db.basic_ref(transaction.sender()) { Ok(account) => account.unwrap_or_default(), Err(err) => return TransactionValidationOutcome::Error(*transaction.hash(), Box::new(err)), diff --git a/src/providers/eth_provider/starknet/relayer.rs b/src/providers/eth_provider/starknet/relayer.rs index c54ee1990..75eba7401 100644 --- a/src/providers/eth_provider/starknet/relayer.rs +++ b/src/providers/eth_provider/starknet/relayer.rs @@ -69,11 +69,7 @@ where execution = execution.max_fee(self.balance - 1); let prepared = execution.prepared().map_err(|_| SignatureError::SigningFailure)?; - let res = prepared - .send() - .await - .inspect_err(|err| tracing::error!(target: "relayer", ?err)) - .map_err(|err| TransactionError::Broadcast(err.into()))?; + let res = prepared.send().await.map_err(|err| TransactionError::Broadcast(err.into()))?; Ok(res.transaction_hash) }